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

Re-landing of commit 43cd49fa85
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
This commit is contained in:
Daniel Norman
2023-05-31 23:07:36 +00:00
parent 5b77c3c822
commit fe61b55650

View File

@@ -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.