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