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

Commit c713bed2 authored by Riley Jones's avatar Riley Jones Committed by Android (Google) Code Review
Browse files

Merge "Fix for a11yManagerService broadcastReceiver ANR" into 24D1-dev

parents f5d7df51 fb4cfc76
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -82,6 +82,16 @@ flag {
    }
}

flag {
    name: "manager_avoid_receiver_timeout"
    namespace: "accessibility"
    description: "Avoid broadcast receiver timeout by offloading potentially slow operations to the background thread."
    bug: "333890389"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "pinch_zoom_zero_min_span"
    namespace: "accessibility"
+49 −31
Original line number Diff line number Diff line
@@ -1028,37 +1028,10 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
                            "context=" + context + ";intent=" + intent);
                }

                String action = intent.getAction();
                if (Intent.ACTION_USER_SWITCHED.equals(action)) {
                    switchUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
                } else if (Intent.ACTION_USER_UNLOCKED.equals(action)) {
                    unlockUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
                } else if (Intent.ACTION_USER_REMOVED.equals(action)) {
                    removeUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
                } else if (Intent.ACTION_SETTING_RESTORED.equals(action)) {
                    final String which = intent.getStringExtra(Intent.EXTRA_SETTING_NAME);
                    if (Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES.equals(which)) {
                        synchronized (mLock) {
                            restoreEnabledAccessibilityServicesLocked(
                                    intent.getStringExtra(Intent.EXTRA_SETTING_PREVIOUS_VALUE),
                                    intent.getStringExtra(Intent.EXTRA_SETTING_NEW_VALUE),
                                    intent.getIntExtra(Intent.EXTRA_SETTING_RESTORED_FROM_SDK_INT,
                                            0));
                        }
                    } else if (ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED.equals(which)) {
                        synchronized (mLock) {
                            restoreLegacyDisplayMagnificationNavBarIfNeededLocked(
                                    intent.getStringExtra(Intent.EXTRA_SETTING_NEW_VALUE),
                                    intent.getIntExtra(Intent.EXTRA_SETTING_RESTORED_FROM_SDK_INT,
                                            0));
                        }
                    } else if (Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS.equals(which)) {
                        synchronized (mLock) {
                            restoreAccessibilityButtonTargetsLocked(
                                    intent.getStringExtra(Intent.EXTRA_SETTING_PREVIOUS_VALUE),
                                    intent.getStringExtra(Intent.EXTRA_SETTING_NEW_VALUE));
                        }
                    }
                if (com.android.server.accessibility.Flags.managerAvoidReceiverTimeout()) {
                    BackgroundThread.getHandler().post(() -> processBroadcast(intent));
                } else {
                    processBroadcast(intent);
                }
            }
        }, UserHandle.ALL, intentFilter, null, null);
@@ -1981,6 +1954,19 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
        mA11yWindowManager.onTouchInteractionEnd();
    }

    private void processBroadcast(Intent intent) {
        String action = intent.getAction();
        if (Intent.ACTION_USER_SWITCHED.equals(action)) {
            switchUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
        } else if (Intent.ACTION_USER_UNLOCKED.equals(action)) {
            unlockUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
        } else if (Intent.ACTION_USER_REMOVED.equals(action)) {
            removeUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
        } else if (Intent.ACTION_SETTING_RESTORED.equals(action)) {
            restoreSetting(intent);
        }
    }

    @VisibleForTesting
    void switchUser(int userId) {
        mMagnificationController.updateUserIdIfNeeded(userId);
@@ -2079,6 +2065,38 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
        getMagnificationController().onUserRemoved(userId);
    }

    private void restoreSetting(Intent intent) {
        final String which = intent.getStringExtra(Intent.EXTRA_SETTING_NAME);
        if (Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES.equals(which)) {
            synchronized (mLock) {
                restoreEnabledAccessibilityServicesLocked(
                        intent.getStringExtra(Intent.EXTRA_SETTING_PREVIOUS_VALUE),
                        intent.getStringExtra(Intent.EXTRA_SETTING_NEW_VALUE),
                        intent.getIntExtra(Intent.EXTRA_SETTING_RESTORED_FROM_SDK_INT,
                                0));
            }
        } else if (ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED.equals(which)) {
            synchronized (mLock) {
                restoreLegacyDisplayMagnificationNavBarIfNeededLocked(
                        intent.getStringExtra(Intent.EXTRA_SETTING_NEW_VALUE),
                        intent.getIntExtra(Intent.EXTRA_SETTING_RESTORED_FROM_SDK_INT,
                                0));
            }
        } else if (Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS.equals(which)) {
            synchronized (mLock) {
                restoreAccessibilityButtonTargetsLocked(
                        intent.getStringExtra(Intent.EXTRA_SETTING_PREVIOUS_VALUE),
                        intent.getStringExtra(Intent.EXTRA_SETTING_NEW_VALUE));
            }
        } else if (Settings.Secure.ACCESSIBILITY_QS_TARGETS.equals(which)) {
            if (!android.view.accessibility.Flags.a11yQsShortcut()) {
                return;
            }
            restoreAccessibilityQsTargets(
                    intent.getStringExtra(Intent.EXTRA_SETTING_NEW_VALUE));
        }
    }

    // Called only during settings restore; currently supports only the owner user
    // TODO: http://b/22388012
    void restoreEnabledAccessibilityServicesLocked(String oldSetting, String newSetting,