[Provider Model] Add Wi-Fi toggle slice
- Reuse “Turn on networks” slice - Add "Turn on Wi-Fi" slice - Show Wi-Fi end icon - Screenshot: https://screenshot.googleplex.com/63pdow7dJh3tTw7 Bug: 181858434 Test: manual test atest -c TurnOnWifiSliceTest \ InternetConnectivityPanelTest Change-Id: I82de79fd45e99d2fe82554437bde50068dc1ae00
This commit is contained in:
@@ -1,122 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.Slice;
|
||||
import androidx.slice.SliceItem;
|
||||
import androidx.slice.SliceMetadata;
|
||||
import androidx.slice.SliceProvider;
|
||||
import androidx.slice.widget.SliceLiveData;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.testutils.ResourcesUtils;
|
||||
|
||||
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 AirplaneSafeNetworksSliceTest {
|
||||
|
||||
@Rule
|
||||
public MockitoRule mMocks = MockitoJUnit.rule();
|
||||
@Mock
|
||||
private WifiManager mWifiManager;
|
||||
|
||||
private Context mContext;
|
||||
private AirplaneSafeNetworksSlice mAirplaneSafeNetworksSlice;
|
||||
|
||||
@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);
|
||||
|
||||
mAirplaneSafeNetworksSlice = new AirplaneSafeNetworksSlice(mContext);
|
||||
mAirplaneSafeNetworksSlice.onAirplaneModeChanged(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_airplaneModeOff_shouldBeNotNull() {
|
||||
mAirplaneSafeNetworksSlice.onAirplaneModeChanged(false);
|
||||
|
||||
assertThat(mAirplaneSafeNetworksSlice.getSlice()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_wifiDisabled_shouldShowTurnOnNetworks() {
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(false);
|
||||
|
||||
final Slice slice = mAirplaneSafeNetworksSlice.getSlice();
|
||||
|
||||
assertThat(slice).isNotNull();
|
||||
final SliceItem sliceTitle =
|
||||
SliceMetadata.from(mContext, slice).getListContent().getHeader().getTitleItem();
|
||||
assertThat(sliceTitle.getText()).isEqualTo(
|
||||
ResourcesUtils.getResourcesString(mContext, "turn_on_networks"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_wifiEnabled_shouldShowTurnOffNetworks() {
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
||||
|
||||
final Slice slice = mAirplaneSafeNetworksSlice.getSlice();
|
||||
|
||||
assertThat(slice).isNotNull();
|
||||
final SliceItem sliceTitle =
|
||||
SliceMetadata.from(mContext, slice).getListContent().getHeader().getTitleItem();
|
||||
assertThat(sliceTitle.getText()).isEqualTo(
|
||||
ResourcesUtils.getResourcesString(mContext, "turn_off_networks"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNotifyChange_turnOnNetworks_shouldSetWifiEnabled() {
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(false);
|
||||
Intent intent = mAirplaneSafeNetworksSlice.getIntent();
|
||||
|
||||
mAirplaneSafeNetworksSlice.onNotifyChange(intent);
|
||||
|
||||
verify(mWifiManager).setWifiEnabled(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNotifyChange_turnOffNetworks_shouldSetWifiDisabled() {
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
||||
Intent intent = mAirplaneSafeNetworksSlice.getIntent();
|
||||
|
||||
mAirplaneSafeNetworksSlice.onNotifyChange(intent);
|
||||
|
||||
verify(mWifiManager).setWifiEnabled(false);
|
||||
}
|
||||
}
|
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
}
|
@@ -157,7 +157,7 @@ public class InternetConnectivityPanelTest {
|
||||
|
||||
assertThat(uris).containsExactly(
|
||||
CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI,
|
||||
CustomSliceRegistry.AIRPLANE_SAFE_NETWORKS_SLICE_URI);
|
||||
CustomSliceRegistry.TURN_ON_WIFI_SLICE_URI);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user