Loading src/java/com/android/internal/telephony/MultiSimSettingController.java +57 −1 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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; /** Loading Loading @@ -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() { Loading @@ -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. */ Loading Loading @@ -353,6 +390,7 @@ public class MultiSimSettingController extends Handler { } reEvaluateAll(); } registerDataSettingsControllerCallbackAsNeeded(); } /** Loading Loading @@ -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; Loading Loading @@ -444,6 +486,7 @@ public class MultiSimSettingController extends Handler { for (Phone phone : PhoneFactory.getPhones()) { phone.mCi.registerForRadioStateChanged(this, EVENT_RADIO_STATE_CHANGED, null); } registerDataSettingsControllerCallbackAsNeeded(); } /** Loading Loading @@ -1013,6 +1056,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); } Loading src/java/com/android/internal/telephony/data/DataNetworkController.java +2 −1 Original line number Diff line number Diff line Loading @@ -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 Loading src/java/com/android/internal/telephony/data/DataSettingsManager.java +18 −16 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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. Loading Loading @@ -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))); } Loading Loading @@ -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); } } Loading Loading @@ -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); } } Loading Loading @@ -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); } } Loading @@ -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); } } Loading @@ -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); } } Loading Loading @@ -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); } Loading src/java/com/android/internal/telephony/data/DataStallRecoveryManager.java +2 −1 Original line number Diff line number Diff line Loading @@ -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); } }); Loading src/java/com/android/internal/telephony/data/PhoneSwitcher.java +4 −2 Original line number Diff line number Diff line Loading @@ -513,7 +513,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( Loading Loading @@ -885,7 +886,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 Loading
src/java/com/android/internal/telephony/MultiSimSettingController.java +57 −1 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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; /** Loading Loading @@ -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() { Loading @@ -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. */ Loading Loading @@ -353,6 +390,7 @@ public class MultiSimSettingController extends Handler { } reEvaluateAll(); } registerDataSettingsControllerCallbackAsNeeded(); } /** Loading Loading @@ -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; Loading Loading @@ -444,6 +486,7 @@ public class MultiSimSettingController extends Handler { for (Phone phone : PhoneFactory.getPhones()) { phone.mCi.registerForRadioStateChanged(this, EVENT_RADIO_STATE_CHANGED, null); } registerDataSettingsControllerCallbackAsNeeded(); } /** Loading Loading @@ -1013,6 +1056,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); } Loading
src/java/com/android/internal/telephony/data/DataNetworkController.java +2 −1 Original line number Diff line number Diff line Loading @@ -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 Loading
src/java/com/android/internal/telephony/data/DataSettingsManager.java +18 −16 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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. Loading Loading @@ -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))); } Loading Loading @@ -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); } } Loading Loading @@ -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); } } Loading Loading @@ -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); } } Loading @@ -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); } } Loading @@ -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); } } Loading Loading @@ -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); } Loading
src/java/com/android/internal/telephony/data/DataStallRecoveryManager.java +2 −1 Original line number Diff line number Diff line Loading @@ -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); } }); Loading
src/java/com/android/internal/telephony/data/PhoneSwitcher.java +4 −2 Original line number Diff line number Diff line Loading @@ -513,7 +513,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( Loading Loading @@ -885,7 +886,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