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

Commit 616453b9 authored by Adnan Begovic's avatar Adnan Begovic Committed by Gerrit Code Review
Browse files

Settings: Disable mobile network settings if sub is invalid/unusable.

Change-Id: Ia4205d536ea0e4a55f543d4cac959f88abb2e49d
parent 03c1704a
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.util.Log;
import android.widget.Toast;

import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.TelephonyIntents;
import com.android.settings.R;
import com.android.settings.RestrictedSettingsFragment;
@@ -81,6 +82,7 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
    private Preference mPrimarySubSelect = null;

    private List<MultiSimEnablerPreference> mSimEnablers = null;
    private List<Preference> mMobileNetworkSettings = null;

    private SubscriptionInfo mCellularData = null;
    private SubscriptionInfo mCalls = null;
@@ -191,6 +193,7 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable

        mAvailableSubInfos = new ArrayList<SubscriptionInfo>(mNumSlots);
        mSimEnablers = new ArrayList<MultiSimEnablerPreference>(mNumSlots);
        mMobileNetworkSettings = new ArrayList<Preference>(mNumSlots);
        for (int i = 0; i < mNumSlots; ++i) {
            final SubscriptionInfo sir = findRecordBySlotId(i);
            if (mNumSlots > 1) {
@@ -216,6 +219,7 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
                    getString(R.string.sim_mobile_network_settings_title, (i + 1)));
            mobileNetworkPref.setIntent(mobileNetworkIntent);
            mobileNetwork.addPreference(mobileNetworkPref);
            mMobileNetworkSettings.add(mobileNetworkPref);
        }
    }

@@ -224,6 +228,7 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
        mSubInfoList = mSubscriptionManager.getActiveSubscriptionInfoList();
        updateActivitesCategory();
        updateSimEnablers();
        updateMobileNetworkSettings();
    }

    private void listen() {
@@ -569,6 +574,23 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
        }
    }

    private void updateMobileNetworkSettings() {
        for (int i = 0; i < mMobileNetworkSettings.size(); i++) {
            Preference preference = mMobileNetworkSettings.get(i);
            if (preference != null) {
                Intent intent = preference.getIntent();
                int subId = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY,
                        SubscriptionManager.INVALID_SUBSCRIPTION_ID);;
                if (!SubscriptionManager.isValidSubscriptionId(subId)
                        || !SubscriptionManager.isUsableSubIdValue(subId)) {
                    preference.setEnabled(false);
                } else {
                    preference.setEnabled(true);
                }
            }
        }
    }

    private void logd(String msg) {
        if (DBG) Log.d(TAG, msg);
    }