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

Commit 44044719 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Stop writing approved pkgs to Settings"

parents 4103bfdf cf389e73
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -272,6 +272,7 @@ package android.app {
    method public void allowAssistantAdjustment(String);
    method public void disallowAssistantAdjustment(String);
    method public android.content.ComponentName getEffectsSuppressor();
    method public boolean isNotificationPolicyAccessGrantedForPackage(@NonNull String);
    method public boolean matchesCallFilter(android.os.Bundle);
    method @RequiresPermission(android.Manifest.permission.MANAGE_NOTIFICATION_LISTENERS) public void setNotificationListenerAccessGranted(@NonNull android.content.ComponentName, boolean, boolean);
    method public void updateNotificationChannel(@NonNull String, int, @NonNull android.app.NotificationChannel);
+2 −1
Original line number Diff line number Diff line
@@ -1501,7 +1501,8 @@ public class NotificationManager {
    }

    /** @hide */
    public boolean isNotificationPolicyAccessGrantedForPackage(String pkg) {
    @TestApi
    public boolean isNotificationPolicyAccessGrantedForPackage(@NonNull String pkg) {
        INotificationManager service = getService();
        try {
            return service.isNotificationPolicyAccessGrantedForPackage(pkg);
+9 −0
Original line number Diff line number Diff line
@@ -4777,6 +4777,15 @@ public class SettingsProvider extends ContentProvider {
                    currentVersion = 195;
                }

                if (currentVersion == 195) {
                    // Version 195: delete obsolete manged services settings
                    getSecureSettingsLocked(userId).deleteSettingLocked(
                            Secure.ENABLED_NOTIFICATION_ASSISTANT);
                    getSecureSettingsLocked(userId).deleteSettingLocked(
                            Secure.ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES);
                    currentVersion = 196;
                }

                // vXXX: Add new settings above this point.

                if (currentVersion != newVersion) {
+1 −1
Original line number Diff line number Diff line
@@ -123,7 +123,7 @@ public class ConditionProviders extends ManagedServices {
        final Config c = new Config();
        c.caption = "condition provider";
        c.serviceInterface = ConditionProviderService.SERVICE_INTERFACE;
        c.secureSettingName = Settings.Secure.ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES;
        c.secureSettingName = null;
        c.xmlTag = TAG_ENABLED_DND_APPS;
        c.secondarySettingName = Settings.Secure.ENABLED_NOTIFICATION_LISTENERS;
        c.bindPermission = android.Manifest.permission.BIND_CONDITION_PROVIDER_SERVICE;
+37 −26
Original line number Diff line number Diff line
@@ -437,9 +437,15 @@ abstract public class ManagedServices {
                        }
                    }
                }
                if (shouldReflectToSettings()) {
                    Settings.Secure.putStringForUser(
                            mContext.getContentResolver(), element, value, userId);
                loadAllowedComponentsFromSettings();
                }

                for (UserInfo user : mUm.getUsers()) {
                    addApprovedList(value, user.id, mConfig.secureSettingName.equals(element));
                }
                Slog.d(TAG, "Done loading approved values from settings");
                rebindServices(false, userId);
            }
        }
@@ -498,11 +504,14 @@ abstract public class ManagedServices {
                            out.endTag(null, TAG_MANAGED_SERVICES);

                            if (!forBackup && isPrimary) {
                                // Also write values to settings, for observers who haven't migrated yet
                                if (shouldReflectToSettings()) {
                                    // Also write values to settings, for observers who haven't
                                    // migrated yet
                                    Settings.Secure.putStringForUser(mContext.getContentResolver(),
                                            getConfig().secureSettingName, allowedItems,
                                            approvedUserId);
                                }
                            }

                        }
                    }
@@ -515,6 +524,13 @@ abstract public class ManagedServices {
        out.endTag(null, getConfig().xmlTag);
    }

    /**
     * Returns whether the approved list of services should also be written to the Settings db
     */
    protected boolean shouldReflectToSettings() {
        return false;
    }

    /**
     * Writes extra xml attributes to {@link #TAG_MANAGED_SERVICES} tag.
     */
@@ -530,8 +546,20 @@ abstract public class ManagedServices {
     */
    protected void readExtraTag(String tag, TypedXmlPullParser parser) throws IOException {}

    protected void migrateToXml() {
        loadAllowedComponentsFromSettings();
    protected final void migrateToXml() {
        for (UserInfo user : mUm.getUsers()) {
            final ContentResolver cr = mContext.getContentResolver();
            addApprovedList(Settings.Secure.getStringForUser(
                    cr,
                    getConfig().secureSettingName,
                    user.id), user.id, true);
            if (!TextUtils.isEmpty(getConfig().secondarySettingName)) {
                addApprovedList(Settings.Secure.getStringForUser(
                        cr,
                        getConfig().secondarySettingName,
                        user.id), user.id, false);
            }
        }
    }

    void readDefaults(TypedXmlPullParser parser) {
@@ -638,23 +666,6 @@ abstract public class ManagedServices {

    protected abstract String getRequiredPermission();

    private void loadAllowedComponentsFromSettings() {
        for (UserInfo user : mUm.getUsers()) {
            final ContentResolver cr = mContext.getContentResolver();
            addApprovedList(Settings.Secure.getStringForUser(
                    cr,
                    getConfig().secureSettingName,
                    user.id), user.id, true);
            if (!TextUtils.isEmpty(getConfig().secondarySettingName)) {
                addApprovedList(Settings.Secure.getStringForUser(
                        cr,
                        getConfig().secondarySettingName,
                        user.id), user.id, false);
            }
        }
        Slog.d(TAG, "Done loading approved values from settings");
    }

    protected void addApprovedList(String approved, int userId, boolean isPrimary) {
        addApprovedList(approved, userId, isPrimary, approved);
    }
Loading