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

Commit e05eda22 authored by Danny Baumann's avatar Danny Baumann
Browse files

(Optionally) allow vibration during priority zen mode.

Change-Id: I6fb81c5898fbfe9e89a4af3fdc042266c8a9be6c
parent 19139443
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ interface INotificationManager
    void setInterruptionFilter(String pkg, int interruptionFilter);

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

    int getZenMode();
+2 −2
Original line number Diff line number Diff line
@@ -341,12 +341,12 @@ public class NotificationManager
    /**
     * @hide
     */
    public boolean matchesCallFilter(Bundle extras) {
    public boolean[] matchesCallFilter(Bundle extras) {
        INotificationManager service = getService();
        try {
            return service.matchesCallFilter(extras);
        } catch (RemoteException e) {
            return false;
            return null;
        }
    }

+19 −10
Original line number Diff line number Diff line
@@ -1264,6 +1264,7 @@ public class NotificationManagerService extends SystemService {
        }
        mZenModeHelper.initZenMode();
        mZenModeHelper.readAllowLightsFromSettings();
        mZenModeHelper.readVibrationModeFromSettings();
        mInterruptionFilter = mZenModeHelper.getZenModeListenerInterruptionFilter();

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

        @Override
        public boolean matchesCallFilter(Bundle extras) {
        public boolean[] matchesCallFilter(Bundle extras) {
            enforceSystemOrSystemUI("INotificationManager.matchesCallFilter");
            return mZenModeHelper.matchesCallFilter(
                    UserHandle.getCallingUserHandle(),
@@ -2698,21 +2699,28 @@ public class NotificationManagerService extends SystemService {
            ZenLog.traceDisableEffects(record, disableEffects);
        }

        if ((disableEffects == null)
        boolean readyForBeepOrBuzz = disableEffects == null
                && (!(record.isUpdate
                    && (notification.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0 ))
                && (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 || mZenModeHelper.allowVibrationForNotifications());
        boolean hasValidSound = false;

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

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

        // sound

        if (canBeep) {
            // should we use the default notification sound? (indicated either by
            // DEFAULT_SOUND or because notification.sound is pointing at
            // Settings.System.NOTIFICATION_SOUND)
@@ -2722,7 +2730,6 @@ public class NotificationManagerService extends SystemService {
                                   .equals(notification.sound);

            Uri soundUri = null;
            boolean hasValidSound = false;

            if (useDefaultSound) {
                soundUri = Settings.System.DEFAULT_NOTIFICATION_URI;
@@ -2763,15 +2770,17 @@ public class NotificationManagerService extends SystemService {
                    }
                }
            }
        }


        // vibrate
        if (canBuzz) {
            // Does the notification want to specify its own vibration?
            final boolean hasCustomVibrate = notification.vibrate != null;

            // new in 4.2: if there was supposed to be a sound and we're in vibrate
            // mode, and no other vibration is specified, we fall back to vibration
            final boolean convertSoundToVibration =
                       !hasCustomVibrate
            final boolean convertSoundToVibration = !hasCustomVibrate
                    && hasValidSound
                    && (mAudioManager.getRingerModeInternal()
                               == AudioManager.RINGER_MODE_VIBRATE);
+32 −5
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ public class ZenModeHelper {
    private AudioManagerInternal mAudioManager;
    private boolean mEffectsSuppressed;
    private boolean mAllowLights;
    private int mVibrationMode;

    public ZenModeHelper(Context context, Looper looper, ConditionProviders conditionProviders) {
        mContext = context;
@@ -117,10 +118,12 @@ 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) {
        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 };
    }

    public boolean isCall(NotificationRecord record) {
@@ -238,6 +241,8 @@ public class ZenModeHelper {
        pw.print(prefix); pw.print("mUser="); pw.println(mUser);
        dump(pw, prefix, "mConfig", mConfig);
        pw.print(prefix); pw.print("mEffectsSuppressed="); pw.println(mEffectsSuppressed);
        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);
    }
@@ -381,6 +386,7 @@ public class ZenModeHelper {
        mZenMode = zen;
        updateRingerModeAffectedStreams();
        readAllowLightsFromSettings();
        readVibrationModeFromSettings();
        setZenModeSetting(mZenMode);
        if (setRingerMode) {
            applyZenToRingerMode();
@@ -428,6 +434,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;

@@ -718,6 +739,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);
@@ -730,6 +753,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);
        }

@@ -746,6 +771,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();
            }
        }
    }