Merge "If in a mobile captive portal is detected enable fail fast." into jb-mr2-dev

This commit is contained in:
Wink Saville
2013-08-08 22:07:27 +00:00
committed by Android (Google) Code Review
12 changed files with 96 additions and 0 deletions

View File

@ -152,6 +152,11 @@ public class BluetoothTetheringDataTracker implements NetworkStateTracker {
// not implemented // not implemented
} }
@Override
public void captivePortalCheckCompleted(boolean isCaptivePortal) {
// not implemented
}
/** /**
* Re-enable connectivity to a network after a {@link #teardown()}. * Re-enable connectivity to a network after a {@link #teardown()}.
*/ */

View File

@ -101,6 +101,11 @@ public abstract class BaseNetworkStateTracker implements NetworkStateTracker {
// not implemented // not implemented
} }
@Override
public void captivePortalCheckCompleted(boolean isCaptivePortal) {
// not implemented
}
@Override @Override
public boolean setRadio(boolean turnOn) { public boolean setRadio(boolean turnOn) {
// Base tracker doesn't handle radios // Base tracker doesn't handle radios

View File

@ -272,6 +272,7 @@ public class CaptivePortalTracker extends StateMachine {
} else { } else {
if (DBG) log("Not captive network " + mNetworkInfo); if (DBG) log("Not captive network " + mNetworkInfo);
} }
notifyPortalCheckCompleted(mNetworkInfo, captive);
if (mDeviceProvisioned) { if (mDeviceProvisioned) {
if (captive) { if (captive) {
// Setup Wizard will assist the user in connecting to a captive // Setup Wizard will assist the user in connecting to a captive
@ -302,12 +303,26 @@ public class CaptivePortalTracker extends StateMachine {
return; return;
} }
try { try {
if (DBG) log("notifyPortalCheckComplete: ni=" + info);
mConnService.captivePortalCheckComplete(info); mConnService.captivePortalCheckComplete(info);
} catch(RemoteException e) { } catch(RemoteException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
private void notifyPortalCheckCompleted(NetworkInfo info, boolean isCaptivePortal) {
if (info == null) {
loge("notifyPortalCheckComplete on null");
return;
}
try {
if (DBG) log("notifyPortalCheckCompleted: captive=" + isCaptivePortal + " ni=" + info);
mConnService.captivePortalCheckCompleted(info, isCaptivePortal);
} catch(RemoteException e) {
e.printStackTrace();
}
}
private boolean isActiveNetwork(NetworkInfo info) { private boolean isActiveNetwork(NetworkInfo info) {
try { try {
NetworkInfo active = mConnService.getActiveNetworkInfo(); NetworkInfo active = mConnService.getActiveNetworkInfo();

View File

@ -1282,6 +1282,25 @@ public class ConnectivityManager {
} }
} }
/**
* Signal that the captive portal check on the indicated network
* is complete and whether its a captive portal or not.
*
* @param info the {@link NetworkInfo} object for the networkType
* in question.
* @param isCaptivePortal true/false.
*
* <p>This method requires the call to hold the permission
* {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
* {@hide}
*/
public void captivePortalCheckCompleted(NetworkInfo info, boolean isCaptivePortal) {
try {
mService.captivePortalCheckCompleted(info, isCaptivePortal);
} catch (RemoteException e) {
}
}
/** /**
* Supply the backend messenger for a network tracker * Supply the backend messenger for a network tracker
* *

View File

@ -120,10 +120,16 @@ public class DummyDataStateTracker implements NetworkStateTracker {
return true; return true;
} }
@Override
public void captivePortalCheckComplete() { public void captivePortalCheckComplete() {
// not implemented // not implemented
} }
@Override
public void captivePortalCheckCompleted(boolean isCaptivePortal) {
// not implemented
}
/** /**
* Record the detailed state of a network, and if it is a * Record the detailed state of a network, and if it is a
* change from the previous state, send a notification to * change from the previous state, send a notification to

View File

@ -279,6 +279,11 @@ public class EthernetDataTracker implements NetworkStateTracker {
// not implemented // not implemented
} }
@Override
public void captivePortalCheckCompleted(boolean isCaptivePortal) {
// not implemented
}
/** /**
* Turn the wireless radio off for a network. * Turn the wireless radio off for a network.
* @param turnOn {@code true} to turn the radio on, {@code false} * @param turnOn {@code true} to turn the radio on, {@code false}

View File

@ -129,6 +129,8 @@ interface IConnectivityManager
void captivePortalCheckComplete(in NetworkInfo info); void captivePortalCheckComplete(in NetworkInfo info);
void captivePortalCheckCompleted(in NetworkInfo info, boolean isCaptivePortal);
void supplyMessenger(int networkType, in Messenger messenger); void supplyMessenger(int networkType, in Messenger messenger);
int findConnectionTypeForIface(in String iface); int findConnectionTypeForIface(in String iface);

View File

@ -40,6 +40,7 @@ import com.android.internal.util.AsyncChannel;
import java.io.CharArrayWriter; import java.io.CharArrayWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.concurrent.atomic.AtomicBoolean;
/** /**
* Track the state of mobile data connectivity. This is done by * Track the state of mobile data connectivity. This is done by
@ -75,6 +76,8 @@ public class MobileDataStateTracker implements NetworkStateTracker {
private Handler mHandler; private Handler mHandler;
private AsyncChannel mDataConnectionTrackerAc; private AsyncChannel mDataConnectionTrackerAc;
private AtomicBoolean mIsCaptivePortal = new AtomicBoolean(false);
/** /**
* Create a new MobileDataStateTracker * Create a new MobileDataStateTracker
* @param netType the ConnectivityManager network type * @param netType the ConnectivityManager network type
@ -377,6 +380,15 @@ public class MobileDataStateTracker implements NetworkStateTracker {
// not implemented // not implemented
} }
@Override
public void captivePortalCheckCompleted(boolean isCaptivePortal) {
if (mIsCaptivePortal.getAndSet(isCaptivePortal) != isCaptivePortal) {
// Captive portal change enable/disable failing fast
setEnableFailFastMobileData(
isCaptivePortal ? DctConstants.ENABLED : DctConstants.DISABLED);
}
}
/** /**
* Record the detailed state of a network, and if it is a * Record the detailed state of a network, and if it is a
* change from the previous state, send a notification to * change from the previous state, send a notification to

View File

@ -143,6 +143,11 @@ public interface NetworkStateTracker {
*/ */
public void captivePortalCheckComplete(); public void captivePortalCheckComplete();
/**
* Captive portal check has completed
*/
public void captivePortalCheckCompleted(boolean isCaptive);
/** /**
* Turn the wireless radio off for a network. * Turn the wireless radio off for a network.
* @param turnOn {@code true} to turn the radio on, {@code false} * @param turnOn {@code true} to turn the radio on, {@code false}

View File

@ -2169,15 +2169,26 @@ public class ConnectivityService extends IConnectivityManager.Stub {
} }
} }
if (DBG) log("handleCaptivePortalTrackerCheck: call captivePortalCheckComplete ni=" + info);
thisNet.captivePortalCheckComplete(); thisNet.captivePortalCheckComplete();
} }
/** @hide */ /** @hide */
@Override
public void captivePortalCheckComplete(NetworkInfo info) { public void captivePortalCheckComplete(NetworkInfo info) {
enforceConnectivityInternalPermission(); enforceConnectivityInternalPermission();
if (DBG) log("captivePortalCheckComplete: ni=" + info);
mNetTrackers[info.getType()].captivePortalCheckComplete(); mNetTrackers[info.getType()].captivePortalCheckComplete();
} }
/** @hide */
@Override
public void captivePortalCheckCompleted(NetworkInfo info, boolean isCaptivePortal) {
enforceConnectivityInternalPermission();
if (DBG) log("captivePortalCheckCompleted: ni=" + info + " captive=" + isCaptivePortal);
mNetTrackers[info.getType()].captivePortalCheckCompleted(isCaptivePortal);
}
/** /**
* Setup data activity tracking for the given network interface. * Setup data activity tracking for the given network interface.
* *

View File

@ -3166,6 +3166,7 @@ public class WifiStateMachine extends StateMachine {
class VerifyingLinkState extends State { class VerifyingLinkState extends State {
@Override @Override
public void enter() { public void enter() {
log(getName() + " enter");
setNetworkDetailedState(DetailedState.VERIFYING_POOR_LINK); setNetworkDetailedState(DetailedState.VERIFYING_POOR_LINK);
mWifiConfigStore.updateStatus(mLastNetworkId, DetailedState.VERIFYING_POOR_LINK); mWifiConfigStore.updateStatus(mLastNetworkId, DetailedState.VERIFYING_POOR_LINK);
sendNetworkStateChangeBroadcast(mLastBssid); sendNetworkStateChangeBroadcast(mLastBssid);
@ -3175,11 +3176,14 @@ public class WifiStateMachine extends StateMachine {
switch (message.what) { switch (message.what) {
case WifiWatchdogStateMachine.POOR_LINK_DETECTED: case WifiWatchdogStateMachine.POOR_LINK_DETECTED:
//stay here //stay here
log(getName() + " POOR_LINK_DETECTED: no transition");
break; break;
case WifiWatchdogStateMachine.GOOD_LINK_DETECTED: case WifiWatchdogStateMachine.GOOD_LINK_DETECTED:
log(getName() + " GOOD_LINK_DETECTED: transition to captive portal check");
transitionTo(mCaptivePortalCheckState); transitionTo(mCaptivePortalCheckState);
break; break;
default: default:
log(getName() + " what=" + message.what + " NOT_HANDLED");
return NOT_HANDLED; return NOT_HANDLED;
} }
return HANDLED; return HANDLED;
@ -3189,6 +3193,7 @@ public class WifiStateMachine extends StateMachine {
class CaptivePortalCheckState extends State { class CaptivePortalCheckState extends State {
@Override @Override
public void enter() { public void enter() {
log(getName() + " enter");
setNetworkDetailedState(DetailedState.CAPTIVE_PORTAL_CHECK); setNetworkDetailedState(DetailedState.CAPTIVE_PORTAL_CHECK);
mWifiConfigStore.updateStatus(mLastNetworkId, DetailedState.CAPTIVE_PORTAL_CHECK); mWifiConfigStore.updateStatus(mLastNetworkId, DetailedState.CAPTIVE_PORTAL_CHECK);
sendNetworkStateChangeBroadcast(mLastBssid); sendNetworkStateChangeBroadcast(mLastBssid);
@ -3197,6 +3202,7 @@ public class WifiStateMachine extends StateMachine {
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
switch (message.what) { switch (message.what) {
case CMD_CAPTIVE_CHECK_COMPLETE: case CMD_CAPTIVE_CHECK_COMPLETE:
log(getName() + " CMD_CAPTIVE_CHECK_COMPLETE");
try { try {
mNwService.enableIpv6(mInterfaceName); mNwService.enableIpv6(mInterfaceName);
} catch (RemoteException re) { } catch (RemoteException re) {

View File

@ -120,6 +120,11 @@ public class WifiStateTracker implements NetworkStateTracker {
mWifiManager.captivePortalCheckComplete(); mWifiManager.captivePortalCheckComplete();
} }
@Override
public void captivePortalCheckCompleted(boolean isCaptivePortal) {
// not implemented
}
/** /**
* Turn the wireless radio off for a network. * Turn the wireless radio off for a network.
* @param turnOn {@code true} to turn the radio on, {@code false} * @param turnOn {@code true} to turn the radio on, {@code false}