diff --git a/src/com/android/settings/FallbackHome.java b/src/com/android/settings/FallbackHome.java index 40867aa0726..b70470b5318 100644 --- a/src/com/android/settings/FallbackHome.java +++ b/src/com/android/settings/FallbackHome.java @@ -42,7 +42,7 @@ import java.util.Objects; public class FallbackHome extends Activity { private static final String TAG = "FallbackHome"; - private static final int PROGRESS_TIMEOUT = 2000; + private int mProgressTimeout; private boolean mProvisioned; private WallpaperManager mWallManager; @@ -76,6 +76,12 @@ public class FallbackHome extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + mProgressTimeout = getResources().getInteger( + com.android.internal.R.integer.config_progressTimeoutFallbackHome); + + if (mProgressTimeout <= 0) { + mProgressTimeout = 0; + } // Set ourselves totally black before the device is provisioned so that // we don't flash the wallpaper before SUW @@ -107,7 +113,7 @@ public class FallbackHome extends Activity { protected void onResume() { super.onResume(); if (mProvisioned) { - mHandler.postDelayed(mProgressTimeoutRunnable, PROGRESS_TIMEOUT); + mHandler.postDelayed(mProgressTimeoutRunnable, mProgressTimeout); } } diff --git a/src/com/android/settings/applications/appinfo/AppLocaleDetails.java b/src/com/android/settings/applications/appinfo/AppLocaleDetails.java index aee360e22f6..164cfd9f2fa 100644 --- a/src/com/android/settings/applications/appinfo/AppLocaleDetails.java +++ b/src/com/android/settings/applications/appinfo/AppLocaleDetails.java @@ -18,6 +18,7 @@ package com.android.settings.applications.appinfo; import static com.android.settings.widget.EntityHeaderController.ActionType; import android.app.Activity; +import android.app.LocaleConfig; import android.app.LocaleManager; import android.app.settings.SettingsEnums; import android.content.Context; @@ -289,12 +290,18 @@ public class AppLocaleDetails extends AppInfoBase implements RadioButtonPreferen @VisibleForTesting void handleSupportedLocales() { - //TODO Waiting for PackageManager api - String[] languages = getAssetSystemLocales(); - - for (String language : languages) { - mSupportedLocales.add(Locale.forLanguageTag(language)); + 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)); + } } + if (mSuggestedLocales != null || !mSuggestedLocales.isEmpty()) { mSupportedLocales.removeAll(mSuggestedLocales); } @@ -349,9 +356,23 @@ public class AppLocaleDetails extends AppInfoBase implements RadioButtonPreferen packageManager.getPackageInfo(mPackageName, PackageManager.MATCH_ALL) .applicationInfo).getAssets().getNonSystemLocales(); } catch (PackageManager.NameNotFoundException e) { - Log.w(TAG, "Can not found the package name : " + e); + Log.w(TAG, "Can not found the package name : " + mPackageName + " / " + e); } return new String[0]; } + + @VisibleForTesting + LocaleList getPackageLocales() { + try { + LocaleConfig localeConfig = + new LocaleConfig(mContext.createPackageContext(mPackageName, 0)); + if (localeConfig.getStatus() == LocaleConfig.STATUS_SUCCESS) { + return localeConfig.getSupportedLocales(); + } + } catch (PackageManager.NameNotFoundException e) { + Log.w(TAG, "Can not found the package name : " + mPackageName + " / " + e); + } + return null; + } } } diff --git a/src/com/android/settings/location/LocationSettings.java b/src/com/android/settings/location/LocationSettings.java index 8f9787b08a5..13300c93c36 100644 --- a/src/com/android/settings/location/LocationSettings.java +++ b/src/com/android/settings/location/LocationSettings.java @@ -63,6 +63,7 @@ public class LocationSettings extends DashboardFragment implements private LocationSwitchBarController mSwitchBarController; private LocationEnabler mLocationEnabler; + private RecentLocationAccessPreferenceController mController; @Override public int getMetricsCategory() { @@ -86,12 +87,21 @@ public class LocationSettings extends DashboardFragment implements super.onAttach(context); use(AppLocationPermissionPreferenceController.class).init(this); - use(RecentLocationAccessPreferenceController.class).init(this); + mController = use(RecentLocationAccessPreferenceController.class); + mController.init(this); use(RecentLocationAccessSeeAllButtonPreferenceController.class).init(this); use(LocationForWorkPreferenceController.class).init(this); use(LocationSettingsFooterPreferenceController.class).init(this); } + @Override + public void onPause() { + super.onPause(); + if (mController != null) { + mController.clearPreferenceList(); + } + } + @Override protected int getPreferenceScreenResId() { return R.xml.location_settings; diff --git a/src/com/android/settings/location/RecentLocationAccessPreferenceController.java b/src/com/android/settings/location/RecentLocationAccessPreferenceController.java index ba660ee3c6d..ea3704cccc0 100644 --- a/src/com/android/settings/location/RecentLocationAccessPreferenceController.java +++ b/src/com/android/settings/location/RecentLocationAccessPreferenceController.java @@ -126,6 +126,15 @@ public class RecentLocationAccessPreferenceController extends LocationBasePrefer mCategoryRecentLocationRequests.setVisible(enabled); } + /** + * Clears the list of apps which recently accessed location from the screen. + */ + public void clearPreferenceList() { + if (mCategoryRecentLocationRequests != null) { + mCategoryRecentLocationRequests.removeAll(); + } + } + /** * Initialize {@link ProfileSelectFragment.ProfileType} of the controller * diff --git a/src/com/android/settings/network/SwitchToEuiccSubscriptionSidecar.java b/src/com/android/settings/network/SwitchToEuiccSubscriptionSidecar.java index 9524164bc33..c6d1ea0149b 100644 --- a/src/com/android/settings/network/SwitchToEuiccSubscriptionSidecar.java +++ b/src/com/android/settings/network/SwitchToEuiccSubscriptionSidecar.java @@ -69,20 +69,15 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar { } } - /** Starts calling EuiccManager#switchToSubscription to enable/disable the eSIM profile. */ - // ToDo: delete this api and refactor the related code. - public void run(int subscriptionId) { - setState(State.RUNNING, Substate.UNUSED); - mCallbackIntent = createCallbackIntent(); - mEuiccManager.switchToSubscription(subscriptionId, mCallbackIntent); - } - /** * Starts calling EuiccManager#switchToSubscription to enable/disable the eSIM profile. * * @param subscriptionId the esim's subscriptionId. - * @param port the esim's portId. If user wants to inactivate esim, then user must to assign the - * the port. If user wants to activate esim, then the port can be -1. + * @param port the esim's portId. If user wants to inactivate esim, then user must to assign + * the corresponding port. If user wants to activate esim, then the port can be + * {@link UiccSlotUtil#INVALID_PORT_ID}. When it is + * {@link UiccSlotUtil#INVALID_PORT_ID}, the system will reassign a corresponding + * port id. * @param removedSubInfo if the all of slots have sims, it should remove the one of active sim. * If the removedSubInfo is null, then use the default value. * The default value is the esim slot and portId 0. diff --git a/src/com/android/settings/network/SwitchToRemovableSlotSidecar.java b/src/com/android/settings/network/SwitchToRemovableSlotSidecar.java index 9b9c0ddbd1a..e98b405ee3d 100644 --- a/src/com/android/settings/network/SwitchToRemovableSlotSidecar.java +++ b/src/com/android/settings/network/SwitchToRemovableSlotSidecar.java @@ -80,29 +80,6 @@ public class SwitchToRemovableSlotSidecar extends EuiccOperationSidecar } } - /** - * Starts switching to the removable slot. It disables the active eSIM profile before switching - * if there is one. - * - * @param physicalSlotId removable physical SIM slot ID. - */ - // ToDo: delete this api and refactor the related code. - public void run(int physicalSlotId) { - mPhysicalSlotId = physicalSlotId; - SubscriptionManager subscriptionManager = - getContext().getSystemService(SubscriptionManager.class); - if (SubscriptionUtil.getActiveSubscriptions(subscriptionManager).stream() - .anyMatch(SubscriptionInfo::isEmbedded)) { - // In SS mode, the esim is active, then inactivate the esim. - Log.i(TAG, "There is an active eSIM profile. Disable the profile first."); - // Use INVALID_SUBSCRIPTION_ID to disable the only active profile. - mSwitchToSubscriptionSidecar.run(SubscriptionManager.INVALID_SUBSCRIPTION_ID, 0, null); - } else { - Log.i(TAG, "There is no active eSIM profiles. Start to switch to removable slot."); - mSwitchSlotSidecar.runSwitchToRemovableSlot(mPhysicalSlotId, null); - } - } - /** * Starts switching to the removable slot. * diff --git a/src/com/android/settings/sim/ChooseSimActivity.java b/src/com/android/settings/sim/ChooseSimActivity.java index d0ccc4c9d01..cebc1ba6d98 100644 --- a/src/com/android/settings/sim/ChooseSimActivity.java +++ b/src/com/android/settings/sim/ChooseSimActivity.java @@ -159,11 +159,12 @@ public class ChooseSimActivity extends Activity mSelectedItemIndex = subItem.getId(); if (mSelectedItemIndex == INDEX_PSIM) { Log.i(TAG, "Ready to switch to pSIM slot."); - mSwitchToRemovableSlotSidecar.run(UiccSlotUtil.INVALID_PHYSICAL_SLOT_ID); + mSwitchToRemovableSlotSidecar.run(UiccSlotUtil.INVALID_PHYSICAL_SLOT_ID, null); } else { Log.i(TAG, "Ready to switch to eSIM subscription with index: " + mSelectedItemIndex); mSwitchToEuiccSubscriptionSidecar.run( - mEmbeddedSubscriptions.get(mSelectedItemIndex).getSubscriptionId()); + mEmbeddedSubscriptions.get(mSelectedItemIndex).getSubscriptionId(), + UiccSlotUtil.INVALID_PORT_ID, null); } } diff --git a/src/com/android/settings/sim/SwitchToEsimConfirmDialogActivity.java b/src/com/android/settings/sim/SwitchToEsimConfirmDialogActivity.java index be2fa2d1c6d..db6e1b44f34 100644 --- a/src/com/android/settings/sim/SwitchToEsimConfirmDialogActivity.java +++ b/src/com/android/settings/sim/SwitchToEsimConfirmDialogActivity.java @@ -23,6 +23,7 @@ import android.util.Log; import com.android.settings.R; import com.android.settings.SidecarFragment; import com.android.settings.network.SwitchToEuiccSubscriptionSidecar; +import com.android.settings.network.UiccSlotUtil; import com.android.settings.network.telephony.AlertDialogFragment; import com.android.settings.network.telephony.ConfirmDialogFragment; import com.android.settings.network.telephony.SubscriptionActionDialogActivity; @@ -110,7 +111,8 @@ public class SwitchToEsimConfirmDialogActivity extends SubscriptionActionDialogA return; } Log.i(TAG, "User confirmed to switch to embedded slot."); - mSwitchToEuiccSubscriptionSidecar.run(mSubToEnabled.getSubscriptionId()); + mSwitchToEuiccSubscriptionSidecar.run(mSubToEnabled.getSubscriptionId(), + UiccSlotUtil.INVALID_PORT_ID, null); showProgressDialog( getString( R.string.sim_action_switch_sub_dialog_progress, diff --git a/src/com/android/settings/sim/receivers/SimSlotChangeHandler.java b/src/com/android/settings/sim/receivers/SimSlotChangeHandler.java index e0bc9cd7995..8c8964f798c 100644 --- a/src/com/android/settings/sim/receivers/SimSlotChangeHandler.java +++ b/src/com/android/settings/sim/receivers/SimSlotChangeHandler.java @@ -210,10 +210,11 @@ public class SimSlotChangeHandler { } List groupedEmbeddedSubscriptions = getGroupedEmbeddedSubscriptions(); - if (groupedEmbeddedSubscriptions.size() == 0 || !removableSlotInfo.getPorts().stream() .findFirst().get().isActive()) { - Log.i(TAG, "eSIM slot is active or no subscriptions exist. Do nothing."); + Log.i(TAG, "eSIM slot is active or no subscriptions exist. Do nothing." + + " The removableSlotInfo: " + removableSlotInfo + + ", groupedEmbeddedSubscriptions: " + groupedEmbeddedSubscriptions); return; } 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 1042a6a20a7..ed4c127dcf5 100644 --- a/tests/unit/src/com/android/settings/applications/appinfo/AppLocaleDetailsTest.java +++ b/tests/unit/src/com/android/settings/applications/appinfo/AppLocaleDetailsTest.java @@ -55,6 +55,7 @@ public class AppLocaleDetailsTest { private LocaleList mSystemLocales; private LocaleList mAppLocale; private String[] mAssetLocales; + private LocaleList mPackageLocales; @Before @UiThreadTest @@ -67,11 +68,13 @@ public class AppLocaleDetailsTest { when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager); when(mContext.getSystemService(LocaleManager.class)).thenReturn(mLocaleManager); - setupInitialLocales("en", - "tw", - "jp", - "en, uk, jp, ne", - new String[]{"en", "ne", "ms", "pa"}); + setupInitialLocales( + /* appLocale= */ "en", + /* simCountry= */ "tw", + /* networkCountry= */ "jp", + /* systemLocales= */ "en, uk, jp, ne", + /* packageLocales= */ "pa, cn, tw, en", + /* assetLocales= */ new String[]{"en", "ne", "ms", "pa"}); } @Test @@ -105,11 +108,13 @@ public class AppLocaleDetailsTest { @UiThreadTest public void handleAllLocalesData_withoutAppLocale_1stSuggestedLocaleIsSimCountryLocale() { Locale simCountryLocale = new Locale("zh", "TW"); - setupInitialLocales("", - "tw", - "", - "en, uk, jp, ne", - new String[]{"en", "ne", "ms", "pa"}); + setupInitialLocales( + /* appLocale= */ "", + /* simCountry= */ "tw", + /* networkCountry= */ "", + /* systemLocales= */ "en, uk, jp, ne", + /* packageLocales= */ "", + /* assetLocales= */ new String[]{}); DummyAppLocaleDetailsHelper helper = new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME); @@ -124,11 +129,13 @@ public class AppLocaleDetailsTest { @UiThreadTest public void handleAllLocalesData_withoutAppLocale_1stSuggestedLocaleIsNetworkCountryLocale() { Locale networkCountryLocale = new Locale("en", "GB"); - setupInitialLocales("", - "", - "gb", - "en, uk, jp, ne", - new String[]{"en", "ne", "ms", "pa"}); + setupInitialLocales( + /* appLocale= */ "", + /* simCountry= */ "", + /* networkCountry= */ "gb", + /* systemLocales= */ "en, uk, jp, ne", + /* packageLocales= */ "", + /* assetLocales= */ new String[]{}); DummyAppLocaleDetailsHelper helper = new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME); @@ -142,11 +149,32 @@ public class AppLocaleDetailsTest { @Test @UiThreadTest public void handleAllLocalesData_noAppAndSimNetworkLocale_1stLocaleIsFirstOneInSystemLocales() { - setupInitialLocales("", - "", - "", - "en, uk, jp, ne", - new String[]{"en", "ne", "ms", "pa"}); + 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))); + } + + @Test + @UiThreadTest + public void handleAllLocalesData_hasPackageAndSystemLocales_1stLocaleIs1stOneInSystemLocales() { + setupInitialLocales( + /* appLocale= */ "", + /* simCountry= */ "", + /* networkCountry= */ "", + /* systemLocales= */ "en, uk, jp, ne", + /* packageLocales= */ "pa, cn, tw, en", + /* assetLocales= */ new String[]{}); DummyAppLocaleDetailsHelper helper = new DummyAppLocaleDetailsHelper(mContext, APP_PACKAGE_NAME); @@ -204,6 +232,11 @@ public class AppLocaleDetailsTest { * * @param systemLocales System locales, a locale list by a multiple language tags with comma. * example: "en, uk, jp" + * + * @param packageLocales PackageManager locales, a locale list by a multiple language tags with + * comma. + * example: "en, uk, jp" + * * @param assetLocales Asset locales, a locale list by a multiple language tags with String * array. * example: new String[] {"en", "ne", "ms", "pa"} @@ -212,10 +245,12 @@ public class AppLocaleDetailsTest { String simCountry, String networkCountry, String systemLocales, + String packageLocales, String[] assetLocales) { mAppLocale = LocaleList.forLanguageTags(appLocale); mSystemLocales = LocaleList.forLanguageTags(systemLocales); mAssetLocales = assetLocales; + mPackageLocales = LocaleList.forLanguageTags(packageLocales); when(mTelephonyManager.getSimCountryIso()).thenReturn(simCountry); when(mTelephonyManager.getNetworkCountryIso()).thenReturn(networkCountry); when(mLocaleManager.getApplicationLocales(anyString())).thenReturn(mAppLocale); @@ -237,6 +272,10 @@ public class AppLocaleDetailsTest { LocaleList getCurrentSystemLocales() { return mSystemLocales; } - } + @Override + LocaleList getPackageLocales() { + return mPackageLocales; + } + } }