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

Commit b9913006 authored by Andrei Stingaceanu's avatar Andrei Stingaceanu Committed by android-build-merger
Browse files

Suspend packages - decline suspending the active launcher am: 9496df19

am: e1fdf4bf

* commit 'e1fdf4bf':
  Suspend packages - decline suspending the active launcher
parents 4d9c9913 e1fdf4bf
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(