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

Commit a024c105 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Migrate to using fixed permissions

When deciding which app/group/channel level fields are editable. If
an app has a fixed notification permission, no importance type fields
(including blocking, importance, minimizing, popping on screen, or
prioirty conversions) can be edited.

Test: Robotests
Bug: 194833441
Change-Id: Idc198ea05cd2ab6e43387ae4e8290f446ccfa0c6
parent e3f34ef7
Loading
Loading
Loading
Loading
+25 −8
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_CACHED;
import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_DYNAMIC;
import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED_BY_ANY_LAUNCHER;
import static android.os.UserHandle.USER_SYSTEM;

import android.app.INotificationManager;
import android.app.NotificationChannel;
@@ -44,6 +45,7 @@ import android.graphics.drawable.Drawable;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.provider.Settings;
import android.service.notification.ConversationChannelWrapper;
import android.service.notification.NotificationListenerFilter;
import android.text.format.DateUtils;
@@ -112,6 +114,15 @@ public class NotificationBackend {

    void recordCanBeBlocked(Context context, PackageManager pm, RoleManager rm, PackageInfo app,
            AppRow row) {
        if (Settings.Secure.getIntForUser(context.getContentResolver(),
                Settings.Secure.NOTIFICATION_PERMISSION_ENABLED, 0, USER_SYSTEM) != 0) {
            try {
                row.systemApp = row.lockedImportance =
                        sINM.isPermissionFixed(app.packageName, row.userId);
            } catch (RemoteException e) {
                Log.w(TAG, "Error calling NMS", e);
            }
        } else {
            row.systemApp = Utils.isSystemPackage(context.getResources(), pm, app);
            List<String> roles = rm.getHeldRolesFromController(app.packageName);
            if (roles.contains(RoleManager.ROLE_DIALER)
@@ -122,6 +133,7 @@ public class NotificationBackend {
                    com.android.internal.R.array.config_nonBlockableNotificationPackages);
            markAppRowWithBlockables(nonBlockablePkgs, row, app.packageName);
        }
    }

    @VisibleForTesting static void markAppRowWithBlockables(String[] nonBlockablePkgs, AppRow row,
            String packageName) {
@@ -653,6 +665,11 @@ public class NotificationBackend {
        return false;
    }

    @VisibleForTesting
    void setNm(INotificationManager inm) {
        sINM = inm;
    }

    /**
     * NotificationsSentState contains how often an app sends notifications and how recently it sent
     * one.
+2 −3
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ public class BlockPreferenceController extends NotificationPreferenceController
            }
            bar.setDisabledByAdmin(mAdmin);

            if (mChannel != null && !isChannelBlockable()) {
            if (mChannel != null && (!isChannelBlockable() || !isChannelConfigurable(mChannel))) {
                bar.setSwitchBarEnabled(false);
            }

@@ -88,8 +88,7 @@ public class BlockPreferenceController extends NotificationPreferenceController
                bar.setSwitchBarEnabled(false);
            }

            if (mChannel == null && mAppRow.systemApp
                    && (!mAppRow.banned || mAppRow.lockedImportance)) {
            if (mChannel == null && !isAppBlockable()) {
                bar.setSwitchBarEnabled(false);
            }

+2 −2
Original line number Diff line number Diff line
@@ -62,9 +62,9 @@ public class ConversationPriorityPreferenceController extends NotificationPrefer

    public void updateState(Preference preference) {
        if (mAppRow != null) {
            preference.setEnabled(mAdmin == null && !mChannel.isImportanceLockedByOEM());
            preference.setEnabled(mAdmin == null && isChannelConfigurable(mChannel));
            ConversationPriorityPreference pref = (ConversationPriorityPreference) preference;
            pref.setConfigurable(!mChannel.isImportanceLockedByOEM());
            pref.setConfigurable(isChannelConfigurable(mChannel));
            pref.setImportance(mChannel.getImportance());
            pref.setOriginalImportance(mChannel.getOriginalImportance());
            pref.setPriorityConversation(mChannel.isImportantConversation());
+1 −1
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ public class HighImportancePreferenceController extends NotificationPreferenceCo
    @Override
    public void updateState(Preference preference) {
        if (mAppRow != null && mChannel != null) {
            preference.setEnabled(mAdmin == null && !mChannel.isImportanceLockedByOEM());
            preference.setEnabled(mAdmin == null && isChannelConfigurable(mChannel));

            RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
            pref.setChecked(mChannel.getImportance() >= IMPORTANCE_HIGH);
+2 −2
Original line number Diff line number Diff line
@@ -66,9 +66,9 @@ public class ImportancePreferenceController extends NotificationPreferenceContro
    @Override
    public void updateState(Preference preference) {
        if (mAppRow!= null && mChannel != null) {
            preference.setEnabled(mAdmin == null && !mChannel.isImportanceLockedByOEM());
            preference.setEnabled(mAdmin == null && isChannelConfigurable(mChannel));
            ImportancePreference pref = (ImportancePreference) preference;
            pref.setConfigurable(!mChannel.isImportanceLockedByOEM());
            pref.setConfigurable(isChannelConfigurable(mChannel));
            pref.setImportance(mChannel.getImportance());
            pref.setDisplayInStatusBar(mBackend.showSilentInStatusBar(mContext.getPackageName()));
            pref.setDisplayOnLockscreen(Settings.Secure.getInt(mContext.getContentResolver(),
Loading