Loading services/core/java/com/android/server/attention/AttentionManagerService.java +7 −5 Original line number Diff line number Diff line Loading @@ -108,7 +108,8 @@ public class AttentionManagerService extends SystemService { private final PowerManager mPowerManager; private final Object mLock; @GuardedBy("mLock") private IAttentionService mService; @VisibleForTesting protected IAttentionService mService; @GuardedBy("mLock") private AttentionCheckCacheBuffer mAttentionCheckCacheBuffer; @GuardedBy("mLock") Loading Loading @@ -158,7 +159,8 @@ public class AttentionManagerService extends SystemService { } /** Resolves and sets up the attention service if it had not been done yet. */ private boolean isServiceAvailable() { @VisibleForTesting protected boolean isServiceAvailable() { if (mComponentName == null) { mComponentName = resolveAttentionService(mContext); } Loading @@ -168,12 +170,12 @@ public class AttentionManagerService extends SystemService { /** * Returns {@code true} if attention service is supported on this device. */ private boolean isAttentionServiceSupported() { @VisibleForTesting protected boolean isAttentionServiceSupported() { return isServiceEnabled() && isServiceConfigured(mContext); } @VisibleForTesting protected boolean isServiceEnabled() { private boolean isServiceEnabled() { return DeviceConfig.getBoolean(NAMESPACE_ATTENTION_MANAGER_SERVICE, KEY_SERVICE_ENABLED, DEFAULT_SERVICE_ENABLED); } Loading services/tests/servicestests/src/com/android/server/attention/AttentionManagerServiceTest.java +5 −1 Original line number Diff line number Diff line Loading @@ -99,6 +99,7 @@ public class AttentionManagerServiceTest { AttentionCheck attentionCheck = new AttentionCheck(mMockAttentionCallbackInternal, mSpyAttentionManager); mSpyAttentionManager.mCurrentAttentionCheck = attentionCheck; mSpyAttentionManager.mService = new MockIAttentionService(); } @Test Loading @@ -115,6 +116,7 @@ public class AttentionManagerServiceTest { @Test public void testCheckAttention_returnFalseWhenPowerManagerNotInteract() throws RemoteException { doReturn(true).when(mSpyAttentionManager).isAttentionServiceSupported(); doReturn(false).when(mMockIPowerManager).isInteractive(); AttentionCallbackInternal callback = Mockito.mock(AttentionCallbackInternal.class); assertThat(mSpyAttentionManager.checkAttention(mTimeout, callback)).isFalse(); Loading @@ -122,9 +124,11 @@ public class AttentionManagerServiceTest { @Test public void testCheckAttention_callOnSuccess() throws RemoteException { doReturn(true).when(mSpyAttentionManager).isServiceEnabled(); doReturn(true).when(mSpyAttentionManager).isAttentionServiceSupported(); doReturn(true).when(mSpyAttentionManager).isServiceAvailable(); doReturn(true).when(mMockIPowerManager).isInteractive(); doNothing().when(mSpyAttentionManager).freeIfInactiveLocked(); mSpyAttentionManager.mCurrentAttentionCheck = null; AttentionCallbackInternal callback = Mockito.mock(AttentionCallbackInternal.class); mSpyAttentionManager.checkAttention(mTimeout, callback); Loading Loading
services/core/java/com/android/server/attention/AttentionManagerService.java +7 −5 Original line number Diff line number Diff line Loading @@ -108,7 +108,8 @@ public class AttentionManagerService extends SystemService { private final PowerManager mPowerManager; private final Object mLock; @GuardedBy("mLock") private IAttentionService mService; @VisibleForTesting protected IAttentionService mService; @GuardedBy("mLock") private AttentionCheckCacheBuffer mAttentionCheckCacheBuffer; @GuardedBy("mLock") Loading Loading @@ -158,7 +159,8 @@ public class AttentionManagerService extends SystemService { } /** Resolves and sets up the attention service if it had not been done yet. */ private boolean isServiceAvailable() { @VisibleForTesting protected boolean isServiceAvailable() { if (mComponentName == null) { mComponentName = resolveAttentionService(mContext); } Loading @@ -168,12 +170,12 @@ public class AttentionManagerService extends SystemService { /** * Returns {@code true} if attention service is supported on this device. */ private boolean isAttentionServiceSupported() { @VisibleForTesting protected boolean isAttentionServiceSupported() { return isServiceEnabled() && isServiceConfigured(mContext); } @VisibleForTesting protected boolean isServiceEnabled() { private boolean isServiceEnabled() { return DeviceConfig.getBoolean(NAMESPACE_ATTENTION_MANAGER_SERVICE, KEY_SERVICE_ENABLED, DEFAULT_SERVICE_ENABLED); } Loading
services/tests/servicestests/src/com/android/server/attention/AttentionManagerServiceTest.java +5 −1 Original line number Diff line number Diff line Loading @@ -99,6 +99,7 @@ public class AttentionManagerServiceTest { AttentionCheck attentionCheck = new AttentionCheck(mMockAttentionCallbackInternal, mSpyAttentionManager); mSpyAttentionManager.mCurrentAttentionCheck = attentionCheck; mSpyAttentionManager.mService = new MockIAttentionService(); } @Test Loading @@ -115,6 +116,7 @@ public class AttentionManagerServiceTest { @Test public void testCheckAttention_returnFalseWhenPowerManagerNotInteract() throws RemoteException { doReturn(true).when(mSpyAttentionManager).isAttentionServiceSupported(); doReturn(false).when(mMockIPowerManager).isInteractive(); AttentionCallbackInternal callback = Mockito.mock(AttentionCallbackInternal.class); assertThat(mSpyAttentionManager.checkAttention(mTimeout, callback)).isFalse(); Loading @@ -122,9 +124,11 @@ public class AttentionManagerServiceTest { @Test public void testCheckAttention_callOnSuccess() throws RemoteException { doReturn(true).when(mSpyAttentionManager).isServiceEnabled(); doReturn(true).when(mSpyAttentionManager).isAttentionServiceSupported(); doReturn(true).when(mSpyAttentionManager).isServiceAvailable(); doReturn(true).when(mMockIPowerManager).isInteractive(); doNothing().when(mSpyAttentionManager).freeIfInactiveLocked(); mSpyAttentionManager.mCurrentAttentionCheck = null; AttentionCallbackInternal callback = Mockito.mock(AttentionCallbackInternal.class); mSpyAttentionManager.checkAttention(mTimeout, callback); Loading