Merge "[Panlingual] Can't set per-app languages for apps on work profile page" into udc-dev am: b1f9d26174
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/22173332
Change-Id: I86052de81858b979e555db860ef9f7fe080b976d
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 d58607f..f1a6d36 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 cb1009a..0fbbf18 100644
--- a/src/com/android/settings/applications/manageapplications/ManageApplications.java
+++ b/src/com/android/settings/applications/manageapplications/ManageApplications.java
@@ -709,8 +709,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 6dab5cf..9efaf63 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,16 +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;
@@ -83,13 +71,13 @@
getActionBar().setDisplayHomeAsUpEnabled(true);
mLocalePickerWithRegion = LocalePickerWithRegion.createLanguagePicker(
- mContextAsUser,
+ this,
this,
false /* translate only */,
null,
mPackageName,
this);
- mAppLocaleDetails = AppLocaleDetails.newInstance(mPackageName, mContextAsUser.getUserId());
+ mAppLocaleDetails = AppLocaleDetails.newInstance(mPackageName, getUserId());
mAppLocaleDetailContainer = launchAppLocaleDetailsPage();
// Launch Locale picker part.
launchLocalePickerPage();
@@ -129,7 +117,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;
@@ -172,8 +160,8 @@
private boolean canDisplayLocaleUi() {
try {
- PackageManager packageManager = mContextAsUser.getPackageManager();
- return AppLocaleUtil.canDisplayLocaleUi(mContextAsUser,
+ PackageManager packageManager = getPackageManager();
+ return AppLocaleUtil.canDisplayLocaleUi(this,
packageManager.getApplicationInfo(mPackageName, 0),
packageManager.queryIntentActivities(AppLocaleUtil.LAUNCHER_ENTRY_INTENT,
PackageManager.GET_META_DATA));
diff --git a/src/com/android/settings/spa/system/AppLanguagesListModel.kt b/src/com/android/settings/spa/system/AppLanguagesListModel.kt
index 4aa4c7a..3141d68 100644
--- a/src/com/android/settings/spa/system/AppLanguagesListModel.kt
+++ b/src/com/android/settings/spa/system/AppLanguagesListModel.kt
@@ -21,6 +21,7 @@
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.net.Uri
+import android.os.UserHandle
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.runtime.remember
@@ -94,9 +95,9 @@
AppListItem {
val intent = Intent(context, AppLocalePickerActivity::class.java).apply {
data = Uri.parse("package:${record.app.packageName}")
- this.putExtra("uid", record.app.uid)
}
- context.startActivity(intent)
+ val userHandle : UserHandle = UserHandle.getUserHandleForUid(record.app.uid)
+ context.startActivityAsUser(intent, userHandle)
}
}
}
diff --git a/tests/robotests/src/com/android/settings/localepicker/AppLocalePickerActivityTest.java b/tests/robotests/src/com/android/settings/localepicker/AppLocalePickerActivityTest.java
index b462d33..48caecd 100644
--- a/tests/robotests/src/com/android/settings/localepicker/AppLocalePickerActivityTest.java
+++ b/tests/robotests/src/com/android/settings/localepicker/AppLocalePickerActivityTest.java
@@ -75,7 +75,6 @@
shadows = {
AppLocalePickerActivityTest.ShadowApplicationPackageManager.class,
AppLocalePickerActivityTest.ShadowResources.class,
- AppLocalePickerActivityTest.ShadowUserHandle.class,
})
public class AppLocalePickerActivityTest {
private static final String TEST_PACKAGE_NAME = "com.android.settings";
@@ -108,7 +107,6 @@
ReflectionHelpers.setStaticField(AppLocaleUtil.class, "sLocaleConfig", null);
ShadowResources.setDisAllowPackage(false);
ShadowApplicationPackageManager.setNoLaunchEntry(false);
- ShadowUserHandle.setUserId(0);
}
@Test
@@ -172,17 +170,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);
@@ -292,17 +279,4 @@
sDisAllowPackage = disAllowPackage;
}
}
-
- @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;
- }
- }
}