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

Commit 7a6cc9b5 authored by Phil Weaver's avatar Phil Weaver
Browse files

Consolidate a11y unit tests and get them working

Moving tests for accessibility manager into the a11y
directory and getting them to use some of the newer
test infrastructure. Minor tweaks to
AccessibilityManager to make it testable.

Deleting the AccessibilityManagerService tests entirely.
This class is difficult to unit test with the current
infrastructure, but is covered in CTS tests to a large
degree. I wasn't able to get these working quickly, and
they rely on timeouts that make them run much slower than
the other tests. They also throw exceptions when their
mock accessibility services receive accessibility events,
which causes the system to blacklist those services, causing
the tests to fail differently until the system is reset.
I think it's better to focus on writing new, more robust
tests than on rewriting these tests to pass.

Bug: 36614219
Test: A11y unit tests now work.
Change-Id: I8effe44f22110d55ebb700dc46f59b7e7a1aa946
(cherry picked from commit 9213d231)
parent c01dd791
Loading
Loading
Loading
Loading
+22 −12
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.util.Log;
import android.view.IWindow;
import android.view.View;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.IntPair;

import java.util.ArrayList;
@@ -126,6 +127,8 @@ public final class AccessibilityManager {

    final Handler mHandler;

    final Handler.Callback mCallback;

    boolean mIsEnabled;

    int mRelevantEventTypes = AccessibilityEvent.TYPES_ALL_MASK;
@@ -217,12 +220,12 @@ public final class AccessibilityManager {
            // is now off an exception will be thrown. We want to have the exception
            // enforcement to guard against apps that fire unnecessary accessibility
            // events when accessibility is off.
            mHandler.obtainMessage(MyHandler.MSG_SET_STATE, state, 0).sendToTarget();
            mHandler.obtainMessage(MyCallback.MSG_SET_STATE, state, 0).sendToTarget();
        }

        @Override
        public void notifyServicesStateChanged() {
            mHandler.obtainMessage(MyHandler.MSG_NOTIFY_SERVICES_STATE_CHANGED).sendToTarget();
            mHandler.obtainMessage(MyCallback.MSG_NOTIFY_SERVICES_STATE_CHANGED).sendToTarget();
        }

        @Override
@@ -271,7 +274,8 @@ public final class AccessibilityManager {
    public AccessibilityManager(Context context, IAccessibilityManager service, int userId) {
        // Constructor can't be chained because we can't create an instance of an inner class
        // before calling another constructor.
        mHandler = new MyHandler(context.getMainLooper());
        mCallback = new MyCallback();
        mHandler = new Handler(context.getMainLooper(), mCallback);
        mUserId = userId;
        synchronized (mLock) {
            tryConnectToServiceLocked(service);
@@ -288,6 +292,7 @@ public final class AccessibilityManager {
     * @hide
     */
    public AccessibilityManager(Handler handler, IAccessibilityManager service, int userId) {
        mCallback = new MyCallback();
        mHandler = handler;
        mUserId = userId;
        synchronized (mLock) {
@@ -302,6 +307,14 @@ public final class AccessibilityManager {
        return mClient;
    }

    /**
     * @hide
     */
    @VisibleForTesting
    public Handler.Callback getCallback() {
        return mCallback;
    }

    /**
     * Returns if the accessibility in the system is enabled.
     *
@@ -711,15 +724,15 @@ public final class AccessibilityManager {
        mIsHighTextContrastEnabled = highTextContrastEnabled;

        if (wasEnabled != enabled) {
            mHandler.sendEmptyMessage(MyHandler.MSG_NOTIFY_ACCESSIBILITY_STATE_CHANGED);
            mHandler.sendEmptyMessage(MyCallback.MSG_NOTIFY_ACCESSIBILITY_STATE_CHANGED);
        }

        if (wasTouchExplorationEnabled != touchExplorationEnabled) {
            mHandler.sendEmptyMessage(MyHandler.MSG_NOTIFY_EXPLORATION_STATE_CHANGED);
            mHandler.sendEmptyMessage(MyCallback.MSG_NOTIFY_EXPLORATION_STATE_CHANGED);
        }

        if (wasHighTextContrastEnabled != highTextContrastEnabled) {
            mHandler.sendEmptyMessage(MyHandler.MSG_NOTIFY_HIGH_TEXT_CONTRAST_STATE_CHANGED);
            mHandler.sendEmptyMessage(MyCallback.MSG_NOTIFY_HIGH_TEXT_CONTRAST_STATE_CHANGED);
        }
    }

@@ -960,19 +973,15 @@ public final class AccessibilityManager {
        }
    }

    private final class MyHandler extends Handler {
    private final class MyCallback implements Handler.Callback {
        public static final int MSG_NOTIFY_ACCESSIBILITY_STATE_CHANGED = 1;
        public static final int MSG_NOTIFY_EXPLORATION_STATE_CHANGED = 2;
        public static final int MSG_NOTIFY_HIGH_TEXT_CONTRAST_STATE_CHANGED = 3;
        public static final int MSG_SET_STATE = 4;
        public static final int MSG_NOTIFY_SERVICES_STATE_CHANGED = 5;

        public MyHandler(Looper looper) {
            super(looper, null, false);
        }

        @Override
        public void handleMessage(Message message) {
        public boolean handleMessage(Message message) {
            switch (message.what) {
                case MSG_NOTIFY_ACCESSIBILITY_STATE_CHANGED: {
                    handleNotifyAccessibilityStateChanged();
@@ -998,6 +1007,7 @@ public final class AccessibilityManager {
                    }
                } break;
            }
            return true;
        }
    }
}
+0 −14
Original line number Diff line number Diff line
@@ -52,20 +52,6 @@
    <application>
        <uses-library android:name="android.test.runner" />

        <service android:name="com.android.server.AccessibilityManagerServiceTest$MyFirstMockAccessibilityService"
            android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
          <intent-filter>
            <action android:name="android.accessibilityservice.AccessibilityService"/>
          </intent-filter>
        </service>

        <service android:name="com.android.server.AccessibilityManagerServiceTest$MySecondMockAccessibilityService"
            android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
          <intent-filter>
            <action android:name="android.accessibilityservice.AccessibilityService"/>
          </intent-filter>
        </service>

        <service android:name="com.android.server.accounts.TestAccountType1AuthenticatorService"
            android:exported="false">
          <intent-filter>
Loading