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

Commit 4074e8a3 authored by Svetoslav Ganov's avatar Svetoslav Ganov
Browse files

System accessibility state update postponed if UI test autmation is running.

1. If a UI test automation accessibility service is connected to the
   system we pospone state updates in the AccessibilityManagerService
   for the moment the UI automations service dies or is disconnected.

bug:6540522

Change-Id: I48ddf603b53d2158a00edcf8ad05cfe2575d4d75
parent 53d003f0
Loading
Loading
Loading
Loading
+42 −21
Original line number Original line Diff line number Diff line
@@ -191,10 +191,13 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
            @Override
            @Override
            public void onSomePackagesChanged() {
            public void onSomePackagesChanged() {
                synchronized (mLock) {
                synchronized (mLock) {
                    // We will update when the automation service dies.
                    if (mUiAutomationService == null) {
                        populateAccessibilityServiceListLocked();
                        populateAccessibilityServiceListLocked();
                        manageServicesLocked();
                        manageServicesLocked();
                    }
                    }
                }
                }
            }


            @Override
            @Override
            public void onPackageRemoved(String packageName, int uid) {
            public void onPackageRemoved(String packageName, int uid) {
@@ -242,12 +245,15 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
            public void onReceive(Context context, Intent intent) {
            public void onReceive(Context context, Intent intent) {
                if (intent.getAction() == Intent.ACTION_BOOT_COMPLETED) {
                if (intent.getAction() == Intent.ACTION_BOOT_COMPLETED) {
                    synchronized (mLock) {
                    synchronized (mLock) {
                        // We will update when the automation service dies.
                        if (mUiAutomationService == null) {
                            populateAccessibilityServiceListLocked();
                            populateAccessibilityServiceListLocked();
                            handleAccessibilityEnabledSettingChangedLocked();
                            handleAccessibilityEnabledSettingChangedLocked();
                            handleTouchExplorationEnabledSettingChangedLocked();
                            handleTouchExplorationEnabledSettingChangedLocked();
                            updateInputFilterLocked();
                            updateInputFilterLocked();
                            sendStateToClientsLocked();
                            sendStateToClientsLocked();
                        }
                        }
                    }


                    return;
                    return;
                }
                }
@@ -294,11 +300,14 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
                public void onChange(boolean selfChange) {
                public void onChange(boolean selfChange) {
                    super.onChange(selfChange);
                    super.onChange(selfChange);
                    synchronized (mLock) {
                    synchronized (mLock) {
                        // We will update when the automation service dies.
                        if (mUiAutomationService == null) {
                            handleAccessibilityEnabledSettingChangedLocked();
                            handleAccessibilityEnabledSettingChangedLocked();
                            updateInputFilterLocked();
                            updateInputFilterLocked();
                            sendStateToClientsLocked();
                            sendStateToClientsLocked();
                        }
                        }
                    }
                    }
                }
            });
            });


        Uri touchExplorationRequestedUri = Settings.Secure.getUriFor(
        Uri touchExplorationRequestedUri = Settings.Secure.getUriFor(
@@ -309,11 +318,14 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
                    public void onChange(boolean selfChange) {
                    public void onChange(boolean selfChange) {
                        super.onChange(selfChange);
                        super.onChange(selfChange);
                        synchronized (mLock) {
                        synchronized (mLock) {
                            // We will update when the automation service dies.
                            if (mUiAutomationService == null) {
                                handleTouchExplorationEnabledSettingChangedLocked();
                                handleTouchExplorationEnabledSettingChangedLocked();
                                updateInputFilterLocked();
                                updateInputFilterLocked();
                                sendStateToClientsLocked();
                                sendStateToClientsLocked();
                            }
                            }
                        }
                        }
                    }
                });
                });


        Uri accessibilityServicesUri =
        Uri accessibilityServicesUri =
@@ -324,9 +336,12 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
                public void onChange(boolean selfChange) {
                public void onChange(boolean selfChange) {
                    super.onChange(selfChange);
                    super.onChange(selfChange);
                    synchronized (mLock) {
                    synchronized (mLock) {
                        // We will update when the automation service dies.
                        if (mUiAutomationService == null) {
                            manageServicesLocked();
                            manageServicesLocked();
                        }
                        }
                    }
                    }
                }
            });
            });
    }
    }


@@ -747,10 +762,6 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
     * Manages services by starting enabled ones and stopping disabled ones.
     * Manages services by starting enabled ones and stopping disabled ones.
     */
     */
    private void manageServicesLocked() {
    private void manageServicesLocked() {
        // While the UI automation service is running it takes over.
        if (mUiAutomationService != null) {
            return;
        }
        populateEnabledServicesLocked(mEnabledServices);
        populateEnabledServicesLocked(mEnabledServices);
        final int enabledInstalledServicesCount = updateServicesStateLocked(mInstalledServices,
        final int enabledInstalledServicesCount = updateServicesStateLocked(mInstalledServices,
                mEnabledServices);
                mEnabledServices);
@@ -926,8 +937,13 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {


    private void tryEnableTouchExploration(final Service service) {
    private void tryEnableTouchExploration(final Service service) {
        if (!mIsTouchExplorationEnabled && service.mRequestTouchExplorationMode) {
        if (!mIsTouchExplorationEnabled && service.mRequestTouchExplorationMode) {
            if (!service.mIsAutomation) {
                mMainHandler.obtainMessage(MSG_SHOW_ENABLE_TOUCH_EXPLORATION_DIALOG,
                mMainHandler.obtainMessage(MSG_SHOW_ENABLE_TOUCH_EXPLORATION_DIALOG,
                        service).sendToTarget();
                        service).sendToTarget();
            } else {
                Settings.Secure.putInt(mContext.getContentResolver(),
                        Settings.Secure.TOUCH_EXPLORATION_ENABLED, 1);
            }
        }
        }
    }
    }


@@ -1479,10 +1495,15 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
                // the state based on values in the settings database.
                // the state based on values in the settings database.
                if (mIsAutomation) {
                if (mIsAutomation) {
                    mUiAutomationService = null;
                    mUiAutomationService = null;

                    handleAccessibilityEnabledSettingChangedLocked();
                    handleAccessibilityEnabledSettingChangedLocked();
                    sendStateToClientsLocked();

                    handleTouchExplorationEnabledSettingChangedLocked();
                    handleTouchExplorationEnabledSettingChangedLocked();
                    updateInputFilterLocked();
                    updateInputFilterLocked();
                    sendStateToClientsLocked();

                    populateAccessibilityServiceListLocked();
                    manageServicesLocked();
                }
                }
            }
            }
        }
        }