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

Commit 523c415c authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Prevent the disabling of specified apps" into main

parents edcfed16 12b06820
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -52,4 +52,9 @@ interface ISystemConfig {
     * @see SystemConfigManager#getDefaultVrComponents
     */
    List<ComponentName> getDefaultVrComponents();

    /**
     * @see SystemConfigManager#getPreventUserDisablePackages
     */
    List<String> getPreventUserDisablePackages();
}
+14 −0
Original line number Diff line number Diff line
@@ -161,4 +161,18 @@ public class SystemConfigManager {
        }
        return Collections.emptyList();
    }

    /**
     * Return the packages that are prevented from being disabled, where if
     * disabled it would result in a non-functioning system or similar.
     * @hide
     */
    @NonNull
    public List<String> getPreventUserDisablePackages() {
        try {
            return mInterface.getPreventUserDisablePackages();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
}
+19 −0
Original line number Diff line number Diff line
@@ -316,6 +316,11 @@ public class SystemConfig {
    private final ArraySet<String> mBugreportWhitelistedPackages = new ArraySet<>();
    private final ArraySet<String> mAppDataIsolationWhitelistedApps = new ArraySet<>();

    // These packages will be set as 'prevent disable', where they are no longer possible
    // for the end user to disable via settings. This flag should only be used for packages
    // which meet the 'force or keep enabled apps' policy.
    private final ArrayList<String> mPreventUserDisablePackages = new ArrayList<>();

    // Map of packagesNames to userTypes. Stored temporarily until cleared by UserManagerService().
    private ArrayMap<String, Set<String>> mPackageToUserTypeWhitelist = new ArrayMap<>();
    private ArrayMap<String, Set<String>> mPackageToUserTypeBlacklist = new ArrayMap<>();
@@ -501,6 +506,10 @@ public class SystemConfig {
        return mAppDataIsolationWhitelistedApps;
    }

    public @NonNull ArrayList<String> getPreventUserDisablePackages() {
        return mPreventUserDisablePackages;
    }

    /**
     * Gets map of packagesNames to userTypes, dictating on which user types each package should be
     * initially installed, and then removes this map from SystemConfig.
@@ -1303,6 +1312,16 @@ public class SystemConfig {
                        }
                        XmlUtils.skipCurrentTag(parser);
                    } break;
                    case "prevent-disable": {
                        String pkgname = parser.getAttributeValue(null, "package");
                        if (pkgname == null) {
                            Slog.w(TAG, "<" + name + "> without package in " + permFile
                                    + " at " + parser.getPositionDescription());
                        } else {
                            mPreventUserDisablePackages.add(pkgname);
                        }
                        XmlUtils.skipCurrentTag(parser);
                    } break;
                    case "install-in-user-type": {
                        // NB: We allow any directory permission to declare install-in-user-type.
                        readInstallInUserType(parser,
+11 −0
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import static java.util.stream.Collectors.toMap;
import android.Manifest;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManagerInternal;
import android.os.Binder;
import android.os.ISystemConfig;
import android.util.ArrayMap;
import android.util.ArraySet;
@@ -108,6 +110,15 @@ public class SystemConfigService extends SystemService {
                    "Caller must hold " + Manifest.permission.QUERY_ALL_PACKAGES);
            return new ArrayList<>(SystemConfig.getInstance().getDefaultVrComponents());
        }

        @Override
        public List<String> getPreventUserDisablePackages() {
            PackageManagerInternal pmi = LocalServices.getService(PackageManagerInternal.class);
            return SystemConfig.getInstance().getPreventUserDisablePackages().stream()
                    .filter(preventUserDisablePackage ->
                            pmi.canQueryPackage(Binder.getCallingUid(), preventUserDisablePackage))
                    .collect(toList());
        }
    };

    public SystemConfigService(Context context) {