Bug 1450449 - Part 4: Starting from Nougat, install updates via content:// URIs. r?jchen draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Sat, 12 May 2018 23:34:25 +0200
changeset 803597 ce464e1f8dfe459789161f77a13cd2840283ca5a
parent 803596 cffc3091e60c1c103755925afa362e542f8c84a5
child 803598 56033eac8fe31aadea1ad7cc629b90dd753e8a09
push id112161
push usermozilla@buttercookie.de
push dateMon, 04 Jun 2018 18:00:37 +0000
reviewersjchen
bugs1450449
milestone62.0a1
Bug 1450449 - Part 4: Starting from Nougat, install updates via content:// URIs. r?jchen We download the update APK into the public downloads directory and normally the only relevant app consuming that URI should be the system package installer, but just to be safe we only switch usage from Nougat onward, too. MozReview-Commit-ID: GtoXMJ7NdJ3
mobile/android/base/java/org/mozilla/gecko/updater/UpdateService.java
--- a/mobile/android/base/java/org/mozilla/gecko/updater/UpdateService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/updater/UpdateService.java
@@ -31,16 +31,17 @@ import android.net.ConnectivityManager;
 import android.net.NetworkInfo;
 import android.net.Uri;
 import android.net.wifi.WifiManager;
 import android.net.wifi.WifiManager.WifiLock;
 import android.os.Environment;
 import android.provider.Settings;
 import android.support.v4.app.NotificationManagerCompat;
 import android.support.v4.content.ContextCompat;
+import android.support.v4.content.FileProvider;
 import android.support.v4.net.ConnectivityManagerCompat;
 import android.support.v4.app.NotificationCompat;
 import android.support.v4.app.NotificationCompat.Builder;
 import android.util.Log;
 
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
 import java.io.File;
@@ -691,18 +692,25 @@ public class UpdateService extends Inten
         Log.i(LOGTAG, "Verifying package: " + updateFile);
 
         if (!verifyDownloadedPackage(updateFile)) {
             Log.e(LOGTAG, "Not installing update, failed verification");
             return;
         }
 
         Intent intent = new Intent(Intent.ACTION_VIEW);
-        intent.setDataAndType(Uri.fromFile(updateFile), "application/vnd.android.package-archive");
-        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        if (AppConstants.Versions.preN) {
+            intent.setDataAndType(Uri.fromFile(updateFile), "application/vnd.android.package-archive");
+        } else {
+            Uri apkUri = FileProvider.getUriForFile(this,
+                    AppConstants.MOZ_FILE_PROVIDER_AUTHORITY, updateFile);
+            intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
+            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+        }
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         startActivity(intent);
     }
 
     private void showPermissionNotification() {
         Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
                 Uri.fromParts("package", getPackageName(), null));
 
         PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);