summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2024-10-21 16:06:25 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2024-10-21 16:06:25 +0000
commiteb55496c10be60e5168ad6ac378ea6ab6b30d218 (patch)
tree036e3e451a79f1195b4d9d432132ff1384530b66
parent078792310a6be7621504e9e513c2be0a395ad24f (diff)
parent80e7d124804521479bf0d5b476118d555cb09707 (diff)
Merge "Notification: The updateLightsLocked method should be called by the NMS.mNotificationLock lock." into main
-rw-r--r--services/core/java/com/android/server/notification/NotificationAttentionHelper.java50
-rw-r--r--services/core/java/com/android/server/notification/NotificationManagerService.java8
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/NotificationAttentionHelperTest.java7
3 files changed, 43 insertions, 22 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationAttentionHelper.java b/services/core/java/com/android/server/notification/NotificationAttentionHelper.java
index a7e14d9baea2..980f40ee4a9a 100644
--- a/services/core/java/com/android/server/notification/NotificationAttentionHelper.java
+++ b/services/core/java/com/android/server/notification/NotificationAttentionHelper.java
@@ -79,6 +79,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;
@@ -119,6 +120,8 @@ public final class NotificationAttentionHelper {
);
private final Context mContext;
+ //This is NMS.mNotificationLock.
+ private final Object mLock;
private final PackageManager mPackageManager;
private final TelephonyManager mTelephonyManager;
private final UserManager mUm;
@@ -132,6 +135,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;
@@ -149,8 +153,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;
@@ -166,12 +172,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;
@@ -315,9 +322,11 @@ public final class NotificationAttentionHelper {
private void loadUserSettings() {
boolean pulseEnabled = Settings.System.getIntForUser(mContext.getContentResolver(),
Settings.System.NOTIFICATION_LIGHT_PULSE, 0, UserHandle.USER_CURRENT) != 0;
- if (mNotificationPulseEnabled != pulseEnabled) {
- mNotificationPulseEnabled = pulseEnabled;
- updateLightsLocked();
+ synchronized (mLock) {
+ if (mNotificationPulseEnabled != pulseEnabled) {
+ mNotificationPulseEnabled = pulseEnabled;
+ updateLightsLocked();
+ }
}
if (Flags.politeNotifications()) {
@@ -1063,7 +1072,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);
@@ -1591,16 +1601,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.
- mScreenOn = true;
- updateLightsLocked();
+ synchronized (mLock) {
+ mScreenOn = true;
+ updateLightsLocked();
+ }
} else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
- mScreenOn = false;
- mUserPresent = false;
- updateLightsLocked();
+ 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));
- updateLightsLocked();
+ synchronized (mLock) {
+ updateLightsLocked();
+ }
} else if (action.equals(Intent.ACTION_USER_PRESENT)) {
mUserPresent = true;
// turn off LED when user passes through lock screen
@@ -1662,9 +1678,11 @@ public final class NotificationAttentionHelper {
Settings.System.NOTIFICATION_LIGHT_PULSE, 0,
UserHandle.USER_CURRENT)
!= 0;
- if (mNotificationPulseEnabled != pulseEnabled) {
- mNotificationPulseEnabled = pulseEnabled;
- updateLightsLocked();
+ synchronized (mLock) {
+ if (mNotificationPulseEnabled != pulseEnabled) {
+ mNotificationPulseEnabled = pulseEnabled;
+ updateLightsLocked();
+ }
}
}
if (Flags.politeNotifications()) {
@@ -1747,7 +1765,9 @@ public final class NotificationAttentionHelper {
@VisibleForTesting
void setScreenOn(boolean on) {
- mScreenOn = on;
+ synchronized (mLock) {
+ mScreenOn = on;
+ }
}
@VisibleForTesting
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index b436c8b42edf..c83351ddebea 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -2573,9 +2573,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
@@ -6916,7 +6916,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);
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationAttentionHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationAttentionHelperTest.java
index 3da80314e6d4..2429ff334efe 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationAttentionHelperTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationAttentionHelperTest.java
@@ -243,9 +243,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);