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

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

Synchronize updates to zen config.

Also, remove some dead code.

Change-Id: If6f4432638aebcedf59a4804a3b5d14b73f12549
parent 339e884b
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -83,10 +83,8 @@ interface INotificationManager

    int getZenMode();
    ZenModeConfig getZenModeConfig();
    boolean setZenModeConfig(in ZenModeConfig config, String reason);
    oneway void setZenMode(int mode, in Uri conditionId, String reason);
    oneway void notifyConditions(String pkg, in IConditionProvider provider, in Condition[] conditions);
    oneway void requestZenModeConditions(in IConditionListener callback, int relevance);
    boolean isNotificationPolicyAccessGranted(String pkg);
    NotificationManager.Policy getNotificationPolicy(String pkg);
    void setNotificationPolicy(String pkg, in NotificationManager.Policy policy);
+0 −23
Original line number Diff line number Diff line
@@ -345,29 +345,6 @@ public class NotificationManager
        }
    }

    /**
     * @hide
     */
    public boolean setZenModeConfig(ZenModeConfig config, String reason) {
        INotificationManager service = getService();
        try {
            return service.setZenModeConfig(config, reason);
        } catch (RemoteException e) {
            return false;
        }
    }

    /**
     * @hide
     */
    public void requestZenModeConditions(IConditionListener listener, int relevance) {
        INotificationManager service = getService();
        try {
            service.requestZenModeConditions(listener, relevance);
        } catch (RemoteException e) {
        }
    }

    /**
     * @hide
     */
+0 −23
Original line number Diff line number Diff line
@@ -125,10 +125,6 @@ public class VolumeDialogController {
        return mAudio;
    }

    public ZenModeConfig getZenModeConfig() {
        return mNoMan.getZenModeConfig();
    }

    public void dismiss() {
        mCallbacks.onDismissRequested(Events.DISMISS_REASON_VOLUME_CONTROLLER);
    }
@@ -348,7 +344,6 @@ public class VolumeDialogController {
        updateRingerModeExternalW(mAudio.getRingerMode());
        updateZenModeW();
        updateEffectsSuppressorW(mNoMan.getEffectsSuppressor());
        updateZenModeConfigW();
        mCallbacks.onStateChanged(mState);
    }

@@ -401,13 +396,6 @@ public class VolumeDialogController {
        return stream == AudioManager.STREAM_RING || stream == AudioManager.STREAM_NOTIFICATION;
    }

    private boolean updateZenModeConfigW() {
        final ZenModeConfig zenModeConfig = getZenModeConfig();
        if (Objects.equals(mState.zenModeConfig, zenModeConfig)) return false;
        mState.zenModeConfig = zenModeConfig;
        return true;
    }

    private boolean updateEffectsSuppressorW(ComponentName effectsSuppressor) {
        if (Objects.equals(mState.effectsSuppressor, effectsSuppressor)) return false;
        mState.effectsSuppressor = effectsSuppressor;
@@ -748,9 +736,6 @@ public class VolumeDialogController {
            if (ZEN_MODE_URI.equals(uri)) {
                changed = updateZenModeW();
            }
            if (ZEN_MODE_CONFIG_URI.equals(uri)) {
                changed = updateZenModeConfigW();
            }
            if (changed) {
                mCallbacks.onStateChanged(mState);
            }
@@ -947,7 +932,6 @@ public class VolumeDialogController {
        public int zenMode;
        public ComponentName effectsSuppressor;
        public String effectsSuppressorName;
        public ZenModeConfig zenModeConfig;
        public int activeStream = NO_ACTIVE_STREAM;

        public State copy() {
@@ -960,7 +944,6 @@ public class VolumeDialogController {
            rt.zenMode = zenMode;
            if (effectsSuppressor != null) rt.effectsSuppressor = effectsSuppressor.clone();
            rt.effectsSuppressorName = effectsSuppressorName;
            if (zenModeConfig != null) rt.zenModeConfig = zenModeConfig.copy();
            rt.activeStream = activeStream;
            return rt;
        }
@@ -989,7 +972,6 @@ public class VolumeDialogController {
            sep(sb, indent); sb.append("zenMode:").append(zenMode);
            sep(sb, indent); sb.append("effectsSuppressor:").append(effectsSuppressor);
            sep(sb, indent); sb.append("effectsSuppressorName:").append(effectsSuppressorName);
            sep(sb, indent); sb.append("zenModeConfig:").append(zenModeConfig);
            sep(sb, indent); sb.append("activeStream:").append(activeStream);
            if (indent > 0) sep(sb, indent);
            return sb.append('}').toString();
@@ -1005,11 +987,6 @@ public class VolumeDialogController {
                sb.append(',');
            }
        }

        public Condition getManualExitCondition() {
            return zenModeConfig != null && zenModeConfig.manualRule != null
                    ? zenModeConfig.manualRule.condition : null;
        }
    }

    public interface Callbacks {
+0 −12
Original line number Diff line number Diff line
@@ -1578,12 +1578,6 @@ public class NotificationManagerService extends SystemService {
            return mZenModeHelper.getConfig();
        }

        @Override
        public boolean setZenModeConfig(ZenModeConfig config, String reason) {
            checkCallerIsSystem();
            return mZenModeHelper.setConfig(config, reason);
        }

        @Override
        public void setZenMode(int mode, Uri conditionId, String reason) throws RemoteException {
            enforceSystemOrSystemUIOrVolume("INotificationManager.setZenMode");
@@ -1669,12 +1663,6 @@ public class NotificationManagerService extends SystemService {
            });
        }

        @Override
        public void requestZenModeConditions(IConditionListener callback, int relevance) {
            enforceSystemOrSystemUIOrVolume("INotificationManager.requestZenModeConditions");
            mZenModeHelper.requestZenModeConditions(callback, relevance);
        }

        private void enforceSystemOrSystemUIOrVolume(String message) {
            if (mAudioManagerInternal != null) {
                final int vcuid = mAudioManagerInternal.getVolumeControllerUid();
+82 −55
Original line number Diff line number Diff line
@@ -121,17 +121,22 @@ public class ZenModeHelper {

    public boolean matchesCallFilter(UserHandle userHandle, Bundle extras,
            ValidateNotificationPeople validator, int contactsTimeoutMs, float timeoutAffinity) {
        return ZenModeFiltering.matchesCallFilter(mContext, mZenMode, mConfig, userHandle, extras,
        synchronized (mConfig) {
            return ZenModeFiltering.matchesCallFilter(mContext, mZenMode, mConfig, userHandle,
                    extras,
                    validator, contactsTimeoutMs, timeoutAffinity);
        }
    }

    public boolean isCall(NotificationRecord record) {
        return mFiltering.isCall(record);
    }

    public boolean shouldIntercept(NotificationRecord record) {
        synchronized (mConfig) {
            return mFiltering.shouldIntercept(mZenMode, mConfig, record);
        }
    }

    public void addCallback(Callback callback) {
        mCallbacks.add(callback);
@@ -175,10 +180,6 @@ public class ZenModeHelper {
        mConfigs.remove(user);
    }

    public void requestZenModeConditions(IConditionListener callback, int relevance) {
        mConditions.requestConditions(callback, relevance);
    }

    public int getZenModeListenerInterruptionFilter() {
        return NotificationManager.zenModeToInterruptionFilter(mZenMode);
    }
@@ -203,18 +204,23 @@ public class ZenModeHelper {

    public List<AutomaticZenRule> getAutomaticZenRules() {
        List<AutomaticZenRule> rules = new ArrayList<>();
        synchronized (mConfig) {
            if (mConfig == null) return rules;
            for (ZenRule rule : mConfig.automaticRules.values()) {
                if (canManageAutomaticZenRule(rule)) {
                    rules.add(createAutomaticZenRule(rule));
                }
            }
        }
        return rules;
    }

    public AutomaticZenRule getAutomaticZenRule(String id) {
        ZenRule rule;
        synchronized (mConfig) {
            if (mConfig == null) return null;
        ZenRule rule = mConfig.automaticRules.get(id);
             rule = mConfig.automaticRules.get(id);
        }
        if (rule == null) return null;
        if (canManageAutomaticZenRule(rule)) {
             return createAutomaticZenRule(rule);
@@ -223,14 +229,18 @@ public class ZenModeHelper {
    }

    public AutomaticZenRule addAutomaticZenRule(AutomaticZenRule automaticZenRule, String reason) {
        ZenModeConfig newConfig;
        synchronized (mConfig) {
            if (mConfig == null) return null;
            if (DEBUG) {
          Log.d(TAG, "addAutomaticZenRule zenRule= " + automaticZenRule + " reason=" +reason);
                Log.d(TAG,
                        "addAutomaticZenRule zenRule= " + automaticZenRule + " reason=" + reason);
            }
            if (!TextUtils.isEmpty(automaticZenRule.getId())) {
                throw new IllegalArgumentException("Rule already exists");
            }
        final ZenModeConfig newConfig = mConfig.copy();
            newConfig = mConfig.copy();
        }
        ZenRule rule = new ZenRule();
        populateZenRule(automaticZenRule, rule, true);
        newConfig.automaticRules.put(rule.id, rule);
@@ -242,12 +252,15 @@ public class ZenModeHelper {
    }

    public boolean updateAutomaticZenRule(AutomaticZenRule automaticZenRule, String reason) {
        ZenModeConfig newConfig;
        synchronized (mConfig) {
            if (mConfig == null) return false;
            if (DEBUG) {
                Log.d(TAG, "updateAutomaticZenRule zenRule=" + automaticZenRule
                        + " reason=" + reason);
            }
        final ZenModeConfig newConfig = mConfig.copy();
            newConfig = mConfig.copy();
        }
        final String ruleId = automaticZenRule.getId();
        ZenModeConfig.ZenRule rule = new ZenModeConfig.ZenRule();
        if (ruleId == null) {
@@ -265,8 +278,11 @@ public class ZenModeHelper {
    }

    public boolean removeAutomaticZenRule(String id, String reason) {
        ZenModeConfig newConfig;
        synchronized (mConfig) {
            if (mConfig == null) return false;
        final ZenModeConfig newConfig = mConfig.copy();
            newConfig = mConfig.copy();
        }
        ZenRule rule = newConfig.automaticRules.get(id);
        if (rule == null) return false;
        if (canManageAutomaticZenRule(rule)) {
@@ -328,12 +344,15 @@ public class ZenModeHelper {

    private void setManualZenMode(int zenMode, Uri conditionId, String reason,
            boolean setRingerMode) {
        ZenModeConfig newConfig;
        synchronized (mConfig) {
            if (mConfig == null) return;
            if (!Global.isValidZenMode(zenMode)) return;
            if (DEBUG) Log.d(TAG, "setManualZenMode " + Global.zenModeToString(zenMode)
                    + " conditionId=" + conditionId + " reason=" + reason
                    + " setRingerMode=" + setRingerMode);
        final ZenModeConfig newConfig = mConfig.copy();
            newConfig = mConfig.copy();
        }
        if (zenMode == Global.ZEN_MODE_OFF) {
            newConfig.manualRule = null;
            for (ZenRule automaticRule : newConfig.automaticRules.values()) {
@@ -360,7 +379,9 @@ public class ZenModeHelper {
            dump(pw, prefix, "mConfigs[u=" + mConfigs.keyAt(i) + "]", mConfigs.valueAt(i));
        }
        pw.print(prefix); pw.print("mUser="); pw.println(mUser);
        synchronized (mConfig) {
            dump(pw, prefix, "mConfig", mConfig);
        }
        pw.print(prefix); pw.print("mEffectsSuppressed="); pw.println(mEffectsSuppressed);
        mFiltering.dump(pw, prefix);
        mConditions.dump(pw, prefix);
@@ -437,7 +458,9 @@ public class ZenModeHelper {
    }

    public ZenModeConfig getConfig() {
        return mConfig;
        synchronized (mConfig) {
            return mConfig.copy();
        }
    }

    public boolean setConfig(ZenModeConfig config, String reason) {
@@ -462,6 +485,7 @@ public class ZenModeHelper {
                return true;
            }
            mConditions.evaluateConfig(config, false /*processSubscriptions*/);  // may modify config
            synchronized (mConfig) {
                mConfigs.put(config.user, config);
                if (DEBUG) Log.d(TAG, "setConfig reason=" + reason, new Throwable());
                ZenLog.traceConfig(reason, mConfig, config);
@@ -474,7 +498,8 @@ public class ZenModeHelper {
                if (policyChanged) {
                    dispatchOnPolicyChanged();
                }
            final String val = Integer.toString(mConfig.hashCode());
            }
            final String val = Integer.toString(config.hashCode());
            Global.putString(mContext.getContentResolver(), Global.ZEN_MODE_CONFIG_ETAG, val);
            if (!evaluateZenMode(reason, setRingerMode)) {
                applyRestrictions();  // evaluateZenMode will also apply restrictions if changed
@@ -529,6 +554,7 @@ public class ZenModeHelper {
    }

    private int computeZenMode() {
        synchronized (mConfig) {
            if (mConfig == null) return Global.ZEN_MODE_OFF;
            if (mConfig.manualRule != null) return mConfig.manualRule.zenMode;
            int zen = Global.ZEN_MODE_OFF;
@@ -541,6 +567,7 @@ public class ZenModeHelper {
            }
            return zen;
        }
    }

    private void applyRestrictions() {
        final boolean zen = mZenMode != Global.ZEN_MODE_OFF;