Merge "[Panlingual] Can't set per-app languages for apps on work profile page" into tm-qpr-dev am: d06d826549

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/22173333

Change-Id: I3d91cd2c803357778718e7d70350aa73c4cec675
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/src/com/android/settings/applications/appinfo/AppLocalePreferenceController.java b/src/com/android/settings/applications/appinfo/AppLocalePreferenceController.java
index 6bf94a6..55331ab 100644
--- a/src/com/android/settings/applications/appinfo/AppLocalePreferenceController.java
+++ b/src/com/android/settings/applications/appinfo/AppLocalePreferenceController.java
@@ -28,7 +28,6 @@
 import androidx.preference.Preference;
 
 import com.android.settings.SettingsPreferenceFragment;
-import com.android.settings.applications.AppInfoBase;
 import com.android.settings.applications.AppLocaleUtil;
 import com.android.settings.localepicker.AppLocalePickerActivity;
 
@@ -72,7 +71,6 @@
         if (mParent != null) {
             Intent intent = new Intent(mContext, AppLocalePickerActivity.class);
             intent.setData(Uri.parse("package:" + mParent.getAppEntry().info.packageName));
-            intent.putExtra(AppInfoBase.ARG_PACKAGE_UID, mParent.getAppEntry().info.uid);
             mContext.startActivity(intent);
             return true;
         } else {
diff --git a/src/com/android/settings/applications/manageapplications/ManageApplications.java b/src/com/android/settings/applications/manageapplications/ManageApplications.java
index d335324..2186bc1 100644
--- a/src/com/android/settings/applications/manageapplications/ManageApplications.java
+++ b/src/com/android/settings/applications/manageapplications/ManageApplications.java
@@ -654,8 +654,8 @@
             case LIST_TYPE_APPS_LOCALE:
                 Intent intent = new Intent(getContext(), AppLocalePickerActivity.class);
                 intent.setData(Uri.parse("package:" + mCurrentPkgName));
-                intent.putExtra(AppInfoBase.ARG_PACKAGE_UID, mCurrentUid);
-                startActivity(intent);
+                getContext().startActivityAsUser(intent,
+                        UserHandle.getUserHandleForUid(mCurrentUid));
                 break;
             case LIST_TYPE_BATTERY_OPTIMIZATION:
                 AdvancedPowerUsageDetail.startBatteryDetailPage(
diff --git a/src/com/android/settings/localepicker/AppLocalePickerActivity.java b/src/com/android/settings/localepicker/AppLocalePickerActivity.java
index 691344d..8d28d6b 100644
--- a/src/com/android/settings/localepicker/AppLocalePickerActivity.java
+++ b/src/com/android/settings/localepicker/AppLocalePickerActivity.java
@@ -18,12 +18,10 @@
 
 import android.app.FragmentTransaction;
 import android.app.LocaleManager;
-import android.content.Context;
 import android.content.pm.PackageManager;
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.LocaleList;
-import android.os.UserHandle;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.MenuItem;
@@ -34,7 +32,6 @@
 import com.android.internal.app.LocalePickerWithRegion;
 import com.android.internal.app.LocaleStore;
 import com.android.settings.R;
-import com.android.settings.applications.AppInfoBase;
 import com.android.settings.applications.AppLocaleUtil;
 import com.android.settings.applications.appinfo.AppLocaleDetails;
 import com.android.settings.core.SettingsBaseActivity;
@@ -46,7 +43,6 @@
     private String mPackageName;
     private LocalePickerWithRegion mLocalePickerWithRegion;
     private AppLocaleDetails mAppLocaleDetails;
-    private Context mContextAsUser;
     private View mAppLocaleDetailContainer;
 
     @Override
@@ -64,15 +60,8 @@
             finish();
             return;
         }
-        mContextAsUser = this;
-        if (getIntent().hasExtra(AppInfoBase.ARG_PACKAGE_UID)) {
-            int uid = getIntent().getIntExtra(AppInfoBase.ARG_PACKAGE_UID, -1);
-            if (uid != -1) {
-                UserHandle userHandle = UserHandle.getUserHandleForUid(uid);
-                mContextAsUser = createContextAsUser(userHandle, 0);
-            }
-        }
-        if (!canDisplayLocaleUi() || mContextAsUser.getUserId() != UserHandle.myUserId()) {
+
+        if (!canDisplayLocaleUi()) {
             Log.w(TAG, "Not allow to display Locale Settings UI.");
             finish();
             return;
@@ -82,12 +71,12 @@
         getActionBar().setDisplayHomeAsUpEnabled(true);
 
         mLocalePickerWithRegion = LocalePickerWithRegion.createLanguagePicker(
-                mContextAsUser,
+                this,
                 this,
                 false /* translate only */,
                 mPackageName,
                 this);
-        mAppLocaleDetails = AppLocaleDetails.newInstance(mPackageName, mContextAsUser.getUserId());
+        mAppLocaleDetails = AppLocaleDetails.newInstance(mPackageName, getUserId());
         mAppLocaleDetailContainer = launchAppLocaleDetailsPage();
         // Launch Locale picker part.
         launchLocalePickerPage();
@@ -127,7 +116,7 @@
     /** Sets the app's locale to the supplied language tag */
     private void setAppDefaultLocale(String languageTag) {
         Log.d(TAG, "setAppDefaultLocale: " + languageTag);
-        LocaleManager localeManager = mContextAsUser.getSystemService(LocaleManager.class);
+        LocaleManager localeManager = getSystemService(LocaleManager.class);
         if (localeManager == null) {
             Log.w(TAG, "LocaleManager is null, cannot set default app locale");
             return;
@@ -169,8 +158,8 @@
     }
 
     private boolean canDisplayLocaleUi() {
-        return AppLocaleUtil.canDisplayLocaleUi(mContextAsUser, mPackageName,
-                mContextAsUser.getPackageManager().queryIntentActivities(
-                        AppLocaleUtil.LAUNCHER_ENTRY_INTENT, PackageManager.GET_META_DATA));
+        return AppLocaleUtil.canDisplayLocaleUi(this, mPackageName,
+                getPackageManager().queryIntentActivities(AppLocaleUtil.LAUNCHER_ENTRY_INTENT,
+                        PackageManager.GET_META_DATA));
     }
 }
diff --git a/tests/robotests/src/com/android/settings/localepicker/AppLocalePickerActivityTest.java b/tests/robotests/src/com/android/settings/localepicker/AppLocalePickerActivityTest.java
index 77b2abb..a8748f4 100644
--- a/tests/robotests/src/com/android/settings/localepicker/AppLocalePickerActivityTest.java
+++ b/tests/robotests/src/com/android/settings/localepicker/AppLocalePickerActivityTest.java
@@ -73,7 +73,6 @@
         shadows = {
                 AppLocalePickerActivityTest.ShadowApplicationPackageManager.class,
                 AppLocalePickerActivityTest.ShadowResources.class,
-                AppLocalePickerActivityTest.ShadowUserHandle.class,
                 AppLocalePickerActivityTest.ShadowLocaleConfig.class,
         })
 public class AppLocalePickerActivityTest {
@@ -100,7 +99,6 @@
         mPackageManager.removePackage(TEST_PACKAGE_NAME);
         ShadowResources.setDisAllowPackage(false);
         ShadowApplicationPackageManager.setNoLaunchEntry(false);
-        ShadowUserHandle.setUserId(0);
         ShadowLocaleConfig.setStatus(LocaleConfig.STATUS_SUCCESS);
     }
 
@@ -165,17 +163,6 @@
     }
 
     @Test
-    public void launchAppLocalePickerActivity_modifyAppLocalesOfAnotherUser_failed() {
-        ShadowUserHandle.setUserId(10);
-
-        ActivityController<TestAppLocalePickerActivity> controller =
-                initActivityController(true);
-        controller.create();
-
-        assertThat(controller.get().isFinishing()).isTrue();
-    }
-
-    @Test
     public void launchAppLocalePickerActivity_intentWithoutPackageName_failed() {
         ActivityController<TestAppLocalePickerActivity> controller =
                 initActivityController(false);
@@ -286,19 +273,6 @@
         }
     }
 
-    @Implements(UserHandle.class)
-    public static class ShadowUserHandle {
-        private static int sUserId = 0;
-        private static void setUserId(int userId) {
-            sUserId = userId;
-        }
-
-        @Implementation
-        public static int getUserId(int userId) {
-            return sUserId;
-        }
-    }
-
     @Implements(LocaleConfig.class)
     public static class ShadowLocaleConfig {
         private static int sStatus = 0;