Merge "Disable the phone number when no subscription" into main
diff --git a/src/com/android/settings/deviceinfo/PhoneNumberPreferenceController.java b/src/com/android/settings/deviceinfo/PhoneNumberPreferenceController.java
index 6df100c..421963e 100644
--- a/src/com/android/settings/deviceinfo/PhoneNumberPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/PhoneNumberPreferenceController.java
@@ -84,7 +84,7 @@
for (int simSlotNumber = 0; simSlotNumber < mPreferenceList.size(); simSlotNumber++) {
final Preference simStatusPreference = mPreferenceList.get(simSlotNumber);
simStatusPreference.setTitle(getPreferenceTitle(simSlotNumber));
- simStatusPreference.setSummary(getPhoneNumber(simSlotNumber));
+ setPhoneNumber(simSlotNumber);
}
}
@@ -93,24 +93,15 @@
return true;
}
- private CharSequence getFirstPhoneNumber() {
- final List<SubscriptionInfo> subscriptionInfoList =
- mSubscriptionManager.getActiveSubscriptionInfoList();
- if (subscriptionInfoList == null || subscriptionInfoList.isEmpty()) {
- return mContext.getText(R.string.device_info_default);
- }
-
- // For now, We only return first result for slice view.
- return getFormattedPhoneNumber(subscriptionInfoList.get(0));
- }
-
- private CharSequence getPhoneNumber(int simSlot) {
+ private void setPhoneNumber(int simSlot) {
+ final Preference simStatusPreference = mPreferenceList.get(simSlot);
final SubscriptionInfo subscriptionInfo = getSubscriptionInfo(simSlot);
+ simStatusPreference.setEnabled(subscriptionInfo != null);
if (subscriptionInfo == null) {
- return mContext.getText(R.string.device_info_default);
+ simStatusPreference.setSummary(mContext.getString(R.string.device_info_not_available));
+ } else {
+ simStatusPreference.setSummary(getFormattedPhoneNumber(subscriptionInfo));
}
-
- return getFormattedPhoneNumber(subscriptionInfo);
}
private CharSequence getPreferenceTitle(int simSlot) {
diff --git a/tests/unit/src/com/android/settings/deviceinfo/PhoneNumberPreferenceControllerTest.java b/tests/unit/src/com/android/settings/deviceinfo/PhoneNumberPreferenceControllerTest.java
index 9a5399c..05e2f24 100644
--- a/tests/unit/src/com/android/settings/deviceinfo/PhoneNumberPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/deviceinfo/PhoneNumberPreferenceControllerTest.java
@@ -37,6 +37,7 @@
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
+import com.android.settings.R;
import com.android.settings.testutils.ResourcesUtils;
import org.junit.Before;
@@ -135,25 +136,23 @@
}
@Test
- public void getSummary_cannotGetActiveSubscriptionInfo_shouldShowUnknown() {
+ public void getSummary_cannotGetActiveSubscriptionInfo_shouldShowNotAvailable() {
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(null);
mController.displayPreference(mScreen);
mController.updateState(mPreference);
- verify(mPreference).setSummary(ResourcesUtils.getResourcesString(
- mContext, "device_info_default"));
+ verify(mPreference).setSummary(mContext.getString(R.string.device_info_not_available));
}
@Test
- public void getSummary_getEmptySubscriptionInfo_shouldShowUnknown() {
+ public void getSummary_getEmptySubscriptionInfo_shouldShowNotAvailable() {
List<SubscriptionInfo> infos = new ArrayList<>();
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(infos);
mController.displayPreference(mScreen);
mController.updateState(mPreference);
- verify(mPreference).setSummary(ResourcesUtils.getResourcesString(
- mContext, "device_info_default"));
+ verify(mPreference).setSummary(mContext.getString(R.string.device_info_not_available));
}
}