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