[Provider model] Add "Turn off/on Wi-Fi" link to Internet Panel
- Replace the left menu button with "Turn off/on Wi-Fi" - Remove the TurnOnWifiSlice - Show "Wi-Fi is off" sub-title when Wi-Fi is disabled - Remove the "Wi\u-Fi is turned on" sub-title when APM is on. Bug: 188710392 Test: manual test atest -c InternetConnectivityPanelTest make RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.panel Change-Id: I53e200f6cadf8b712bf794bcbd5ff79f0f239cc0
This commit is contained in:
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.network;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import androidx.slice.SliceProvider;
|
||||
import androidx.slice.widget.SliceLiveData;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class TurnOnWifiSliceTest {
|
||||
|
||||
@Rule
|
||||
public MockitoRule mMocks = MockitoJUnit.rule();
|
||||
@Mock
|
||||
private WifiManager mWifiManager;
|
||||
|
||||
private Context mContext;
|
||||
private TurnOnWifiSlice mSlice;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
|
||||
|
||||
// Set-up specs for SliceMetadata.
|
||||
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
|
||||
mSlice = new TurnOnWifiSlice(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_wifiEnabled_shouldBeNull() {
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
||||
|
||||
assertThat(mSlice.getSlice()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_wifiDisabled_shouldBeNotNull() {
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(false);
|
||||
|
||||
assertThat(mSlice.getSlice()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNotifyChange_shouldSetWifiEnabled() {
|
||||
Intent intent = mSlice.getIntent();
|
||||
|
||||
mSlice.onNotifyChange(intent);
|
||||
|
||||
verify(mWifiManager).setWifiEnabled(true);
|
||||
}
|
||||
}
|
@@ -34,6 +34,7 @@ import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Handler;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
@@ -61,19 +62,22 @@ public class InternetConnectivityPanelTest {
|
||||
ApplicationProvider.getApplicationContext(), "provider_internet_settings");
|
||||
public static final String TITLE_APM = ResourcesUtils.getResourcesString(
|
||||
ApplicationProvider.getApplicationContext(), "airplane_mode");
|
||||
public static final String SUBTITLE_WIFI_IS_TURNED_ON = ResourcesUtils.getResourcesString(
|
||||
ApplicationProvider.getApplicationContext(), "wifi_is_turned_on_subtitle");
|
||||
public static final String SUBTITLE_TEXT_WIFI_IS_OFF =
|
||||
ResourcesUtils.getResourcesString(ApplicationProvider.getApplicationContext(),
|
||||
"wifi_is_off");
|
||||
public static final String SUBTITLE_TEXT_TAP_A_NETWORK_TO_CONNECT =
|
||||
ResourcesUtils.getResourcesString(ApplicationProvider.getApplicationContext(),
|
||||
"tap_a_network_to_connect");
|
||||
public static final String BUTTON_SETTINGS = ResourcesUtils.getResourcesString(
|
||||
ApplicationProvider.getApplicationContext(), "settings_button");
|
||||
public static final String SUBTITLE_NON_CARRIER_NETWORK_UNAVAILABLE =
|
||||
ResourcesUtils.getResourcesString(ApplicationProvider.getApplicationContext(),
|
||||
"non_carrier_network_unavailable");
|
||||
public static final String SUBTITLE_ALL_NETWORK_UNAVAILABLE =
|
||||
ResourcesUtils.getResourcesString(ApplicationProvider.getApplicationContext(),
|
||||
"all_network_unavailable");
|
||||
public static final String BUTTON_TURN_ON_WIFI = ResourcesUtils.getResourcesString(
|
||||
ApplicationProvider.getApplicationContext(), "turn_on_wifi");
|
||||
public static final String BUTTON_TURN_OFF_WIFI = ResourcesUtils.getResourcesString(
|
||||
ApplicationProvider.getApplicationContext(), "turn_off_wifi");
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mMocks = MockitoJUnit.rule();
|
||||
@@ -87,6 +91,8 @@ public class InternetConnectivityPanelTest {
|
||||
private WifiManager mWifiManager;
|
||||
@Mock
|
||||
private ProviderModelSliceHelper mProviderModelSliceHelper;
|
||||
@Mock
|
||||
private FragmentActivity mPanelActivity;
|
||||
|
||||
private Context mContext;
|
||||
private InternetConnectivityPanel mPanel;
|
||||
@@ -128,13 +134,21 @@ public class InternetConnectivityPanelTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSubTitle_apmOnWifiOn_shouldWifiIsTurnedOn() {
|
||||
public void getSubTitle_apmOnWifiOn_shouldBeNull() {
|
||||
doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
|
||||
doReturn(true).when(mInternetUpdater).isWifiEnabled();
|
||||
|
||||
assertThat(mPanel.getSubTitle()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSubTitle_apmOffWifiOff_wifiIsOn() {
|
||||
doReturn(false).when(mInternetUpdater).isAirplaneModeOn();
|
||||
doReturn(false).when(mInternetUpdater).isWifiEnabled();
|
||||
|
||||
mPanel.updatePanelTitle();
|
||||
|
||||
assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_WIFI_IS_TURNED_ON);
|
||||
assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_TEXT_WIFI_IS_OFF);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -190,26 +204,17 @@ public class InternetConnectivityPanelTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCustomizedButtonTitle_apmOff_shouldBeSettings() {
|
||||
doReturn(false).when(mInternetUpdater).isAirplaneModeOn();
|
||||
|
||||
assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_SETTINGS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCustomizedButtonTitle_apmOnWifiOff_shouldBeNull() {
|
||||
doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
|
||||
public void getCustomizedButtonTitle_wifiOff_turnOnWifi() {
|
||||
doReturn(false).when(mInternetUpdater).isWifiEnabled();
|
||||
|
||||
assertThat(mPanel.getCustomizedButtonTitle()).isNull();
|
||||
assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_TURN_ON_WIFI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCustomizedButtonTitle_apmOnWifiOn_shouldBeSettings() {
|
||||
doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
|
||||
public void getCustomizedButtonTitle_wifiOn_turnOffWifi() {
|
||||
doReturn(true).when(mInternetUpdater).isWifiEnabled();
|
||||
|
||||
assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_SETTINGS);
|
||||
assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_TURN_OFF_WIFI);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -227,92 +232,60 @@ public class InternetConnectivityPanelTest {
|
||||
public void getSlices_providerModelEnabled_containsNecessarySlices() {
|
||||
List<Uri> uris = mPanel.getSlices();
|
||||
|
||||
assertThat(uris).containsExactly(
|
||||
CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI,
|
||||
CustomSliceRegistry.TURN_ON_WIFI_SLICE_URI);
|
||||
assertThat(uris).containsExactly(CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSeeMoreIntent_notNull() {
|
||||
assertThat(mPanel.getSeeMoreIntent()).isNotNull();
|
||||
public void getSeeMoreIntent_shouldBeNull() {
|
||||
assertThat(mPanel.getSeeMoreIntent()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onAirplaneModeOn_apmOff_onTitleChanged() {
|
||||
doReturn(false).when(mInternetUpdater).isAirplaneModeOn();
|
||||
clearInvocations(mPanelContentCallback);
|
||||
|
||||
mPanel.onAirplaneModeChanged(false);
|
||||
|
||||
verify(mPanelContentCallback).onTitleChanged();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onAirplaneModeOn_apmOnWifiOff_onTitleChanged() {
|
||||
doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
|
||||
doReturn(false).when(mInternetUpdater).isWifiEnabled();
|
||||
clearInvocations(mPanelContentCallback);
|
||||
|
||||
mPanel.onAirplaneModeChanged(true);
|
||||
|
||||
verify(mPanelContentCallback).onTitleChanged();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onAirplaneModeOn_apmOnWifiOn_onHeaderChanged() {
|
||||
doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
|
||||
public void onClickCustomizedButton_wifiOn_setWifiOff() {
|
||||
doReturn(true).when(mInternetUpdater).isWifiEnabled();
|
||||
|
||||
mPanel.onClickCustomizedButton(mPanelActivity);
|
||||
|
||||
verify(mWifiManager).setWifiEnabled(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onClickCustomizedButton_wifiOff_setWifiOn() {
|
||||
doReturn(false).when(mInternetUpdater).isWifiEnabled();
|
||||
|
||||
mPanel.onClickCustomizedButton(mPanelActivity);
|
||||
|
||||
verify(mWifiManager).setWifiEnabled(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onClickCustomizedButton_shouldNotFinishActivity() {
|
||||
mPanel.onClickCustomizedButton(mPanelActivity);
|
||||
|
||||
verify(mPanelActivity, never()).finish();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatePanelTitle_onHeaderChanged() {
|
||||
clearInvocations(mPanelContentCallback);
|
||||
|
||||
mPanel.onAirplaneModeChanged(true);
|
||||
mPanel.updatePanelTitle();
|
||||
|
||||
verify(mPanelContentCallback).onHeaderChanged();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onAirplaneModeOn_onCustomizedButtonStateChanged() {
|
||||
doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
|
||||
public void onWifiEnabledChanged_wifiOff_onCustomizedButtonStateChanged() {
|
||||
doReturn(false).when(mInternetUpdater).isWifiEnabled();
|
||||
clearInvocations(mPanelContentCallback);
|
||||
|
||||
mPanel.onAirplaneModeChanged(true);
|
||||
mPanel.onWifiEnabledChanged(false);
|
||||
|
||||
verify(mPanelContentCallback).onCustomizedButtonStateChanged();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onWifiEnabledChanged_apmOff_onTitleChanged() {
|
||||
doReturn(false).when(mInternetUpdater).isAirplaneModeOn();
|
||||
clearInvocations(mPanelContentCallback);
|
||||
|
||||
mPanel.onWifiEnabledChanged(false);
|
||||
|
||||
verify(mPanelContentCallback).onTitleChanged();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onWifiEnabledChanged_apmOnWifiOff_onTitleChanged() {
|
||||
doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
|
||||
doReturn(false).when(mInternetUpdater).isWifiEnabled();
|
||||
clearInvocations(mPanelContentCallback);
|
||||
|
||||
mPanel.onWifiEnabledChanged(true);
|
||||
|
||||
verify(mPanelContentCallback).onTitleChanged();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onWifiEnabledChanged_apmOnWifiOn_onHeaderChanged() {
|
||||
doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
|
||||
doReturn(true).when(mInternetUpdater).isWifiEnabled();
|
||||
clearInvocations(mPanelContentCallback);
|
||||
|
||||
mPanel.onWifiEnabledChanged(true);
|
||||
|
||||
verify(mPanelContentCallback).onHeaderChanged();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onWifiEnabledChanged_onCustomizedButtonStateChanged() {
|
||||
public void onWifiEnabledChanged_wifiOn_onCustomizedButtonStateChanged() {
|
||||
doReturn(true).when(mInternetUpdater).isWifiEnabled();
|
||||
clearInvocations(mPanelContentCallback);
|
||||
|
||||
|
Reference in New Issue
Block a user