Loading services/core/java/com/android/server/locales/LocaleManagerService.java +6 −5 Original line number Original line Diff line number Diff line Loading @@ -323,7 +323,7 @@ public class LocaleManagerService extends SystemService { */ */ void notifyInstallerOfAppWhoseLocaleChanged(String appPackageName, int userId, void notifyInstallerOfAppWhoseLocaleChanged(String appPackageName, int userId, LocaleList locales) { LocaleList locales) { String installingPackageName = getInstallingPackageName(appPackageName); String installingPackageName = getInstallingPackageName(appPackageName, userId); if (installingPackageName != null) { if (installingPackageName != null) { Intent intent = createBaseIntent(Intent.ACTION_APPLICATION_LOCALE_CHANGED, Intent intent = createBaseIntent(Intent.ACTION_APPLICATION_LOCALE_CHANGED, appPackageName, locales); appPackageName, locales); Loading Loading @@ -464,7 +464,7 @@ public class LocaleManagerService extends SystemService { * Checks if the calling app is the installer of the app whose locale changed. * Checks if the calling app is the installer of the app whose locale changed. */ */ private boolean isCallerInstaller(String appPackageName, int userId) { private boolean isCallerInstaller(String appPackageName, int userId) { String installingPackageName = getInstallingPackageName(appPackageName); String installingPackageName = getInstallingPackageName(appPackageName, userId); if (installingPackageName != null) { if (installingPackageName != null) { // Get the uid of installer-on-record to compare with the calling uid. // Get the uid of installer-on-record to compare with the calling uid. int installerUid = getPackageUid(installingPackageName, userId); int installerUid = getPackageUid(installingPackageName, userId); Loading Loading @@ -513,10 +513,11 @@ public class LocaleManagerService extends SystemService { } } @Nullable @Nullable String getInstallingPackageName(String packageName) { String getInstallingPackageName(String packageName, int userId) { try { try { return mContext.getPackageManager() return mContext.createContextAsUser(UserHandle.of(userId), /* flags= */ .getInstallSourceInfo(packageName).getInstallingPackageName(); 0).getPackageManager().getInstallSourceInfo( packageName).getInstallingPackageName(); } catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) { Slog.w(TAG, "Package not found " + packageName); Slog.w(TAG, "Package not found " + packageName); } } Loading services/core/java/com/android/server/locales/SystemAppUpdateTracker.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -152,9 +152,10 @@ public class SystemAppUpdateTracker { void onPackageUpdateFinished(String packageName, int uid) { void onPackageUpdateFinished(String packageName, int uid) { try { try { if ((!mUpdatedApps.contains(packageName)) && isUpdatedSystemApp(packageName)) { 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. // If a system app is updated, verify that it has an installer-on-record. String installingPackageName = mLocaleManagerService.getInstallingPackageName( String installingPackageName = mLocaleManagerService.getInstallingPackageName( packageName); packageName, userId); if (installingPackageName == null) { if (installingPackageName == null) { // We want to broadcast the locales info to the installer. // We want to broadcast the locales info to the installer. // If this app does not have an installer then do nothing. // If this app does not have an installer then do nothing. Loading @@ -162,7 +163,6 @@ public class SystemAppUpdateTracker { } } try { try { int userId = UserHandle.getUserId(uid); // Fetch the app-specific locales. // Fetch the app-specific locales. // If non-empty then send the info to the installer. // If non-empty then send the info to the installer. LocaleList appLocales = mLocaleManagerService.getApplicationLocales( LocaleList appLocales = mLocaleManagerService.getApplicationLocales( Loading services/tests/servicestests/src/com/android/server/locales/LocaleManagerServiceTest.java +1 −0 Original line number Original line Diff line number Diff line Loading @@ -105,6 +105,7 @@ public class LocaleManagerServiceTest { mMockPackageManager = mock(PackageManager.class); mMockPackageManager = mock(PackageManager.class); mMockPackageMonitor = mock(PackageMonitor.class); mMockPackageMonitor = mock(PackageMonitor.class); doReturn(mMockContext).when(mMockContext).createContextAsUser(any(), anyInt()); // For unit tests, set the default installer info // For unit tests, set the default installer info doReturn(DEFAULT_INSTALL_SOURCE_INFO).when(mMockPackageManager) doReturn(DEFAULT_INSTALL_SOURCE_INFO).when(mMockPackageManager) .getInstallSourceInfo(anyString()); .getInstallSourceInfo(anyString()); Loading services/tests/servicestests/src/com/android/server/locales/SystemAppUpdateTrackerTest.java +1 −0 Original line number Original line Diff line number Diff line Loading @@ -131,6 +131,7 @@ public class SystemAppUpdateTrackerTest { doReturn(mMockPackageManager).when(mMockContext).getPackageManager(); doReturn(mMockPackageManager).when(mMockContext).getPackageManager(); doReturn(InstrumentationRegistry.getContext().getContentResolver()) doReturn(InstrumentationRegistry.getContext().getContentResolver()) .when(mMockContext).getContentResolver(); .when(mMockContext).getContentResolver(); doReturn(mMockContext).when(mMockContext).createContextAsUser(any(), anyInt()); mStoragefile = new AtomicFile(new File( mStoragefile = new AtomicFile(new File( Environment.getExternalStorageDirectory(), "systemUpdateUnitTests.xml")); Environment.getExternalStorageDirectory(), "systemUpdateUnitTests.xml")); Loading Loading
services/core/java/com/android/server/locales/LocaleManagerService.java +6 −5 Original line number Original line Diff line number Diff line Loading @@ -323,7 +323,7 @@ public class LocaleManagerService extends SystemService { */ */ void notifyInstallerOfAppWhoseLocaleChanged(String appPackageName, int userId, void notifyInstallerOfAppWhoseLocaleChanged(String appPackageName, int userId, LocaleList locales) { LocaleList locales) { String installingPackageName = getInstallingPackageName(appPackageName); String installingPackageName = getInstallingPackageName(appPackageName, userId); if (installingPackageName != null) { if (installingPackageName != null) { Intent intent = createBaseIntent(Intent.ACTION_APPLICATION_LOCALE_CHANGED, Intent intent = createBaseIntent(Intent.ACTION_APPLICATION_LOCALE_CHANGED, appPackageName, locales); appPackageName, locales); Loading Loading @@ -464,7 +464,7 @@ public class LocaleManagerService extends SystemService { * Checks if the calling app is the installer of the app whose locale changed. * Checks if the calling app is the installer of the app whose locale changed. */ */ private boolean isCallerInstaller(String appPackageName, int userId) { private boolean isCallerInstaller(String appPackageName, int userId) { String installingPackageName = getInstallingPackageName(appPackageName); String installingPackageName = getInstallingPackageName(appPackageName, userId); if (installingPackageName != null) { if (installingPackageName != null) { // Get the uid of installer-on-record to compare with the calling uid. // Get the uid of installer-on-record to compare with the calling uid. int installerUid = getPackageUid(installingPackageName, userId); int installerUid = getPackageUid(installingPackageName, userId); Loading Loading @@ -513,10 +513,11 @@ public class LocaleManagerService extends SystemService { } } @Nullable @Nullable String getInstallingPackageName(String packageName) { String getInstallingPackageName(String packageName, int userId) { try { try { return mContext.getPackageManager() return mContext.createContextAsUser(UserHandle.of(userId), /* flags= */ .getInstallSourceInfo(packageName).getInstallingPackageName(); 0).getPackageManager().getInstallSourceInfo( packageName).getInstallingPackageName(); } catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) { Slog.w(TAG, "Package not found " + packageName); Slog.w(TAG, "Package not found " + packageName); } } Loading
services/core/java/com/android/server/locales/SystemAppUpdateTracker.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -152,9 +152,10 @@ public class SystemAppUpdateTracker { void onPackageUpdateFinished(String packageName, int uid) { void onPackageUpdateFinished(String packageName, int uid) { try { try { if ((!mUpdatedApps.contains(packageName)) && isUpdatedSystemApp(packageName)) { 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. // If a system app is updated, verify that it has an installer-on-record. String installingPackageName = mLocaleManagerService.getInstallingPackageName( String installingPackageName = mLocaleManagerService.getInstallingPackageName( packageName); packageName, userId); if (installingPackageName == null) { if (installingPackageName == null) { // We want to broadcast the locales info to the installer. // We want to broadcast the locales info to the installer. // If this app does not have an installer then do nothing. // If this app does not have an installer then do nothing. Loading @@ -162,7 +163,6 @@ public class SystemAppUpdateTracker { } } try { try { int userId = UserHandle.getUserId(uid); // Fetch the app-specific locales. // Fetch the app-specific locales. // If non-empty then send the info to the installer. // If non-empty then send the info to the installer. LocaleList appLocales = mLocaleManagerService.getApplicationLocales( LocaleList appLocales = mLocaleManagerService.getApplicationLocales( Loading
services/tests/servicestests/src/com/android/server/locales/LocaleManagerServiceTest.java +1 −0 Original line number Original line Diff line number Diff line Loading @@ -105,6 +105,7 @@ public class LocaleManagerServiceTest { mMockPackageManager = mock(PackageManager.class); mMockPackageManager = mock(PackageManager.class); mMockPackageMonitor = mock(PackageMonitor.class); mMockPackageMonitor = mock(PackageMonitor.class); doReturn(mMockContext).when(mMockContext).createContextAsUser(any(), anyInt()); // For unit tests, set the default installer info // For unit tests, set the default installer info doReturn(DEFAULT_INSTALL_SOURCE_INFO).when(mMockPackageManager) doReturn(DEFAULT_INSTALL_SOURCE_INFO).when(mMockPackageManager) .getInstallSourceInfo(anyString()); .getInstallSourceInfo(anyString()); Loading
services/tests/servicestests/src/com/android/server/locales/SystemAppUpdateTrackerTest.java +1 −0 Original line number Original line Diff line number Diff line Loading @@ -131,6 +131,7 @@ public class SystemAppUpdateTrackerTest { doReturn(mMockPackageManager).when(mMockContext).getPackageManager(); doReturn(mMockPackageManager).when(mMockContext).getPackageManager(); doReturn(InstrumentationRegistry.getContext().getContentResolver()) doReturn(InstrumentationRegistry.getContext().getContentResolver()) .when(mMockContext).getContentResolver(); .when(mMockContext).getContentResolver(); doReturn(mMockContext).when(mMockContext).createContextAsUser(any(), anyInt()); mStoragefile = new AtomicFile(new File( mStoragefile = new AtomicFile(new File( Environment.getExternalStorageDirectory(), "systemUpdateUnitTests.xml")); Environment.getExternalStorageDirectory(), "systemUpdateUnitTests.xml")); Loading