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

Commit 2839ddd9 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Notification: The updateLightsLocked method should be called by the...

Merge "Notification: The updateLightsLocked method should be called by the NMS.mNotificationLock lock." into main am: eb55496c am: 173ed43e

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/3298356



Change-Id: Iae3c7f442cf88d45cea536968d8282b39ba661e3
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 48786fcb 173ed43e
Loading
Loading
Loading
Loading
+35 −15
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ import com.android.server.lights.LogicalLight;
import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import com.android.internal.annotations.GuardedBy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -152,6 +153,8 @@ public final class NotificationAttentionHelper {
    @interface MuteReason {}

    private final Context mContext;
    //This is NMS.mNotificationLock.
    private final Object mLock;
    private final PackageManager mPackageManager;
    private final TelephonyManager mTelephonyManager;
    private final UserManager mUm;
@@ -165,6 +168,7 @@ public final class NotificationAttentionHelper {

    private VibratorHelper mVibratorHelper;
    // The last key in this list owns the hardware.
    @GuardedBy("mLock")
    ArrayList<String> mLights = new ArrayList<>();
    private LogicalLight mNotificationLight;
    private LogicalLight mAttentionLight;
@@ -183,8 +187,10 @@ public final class NotificationAttentionHelper {
    private String mVibrateNotificationKey;
    private boolean mSystemReady;
    private boolean mInCallStateOffHook = false;
    @GuardedBy("mLock")
    private boolean mScreenOn = true;
    private boolean mUserPresent = false;
    @GuardedBy("mLock")
    private boolean mNotificationPulseEnabled;
    private final Uri mInCallNotificationUri;
    private final AudioAttributes mInCallNotificationAudioAttributes;
@@ -200,12 +206,13 @@ public final class NotificationAttentionHelper {
    private final PolitenessStrategy mStrategy;
    private int mCurrentWorkProfileId = UserHandle.USER_NULL;

    public NotificationAttentionHelper(Context context, LightsManager lightsManager,
    public NotificationAttentionHelper(Context context, Object lock, LightsManager lightsManager,
            AccessibilityManager accessibilityManager, PackageManager packageManager,
            UserManager userManager, NotificationUsageStats usageStats,
            NotificationManagerPrivate notificationManagerPrivate,
            ZenModeHelper zenModeHelper, SystemUiSystemPropertiesFlags.FlagResolver flagResolver) {
        mContext = context;
        mLock = lock;
        mPackageManager = packageManager;
        mTelephonyManager = context.getSystemService(TelephonyManager.class);
        mAccessibilityManager = accessibilityManager;
@@ -368,10 +375,12 @@ public final class NotificationAttentionHelper {
    private void loadUserSettings() {
        boolean pulseEnabled = Settings.System.getIntForUser(mContext.getContentResolver(),
                Settings.System.NOTIFICATION_LIGHT_PULSE, 0, UserHandle.USER_CURRENT) != 0;
        synchronized (mLock) {
            if (mNotificationPulseEnabled != pulseEnabled) {
                mNotificationPulseEnabled = pulseEnabled;
                updateLightsLocked();
            }
        }

        if (Flags.politeNotifications()) {
            try {
@@ -1148,7 +1157,8 @@ public final class NotificationAttentionHelper {
        }
    }

    public void dump(PrintWriter pw, String prefix, NotificationManagerService.DumpFilter filter) {
    public void dumpLocked(PrintWriter pw, String prefix,
            NotificationManagerService.DumpFilter filter) {
        pw.println("\n  Notification attention state:");
        pw.print(prefix);
        pw.println("  mSoundNotificationKey=" + mSoundNotificationKey);
@@ -1684,16 +1694,22 @@ public final class NotificationAttentionHelper {
            if (action.equals(Intent.ACTION_SCREEN_ON)) {
                // Keep track of screen on/off state, but do not turn off the notification light
                // until user passes through the lock screen or views the notification.
                synchronized (mLock) {
                    mScreenOn = true;
                    updateLightsLocked();
                }
            } else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
                synchronized (mLock) {
                    mScreenOn = false;
                    mUserPresent = false;
                    updateLightsLocked();
                }
            } else if (action.equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
                mInCallStateOffHook = TelephonyManager.EXTRA_STATE_OFFHOOK
                        .equals(intent.getStringExtra(TelephonyManager.EXTRA_STATE));
                synchronized (mLock) {
                    updateLightsLocked();
                }
            } else if (action.equals(Intent.ACTION_USER_PRESENT)) {
                mUserPresent = true;
                // turn off LED when user passes through lock screen
@@ -1755,11 +1771,13 @@ public final class NotificationAttentionHelper {
                        Settings.System.NOTIFICATION_LIGHT_PULSE, 0,
                        UserHandle.USER_CURRENT)
                        != 0;
                synchronized (mLock) {
                    if (mNotificationPulseEnabled != pulseEnabled) {
                        mNotificationPulseEnabled = pulseEnabled;
                        updateLightsLocked();
                    }
                }
            }
            if (Flags.politeNotifications()) {
                if (NOTIFICATION_COOLDOWN_ENABLED_URI.equals(uri)) {
                    mNotificationCooldownEnabled = Settings.System.getIntForUser(
@@ -1840,8 +1858,10 @@ public final class NotificationAttentionHelper {

    @VisibleForTesting
    void setScreenOn(boolean on) {
        synchronized (mLock) {
            mScreenOn = on;
        }
    }

    @VisibleForTesting
    void setUserPresent(boolean userPresent) {
+4 −4
Original line number Diff line number Diff line
@@ -2640,9 +2640,9 @@ public class NotificationManagerService extends SystemService {
        mToastRateLimiter = toastRateLimiter;
        mAttentionHelper = new NotificationAttentionHelper(getContext(), lightsManager,
                mAccessibilityManager, mPackageManagerClient, userManager, usageStats,
                mNotificationManagerPrivate, mZenModeHelper, flagResolver);
        mAttentionHelper = new NotificationAttentionHelper(getContext(), mNotificationLock,
                lightsManager, mAccessibilityManager, mPackageManagerClient, userManager,
                usageStats, mNotificationManagerPrivate, mZenModeHelper, flagResolver);
        // register for various Intents.
        // If this is called within a test, make sure to unregister the intent receivers by
@@ -7331,7 +7331,7 @@ public class NotificationManagerService extends SystemService {
                    pw.println("  mMaxPackageEnqueueRate=" + mMaxPackageEnqueueRate);
                    pw.println("  hideSilentStatusBar="
                            + mPreferencesHelper.shouldHideSilentStatusIcons());
                    mAttentionHelper.dump(pw, "    ", filter);
                    mAttentionHelper.dumpLocked(pw, "    ", filter);
                }
                pw.println("  mArchive=" + mArchive.toString());
                mArchive.dumpImpl(pw, filter);
+4 −3
Original line number Diff line number Diff line
@@ -260,9 +260,10 @@ public class NotificationAttentionHelperTest extends UiServiceTestCase {
    }

    private void initAttentionHelper(TestableFlagResolver flagResolver) {
        mAttentionHelper = new NotificationAttentionHelper(getContext(), mock(LightsManager.class),
                mAccessibilityManager, mPackageManager, mUserManager, mUsageStats,
                mService.mNotificationManagerPrivate, mock(ZenModeHelper.class), flagResolver);
        mAttentionHelper = new NotificationAttentionHelper(getContext(), new Object(),
                mock(LightsManager.class),mAccessibilityManager, mPackageManager,
                mUserManager, mUsageStats, mService.mNotificationManagerPrivate,
                mock(ZenModeHelper.class), flagResolver);
        mAttentionHelper.onSystemReady();
        mAttentionHelper.setVibratorHelper(spy(new VibratorHelper(getContext())));
        mAttentionHelper.setAudioManager(mAudioManager);