Remove captive portal code that has no effect.

Note that this CL does not change any behaviour.

At the center of this change is
CaptivePortalTracker#detectCaptivePortal(), which does nothing
except call back into ConnectivityService. Removing it allows us to
simplify code in ConnectivityService. It also allows us to remove
ConnectivityService#captivePortalCheckComplete which was only ever
called in response to this method.

While this does not change any behaviour, it preserves existing
bad behaviour, i.e, that the CAPTIVE_PORTAL_CHECK NetworkInfo
state does not correspond to actual captive portal detection.
We transition into that state and immediately (and unconditionally)
out of it and into CONNECTED.

Change-Id: Ib3797f956d2db5e3cacaaa53e899d81aa8e958af
This commit is contained in:
Narayan Kamath
2013-08-29 13:40:43 +01:00
parent 805f7a1d01
commit 98e1797367
15 changed files with 28 additions and 186 deletions

View File

@@ -142,11 +142,6 @@ public class BluetoothTetheringDataTracker extends BaseNetworkStateTracker {
return true;
}
@Override
public void captivePortalCheckComplete() {
// not implemented
}
@Override
public void captivePortalCheckCompleted(boolean isCaptivePortal) {
// not implemented

View File

@@ -20,10 +20,10 @@ import android.content.Context;
import android.os.Handler;
import android.os.Messenger;
import com.android.internal.util.Preconditions;
import java.util.concurrent.atomic.AtomicBoolean;
import com.android.internal.util.Preconditions;
/**
* Interface to control and observe state of a specific network, hiding
* network-specific details from {@link ConnectivityManager}. Surfaces events
@@ -107,11 +107,6 @@ public abstract class BaseNetworkStateTracker implements NetworkStateTracker {
return null;
}
@Override
public void captivePortalCheckComplete() {
// not implemented
}
@Override
public void captivePortalCheckCompleted(boolean isCaptivePortal) {
// not implemented

View File

@@ -84,13 +84,12 @@ public class CaptivePortalTracker extends StateMachine {
private String mServer;
private String mUrl;
private boolean mIsCaptivePortalCheckEnabled = false;
private IConnectivityManager mConnService;
private TelephonyManager mTelephonyManager;
private WifiManager mWifiManager;
private Context mContext;
private final IConnectivityManager mConnService;
private final TelephonyManager mTelephonyManager;
private final WifiManager mWifiManager;
private final Context mContext;
private NetworkInfo mNetworkInfo;
private static final int CMD_DETECT_PORTAL = 0;
private static final int CMD_CONNECTIVITY_CHANGE = 1;
private static final int CMD_DELAYED_CAPTIVE_CHECK = 2;
@@ -98,14 +97,15 @@ public class CaptivePortalTracker extends StateMachine {
private static final int DELAYED_CHECK_INTERVAL_MS = 10000;
private int mDelayedCheckToken = 0;
private State mDefaultState = new DefaultState();
private State mNoActiveNetworkState = new NoActiveNetworkState();
private State mActiveNetworkState = new ActiveNetworkState();
private State mDelayedCaptiveCheckState = new DelayedCaptiveCheckState();
private final State mDefaultState = new DefaultState();
private final State mNoActiveNetworkState = new NoActiveNetworkState();
private final State mActiveNetworkState = new ActiveNetworkState();
private final State mDelayedCaptiveCheckState = new DelayedCaptiveCheckState();
private static final String SETUP_WIZARD_PACKAGE = "com.google.android.setupwizard";
private boolean mDeviceProvisioned = false;
private ProvisioningObserver mProvisioningObserver;
@SuppressWarnings("unused")
private final ProvisioningObserver mProvisioningObserver;
private CaptivePortalTracker(Context context, IConnectivityManager cs) {
super(TAG);
@@ -174,29 +174,11 @@ public class CaptivePortalTracker extends StateMachine {
return captivePortal;
}
public void detectCaptivePortal(NetworkInfo info) {
sendMessage(obtainMessage(CMD_DETECT_PORTAL, info));
}
private class DefaultState extends State {
@Override
public boolean processMessage(Message message) {
if (DBG) log(getName() + message.toString());
switch (message.what) {
case CMD_DETECT_PORTAL:
NetworkInfo info = (NetworkInfo) message.obj;
// Checking on a secondary connection is not supported
// yet
notifyPortalCheckComplete(info);
break;
case CMD_CONNECTIVITY_CHANGE:
case CMD_DELAYED_CAPTIVE_CHECK:
break;
default:
loge("Ignoring " + message);
break;
}
loge("Ignoring " + message);
return HANDLED;
}
}
@@ -316,19 +298,6 @@ public class CaptivePortalTracker extends StateMachine {
}
}
private void notifyPortalCheckComplete(NetworkInfo info) {
if (info == null) {
loge("notifyPortalCheckComplete on null");
return;
}
try {
if (DBG) log("notifyPortalCheckComplete: ni=" + info);
mConnService.captivePortalCheckComplete(info);
} catch(RemoteException e) {
e.printStackTrace();
}
}
private void notifyPortalCheckCompleted(NetworkInfo info, boolean isCaptivePortal) {
if (info == null) {
loge("notifyPortalCheckComplete on null");
@@ -464,7 +433,6 @@ public class CaptivePortalTracker extends StateMachine {
latencyBroadcast.putExtra(EXTRA_NETWORK_TYPE, mTelephonyManager.getNetworkType());
List<CellInfo> info = mTelephonyManager.getAllCellInfo();
if (info == null) return;
StringBuffer uniqueCellId = new StringBuffer();
int numRegisteredCellInfo = 0;
for (CellInfo cellInfo : info) {
if (cellInfo.isRegistered()) {

View File

@@ -1328,24 +1328,6 @@ public class ConnectivityManager {
}
}
/**
* Signal that the captive portal check on the indicated network
* is complete and we can turn the network on for general use.
*
* @param info the {@link NetworkInfo} object for the networkType
* in question.
*
* <p>This method requires the call to hold the permission
* {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
* {@hide}
*/
public void captivePortalCheckComplete(NetworkInfo info) {
try {
mService.captivePortalCheckComplete(info);
} catch (RemoteException e) {
}
}
/**
* Signal that the captive portal check on the indicated network
* is complete and whether its a captive portal or not.

View File

@@ -116,11 +116,6 @@ public class DummyDataStateTracker extends BaseNetworkStateTracker {
return true;
}
@Override
public void captivePortalCheckComplete() {
// not implemented
}
@Override
public void captivePortalCheckCompleted(boolean isCaptivePortal) {
// not implemented

View File

@@ -269,11 +269,6 @@ public class EthernetDataTracker extends BaseNetworkStateTracker {
return mLinkUp;
}
@Override
public void captivePortalCheckComplete() {
// not implemented
}
@Override
public void captivePortalCheckCompleted(boolean isCaptivePortal) {
// not implemented

View File

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

View File

@@ -459,11 +459,6 @@ public class MobileDataStateTracker extends BaseNetworkStateTracker {
return mDataConnectionTrackerAc != null;
}
@Override
public void captivePortalCheckComplete() {
// not implemented
}
@Override
public void captivePortalCheckCompleted(boolean isCaptivePortal) {
if (mIsCaptivePortal.getAndSet(isCaptivePortal) != isCaptivePortal) {

View File

@@ -143,11 +143,6 @@ public interface NetworkStateTracker {
*/
public boolean reconnect();
/**
* Ready to switch on to the network after captive portal check
*/
public void captivePortalCheckComplete();
/**
* Captive portal check has completed
*/

View File

@@ -2316,36 +2316,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
}
}
private void handleCaptivePortalTrackerCheck(NetworkInfo info) {
if (DBG) log("Captive portal check " + info);
int type = info.getType();
final NetworkStateTracker thisNet = mNetTrackers[type];
if (mNetConfigs[type].isDefault()) {
if (mActiveDefaultNetwork != -1 && mActiveDefaultNetwork != type) {
if (isNewNetTypePreferredOverCurrentNetType(type)) {
if (DBG) log("Captive check on " + info.getTypeName());
mCaptivePortalTracker.detectCaptivePortal(new NetworkInfo(info));
return;
} else {
if (DBG) log("Tear down low priority net " + info.getTypeName());
teardown(thisNet);
return;
}
}
}
if (DBG) log("handleCaptivePortalTrackerCheck: call captivePortalCheckComplete ni=" + info);
thisNet.captivePortalCheckComplete();
}
/** @hide */
@Override
public void captivePortalCheckComplete(NetworkInfo info) {
enforceConnectivityInternalPermission();
if (DBG) log("captivePortalCheckComplete: ni=" + info);
mNetTrackers[info.getType()].captivePortalCheckComplete();
}
/** @hide */
@Override
public void captivePortalCheckCompleted(NetworkInfo info, boolean isCaptivePortal) {
@@ -2972,9 +2942,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
if (info.getDetailedState() ==
NetworkInfo.DetailedState.FAILED) {
handleConnectionFailure(info);
} else if (info.getDetailedState() ==
DetailedState.CAPTIVE_PORTAL_CHECK) {
handleCaptivePortalTrackerCheck(info);
} else if (info.isConnectedToProvisioningNetwork()) {
/**
* TODO: Create ConnectivityManager.TYPE_MOBILE_PROVISIONING

View File

@@ -930,11 +930,6 @@ public final class WifiService extends IWifiManager.Stub {
mWifiStateMachine.reconnectCommand();
}
public void captivePortalCheckComplete() {
enforceConnectivityInternalPermission();
mWifiStateMachine.captivePortalCheckComplete();
}
/**
* see {@link android.net.wifi.WifiManager#stopWifi}
*

View File

@@ -111,8 +111,6 @@ interface IWifiManager
String getConfigFile();
void captivePortalCheckComplete();
void enableTdls(String remoteIPAddress, boolean enable);
void enableTdlsWithMacAddress(String remoteMacAddress, boolean enable);

View File

@@ -2157,13 +2157,6 @@ public class WifiManager {
}
}
/** @hide */
public void captivePortalCheckComplete() {
try {
mService.captivePortalCheckComplete();
} catch (RemoteException e) {}
}
protected void finalize() throws Throwable {
try {
synchronized (sThreadRefLock) {

View File

@@ -56,13 +56,11 @@ import android.net.wifi.WpsResult.Status;
import android.net.wifi.p2p.WifiP2pManager;
import android.net.wifi.p2p.WifiP2pService;
import android.os.BatteryStats;
import android.os.Binder;
import android.os.IBinder;
import android.os.INetworkManagementService;
import android.os.Message;
import android.os.Messenger;
import android.os.PowerManager;
import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
@@ -70,7 +68,6 @@ import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.WorkSource;
import android.provider.Settings;
import android.util.Log;
import android.util.LruCache;
import android.text.TextUtils;
@@ -86,7 +83,6 @@ import com.android.server.net.BaseNetworkObserver;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Inet6Address;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@@ -303,8 +299,6 @@ public class WifiStateMachine extends StateMachine {
static final int CMD_DELAYED_STOP_DRIVER = BASE + 18;
/* A delayed message sent to start driver when it fail to come up */
static final int CMD_DRIVER_START_TIMED_OUT = BASE + 19;
/* Ready to switch to network as default */
static final int CMD_CAPTIVE_CHECK_COMPLETE = BASE + 20;
/* Start the soft access point */
static final int CMD_START_AP = BASE + 21;
@@ -536,8 +530,6 @@ public class WifiStateMachine extends StateMachine {
private State mObtainingIpState = new ObtainingIpState();
/* Waiting for link quality verification to be complete */
private State mVerifyingLinkState = new VerifyingLinkState();
/* Waiting for captive portal check to be complete */
private State mCaptivePortalCheckState = new CaptivePortalCheckState();
/* Connected with IP addr */
private State mConnectedState = new ConnectedState();
/* disconnect issued, waiting for network disconnect confirmation */
@@ -774,7 +766,6 @@ public class WifiStateMachine extends StateMachine {
addState(mL2ConnectedState, mConnectModeState);
addState(mObtainingIpState, mL2ConnectedState);
addState(mVerifyingLinkState, mL2ConnectedState);
addState(mCaptivePortalCheckState, mL2ConnectedState);
addState(mConnectedState, mL2ConnectedState);
addState(mDisconnectingState, mConnectModeState);
addState(mDisconnectedState, mConnectModeState);
@@ -1277,10 +1268,6 @@ public class WifiStateMachine extends StateMachine {
}
}
public void captivePortalCheckComplete() {
sendMessage(CMD_CAPTIVE_CHECK_COMPLETE);
}
/**
* TODO: doc
*/
@@ -2459,7 +2446,6 @@ public class WifiStateMachine extends StateMachine {
case CMD_STOP_DRIVER:
case CMD_DELAYED_STOP_DRIVER:
case CMD_DRIVER_START_TIMED_OUT:
case CMD_CAPTIVE_CHECK_COMPLETE:
case CMD_START_AP:
case CMD_START_AP_SUCCESS:
case CMD_START_AP_FAILURE:
@@ -3731,29 +3717,17 @@ public class WifiStateMachine extends StateMachine {
break;
case WifiWatchdogStateMachine.GOOD_LINK_DETECTED:
log(getName() + " GOOD_LINK_DETECTED: transition to captive portal check");
transitionTo(mCaptivePortalCheckState);
break;
default:
if (DBG) log(getName() + " what=" + message.what + " NOT_HANDLED");
return NOT_HANDLED;
}
return HANDLED;
}
}
// Send out a broadcast with the CAPTIVE_PORTAL_CHECK to preserve
// existing behaviour. The captive portal check really happens after we
// transition into DetailedState.CONNECTED.
setNetworkDetailedState(DetailedState.CAPTIVE_PORTAL_CHECK);
mWifiConfigStore.updateStatus(mLastNetworkId,
DetailedState.CAPTIVE_PORTAL_CHECK);
sendNetworkStateChangeBroadcast(mLastBssid);
class CaptivePortalCheckState extends State {
@Override
public void enter() {
log(getName() + " enter");
setNetworkDetailedState(DetailedState.CAPTIVE_PORTAL_CHECK);
mWifiConfigStore.updateStatus(mLastNetworkId, DetailedState.CAPTIVE_PORTAL_CHECK);
sendNetworkStateChangeBroadcast(mLastBssid);
}
@Override
public boolean processMessage(Message message) {
switch (message.what) {
case CMD_CAPTIVE_CHECK_COMPLETE:
log(getName() + " CMD_CAPTIVE_CHECK_COMPLETE");
// NOTE: This might look like an odd place to enable IPV6 but this is in
// response to transitioning into GOOD_LINK_DETECTED. Similarly, we disable
// ipv6 when we transition into POOR_LINK_DETECTED in mConnectedState.
try {
mNwService.enableIpv6(mInterfaceName);
} catch (RemoteException re) {
@@ -3761,12 +3735,16 @@ public class WifiStateMachine extends StateMachine {
} catch (IllegalStateException e) {
loge("Failed to enable IPv6: " + e);
}
log(getName() + " GOOD_LINK_DETECTED: transition to CONNECTED");
setNetworkDetailedState(DetailedState.CONNECTED);
mWifiConfigStore.updateStatus(mLastNetworkId, DetailedState.CONNECTED);
sendNetworkStateChangeBroadcast(mLastBssid);
transitionTo(mConnectedState);
break;
default:
if (DBG) log(getName() + " what=" + message.what + " NOT_HANDLED");
return NOT_HANDLED;
}
return HANDLED;
@@ -3798,6 +3776,7 @@ public class WifiStateMachine extends StateMachine {
}
return HANDLED;
}
@Override
public void exit() {
/* Request a CS wakelock during transition to mobile */

View File

@@ -115,14 +115,6 @@ public class WifiStateTracker extends BaseNetworkStateTracker {
return true;
}
/**
* Captive check is complete, switch to network
*/
@Override
public void captivePortalCheckComplete() {
mWifiManager.captivePortalCheckComplete();
}
@Override
public void captivePortalCheckCompleted(boolean isCaptivePortal) {
// not implemented