Update auto wi-fi to prompt user for permissions

This CL makes it so that auto wi-fi will correctly prompt users
to enable the correct permissions before allowing them to turn
on the setting. Additionally it provides users with important
information regarding each setting.

Bug: 67070896
Test: Robotests
Change-Id: Ieddfa421be6e45ce69f3d6048ae051a7e3ce4c76
This commit is contained in:
Salvador Martinez
2018-03-19 08:41:32 -07:00
parent 861bf93502
commit 2f5292454b
9 changed files with 416 additions and 32 deletions

View File

@@ -19,15 +19,20 @@ package com.android.settings.wifi;
import static android.provider.Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE;
import static android.provider.Settings.Global.WIFI_WAKEUP_ENABLED;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import android.app.Fragment;
import android.content.Context;
import android.location.LocationManager;
import android.provider.Settings;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
@@ -35,21 +40,34 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
@RunWith(SettingsRobolectricTestRunner.class)
public class WifiWakeupPreferenceControllerTest {
private static final String NO_LOCATION_STRING =
"Unavailable because location is turned off. Turn on location.";
private Context mContext;
private WifiWakeupPreferenceController mController;
@Mock
DashboardFragment mFragment;
@Mock
LocationManager mLocationManager;
@Mock
SwitchPreference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mController = new WifiWakeupPreferenceController(mContext);
mController = new WifiWakeupPreferenceController(mContext, mFragment);
mController.mLocationManager = mLocationManager;
mController.mPreference = mPreference;
Settings.System.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 1);
doReturn(true).when(mLocationManager).isLocationEnabled();
}
@After
@@ -84,39 +102,72 @@ public class WifiWakeupPreferenceControllerTest {
}
@Test
public void updateState_preferenceSetCheckedAndSetEnabledWhenWakeupSettingEnabled() {
public void updateState_preferenceSetCheckedWhenWakeupSettingEnabled() {
final SwitchPreference preference = mock(SwitchPreference.class);
Settings.System.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 1);
mController.updateState(preference);
verify(preference).setChecked(true);
verify(preference).setEnabled(true);
verify(preference).setSummary(R.string.wifi_wakeup_summary);
}
@Test
public void updateState_preferenceSetUncheckedAndSetEnabledWhenWakeupSettingDisabled() {
public void updateState_preferenceSetUncheckedWhenWakeupSettingDisabled() {
final SwitchPreference preference = mock(SwitchPreference.class);
Settings.System.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 0);
mController.updateState(preference);
verify(preference).setChecked(false);
verify(preference).setEnabled(true);
verify(preference).setSummary(R.string.wifi_wakeup_summary);
}
@Test
public void updateState_preferenceSetUncheckedAndSetDisabledWhenWifiScanningDisabled() {
public void updateState_preferenceSetUncheckedWhenWifiScanningDisabled() {
final SwitchPreference preference = mock(SwitchPreference.class);
Settings.System.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 1);
Settings.System.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 0);
mController.updateState(preference);
verify(preference).setChecked(true);
verify(preference).setEnabled(false);
verify(preference).setSummary(R.string.wifi_wakeup_summary_scanning_disabled);
verify(preference).setChecked(false);
}
@Test
public void updateState_preferenceSetUncheckedWhenWakeupSettingEnabledNoLocation() {
final SwitchPreference preference = mock(SwitchPreference.class);
Settings.System.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 1);
doReturn(false).when(mLocationManager).isLocationEnabled();
mController.updateState(preference);
verify(preference).setChecked(false);
verify(preference).setSummary(mController.getNoLocationSummary());
}
@Test
public void updateState_preferenceSetUncheckedWhenWakeupSettingDisabledLocationEnabled() {
final SwitchPreference preference = mock(SwitchPreference.class);
Settings.System.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 0);
doReturn(false).when(mLocationManager).isLocationEnabled();
mController.updateState(preference);
verify(preference).setChecked(false);
verify(preference).setSummary(mController.getNoLocationSummary());
}
@Test
public void updateState_preferenceSetUncheckedWhenWifiScanningDisabledLocationEnabled() {
final SwitchPreference preference = mock(SwitchPreference.class);
Settings.System.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 1);
Settings.System.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 0);
doReturn(false).when(mLocationManager).isLocationEnabled();
mController.updateState(preference);
verify(preference).setChecked(false);
verify(preference).setSummary(mController.getNoLocationSummary());
}
}