diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2019-04-25 07:05:41 -0700 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2019-04-25 07:08:15 -0700 |
commit | 2e4477accbe2d681a8d818088eaca9d2eb48c95b (patch) | |
tree | 15f5da352fd7d968be570fcdcf2325c2d9b9e059 /src/com/android/launcher3/util/IOUtils.java | |
parent | b0c81fc031162d163922f7cdcbf2cbcf3de958b5 (diff) | |
download | packages_apps_Trebuchet-2e4477accbe2d681a8d818088eaca9d2eb48c95b.tar.gz packages_apps_Trebuchet-2e4477accbe2d681a8d818088eaca9d2eb48c95b.tar.bz2 packages_apps_Trebuchet-2e4477accbe2d681a8d818088eaca9d2eb48c95b.zip |
Filling in content values on the worker thread
Writing to disk hapens on the worker thread, so if we create content values on
UI thread, some values can change before it is written to disk.
This happens in case of shortcuts, where the badge is applied after the icon is queued,
but before it is written
Bug: 131303610
Change-Id: Ic35b17071d4ed3e5c5fee9f003a225e4ffdc74f3
Diffstat (limited to 'src/com/android/launcher3/util/IOUtils.java')
-rw-r--r-- | src/com/android/launcher3/util/IOUtils.java | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/com/android/launcher3/util/IOUtils.java b/src/com/android/launcher3/util/IOUtils.java index 77c21fe92..f95f74d60 100644 --- a/src/com/android/launcher3/util/IOUtils.java +++ b/src/com/android/launcher3/util/IOUtils.java @@ -16,12 +16,18 @@ package com.android.launcher3.util; +import android.content.Context; + +import com.android.launcher3.config.FeatureFlags; + import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.UUID; /** * Supports various IO utility functions @@ -52,4 +58,23 @@ public class IOUtils { } return total; } + + /** + * Utility method to debug binary data + */ + public static String createTempFile(Context context, byte[] data) { + if (!FeatureFlags.IS_DOGFOOD_BUILD) { + throw new IllegalStateException("Method only allowed in development mode"); + } + + String name = UUID.randomUUID().toString(); + File file = new File(context.getCacheDir(), name); + try (FileOutputStream fo = new FileOutputStream(file)) { + fo.write(data); + fo.flush(); + } catch (Exception e) { + throw new RuntimeException(e); + } + return file.getAbsolutePath(); + } } |