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

Commit 3bbc5abe authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge changes I2bb5c346,I85e7fd9d,Id7b20d4a,I2bf3dc81,Ie2e41c1c, ... am: c854d620

parents bb840248 c854d620
Loading
Loading
Loading
Loading
+57 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import static android.telephony.TelephonyManager.EXTRA_SIM_COMBINATION_WARNING_T
import static android.telephony.TelephonyManager.EXTRA_SIM_COMBINATION_WARNING_TYPE_NONE;
import static android.telephony.TelephonyManager.EXTRA_SUBSCRIPTION_ID;

import android.annotation.CallbackExecutor;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.app.PendingIntent;
@@ -52,6 +53,7 @@ import android.text.TextUtils;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.data.DataSettingsManager.DataSettingsManagerCallback;
import com.android.internal.telephony.util.ArrayUtils;

import java.lang.annotation.Retention;
@@ -59,6 +61,7 @@ import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;

/**
@@ -150,6 +153,9 @@ public class MultiSimSettingController extends Handler {
    // device.
    private final boolean mIsAskEverytimeSupportedForSms;

    // The number of existing DataSettingsControllerCallback
    private int mCallbacksCount;

    private static final String SETTING_USER_PREF_DATA_SUB = "user_preferred_data_sub";

    private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@@ -165,6 +171,37 @@ public class MultiSimSettingController extends Handler {
        }
    };

    private static class DataSettingsControllerCallback extends DataSettingsManagerCallback {
        private final Phone mPhone;

        DataSettingsControllerCallback(@NonNull Phone phone,
                @NonNull @CallbackExecutor Executor executor) {
            super(executor);
            mPhone = phone;
        }

        @Override
        public void onDataEnabledChanged(boolean enabled,
                @TelephonyManager.DataEnabledChangedReason int reason, String callingPackage) {
            int subId = mPhone.getSubId();
            // notifyUserDataEnabled if the change is called from external and reason is
            // DATA_ENABLED_REASON_USER
            if (SubscriptionManager.isValidSubscriptionId(subId)
                    && reason == TelephonyManager.DATA_ENABLED_REASON_USER
                    && !getInstance().mContext.getOpPackageName().equals(callingPackage)) {
                getInstance().notifyUserDataEnabled(mPhone.getSubId(), enabled);
            }
        }

        @Override
        public void onDataRoamingEnabledChanged(boolean enabled) {
            int subId = mPhone.getSubId();
            if (SubscriptionManager.isValidSubscriptionId(subId)) {
                getInstance().notifyRoamingDataEnabled(mPhone.getSubId(), enabled);
            }
        }
    }

    /**
     * Return the singleton or create one if not existed.
     */
@@ -353,6 +390,7 @@ public class MultiSimSettingController extends Handler {
            }
            reEvaluateAll();
        }
        registerDataSettingsControllerCallbackAsNeeded();
    }

    /**
@@ -416,7 +454,11 @@ public class MultiSimSettingController extends Handler {
        reEvaluateAll();
    }

    private boolean isCarrierConfigLoadedForAllSub() {
    /**
     * Check whether carrier config loaded for all subs
     */
    @VisibleForTesting
    public boolean isCarrierConfigLoadedForAllSub() {
        int[] activeSubIds = mSubController.getActiveSubIdList(false);
        for (int activeSubId : activeSubIds) {
            boolean isLoaded = false;
@@ -444,6 +486,7 @@ public class MultiSimSettingController extends Handler {
        for (Phone phone : PhoneFactory.getPhones()) {
            phone.mCi.registerForRadioStateChanged(this, EVENT_RADIO_STATE_CHANGED, null);
        }
        registerDataSettingsControllerCallbackAsNeeded();
    }

    /**
@@ -1009,6 +1052,19 @@ public class MultiSimSettingController extends Handler {
        return true;
    }

    private void registerDataSettingsControllerCallbackAsNeeded() {
        // Only register callbacks for new phone instance as PhoneFactory does not remove
        // existing phone instance.
        Phone[] phones = PhoneFactory.getPhones();
        for (int i = mCallbacksCount; i < phones.length; i++) {
            if (phones[i].isUsingNewDataStack()) {
                phones[i].getDataSettingsManager().registerCallback(
                        new DataSettingsControllerCallback(phones[i], this::post));
            }
        }
        mCallbacksCount = phones.length;
    }

    private void log(String msg) {
        Log.d(LOG_TAG, msg);
    }
+2 −1
Original line number Diff line number Diff line
@@ -801,7 +801,8 @@ public class DataNetworkController extends Handler {
                        new DataSettingsManagerCallback(this::post) {
                            @Override
                            public void onDataEnabledChanged(boolean enabled,
                                    @TelephonyManager.DataEnabledChangedReason int reason) {
                                    @TelephonyManager.DataEnabledChangedReason int reason,
                                    @NonNull String callingPackage) {
                                // If mobile data is enabled by the user, evaluate the unsatisfied
                                // network requests and then attempt to setup data networks to
                                // satisfy them. If mobile data is disabled, evaluate the existing
+18 −16
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ import android.util.IndentingPrintWriter;
import android.util.LocalLog;

import com.android.internal.telephony.GlobalSettingsHelper;
import com.android.internal.telephony.MultiSimSettingController;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.SettingsObserver;
import com.android.internal.telephony.SubscriptionController;
@@ -127,9 +126,11 @@ public class DataSettingsManager extends Handler {
         * @param enabled {@code true} indicates mobile data is enabled.
         * @param reason {@link TelephonyManager.DataEnabledChangedReason} indicating the reason why
         *               mobile data enabled changed.
         * @param callingPackage The package that changed the data enabled state.
         */
        public void onDataEnabledChanged(boolean enabled,
                @TelephonyManager.DataEnabledChangedReason int reason) {}
                @TelephonyManager.DataEnabledChangedReason int reason,
                @NonNull String callingPackage) {}

        /**
         * Called when data enabled override changed.
@@ -228,8 +229,6 @@ public class DataSettingsManager extends Handler {
                        Settings.Global.DATA_ROAMING, mSubId, enabled);
                if (changed) {
                    logl("DataRoamingEnabled changed to " + enabled);
                    MultiSimSettingController.getInstance().notifyRoamingDataEnabled(mSubId,
                            enabled);
                    mDataSettingsManagerCallbacks.forEach(callback -> callback.invokeFromExecutor(
                            () -> callback.onDataRoamingEnabledChanged(enabled)));
                }
@@ -336,12 +335,17 @@ public class DataSettingsManager extends Handler {
    }

    private void updateDataEnabledAndNotify(@TelephonyManager.DataEnabledChangedReason int reason) {
        updateDataEnabledAndNotify(reason, mPhone.getContext().getOpPackageName());
    }

    private void updateDataEnabledAndNotify(@TelephonyManager.DataEnabledChangedReason int reason,
            @NonNull String callingPackage) {
        boolean prevDataEnabled = mIsDataEnabled;
        mIsDataEnabled = isDataEnabled(ApnSetting.TYPE_ALL);
        log("mIsDataEnabled=" + mIsDataEnabled + ", prevDataEnabled=" + prevDataEnabled);
        if (!mInitialized || prevDataEnabled != mIsDataEnabled) {
            if (!mInitialized) mInitialized = true;
            notifyDataEnabledChanged(mIsDataEnabled, reason);
            notifyDataEnabledChanged(mIsDataEnabled, reason, callingPackage);
        }
    }

@@ -429,11 +433,7 @@ public class DataSettingsManager extends Handler {
        if (changed) {
            logl("UserDataEnabled changed to " + enabled);
            mPhone.notifyUserMobileDataStateChanged(enabled);
            updateDataEnabledAndNotify(TelephonyManager.DATA_ENABLED_REASON_USER);
            // TODO: MultiSimSettingController should register the callback instead of let
            //   DataSettingsManager directly feed information to it.
            //   Also revisit if sub id is really needed.
            MultiSimSettingController.getInstance().notifyUserDataEnabled(mSubId, enabled);
            updateDataEnabledAndNotify(TelephonyManager.DATA_ENABLED_REASON_USER, callingPackage);
        }
    }

@@ -464,7 +464,7 @@ public class DataSettingsManager extends Handler {
        if (mDataEnabledSettings.get(TelephonyManager.DATA_ENABLED_REASON_POLICY) != enabled) {
            logl("PolicyDataEnabled changed to " + enabled + ", callingPackage=" + callingPackage);
            mDataEnabledSettings.put(TelephonyManager.DATA_ENABLED_REASON_POLICY, enabled);
            updateDataEnabledAndNotify(TelephonyManager.DATA_ENABLED_REASON_POLICY);
            updateDataEnabledAndNotify(TelephonyManager.DATA_ENABLED_REASON_POLICY, callingPackage);
        }
    }

@@ -477,7 +477,8 @@ public class DataSettingsManager extends Handler {
        if (mDataEnabledSettings.get(TelephonyManager.DATA_ENABLED_REASON_CARRIER) != enabled) {
            logl("CarrierDataEnabled changed to " + enabled + ", callingPackage=" + callingPackage);
            mDataEnabledSettings.put(TelephonyManager.DATA_ENABLED_REASON_CARRIER, enabled);
            updateDataEnabledAndNotify(TelephonyManager.DATA_ENABLED_REASON_CARRIER);
            updateDataEnabledAndNotify(TelephonyManager.DATA_ENABLED_REASON_CARRIER,
                    callingPackage);
        }
    }

@@ -490,7 +491,8 @@ public class DataSettingsManager extends Handler {
        if (mDataEnabledSettings.get(TelephonyManager.DATA_ENABLED_REASON_THERMAL) != enabled) {
            logl("ThermalDataEnabled changed to " + enabled + ", callingPackage=" + callingPackage);
            mDataEnabledSettings.put(TelephonyManager.DATA_ENABLED_REASON_THERMAL, enabled);
            updateDataEnabledAndNotify(TelephonyManager.DATA_ENABLED_REASON_THERMAL);
            updateDataEnabledAndNotify(TelephonyManager.DATA_ENABLED_REASON_THERMAL,
                    callingPackage);
        }
    }

@@ -574,11 +576,11 @@ public class DataSettingsManager extends Handler {
    }

    private void notifyDataEnabledChanged(boolean enabled,
            @TelephonyManager.DataEnabledChangedReason int reason) {
            @TelephonyManager.DataEnabledChangedReason int reason, @NonNull String callingPackage) {
        logl("notifyDataEnabledChanged: enabled=" + enabled + ", reason="
                + dataEnabledChangedReasonToString(reason));
                + dataEnabledChangedReasonToString(reason) + ", callingPackage=" + callingPackage);
        mDataSettingsManagerCallbacks.forEach(callback -> callback.invokeFromExecutor(
                () -> callback.onDataEnabledChanged(enabled, reason)));
                () -> callback.onDataEnabledChanged(enabled, reason, callingPackage)));
        mPhone.notifyDataEnabled(enabled, reason);
    }

+2 −1
Original line number Diff line number Diff line
@@ -231,7 +231,8 @@ public class DataStallRecoveryManager extends Handler {
                            @Override
                            public void onDataEnabledChanged(
                                    boolean enabled,
                                    @TelephonyManager.DataEnabledChangedReason int reason) {
                                    @TelephonyManager.DataEnabledChangedReason int reason,
                                    @NonNull String callingPackage) {
                                onMobileDataEnabledChanged(enabled);
                            }
                        });
+4 −2
Original line number Diff line number Diff line
@@ -512,7 +512,8 @@ public class PhoneSwitcher extends Handler {
                            v -> new DataSettingsManagerCallback(this::post) {
                                @Override
                                public void onDataEnabledChanged(boolean enabled,
                                        @TelephonyManager.DataEnabledChangedReason int reason) {
                                        @TelephonyManager.DataEnabledChangedReason int reason,
                                        @NonNull String callingPackage) {
                                    evaluateIfDataSwitchIsNeeded("EVENT_DATA_ENABLED_CHANGED");
                                }});
                    phone.getDataSettingsManager().registerCallback(
@@ -884,7 +885,8 @@ public class PhoneSwitcher extends Handler {
                        v -> new DataSettingsManagerCallback(this::post) {
                            @Override
                            public void onDataEnabledChanged(boolean enabled,
                                    @TelephonyManager.DataEnabledChangedReason int reason) {
                                    @TelephonyManager.DataEnabledChangedReason int reason,
                                    @NonNull String callingPackage) {
                                evaluateIfDataSwitchIsNeeded("EVENT_DATA_ENABLED_CHANGED");
                            }
                        });
Loading