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

Commit 7c96b58c authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Send notification state event more frequently

- For all new notifications that will appear in the status
bar.

Change-Id: I7f3414d4007be26558f8f4b7ec72dde17a538b05
Fixes: 38500162
Test: manual
parent ef4e38f9
Loading
Loading
Loading
Loading
+53 −44
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package com.android.server.notification;
package com.android.server.notification;


import static android.app.NotificationManager.IMPORTANCE_MIN;
import static android.app.NotificationManager.IMPORTANCE_NONE;
import static android.app.NotificationManager.IMPORTANCE_NONE;
import static android.content.pm.PackageManager.FEATURE_LEANBACK;
import static android.content.pm.PackageManager.FEATURE_LEANBACK;
import static android.content.pm.PackageManager.FEATURE_TELEVISION;
import static android.content.pm.PackageManager.FEATURE_TELEVISION;
@@ -3659,14 +3660,6 @@ public class NotificationManagerService extends SystemService {
                            " intercept=" + record.isIntercepted()
                            " intercept=" + record.isIntercepted()
            );
            );


        final int currentUser;
        final long token = Binder.clearCallingIdentity();
        try {
            currentUser = ActivityManager.getCurrentUser();
        } finally {
            Binder.restoreCallingIdentity(token);
        }

        // If we're not supposed to beep, vibrate, etc. then don't.
        // If we're not supposed to beep, vibrate, etc. then don't.
        final String disableEffects = disableNotificationEffects(record);
        final String disableEffects = disableNotificationEffects(record);
        if (disableEffects != null) {
        if (disableEffects != null) {
@@ -3676,19 +3669,22 @@ public class NotificationManagerService extends SystemService {
        // Remember if this notification already owns the notification channels.
        // Remember if this notification already owns the notification channels.
        boolean wasBeep = key != null && key.equals(mSoundNotificationKey);
        boolean wasBeep = key != null && key.equals(mSoundNotificationKey);
        boolean wasBuzz = key != null && key.equals(mVibrateNotificationKey);
        boolean wasBuzz = key != null && key.equals(mVibrateNotificationKey);

        // These are set inside the conditional if the notification is allowed to make noise.
        // These are set inside the conditional if the notification is allowed to make noise.
        boolean hasValidVibrate = false;
        boolean hasValidVibrate = false;
        boolean hasValidSound = false;
        boolean hasValidSound = false;

        if (isNotificationForCurrentUser(record)) {
            // If the notification will appear in the status bar, it should send an accessibility
            // event
            if (!record.isUpdate && record.getImportance() > IMPORTANCE_MIN) {
                sendAccessibilityEvent(notification, record.sbn.getPackageName());
            }

            if (disableEffects == null
            if (disableEffects == null
                && (record.getUserId() == UserHandle.USER_ALL ||
                    record.getUserId() == currentUser ||
                    mUserProfiles.isCurrentProfile(record.getUserId()))
                    && canInterrupt
                    && canInterrupt
                    && mSystemReady
                    && mSystemReady
                    && mAudioManager != null) {
                    && mAudioManager != null) {
                if (DBG) Slog.v(TAG, "Interrupting!");
                if (DBG) Slog.v(TAG, "Interrupting!");

                Uri soundUri = record.getSound();
                Uri soundUri = record.getSound();
                hasValidSound = soundUri != null && !Uri.EMPTY.equals(soundUri);
                hasValidSound = soundUri != null && !Uri.EMPTY.equals(soundUri);
                long[] vibration = record.getVibration();
                long[] vibration = record.getVibration();
@@ -3702,8 +3698,6 @@ public class NotificationManagerService extends SystemService {
                hasValidVibrate = vibration != null;
                hasValidVibrate = vibration != null;


                if (!shouldMuteNotificationLocked(record)) {
                if (!shouldMuteNotificationLocked(record)) {
                sendAccessibilityEvent(notification, record.sbn.getPackageName());

                    if (hasValidSound) {
                    if (hasValidSound) {
                        mSoundNotificationKey = key;
                        mSoundNotificationKey = key;
                        if (mInCall) {
                        if (mInCall) {
@@ -3715,7 +3709,8 @@ public class NotificationManagerService extends SystemService {
                    }
                    }


                    final boolean ringerModeSilent =
                    final boolean ringerModeSilent =
                        mAudioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT;
                            mAudioManager.getRingerModeInternal()
                                    == AudioManager.RINGER_MODE_SILENT;
                    if (!mInCall && hasValidVibrate && !ringerModeSilent) {
                    if (!mInCall && hasValidVibrate && !ringerModeSilent) {
                        mVibrateNotificationKey = key;
                        mVibrateNotificationKey = key;


@@ -3723,6 +3718,7 @@ public class NotificationManagerService extends SystemService {
                    }
                    }
                }
                }
            }
            }
        }
        // If a notification is updated to remove the actively playing sound or vibrate,
        // If a notification is updated to remove the actively playing sound or vibrate,
        // cancel that feedback now
        // cancel that feedback now
        if (wasBeep && !hasValidSound) {
        if (wasBeep && !hasValidSound) {
@@ -3819,6 +3815,19 @@ public class NotificationManagerService extends SystemService {
        }
        }
    }
    }


    private boolean isNotificationForCurrentUser(NotificationRecord record) {
        final int currentUser;
        final long token = Binder.clearCallingIdentity();
        try {
            currentUser = ActivityManager.getCurrentUser();
        } finally {
            Binder.restoreCallingIdentity(token);
        }
        return (record.getUserId() == UserHandle.USER_ALL ||
                record.getUserId() == currentUser ||
                mUserProfiles.isCurrentProfile(record.getUserId()));
    }

    private void playInCallNotification() {
    private void playInCallNotification() {
        new Thread() {
        new Thread() {
            @Override
            @Override