diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 92dfbe51aac..290f84e2030 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2942,24 +2942,6 @@
android:value="true" />
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 36e1193e3ed..5472a9d7b45 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -491,6 +491,12 @@
All languages
+
+ System language
+
+
+ System default - %1$s
+
The app is set to %1$s by default and doesn\u2019t support multiple languages.
@@ -597,7 +603,7 @@
Set date and time
Set date, time, time zone, & formats
-
+
Set time automatically
Set time zone automatically
@@ -5248,9 +5254,11 @@
Tap 3 times to zoom
Tap a button to zoom
+
+ Quickly zoom in on the screen to make content larger
-
+ To zoom in:
{0,number,integer}. Use shortcut to start magnification
{1,number,integer}. Tap the screen
@@ -5258,10 +5266,11 @@
{3,number,integer}. Pinch with 2 fingers to adjust zoom
{4,number,integer}. Use shortcut to stop magnification
To zoom in temporarily:
- {0,number,integer}. Use shortcut to start magnification
- {1,number,integer}. Touch & hold anywhere on the screen
- {2,number,integer}. Drag finger to move around screen
- {3,number,integer}. Lift finger to stop magnification
+ {0,number,integer}. Make sure your magnification type is set to full screen
+ {1,number,integer}. Use shortcut to start magnification
+ {2,number,integer}. Touch & hold anywhere on the screen
+ {3,number,integer}. Drag finger to move around screen
+ {4,number,integer}. Lift finger to stop magnification
]]>
@@ -5386,6 +5395,8 @@
Non-transparent
High contrast text
+
+ Change text color to black or white. Maximizes contrast with the background.
Auto
update screen magnification
@@ -5428,7 +5439,9 @@
Time to take action
- Choose how long to show messages that ask you to take action, but are visible only temporarily.\n\nNot all apps support this setting.
+ This timing preference isn\u2019t supported by all apps
+
+ Choose how long to show temporary messages that ask you to take action
Touch & hold delay
@@ -5438,14 +5451,15 @@
Use color inversion
Color inversion shortcut
+
+ Color inversion turns light screens dark. It also turns dark screens light.
-
- Note:
+ Keep in mind
- - \u00a0Color inversion also turns dark screens light.
- - \u00a0Colors will change in media and images.
- - \u00a0Dark theme can be used to display a dark background. Dark theme works with supported apps. Color inversion works on all apps.
+ - \u00a0Colors will change in media and images
+ - \u00a0Color inversion works on all apps
+ - \u00a0To display a dark background, Dark theme can be used instead
]]>
@@ -5455,10 +5469,12 @@
About autoclick (dwell timing)
Learn more about autoclick (dwell timing)
-
- Autoclick works with a connected mouse. You can set the mouse cursor to click automatically when the cursor stops moving for a certain amount of time.
+
+ You can set a connected mouse to click automatically when the cursor stops moving for a certain amount of time
+
+ Autoclick can be helpful if clicking the mouse is difficult
- Off
+ Autoclick off
Short
@@ -5511,6 +5527,10 @@
%1$s added to Quick Settings. Swipe down to turn it on or off anytime.
Dismiss
+
+ Adjust how colors display on your phone
+
+ Adjust how colors display on your tablet
Use color correction
@@ -5590,22 +5610,20 @@
Show in Quick Settings
-
- Correction mode
- Deuteranomaly
+ Red-green
- Protanomaly
+ Red-green
- Tritanomaly
+ Blue-yellow
Grayscale
- Red-green
+ Green weak, deuteranomaly
- Red-green
+ Red weak, protanomaly
- Blue-yellow
+ Tritanomaly
Extra dim
@@ -5619,10 +5637,11 @@
Dim screen beyond your phone\u2019s minimum brightness
Dim screen beyond your tablet\u2019s minimum brightness
+
+ Make your screen dimmer so it\u2019s more comfortable to read
-
- This can be helpful when:
+
\u00a0Your phone\u2019s default minimum brightness is still too bright
\u00a0You\u2019re using your phone in dark situations, like at night or in a dark room before bed
@@ -5631,8 +5650,7 @@
-
- This can be helpful when:
+
\u00a0Your tablet\u2019s default minimum brightness is still too bright
\u00a0You\u2019re using your tablet in dark situations, like at night or in a dark room before bed
diff --git a/res/xml/accessibility_autoclick_settings.xml b/res/xml/accessibility_autoclick_settings.xml
index 617f22a94b1..943bc67b478 100644
--- a/res/xml/accessibility_autoclick_settings.xml
+++ b/res/xml/accessibility_autoclick_settings.xml
@@ -19,18 +19,21 @@
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/accessibility_autoclick_preference_title">
+
+
+ android:title="@string/accessibility_autoclick_default_title" />
+
+
@@ -28,7 +33,6 @@
-
+
-
+
-
+
-
-
-
-
+
diff --git a/res/xml/accessibility_text_reading_options.xml b/res/xml/accessibility_text_reading_options.xml
index 7d815653e19..d55882d2011 100644
--- a/res/xml/accessibility_text_reading_options.xml
+++ b/res/xml/accessibility_text_reading_options.xml
@@ -54,6 +54,7 @@
+ android:title="@string/suggested_app_locales_title" >
+
+
+
+
sControllers = new ArrayList<>();
private static List buildPreferenceControllers(Context context,
@@ -82,6 +85,7 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
mComponentName = DALTONIZER_COMPONENT_NAME;
mPackageName = getText(R.string.accessibility_display_daltonizer_preference_title);
mHtmlDescription = getText(R.string.accessibility_display_daltonizer_preference_subtitle);
+ mTopIntroTitle = getText(R.string.accessibility_daltonizer_about_intro_text);
final View view = super.onCreateView(inflater, container, savedInstanceState);
updateFooterPreference();
return view;
@@ -111,9 +115,13 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
/** Customizes the order by preference key. */
protected List getPreferenceOrderList() {
final List lists = new ArrayList<>();
+ lists.add(KEY_TOP_INTRO_PREFERENCE);
lists.add(KEY_PREVIEW);
lists.add(KEY_USE_SERVICE_PREFERENCE);
- lists.add(KEY_CATEGORY_MODE);
+ lists.add(KEY_DEUTERANOMALY);
+ lists.add(KEY_PROTANOMALY);
+ lists.add(KEY_TRITANOMEALY);
+ lists.add(KEY_GRAYSCALE);
lists.add(KEY_GENERAL_CATEGORY);
lists.add(KEY_HTML_DESCRIPTION_PREFERENCE);
return lists;
diff --git a/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
index 973e27cd616..1e2e9e56909 100644
--- a/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
@@ -68,6 +68,7 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
mComponentName = REDUCE_BRIGHT_COLORS_COMPONENT_NAME;
mPackageName = getText(R.string.reduce_bright_colors_preference_title);
mHtmlDescription = getText(R.string.reduce_bright_colors_preference_subtitle);
+ mTopIntroTitle = getText(R.string.reduce_bright_colors_preference_intro_text);
mRbcIntensityPreferenceController =
new ReduceBrightColorsIntensityPreferenceController(getContext(), KEY_INTENSITY);
mRbcPersistencePreferenceController =
diff --git a/src/com/android/settings/applications/appinfo/AppLocaleDetails.java b/src/com/android/settings/applications/appinfo/AppLocaleDetails.java
index 164cfd9f2fa..8f1c212ad57 100644
--- a/src/com/android/settings/applications/appinfo/AppLocaleDetails.java
+++ b/src/com/android/settings/applications/appinfo/AppLocaleDetails.java
@@ -38,8 +38,6 @@ import androidx.appcompat.app.AlertDialog;
import androidx.preference.Preference;
import androidx.preference.PreferenceGroup;
-import com.android.internal.app.LocalePicker;
-import com.android.internal.app.LocalePicker.LocaleInfo;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.applications.AppInfoBase;
@@ -48,11 +46,8 @@ import com.android.settingslib.applications.AppUtils;
import com.android.settingslib.widget.LayoutPreference;
import com.android.settingslib.widget.RadioButtonPreference;
-import com.google.common.collect.Iterables;
-
import java.util.ArrayList;
import java.util.Collection;
-import java.util.List;
import java.util.Locale;
/**
@@ -66,13 +61,17 @@ public class AppLocaleDetails extends AppInfoBase implements RadioButtonPreferen
private static final String CATEGORY_KEY_ALL_LANGUAGES =
"category_key_all_languages";
private static final String KEY_APP_DESCRIPTION = "app_locale_description";
+ @VisibleForTesting
+ static final String KEY_SYSTEM_DEFAULT_LOCALE = "system_default_locale";
private boolean mCreated = false;
- private AppLocaleDetailsHelper mAppLocaleDetailsHelper;
+ @VisibleForTesting
+ AppLocaleDetailsHelper mAppLocaleDetailsHelper;
private PreferenceGroup mGroupOfSuggestedLocales;
private PreferenceGroup mGroupOfSupportedLocales;
private LayoutPreference mPrefOfDescription;
+ private RadioButtonPreference mDefaultPreference;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -85,6 +84,10 @@ public class AppLocaleDetails extends AppInfoBase implements RadioButtonPreferen
mGroupOfSupportedLocales =
getPreferenceScreen().findPreference(CATEGORY_KEY_ALL_LANGUAGES);
mPrefOfDescription = getPreferenceScreen().findPreference(KEY_APP_DESCRIPTION);
+
+ mDefaultPreference = (RadioButtonPreference) getPreferenceScreen()
+ .findPreference(KEY_SYSTEM_DEFAULT_LOCALE);
+ mDefaultPreference.setOnClickListener(this);
}
// Override here so we don't have an empty screen
@@ -104,30 +107,43 @@ public class AppLocaleDetails extends AppInfoBase implements RadioButtonPreferen
// Update Locales first, before refresh ui.
mAppLocaleDetailsHelper.handleAllLocalesData();
super.onResume();
+ mDefaultPreference.setSummary(Locale.getDefault().getDisplayName(Locale.getDefault()));
}
@Override
protected boolean refreshUi() {
+ refreshUiInternal();
+ return true;
+ }
+
+ @VisibleForTesting
+ void refreshUiInternal() {
if (mAppLocaleDetailsHelper.getSupportedLocales().isEmpty()) {
Log.d(TAG, "No supported language.");
mGroupOfSuggestedLocales.setVisible(false);
mGroupOfSupportedLocales.setVisible(false);
mPrefOfDescription.setVisible(true);
TextView description = (TextView) mPrefOfDescription.findViewById(R.id.description);
- Locale locale = mAppLocaleDetailsHelper.getCurrentSystemLocales().get(0);
description.setText(getContext().getString(R.string.no_multiple_language_supported,
- locale.getDisplayName(locale)));
- return true;
+ Locale.getDefault().getDisplayName(Locale.getDefault())));
+ return;
}
-
- mGroupOfSuggestedLocales.removeAll();
- mGroupOfSupportedLocales.removeAll();
+ resetLocalePreferences();
Locale appLocale = AppLocaleDetailsHelper.getAppDefaultLocale(getContext(), mPackageName);
+ // Sets up default locale preference.
+ mGroupOfSuggestedLocales.addPreference(mDefaultPreference);
+ mDefaultPreference.setChecked(appLocale == null);
+ // Sets up suggested locales of per app.
setLanguagesPreference(mGroupOfSuggestedLocales,
mAppLocaleDetailsHelper.getSuggestedLocales(), appLocale);
+ // Sets up supported locales of per app.
setLanguagesPreference(mGroupOfSupportedLocales,
mAppLocaleDetailsHelper.getSupportedLocales(), appLocale);
- return true;
+ }
+
+ private void resetLocalePreferences() {
+ mGroupOfSuggestedLocales.removeAll();
+ mGroupOfSupportedLocales.removeAll();
}
@Override
@@ -142,7 +158,12 @@ public class AppLocaleDetails extends AppInfoBase implements RadioButtonPreferen
@Override
public void onRadioButtonClicked(RadioButtonPreference pref) {
- mAppLocaleDetailsHelper.setAppDefaultLocale(pref.getKey());
+ String key = pref.getKey();
+ if (KEY_SYSTEM_DEFAULT_LOCALE.equals(key)) {
+ mAppLocaleDetailsHelper.setAppDefaultLocale(LocaleList.forLanguageTags(""));
+ } else {
+ mAppLocaleDetailsHelper.setAppDefaultLocale(key);
+ }
refreshUi();
}
@@ -180,7 +201,13 @@ public class AppLocaleDetails extends AppInfoBase implements RadioButtonPreferen
public static CharSequence getSummary(Context context, String packageName) {
Locale appLocale =
AppLocaleDetailsHelper.getAppDefaultLocale(context, packageName);
- return appLocale == null ? "" : appLocale.getDisplayName(appLocale);
+ if (appLocale == null) {
+ Locale systemLocale = Locale.getDefault();
+ return context.getString(R.string.preference_of_system_locale_summary,
+ systemLocale.getDisplayName(systemLocale));
+ } else {
+ return appLocale.getDisplayName(appLocale);
+ }
}
private void setLanguagesPreference(PreferenceGroup group,
@@ -190,9 +217,15 @@ public class AppLocaleDetails extends AppInfoBase implements RadioButtonPreferen
}
for (Locale locale : locales) {
+ if (locale == null) {
+ continue;
+ }
+
RadioButtonPreference pref = new RadioButtonPreference(getContext());
pref.setTitle(locale.getDisplayName(locale));
pref.setKey(locale.toLanguageTag());
+ // Will never be checked if appLocale is null
+ // aka if there is no per-app locale
pref.setChecked(locale.equals(appLocale));
pref.setOnClickListener(this);
group.addPreference(pref);
@@ -206,14 +239,17 @@ public class AppLocaleDetails extends AppInfoBase implements RadioButtonPreferen
private TelephonyManager mTelephonyManager;
private LocaleManager mLocaleManager;
- private Collection mSuggestedLocales = new ArrayList<>();
- private Collection mSupportedLocales = new ArrayList<>();
+ private Collection mProcessedSuggestedLocales = new ArrayList<>();
+ private Collection mProcessedSupportedLocales = new ArrayList<>();
+
+ private Collection mAppSupportedLocales = new ArrayList<>();
AppLocaleDetailsHelper(Context context, String packageName) {
mContext = context;
mPackageName = packageName;
mTelephonyManager = context.getSystemService(TelephonyManager.class);
mLocaleManager = context.getSystemService(LocaleManager.class);
+ mAppSupportedLocales = getAppSupportedLocales();
}
/** Handle suggested and supported locales for UI display. */
@@ -225,49 +261,47 @@ public class AppLocaleDetails extends AppInfoBase implements RadioButtonPreferen
/** Gets suggested locales in the app. */
public Collection getSuggestedLocales() {
- return mSuggestedLocales;
+ return mProcessedSuggestedLocales;
}
/** Gets supported locales in the app. */
public Collection getSupportedLocales() {
- return mSupportedLocales;
+ return mProcessedSupportedLocales;
}
@VisibleForTesting
void handleSuggestedLocales() {
- LocaleList currentSystemLocales = getCurrentSystemLocales();
Locale appLocale = getAppDefaultLocale(mContext, mPackageName);
+ // 1st locale in suggested languages group.
+ for (Locale supportedlocale : mAppSupportedLocales) {
+ if (compareLocale(supportedlocale, appLocale)) {
+ mProcessedSuggestedLocales.add(appLocale);
+ break;
+ }
+ }
+
+ // 2nd and 3rd locale in suggested languages group.
String simCountry = mTelephonyManager.getSimCountryIso().toUpperCase(Locale.US);
String networkCountry = mTelephonyManager.getNetworkCountryIso().toUpperCase(Locale.US);
- // 1st locale in suggested languages group.
- if (appLocale != null) {
- mSuggestedLocales.add(appLocale);
- }
- // 2nd locale in suggested languages group.
- final List localeInfos = LocalePicker.getAllAssetLocales(mContext, false);
- for (LocaleInfo localeInfo : localeInfos) {
- Locale locale = localeInfo.getLocale();
- String localeCountry = locale.getCountry().toUpperCase(Locale.US);
- if (!compareLocale(locale, appLocale)
+ mAppSupportedLocales.forEach(supportedlocale -> {
+ String localeCountry = supportedlocale.getCountry().toUpperCase(Locale.US);
+ if (!compareLocale(supportedlocale, appLocale)
&& isCountrySuggestedLocale(localeCountry, simCountry, networkCountry)) {
- mSuggestedLocales.add(locale);
+ mProcessedSuggestedLocales.add(supportedlocale);
}
- }
+ });
+
// Other locales in suggested languages group.
- for (int i = 0; i < currentSystemLocales.size(); i++) {
- Locale locale = currentSystemLocales.get(i);
- boolean isInSuggestedLocales = false;
- for (int j = 0; j < mSuggestedLocales.size(); j++) {
- Locale suggestedLocale = Iterables.get(mSuggestedLocales, j);
- if (compareLocale(locale, suggestedLocale)) {
- isInSuggestedLocales = true;
- break;
+ Collection supportedSystemLocales = new ArrayList<>();
+ getCurrentSystemLocales().forEach(systemLocale -> {
+ mAppSupportedLocales.forEach(supportedLocale -> {
+ if (compareLocale(systemLocale, supportedLocale)) {
+ supportedSystemLocales.add(supportedLocale);
}
- }
- if (!isInSuggestedLocales) {
- mSuggestedLocales.add(locale);
- }
- }
+ });
+ });
+ supportedSystemLocales.removeAll(mProcessedSuggestedLocales);
+ mProcessedSuggestedLocales.addAll(supportedSystemLocales);
}
@VisibleForTesting
@@ -290,26 +324,34 @@ public class AppLocaleDetails extends AppInfoBase implements RadioButtonPreferen
@VisibleForTesting
void handleSupportedLocales() {
- LocaleList localeList = getPackageLocales();
- if (localeList == null) {
- String[] languages = getAssetSystemLocales();
- for (String language : languages) {
- mSupportedLocales.add(Locale.forLanguageTag(language));
- }
- } else {
- for (int i = 0; i < localeList.size(); i++) {
- mSupportedLocales.add(localeList.get(i));
- }
- }
+ mProcessedSupportedLocales.addAll(mAppSupportedLocales);
- if (mSuggestedLocales != null || !mSuggestedLocales.isEmpty()) {
- mSupportedLocales.removeAll(mSuggestedLocales);
+ if (mProcessedSuggestedLocales != null || !mProcessedSuggestedLocales.isEmpty()) {
+ mProcessedSuggestedLocales.retainAll(mProcessedSupportedLocales);
+ mProcessedSupportedLocales.removeAll(mProcessedSuggestedLocales);
}
}
private void clearLocalesData() {
- mSuggestedLocales.clear();
- mSupportedLocales.clear();
+ mProcessedSuggestedLocales.clear();
+ mProcessedSupportedLocales.clear();
+ }
+
+ private Collection getAppSupportedLocales() {
+ Collection appSupportedLocales = new ArrayList<>();
+ LocaleList localeList = getPackageLocales();
+
+ if (localeList != null && localeList.size() > 0) {
+ for (int i = 0; i < localeList.size(); i++) {
+ appSupportedLocales.add(localeList.get(i));
+ }
+ } else {
+ String[] languages = getAssetLocales();
+ for (String language : languages) {
+ appSupportedLocales.add(Locale.forLanguageTag(language));
+ }
+ }
+ return appSupportedLocales;
}
/** Gets per app's default locale */
@@ -317,8 +359,8 @@ public class AppLocaleDetails extends AppInfoBase implements RadioButtonPreferen
LocaleManager localeManager = context.getSystemService(LocaleManager.class);
try {
LocaleList localeList = (localeManager == null)
- ? new LocaleList() : localeManager.getApplicationLocales(packageName);
- return localeList.isEmpty() ? null : localeList.get(0);
+ ? null : localeManager.getApplicationLocales(packageName);
+ return localeList == null ? null : localeList.get(0);
} catch (IllegalArgumentException e) {
Log.w(TAG, "package name : " + packageName + " is not correct. " + e);
}
@@ -344,12 +386,17 @@ public class AppLocaleDetails extends AppInfoBase implements RadioButtonPreferen
}
@VisibleForTesting
- LocaleList getCurrentSystemLocales() {
- return Resources.getSystem().getConfiguration().getLocales();
+ Collection getCurrentSystemLocales() {
+ LocaleList localeList = Resources.getSystem().getConfiguration().getLocales();
+ Collection systemLocales = new ArrayList<>();
+ for (int i = 0; i < localeList.size(); i++) {
+ systemLocales.add(localeList.get(i));
+ }
+ return systemLocales;
}
@VisibleForTesting
- String[] getAssetSystemLocales() {
+ String[] getAssetLocales() {
try {
PackageManager packageManager = mContext.getPackageManager();
return packageManager.getResourcesForApplication(
diff --git a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
index cdac3b9f41d..8ad66d23e4f 100644
--- a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
+++ b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
@@ -171,11 +171,13 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
intent.setAction(action);
}
// Register the rule for injected apps.
- ActivityEmbeddingRulesController.registerTwoPanePairRuleForSettingsHome(
- mContext,
- new ComponentName(tile.getPackageName(), tile.getComponentName()),
- action,
- true /* clearTop */);
+ if (fragment instanceof TopLevelSettings) {
+ ActivityEmbeddingRulesController.registerTwoPanePairRuleForSettingsHome(
+ mContext,
+ new ComponentName(tile.getPackageName(), tile.getComponentName()),
+ action,
+ true /* clearTop */);
+ }
pref.setOnPreferenceClickListener(preference -> {
TopLevelHighlightMixin highlightMixin = null;
if (fragment instanceof TopLevelSettings
@@ -442,11 +444,6 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
ProfileSelectDialog.updateUserHandlesIfNeeded(mContext, tile);
mMetricsFeatureProvider.logStartedIntent(intent, sourceMetricCategory);
- //TODO(b/201970810): Add test cases.
- if (tile.isNewTask(mContext)) {
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- }
-
if (tile.userHandle == null || tile.isPrimaryProfileOnly()) {
activity.startActivity(intent);
} else if (tile.userHandle.size() == 1) {
diff --git a/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java
index e0ba3787199..d3234dd1151 100644
--- a/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java
+++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java
@@ -97,7 +97,7 @@ public class ProfileSelectDialog extends DialogFragment implements OnClickListen
public void onClick(DialogInterface dialog, int which) {
final UserHandle user = mSelectedTile.userHandle.get(which);
// Show menu on top level items.
- final Intent intent = mSelectedTile.getIntent();
+ final Intent intent = new Intent(mSelectedTile.getIntent());
FeatureFactory.getFactory(getContext()).getMetricsFeatureProvider()
.logStartedIntentWithProfile(intent, mSourceMetricCategory,
which == 1 /* isWorkProfile */);
diff --git a/src/com/android/settings/dream/AutoFitGridLayoutManager.java b/src/com/android/settings/dream/AutoFitGridLayoutManager.java
index 0e5d3e1bbd5..7de0eaead72 100644
--- a/src/com/android/settings/dream/AutoFitGridLayoutManager.java
+++ b/src/com/android/settings/dream/AutoFitGridLayoutManager.java
@@ -24,10 +24,10 @@ import androidx.recyclerview.widget.RecyclerView;
import com.android.settings.R;
/** Grid layout manager that calculates the number of columns for the screen size. */
-final class AutoFitGridLayoutManager extends GridLayoutManager {
+public final class AutoFitGridLayoutManager extends GridLayoutManager {
private final float mColumnWidth;
- AutoFitGridLayoutManager(Context context) {
+ public AutoFitGridLayoutManager(Context context) {
super(context, /* spanCount= */ 1);
this.mColumnWidth = context
.getResources()
diff --git a/src/com/android/settings/dream/DreamAdapter.java b/src/com/android/settings/dream/DreamAdapter.java
index e6745464ed2..8d0e9d5d297 100644
--- a/src/com/android/settings/dream/DreamAdapter.java
+++ b/src/com/android/settings/dream/DreamAdapter.java
@@ -37,7 +37,7 @@ import java.util.List;
/**
* RecyclerView adapter which displays list of items for the user to select.
*/
-class DreamAdapter extends RecyclerView.Adapter {
+public class DreamAdapter extends RecyclerView.Adapter {
private final List mItemList;
private int mLastSelectedPos = -1;
@@ -103,7 +103,7 @@ class DreamAdapter extends RecyclerView.Adapter {
}
}
- DreamAdapter(List itemList) {
+ public DreamAdapter(List itemList) {
mItemList = itemList;
}
diff --git a/src/com/android/settings/dream/DreamSetupActivity.java b/src/com/android/settings/dream/DreamSetupActivity.java
deleted file mode 100644
index 6a126713686..00000000000
--- a/src/com/android/settings/dream/DreamSetupActivity.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.dream;
-
-import android.app.settings.SettingsEnums;
-import android.content.Intent;
-import android.graphics.drawable.Drawable;
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-
-import androidx.recyclerview.widget.RecyclerView;
-
-import com.android.settings.R;
-import com.android.settings.SettingsActivity;
-import com.android.settings.SettingsPreferenceFragment;
-import com.android.settingslib.dream.DreamBackend;
-
-import com.google.android.setupcompat.template.FooterBarMixin;
-import com.google.android.setupcompat.template.FooterButton;
-import com.google.android.setupcompat.util.WizardManagerHelper;
-import com.google.android.setupdesign.GlifLayout;
-import com.google.android.setupdesign.util.ThemeHelper;
-import com.google.android.setupdesign.util.ThemeResolver;
-
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * The setup activity for dreams which is displayed during setup wizard.
- */
-public class DreamSetupActivity extends SettingsActivity {
- @Override
- public Intent getIntent() {
- Intent modIntent = new Intent(super.getIntent());
- modIntent.putExtra(EXTRA_SHOW_FRAGMENT, DreamSetupFragment.class.getName());
- return modIntent;
- }
-
- @Override
- protected boolean isValidFragment(String fragmentName) {
- return DreamSetupFragment.class.getName().equals(fragmentName);
- }
-
- @Override
- protected void onCreate(Bundle savedInstance) {
- setTheme(ThemeResolver.getDefault().resolve(getIntent()));
- ThemeHelper.trySetDynamicColor(this);
- super.onCreate(savedInstance);
- }
-
- @Override
- protected boolean isToolbarEnabled() {
- return false;
- }
-
- /**
- * Fragment used to control the active dream.
- */
- public static class DreamSetupFragment extends SettingsPreferenceFragment {
- private DreamBackend mBackend;
- private DreamBackend.DreamInfo mActiveDream;
- private FooterButton mFooterButton;
-
- @Override
- public int getMetricsCategory() {
- return SettingsEnums.DREAM;
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- return inflater.inflate(R.layout.dream_setup_layout, container, false);
- }
-
- @Override
- public void onViewCreated(View view, Bundle savedInstanceState) {
- super.onViewCreated(view, savedInstanceState);
-
- mBackend = DreamBackend.getInstance(getContext());
- final List dreamInfos = mBackend.getDreamInfos();
- mActiveDream = dreamInfos.stream().filter(d -> d.isActive).findFirst().orElse(null);
- DreamAdapter dreamAdapter = new DreamAdapter(dreamInfos.stream()
- .map(DreamItem::new)
- .collect(Collectors.toList()));
-
- final RecyclerView recyclerView = view.findViewById(R.id.dream_setup_list);
- recyclerView.setLayoutManager(new AutoFitGridLayoutManager(getContext()));
- recyclerView.setHasFixedSize(true);
- recyclerView.setAdapter(dreamAdapter);
-
- final GlifLayout layout = view.findViewById(R.id.setup_wizard_layout);
- final FooterBarMixin mixin = layout.getMixin(FooterBarMixin.class);
- mFooterButton = new FooterButton.Builder(getContext())
- .setListener(this::onPrimaryButtonClicked)
- .setButtonType(FooterButton.ButtonType.NEXT)
- .setTheme(R.style.SudGlifButton_Primary)
- .build();
- updateFooterButtonText();
- mixin.setPrimaryButton(mFooterButton);
- }
-
- private void updateFooterButtonText() {
- final int res = canCustomizeDream() ? R.string.wizard_next : R.string.wizard_finish;
- mFooterButton.setText(getContext().getString(res));
- }
-
- private boolean canCustomizeDream() {
- return mActiveDream != null && mActiveDream.settingsComponentName != null;
- }
-
- private void onPrimaryButtonClicked(View view) {
- if (canCustomizeDream()) {
- final Intent intent = new Intent().setComponent(mActiveDream.settingsComponentName);
- WizardManagerHelper.copyWizardManagerExtras(getIntent(), intent);
- startActivity(intent);
- }
-
- // Use RESULT_CANCELED here so that the user may go back and change this if they wish.
- setResult(RESULT_CANCELED);
- finish();
- }
-
- private class DreamItem implements IDreamItem {
- private final DreamBackend.DreamInfo mDreamInfo;
-
- private DreamItem(DreamBackend.DreamInfo dreamInfo) {
- mDreamInfo = dreamInfo;
- }
-
- @Override
- public CharSequence getTitle() {
- return mDreamInfo.caption;
- }
-
- @Override
- public Drawable getIcon() {
- return mDreamInfo.icon;
- }
-
- @Override
- public void onItemClicked() {
- mActiveDream = mDreamInfo;
- mBackend.setActiveDream(mDreamInfo.componentName);
- updateFooterButtonText();
- }
-
- @Override
- public Drawable getPreviewImage() {
- return mDreamInfo.previewImage;
- }
-
- @Override
- public boolean isActive() {
- if (mActiveDream == null) {
- return false;
- }
- return mDreamInfo.componentName.equals(mActiveDream.componentName);
- }
- }
- }
-}
diff --git a/src/com/android/settings/dream/IDreamItem.java b/src/com/android/settings/dream/IDreamItem.java
index 66528575eec..c462fe25502 100644
--- a/src/com/android/settings/dream/IDreamItem.java
+++ b/src/com/android/settings/dream/IDreamItem.java
@@ -18,7 +18,10 @@ package com.android.settings.dream;
import android.graphics.drawable.Drawable;
-interface IDreamItem {
+/**
+ * Interface representing a dream item to be displayed.
+ */
+public interface IDreamItem {
CharSequence getTitle();
Drawable getIcon();
diff --git a/src/com/android/settings/location/RecentLocationAccessSeeAllPreferenceController.java b/src/com/android/settings/location/RecentLocationAccessSeeAllPreferenceController.java
index e3379c7da7f..75406f7132a 100644
--- a/src/com/android/settings/location/RecentLocationAccessSeeAllPreferenceController.java
+++ b/src/com/android/settings/location/RecentLocationAccessSeeAllPreferenceController.java
@@ -27,7 +27,9 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
+import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.applications.RecentAppOpsAccess;
+import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.widget.AppPreference;
import java.util.ArrayList;
@@ -37,8 +39,10 @@ import java.util.List;
public class RecentLocationAccessSeeAllPreferenceController
extends LocationBasePreferenceController {
- private PreferenceScreen mCategoryAllRecentLocationAccess;
private final RecentAppOpsAccess mRecentLocationAccesses;
+
+ private PreferenceScreen mCategoryAllRecentLocationAccess;
+ private MetricsFeatureProvider mMetricsFeatureProvider;
private boolean mShowSystem = false;
private Preference mPreference;
@@ -47,6 +51,7 @@ public class RecentLocationAccessSeeAllPreferenceController
mShowSystem = Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.LOCATION_SHOW_SYSTEM_OPS, 0) == 1;
mRecentLocationAccesses = RecentAppOpsAccess.createForLocation(context);
+ mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
}
@Override
@@ -99,6 +104,7 @@ public class RecentLocationAccessSeeAllPreferenceController
mShowSystem = showSystem;
if (mPreference != null) {
updateState(mPreference);
+ mMetricsFeatureProvider.logClickedPreference(mPreference, getMetricsCategory());
}
}
}
diff --git a/src/com/android/settings/nfc/PaymentDefaultDialog.java b/src/com/android/settings/nfc/PaymentDefaultDialog.java
index a888167b899..75746ce94d2 100644
--- a/src/com/android/settings/nfc/PaymentDefaultDialog.java
+++ b/src/com/android/settings/nfc/PaymentDefaultDialog.java
@@ -58,7 +58,11 @@ public final class PaymentDefaultDialog extends AlertActivity implements
ComponentName component = intent.getParcelableExtra(
CardEmulation.EXTRA_SERVICE_COMPONENT);
String category = intent.getStringExtra(CardEmulation.EXTRA_CATEGORY);
- int userId = intent.getIntExtra(CardEmulation.EXTRA_USERID, UserHandle.myUserId());
+ UserHandle userHandle = intent.getParcelableExtra(Intent.EXTRA_USER);
+ if (userHandle == null) {
+ userHandle = UserHandle.CURRENT;
+ }
+ int userId = userHandle.getIdentifier();
setResult(RESULT_CANCELED);
if (!buildDialog(component, category, userId)) {
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/EligibleCardCheckerTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/EligibleCardCheckerTest.java
index e63dd80a799..64dbbb28728 100644
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/EligibleCardCheckerTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/EligibleCardCheckerTest.java
@@ -24,20 +24,26 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
+import android.app.Activity;
+import android.app.PendingIntent;
import android.content.Context;
+import android.content.Intent;
import android.net.Uri;
+import androidx.core.graphics.drawable.IconCompat;
import androidx.slice.Slice;
import androidx.slice.SliceProvider;
import androidx.slice.widget.SliceLiveData;
+import androidx.slice.builders.ListBuilder;
+import androidx.slice.builders.SliceAction;
+import com.android.settings.R;
import com.android.settings.slices.CustomSliceRegistry;
-import com.android.settings.wifi.slice.ContextualWifiSlice;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@@ -48,6 +54,7 @@ public class EligibleCardCheckerTest {
private Context mContext;
private EligibleCardChecker mEligibleCardChecker;
+ private Activity mActivity;
@Before
public void setUp() {
@@ -55,22 +62,19 @@ public class EligibleCardCheckerTest {
mEligibleCardChecker =
spy(new EligibleCardChecker(mContext, getContextualCard(TEST_SLICE_URI)));
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
+ mActivity = Robolectric.buildActivity(Activity.class).create().get();
}
@Test
- @Ignore
public void isSliceToggleable_cardWithToggle_returnTrue() {
- final ContextualWifiSlice wifiSlice = new ContextualWifiSlice(mContext);
- final Slice slice = wifiSlice.getSlice();
+ final Slice slice = buildSlice();
assertThat(mEligibleCardChecker.isSliceToggleable(slice)).isTrue();
}
@Test
- @Ignore
public void isCardEligibleToDisplay_toggleSlice_hasInlineActionShouldBeTrue() {
- final ContextualWifiSlice wifiSlice = new ContextualWifiSlice(mContext);
- final Slice slice = wifiSlice.getSlice();
+ final Slice slice = buildSlice();
doReturn(slice).when(mEligibleCardChecker).bindSlice(any(Uri.class));
mEligibleCardChecker.isCardEligibleToDisplay(getContextualCard(TEST_SLICE_URI));
@@ -118,10 +122,8 @@ public class EligibleCardCheckerTest {
}
@Test
- @Ignore
public void isCardEligibleToDisplay_sliceNotNull_cacheSliceToCard() {
- final ContextualWifiSlice wifiSlice = new ContextualWifiSlice(mContext);
- final Slice slice = wifiSlice.getSlice();
+ final Slice slice = buildSlice();
doReturn(slice).when(mEligibleCardChecker).bindSlice(any(Uri.class));
mEligibleCardChecker.isCardEligibleToDisplay(getContextualCard(TEST_SLICE_URI));
@@ -137,4 +139,23 @@ public class EligibleCardCheckerTest {
.setSliceUri(sliceUri)
.build();
}
+
+ private Slice buildSlice() {
+ final String title = "test_title";
+ final IconCompat icon = IconCompat.createWithResource(mActivity, R.drawable.empty_icon);
+ final PendingIntent pendingIntent = PendingIntent.getActivity(
+ mActivity,
+ title.hashCode() /* requestCode */,
+ new Intent("test action"),
+ PendingIntent.FLAG_IMMUTABLE);
+ final SliceAction action
+ = SliceAction.createDeeplink(pendingIntent, icon, ListBuilder.SMALL_IMAGE, title);
+ return new ListBuilder(mActivity, TEST_SLICE_URI, ListBuilder.INFINITY)
+ .addRow(new ListBuilder.RowBuilder()
+ .addEndItem(icon, ListBuilder.ICON_IMAGE)
+ .setTitle(title)
+ .setPrimaryAction(action))
+ .addAction(SliceAction.createToggle(pendingIntent, null /* actionTitle */, true))
+ .build();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java b/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java
index fc6481b8cc4..dcf086c68fb 100644
--- a/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java
@@ -44,6 +44,8 @@ import androidx.lifecycle.Lifecycle;
import androidx.preference.PreferenceScreen;
import com.android.settings.Settings.MobileNetworkActivity;
+import com.android.settings.network.helper.SubscriptionAnnotation;
+import com.android.settings.network.helper.SubscriptionGrouping;
import com.android.settings.widget.AddPreference;
import com.android.settingslib.RestrictedLockUtils;
@@ -123,7 +125,6 @@ public class MobileNetworkSummaryControllerTest {
@Test
- @Ignore
public void getSummary_noSubscriptions_correctSummaryAndClickHandler() {
mController.displayPreference(mPreferenceScreen);
mController.onResume();
@@ -211,23 +212,6 @@ public class MobileNetworkSummaryControllerTest {
SubscriptionManager.INVALID_SUBSCRIPTION_ID)).isEqualTo(sub1.getSubscriptionId());
}
- @Test
- @Ignore
- public void getSummary_providerModel_Enabled() {
- final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
- final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
- when(sub1.getSubscriptionId()).thenReturn(1);
- when(sub2.getSubscriptionId()).thenReturn(2);
- when(sub1.getDisplayName()).thenReturn("sub1");
- when(sub2.getDisplayName()).thenReturn("sub2");
-
- SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1, sub2));
- SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1, sub2));
- mController.displayPreference(mPreferenceScreen);
- mController.onResume();
- assertThat(mController.getSummary()).isEqualTo("sub1, sub2");
- }
-
@Test
public void addButton_noSubscriptionsNoEuiccMgr_noAddClickListener() {
when(mEuiccManager.isEnabled()).thenReturn(false);
@@ -319,7 +303,6 @@ public class MobileNetworkSummaryControllerTest {
}
@Test
- @Ignore
public void onAirplaneModeChanged_oneSubscriptionAirplaneModeGetsTurnedOn_isDisabled() {
final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1));
diff --git a/tests/unit/src/com/android/settings/applications/appinfo/AppLocaleDetailsTest.java b/tests/unit/src/com/android/settings/applications/appinfo/AppLocaleDetailsTest.java
index ed4c127dcf5..0f9d54b441d 100644
--- a/tests/unit/src/com/android/settings/applications/appinfo/AppLocaleDetailsTest.java
+++ b/tests/unit/src/com/android/settings/applications/appinfo/AppLocaleDetailsTest.java
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.LocaleManager;
@@ -32,7 +33,7 @@ import androidx.test.annotation.UiThreadTest;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
-import com.google.common.collect.Iterables;
+import com.android.settingslib.widget.RadioButtonPreference;
import org.junit.Before;
import org.junit.Test;
@@ -40,8 +41,14 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.Locale;
+/**
+ * Unittest for ApplocaleDetails
+ * TODO Need to add a unittest for the UI preference component.
+ */
@RunWith(AndroidJUnit4.class)
public class AppLocaleDetailsTest {
private static final String APP_PACKAGE_NAME = "app_package_name";
@@ -52,7 +59,7 @@ public class AppLocaleDetailsTest {
private LocaleManager mLocaleManager;
private Context mContext;
- private LocaleList mSystemLocales;
+ private Collection mSystemLocales;
private LocaleList mAppLocale;
private String[] mAssetLocales;
private LocaleList mPackageLocales;
@@ -69,12 +76,48 @@ public class AppLocaleDetailsTest {
when(mContext.getSystemService(LocaleManager.class)).thenReturn(mLocaleManager);
setupInitialLocales(
- /* appLocale= */ "en",
+ /* appLocale= */ "en-gb",
/* simCountry= */ "tw",
/* networkCountry= */ "jp",
- /* systemLocales= */ "en, uk, jp, ne",
- /* packageLocales= */ "pa, cn, tw, en",
- /* assetLocales= */ new String[]{"en", "ne", "ms", "pa"});
+ /* systemLocales= */ "en-gb, ru, ja-jp, ne, zh-tw",
+ /* packageLocales= */ "pa, cn, zh-tw, en-gb, ja-jp",
+ /* assetLocales= */ new String[]{"en-gb", "ne", "ms", "pa", "zh-tw", "ja-jp"});
+ }
+
+ @Test
+ @UiThreadTest
+ public void onRadioButtonClicked_setCurrentLocaleToSystem() {
+ AppLocaleDetails appLocaleDetails = new AppLocaleDetails() {
+ @Override
+ void refreshUiInternal() {}
+ };
+ DummyAppLocaleDetailsHelper helper =
+ spy(new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME));
+ appLocaleDetails.mAppLocaleDetailsHelper = helper;
+ RadioButtonPreference pref = new RadioButtonPreference(mContext);
+ pref.setKey(AppLocaleDetails.KEY_SYSTEM_DEFAULT_LOCALE);
+
+ appLocaleDetails.onRadioButtonClicked(pref);
+
+ verify(helper).setAppDefaultLocale(LocaleList.forLanguageTags(""));
+ }
+
+ @Test
+ @UiThreadTest
+ public void onRadioButtonClicked_setCurrentLocaleForUserSelected() {
+ AppLocaleDetails appLocaleDetails = new AppLocaleDetails() {
+ @Override
+ void refreshUiInternal() {}
+ };
+ DummyAppLocaleDetailsHelper helper =
+ spy(new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME));
+ appLocaleDetails.mAppLocaleDetailsHelper = helper;
+ RadioButtonPreference pref = new RadioButtonPreference(mContext);
+ pref.setKey("en");
+
+ appLocaleDetails.onRadioButtonClicked(pref);
+
+ verify(helper).setAppDefaultLocale("en");
}
@Test
@@ -90,7 +133,7 @@ public class AppLocaleDetailsTest {
@Test
@UiThreadTest
- public void handleAllLocalesData_1stLocaleOfSuggestedLocaleListIsAppLocale() {
+ public void handleAllLocalesData_1stLocaleIsAppLocaleAndHasSimAndNetwork() {
Locale simCountryLocale = new Locale("zh", "TW");
Locale networkCountryLocale = new Locale("ja", "JP");
DummyAppLocaleDetailsHelper helper =
@@ -98,36 +141,122 @@ public class AppLocaleDetailsTest {
helper.handleAllLocalesData();
- Locale locale = Iterables.get(helper.getSuggestedLocales(), 0);
+ Collection suggestedLocales = helper.getSuggestedLocales();
+ Locale locale = suggestedLocales.iterator().next();
assertTrue(locale.equals(mAppLocale.get(0)));
- assertTrue(helper.getSuggestedLocales().contains(simCountryLocale));
- assertTrue(helper.getSuggestedLocales().contains(networkCountryLocale));
+ assertTrue(suggestedLocales.contains(simCountryLocale));
+ assertTrue(suggestedLocales.contains(networkCountryLocale));
}
@Test
@UiThreadTest
- public void handleAllLocalesData_withoutAppLocale_1stSuggestedLocaleIsSimCountryLocale() {
- Locale simCountryLocale = new Locale("zh", "TW");
+ public void
+ handleAllLocalesData_noAppAndNoSupportedSimLocale_1stSuggestedLocaleIsAssetLocale() {
+ Locale firstAssetLocale = new Locale("en", "GB");
setupInitialLocales(
/* appLocale= */ "",
/* simCountry= */ "tw",
/* networkCountry= */ "",
- /* systemLocales= */ "en, uk, jp, ne",
+ /* systemLocales= */ "en-gb, ru, ja-jp, ne, zh-tw",
/* packageLocales= */ "",
- /* assetLocales= */ new String[]{});
+ /* assetLocales= */ new String[]{"en-gb", "ne", "ms", "pa", "ja-jp"});
DummyAppLocaleDetailsHelper helper =
new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME);
helper.handleAllLocalesData();
- Locale locale = Iterables.get(helper.getSuggestedLocales(), 0);
- assertTrue(locale.equals(simCountryLocale));
- assertFalse(helper.getSuggestedLocales().contains(mAppLocale.get(0)));
+ Collection suggestedLocales = helper.getSuggestedLocales();
+ Locale locale = suggestedLocales.iterator().next();
+ assertTrue(locale.equals(firstAssetLocale));
}
@Test
@UiThreadTest
- public void handleAllLocalesData_withoutAppLocale_1stSuggestedLocaleIsNetworkCountryLocale() {
+ public void handleAllLocalesData_noAppButHasSupportedSimLocale_1stSuggestedLocaleIsSim() {
+ Locale simLocale = new Locale("zh", "tw");
+ setupInitialLocales(
+ /* appLocale= */ "",
+ /* simCountry= */ "tw",
+ /* networkCountry= */ "",
+ /* systemLocales= */ "en-gb, ru, ja-jp, ne, zh-tw",
+ /* packageLocales= */ "",
+ /* assetLocales= */ new String[]{"en-gb", "ne", "ms", "pa", "ja-jp", "zh-tw"});
+ DummyAppLocaleDetailsHelper helper =
+ new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME);
+
+ helper.handleAllLocalesData();
+
+ Collection suggestedLocales = helper.getSuggestedLocales();
+ Locale locale = suggestedLocales.iterator().next();
+ assertTrue(locale.equals(simLocale));
+ }
+
+ @Test
+ @UiThreadTest
+ public void
+ handleAllLocalesData_noAppButHasSupportedNetworkLocale_1stSuggestedLocaleIsNetwork() {
+ Locale networkLocale = new Locale("ja", "JP");
+ setupInitialLocales(
+ /* appLocale= */ "",
+ /* simCountry= */ "",
+ /* networkCountry= */ "jp",
+ /* systemLocales= */ "en-gb, ru, ja-jp, ne, zh-tw",
+ /* packageLocales= */ "",
+ /* assetLocales= */ new String[]{"en-gb", "ne", "ms", "pa", "ja-jp"});
+ DummyAppLocaleDetailsHelper helper =
+ new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME);
+
+ helper.handleAllLocalesData();
+
+ Collection suggestedLocales = helper.getSuggestedLocales();
+ Locale locale = suggestedLocales.iterator().next();
+ assertTrue(locale.equals(networkLocale));
+ }
+
+ @Test
+ @UiThreadTest
+ public void handleAllLocalesData_noAppSimOrNetworkLocale_suggestedLocalesHasSystemLocale() {
+ setupInitialLocales(
+ /* appLocale= */ "",
+ /* simCountry= */ "",
+ /* networkCountry= */ "",
+ /* systemLocales= */ "en-gb, ru, ja-jp, ne, zh-tw",
+ /* packageLocales= */ "",
+ /* assetLocales= */ new String[]{"en-gb", "ne", "ms", "pa", "zh-tw", "ja-jp"});
+ DummyAppLocaleDetailsHelper helper =
+ new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME);
+ helper.handleAllLocalesData();
+
+ Collection suggestedLocales = helper.getSuggestedLocales();
+ assertTrue(suggestedLocales.contains(Locale.forLanguageTag("ne")));
+ // ru language is not present in the asset locales
+ assertFalse(suggestedLocales.contains(Locale.forLanguageTag("ru")));
+ }
+
+ @Test
+ @UiThreadTest
+ public void handleAllLocalesData_noAppButHasSimAndNetworkLocale_1stLocaleIsSimLocale() {
+ Locale simCountryLocale = new Locale("zh", "TW");
+ setupInitialLocales(
+ /* appLocale= */ "",
+ /* simCountry= */ "tw",
+ /* networkCountry= */ "jp",
+ /* systemLocales= */ "en-gb, ru, ja-jp, ne, zh-tw",
+ /* packageLocales= */ "",
+ /* assetLocales= */ new String[]{"en-gb", "ne", "ms", "pa", "zh-tw", "ja-jp"});
+
+ DummyAppLocaleDetailsHelper helper =
+ new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME);
+ helper.handleAllLocalesData();
+
+ Collection suggestedLocales = helper.getSuggestedLocales();
+ Locale locale = suggestedLocales.iterator().next();
+ assertTrue(locale.equals(simCountryLocale));
+ }
+
+ @Test
+ @UiThreadTest
+ public void handleAllLocalesData_noSupportedLocale_noSuggestedLocales() {
Locale networkCountryLocale = new Locale("en", "GB");
setupInitialLocales(
/* appLocale= */ "",
@@ -141,28 +270,8 @@ public class AppLocaleDetailsTest {
helper.handleAllLocalesData();
- Locale locale = Iterables.get(helper.getSuggestedLocales(), 0);
- assertTrue(locale.equals(networkCountryLocale));
- assertFalse(helper.getSuggestedLocales().contains(mAppLocale.get(0)));
- }
-
- @Test
- @UiThreadTest
- public void handleAllLocalesData_noAppAndSimNetworkLocale_1stLocaleIsFirstOneInSystemLocales() {
- setupInitialLocales(
- /* appLocale= */ "",
- /* simCountry= */ "",
- /* networkCountry= */ "",
- /* systemLocales= */ "en, uk, jp, ne",
- /* packageLocales= */ "",
- /* assetLocales= */ new String[]{});
- DummyAppLocaleDetailsHelper helper =
- new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME);
-
- helper.handleAllLocalesData();
-
- Locale locale = Iterables.get(helper.getSuggestedLocales(), 0);
- assertTrue(locale.equals(mSystemLocales.get(0)));
+ Collection suggestedLocales = helper.getSuggestedLocales();
+ assertTrue(suggestedLocales.size() == 0);
}
@Test
@@ -180,8 +289,10 @@ public class AppLocaleDetailsTest {
helper.handleAllLocalesData();
- Locale locale = Iterables.get(helper.getSuggestedLocales(), 0);
- assertTrue(locale.equals(mSystemLocales.get(0)));
+ Collection suggestedLocales = helper.getSuggestedLocales();
+ Locale locale = suggestedLocales.iterator().next();
+ Locale systemLocale = mSystemLocales.iterator().next();
+ assertTrue(locale.equals(systemLocale));
}
@Test
@@ -248,15 +359,23 @@ public class AppLocaleDetailsTest {
String packageLocales,
String[] assetLocales) {
mAppLocale = LocaleList.forLanguageTags(appLocale);
- mSystemLocales = LocaleList.forLanguageTags(systemLocales);
+ // forLanguageTags does not filter space to the input string. If there is any space included
+ // in string, this will make locale fail to generate.
+ systemLocales = systemLocales.replaceAll("\\s+", "");
+ LocaleList listOfSystemLocales = LocaleList.forLanguageTags(systemLocales);
+ mSystemLocales = new ArrayList<>();
+ for (int i = 0; i < listOfSystemLocales.size(); i++) {
+ mSystemLocales.add(listOfSystemLocales.get(i));
+ }
mAssetLocales = assetLocales;
+ packageLocales = packageLocales.replaceAll("\\s+", "");
mPackageLocales = LocaleList.forLanguageTags(packageLocales);
when(mTelephonyManager.getSimCountryIso()).thenReturn(simCountry);
when(mTelephonyManager.getNetworkCountryIso()).thenReturn(networkCountry);
when(mLocaleManager.getApplicationLocales(anyString())).thenReturn(mAppLocale);
}
- private class DummyAppLocaleDetailsHelper
+ public class DummyAppLocaleDetailsHelper
extends AppLocaleDetails.AppLocaleDetailsHelper {
DummyAppLocaleDetailsHelper(Context context, String packageName) {
@@ -264,12 +383,12 @@ public class AppLocaleDetailsTest {
}
@Override
- String[] getAssetSystemLocales() {
+ String[] getAssetLocales() {
return mAssetLocales;
}
@Override
- LocaleList getCurrentSystemLocales() {
+ Collection getCurrentSystemLocales() {
return mSystemLocales;
}