summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yi Jiang <eejiang@google.com> 2019-04-16 17:23:11 -0700
committer Yi Jiang <eejiang@google.com> 2019-04-17 11:21:51 -0700
commitfa323e7dcb263ac699d30a6722774ef186a168f2 (patch)
treef819fce88705291f23afa1dd39b5ad421a7c69a6
parentb33a6c6067ec3896be2584e4481b1ec038e7f774 (diff)
Add unit tests for AttentionManagerService. Make sure it won't crash when OnSwitchUser() is invoked while the bound service is null.
Bug: 130659721 Test: atest AttentionManagerServiceTest Change-Id: I71e1252e92eabca02fe2ae9b21596377f22f064c
-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);