PrivilegedInstaller: fallback to default installer for uninstall
* On API >= 24, in cases when the installer package name is not set to privext, the system won't let us uninstall. * Fallback to the DefaultInstaller so that uninstall still works.
This commit is contained in:
parent
db4aa3b519
commit
432f45254b
@ -29,6 +29,8 @@ public class PackageManagerCompat {
|
||||
mPm.setInstallerPackageName(packageName, "org.fdroid.fdroid");
|
||||
}
|
||||
Utils.debugLog(TAG, "Installer package name for " + packageName + " set successfully");
|
||||
} catch (SecurityException e) {
|
||||
throw new SecurityException(e);
|
||||
} catch (Exception e) {
|
||||
// Many problems can occur:
|
||||
// * App wasn't installed due to incompatibility
|
||||
|
@ -338,7 +338,11 @@ public class InstallManagerService extends Service {
|
||||
Apk apkComplete = appUpdateStatusManager.getApk(downloadUrl);
|
||||
|
||||
if (apkComplete != null) {
|
||||
PackageManagerCompat.setInstaller(context, getPackageManager(), apkComplete.packageName);
|
||||
try {
|
||||
PackageManagerCompat.setInstaller(context, getPackageManager(), apkComplete.packageName);
|
||||
} catch (SecurityException e) {
|
||||
// Will happen if we fell back to DefaultInstaller for some reason.
|
||||
}
|
||||
}
|
||||
localBroadcastManager.unregisterReceiver(this);
|
||||
break;
|
||||
|
@ -31,6 +31,8 @@ import android.support.v4.content.LocalBroadcastManager;
|
||||
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;
|
||||
@ -138,6 +140,16 @@ public abstract class Installer {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
PackageManagerCompat.setInstaller(context, context.getPackageManager(), apk.packageName);
|
||||
} catch (SecurityException e) {
|
||||
Utils.debugLog(TAG, "Falling back to default installer for uninstall");
|
||||
Intent intent = new Intent(context, DefaultInstallerActivity.class);
|
||||
intent.setAction(DefaultInstallerActivity.ACTION_UNINSTALL_PACKAGE);
|
||||
intent.putExtra(Installer.EXTRA_APK, apk);
|
||||
return intent;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(context, UninstallDialogActivity.class);
|
||||
intent.putExtra(Installer.EXTRA_APK, apk);
|
||||
|
||||
|
@ -34,6 +34,7 @@ import android.util.Log;
|
||||
|
||||
import org.fdroid.fdroid.Preferences;
|
||||
import org.fdroid.fdroid.R;
|
||||
import org.fdroid.fdroid.Utils;
|
||||
import org.fdroid.fdroid.compat.PackageManagerCompat;
|
||||
import org.fdroid.fdroid.data.Apk;
|
||||
import org.fdroid.fdroid.privileged.IPrivilegedCallback;
|
||||
@ -395,10 +396,6 @@ public class PrivilegedInstaller extends Installer {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Set installer to the privileged extension
|
||||
*/
|
||||
PackageManagerCompat.setInstaller(context, context.getPackageManager(), apk.packageName);
|
||||
Intent serviceIntent = new Intent(PRIVILEGED_EXTENSION_SERVICE_INTENT);
|
||||
serviceIntent.setPackage(PRIVILEGED_EXTENSION_PACKAGE_NAME);
|
||||
context.getApplicationContext().bindService(serviceIntent, mServiceConnection,
|
||||
|
Loading…
x
Reference in New Issue
Block a user