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

Commit 9496df19 authored by Andrei Stingaceanu's avatar Andrei Stingaceanu
Browse files

Suspend packages - decline suspending the active launcher

Bug: 26953019
Bug: 26683041
Bug: 22776761
Change-Id: I7b65abff03aa32f5db8dce68364467a588facdac
parent 5ae4e73e
Loading
Loading
Loading
Loading
+31 −4
Original line number Diff line number Diff line
@@ -10678,10 +10678,7 @@ public class PackageManagerService extends IPackageManager.Stub {
        enforceCrossUserPermission(Binder.getCallingUid(), userId, true, true,
                "setPackageSuspended for user " + userId);
        // TODO: investigate and add more restrictions for suspending crucial packages.
        if (isPackageDeviceAdmin(packageName, userId)) {
            Slog.w(TAG, "Not suspending/un-suspending package \"" + packageName
                    + "\": has active device admin");
        if (!canSuspendPackageForUser(packageName, userId)) {
            return false;
        }
@@ -10726,6 +10723,36 @@ public class PackageManagerService extends IPackageManager.Stub {
        }
    }
    // TODO: investigate and add more restrictions for suspending crucial packages.
    private boolean canSuspendPackageForUser(String packageName, int userId) {
        if (isPackageDeviceAdmin(packageName, userId)) {
            Slog.w(TAG, "Not suspending/un-suspending package \"" + packageName
                    + "\": has active device admin");
            return false;
        }
        String activeLauncherPackageName = getActiveLauncherPackageName(userId);
        if (packageName.equals(activeLauncherPackageName)) {
            Slog.w(TAG, "Not suspending/un-suspending package \"" + packageName
                    + "\" because it is set as the active launcher");
            return false;
        }
        return true;
    }
    private String getActiveLauncherPackageName(int userId) {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        ResolveInfo resolveInfo = resolveIntent(
                intent,
                intent.resolveTypeIfNeeded(mContext.getContentResolver()),
                PackageManager.MATCH_DEFAULT_ONLY,
                userId);
        return resolveInfo == null ? null : resolveInfo.activityInfo.packageName;
    }
    @Override
    public void verifyPendingInstall(int id, int verificationCode) throws RemoteException {
        mContext.enforceCallingOrSelfPermission(