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

Commit 6dfe2a43 authored by Venkatraman Nerellapalli's avatar Venkatraman Nerellapalli Committed by Linux Build Service Account
Browse files

MSIM: Remove inter dependency for cellular data options

Removing the depedency of both subs in multi sim device when enabling cellular data
in both subs at a time,to avoid some issues where data on both subs is required.

Change-Id: I901dcae6beea98261181528e7345db504a9bb07d
CRs-Fixed:1018528
parent 30e132e8
Loading
Loading
Loading
Loading
+1 −73
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@ public class CellDataPreference extends CustomDialogPreference implements Templa

    public int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
    public boolean mChecked;
    public boolean mMultiSimDialog;
    private TelephonyManager mTelephonyManager;
    private SubscriptionManager mSubscriptionManager;
    private String mCarrierMode = SystemProperties.get("persist.radio.carrier_mode", "default");
@@ -65,7 +64,6 @@ public class CellDataPreference extends CustomDialogPreference implements Templa
        super.onRestoreInstanceState(state.getSuperState());
        mTelephonyManager = TelephonyManager.from(getContext());
        mChecked = state.mChecked;
        mMultiSimDialog = state.mMultiSimDialog;
        if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
            mSubId = state.mSubId;
            setKey(getKey() + mSubId);
@@ -77,7 +75,6 @@ public class CellDataPreference extends CustomDialogPreference implements Templa
    protected Parcelable onSaveInstanceState() {
        CellDataState state = new CellDataState(super.onSaveInstanceState());
        state.mChecked = mChecked;
        state.mMultiSimDialog = mMultiSimDialog;
        state.mSubId = mSubId;
        return state;
    }
@@ -116,36 +113,11 @@ public class CellDataPreference extends CustomDialogPreference implements Templa
    protected void performClick(View view) {
        MetricsLogger.action(getContext(), MetricsEvent.ACTION_CELL_DATA_TOGGLE, !mChecked);
        if (mChecked) {
            final SubscriptionInfo currentSir = mSubscriptionManager.getActiveSubscriptionInfo(
                    mSubId);
            final SubscriptionInfo nextSir = mSubscriptionManager.getDefaultDataSubscriptionInfo();

            // If the device is single SIM or is enabling data on the active data SIM then forgo
            // the pop-up.
            if (!Utils.showSimCardTile(getContext()) ||
                    (nextSir != null && currentSir != null &&
                            currentSir.getSubscriptionId() == nextSir.getSubscriptionId())) {
                setMobileDataEnabled(false);
                if (nextSir != null && currentSir != null && !mIsCTClassA &&
                        currentSir.getSubscriptionId() == nextSir.getSubscriptionId()) {
                    disableDataForOtherSubscriptions(mSubId);
                }
                return;
            }
            // disabling data; show confirmation dialog which eventually
            // calls setMobileDataEnabled() once user confirms.
            mMultiSimDialog = false;
            super.performClick(view);
        } else {
            // If we are showing the Sim Card tile then we are a Multi-Sim device.
            if (Utils.showSimCardTile(getContext())) {
                mMultiSimDialog = true;
            super.performClick(view);
        } else {
            setMobileDataEnabled(true);
        }
    }
    }

    private void setMobileDataEnabled(boolean enabled) {
        if (DataUsageSummary.LOGD) Log.d(TAG, "setMobileDataEnabled(" + enabled + ","
@@ -171,12 +143,8 @@ public class CellDataPreference extends CustomDialogPreference implements Templa
    @Override
    protected void onPrepareDialogBuilder(AlertDialog.Builder builder,
            DialogInterface.OnClickListener listener) {
        if (mMultiSimDialog && !mIsCTClassA) {
            showMultiSimDialog(builder, listener);
        } else {
            showDisableDialog(builder, listener);
    }
    }

    private void showDisableDialog(AlertDialog.Builder builder,
            DialogInterface.OnClickListener listener) {
@@ -186,51 +154,14 @@ public class CellDataPreference extends CustomDialogPreference implements Templa
                .setNegativeButton(android.R.string.cancel, null);
    }

    private void showMultiSimDialog(AlertDialog.Builder builder,
            DialogInterface.OnClickListener listener) {
        final SubscriptionInfo currentSir = mSubscriptionManager.getActiveSubscriptionInfo(mSubId);
        final SubscriptionInfo nextSir = mSubscriptionManager.getDefaultDataSubscriptionInfo();

        final String previousName = (nextSir == null)
            ? getContext().getResources().getString(R.string.sim_selection_required_pref)
            : nextSir.getDisplayName().toString();

        builder.setTitle(R.string.sim_change_data_title);
        builder.setMessage(getContext().getString(R.string.sim_change_data_message,
                String.valueOf(currentSir != null ? currentSir.getDisplayName() : null),
                previousName));

        builder.setPositiveButton(R.string.okay, listener);
        builder.setNegativeButton(R.string.cancel, null);
    }

    private void disableDataForOtherSubscriptions(int subId) {
        List<SubscriptionInfo> subInfoList = mSubscriptionManager.getActiveSubscriptionInfoList();
        if (subInfoList != null) {
            for (SubscriptionInfo subInfo : subInfoList) {
                if (subInfo.getSubscriptionId() != subId) {
                    mTelephonyManager.setDataEnabled(subInfo.getSubscriptionId(), false);
                }
            }
        }
    }

    @Override
    protected void onClick(DialogInterface dialog, int which) {
        if (which != DialogInterface.BUTTON_POSITIVE) {
            return;
        }
        if (mMultiSimDialog) {
            if (!mIsCTClassA) {
                mSubscriptionManager.setDefaultDataSubId(mSubId);
                disableDataForOtherSubscriptions(mSubId);
            }
            setMobileDataEnabled(true);
        } else {
            // TODO: extend to modify policy enabled flag.
            setMobileDataEnabled(false);
    }
    }

    private final DataStateListener mListener = new DataStateListener() {
        @Override
@@ -260,7 +191,6 @@ public class CellDataPreference extends CustomDialogPreference implements Templa
    public static class CellDataState extends BaseSavedState {
        public int mSubId;
        public boolean mChecked;
        public boolean mMultiSimDialog;

        public CellDataState(Parcelable base) {
            super(base);
@@ -269,7 +199,6 @@ public class CellDataPreference extends CustomDialogPreference implements Templa
        public CellDataState(Parcel source) {
            super(source);
            mChecked = source.readByte() != 0;
            mMultiSimDialog = source.readByte() != 0;
            mSubId = source.readInt();
        }

@@ -277,7 +206,6 @@ public class CellDataPreference extends CustomDialogPreference implements Templa
        public void writeToParcel(Parcel dest, int flags) {
            super.writeToParcel(dest, flags);
            dest.writeByte((byte) (mChecked ? 1 : 0));
            dest.writeByte((byte) (mMultiSimDialog ? 1 : 0));
            dest.writeInt(mSubId);
        }