Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a2402aba authored by tom hsu's avatar tom hsu Committed by Tom Hsu
Browse files

[Settings] Prevent crash from abnormal behavior.

 - The problem is user remove SIM when stop in ApnSettings page, and do
 unexpected operation.

 - To figure out this problem, listen SIM absent event and make activity
 finish at this moment.

Bug: 189909956
Test: Manual test.
Change-Id: I179c708debcbc31ba9a93e4e434ae810051f5004
parent 46bcf5ae
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -88,6 +88,13 @@ public class ApnSettings extends RestrictedSettingsFragment
            Telephony.Carriers.EDITED_STATUS,
    };

    /** Copied from {@code com.android.internal.telephony.TelephonyIntents} */
    private static final String ACTION_SIM_STATE_CHANGED =
            "android.intent.action.SIM_STATE_CHANGED";
    /** Copied from {@code com.android.internal.telephony.IccCardConstants} */
    public static final String INTENT_KEY_ICC_STATE = "ss";
    public static final String INTENT_VALUE_ICC_ABSENT = "ABSENT";

    private static final int ID_INDEX = 0;
    private static final int NAME_INDEX = 1;
    private static final int APN_INDEX = 2;
@@ -151,7 +158,16 @@ public class ApnSettings extends RestrictedSettingsFragment
    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(
            String action = intent.getAction();
            if (ACTION_SIM_STATE_CHANGED.equals(action)
                    && intent.getStringExtra(INTENT_KEY_ICC_STATE)
                    .equals(INTENT_VALUE_ICC_ABSENT)) {
                final SubscriptionManager sm = context.getSystemService(SubscriptionManager.class);
                if (sm != null && !sm.isActiveSubscriptionId(mSubId)) {
                    Log.d(TAG, "Due to SIM absent, closes APN settings page");
                    finish();
                }
            } else if (intent.getAction().equals(
                    TelephonyManager.ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED)) {
                if (mRestoreDefaultApnMode) {
                    return;
@@ -201,8 +217,9 @@ public class ApnSettings extends RestrictedSettingsFragment
        mSubId = activity.getIntent().getIntExtra(SUB_ID,
                SubscriptionManager.INVALID_SUBSCRIPTION_ID);
        mPhoneId = SubscriptionUtil.getPhoneId(activity, mSubId);
        mIntentFilter = new IntentFilter(
                TelephonyManager.ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED);
        mIntentFilter = new IntentFilter();
        mIntentFilter.addAction(TelephonyManager.ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED);
        mIntentFilter.addAction(ACTION_SIM_STATE_CHANGED);

        setIfOnlyAvailableForAdmins(true);