Merge "Make it so client code does not tie tether to wifi" into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
f005640b9c
@@ -160,15 +160,14 @@ public class WifiEnabler implements SwitchWidgetController.OnSwitchChangeListene
|
||||
setSwitchBarChecked(false);
|
||||
mSwitchWidget.setEnabled(true);
|
||||
}
|
||||
if (mayDisableTethering(!mSwitchWidget.isChecked())) {
|
||||
if (RestrictedLockUtils.hasBaseUserRestriction(mContext,
|
||||
UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId())) {
|
||||
mSwitchWidget.setEnabled(false);
|
||||
} else {
|
||||
final EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(mContext,
|
||||
UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId());
|
||||
mSwitchWidget.setDisabledByAdmin(admin);
|
||||
}
|
||||
|
||||
if (RestrictedLockUtils.hasBaseUserRestriction(mContext,
|
||||
UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId())) {
|
||||
mSwitchWidget.setEnabled(false);
|
||||
} else {
|
||||
final EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(mContext,
|
||||
UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId());
|
||||
mSwitchWidget.setDisabledByAdmin(admin);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,15 +202,11 @@ public class WifiEnabler implements SwitchWidgetController.OnSwitchChangeListene
|
||||
// Show toast message if Wi-Fi is not allowed in airplane mode
|
||||
if (isChecked && !WirelessUtils.isRadioAllowed(mContext, Settings.Global.RADIO_WIFI)) {
|
||||
Toast.makeText(mContext, R.string.wifi_in_airplane_mode, Toast.LENGTH_SHORT).show();
|
||||
// Reset switch to off. No infinite check/listenenr loop.
|
||||
// Reset switch to off. No infinite check/listener loop.
|
||||
mSwitchWidget.setChecked(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Disable tethering if enabling Wifi
|
||||
if (mayDisableTethering(isChecked)) {
|
||||
mConnectivityManager.stopTethering(ConnectivityManager.TETHERING_WIFI);
|
||||
}
|
||||
if (isChecked) {
|
||||
mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_WIFI_ON);
|
||||
} else {
|
||||
@@ -226,10 +221,4 @@ public class WifiEnabler implements SwitchWidgetController.OnSwitchChangeListene
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean mayDisableTethering(boolean isChecked) {
|
||||
final int wifiApState = mWifiManager.getWifiApState();
|
||||
return isChecked && ((wifiApState == WifiManager.WIFI_AP_STATE_ENABLING) ||
|
||||
(wifiApState == WifiManager.WIFI_AP_STATE_ENABLED));
|
||||
}
|
||||
}
|
||||
|
@@ -28,26 +28,26 @@ import org.robolectric.annotation.Resetter;
|
||||
|
||||
@Implements(RestrictedLockUtils.class)
|
||||
public class ShadowRestrictedLockUtils {
|
||||
private static boolean isRestricted;
|
||||
private static String[] restrictedPkgs;
|
||||
private static boolean adminSupportDetailsIntentLaunched;
|
||||
private static int keyguardDisabledFeatures;
|
||||
private static boolean sIsRestricted;
|
||||
private static String[] sRestrictedPkgs;
|
||||
private static boolean sAdminSupportDetailsIntentLaunched;
|
||||
private static int sKeyguardDisabledFeatures;
|
||||
|
||||
@Resetter
|
||||
public static void reset() {
|
||||
isRestricted = false;
|
||||
restrictedPkgs = null;
|
||||
adminSupportDetailsIntentLaunched = false;
|
||||
keyguardDisabledFeatures = 0;
|
||||
sIsRestricted = false;
|
||||
sRestrictedPkgs = null;
|
||||
sAdminSupportDetailsIntentLaunched = false;
|
||||
sKeyguardDisabledFeatures = 0;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static EnforcedAdmin checkIfMeteredDataRestricted(Context context,
|
||||
String packageName, int userId) {
|
||||
if (isRestricted) {
|
||||
if (sIsRestricted) {
|
||||
return new EnforcedAdmin();
|
||||
}
|
||||
if (ArrayUtils.contains(restrictedPkgs, packageName)) {
|
||||
if (ArrayUtils.contains(sRestrictedPkgs, packageName)) {
|
||||
return new EnforcedAdmin();
|
||||
}
|
||||
return null;
|
||||
@@ -55,32 +55,44 @@ public class ShadowRestrictedLockUtils {
|
||||
|
||||
@Implementation
|
||||
public static void sendShowAdminSupportDetailsIntent(Context context, EnforcedAdmin admin) {
|
||||
adminSupportDetailsIntentLaunched = true;
|
||||
sAdminSupportDetailsIntentLaunched = true;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static EnforcedAdmin checkIfKeyguardFeaturesDisabled(Context context,
|
||||
int features, final @UserIdInt int userId) {
|
||||
return (keyguardDisabledFeatures & features) == 0 ? null : new EnforcedAdmin();
|
||||
return (sKeyguardDisabledFeatures & features) == 0 ? null : new EnforcedAdmin();
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static boolean hasBaseUserRestriction(Context context,
|
||||
String userRestriction, int userId) {
|
||||
return sIsRestricted;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static EnforcedAdmin checkIfRestrictionEnforced(Context context,
|
||||
String userRestriction, int userId) {
|
||||
return sIsRestricted ? new EnforcedAdmin() : null;
|
||||
}
|
||||
|
||||
public static boolean hasAdminSupportDetailsIntentLaunched() {
|
||||
return adminSupportDetailsIntentLaunched;
|
||||
return sAdminSupportDetailsIntentLaunched;
|
||||
}
|
||||
|
||||
public static void clearAdminSupportDetailsIntentLaunch() {
|
||||
adminSupportDetailsIntentLaunched = false;
|
||||
sAdminSupportDetailsIntentLaunched = false;
|
||||
}
|
||||
|
||||
public static void setRestricted(boolean restricted) {
|
||||
isRestricted = restricted;
|
||||
sIsRestricted = restricted;
|
||||
}
|
||||
|
||||
public static void setRestrictedPkgs(String... pkgs) {
|
||||
restrictedPkgs = pkgs;
|
||||
sRestrictedPkgs = pkgs;
|
||||
}
|
||||
|
||||
public static void setKeyguardDisabledFeatures(int features) {
|
||||
keyguardDisabledFeatures = features;
|
||||
sKeyguardDisabledFeatures = features;
|
||||
}
|
||||
}
|
||||
|
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.wifi;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -25,6 +27,7 @@ import android.net.ConnectivityManager;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtils;
|
||||
import com.android.settings.widget.SwitchWidgetController;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
@@ -33,8 +36,10 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowRestrictedLockUtils.class)
|
||||
public class WifiEnablerTest {
|
||||
|
||||
@Mock
|
||||
@@ -59,8 +64,6 @@ public class WifiEnablerTest {
|
||||
when(mWifiManager.setWifiEnabled(true)).thenReturn(true);
|
||||
when(mWifiManager.getWifiApState()).thenReturn(WifiManager.WIFI_AP_STATE_ENABLED);
|
||||
|
||||
mEnabler.onSwitchToggled(true);
|
||||
|
||||
verify(mConnectivityManager).stopTethering(ConnectivityManager.TETHERING_WIFI);
|
||||
assertThat(mEnabler.onSwitchToggled(true)).isTrue();
|
||||
}
|
||||
}
|
||||
|
@@ -36,6 +36,7 @@ import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtils;
|
||||
import com.android.settings.widget.MasterSwitchPreference;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
@@ -48,6 +49,7 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowRestrictedLockUtils.class)
|
||||
public class WifiMasterSwitchPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
|
Reference in New Issue
Block a user