Merge "[Provider Model] Do not set mobile state repeatedly" into tm-qpr-dev

This commit is contained in:
Zoey Chen
2022-12-14 11:38:55 +00:00
committed by Android (Google) Code Review
2 changed files with 37 additions and 8 deletions

View File

@@ -363,6 +363,9 @@ public class InternetDialog extends SystemUIDialog implements
if (!isChecked && shouldShowMobileDialog()) {
showTurnOffMobileDialog();
} else if (!shouldShowMobileDialog()) {
if (mInternetDialogController.isMobileDataEnabled() == isChecked) {
return;
}
mInternetDialogController.setMobileDataEnabled(mContext, mDefaultDataSubId,
isChecked, false);
}

View File

@@ -84,7 +84,8 @@ public class InternetDialogTest extends SysuiTestCase {
private View mDialogView;
private View mSubTitle;
private LinearLayout mEthernet;
private LinearLayout mMobileDataToggle;
private LinearLayout mMobileDataLayout;
private Switch mMobileToggleSwitch;
private LinearLayout mWifiToggle;
private Switch mWifiToggleSwitch;
private TextView mWifiToggleSummary;
@@ -133,7 +134,8 @@ public class InternetDialogTest extends SysuiTestCase {
mDialogView = mInternetDialog.mDialogView;
mSubTitle = mDialogView.requireViewById(R.id.internet_dialog_subtitle);
mEthernet = mDialogView.requireViewById(R.id.ethernet_layout);
mMobileDataToggle = mDialogView.requireViewById(R.id.mobile_network_layout);
mMobileDataLayout = mDialogView.requireViewById(R.id.mobile_network_layout);
mMobileToggleSwitch = mDialogView.requireViewById(R.id.mobile_toggle);
mWifiToggle = mDialogView.requireViewById(R.id.turn_on_wifi_layout);
mWifiToggleSwitch = mDialogView.requireViewById(R.id.wifi_toggle);
mWifiToggleSummary = mDialogView.requireViewById(R.id.wifi_toggle_summary);
@@ -234,7 +236,7 @@ public class InternetDialogTest extends SysuiTestCase {
mInternetDialog.updateDialog(true);
assertThat(mMobileDataToggle.getVisibility()).isEqualTo(View.GONE);
assertThat(mMobileDataLayout.getVisibility()).isEqualTo(View.GONE);
}
@Test
@@ -246,7 +248,7 @@ public class InternetDialogTest extends SysuiTestCase {
mInternetDialog.updateDialog(true);
assertThat(mMobileDataToggle.getVisibility()).isEqualTo(View.GONE);
assertThat(mMobileDataLayout.getVisibility()).isEqualTo(View.GONE);
// Carrier network should be visible if airplane mode ON and Wi-Fi is ON.
when(mInternetDialogController.isCarrierNetworkActive()).thenReturn(true);
@@ -255,7 +257,7 @@ public class InternetDialogTest extends SysuiTestCase {
mInternetDialog.updateDialog(true);
assertThat(mMobileDataToggle.getVisibility()).isEqualTo(View.VISIBLE);
assertThat(mMobileDataLayout.getVisibility()).isEqualTo(View.VISIBLE);
}
@Test
@@ -265,7 +267,7 @@ public class InternetDialogTest extends SysuiTestCase {
mInternetDialog.updateDialog(true);
assertThat(mMobileDataToggle.getVisibility()).isEqualTo(View.GONE);
assertThat(mMobileDataLayout.getVisibility()).isEqualTo(View.GONE);
}
@Test
@@ -277,7 +279,7 @@ public class InternetDialogTest extends SysuiTestCase {
mInternetDialog.updateDialog(true);
assertThat(mMobileDataToggle.getVisibility()).isEqualTo(View.VISIBLE);
assertThat(mMobileDataLayout.getVisibility()).isEqualTo(View.VISIBLE);
assertThat(mAirplaneModeSummaryText.getVisibility()).isEqualTo(View.VISIBLE);
}
@@ -313,6 +315,30 @@ public class InternetDialogTest extends SysuiTestCase {
assertThat(mAirplaneModeSummaryText.getVisibility()).isEqualTo(View.GONE);
}
@Test
public void updateDialog_mobileDataIsEnabled_checkMobileDataSwitch() {
doReturn(true).when(mInternetDialogController).hasActiveSubId();
when(mInternetDialogController.isCarrierNetworkActive()).thenReturn(true);
when(mInternetDialogController.isMobileDataEnabled()).thenReturn(true);
mMobileToggleSwitch.setChecked(false);
mInternetDialog.updateDialog(true);
assertThat(mMobileToggleSwitch.isChecked()).isTrue();
}
@Test
public void updateDialog_mobileDataIsNotChanged_checkMobileDataSwitch() {
doReturn(true).when(mInternetDialogController).hasActiveSubId();
when(mInternetDialogController.isCarrierNetworkActive()).thenReturn(true);
when(mInternetDialogController.isMobileDataEnabled()).thenReturn(false);
mMobileToggleSwitch.setChecked(false);
mInternetDialog.updateDialog(true);
assertThat(mMobileToggleSwitch.isChecked()).isFalse();
}
@Test
public void updateDialog_wifiOnAndHasInternetWifi_showConnectedWifi() {
mInternetDialog.dismissDialog();
@@ -694,7 +720,7 @@ public class InternetDialogTest extends SysuiTestCase {
private void setNetworkVisible(boolean ethernetVisible, boolean mobileDataVisible,
boolean connectedWifiVisible) {
mEthernet.setVisibility(ethernetVisible ? View.VISIBLE : View.GONE);
mMobileDataToggle.setVisibility(mobileDataVisible ? View.VISIBLE : View.GONE);
mMobileDataLayout.setVisibility(mobileDataVisible ? View.VISIBLE : View.GONE);
mConnectedWifi.setVisibility(connectedWifiVisible ? View.VISIBLE : View.GONE);
}
}