Merge "Simple cleanups to Tethering"
This commit is contained in:
@@ -3087,8 +3087,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startTethering(int type, ResultReceiver receiver,
|
||||
boolean showProvisioningUi) {
|
||||
public void startTethering(int type, ResultReceiver receiver, boolean showProvisioningUi) {
|
||||
ConnectivityManager.enforceTetherChangePermission(mContext);
|
||||
if (!isTetheringSupported()) {
|
||||
receiver.send(ConnectivityManager.TETHER_ERROR_UNSUPPORTED, null);
|
||||
|
||||
@@ -77,8 +77,8 @@ import com.android.server.connectivity.tethering.IControlsTethering;
|
||||
import com.android.server.connectivity.tethering.IPv6TetheringCoordinator;
|
||||
import com.android.server.connectivity.tethering.IPv6TetheringInterfaceServices;
|
||||
import com.android.server.connectivity.tethering.OffloadController;
|
||||
import com.android.server.connectivity.tethering.TetheringConfiguration;
|
||||
import com.android.server.connectivity.tethering.TetherInterfaceStateMachine;
|
||||
import com.android.server.connectivity.tethering.TetheringConfiguration;
|
||||
import com.android.server.connectivity.tethering.UpstreamNetworkMonitor;
|
||||
import com.android.server.net.BaseNetworkObserver;
|
||||
|
||||
@@ -102,8 +102,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
*/
|
||||
public class Tethering extends BaseNetworkObserver implements IControlsTethering {
|
||||
|
||||
private final Context mContext;
|
||||
private final static String TAG = "Tethering";
|
||||
private final static String TAG = Tethering.class.getSimpleName();
|
||||
private final static boolean DBG = false;
|
||||
private final static boolean VDBG = false;
|
||||
|
||||
@@ -115,48 +114,43 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
|
||||
private static final SparseArray<String> sMagicDecoderRing =
|
||||
MessageUtils.findMessageNames(messageClasses);
|
||||
|
||||
private volatile TetheringConfiguration mConfig;
|
||||
// {@link ComponentName} of the Service used to run tether provisioning.
|
||||
private static final ComponentName TETHER_SERVICE = ComponentName.unflattenFromString(Resources
|
||||
.getSystem().getString(com.android.internal.R.string.config_wifi_tether_enable));
|
||||
|
||||
private static class TetherState {
|
||||
public final TetherInterfaceStateMachine stateMachine;
|
||||
public int lastState;
|
||||
public int lastError;
|
||||
public TetherState(TetherInterfaceStateMachine sm) {
|
||||
stateMachine = sm;
|
||||
// Assume all state machines start out available and with no errors.
|
||||
lastState = IControlsTethering.STATE_AVAILABLE;
|
||||
lastError = ConnectivityManager.TETHER_ERROR_NO_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
// used to synchronize public access to members
|
||||
private final Object mPublicSync;
|
||||
|
||||
private final Context mContext;
|
||||
private final ArrayMap<String, TetherState> mTetherStates;
|
||||
private final BroadcastReceiver mStateReceiver;
|
||||
private final INetworkManagementService mNMService;
|
||||
private final INetworkStatsService mStatsService;
|
||||
private final INetworkPolicyManager mPolicyManager;
|
||||
private final Looper mLooper;
|
||||
private final MockableSystemProperties mSystemProperties;
|
||||
|
||||
private static class TetherState {
|
||||
public final TetherInterfaceStateMachine mStateMachine;
|
||||
public int mLastState;
|
||||
public int mLastError;
|
||||
public TetherState(TetherInterfaceStateMachine sm) {
|
||||
mStateMachine = sm;
|
||||
// Assume all state machines start out available and with no errors.
|
||||
mLastState = IControlsTethering.STATE_AVAILABLE;
|
||||
mLastError = ConnectivityManager.TETHER_ERROR_NO_ERROR;
|
||||
}
|
||||
}
|
||||
private final ArrayMap<String, TetherState> mTetherStates;
|
||||
|
||||
private final BroadcastReceiver mStateReceiver;
|
||||
|
||||
// {@link ComponentName} of the Service used to run tether provisioning.
|
||||
private static final ComponentName TETHER_SERVICE = ComponentName.unflattenFromString(Resources
|
||||
.getSystem().getString(com.android.internal.R.string.config_wifi_tether_enable));
|
||||
|
||||
private final StateMachine mTetherMasterSM;
|
||||
private final OffloadController mOffloadController;
|
||||
private final UpstreamNetworkMonitor mUpstreamNetworkMonitor;
|
||||
private String mCurrentUpstreamIface;
|
||||
|
||||
private volatile TetheringConfiguration mConfig;
|
||||
private String mCurrentUpstreamIface;
|
||||
private Notification.Builder mTetheredNotificationBuilder;
|
||||
private int mLastNotificationId;
|
||||
|
||||
private boolean mRndisEnabled; // track the RNDIS function enabled state
|
||||
private boolean mUsbTetherRequested; // true if USB tethering should be started
|
||||
// when RNDIS is enabled
|
||||
|
||||
// True iff WiFi tethering should be started when soft AP is ready.
|
||||
private boolean mWifiTetherRequested;
|
||||
|
||||
@@ -227,7 +221,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
|
||||
}
|
||||
} else {
|
||||
if (interfaceType == ConnectivityManager.TETHERING_BLUETOOTH) {
|
||||
tetherState.mStateMachine.sendMessage(
|
||||
tetherState.stateMachine.sendMessage(
|
||||
TetherInterfaceStateMachine.CMD_INTERFACE_DOWN);
|
||||
mTetherStates.remove(iface);
|
||||
} else {
|
||||
@@ -289,13 +283,12 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
|
||||
}
|
||||
return;
|
||||
}
|
||||
tetherState.mStateMachine.sendMessage(TetherInterfaceStateMachine.CMD_INTERFACE_DOWN);
|
||||
tetherState.stateMachine.sendMessage(TetherInterfaceStateMachine.CMD_INTERFACE_DOWN);
|
||||
mTetherStates.remove(iface);
|
||||
}
|
||||
}
|
||||
|
||||
public void startTethering(int type, ResultReceiver receiver,
|
||||
boolean showProvisioningUi) {
|
||||
public void startTethering(int type, ResultReceiver receiver, boolean showProvisioningUi) {
|
||||
if (!isTetherProvisioningRequired()) {
|
||||
enableTetheringInternal(type, true, receiver);
|
||||
return;
|
||||
@@ -527,11 +520,11 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
|
||||
}
|
||||
// Ignore the error status of the interface. If the interface is available,
|
||||
// the errors are referring to past tethering attempts anyway.
|
||||
if (tetherState.mLastState != IControlsTethering.STATE_AVAILABLE) {
|
||||
if (tetherState.lastState != IControlsTethering.STATE_AVAILABLE) {
|
||||
Log.e(TAG, "Tried to Tether an unavailable iface: " + iface + ", ignoring");
|
||||
return ConnectivityManager.TETHER_ERROR_UNAVAIL_IFACE;
|
||||
}
|
||||
tetherState.mStateMachine.sendMessage(TetherInterfaceStateMachine.CMD_TETHER_REQUESTED);
|
||||
tetherState.stateMachine.sendMessage(TetherInterfaceStateMachine.CMD_TETHER_REQUESTED);
|
||||
return ConnectivityManager.TETHER_ERROR_NO_ERROR;
|
||||
}
|
||||
}
|
||||
@@ -544,11 +537,11 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
|
||||
Log.e(TAG, "Tried to Untether an unknown iface :" + iface + ", ignoring");
|
||||
return ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE;
|
||||
}
|
||||
if (tetherState.mLastState != IControlsTethering.STATE_TETHERED) {
|
||||
if (tetherState.lastState != IControlsTethering.STATE_TETHERED) {
|
||||
Log.e(TAG, "Tried to untether an untethered iface :" + iface + ", ignoring");
|
||||
return ConnectivityManager.TETHER_ERROR_UNAVAIL_IFACE;
|
||||
}
|
||||
tetherState.mStateMachine.sendMessage(
|
||||
tetherState.stateMachine.sendMessage(
|
||||
TetherInterfaceStateMachine.CMD_TETHER_UNREQUESTED);
|
||||
return ConnectivityManager.TETHER_ERROR_NO_ERROR;
|
||||
}
|
||||
@@ -568,7 +561,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
|
||||
", ignoring");
|
||||
return ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE;
|
||||
}
|
||||
return tetherState.mLastError;
|
||||
return tetherState.lastError;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -589,11 +582,11 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
|
||||
for (int i = 0; i < mTetherStates.size(); i++) {
|
||||
TetherState tetherState = mTetherStates.valueAt(i);
|
||||
String iface = mTetherStates.keyAt(i);
|
||||
if (tetherState.mLastError != ConnectivityManager.TETHER_ERROR_NO_ERROR) {
|
||||
if (tetherState.lastError != ConnectivityManager.TETHER_ERROR_NO_ERROR) {
|
||||
erroredList.add(iface);
|
||||
} else if (tetherState.mLastState == IControlsTethering.STATE_AVAILABLE) {
|
||||
} else if (tetherState.lastState == IControlsTethering.STATE_AVAILABLE) {
|
||||
availableList.add(iface);
|
||||
} else if (tetherState.mLastState == IControlsTethering.STATE_TETHERED) {
|
||||
} else if (tetherState.lastState == IControlsTethering.STATE_TETHERED) {
|
||||
if (cfg.isUsb(iface)) {
|
||||
usbTethered = true;
|
||||
} else if (cfg.isWifi(iface)) {
|
||||
@@ -766,7 +759,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
|
||||
// themselves down.
|
||||
for (int i = 0; i < mTetherStates.size(); i++) {
|
||||
TetherInterfaceStateMachine tism =
|
||||
mTetherStates.valueAt(i).mStateMachine;
|
||||
mTetherStates.valueAt(i).stateMachine;
|
||||
if (tism.interfaceType() == ConnectivityManager.TETHERING_WIFI) {
|
||||
tism.sendMessage(
|
||||
TetherInterfaceStateMachine.CMD_TETHER_UNREQUESTED);
|
||||
@@ -881,7 +874,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
|
||||
synchronized (mPublicSync) {
|
||||
for (int i = 0; i < mTetherStates.size(); i++) {
|
||||
TetherState tetherState = mTetherStates.valueAt(i);
|
||||
if (tetherState.mLastState == IControlsTethering.STATE_TETHERED) {
|
||||
if (tetherState.lastState == IControlsTethering.STATE_TETHERED) {
|
||||
list.add(mTetherStates.keyAt(i));
|
||||
}
|
||||
}
|
||||
@@ -894,7 +887,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
|
||||
synchronized (mPublicSync) {
|
||||
for (int i = 0; i < mTetherStates.size(); i++) {
|
||||
TetherState tetherState = mTetherStates.valueAt(i);
|
||||
if (tetherState.mLastState == IControlsTethering.STATE_AVAILABLE) {
|
||||
if (tetherState.lastState == IControlsTethering.STATE_AVAILABLE) {
|
||||
list.add(mTetherStates.keyAt(i));
|
||||
}
|
||||
}
|
||||
@@ -911,7 +904,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
|
||||
synchronized (mPublicSync) {
|
||||
for (int i = 0; i < mTetherStates.size(); i++) {
|
||||
TetherState tetherState = mTetherStates.valueAt(i);
|
||||
if (tetherState.mLastError != ConnectivityManager.TETHER_ERROR_NO_ERROR) {
|
||||
if (tetherState.lastError != ConnectivityManager.TETHER_ERROR_NO_ERROR) {
|
||||
list.add(mTetherStates.keyAt(i));
|
||||
}
|
||||
}
|
||||
@@ -1318,7 +1311,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
|
||||
synchronized (mPublicSync) {
|
||||
for (int i = 0; i < mTetherStates.size(); i++) {
|
||||
TetherState tetherState = mTetherStates.valueAt(i);
|
||||
if (tetherState.mLastState != IControlsTethering.STATE_TETHERED) {
|
||||
if (tetherState.lastState != IControlsTethering.STATE_TETHERED) {
|
||||
continue; // Skip interfaces that aren't tethered.
|
||||
}
|
||||
String iface = mTetherStates.keyAt(i);
|
||||
@@ -1606,7 +1599,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
|
||||
final TetherState tetherState = mTetherStates.valueAt(i);
|
||||
pw.print(iface + " - ");
|
||||
|
||||
switch (tetherState.mLastState) {
|
||||
switch (tetherState.lastState) {
|
||||
case IControlsTethering.STATE_UNAVAILABLE:
|
||||
pw.print("UnavailableState");
|
||||
break;
|
||||
@@ -1620,7 +1613,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
|
||||
pw.print("UnknownState");
|
||||
break;
|
||||
}
|
||||
pw.println(" - lastError = " + tetherState.mLastError);
|
||||
pw.println(" - lastError = " + tetherState.lastError);
|
||||
}
|
||||
pw.decreaseIndent();
|
||||
}
|
||||
@@ -1632,9 +1625,9 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
|
||||
int state, int error) {
|
||||
synchronized (mPublicSync) {
|
||||
TetherState tetherState = mTetherStates.get(iface);
|
||||
if (tetherState != null && tetherState.mStateMachine.equals(who)) {
|
||||
tetherState.mLastState = state;
|
||||
tetherState.mLastError = error;
|
||||
if (tetherState != null && tetherState.stateMachine.equals(who)) {
|
||||
tetherState.lastState = state;
|
||||
tetherState.lastError = error;
|
||||
} else {
|
||||
if (DBG) Log.d(TAG, "got notification from stale iface " + iface);
|
||||
}
|
||||
@@ -1678,7 +1671,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
|
||||
interfaceType, mNMService, mStatsService, this,
|
||||
new IPv6TetheringInterfaceServices(iface, mNMService)));
|
||||
mTetherStates.put(iface, tetherState);
|
||||
tetherState.mStateMachine.start();
|
||||
tetherState.stateMachine.start();
|
||||
}
|
||||
|
||||
private static String[] copy(String[] strarray) {
|
||||
|
||||
Reference in New Issue
Block a user