[Panlingual] Fix the app language is shown incorrectly in the work profile

The root cause is that the context corresponding to the specified
profile Id is not correctly used when using LocaleManager to query the
app language.

Bug: 222769707
Test: Verify the issue by using the steps provided in the bug
Change-Id: Ic1f9e4cc9e90f5aecfa5e1094184aa63f3d94ffb
This commit is contained in:
Josh Hou
2022-03-28 11:53:19 +08:00
parent 213b3ce4af
commit e32d422d3d
4 changed files with 27 additions and 7 deletions

View File

@@ -26,6 +26,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.LocaleList;
import android.os.UserHandle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@@ -40,6 +41,7 @@ import com.android.settings.Utils;
import com.android.settings.applications.AppInfoBase;
import com.android.settings.widget.EntityHeaderController;
import com.android.settingslib.applications.AppUtils;
import com.android.settingslib.applications.ApplicationsState.AppEntry;
import com.android.settingslib.widget.LayoutPreference;
import java.util.Locale;
@@ -214,8 +216,10 @@ public class AppLocaleDetails extends SettingsPreferenceFragment {
* TODO (b209962418) Do a performance test to low end device.
* @return Return the summary to show the current app's language.
*/
public static CharSequence getSummary(Context context, String packageName) {
Locale appLocale = getAppDefaultLocale(context, packageName);
public static CharSequence getSummary(Context context, AppEntry entry) {
final UserHandle userHandle = UserHandle.getUserHandleForUid(entry.info.uid);
final Context contextAsUser = context.createContextAsUser(userHandle, 0);
Locale appLocale = getAppDefaultLocale(contextAsUser, entry.info.packageName);
if (appLocale == null) {
Locale systemLocale = Locale.getDefault();
return context.getString(R.string.preference_of_system_locale_summary,

View File

@@ -29,6 +29,7 @@ import androidx.annotation.VisibleForTesting;
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;
@@ -62,7 +63,7 @@ public class AppLocalePreferenceController extends AppInfoPreferenceControllerBa
@Override
public CharSequence getSummary() {
return AppLocaleDetails.getSummary(mContext, mParent.getAppEntry().info.packageName);
return AppLocaleDetails.getSummary(mContext, mParent.getAppEntry());
}
@Override
@@ -74,6 +75,7 @@ public class AppLocalePreferenceController extends AppInfoPreferenceControllerBa
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 {

View File

@@ -638,6 +638,7 @@ public class ManageApplications extends InstrumentedFragment
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);
break;
// TODO: Figure out if there is a way where we can spin up the profile's settings
@@ -1561,8 +1562,7 @@ public class ManageApplications extends InstrumentedFragment
holder.setSummary(MediaManagementAppsDetails.getSummary(mContext, entry));
break;
case LIST_TYPE_APPS_LOCALE:
holder.setSummary(AppLocaleDetails
.getSummary(mContext, entry.info.packageName));
holder.setSummary(AppLocaleDetails.getSummary(mContext, entry));
break;
default:
holder.updateSizeText(entry, mManageApplications.mInvalidSizeStr, mWhichSize);