Merge "Fix empty account labels in airplane mode" into nyc-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 05d0eb3..b30f8ce 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -139,6 +139,8 @@
     <string name="phone_accounts_make_sip_calls_with">Make SIP calls with</string>
     <!-- Entry in dialog to "ask first" for accounts when making a call -->
     <string name="phone_accounts_ask_every_time">Ask first</string>
+    <!-- Account label for when a SIM account has no service (i.e. airplane mode) -->
+    <string name="phone_accounts_default_account_label">No network available</string>
 
     <!-- Label for heading of the per-account settings section in the phone accounts settings
          screen. -->
diff --git a/src/com/android/phone/settings/AccountSelectionPreference.java b/src/com/android/phone/settings/AccountSelectionPreference.java
index 6872a16..58072d9 100644
--- a/src/com/android/phone/settings/AccountSelectionPreference.java
+++ b/src/com/android/phone/settings/AccountSelectionPreference.java
@@ -26,8 +26,10 @@
 import android.os.UserHandle;
 import android.preference.ListPreference;
 import android.preference.Preference;
+import android.telecom.PhoneAccount;
 import android.telecom.PhoneAccountHandle;
 import android.telecom.TelecomManager;
+import android.text.TextUtils;
 import android.util.AttributeSet;
 
 import java.util.List;
@@ -82,11 +84,16 @@
         int selectedIndex = mAccounts.length;  // Points to nullSelectionString by default
         int i = 0;
         for ( ; i < mAccounts.length; i++) {
-            CharSequence label = telecomManager.getPhoneAccount(mAccounts[i]).getLabel();
+            PhoneAccount account = telecomManager.getPhoneAccount(mAccounts[i]);
+            CharSequence label = account.getLabel();
             if (label != null) {
                 label = pm.getUserBadgedLabel(label, mAccounts[i].getUserHandle());
             }
-            mEntries[i] = label == null ? null : label.toString();
+            boolean isSimAccount =
+                    account.hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION);
+            mEntries[i] = (TextUtils.isEmpty(label) && isSimAccount)
+                    ? mContext.getString(R.string.phone_accounts_default_account_label)
+                    : String.valueOf(label);
             mEntryValues[i] = Integer.toString(i);
             if (Objects.equals(currentSelection, mAccounts[i])) {
                 selectedIndex = i;
diff --git a/src/com/android/phone/settings/PhoneAccountSettingsFragment.java b/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
index 53f9567..70e9fad 100644
--- a/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
+++ b/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
@@ -357,7 +357,11 @@
 
             // Create the preference & add the label
             Preference accountPreference = new Preference(getActivity());
-            accountPreference.setTitle(account.getLabel());
+            CharSequence accountLabel = account.getLabel();
+            boolean isSimAccount =
+                    account.hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION);
+            accountPreference.setTitle((TextUtils.isEmpty(accountLabel) && isSimAccount)
+                    ? getString(R.string.phone_accounts_default_account_label) : accountLabel);
 
             // Add an icon.
             Icon icon = account.getIcon();