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
--- 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);