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

Unverified Commit 8e2b0438 authored by Danny Baumann's avatar Danny Baumann Committed by Michael Bestas
Browse files

(Optionally) allow vibration during priority zen mode.

Change-Id: I6fb81c5898fbfe9e89a4af3fdc042266c8a9be6c
parent 8f387217
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -85,7 +85,7 @@ interface INotificationManager
    void applyAdjustmentsFromRankerService(in INotificationListener token, in List<Adjustment> adjustments);

    ComponentName getEffectsSuppressor();
    boolean matchesCallFilter(in Bundle extras);
    boolean[] matchesCallFilter(in Bundle extras);
    boolean isSystemConditionProviderEnabled(String path);

    int getZenMode();
+1 −1
Original line number Diff line number Diff line
@@ -399,7 +399,7 @@ public class NotificationManager
    /**
     * @hide
     */
    public boolean matchesCallFilter(Bundle extras) {
    public boolean[] matchesCallFilter(Bundle extras) {
        INotificationManager service = getService();
        try {
            return service.matchesCallFilter(extras);
+14 −7
Original line number Diff line number Diff line
@@ -1179,6 +1179,7 @@ public class NotificationManagerService extends SystemService {
        }
        mZenModeHelper.initZenMode();
        mZenModeHelper.readAllowLightsFromSettings();
        mZenModeHelper.readVibrationModeFromSettings();
        mInterruptionFilter = mZenModeHelper.getZenModeListenerInterruptionFilter();

        mUserProfiles.updateCache(getContext());
@@ -2209,7 +2210,7 @@ public class NotificationManagerService extends SystemService {
        }

        @Override
        public boolean matchesCallFilter(Bundle extras) {
        public boolean[] matchesCallFilter(Bundle extras) {
            enforceSystemOrSystemUI("INotificationManager.matchesCallFilter");
            return mZenModeHelper.matchesCallFilter(
                    Binder.getCallingUserHandle(),
@@ -2984,13 +2985,19 @@ public class NotificationManagerService extends SystemService {
        boolean hasValidVibrate = false;
        boolean hasValidSound = false;

        if (disableEffects == null
        boolean readyForBeepOrBuzz = disableEffects == null
                && (record.getUserId() == UserHandle.USER_ALL ||
                    record.getUserId() == currentUser ||
                    mUserProfiles.isCurrentProfile(record.getUserId()))
                && canInterrupt
                && mSystemReady
                && mAudioManager != null) {
                && mAudioManager != null;

        boolean canBeep = readyForBeepOrBuzz && canInterrupt;
        boolean canBuzz = readyForBeepOrBuzz &&
                (canInterrupt ||
                        (aboveThreshold && mZenModeHelper.allowVibrationForNotifications()));

        if (canBeep || canBuzz) {
            if (DBG) Slog.v(TAG, "Interrupting!");

            // should we use the default notification sound? (indicated either by
@@ -3036,7 +3043,7 @@ public class NotificationManagerService extends SystemService {

                sendAccessibilityEvent(notification, record.sbn.getPackageName());

                if (hasValidSound) {
                if (canBeep && hasValidSound) {
                    boolean looping =
                            (notification.flags & Notification.FLAG_INSISTENT) != 0;
                    AudioAttributes audioAttributes = audioAttributesForNotification(notification);
@@ -3064,8 +3071,8 @@ public class NotificationManagerService extends SystemService {
                    }
                }

                if (hasValidVibrate && !(mAudioManager.getRingerModeInternal()
                        == AudioManager.RINGER_MODE_SILENT)) {
                if (canBuzz && hasValidVibrate &&
                        mAudioManager.getRingerModeInternal() != AudioManager.RINGER_MODE_SILENT) {
                    mVibrateNotificationKey = key;

                    if (useDefaultVibrate || convertSoundToVibration) {
+32 −5
Original line number Diff line number Diff line
@@ -106,6 +106,7 @@ public class ZenModeHelper {
    private PackageManager mPm;
    private long mSuppressedEffects;
    private boolean mAllowLights;
    private int mVibrationMode;

    public static final long SUPPRESSED_EFFECT_NOTIFICATIONS = 1;
    public static final long SUPPRESSED_EFFECT_CALLS = 1 << 1;
@@ -138,11 +139,13 @@ public class ZenModeHelper {
        return TAG;
    }

    public boolean matchesCallFilter(UserHandle userHandle, Bundle extras,
    public boolean[] matchesCallFilter(UserHandle userHandle, Bundle extras,
            ValidateNotificationPeople validator, int contactsTimeoutMs, float timeoutAffinity) {
        synchronized (mConfig) {
            return ZenModeFiltering.matchesCallFilter(mContext, mZenMode, mConfig, userHandle,
                    extras, validator, contactsTimeoutMs, timeoutAffinity);
            boolean matches = ZenModeFiltering.matchesCallFilter(mContext, mZenMode, mConfig,
                    userHandle, extras, validator, contactsTimeoutMs, timeoutAffinity);
            boolean matchesForVibration = matches || allowVibrationForCalls();
            return new boolean[] { matches, matchesForVibration };
        }
    }

@@ -504,6 +507,8 @@ public class ZenModeHelper {
        }

        pw.print(prefix); pw.print("mSuppressedEffects="); pw.println(mSuppressedEffects);
        pw.print(prefix); pw.print("mAllowLights="); pw.println(mAllowLights);
        pw.print(prefix); pw.print("mVibrationMode="); pw.println(mVibrationMode);
        mFiltering.dump(pw, prefix);
        mConditions.dump(pw, prefix);
    }
@@ -697,6 +702,7 @@ public class ZenModeHelper {
        mZenMode = zen;
        updateRingerModeAffectedStreams();
        readAllowLightsFromSettings();
        readVibrationModeFromSettings();
        setZenModeSetting(mZenMode);
        if (setRingerMode) {
            applyZenToRingerMode();
@@ -748,6 +754,21 @@ public class ZenModeHelper {
        }
    }

    public boolean allowVibrationForCalls() {
        return mVibrationMode > 0;
    }

    public boolean allowVibrationForNotifications() {
        return mVibrationMode > 1;
    }

    public void readVibrationModeFromSettings() {
        final ContentResolver cr = mContext.getContentResolver();
        mVibrationMode = mZenMode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS
                ? CMSettings.System.getInt(cr, CMSettings.System.ZEN_PRIORITY_VIBRATION_MODE, 0)
                : 0;
    }

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

@@ -1058,6 +1079,8 @@ public class ZenModeHelper {
                CMSettings.System.ZEN_ALLOW_LIGHTS);
        private final Uri ZEN_PRIORITY_ALLOW_LIGHTS = CMSettings.System.getUriFor(
                CMSettings.System.ZEN_PRIORITY_ALLOW_LIGHTS);
        private final Uri ZEN_PRIORITY_VIBRATION_MODE = CMSettings.System.getUriFor(
                CMSettings.System.ZEN_PRIORITY_VIBRATION_MODE);

        public SettingsObserver(Handler handler) {
            super(handler);
@@ -1070,6 +1093,8 @@ public class ZenModeHelper {
                     ZEN_ALLOW_LIGHTS, false /*notifyForDescendents*/, this);
            resolver.registerContentObserver(
                     ZEN_PRIORITY_ALLOW_LIGHTS, false /*notifyForDescendents*/, this);
            resolver.registerContentObserver(
                     ZEN_PRIORITY_VIBRATION_MODE, false /*notifyForDescendents*/, this);
            update(null);
        }

@@ -1086,6 +1111,8 @@ public class ZenModeHelper {
                }
            } else if (ZEN_ALLOW_LIGHTS.equals(uri) || ZEN_PRIORITY_ALLOW_LIGHTS.equals(uri)) {
                readAllowLightsFromSettings();
            } else if (ZEN_PRIORITY_VIBRATION_MODE.equals(uri)) {
                readVibrationModeFromSettings();
            }
        }
    }