LocaleActivity: Handle unexpected MCC strings

Don't crash if MCC string is empty or not a number.

Issue: calyxos#2269
Change-Id: I5efee6e826600869efe133a8a097d9d24337602c
diff --git a/src/org/lineageos/setupwizard/LocaleActivity.java b/src/org/lineageos/setupwizard/LocaleActivity.java
index bf798e5..b350ccf 100644
--- a/src/org/lineageos/setupwizard/LocaleActivity.java
+++ b/src/org/lineageos/setupwizard/LocaleActivity.java
@@ -17,6 +17,7 @@
 import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
+import android.util.Log;
 import android.view.View;
 import android.widget.ArrayAdapter;
 import android.widget.NumberPicker;
@@ -36,6 +37,8 @@
 
 public class LocaleActivity extends BaseSetupWizardActivity {
 
+    private static final String TAG = LocaleActivity.class.getSimpleName();
+
     private ArrayAdapter<com.android.internal.app.LocalePicker.LocaleInfo> mLocaleAdapter;
     private Locale mCurrentLocale;
     private int[] mAdapterIndices;
@@ -173,7 +176,7 @@
         }
         mFetchUpdateSimLocaleTask = Executors.newSingleThreadExecutor();
         mFetchUpdateSimLocaleTask.execute(() -> {
-            Locale locale;
+            Locale locale = null;
             Activity activity = LocaleActivity.this;
             if (!activity.isFinishing() || !activity.isDestroyed()) {
                 // If the sim is currently pin locked, return
@@ -194,8 +197,17 @@
                 }
 
                 // Fetch locale for active sim's MCC
-                int mcc = Integer.parseInt(activeSubs.get(0).getMccString());
-                locale = LocaleUtils.getLocaleFromMcc(activity, mcc, null);
+                final String mccString = activeSubs.get(0).getMccString();
+                try {
+                    if (mccString != null && !mccString.isEmpty()) {
+                        int mcc = Integer.parseInt(mccString);
+                        locale = LocaleUtils.getLocaleFromMcc(activity, mcc, null);
+                    } else {
+                        Log.w(TAG, "Unexpected mccString: '" + mccString + "'");
+                    }
+                } catch (NumberFormatException e) {
+                    Log.w(TAG, "mccString not a number: '" + mccString + "'", e);
+                }
 
                 // If that fails, fall back to preferred languages reported
                 // by the sim