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

Commit 9798973c authored by Pavel Grafov's avatar Pavel Grafov
Browse files

Clear uninstall block when removing DO.

Another way was to clear it using existing APIs for each package
but each call would cause Package Manager to re-serialize the
package-restrictions.xml, so I added a separate API to do it in
one go.

Bug: 149075700
Test: manual, set TestDPC as a DO, block uninstall, remove DO.
Test: manual, set TestDPC in COMP, block uninstall, migrate to COPE.
Change-Id: I9be69af5d7ae9e0ddda087d3e01e35f3429f25f4
parent ae92bace
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -977,4 +977,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
@@ -24651,6 +24651,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
@@ -1829,6 +1829,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) {
+1 −0
Original line number Diff line number Diff line
@@ -8766,6 +8766,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        clearUserPoliciesLocked(userId);
        clearOverrideApnUnchecked();
        clearApplicationRestrictions(userId);
        mInjector.getPackageManagerInternal().clearBlockUninstallForUser(userId);
        mOwners.clearDeviceOwner();
        mOwners.writeDeviceOwner();