Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 855b5df0 authored by Patrick's avatar Patrick
Browse files

Early exit if we don't have a package on record

In NMR1, the ability to silently uninstall orphaned packages was added.
This code path added a new throw from the uninstall flow if the package
didn't exist and resulted in uninstall of a non-existant package
printing a stack trace instead of DELETE_FAILED_INTERNAL_ERROR as it did
in prior versions. This change simply checks for the existance of the
package and fails early when no such package exist. Also moves all calls
to the observer to a post to the handler.

Change-Id: I89d1d5002ef2f37b65a6910fb366ff4a68070e6d
Fixes: 33230110
Test: unisntalled missing package
parent 304fcaf7
Loading
Loading
Loading
Loading
+66 −60
Original line number Diff line number Diff line
@@ -17887,6 +17887,7 @@ public class PackageManagerService extends IPackageManager.Stub
        final int uid = Binder.getCallingUid();
        if (!isOrphaned(internalPackageName)
                && !isCallerAllowedToSilentlyUninstall(uid, internalPackageName)) {
            mHandler.post(() -> {
                try {
                    final Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE);
                    intent.setData(Uri.fromParts(PACKAGE_SCHEME, packageName, null));
@@ -17894,6 +17895,7 @@ public class PackageManagerService extends IPackageManager.Stub
                    observer.onUserActionRequired(intent);
                } catch (RemoteException re) {
                }
            });
            return;
        }
        final boolean deleteAllUsers = (deleteFlags & PackageManager.DELETE_ALL_USERS) != 0;
@@ -17905,20 +17907,24 @@ public class PackageManagerService extends IPackageManager.Stub
        }
        if (isUserRestricted(userId, UserManager.DISALLOW_UNINSTALL_APPS)) {
            mHandler.post(() -> {
                try {
                    observer.onPackageDeleted(packageName,
                            PackageManager.DELETE_FAILED_USER_RESTRICTED, null);
                } catch (RemoteException re) {
                }
            });
            return;
        }
        if (!deleteAllUsers && getBlockUninstallForUser(internalPackageName, userId)) {
            mHandler.post(() -> {
                try {
                    observer.onPackageDeleted(packageName,
                            PackageManager.DELETE_FAILED_OWNER_BLOCKED, null);
                } catch (RemoteException re) {
                }
            });
            return;
        }
@@ -17929,9 +17935,7 @@ public class PackageManagerService extends IPackageManager.Stub
                    ? "VERSION_CODE_HIGHEST" : versionCode));
        }
        // Queue up an async operation since the package deletion may take a little while.
        mHandler.post(new Runnable() {
            public void run() {
                mHandler.removeCallbacks(this);
        mHandler.post(() -> {
            int returnCode;
            final PackageSetting ps = mSettings.mPackages.get(internalPackageName);
            boolean doDeletePackage = true;
@@ -17955,12 +17959,12 @@ public class PackageManagerService extends IPackageManager.Stub
                    } else {
                        // Otherwise uninstall individually for users with blockUninstalls=false
                        final int userFlags = deleteFlags & ~PackageManager.DELETE_ALL_USERS;
                            for (int userId : users) {
                                if (!ArrayUtils.contains(blockUninstallUserIds, userId)) {
                        for (int userId1 : users) {
                            if (!ArrayUtils.contains(blockUninstallUserIds, userId1)) {
                                returnCode = deletePackageX(internalPackageName, versionCode,
                                            userId, userFlags);
                                        userId1, userFlags);
                                if (returnCode != PackageManager.DELETE_SUCCEEDED) {
                                        Slog.w(TAG, "Package delete failed for user " + userId
                                    Slog.w(TAG, "Package delete failed for user " + userId1
                                            + ", returnCode " + returnCode);
                                }
                            }
@@ -17978,7 +17982,6 @@ public class PackageManagerService extends IPackageManager.Stub
            } catch (RemoteException e) {
                Log.i(TAG, "Observer no longer exists.");
            } //end catch
            } //end run
        });
    }
@@ -21064,6 +21067,9 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
    public boolean isOrphaned(String packageName) {
        // reader
        synchronized (mPackages) {
            if (!mPackages.containsKey(packageName)) {
                return false;
            }
            return mSettings.isOrphaned(packageName);
        }
    }