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

Commit 0ae5257f authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge changes I9be69af5,Ib85ee393 into rvc-dev am: faf1d06d am: f9415dcb

Change-Id: I7b2ef09e46c7e5af46b326e4749fd4aa38a5882f
parents 15b526a7 f9415dcb
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -983,4 +983,9 @@ public abstract class PackageManagerInternal {
     * Returns if a package name is a valid system package.
     */
    public abstract boolean isSystemPackage(@NonNull String packageName);

    /**
     * Unblocks uninstall for all packages for the user.
     */
    public abstract void clearBlockUninstallForUser(@UserIdInt int userId);
}
+8 −0
Original line number Diff line number Diff line
@@ -24721,6 +24721,14 @@ public class PackageManagerService extends IPackageManager.Stub
            return packageName.equals(
                    PackageManagerService.this.ensureSystemPackageName(packageName));
        }
        @Override
        public void clearBlockUninstallForUser(@UserIdInt int userId) {
            synchronized (mLock) {
                mSettings.clearBlockUninstallLPw(userId);
                mSettings.writePackageRestrictionsLPr(userId);
            }
        }
    }
    @GuardedBy("mLock")
+4 −0
Original line number Diff line number Diff line
@@ -1833,6 +1833,10 @@ public final class Settings {
        }
    }

    void clearBlockUninstallLPw(int userId) {
        mBlockUninstallPackages.remove(userId);
    }

    boolean getBlockUninstallLPr(int userId, String packageName) {
        ArraySet<String> packages = mBlockUninstallPackages.get(userId);
        if (packages == null) {
+16 −5
Original line number Diff line number Diff line
@@ -3153,13 +3153,17 @@ public class UserManagerService extends IUserManager.Stub {

    /**
     * Removes the app restrictions file for a specific package and user id, if it exists.
     *
     * @return whether there were any restrictions.
     */
    private static void cleanAppRestrictionsForPackageLAr(String pkg, @UserIdInt int userId) {
        File dir = Environment.getUserSystemDirectory(userId);
        File resFile = new File(dir, packageToRestrictionsFileName(pkg));
    private static boolean cleanAppRestrictionsForPackageLAr(String pkg, @UserIdInt int userId) {
        final File dir = Environment.getUserSystemDirectory(userId);
        final File resFile = new File(dir, packageToRestrictionsFileName(pkg));
        if (resFile.exists()) {
            resFile.delete();
            return true;
        }
        return false;
    }

    /**
@@ -4003,17 +4007,24 @@ public class UserManagerService extends IUserManager.Stub {
        if (restrictions != null) {
            restrictions.setDefusable(true);
        }
        final boolean changed;
        synchronized (mAppRestrictionsLock) {
            if (restrictions == null || restrictions.isEmpty()) {
                cleanAppRestrictionsForPackageLAr(packageName, userId);
                changed = cleanAppRestrictionsForPackageLAr(packageName, userId);
            } else {
                // Write the restrictions to XML
                writeApplicationRestrictionsLAr(packageName, restrictions, userId);
                // TODO(b/154323615): avoid unnecessary broadcast when there is no change.
                changed = true;
            }
        }

        if (!changed) {
            return;
        }

        // Notify package of changes via an intent - only sent to explicitly registered receivers.
        Intent changeIntent = new Intent(Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED);
        final Intent changeIntent = new Intent(Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED);
        changeIntent.setPackage(packageName);
        changeIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
        mContext.sendBroadcastAsUser(changeIntent, UserHandle.of(userId));
+16 −1
Original line number Diff line number Diff line
@@ -2703,7 +2703,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        final ComponentName doAdminReceiver = doAdmin.info.getComponent();
        clearDeviceOwnerLocked(doAdmin, doUserId);
        Slog.i(LOG_TAG, "Removing admin artifacts...");
        // TODO(b/149075700): Clean up application restrictions in UserManager.
        removeAdminArtifacts(doAdminReceiver, doUserId);
        Slog.i(LOG_TAG, "Migration complete.");
@@ -8766,6 +8765,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        saveSettingsLocked(UserHandle.USER_SYSTEM);
        clearUserPoliciesLocked(userId);
        clearOverrideApnUnchecked();
        clearApplicationRestrictions(userId);
        mInjector.getPackageManagerInternal().clearBlockUninstallForUser(userId);
        mOwners.clearDeviceOwner();
        mOwners.writeDeviceOwner();
@@ -8779,6 +8780,19 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        toggleBackupServiceActive(UserHandle.USER_SYSTEM, true);
    }
    private void clearApplicationRestrictions(int userId) {
        // Changing app restrictions involves disk IO, offload it to the background thread.
        mBackgroundHandler.post(() -> {
            final List<PackageInfo> installedPackageInfos = mInjector.getPackageManager(userId)
                    .getInstalledPackages(MATCH_DIRECT_BOOT_AWARE | MATCH_DIRECT_BOOT_UNAWARE);
            final UserHandle userHandle = UserHandle.of(userId);
            for (final PackageInfo packageInfo : installedPackageInfos) {
                mInjector.getUserManager().setApplicationRestrictions(
                        packageInfo.packageName, null /* restrictions */, userHandle);
            }
        });
    }
    @Override
    public boolean setProfileOwner(ComponentName who, String ownerName, int userHandle) {
        if (!mHasFeature) {
@@ -8898,6 +8912,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        policyData.mOwnerInstalledCaCerts.clear();
        saveSettingsLocked(userId);
        clearUserPoliciesLocked(userId);
        clearApplicationRestrictions(userId);
        mOwners.removeProfileOwner(userId);
        mOwners.writeProfileOwner(userId);
        deleteTransferOwnershipBundleLocked(userId);
Loading