Merge "Add callback when tethering fails" into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
1682085feb
@@ -27,6 +27,7 @@ import android.net.wifi.WifiManager;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.support.annotation.VisibleForTesting;
|
||||||
|
|
||||||
import com.android.settings.datausage.DataSaverBackend;
|
import com.android.settings.datausage.DataSaverBackend;
|
||||||
import com.android.settings.widget.SwitchWidgetController;
|
import com.android.settings.widget.SwitchWidgetController;
|
||||||
@@ -44,6 +45,16 @@ public class WifiTetherSwitchBarController implements SwitchWidgetController.OnS
|
|||||||
private final ConnectivityManager mConnectivityManager;
|
private final ConnectivityManager mConnectivityManager;
|
||||||
private final DataSaverBackend mDataSaverBackend;
|
private final DataSaverBackend mDataSaverBackend;
|
||||||
private final WifiManager mWifiManager;
|
private final WifiManager mWifiManager;
|
||||||
|
@VisibleForTesting
|
||||||
|
final ConnectivityManager.OnStartTetheringCallback mOnStartTetheringCallback =
|
||||||
|
new ConnectivityManager.OnStartTetheringCallback() {
|
||||||
|
@Override
|
||||||
|
public void onTetheringFailed() {
|
||||||
|
super.onTetheringFailed();
|
||||||
|
mSwitchBar.setChecked(false);
|
||||||
|
updateWifiSwitch();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
static {
|
static {
|
||||||
WIFI_INTENT_FILTER = new IntentFilter(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
|
WIFI_INTENT_FILTER = new IntentFilter(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
|
||||||
@@ -92,7 +103,7 @@ public class WifiTetherSwitchBarController implements SwitchWidgetController.OnS
|
|||||||
void startTether() {
|
void startTether() {
|
||||||
mSwitchBar.setEnabled(false);
|
mSwitchBar.setEnabled(false);
|
||||||
mConnectivityManager.startTethering(TETHERING_WIFI, true /* showProvisioningUi */,
|
mConnectivityManager.startTethering(TETHERING_WIFI, true /* showProvisioningUi */,
|
||||||
NoOpOnStartTetheringCallback.newInstance(), new Handler(Looper.getMainLooper()));
|
mOnStartTetheringCallback, new Handler(Looper.getMainLooper()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
|
@@ -22,6 +22,8 @@ import static org.mockito.Mockito.spy;
|
|||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.NetworkPolicyManager;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
@@ -40,9 +42,14 @@ import org.robolectric.RuntimeEnvironment;
|
|||||||
public class WifiTetherSwitchBarControllerTest {
|
public class WifiTetherSwitchBarControllerTest {
|
||||||
@Mock
|
@Mock
|
||||||
private WifiManager mWifiManager;
|
private WifiManager mWifiManager;
|
||||||
|
@Mock
|
||||||
|
private ConnectivityManager mConnectivityManager;
|
||||||
|
@Mock
|
||||||
|
private NetworkPolicyManager mNetworkPolicyManager;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private SwitchBar mSwitchBar;
|
private SwitchBar mSwitchBar;
|
||||||
|
private WifiTetherSwitchBarController mController;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -51,6 +58,13 @@ public class WifiTetherSwitchBarControllerTest {
|
|||||||
mContext = spy(RuntimeEnvironment.application);
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
mSwitchBar = new SwitchBar(mContext);
|
mSwitchBar = new SwitchBar(mContext);
|
||||||
when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
|
when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
|
||||||
|
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
|
||||||
|
mConnectivityManager);
|
||||||
|
when(mContext.getSystemService(Context.NETWORK_POLICY_SERVICE)).thenReturn(
|
||||||
|
mNetworkPolicyManager);
|
||||||
|
|
||||||
|
mController = new WifiTetherSwitchBarController(mContext,
|
||||||
|
new SwitchBarController(mSwitchBar));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -63,4 +77,15 @@ public class WifiTetherSwitchBarControllerTest {
|
|||||||
|
|
||||||
assertThat(mSwitchBar.isEnabled()).isFalse();
|
assertThat(mSwitchBar.isEnabled()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStartTether_fail_resetSwitchBar() {
|
||||||
|
when(mNetworkPolicyManager.getRestrictBackground()).thenReturn(false);
|
||||||
|
|
||||||
|
mController.startTether();
|
||||||
|
mController.mOnStartTetheringCallback.onTetheringFailed();
|
||||||
|
|
||||||
|
assertThat(mSwitchBar.isChecked()).isFalse();
|
||||||
|
assertThat(mSwitchBar.isEnabled()).isTrue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user