Bug 1396292 - Part 2: Explicitly run permissions callback on background thread where applicable. r=sebastian, a=lizzard
authorJan Henning <jh+bugzilla@buttercookie.de>
Sat, 02 Sep 2017 21:55:40 +0200
changeset 423967 4bc7d657fca2ae674cebf2193a8d682a85918c05
parent 423966 64b7ee7060ed09d4376dc7587001984f368e0b4d
child 423968 abc3387aaa6fcd05922670e0345f3b513285d8d7
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian, lizzard
bugs1396292
milestone56.0
Bug 1396292 - Part 2: Explicitly run permissions callback on background thread where applicable. r=sebastian, a=lizzard Currently, this only concerns setImageAs, where not running on the UI thread after a permissions prompt triggers a network-related strict mode violation and interestingly enough results in a crash (as opposed to a logcat complaint) on release builds. There's also a permissions check in the UpdateService which runs on a (but not *the*) background thread, but since we don't prompt in that case there's no action necessary. MozReview-Commit-ID: KKxW96AyDWH
mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -937,16 +937,17 @@ public abstract class GeckoApp extends G
             }
         });
     }
 
     // Checks the necessary permissions before attempting to download and set the image as wallpaper.
     private void setImageAs(final String aSrc) {
         Permissions
                 .from(this)
+                .onBackgroundThread()
                 .withPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE)
                 .andFallback(new Runnable() {
                     @Override
                     public void run() {
                         showSetImageResult(/* success */ false, R.string.set_image_path_fail, null);
                     }
                 })
                 .run(new Runnable() {
@@ -960,16 +961,19 @@ public abstract class GeckoApp extends G
 
     /**
      * Downloads the image given by <code>aSrc</code> synchronously and then displays the Chooser
      * activity to set the image as wallpaper.
      *
      * @param aSrc The URI to download the image from.
      */
     private void downloadImageForSetImage(final String aSrc) {
+        // Network access from the main thread can cause a StrictMode crash on release builds.
+        ThreadUtils.assertOnBackgroundThread();
+
         boolean isDataURI = aSrc.startsWith("data:");
         Bitmap image = null;
         InputStream is = null;
         ByteArrayOutputStream os = null;
         try {
             if (isDataURI) {
                 int dataStart = aSrc.indexOf(",");
                 byte[] buf = Base64.decode(aSrc.substring(dataStart + 1), Base64.DEFAULT);