Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4532856f authored by Daniel's avatar Daniel
Browse files

Add isProximitySupported endpoint to AttentionManagerService

AttentionManagerService will read android config value that tells whether the
proximity update is supported by the Attention Service. The
AttentionManagerService will return whether the proximity feature is
enabled based on this config value.

By default, the config_enableProximityService will be false.

Test: atest AttentionManagerServiceTest, atest
CtsVoiceInteractionTestCases, atest CtsAttentionServiceDeviceTestCases
Bug: 263994901

Change-Id: Icb902c94acfa9028f28544226ce576195a7ad052
parent d9b7bb0d
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -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.
     *
+4 −0
Original line number Diff line number Diff line
@@ -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>
+1 −0
Original line number Diff line number Diff line
@@ -415,6 +415,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" />
+14 −2
Original line number Diff line number Diff line
@@ -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.
@@ -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);
        }
    }

@@ -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;
        }
@@ -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:");
@@ -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);
+20 −0
Original line number Diff line number Diff line
@@ -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();
@@ -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(
@@ -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();

@@ -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();

@@ -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();

@@ -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);
@@ -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);
@@ -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);
@@ -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();
@@ -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