Loading src/java/com/android/internal/telephony/MultiSimSettingController.java +4 −6 Original line number Diff line number Diff line Loading @@ -163,15 +163,13 @@ public class MultiSimSettingController extends Handler { } @Override public void onDataEnabledChanged(boolean enabled, @TelephonyManager.DataEnabledChangedReason int reason, String callingPackage) { public void onUserDataEnabledChanged(boolean enabled, @NonNull String callingPackage) { int subId = mPhone.getSubId(); // notifyUserDataEnabled if the change is called from external and reason is // DATA_ENABLED_REASON_USER // only notifyUserDataEnabled if the change is called from external to avoid // setUserDataEnabledForGroup infinite loop if (SubscriptionManager.isValidSubscriptionId(subId) && reason == TelephonyManager.DATA_ENABLED_REASON_USER && !getInstance().mContext.getOpPackageName().equals(callingPackage)) { getInstance().notifyUserDataEnabled(mPhone.getSubId(), enabled); getInstance().notifyUserDataEnabled(subId, enabled); } } Loading src/java/com/android/internal/telephony/data/DataSettingsManager.java +7 −4 Original line number Diff line number Diff line Loading @@ -133,8 +133,9 @@ public class DataSettingsManager extends Handler { * Called when user data enabled state changed. * * @param enabled {@code true} indicates user mobile data is enabled. * @param callingPackage The package that changed the data enabled state. */ public void onUserDataEnabledChanged(boolean enabled) {} public void onUserDataEnabledChanged(boolean enabled, @NonNull String callingPackage) {} /** * Called when overall data enabled state changed. Loading Loading @@ -302,9 +303,11 @@ public class DataSettingsManager extends Handler { phone.getDataSettingsManager().registerCallback(new DataSettingsManagerCallback( this::post) { @Override public void onUserDataEnabledChanged(boolean enabled) { public void onUserDataEnabledChanged(boolean enabled, @NonNull String callingPackage) { log("phone" + phone.getPhoneId() + " onUserDataEnabledChanged " + enabled + ", reevaluating mobile data policies"); + enabled + " by " + callingPackage + ", reevaluating mobile data policies"); DataSettingsManager.this.updateDataEnabledAndNotify( TelephonyManager.DATA_ENABLED_REASON_OVERRIDE); } Loading Loading @@ -439,7 +442,7 @@ public class DataSettingsManager extends Handler { logl("UserDataEnabled changed to " + enabled); mPhone.notifyUserMobileDataStateChanged(enabled); mDataSettingsManagerCallbacks.forEach(callback -> callback.invokeFromExecutor( () -> callback.onUserDataEnabledChanged(enabled))); () -> callback.onUserDataEnabledChanged(enabled, callingPackage))); updateDataEnabledAndNotify(TelephonyManager.DATA_ENABLED_REASON_USER, callingPackage); } } Loading tests/telephonytests/src/com/android/internal/telephony/data/DataNetworkControllerTest.java +17 −2 Original line number Diff line number Diff line Loading @@ -1641,13 +1641,27 @@ public class DataNetworkControllerTest extends TelephonyTest { doReturn(true).when(controller).isCarrierConfigLoadedForAllSub(); replaceInstance(MultiSimSettingController.class, "sInstance", null, controller); // Mock Data Overall data is always enabled due to auto data switch, // verify the test shouldn't rely on the overall data status doReturn(1).when(mPhone).getSubId(); doReturn(2).when(mSubscriptionManagerService).getDefaultDataSubId(); Phone phone2 = Mockito.mock(Phone.class); phone2.mCi = mSimulatedCommands; doReturn(true).when(phone2).isUserDataEnabled(); doReturn(mDataSettingsManager).when(phone2).getDataSettingsManager(); replaceInstance(PhoneFactory.class, "sPhones", null, new Phone[]{mPhone, phone2}); mDataNetworkControllerUT.getDataSettingsManager().setMobileDataPolicy(TelephonyManager .MOBILE_DATA_POLICY_AUTO_DATA_SWITCH, true); processAllMessages(); clearInvocations(mPhone); controller.notifyAllSubscriptionLoaded(); mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled( TelephonyManager.DATA_ENABLED_REASON_USER, !isDataEnabled, mContext.getOpPackageName()); processAllMessages(); // Verify not to notify MultiSimSettingController // Verify not to notify MultiSimSettingController due to internal calling package verify(controller, never()).notifyUserDataEnabled(anyInt(), anyBoolean()); mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled( Loading @@ -1655,7 +1669,7 @@ public class DataNetworkControllerTest extends TelephonyTest { mContext.getOpPackageName()); processAllMessages(); // Verify not to notify MultiSimSettingController // Verify not to notify MultiSimSettingController due to internal calling package verify(controller, never()).notifyUserDataEnabled(anyInt(), anyBoolean()); mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled( Loading @@ -1666,6 +1680,7 @@ public class DataNetworkControllerTest extends TelephonyTest { // Verify to notify MultiSimSettingController exactly 2 times verify(controller, times(2)).notifyUserDataEnabled(anyInt(), anyBoolean()); verify(mPhone, never()).notifyDataEnabled(anyBoolean(), anyInt()); } @Test Loading tests/telephonytests/src/com/android/internal/telephony/data/DataSettingsManagerTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -175,7 +175,7 @@ public class DataSettingsManagerTest extends TelephonyTest { // Verify the override takes effect upon DDS user enabled. doReturn(true).when(phone2).isUserDataEnabled(); callback.onUserDataEnabledChanged(true); callback.onUserDataEnabledChanged(true, "callingPackage"); verify(mPhone).notifyDataEnabled(true, TelephonyManager.DATA_ENABLED_REASON_OVERRIDE); } } Loading
src/java/com/android/internal/telephony/MultiSimSettingController.java +4 −6 Original line number Diff line number Diff line Loading @@ -163,15 +163,13 @@ public class MultiSimSettingController extends Handler { } @Override public void onDataEnabledChanged(boolean enabled, @TelephonyManager.DataEnabledChangedReason int reason, String callingPackage) { public void onUserDataEnabledChanged(boolean enabled, @NonNull String callingPackage) { int subId = mPhone.getSubId(); // notifyUserDataEnabled if the change is called from external and reason is // DATA_ENABLED_REASON_USER // only notifyUserDataEnabled if the change is called from external to avoid // setUserDataEnabledForGroup infinite loop if (SubscriptionManager.isValidSubscriptionId(subId) && reason == TelephonyManager.DATA_ENABLED_REASON_USER && !getInstance().mContext.getOpPackageName().equals(callingPackage)) { getInstance().notifyUserDataEnabled(mPhone.getSubId(), enabled); getInstance().notifyUserDataEnabled(subId, enabled); } } Loading
src/java/com/android/internal/telephony/data/DataSettingsManager.java +7 −4 Original line number Diff line number Diff line Loading @@ -133,8 +133,9 @@ public class DataSettingsManager extends Handler { * Called when user data enabled state changed. * * @param enabled {@code true} indicates user mobile data is enabled. * @param callingPackage The package that changed the data enabled state. */ public void onUserDataEnabledChanged(boolean enabled) {} public void onUserDataEnabledChanged(boolean enabled, @NonNull String callingPackage) {} /** * Called when overall data enabled state changed. Loading Loading @@ -302,9 +303,11 @@ public class DataSettingsManager extends Handler { phone.getDataSettingsManager().registerCallback(new DataSettingsManagerCallback( this::post) { @Override public void onUserDataEnabledChanged(boolean enabled) { public void onUserDataEnabledChanged(boolean enabled, @NonNull String callingPackage) { log("phone" + phone.getPhoneId() + " onUserDataEnabledChanged " + enabled + ", reevaluating mobile data policies"); + enabled + " by " + callingPackage + ", reevaluating mobile data policies"); DataSettingsManager.this.updateDataEnabledAndNotify( TelephonyManager.DATA_ENABLED_REASON_OVERRIDE); } Loading Loading @@ -439,7 +442,7 @@ public class DataSettingsManager extends Handler { logl("UserDataEnabled changed to " + enabled); mPhone.notifyUserMobileDataStateChanged(enabled); mDataSettingsManagerCallbacks.forEach(callback -> callback.invokeFromExecutor( () -> callback.onUserDataEnabledChanged(enabled))); () -> callback.onUserDataEnabledChanged(enabled, callingPackage))); updateDataEnabledAndNotify(TelephonyManager.DATA_ENABLED_REASON_USER, callingPackage); } } Loading
tests/telephonytests/src/com/android/internal/telephony/data/DataNetworkControllerTest.java +17 −2 Original line number Diff line number Diff line Loading @@ -1641,13 +1641,27 @@ public class DataNetworkControllerTest extends TelephonyTest { doReturn(true).when(controller).isCarrierConfigLoadedForAllSub(); replaceInstance(MultiSimSettingController.class, "sInstance", null, controller); // Mock Data Overall data is always enabled due to auto data switch, // verify the test shouldn't rely on the overall data status doReturn(1).when(mPhone).getSubId(); doReturn(2).when(mSubscriptionManagerService).getDefaultDataSubId(); Phone phone2 = Mockito.mock(Phone.class); phone2.mCi = mSimulatedCommands; doReturn(true).when(phone2).isUserDataEnabled(); doReturn(mDataSettingsManager).when(phone2).getDataSettingsManager(); replaceInstance(PhoneFactory.class, "sPhones", null, new Phone[]{mPhone, phone2}); mDataNetworkControllerUT.getDataSettingsManager().setMobileDataPolicy(TelephonyManager .MOBILE_DATA_POLICY_AUTO_DATA_SWITCH, true); processAllMessages(); clearInvocations(mPhone); controller.notifyAllSubscriptionLoaded(); mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled( TelephonyManager.DATA_ENABLED_REASON_USER, !isDataEnabled, mContext.getOpPackageName()); processAllMessages(); // Verify not to notify MultiSimSettingController // Verify not to notify MultiSimSettingController due to internal calling package verify(controller, never()).notifyUserDataEnabled(anyInt(), anyBoolean()); mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled( Loading @@ -1655,7 +1669,7 @@ public class DataNetworkControllerTest extends TelephonyTest { mContext.getOpPackageName()); processAllMessages(); // Verify not to notify MultiSimSettingController // Verify not to notify MultiSimSettingController due to internal calling package verify(controller, never()).notifyUserDataEnabled(anyInt(), anyBoolean()); mDataNetworkControllerUT.getDataSettingsManager().setDataEnabled( Loading @@ -1666,6 +1680,7 @@ public class DataNetworkControllerTest extends TelephonyTest { // Verify to notify MultiSimSettingController exactly 2 times verify(controller, times(2)).notifyUserDataEnabled(anyInt(), anyBoolean()); verify(mPhone, never()).notifyDataEnabled(anyBoolean(), anyInt()); } @Test Loading
tests/telephonytests/src/com/android/internal/telephony/data/DataSettingsManagerTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -175,7 +175,7 @@ public class DataSettingsManagerTest extends TelephonyTest { // Verify the override takes effect upon DDS user enabled. doReturn(true).when(phone2).isUserDataEnabled(); callback.onUserDataEnabledChanged(true); callback.onUserDataEnabledChanged(true, "callingPackage"); verify(mPhone).notifyDataEnabled(true, TelephonyManager.DATA_ENABLED_REASON_OVERRIDE); } }