Bug 1476681 - 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.
This patch had already landed as part of
bug 1450449, but subsequently got
overwritten during the refactoring in
bug 1407046.
MozReview-Commit-ID: Ipmmlpm91zK
--- a/mobile/android/base/java/org/mozilla/gecko/updater/Updater.java
+++ b/mobile/android/base/java/org/mozilla/gecko/updater/Updater.java
@@ -21,16 +21,17 @@ import android.net.wifi.WifiManager;
import android.net.wifi.WifiManager.WifiLock;
import android.os.Environment;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.support.v4.app.NotificationCompat;
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.util.Log;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.GeckoUpdateReceiver;
import org.mozilla.gecko.R;
import org.mozilla.gecko.permissions.Permissions;
@@ -510,18 +511,25 @@ public class Updater {
}
if (!PackageVerifier.verifyDownloadedPackage(prefs, updateFile, bufferSize)) {
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(context,
+ 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);
context.startActivity(intent);
}
private boolean deleteUpdatePackage(String path) {
if (path == null) {
return false;
}