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

Commit fe61b556 authored by Daniel Norman's avatar Daniel Norman
Browse files

Attempt v2 of "Disables non-system AccessibilityMenu for secondary users."

Re-landing of commit 43cd49fa
but uses createContextAsUser instead of createPackageContextAsUser.
createPackageContextAsUser looks up the package info for non-system
packages, which caused a boottime regression for A11yManagerService
from 5ms to ~40ms. This new version has no regression and functions
the same for our purposes.

Bug: 284196235
Test: Create secondary user, observe only one Accessibility Menu entry
      in Settings > Accessibility.
Test: v2/android-crystalball-eng/asit/perf/boottime_test
      locally and with go/abtd
Change-Id: I8410d818891690d9d3307897b168b94125d41b16
parent 5b77c3c8
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -958,7 +958,13 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
        final ComponentName menuToMigrate =
                AccessibilityUtils.getAccessibilityMenuComponentToMigrate(mPackageManager, userId);
        if (menuToMigrate != null) {
            mPackageManager.setComponentEnabledSetting(
            // PackageManager#setComponentEnabledSetting disables the component for only the user
            // linked to PackageManager's context, but mPackageManager is linked to the system user,
            // so grab a new PackageManager for the current user to support secondary users.
            final PackageManager userPackageManager =
                    mContext.createContextAsUser(UserHandle.of(userId), /* flags = */ 0)
                            .getPackageManager();
            userPackageManager.setComponentEnabledSetting(
                    menuToMigrate,
                    PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                    PackageManager.DONT_KILL_APP);
@@ -1845,6 +1851,9 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
            // find out a way to detect the device finished the OTA and switch the user.
            migrateAccessibilityButtonSettingsIfNecessaryLocked(userState, null,
                    /* restoreFromSdkInt = */0);
            // Package components are disabled per user, so secondary users also need their migrated
            // Accessibility Menu component disabled.
            disableAccessibilityMenuToMigrateIfNeeded();

            if (announceNewUser) {
                // Schedule announcement of the current user if needed.