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

Commit bf3934e0 authored by Kholoud Mohamed's avatar Kholoud Mohamed Committed by Android (Google) Code Review
Browse files

Merge "Expose PM#setKeepUninstalledPackages as TestAPI" into sc-dev

parents b28b2057 a0e1d714
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -693,6 +693,7 @@ package android.content.pm {
    method @Nullable public String getSystemTextClassifierPackageName();
    method @Nullable public String getWellbeingPackageName();
    method public void holdLock(android.os.IBinder, int);
    method @RequiresPermission(android.Manifest.permission.KEEP_UNINSTALLED_PACKAGES) public void setKeepUninstalledPackages(@NonNull java.util.List<java.lang.String>);
    field public static final String FEATURE_ADOPTABLE_STORAGE = "android.software.adoptable_storage";
    field public static final String FEATURE_FILE_BASED_ENCRYPTION = "android.software.file_based_encryption";
    field public static final String FEATURE_HDMI_CEC = "android.hardware.hdmi.cec";
+2 −0
Original line number Diff line number Diff line
@@ -808,4 +808,6 @@ interface IPackageManager {

    PackageManager.Property getProperty(String propertyName, String packageName, String className);
    ParceledListSlice queryProperty(String propertyName, int componentType);

    void setKeepUninstalledPackages(in List<String> packageList);
}
+17 −1
Original line number Diff line number Diff line
@@ -47,8 +47,8 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentSender;
import android.content.pm.verify.domain.DomainVerificationManager;
import android.content.pm.dex.ArtManager;
import android.content.pm.verify.domain.DomainVerificationManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
@@ -9282,4 +9282,20 @@ public abstract class PackageManager {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Set a list of apps to keep around as APKs even if no user has currently installed it.
     * @param packageList List of package names to keep cached.
     *
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.KEEP_UNINSTALLED_PACKAGES)
    @TestApi
    public void setKeepUninstalledPackages(@NonNull List<String> packageList) {
        try {
            ActivityThread.getPackageManager().setKeepUninstalledPackages(packageList);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
}
+38 −24
Original line number Diff line number Diff line
@@ -26211,30 +26211,7 @@ public class PackageManagerService extends IPackageManager.Stub
        @Override
        public void setKeepUninstalledPackages(final List<String> packageList) {
            Preconditions.checkNotNull(packageList);
            List<String> removedFromList = null;
            synchronized (mLock) {
                if (mKeepUninstalledPackages != null) {
                    final int packagesCount = mKeepUninstalledPackages.size();
                    for (int i = 0; i < packagesCount; i++) {
                        String oldPackage = mKeepUninstalledPackages.get(i);
                        if (packageList != null && packageList.contains(oldPackage)) {
                            continue;
                        }
                        if (removedFromList == null) {
                            removedFromList = new ArrayList<>();
                        }
                        removedFromList.add(oldPackage);
                    }
                }
                mKeepUninstalledPackages = new ArrayList<>(packageList);
                if (removedFromList != null) {
                    final int removedCount = removedFromList.size();
                    for (int i = 0; i < removedCount; i++) {
                        deletePackageIfUnusedLPr(removedFromList.get(i));
                    }
                }
            }
            PackageManagerService.this.setKeepUninstalledPackagesInternal(packageList);
        }
        @Override
@@ -27732,6 +27709,43 @@ public class PackageManagerService extends IPackageManager.Stub
    public DomainVerificationService.Connection getDomainVerificationConnection() {
        return mDomainVerificationConnection;
    }
    @Override
    public void setKeepUninstalledPackages(List<String> packageList) {
        mContext.enforceCallingPermission(
                Manifest.permission.KEEP_UNINSTALLED_PACKAGES,
                "setKeepUninstalledPackages requires KEEP_UNINSTALLED_PACKAGES permission");
        Objects.requireNonNull(packageList);
        setKeepUninstalledPackagesInternal(packageList);
    }
    private void setKeepUninstalledPackagesInternal(List<String> packageList) {
        Preconditions.checkNotNull(packageList);
        List<String> removedFromList = null;
        synchronized (mLock) {
            if (mKeepUninstalledPackages != null) {
                final int packagesCount = mKeepUninstalledPackages.size();
                for (int i = 0; i < packagesCount; i++) {
                    String oldPackage = mKeepUninstalledPackages.get(i);
                    if (packageList != null && packageList.contains(oldPackage)) {
                        continue;
                    }
                    if (removedFromList == null) {
                        removedFromList = new ArrayList<>();
                    }
                    removedFromList.add(oldPackage);
                }
            }
            mKeepUninstalledPackages = new ArrayList<>(packageList);
            if (removedFromList != null) {
                final int removedCount = removedFromList.size();
                for (int i = 0; i < removedCount; i++) {
                    deletePackageIfUnusedLPr(removedFromList.get(i));
                }
            }
        }
    }
}
interface PackageSender {