[core] No need to uninstall if upgrade manager under the same sign

This commit is contained in:
LoveSy 2021-03-07 03:18:12 +08:00 committed by tehcneko
parent 74f4404d7a
commit 80abe3dc64
1 changed files with 11 additions and 6 deletions

View File

@ -218,15 +218,19 @@ public class PackageService {
} }
} }
public static void uninstallPackage(VersionedPackage versionedPackage) throws RemoteException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { public static boolean uninstallPackage(VersionedPackage versionedPackage) throws RemoteException, InterruptedException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
final boolean[] result = {false};
pm.getPackageInstaller().uninstallExistingPackage(versionedPackage, "com.android.shell", new IntentSenderAdaptor() { pm.getPackageInstaller().uninstallExistingPackage(versionedPackage, "com.android.shell", new IntentSenderAdaptor() {
@Override @Override
public void send(Intent intent) { public void send(Intent intent) {
int status = intent.getIntExtra(PackageInstaller.EXTRA_STATUS, PackageInstaller.STATUS_FAILURE);
result[0] = status == PackageInstaller.STATUS_SUCCESS;
latch.countDown(); latch.countDown();
} }
}.getIntentSender(), 0); }.getIntentSender(), 0);
latch.await(); latch.await();
return result[0];
} }
public static synchronized boolean installManagerIfAbsent(String packageName, File apkFile) { public static synchronized boolean installManagerIfAbsent(String packageName, File apkFile) {
@ -235,11 +239,12 @@ public class PackageService {
try { try {
PackageInfo pkgInfo = pm.getPackageInfo(packageName, 0, 0); PackageInfo pkgInfo = pm.getPackageInfo(packageName, 0, 0);
if (pkgInfo != null && pkgInfo.versionName != null && pkgInfo.versionName.equals(BuildConfig.VERSION_NAME) && pkgInfo.applicationInfo != null && InstallerVerifier.verifyInstallerSignature(pkgInfo.applicationInfo)) if (pkgInfo != null && pkgInfo.versionName != null && pkgInfo.applicationInfo != null) {
return false; boolean versionMatch = pkgInfo.versionName.equals(BuildConfig.VERSION_NAME);
// manager is not installed or version not matched, install stub boolean signatureMatch = InstallerVerifier.verifyInstallerSignature(pkgInfo.applicationInfo);
if (pkgInfo != null) { if (versionMatch && signatureMatch) return false;
uninstallPackage(new VersionedPackage(pkgInfo.packageName, pkgInfo.versionCode)); if (!signatureMatch || pkgInfo.versionCode > BuildConfig.VERSION_CODE)
uninstallPackage(new VersionedPackage(pkgInfo.packageName, pkgInfo.versionCode));
} }
IPackageInstaller installerService = pm.getPackageInstaller(); IPackageInstaller installerService = pm.getPackageInstaller();
String installerPackageName = "com.android.shell"; String installerPackageName = "com.android.shell";