LocaleActivity: Handle unexpected MCC strings
Don't crash if MCC string is empty or not a number. Issue: calyxos#2269 Change-Id: I5efee6e826600869efe133a8a097d9d24337602c
This commit is contained in:
committed by
Michael Bestas
parent
1bbf009729
commit
ac47a02936
@@ -17,6 +17,7 @@ import android.os.Looper;
|
|||||||
import android.telephony.SubscriptionInfo;
|
import android.telephony.SubscriptionInfo;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.NumberPicker;
|
import android.widget.NumberPicker;
|
||||||
@@ -36,6 +37,8 @@ import java.util.concurrent.Executors;
|
|||||||
|
|
||||||
public class LocaleActivity extends BaseSetupWizardActivity {
|
public class LocaleActivity extends BaseSetupWizardActivity {
|
||||||
|
|
||||||
|
private static final String TAG = LocaleActivity.class.getSimpleName();
|
||||||
|
|
||||||
private ArrayAdapter<com.android.internal.app.LocalePicker.LocaleInfo> mLocaleAdapter;
|
private ArrayAdapter<com.android.internal.app.LocalePicker.LocaleInfo> mLocaleAdapter;
|
||||||
private Locale mCurrentLocale;
|
private Locale mCurrentLocale;
|
||||||
private int[] mAdapterIndices;
|
private int[] mAdapterIndices;
|
||||||
@@ -173,7 +176,7 @@ public class LocaleActivity extends BaseSetupWizardActivity {
|
|||||||
}
|
}
|
||||||
mFetchUpdateSimLocaleTask = Executors.newSingleThreadExecutor();
|
mFetchUpdateSimLocaleTask = Executors.newSingleThreadExecutor();
|
||||||
mFetchUpdateSimLocaleTask.execute(() -> {
|
mFetchUpdateSimLocaleTask.execute(() -> {
|
||||||
Locale locale;
|
Locale locale = null;
|
||||||
Activity activity = LocaleActivity.this;
|
Activity activity = LocaleActivity.this;
|
||||||
if (!activity.isFinishing() || !activity.isDestroyed()) {
|
if (!activity.isFinishing() || !activity.isDestroyed()) {
|
||||||
// If the sim is currently pin locked, return
|
// If the sim is currently pin locked, return
|
||||||
@@ -194,8 +197,17 @@ public class LocaleActivity extends BaseSetupWizardActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fetch locale for active sim's MCC
|
// Fetch locale for active sim's MCC
|
||||||
int mcc = Integer.parseInt(activeSubs.get(0).getMccString());
|
final String mccString = activeSubs.get(0).getMccString();
|
||||||
locale = LocaleUtils.getLocaleFromMcc(activity, mcc, null);
|
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
|
// If that fails, fall back to preferred languages reported
|
||||||
// by the sim
|
// by the sim
|
||||||
|
Reference in New Issue
Block a user