Loading core/java/android/attention/AttentionManagerInternal.java +5 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,11 @@ public abstract class AttentionManagerInternal { */ public abstract boolean isAttentionServiceSupported(); /** * Returns {@code true} if proximity update is supported by the service. */ public abstract boolean isProximitySupported(); /** * Checks whether user attention is at the screen and calls in the provided callback. * Loading core/res/res/values/config.xml +4 −0 Original line number Diff line number Diff line Loading @@ -192,6 +192,10 @@ available on some devices. --> <bool name="config_enableHapticTextHandle">false</bool> <!-- Enables or disables proximity service that approximates proximity with aiai attention service. Off by default, since the service may not be available on some devices. --> <bool name="config_enableProximityService">false</bool> <!-- Whether dialogs should close automatically when the user touches outside of them. This should not normally be modified. --> <bool name="config_closeDialogWhenTouchOutside">true</bool> Loading core/res/res/values/symbols.xml +1 −0 Original line number Diff line number Diff line Loading @@ -416,6 +416,7 @@ <java-symbol type="bool" name="config_guestUserAllowEphemeralStateChange" /> <java-symbol type="bool" name="config_localDisplaysMirrorContent" /> <java-symbol type="bool" name="config_ignoreUdfpsVote" /> <java-symbol type="bool" name="config_enableProximityService" /> <java-symbol type="array" name="config_localPrivateDisplayPorts" /> <java-symbol type="integer" name="config_defaultDisplayDefaultColorMode" /> <java-symbol type="bool" name="config_enableAppWidgetService" /> Loading services/core/java/com/android/server/attention/AttentionManagerService.java +14 −2 Original line number Diff line number Diff line Loading @@ -96,12 +96,15 @@ public class AttentionManagerService extends SystemService { @VisibleForTesting static final String KEY_SERVICE_ENABLED = "service_enabled"; /** Default value in absence of {@link DeviceConfig} override. */ /** Default service enabled value in absence of {@link DeviceConfig} override. */ private static final boolean DEFAULT_SERVICE_ENABLED = true; @VisibleForTesting boolean mIsServiceEnabled; @VisibleForTesting boolean mIsProximityEnabled; /** * DeviceConfig flag name, describes how much time we consider a result fresh; if the check * attention called within that period - cached value will be returned. Loading Loading @@ -180,6 +183,9 @@ public class AttentionManagerService extends SystemService { DeviceConfig.addOnPropertiesChangedListener(NAMESPACE_ATTENTION_MANAGER_SERVICE, ActivityThread.currentApplication().getMainExecutor(), (properties) -> onDeviceConfigChange(properties.getKeyset())); mIsProximityEnabled = mContext.getResources() .getBoolean(com.android.internal.R.bool.config_enableProximityService); Slog.i(LOG_TAG, "mIsProximityEnabled is: " + mIsProximityEnabled); } } Loading Loading @@ -351,7 +357,7 @@ public class AttentionManagerService extends SystemService { @VisibleForTesting boolean onStartProximityUpdates(ProximityUpdateCallbackInternal callbackInternal) { Objects.requireNonNull(callbackInternal); if (!mIsServiceEnabled) { if (!mIsProximityEnabled) { Slog.w(LOG_TAG, "Trying to call onProximityUpdate() on an unsupported device."); return false; } Loading Loading @@ -488,6 +494,7 @@ public class AttentionManagerService extends SystemService { private void dumpInternal(IndentingPrintWriter ipw) { ipw.println("Attention Manager Service (dumpsys attention) state:\n"); ipw.println("isServiceEnabled=" + mIsServiceEnabled); ipw.println("mIsProximityEnabled=" + mIsProximityEnabled); ipw.println("mStaleAfterMillis=" + mStaleAfterMillis); ipw.println("AttentionServicePackageName=" + getServiceConfigPackage(mContext)); ipw.println("Resolved component:"); Loading Loading @@ -518,6 +525,11 @@ public class AttentionManagerService extends SystemService { return AttentionManagerService.this.mIsServiceEnabled; } @Override public boolean isProximitySupported() { return AttentionManagerService.this.mIsProximityEnabled; } @Override public boolean checkAttention(long timeout, AttentionCallbackInternal callbackInternal) { return AttentionManagerService.this.checkAttention(timeout, callbackInternal); Loading services/tests/servicestests/src/com/android/server/attention/AttentionManagerServiceTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -71,6 +71,7 @@ import org.mockito.MockitoAnnotations; @SmallTest public class AttentionManagerServiceTest { private static final double PROXIMITY_SUCCESS_STATE = 1.0; private AttentionManagerService mSpyAttentionManager; private final int mTimeout = 1000; private final Object mLock = new Object(); Loading Loading @@ -124,9 +125,20 @@ public class AttentionManagerServiceTest { .isFalse(); } @Test public void testRegisterProximityUpdates_returnFalseWhenProximityDisabled() { mSpyAttentionManager.mIsServiceEnabled = true; mSpyAttentionManager.mIsProximityEnabled = false; assertThat(mSpyAttentionManager.onStartProximityUpdates( mMockProximityUpdateCallbackInternal)) .isFalse(); } @Test public void testRegisterProximityUpdates_returnFalseWhenServiceUnavailable() { mSpyAttentionManager.mIsServiceEnabled = true; mSpyAttentionManager.mIsProximityEnabled = true; doReturn(false).when(mSpyAttentionManager).isServiceAvailable(); assertThat(mSpyAttentionManager.onStartProximityUpdates( Loading @@ -138,6 +150,7 @@ public class AttentionManagerServiceTest { public void testRegisterProximityUpdates_returnFalseWhenPowerManagerNotInteract() throws RemoteException { mSpyAttentionManager.mIsServiceEnabled = true; mSpyAttentionManager.mIsProximityEnabled = true; doReturn(true).when(mSpyAttentionManager).isServiceAvailable(); doReturn(false).when(mMockIPowerManager).isInteractive(); Loading @@ -149,6 +162,7 @@ public class AttentionManagerServiceTest { @Test public void testRegisterProximityUpdates_callOnSuccess() throws RemoteException { mSpyAttentionManager.mIsServiceEnabled = true; mSpyAttentionManager.mIsProximityEnabled = true; doReturn(true).when(mSpyAttentionManager).isServiceAvailable(); doReturn(true).when(mMockIPowerManager).isInteractive(); Loading @@ -162,6 +176,7 @@ public class AttentionManagerServiceTest { @Test public void testRegisterProximityUpdates_callOnSuccessTwiceInARow() throws RemoteException { mSpyAttentionManager.mIsServiceEnabled = true; mSpyAttentionManager.mIsProximityEnabled = true; doReturn(true).when(mSpyAttentionManager).isServiceAvailable(); doReturn(true).when(mMockIPowerManager).isInteractive(); Loading @@ -188,6 +203,7 @@ public class AttentionManagerServiceTest { public void testUnregisterProximityUpdates_noCrashWhenCallbackMismatched() throws RemoteException { mSpyAttentionManager.mIsServiceEnabled = true; mSpyAttentionManager.mIsProximityEnabled = true; doReturn(true).when(mSpyAttentionManager).isServiceAvailable(); doReturn(true).when(mMockIPowerManager).isInteractive(); mSpyAttentionManager.onStartProximityUpdates(mMockProximityUpdateCallbackInternal); Loading @@ -209,6 +225,7 @@ public class AttentionManagerServiceTest { public void testUnregisterProximityUpdates_cancelRegistrationWhenMatched() throws RemoteException { mSpyAttentionManager.mIsServiceEnabled = true; mSpyAttentionManager.mIsProximityEnabled = true; doReturn(true).when(mSpyAttentionManager).isServiceAvailable(); doReturn(true).when(mMockIPowerManager).isInteractive(); mSpyAttentionManager.onStartProximityUpdates(mMockProximityUpdateCallbackInternal); Loading @@ -221,6 +238,7 @@ public class AttentionManagerServiceTest { public void testUnregisterProximityUpdates_noCrashWhenTwiceInARow() throws RemoteException { // Attention Service registers proximity updates. mSpyAttentionManager.mIsServiceEnabled = true; mSpyAttentionManager.mIsProximityEnabled = true; doReturn(true).when(mSpyAttentionManager).isServiceAvailable(); doReturn(true).when(mMockIPowerManager).isInteractive(); mSpyAttentionManager.onStartProximityUpdates(mMockProximityUpdateCallbackInternal); Loading Loading @@ -248,6 +266,7 @@ public class AttentionManagerServiceTest { @Test public void testCheckAttention_returnFalseWhenPowerManagerNotInteract() throws RemoteException { mSpyAttentionManager.mIsServiceEnabled = true; mSpyAttentionManager.mIsProximityEnabled = true; doReturn(false).when(mMockIPowerManager).isInteractive(); AttentionCallbackInternal callback = Mockito.mock(AttentionCallbackInternal.class); assertThat(mSpyAttentionManager.checkAttention(mTimeout, callback)).isFalse(); Loading @@ -256,6 +275,7 @@ public class AttentionManagerServiceTest { @Test public void testCheckAttention_callOnSuccess() throws RemoteException { mSpyAttentionManager.mIsServiceEnabled = true; mSpyAttentionManager.mIsProximityEnabled = true; doReturn(true).when(mSpyAttentionManager).isServiceAvailable(); doReturn(true).when(mMockIPowerManager).isInteractive(); mSpyAttentionManager.mCurrentAttentionCheck = null; Loading Loading
core/java/android/attention/AttentionManagerInternal.java +5 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,11 @@ public abstract class AttentionManagerInternal { */ public abstract boolean isAttentionServiceSupported(); /** * Returns {@code true} if proximity update is supported by the service. */ public abstract boolean isProximitySupported(); /** * Checks whether user attention is at the screen and calls in the provided callback. * Loading
core/res/res/values/config.xml +4 −0 Original line number Diff line number Diff line Loading @@ -192,6 +192,10 @@ available on some devices. --> <bool name="config_enableHapticTextHandle">false</bool> <!-- Enables or disables proximity service that approximates proximity with aiai attention service. Off by default, since the service may not be available on some devices. --> <bool name="config_enableProximityService">false</bool> <!-- Whether dialogs should close automatically when the user touches outside of them. This should not normally be modified. --> <bool name="config_closeDialogWhenTouchOutside">true</bool> Loading
core/res/res/values/symbols.xml +1 −0 Original line number Diff line number Diff line Loading @@ -416,6 +416,7 @@ <java-symbol type="bool" name="config_guestUserAllowEphemeralStateChange" /> <java-symbol type="bool" name="config_localDisplaysMirrorContent" /> <java-symbol type="bool" name="config_ignoreUdfpsVote" /> <java-symbol type="bool" name="config_enableProximityService" /> <java-symbol type="array" name="config_localPrivateDisplayPorts" /> <java-symbol type="integer" name="config_defaultDisplayDefaultColorMode" /> <java-symbol type="bool" name="config_enableAppWidgetService" /> Loading
services/core/java/com/android/server/attention/AttentionManagerService.java +14 −2 Original line number Diff line number Diff line Loading @@ -96,12 +96,15 @@ public class AttentionManagerService extends SystemService { @VisibleForTesting static final String KEY_SERVICE_ENABLED = "service_enabled"; /** Default value in absence of {@link DeviceConfig} override. */ /** Default service enabled value in absence of {@link DeviceConfig} override. */ private static final boolean DEFAULT_SERVICE_ENABLED = true; @VisibleForTesting boolean mIsServiceEnabled; @VisibleForTesting boolean mIsProximityEnabled; /** * DeviceConfig flag name, describes how much time we consider a result fresh; if the check * attention called within that period - cached value will be returned. Loading Loading @@ -180,6 +183,9 @@ public class AttentionManagerService extends SystemService { DeviceConfig.addOnPropertiesChangedListener(NAMESPACE_ATTENTION_MANAGER_SERVICE, ActivityThread.currentApplication().getMainExecutor(), (properties) -> onDeviceConfigChange(properties.getKeyset())); mIsProximityEnabled = mContext.getResources() .getBoolean(com.android.internal.R.bool.config_enableProximityService); Slog.i(LOG_TAG, "mIsProximityEnabled is: " + mIsProximityEnabled); } } Loading Loading @@ -351,7 +357,7 @@ public class AttentionManagerService extends SystemService { @VisibleForTesting boolean onStartProximityUpdates(ProximityUpdateCallbackInternal callbackInternal) { Objects.requireNonNull(callbackInternal); if (!mIsServiceEnabled) { if (!mIsProximityEnabled) { Slog.w(LOG_TAG, "Trying to call onProximityUpdate() on an unsupported device."); return false; } Loading Loading @@ -488,6 +494,7 @@ public class AttentionManagerService extends SystemService { private void dumpInternal(IndentingPrintWriter ipw) { ipw.println("Attention Manager Service (dumpsys attention) state:\n"); ipw.println("isServiceEnabled=" + mIsServiceEnabled); ipw.println("mIsProximityEnabled=" + mIsProximityEnabled); ipw.println("mStaleAfterMillis=" + mStaleAfterMillis); ipw.println("AttentionServicePackageName=" + getServiceConfigPackage(mContext)); ipw.println("Resolved component:"); Loading Loading @@ -518,6 +525,11 @@ public class AttentionManagerService extends SystemService { return AttentionManagerService.this.mIsServiceEnabled; } @Override public boolean isProximitySupported() { return AttentionManagerService.this.mIsProximityEnabled; } @Override public boolean checkAttention(long timeout, AttentionCallbackInternal callbackInternal) { return AttentionManagerService.this.checkAttention(timeout, callbackInternal); Loading
services/tests/servicestests/src/com/android/server/attention/AttentionManagerServiceTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -71,6 +71,7 @@ import org.mockito.MockitoAnnotations; @SmallTest public class AttentionManagerServiceTest { private static final double PROXIMITY_SUCCESS_STATE = 1.0; private AttentionManagerService mSpyAttentionManager; private final int mTimeout = 1000; private final Object mLock = new Object(); Loading Loading @@ -124,9 +125,20 @@ public class AttentionManagerServiceTest { .isFalse(); } @Test public void testRegisterProximityUpdates_returnFalseWhenProximityDisabled() { mSpyAttentionManager.mIsServiceEnabled = true; mSpyAttentionManager.mIsProximityEnabled = false; assertThat(mSpyAttentionManager.onStartProximityUpdates( mMockProximityUpdateCallbackInternal)) .isFalse(); } @Test public void testRegisterProximityUpdates_returnFalseWhenServiceUnavailable() { mSpyAttentionManager.mIsServiceEnabled = true; mSpyAttentionManager.mIsProximityEnabled = true; doReturn(false).when(mSpyAttentionManager).isServiceAvailable(); assertThat(mSpyAttentionManager.onStartProximityUpdates( Loading @@ -138,6 +150,7 @@ public class AttentionManagerServiceTest { public void testRegisterProximityUpdates_returnFalseWhenPowerManagerNotInteract() throws RemoteException { mSpyAttentionManager.mIsServiceEnabled = true; mSpyAttentionManager.mIsProximityEnabled = true; doReturn(true).when(mSpyAttentionManager).isServiceAvailable(); doReturn(false).when(mMockIPowerManager).isInteractive(); Loading @@ -149,6 +162,7 @@ public class AttentionManagerServiceTest { @Test public void testRegisterProximityUpdates_callOnSuccess() throws RemoteException { mSpyAttentionManager.mIsServiceEnabled = true; mSpyAttentionManager.mIsProximityEnabled = true; doReturn(true).when(mSpyAttentionManager).isServiceAvailable(); doReturn(true).when(mMockIPowerManager).isInteractive(); Loading @@ -162,6 +176,7 @@ public class AttentionManagerServiceTest { @Test public void testRegisterProximityUpdates_callOnSuccessTwiceInARow() throws RemoteException { mSpyAttentionManager.mIsServiceEnabled = true; mSpyAttentionManager.mIsProximityEnabled = true; doReturn(true).when(mSpyAttentionManager).isServiceAvailable(); doReturn(true).when(mMockIPowerManager).isInteractive(); Loading @@ -188,6 +203,7 @@ public class AttentionManagerServiceTest { public void testUnregisterProximityUpdates_noCrashWhenCallbackMismatched() throws RemoteException { mSpyAttentionManager.mIsServiceEnabled = true; mSpyAttentionManager.mIsProximityEnabled = true; doReturn(true).when(mSpyAttentionManager).isServiceAvailable(); doReturn(true).when(mMockIPowerManager).isInteractive(); mSpyAttentionManager.onStartProximityUpdates(mMockProximityUpdateCallbackInternal); Loading @@ -209,6 +225,7 @@ public class AttentionManagerServiceTest { public void testUnregisterProximityUpdates_cancelRegistrationWhenMatched() throws RemoteException { mSpyAttentionManager.mIsServiceEnabled = true; mSpyAttentionManager.mIsProximityEnabled = true; doReturn(true).when(mSpyAttentionManager).isServiceAvailable(); doReturn(true).when(mMockIPowerManager).isInteractive(); mSpyAttentionManager.onStartProximityUpdates(mMockProximityUpdateCallbackInternal); Loading @@ -221,6 +238,7 @@ public class AttentionManagerServiceTest { public void testUnregisterProximityUpdates_noCrashWhenTwiceInARow() throws RemoteException { // Attention Service registers proximity updates. mSpyAttentionManager.mIsServiceEnabled = true; mSpyAttentionManager.mIsProximityEnabled = true; doReturn(true).when(mSpyAttentionManager).isServiceAvailable(); doReturn(true).when(mMockIPowerManager).isInteractive(); mSpyAttentionManager.onStartProximityUpdates(mMockProximityUpdateCallbackInternal); Loading Loading @@ -248,6 +266,7 @@ public class AttentionManagerServiceTest { @Test public void testCheckAttention_returnFalseWhenPowerManagerNotInteract() throws RemoteException { mSpyAttentionManager.mIsServiceEnabled = true; mSpyAttentionManager.mIsProximityEnabled = true; doReturn(false).when(mMockIPowerManager).isInteractive(); AttentionCallbackInternal callback = Mockito.mock(AttentionCallbackInternal.class); assertThat(mSpyAttentionManager.checkAttention(mTimeout, callback)).isFalse(); Loading @@ -256,6 +275,7 @@ public class AttentionManagerServiceTest { @Test public void testCheckAttention_callOnSuccess() throws RemoteException { mSpyAttentionManager.mIsServiceEnabled = true; mSpyAttentionManager.mIsProximityEnabled = true; doReturn(true).when(mSpyAttentionManager).isServiceAvailable(); doReturn(true).when(mMockIPowerManager).isInteractive(); mSpyAttentionManager.mCurrentAttentionCheck = null; Loading