Merge branch 'installer-fallback-N' into 'master'
PrivExt API >= 24 uninstall fixes. See merge request !486
This commit is contained in:
commit
e40ce864ce
@ -5,9 +5,24 @@ import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import org.fdroid.fdroid.Utils;
|
||||
import org.fdroid.fdroid.installer.PrivilegedInstaller;
|
||||
|
||||
/**
|
||||
* Starting with 7.0 (API 24), we're using PackageInstaller APIs
|
||||
* to install and uninstall apps via the privileged extension.
|
||||
* That enforces the uninstaller being the same as the installer,
|
||||
* so set the package name to privileged extension if it is being used.
|
||||
* <p>
|
||||
* While setting the installer package name, many problems can occur,
|
||||
* such as:
|
||||
* <li> App wasn't installed due to incompatibility
|
||||
* <li> User canceled install
|
||||
* <li> Another app interfered in the process
|
||||
* <li> Another app already set the target's installer package,
|
||||
* which happens in the case where we fell back to {@link org.fdroid.fdroid.installer.DefaultInstaller}
|
||||
*/
|
||||
public class PackageManagerCompat {
|
||||
|
||||
private static final String TAG = "PackageManagerCompat";
|
||||
@ -16,25 +31,13 @@ public class PackageManagerCompat {
|
||||
public static void setInstaller(Context context, PackageManager mPm, String packageName) {
|
||||
if (Build.VERSION.SDK_INT < 11) return;
|
||||
try {
|
||||
/*
|
||||
* Starting with 7.0 (API 24), we're using PackageInstaller APIs
|
||||
* to install and uninstall apps via the privileged extension.
|
||||
* That enforces the uninstaller being the same as the installer,
|
||||
* so set the package name to that.
|
||||
*/
|
||||
if (Build.VERSION.SDK_INT >= 24 && PrivilegedInstaller.isDefault(context)) {
|
||||
mPm.setInstallerPackageName(packageName, "org.fdroid.fdroid.privileged");
|
||||
} else {
|
||||
mPm.setInstallerPackageName(packageName, "org.fdroid.fdroid");
|
||||
}
|
||||
Utils.debugLog(TAG, "Installer package name for " + packageName + " set successfully");
|
||||
} catch (Exception e) {
|
||||
// Many problems can occur:
|
||||
// * App wasn't installed due to incompatibility
|
||||
// * User canceled install
|
||||
// * Another app interfered in the process
|
||||
// * Another app already set the target's installer package
|
||||
// * ...
|
||||
} catch (SecurityException | IllegalArgumentException e) {
|
||||
Log.e(TAG, "Could not set installer package name for " +
|
||||
packageName, e);
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.PatternMatcher;
|
||||
@ -32,7 +33,6 @@ import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import org.fdroid.fdroid.Utils;
|
||||
import org.fdroid.fdroid.compat.PackageManagerCompat;
|
||||
import org.fdroid.fdroid.data.Apk;
|
||||
import org.fdroid.fdroid.data.ApkProvider;
|
||||
import org.fdroid.fdroid.privileged.views.AppDiff;
|
||||
@ -141,9 +141,10 @@ public abstract class Installer {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
PackageManagerCompat.setInstaller(context, context.getPackageManager(), apk.packageName);
|
||||
} catch (SecurityException e) {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
if (Build.VERSION.SDK_INT >= 24 && (
|
||||
pm.getInstallerPackageName(apk.packageName).equals("com.android.packageinstaller")
|
||||
|| pm.getInstallerPackageName(apk.packageName).equals("com.google.android.packageinstaller"))) {
|
||||
Utils.debugLog(TAG, "Falling back to default installer for uninstall");
|
||||
Intent intent = new Intent(context, DefaultInstallerActivity.class);
|
||||
intent.setAction(DefaultInstallerActivity.ACTION_UNINSTALL_PACKAGE);
|
||||
|
Loading…
x
Reference in New Issue
Block a user