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

Commit 976f401c authored by Xiangyu/Malcolm Chen's avatar Xiangyu/Malcolm Chen Committed by Android (Google) Code Review
Browse files

Merge "In DSDS mode, only show Mobile data enabled for default data sub."

parents 279b6087 a135ffa3
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -2037,6 +2037,7 @@ public class SubscriptionController extends ISub.Stub {

        Settings.Global.putInt(mContext.getContentResolver(),
                Settings.Global.MULTI_SIM_DATA_CALL_SUBSCRIPTION, subId);
        updateDataEnabledSettings();
        broadcastDefaultDataSubIdChanged(subId);
    }

@@ -2159,6 +2160,23 @@ public class SubscriptionController extends ISub.Stub {
        return true;
    }

    /**
     * Make sure in multi SIM scenarios, user data is enabled or disabled correctly.
     */
    public void updateDataEnabledSettings() {
        Phone[] phones = PhoneFactory.getPhones();
        if (phones == null || phones.length < 2) return;

        for (Phone phone : phones) {
            if (isActiveSubId(phone.getSubId())) {
                // Only enable it if it was enabled and it's the default data subscription.
                // Otherwise it should be disabled.
                phone.getDataEnabledSettings().setUserDataEnabled(
                        phone.isUserDataEnabled() && phone.getSubId() == getDefaultDataSubId());
            }
        }
    }

    // FIXME: We need we should not be assuming phoneId == slotIndex as it will not be true
    // when there are multiple subscriptions per sim and probably for other reasons.
    public int getSubIdUsingPhoneId(int phoneId) {
+3 −3
Original line number Diff line number Diff line
@@ -587,10 +587,10 @@ public class SubscriptionInfoUpdater extends Handler {
                                uiccSlot.getUiccCard().getCardId()))
                        .forEach(cardId -> updateEmbeddedSubscriptions(cardId));
            }
        }

            // update default subId
            SubscriptionController.getInstance().clearDefaultsForInactiveSubIds();
            SubscriptionController.getInstance().updateDataEnabledSettings();
        }

        SubscriptionController.getInstance().notifySubscriptionInfoChanged();
        logd("updateSubscriptionInfoByIccId:- SubscriptionInfo update complete");
+30 −3
Original line number Diff line number Diff line
@@ -24,12 +24,14 @@ import android.os.RegistrantList;
import android.os.SystemProperties;
import android.provider.Settings;
import android.telephony.Rlog;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.LocalLog;
import android.util.Pair;

import com.android.internal.telephony.Phone;
import com.android.internal.telephony.SubscriptionController;

import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -126,13 +128,28 @@ public class DataEnabledSettings {
    }

    public synchronized void setUserDataEnabled(boolean enabled) {
        // Can't disable data for opportunistic subscription.
        if (isSubOpportunistic() && !enabled) return;
        // Can't enable data for non-default data subscription.
        if (!isDefaultDataSub() && enabled) return;

        localLog("UserDataEnabled", enabled);
        Settings.Global.putInt(mResolver, getMobileDataSettingName(), enabled ? 1 : 0);
        // Make sure if value is not initialized, it gets overwritten by the target value.
        int uninitializedValue = -1;
        int currentValue = Settings.Global.getInt(
                mResolver, getMobileDataSettingName(), uninitializedValue);
        int targetValue = (enabled ? 1 : 0);
        if (currentValue != targetValue) {
            Settings.Global.putInt(mResolver, getMobileDataSettingName(), targetValue);
            mPhone.notifyUserMobileDataStateChanged(enabled);
            updateDataEnabledAndNotify(REASON_USER_DATA_ENABLED);
        }
    }

    public synchronized boolean isUserDataEnabled() {
        // User data should always be true for opportunistic subscription.
        if (isSubOpportunistic()) return true;

        boolean defaultVal = "true".equalsIgnoreCase(SystemProperties.get(
                "ro.com.android.mobiledata", "true"));

@@ -244,6 +261,16 @@ public class DataEnabledSettings {
        mOverallDataEnabledChangedRegistrants.remove(h);
    }

    private boolean isSubOpportunistic() {
        SubscriptionInfo info = SubscriptionController.getInstance().getActiveSubscriptionInfo(
                mPhone.getSubId(), mPhone.getContext().getOpPackageName());
        return (info != null) && info.isOpportunistic();
    }

    private boolean isDefaultDataSub() {
        return SubscriptionController.getInstance().getDefaultDataSubId() == mPhone.getSubId();
    }

    private void log(String s) {
        Rlog.d(LOG_TAG, "[" + mPhone.getPhoneId() + "]" + s);
    }