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

Commit 0dc591b4 authored by Robin Lee's avatar Robin Lee
Browse files

Disallow suspending the default dialer

This is the only case that still had to be protected by priv-app, so
that check is removed at the same time.

Bug: 27635033
Change-Id: Ifd5e59ab56eb45f0651cb25882ead920c758ae51
parent 7544ac22
Loading
Loading
Loading
Loading
+15 −14
Original line number Diff line number Diff line
@@ -11440,10 +11440,10 @@ public class PackageManagerService extends IPackageManager.Stub {
        // List of package names for whom the suspended state is not set as requested in this
        // method.
        List<String> unactionedPackages = new ArrayList<>(packageNames.length);
        for (int i = 0; i < packageNames.length; i++) {
            String packageName = packageNames[i];
        long callingId = Binder.clearCallingIdentity();
        try {
            for (int i = 0; i < packageNames.length; i++) {
                String packageName = packageNames[i];
                boolean changed = false;
                final int appId;
                synchronized (mPackages) {
@@ -11471,10 +11471,10 @@ public class PackageManagerService extends IPackageManager.Stub {
                    killApplication(packageName, UserHandle.getUid(userId, appId),
                            "suspending package");
                }
            }
        } finally {
            Binder.restoreCallingIdentity(callingId);
        }
        }
        if (!changedPackages.isEmpty()) {
            sendPackagesSuspendedForUser(changedPackages.toArray(
@@ -11498,11 +11498,6 @@ public class PackageManagerService extends IPackageManager.Stub {
        }
    }
    /**
     * TODO: cache and disallow blocking the active dialer.
     *
     * @see also DefaultPermissionGrantPolicy#grantDefaultSystemHandlerPermissions
     */
    private boolean canSuspendPackageForUserLocked(String packageName, int userId) {
        if (isPackageDeviceAdmin(packageName, userId)) {
            Slog.w(TAG, "Cannot suspend/un-suspend package \"" + packageName
@@ -11529,10 +11524,9 @@ public class PackageManagerService extends IPackageManager.Stub {
            return false;
        }
        final PackageParser.Package pkg = mPackages.get(packageName);
        if (pkg != null && isPrivilegedApp(pkg)) {
        if (packageName.equals(getDefaultDialerPackageName(userId))) {
            Slog.w(TAG, "Cannot suspend/un-suspend package \"" + packageName
                    + "\": is a privileged app");
                    + "\": is the default dialer");
            return false;
        }
@@ -11551,6 +11545,12 @@ public class PackageManagerService extends IPackageManager.Stub {
        return resolveInfo == null ? null : resolveInfo.activityInfo.packageName;
    }
    private String getDefaultDialerPackageName(int userId) {
        synchronized (mPackages) {
            return mSettings.getDefaultDialerPackageNameLPw(userId);
        }
    }
    @Override
    public void verifyPendingInstall(int id, int verificationCode) throws RemoteException {
        mContext.enforceCallingOrSelfPermission(
@@ -20247,6 +20247,7 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
        @Override
        public void grantDefaultPermissionsToDefaultDialerApp(String packageName, int userId) {
            synchronized (mPackages) {
                mSettings.setDefaultDialerPackageNameLPw(packageName, userId);
                mDefaultPermissionPolicy.grantDefaultPermissionsToDefaultDialerAppLPr(
                        packageName, userId);
            }
+29 −3
Original line number Diff line number Diff line
@@ -189,6 +189,7 @@ final class Settings {
    private static final String TAG_ALL_INTENT_FILTER_VERIFICATION =
            "all-intent-filter-verifications";
    private static final String TAG_DEFAULT_BROWSER = "default-browser";
    private static final String TAG_DEFAULT_DIALER = "default-dialer";
    private static final String TAG_VERSION = "version";
    private static final String TAG_N_WORK = "n-work";

@@ -376,6 +377,9 @@ final class Settings {
    // For every user, it is used to find the package name of the default Browser App.
    final SparseArray<String> mDefaultBrowserApp = new SparseArray<String>();

    // For every user, a record of the package name of the default Dialer App.
    final SparseArray<String> mDefaultDialerApp = new SparseArray<String>();

    // App-link priority tracking, per-user
    final SparseIntArray mNextAppLinkGeneration = new SparseIntArray();

@@ -1356,6 +1360,19 @@ final class Settings {
        return (userId == UserHandle.USER_ALL) ? null : mDefaultBrowserApp.get(userId);
    }

    boolean setDefaultDialerPackageNameLPw(String packageName, int userId) {
        if (userId == UserHandle.USER_ALL) {
            return false;
        }
        mDefaultDialerApp.put(userId, packageName);
        writePackageRestrictionsLPr(userId);
        return true;
    }

    String getDefaultDialerPackageNameLPw(int userId) {
        return (userId == UserHandle.USER_ALL) ? null : mDefaultDialerApp.get(userId);
    }

    private File getUserPackagesStateFile(int userId) {
        // TODO: Implement a cleaner solution when adding tests.
        // This instead of Environment.getUserSystemDirectory(userId) to support testing.
@@ -1545,6 +1562,9 @@ final class Settings {
            if (tagName.equals(TAG_DEFAULT_BROWSER)) {
                String packageName = parser.getAttributeValue(null, ATTR_PACKAGE_NAME);
                mDefaultBrowserApp.put(userId, packageName);
            } else if (tagName.equals(TAG_DEFAULT_DIALER)) {
                String packageName = parser.getAttributeValue(null, ATTR_PACKAGE_NAME);
                mDefaultDialerApp.put(userId, packageName);
            } else {
                String msg = "Unknown element under " +  TAG_DEFAULT_APPS + ": " +
                        parser.getName();
@@ -1892,12 +1912,18 @@ final class Settings {
    void writeDefaultAppsLPr(XmlSerializer serializer, int userId)
            throws IllegalArgumentException, IllegalStateException, IOException {
        serializer.startTag(null, TAG_DEFAULT_APPS);
        String packageName = mDefaultBrowserApp.get(userId);
        if (!TextUtils.isEmpty(packageName)) {
        String defaultBrowser = mDefaultBrowserApp.get(userId);
        if (!TextUtils.isEmpty(defaultBrowser)) {
            serializer.startTag(null, TAG_DEFAULT_BROWSER);
            serializer.attribute(null, ATTR_PACKAGE_NAME, packageName);
            serializer.attribute(null, ATTR_PACKAGE_NAME, defaultBrowser);
            serializer.endTag(null, TAG_DEFAULT_BROWSER);
        }
        String defaultDialer = mDefaultDialerApp.get(userId);
        if (!TextUtils.isEmpty(defaultDialer)) {
            serializer.startTag(null, TAG_DEFAULT_DIALER);
            serializer.attribute(null, ATTR_PACKAGE_NAME, defaultDialer);
            serializer.endTag(null, TAG_DEFAULT_DIALER);
        }
        serializer.endTag(null, TAG_DEFAULT_APPS);
    }