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:
Chirayu Desai 2017-04-18 23:49:16 +05:30
parent db4aa3b519
commit 432f45254b
4 changed files with 20 additions and 5 deletions

View File

@ -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

View File

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

View File

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

View File

@ -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,