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

Commit ad510146 authored by Chun-Ku Lin's avatar Chun-Ku Lin Committed by Android (Google) Code Review
Browse files

Merge "Handle component's enablement state changes" into main

parents fba10a4d d3c41a6f
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -6263,6 +6263,13 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
                }
            }
        }

        @Override
        public boolean onPackageChanged(String packageName, int uid, String[] components) {
            // We care about all package changes, not just the whole package itself which is
            // default behavior.
            return true;
        }
    }

    void sendPendingWindowStateChangedEventsForAvailableWindowLocked(int windowId) {
+32 −0
Original line number Diff line number Diff line
@@ -913,6 +913,38 @@ public class AccessibilityManagerServiceTest {
        assertThat(lockState.get()).containsExactly(false);
    }

    @Test
    public void onPackageChanged_disableComponent_updateInstalledServices() {
        // Sets up two accessibility services as installed services
        setupShortcutTargetServices();
        assertThat(mA11yms.getCurrentUserState().mInstalledServices).hasSize(2);
        AccessibilityServiceInfo installedService1 =
                mA11yms.getCurrentUserState().mInstalledServices.getFirst();
        ResolveInfo resolveInfo1 = installedService1.getResolveInfo();
        AccessibilityServiceInfo installedService2 =
                mA11yms.getCurrentUserState().mInstalledServices.getLast();

        // Disables `installedService2`
        when(mMockPackageManager.queryIntentServicesAsUser(any(), anyInt(), anyInt()))
                .thenReturn(List.of(resolveInfo1));
        when(mMockSecurityPolicy.canRegisterService(any())).thenReturn(true);
        final Intent packageIntent = new Intent(Intent.ACTION_PACKAGE_CHANGED);
        packageIntent.setData(
                Uri.parse("package:" + installedService2.getResolveInfo().serviceInfo.packageName));
        packageIntent.putExtra(Intent.EXTRA_UID, UserHandle.myUserId());
        packageIntent.putExtra(Intent.EXTRA_USER_HANDLE, mA11yms.getCurrentUserIdLocked());
        packageIntent.putExtra(Intent.EXTRA_CHANGED_COMPONENT_NAME_LIST,
                new String[]{
                        installedService2.getComponentName().flattenToString()});
        mA11yms.getPackageMonitor().doHandlePackageEvent(packageIntent);

        assertThat(mA11yms.getCurrentUserState().mInstalledServices).hasSize(1);
        ComponentName installedService =
                mA11yms.getCurrentUserState().mInstalledServices.getFirst().getComponentName();
        assertThat(installedService)
                .isEqualTo(installedService1.getComponentName());
    }

    @Test
    public void testSwitchUserScanPackages_scansWithoutHoldingLock() {
        setupAccessibilityServiceConnection(0);