Bug 1396292 - Part 2 - Explicitly run permissions callback on background thread where applicable. r=sebastian
authorJan Henning <jh+bugzilla@buttercookie.de>
Sat, 02 Sep 2017 21:55:40 +0200
changeset 428439 1320c22e21796cb54f02d1712e28b78066fad6c0
parent 428438 6949a7ee45ee4e3f10a5ba437acf643eb75dd52b
child 428440 bf39016f88787bc08d62f69d6391374978bfcee6
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1396292
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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);