[Provider Model] Internet Panel - Airplane mode is on

- Add "Airplane mode is on" to sub-title
  - Set the header layout to CENTER_HORIZONTAL if it's no icon

- Hide "Settings" button

- Screenshot
  https://screenshot.googleplex.com/6m5dFVZu7ar4nKW

Bug: 178717651
Test: manual test
atest InternetConnectivityPanelTest \
      PanelFragmentTest \
      ProviderModelSliceTest

Change-Id: I899a817fd99415e9cad608aa4deac1e45365696a
This commit is contained in:
Weng Su
2021-02-02 14:32:01 +08:00
parent bcfd351521
commit 7a62ab1fff
7 changed files with 245 additions and 159 deletions

View File

@@ -16,8 +16,6 @@
package com.android.settings.network;
import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -25,6 +23,7 @@ import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -387,35 +386,34 @@ public class ProviderModelSliceTest {
}
@Test
public void onNotifyChange_intentToggleActionOn_shouldSetCarrierNetworkEnabledTrue() {
when(mMockProviderModelSlice.defaultSubscriptionIsUsable(anyInt())).thenReturn(true);
Intent intent = mMockProviderModelSlice.getBroadcastIntent(mContext).getIntent();
intent.putExtra(EXTRA_TOGGLE_STATE, true);
mMockProviderModelSlice.onNotifyChange(intent);
public void doCarrierNetworkAction_toggleActionSetDataEnabled_setCarrierNetworkEnabledTrue() {
mMockProviderModelSlice.doCarrierNetworkAction(true /* isToggleAction */,
true /* isDataEnabled */);
verify(mMockNetworkProviderWorker).setCarrierNetworkEnabled(true);
}
@Test
public void onNotifyChange_intentToggleActionOff_shouldSetCarrierNetworkEnabledFalse() {
when(mMockProviderModelSlice.defaultSubscriptionIsUsable(anyInt())).thenReturn(true);
Intent intent = mMockProviderModelSlice.getBroadcastIntent(mContext).getIntent();
intent.putExtra(EXTRA_TOGGLE_STATE, false);
mMockProviderModelSlice.onNotifyChange(intent);
public void doCarrierNetworkAction_toggleActionSetDataDisabled_setCarrierNetworkEnabledFalse() {
mMockProviderModelSlice.doCarrierNetworkAction(true /* isToggleAction */,
false /* isDataEnabled */);
verify(mMockNetworkProviderWorker).setCarrierNetworkEnabled(false);
}
@Test
public void onNotifyChange_intentPrimaryAction_shouldConnectCarrierNetwork() {
when(mMockProviderModelSlice.defaultSubscriptionIsUsable(anyInt())).thenReturn(true);
when(mTelephonyManager.isDataEnabled()).thenReturn(true);
Intent intent = mMockProviderModelSlice.getBroadcastIntent(mContext).getIntent();
mMockProviderModelSlice.onNotifyChange(intent);
public void doCarrierNetworkAction_primaryActionAndDataEnabled_connectCarrierNetwork() {
mMockProviderModelSlice.doCarrierNetworkAction(false /* isToggleAction */,
true /* isDataEnabled */);
verify(mMockNetworkProviderWorker).connectCarrierNetwork();
}
@Test
public void doCarrierNetworkAction_primaryActionAndDataDisabled_notConnectCarrierNetwork() {
mMockProviderModelSlice.doCarrierNetworkAction(false /* isToggleAction */,
false /* isDataEnabled */);
verify(mMockNetworkProviderWorker, never()).connectCarrierNetwork();
}
}

View File

@@ -18,6 +18,9 @@ package com.android.settings.panel;
import static com.android.settings.network.InternetUpdater.INTERNET_APM;
import static com.android.settings.network.InternetUpdater.INTERNET_APM_NETWORKS;
import static com.android.settings.network.InternetUpdater.INTERNET_CELLULAR;
import static com.android.settings.network.InternetUpdater.INTERNET_ETHERNET;
import static com.android.settings.network.InternetUpdater.INTERNET_WIFI;
import static com.google.common.truth.Truth.assertThat;
@@ -26,10 +29,13 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.content.Context;
import android.net.Uri;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.settings.network.AirplaneModePreferenceController;
import com.android.settings.slices.CustomSliceRegistry;
import com.android.settings.testutils.ResourcesUtils;
import org.junit.Before;
@@ -40,6 +46,8 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import java.util.List;
@RunWith(AndroidJUnit4.class)
public class InternetConnectivityPanelTest {
@@ -47,6 +55,10 @@ public class InternetConnectivityPanelTest {
ApplicationProvider.getApplicationContext(), "provider_internet_settings");
public static final String TITLE_APM_NETWORKS = ResourcesUtils.getResourcesString(
ApplicationProvider.getApplicationContext(), "airplane_mode_network_panel_title");
public static final String SUBTITLE_APM_IS_ON = ResourcesUtils.getResourcesString(
ApplicationProvider.getApplicationContext(), "condition_airplane_title");
public static final String BUTTON_SETTINGS = ResourcesUtils.getResourcesString(
ApplicationProvider.getApplicationContext(), "settings_button");
@Rule
public final MockitoRule mMocks = MockitoJUnit.rule();
@@ -66,30 +78,147 @@ public class InternetConnectivityPanelTest {
}
@Test
public void getTitle_internetTypeChangedFromApmToApmNetworks_verifyTitleChanged() {
public void getTitle_internetApmNetworks_shouldBeApmNetworks() {
mPanel.onInternetTypeChanged(INTERNET_APM_NETWORKS);
assertThat(mPanel.getTitle()).isEqualTo(TITLE_APM_NETWORKS);
}
@Test
public void getTitle_notInternetApmNetworks_shouldBeInternet() {
mPanel.onInternetTypeChanged(INTERNET_APM);
assertThat(mPanel.getTitle()).isEqualTo(TITLE_INTERNET);
mPanel.onInternetTypeChanged(INTERNET_WIFI);
assertThat(mPanel.getTitle()).isEqualTo(TITLE_INTERNET);
mPanel.onInternetTypeChanged(INTERNET_CELLULAR);
assertThat(mPanel.getTitle()).isEqualTo(TITLE_INTERNET);
mPanel.onInternetTypeChanged(INTERNET_ETHERNET);
assertThat(mPanel.getTitle()).isEqualTo(TITLE_INTERNET);
}
@Test
public void getSubTitle_internetApm_shouldBeApmIsOn() {
mPanel.onInternetTypeChanged(INTERNET_APM);
assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_APM_IS_ON);
}
@Test
public void getSubTitle_notinternetApm_shouldBeNull() {
mPanel.onInternetTypeChanged(INTERNET_APM_NETWORKS);
assertThat(mPanel.getSubTitle()).isNull();
mPanel.onInternetTypeChanged(INTERNET_WIFI);
assertThat(mPanel.getSubTitle()).isNull();
mPanel.onInternetTypeChanged(INTERNET_CELLULAR);
assertThat(mPanel.getSubTitle()).isNull();
mPanel.onInternetTypeChanged(INTERNET_ETHERNET);
assertThat(mPanel.getSubTitle()).isNull();
}
@Test
public void getCustomizedButtonTitle_internetApm_shouldBeNull() {
mPanel.onInternetTypeChanged(INTERNET_APM);
assertThat(mPanel.getCustomizedButtonTitle()).isNull();
}
@Test
public void getCustomizedButtonTitle_notInternetApm_shouldBeSettings() {
mPanel.onInternetTypeChanged(INTERNET_APM_NETWORKS);
assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_SETTINGS);
mPanel.onInternetTypeChanged(INTERNET_WIFI);
assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_SETTINGS);
mPanel.onInternetTypeChanged(INTERNET_CELLULAR);
assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_SETTINGS);
mPanel.onInternetTypeChanged(INTERNET_ETHERNET);
assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_SETTINGS);
}
@Test
public void getSlices_providerModelDisabled_containsNecessarySlices() {
mPanel.mIsProviderModelEnabled = false;
final List<Uri> uris = mPanel.getSlices();
assertThat(uris).containsExactly(
AirplaneModePreferenceController.SLICE_URI,
CustomSliceRegistry.MOBILE_DATA_SLICE_URI,
CustomSliceRegistry.WIFI_SLICE_URI);
}
@Test
public void getSlices_providerModelEnabled_containsNecessarySlices() {
final List<Uri> uris = mPanel.getSlices();
assertThat(uris).containsExactly(
CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI,
CustomSliceRegistry.AIRPLANE_SAFE_NETWORKS_SLICE_URI);
}
@Test
public void getSeeMoreIntent_notNull() {
assertThat(mPanel.getSeeMoreIntent()).isNotNull();
}
@Test
public void onInternetTypeChanged_internetTypeChangedToApm_changeHeaderAndHideSettings() {
mPanel.onInternetTypeChanged(INTERNET_APM_NETWORKS);
clearInvocations(mPanelContentCallback);
mPanel.onInternetTypeChanged(INTERNET_APM);
verify(mPanelContentCallback).onHeaderChanged();
verify(mPanelContentCallback).onCustomizedButtonStateChanged();
}
@Test
public void onInternetTypeChanged_internetTypeChangedFomApm_changeTitleAndShowSettings() {
mPanel.onInternetTypeChanged(INTERNET_APM);
clearInvocations(mPanelContentCallback);
mPanel.onInternetTypeChanged(INTERNET_APM_NETWORKS);
verify(mPanelContentCallback).onTitleChanged();
verify(mPanelContentCallback).onCustomizedButtonStateChanged();
}
@Test
public void onInternetTypeChanged_internetTypeChangedToApmNetworks_changeTitle() {
mPanel.onInternetTypeChanged(INTERNET_WIFI);
clearInvocations(mPanelContentCallback);
mPanel.onInternetTypeChanged(INTERNET_APM_NETWORKS);
assertThat(mPanel.getTitle()).isEqualTo(TITLE_APM_NETWORKS);
verify(mPanelContentCallback).onTitleChanged();
}
@Test
public void getTitle_internetTypeChangedFromApmNetworksToApm_verifyTitleChanged() {
public void onInternetTypeChanged_internetTypeChangedFromApmNetworks_changeTitle() {
mPanel.onInternetTypeChanged(INTERNET_APM_NETWORKS);
assertThat(mPanel.getTitle()).isEqualTo(TITLE_APM_NETWORKS);
clearInvocations(mPanelContentCallback);
mPanel.onInternetTypeChanged(INTERNET_APM);
mPanel.onInternetTypeChanged(INTERNET_WIFI);
assertThat(mPanel.getTitle()).isEqualTo(TITLE_INTERNET);
verify(mPanelContentCallback).onTitleChanged();
}
}