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

Commit 9dc1c23d authored by Josh Hou's avatar Josh Hou
Browse files

Fix CTS failed test cases issue

Take the user's context to get PackageManager#getInstallSourceInfo API

Bug: 274199130
Test: atest LocaleConfigAppUpdateTest
      atest LocaleManagerOverrideLocaleConfigTest
      atest LocaleManagerTests
Change-Id: I2721991d033e4c3cd59a24ea353818abf2947c3f
parent 9b6e5783
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -323,7 +323,7 @@ public class LocaleManagerService extends SystemService {
     */
    void notifyInstallerOfAppWhoseLocaleChanged(String appPackageName, int userId,
            LocaleList locales) {
        String installingPackageName = getInstallingPackageName(appPackageName);
        String installingPackageName = getInstallingPackageName(appPackageName, userId);
        if (installingPackageName != null) {
            Intent intent = createBaseIntent(Intent.ACTION_APPLICATION_LOCALE_CHANGED,
                    appPackageName, locales);
@@ -464,7 +464,7 @@ public class LocaleManagerService extends SystemService {
     * Checks if the calling app is the installer of the app whose locale changed.
     */
    private boolean isCallerInstaller(String appPackageName, int userId) {
        String installingPackageName = getInstallingPackageName(appPackageName);
        String installingPackageName = getInstallingPackageName(appPackageName, userId);
        if (installingPackageName != null) {
            // Get the uid of installer-on-record to compare with the calling uid.
            int installerUid = getPackageUid(installingPackageName, userId);
@@ -513,10 +513,11 @@ public class LocaleManagerService extends SystemService {
    }

    @Nullable
    String getInstallingPackageName(String packageName) {
    String getInstallingPackageName(String packageName, int userId) {
        try {
            return mContext.getPackageManager()
                    .getInstallSourceInfo(packageName).getInstallingPackageName();
            return mContext.createContextAsUser(UserHandle.of(userId), /* flags= */
                    0).getPackageManager().getInstallSourceInfo(
                    packageName).getInstallingPackageName();
        } catch (PackageManager.NameNotFoundException e) {
            Slog.w(TAG, "Package not found " + packageName);
        }
+2 −2
Original line number Diff line number Diff line
@@ -152,9 +152,10 @@ public class SystemAppUpdateTracker {
    void onPackageUpdateFinished(String packageName, int uid) {
        try {
            if ((!mUpdatedApps.contains(packageName)) && isUpdatedSystemApp(packageName)) {
                int userId = UserHandle.getUserId(uid);
                // If a system app is updated, verify that it has an installer-on-record.
                String installingPackageName = mLocaleManagerService.getInstallingPackageName(
                        packageName);
                        packageName, userId);
                if (installingPackageName == null) {
                    // We want to broadcast the locales info to the installer.
                    // If this app does not have an installer then do nothing.
@@ -162,7 +163,6 @@ public class SystemAppUpdateTracker {
                }

                try {
                    int userId = UserHandle.getUserId(uid);
                    // Fetch the app-specific locales.
                    // If non-empty then send the info to the installer.
                    LocaleList appLocales = mLocaleManagerService.getApplicationLocales(
+1 −0
Original line number Diff line number Diff line
@@ -105,6 +105,7 @@ public class LocaleManagerServiceTest {
        mMockPackageManager = mock(PackageManager.class);
        mMockPackageMonitor = mock(PackageMonitor.class);

        doReturn(mMockContext).when(mMockContext).createContextAsUser(any(), anyInt());
        // For unit tests, set the default installer info
        doReturn(DEFAULT_INSTALL_SOURCE_INFO).when(mMockPackageManager)
                .getInstallSourceInfo(anyString());
+1 −0
Original line number Diff line number Diff line
@@ -131,6 +131,7 @@ public class SystemAppUpdateTrackerTest {
        doReturn(mMockPackageManager).when(mMockContext).getPackageManager();
        doReturn(InstrumentationRegistry.getContext().getContentResolver())
                .when(mMockContext).getContentResolver();
        doReturn(mMockContext).when(mMockContext).createContextAsUser(any(), anyInt());

        mStoragefile = new AtomicFile(new File(
                Environment.getExternalStorageDirectory(), "systemUpdateUnitTests.xml"));