summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2019-04-17 20:28:20 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2019-04-17 20:28:20 +0000
commita8853fe2829fab3deb3a8cf7fcf8a0dcaed4b4c8 (patch)
tree2d248e821d4bbf2ee8d73e3025f8ffc7e2115b5d
parenteaf1f8fd6da652d9bc42da70d9d188ba665db4bc (diff)
parentfa323e7dcb263ac699d30a6722774ef186a168f2 (diff)
Merge "Add unit tests for AttentionManagerService. Make sure it won't crash when OnSwitchUser() is invoked while the bound service is null." into qt-dev
-rw-r--r--services/core/java/com/android/server/attention/AttentionManagerService.java3
-rw-r--r--services/tests/servicestests/src/com/android/server/attention/AttentionManagerServiceTest.java7
2 files changed, 9 insertions, 1 deletions
diff --git a/services/core/java/com/android/server/attention/AttentionManagerService.java b/services/core/java/com/android/server/attention/AttentionManagerService.java
index d7d4851bf33f..b50af28b12b3 100644
--- a/services/core/java/com/android/server/attention/AttentionManagerService.java
+++ b/services/core/java/com/android/server/attention/AttentionManagerService.java
@@ -309,7 +309,8 @@ public class AttentionManagerService extends SystemService {
}
@GuardedBy("mLock")
- private UserState getOrCreateUserStateLocked(int userId) {
+ @VisibleForTesting
+ protected UserState getOrCreateUserStateLocked(int userId) {
UserState result = mUserStates.get(userId);
if (result == null) {
result = new UserState(userId, mContext, mLock, mComponentName);
diff --git a/services/tests/servicestests/src/com/android/server/attention/AttentionManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/attention/AttentionManagerServiceTest.java
index 8426a0bb2c11..bb9f49e6f37f 100644
--- a/services/tests/servicestests/src/com/android/server/attention/AttentionManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/attention/AttentionManagerServiceTest.java
@@ -132,6 +132,13 @@ public class AttentionManagerServiceTest {
verify(callback).onSuccess(anyInt(), anyLong());
}
+ @Test
+ public void testOnSwitchUser_noCrashCurrentServiceIsNull() {
+ final int userId = 10;
+ mSpyAttentionManager.getOrCreateUserStateLocked(userId);
+ mSpyAttentionManager.onSwitchUser(userId);
+ }
+
private class MockIAttentionService implements IAttentionService {
public void checkAttention(IAttentionCallback callback) throws RemoteException {
callback.onSuccess(0, 0);