Bug 1396292 - Part 2 - Explicitly run permissions callback on background thread where applicable. r?sebastian draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Sat, 02 Sep 2017 21:55:40 +0200
changeset 658744 713a1765ba69c7cedeaf5980d8ee9ea9d3176ed9
parent 658743 62a0ee11c329bf081095e8c4a61f93911e358c40
child 729745 ccbbd66574f4d2886b15fb0cb9739af4e15e6497
push id77865
push usermozilla@buttercookie.de
push dateMon, 04 Sep 2017 20:07:24 +0000
reviewerssebastian
bugs1396292
milestone57.0a1
Bug 1396292 - Part 2 - Explicitly run permissions callback on background thread where applicable. r?sebastian 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
@@ -904,16 +904,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() {
@@ -927,16 +928,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);