Merge "Refactor isTetheringSupported() calls" into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
5a36b3b6ea
@@ -910,7 +910,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
private Tethering makeTethering() {
|
private Tethering makeTethering() {
|
||||||
// TODO: Move other elements into @Overridden getters.
|
// TODO: Move other elements into @Overridden getters.
|
||||||
final TetheringDependencies deps = new TetheringDependencies();
|
final TetheringDependencies deps = new TetheringDependencies() {
|
||||||
|
@Override
|
||||||
|
public boolean isTetheringSupported() {
|
||||||
|
return ConnectivityService.this.isTetheringSupported();
|
||||||
|
}
|
||||||
|
};
|
||||||
return new Tethering(mContext, mNetd, mStatsService, mPolicyManager,
|
return new Tethering(mContext, mNetd, mStatsService, mPolicyManager,
|
||||||
IoThread.get().getLooper(), new MockableSystemProperties(),
|
IoThread.get().getLooper(), new MockableSystemProperties(),
|
||||||
deps);
|
deps);
|
||||||
|
|||||||
@@ -19,6 +19,27 @@ package com.android.server.connectivity;
|
|||||||
import static android.hardware.usb.UsbManager.USB_CONFIGURED;
|
import static android.hardware.usb.UsbManager.USB_CONFIGURED;
|
||||||
import static android.hardware.usb.UsbManager.USB_CONNECTED;
|
import static android.hardware.usb.UsbManager.USB_CONNECTED;
|
||||||
import static android.hardware.usb.UsbManager.USB_FUNCTION_RNDIS;
|
import static android.hardware.usb.UsbManager.USB_FUNCTION_RNDIS;
|
||||||
|
import static android.net.ConnectivityManager.ACTION_TETHER_STATE_CHANGED;
|
||||||
|
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
|
||||||
|
import static android.net.ConnectivityManager.EXTRA_ACTIVE_LOCAL_ONLY;
|
||||||
|
import static android.net.ConnectivityManager.EXTRA_ACTIVE_TETHER;
|
||||||
|
import static android.net.ConnectivityManager.EXTRA_ADD_TETHER_TYPE;
|
||||||
|
import static android.net.ConnectivityManager.EXTRA_AVAILABLE_TETHER;
|
||||||
|
import static android.net.ConnectivityManager.EXTRA_ERRORED_TETHER;
|
||||||
|
import static android.net.ConnectivityManager.EXTRA_NETWORK_INFO;
|
||||||
|
import static android.net.ConnectivityManager.EXTRA_PROVISION_CALLBACK;
|
||||||
|
import static android.net.ConnectivityManager.EXTRA_REM_TETHER_TYPE;
|
||||||
|
import static android.net.ConnectivityManager.EXTRA_RUN_PROVISION;
|
||||||
|
import static android.net.ConnectivityManager.EXTRA_SET_ALARM;
|
||||||
|
import static android.net.ConnectivityManager.TETHER_ERROR_MASTER_ERROR;
|
||||||
|
import static android.net.ConnectivityManager.TETHER_ERROR_NO_ERROR;
|
||||||
|
import static android.net.ConnectivityManager.TETHER_ERROR_SERVICE_UNAVAIL;
|
||||||
|
import static android.net.ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE;
|
||||||
|
import static android.net.ConnectivityManager.TETHER_ERROR_UNAVAIL_IFACE;
|
||||||
|
import static android.net.ConnectivityManager.TETHERING_BLUETOOTH;
|
||||||
|
import static android.net.ConnectivityManager.TETHERING_INVALID;
|
||||||
|
import static android.net.ConnectivityManager.TETHERING_USB;
|
||||||
|
import static android.net.ConnectivityManager.TETHERING_WIFI;
|
||||||
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
|
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
|
||||||
import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_INTERFACE_NAME;
|
import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_INTERFACE_NAME;
|
||||||
import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_MODE;
|
import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_MODE;
|
||||||
@@ -45,7 +66,6 @@ import android.content.Intent;
|
|||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.hardware.usb.UsbManager;
|
import android.hardware.usb.UsbManager;
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.net.INetworkPolicyManager;
|
import android.net.INetworkPolicyManager;
|
||||||
import android.net.INetworkStatsService;
|
import android.net.INetworkStatsService;
|
||||||
import android.net.IpPrefix;
|
import android.net.IpPrefix;
|
||||||
@@ -148,7 +168,7 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
stateMachine = sm;
|
stateMachine = sm;
|
||||||
// Assume all state machines start out available and with no errors.
|
// Assume all state machines start out available and with no errors.
|
||||||
lastState = IControlsTethering.STATE_AVAILABLE;
|
lastState = IControlsTethering.STATE_AVAILABLE;
|
||||||
lastError = ConnectivityManager.TETHER_ERROR_NO_ERROR;
|
lastError = TETHER_ERROR_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCurrentlyServing() {
|
public boolean isCurrentlyServing() {
|
||||||
@@ -216,7 +236,7 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
|
|
||||||
final Handler smHandler = mTetherMasterSM.getHandler();
|
final Handler smHandler = mTetherMasterSM.getHandler();
|
||||||
mOffloadController = new OffloadController(smHandler,
|
mOffloadController = new OffloadController(smHandler,
|
||||||
deps.getOffloadHardwareInterface(smHandler, mLog),
|
mDeps.getOffloadHardwareInterface(smHandler, mLog),
|
||||||
mContext.getContentResolver(), mNMService,
|
mContext.getContentResolver(), mNMService,
|
||||||
mLog);
|
mLog);
|
||||||
mUpstreamNetworkMonitor = deps.getUpstreamNetworkMonitor(mContext, mTetherMasterSM, mLog,
|
mUpstreamNetworkMonitor = deps.getUpstreamNetworkMonitor(mContext, mTetherMasterSM, mLog,
|
||||||
@@ -243,7 +263,7 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
mStateReceiver = new StateReceiver();
|
mStateReceiver = new StateReceiver();
|
||||||
filter = new IntentFilter();
|
filter = new IntentFilter();
|
||||||
filter.addAction(UsbManager.ACTION_USB_STATE);
|
filter.addAction(UsbManager.ACTION_USB_STATE);
|
||||||
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
filter.addAction(CONNECTIVITY_ACTION);
|
||||||
filter.addAction(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
|
filter.addAction(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
|
||||||
filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
|
filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
|
||||||
mContext.registerReceiver(mStateReceiver, filter, null, smHandler);
|
mContext.registerReceiver(mStateReceiver, filter, null, smHandler);
|
||||||
@@ -265,12 +285,6 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
updateConfiguration();
|
updateConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
// We can't do this once in the Tethering() constructor and cache the value, because the
|
|
||||||
// CONNECTIVITY_SERVICE is registered only after the Tethering() constructor has completed.
|
|
||||||
private ConnectivityManager getConnectivityManager() {
|
|
||||||
return (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
}
|
|
||||||
|
|
||||||
private WifiManager getWifiManager() {
|
private WifiManager getWifiManager() {
|
||||||
return (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
|
return (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
|
||||||
}
|
}
|
||||||
@@ -296,7 +310,7 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
if (up) {
|
if (up) {
|
||||||
maybeTrackNewInterfaceLocked(iface);
|
maybeTrackNewInterfaceLocked(iface);
|
||||||
} else {
|
} else {
|
||||||
if (ifaceNameToType(iface) == ConnectivityManager.TETHERING_BLUETOOTH) {
|
if (ifaceNameToType(iface) == TETHERING_BLUETOOTH) {
|
||||||
stopTrackingInterfaceLocked(iface);
|
stopTrackingInterfaceLocked(iface);
|
||||||
} else {
|
} else {
|
||||||
// Ignore usb0 down after enabling RNDIS.
|
// Ignore usb0 down after enabling RNDIS.
|
||||||
@@ -318,13 +332,13 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
final TetheringConfiguration cfg = mConfig;
|
final TetheringConfiguration cfg = mConfig;
|
||||||
|
|
||||||
if (cfg.isWifi(iface)) {
|
if (cfg.isWifi(iface)) {
|
||||||
return ConnectivityManager.TETHERING_WIFI;
|
return TETHERING_WIFI;
|
||||||
} else if (cfg.isUsb(iface)) {
|
} else if (cfg.isUsb(iface)) {
|
||||||
return ConnectivityManager.TETHERING_USB;
|
return TETHERING_USB;
|
||||||
} else if (cfg.isBluetooth(iface)) {
|
} else if (cfg.isBluetooth(iface)) {
|
||||||
return ConnectivityManager.TETHERING_BLUETOOTH;
|
return TETHERING_BLUETOOTH;
|
||||||
}
|
}
|
||||||
return ConnectivityManager.TETHERING_INVALID;
|
return TETHERING_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -426,26 +440,26 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
boolean isProvisioningRequired = enable && isTetherProvisioningRequired();
|
boolean isProvisioningRequired = enable && isTetherProvisioningRequired();
|
||||||
int result;
|
int result;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ConnectivityManager.TETHERING_WIFI:
|
case TETHERING_WIFI:
|
||||||
result = setWifiTethering(enable);
|
result = setWifiTethering(enable);
|
||||||
if (isProvisioningRequired && result == ConnectivityManager.TETHER_ERROR_NO_ERROR) {
|
if (isProvisioningRequired && result == TETHER_ERROR_NO_ERROR) {
|
||||||
scheduleProvisioningRechecks(type);
|
scheduleProvisioningRechecks(type);
|
||||||
}
|
}
|
||||||
sendTetherResult(receiver, result);
|
sendTetherResult(receiver, result);
|
||||||
break;
|
break;
|
||||||
case ConnectivityManager.TETHERING_USB:
|
case TETHERING_USB:
|
||||||
result = setUsbTethering(enable);
|
result = setUsbTethering(enable);
|
||||||
if (isProvisioningRequired && result == ConnectivityManager.TETHER_ERROR_NO_ERROR) {
|
if (isProvisioningRequired && result == TETHER_ERROR_NO_ERROR) {
|
||||||
scheduleProvisioningRechecks(type);
|
scheduleProvisioningRechecks(type);
|
||||||
}
|
}
|
||||||
sendTetherResult(receiver, result);
|
sendTetherResult(receiver, result);
|
||||||
break;
|
break;
|
||||||
case ConnectivityManager.TETHERING_BLUETOOTH:
|
case TETHERING_BLUETOOTH:
|
||||||
setBluetoothTethering(enable, receiver);
|
setBluetoothTethering(enable, receiver);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Log.w(TAG, "Invalid tether type.");
|
Log.w(TAG, "Invalid tether type.");
|
||||||
sendTetherResult(receiver, ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE);
|
sendTetherResult(receiver, TETHER_ERROR_UNKNOWN_IFACE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -456,7 +470,7 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int setWifiTethering(final boolean enable) {
|
private int setWifiTethering(final boolean enable) {
|
||||||
int rval = ConnectivityManager.TETHER_ERROR_MASTER_ERROR;
|
int rval = TETHER_ERROR_MASTER_ERROR;
|
||||||
final long ident = Binder.clearCallingIdentity();
|
final long ident = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
synchronized (mPublicSync) {
|
synchronized (mPublicSync) {
|
||||||
@@ -464,7 +478,7 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
final WifiManager mgr = getWifiManager();
|
final WifiManager mgr = getWifiManager();
|
||||||
if ((enable && mgr.startSoftAp(null /* use existing wifi config */)) ||
|
if ((enable && mgr.startSoftAp(null /* use existing wifi config */)) ||
|
||||||
(!enable && mgr.stopSoftAp())) {
|
(!enable && mgr.stopSoftAp())) {
|
||||||
rval = ConnectivityManager.TETHER_ERROR_NO_ERROR;
|
rval = TETHER_ERROR_NO_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@@ -478,7 +492,7 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
if (adapter == null || !adapter.isEnabled()) {
|
if (adapter == null || !adapter.isEnabled()) {
|
||||||
Log.w(TAG, "Tried to enable bluetooth tethering with null or disabled adapter. null: " +
|
Log.w(TAG, "Tried to enable bluetooth tethering with null or disabled adapter. null: " +
|
||||||
(adapter == null));
|
(adapter == null));
|
||||||
sendTetherResult(receiver, ConnectivityManager.TETHER_ERROR_SERVICE_UNAVAIL);
|
sendTetherResult(receiver, TETHER_ERROR_SERVICE_UNAVAIL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -491,12 +505,12 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
((BluetoothPan) proxy).setBluetoothTethering(enable);
|
((BluetoothPan) proxy).setBluetoothTethering(enable);
|
||||||
// TODO: Enabling bluetooth tethering can fail asynchronously here.
|
// TODO: Enabling bluetooth tethering can fail asynchronously here.
|
||||||
// We should figure out a way to bubble up that failure instead of sending success.
|
// We should figure out a way to bubble up that failure instead of sending success.
|
||||||
int result = ((BluetoothPan) proxy).isTetheringOn() == enable ?
|
final int result = (((BluetoothPan) proxy).isTetheringOn() == enable)
|
||||||
ConnectivityManager.TETHER_ERROR_NO_ERROR :
|
? TETHER_ERROR_NO_ERROR
|
||||||
ConnectivityManager.TETHER_ERROR_MASTER_ERROR;
|
: TETHER_ERROR_MASTER_ERROR;
|
||||||
sendTetherResult(receiver, result);
|
sendTetherResult(receiver, result);
|
||||||
if (enable && isTetherProvisioningRequired()) {
|
if (enable && isTetherProvisioningRequired()) {
|
||||||
scheduleProvisioningRechecks(ConnectivityManager.TETHERING_BLUETOOTH);
|
scheduleProvisioningRechecks(TETHERING_BLUETOOTH);
|
||||||
}
|
}
|
||||||
adapter.closeProfileProxy(BluetoothProfile.PAN, proxy);
|
adapter.closeProfileProxy(BluetoothProfile.PAN, proxy);
|
||||||
}
|
}
|
||||||
@@ -510,8 +524,8 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
|
|
||||||
private void sendUiTetherProvisionIntent(int type, ResultReceiver receiver) {
|
private void sendUiTetherProvisionIntent(int type, ResultReceiver receiver) {
|
||||||
Intent intent = new Intent(Settings.ACTION_TETHER_PROVISIONING);
|
Intent intent = new Intent(Settings.ACTION_TETHER_PROVISIONING);
|
||||||
intent.putExtra(ConnectivityManager.EXTRA_ADD_TETHER_TYPE, type);
|
intent.putExtra(EXTRA_ADD_TETHER_TYPE, type);
|
||||||
intent.putExtra(ConnectivityManager.EXTRA_PROVISION_CALLBACK, receiver);
|
intent.putExtra(EXTRA_PROVISION_CALLBACK, receiver);
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
final long ident = Binder.clearCallingIdentity();
|
final long ident = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
@@ -534,7 +548,7 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
@Override
|
@Override
|
||||||
protected void onReceiveResult(int resultCode, Bundle resultData) {
|
protected void onReceiveResult(int resultCode, Bundle resultData) {
|
||||||
// If provisioning is successful, enable tethering, otherwise just send the error.
|
// If provisioning is successful, enable tethering, otherwise just send the error.
|
||||||
if (resultCode == ConnectivityManager.TETHER_ERROR_NO_ERROR) {
|
if (resultCode == TETHER_ERROR_NO_ERROR) {
|
||||||
enableTetheringInternal(type, true, receiver);
|
enableTetheringInternal(type, true, receiver);
|
||||||
} else {
|
} else {
|
||||||
sendTetherResult(receiver, resultCode);
|
sendTetherResult(receiver, resultCode);
|
||||||
@@ -554,8 +568,8 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
|
|
||||||
private void scheduleProvisioningRechecks(int type) {
|
private void scheduleProvisioningRechecks(int type) {
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.putExtra(ConnectivityManager.EXTRA_ADD_TETHER_TYPE, type);
|
intent.putExtra(EXTRA_ADD_TETHER_TYPE, type);
|
||||||
intent.putExtra(ConnectivityManager.EXTRA_SET_ALARM, true);
|
intent.putExtra(EXTRA_SET_ALARM, true);
|
||||||
intent.setComponent(TETHER_SERVICE);
|
intent.setComponent(TETHER_SERVICE);
|
||||||
final long ident = Binder.clearCallingIdentity();
|
final long ident = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
@@ -572,9 +586,9 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
|
|
||||||
private void sendSilentTetherProvisionIntent(int type, ResultReceiver receiver) {
|
private void sendSilentTetherProvisionIntent(int type, ResultReceiver receiver) {
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.putExtra(ConnectivityManager.EXTRA_ADD_TETHER_TYPE, type);
|
intent.putExtra(EXTRA_ADD_TETHER_TYPE, type);
|
||||||
intent.putExtra(ConnectivityManager.EXTRA_RUN_PROVISION, true);
|
intent.putExtra(EXTRA_RUN_PROVISION, true);
|
||||||
intent.putExtra(ConnectivityManager.EXTRA_PROVISION_CALLBACK, receiver);
|
intent.putExtra(EXTRA_PROVISION_CALLBACK, receiver);
|
||||||
intent.setComponent(TETHER_SERVICE);
|
intent.setComponent(TETHER_SERVICE);
|
||||||
final long ident = Binder.clearCallingIdentity();
|
final long ident = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
@@ -585,9 +599,9 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void cancelTetherProvisioningRechecks(int type) {
|
private void cancelTetherProvisioningRechecks(int type) {
|
||||||
if (getConnectivityManager().isTetheringSupported()) {
|
if (mDeps.isTetheringSupported()) {
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.putExtra(ConnectivityManager.EXTRA_REM_TETHER_TYPE, type);
|
intent.putExtra(EXTRA_REM_TETHER_TYPE, type);
|
||||||
intent.setComponent(TETHER_SERVICE);
|
intent.setComponent(TETHER_SERVICE);
|
||||||
final long ident = Binder.clearCallingIdentity();
|
final long ident = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
@@ -602,8 +616,8 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
// TODO: De-duplicate with above code, where possible.
|
// TODO: De-duplicate with above code, where possible.
|
||||||
private void startProvisionIntent(int tetherType) {
|
private void startProvisionIntent(int tetherType) {
|
||||||
final Intent startProvIntent = new Intent();
|
final Intent startProvIntent = new Intent();
|
||||||
startProvIntent.putExtra(ConnectivityManager.EXTRA_ADD_TETHER_TYPE, tetherType);
|
startProvIntent.putExtra(EXTRA_ADD_TETHER_TYPE, tetherType);
|
||||||
startProvIntent.putExtra(ConnectivityManager.EXTRA_RUN_PROVISION, true);
|
startProvIntent.putExtra(EXTRA_RUN_PROVISION, true);
|
||||||
startProvIntent.setComponent(TETHER_SERVICE);
|
startProvIntent.setComponent(TETHER_SERVICE);
|
||||||
mContext.startServiceAsUser(startProvIntent, UserHandle.CURRENT);
|
mContext.startServiceAsUser(startProvIntent, UserHandle.CURRENT);
|
||||||
}
|
}
|
||||||
@@ -618,13 +632,13 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
TetherState tetherState = mTetherStates.get(iface);
|
TetherState tetherState = mTetherStates.get(iface);
|
||||||
if (tetherState == null) {
|
if (tetherState == null) {
|
||||||
Log.e(TAG, "Tried to Tether an unknown iface: " + iface + ", ignoring");
|
Log.e(TAG, "Tried to Tether an unknown iface: " + iface + ", ignoring");
|
||||||
return ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE;
|
return TETHER_ERROR_UNKNOWN_IFACE;
|
||||||
}
|
}
|
||||||
// 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.lastState != 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 TETHER_ERROR_UNAVAIL_IFACE;
|
||||||
}
|
}
|
||||||
// NOTE: If a CMD_TETHER_REQUESTED message is already in the TISM's
|
// NOTE: If a CMD_TETHER_REQUESTED message is already in the TISM's
|
||||||
// queue but not yet processed, this will be a no-op and it will not
|
// queue but not yet processed, this will be a no-op and it will not
|
||||||
@@ -633,7 +647,7 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
// TODO: reexamine the threading and messaging model.
|
// TODO: reexamine the threading and messaging model.
|
||||||
tetherState.stateMachine.sendMessage(
|
tetherState.stateMachine.sendMessage(
|
||||||
TetherInterfaceStateMachine.CMD_TETHER_REQUESTED, requestedState);
|
TetherInterfaceStateMachine.CMD_TETHER_REQUESTED, requestedState);
|
||||||
return ConnectivityManager.TETHER_ERROR_NO_ERROR;
|
return TETHER_ERROR_NO_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -643,22 +657,22 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
TetherState tetherState = mTetherStates.get(iface);
|
TetherState tetherState = mTetherStates.get(iface);
|
||||||
if (tetherState == null) {
|
if (tetherState == null) {
|
||||||
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 TETHER_ERROR_UNKNOWN_IFACE;
|
||||||
}
|
}
|
||||||
if (!tetherState.isCurrentlyServing()) {
|
if (!tetherState.isCurrentlyServing()) {
|
||||||
Log.e(TAG, "Tried to untether an inactive iface :" + iface + ", ignoring");
|
Log.e(TAG, "Tried to untether an inactive iface :" + iface + ", ignoring");
|
||||||
return ConnectivityManager.TETHER_ERROR_UNAVAIL_IFACE;
|
return TETHER_ERROR_UNAVAIL_IFACE;
|
||||||
}
|
}
|
||||||
tetherState.stateMachine.sendMessage(
|
tetherState.stateMachine.sendMessage(
|
||||||
TetherInterfaceStateMachine.CMD_TETHER_UNREQUESTED);
|
TetherInterfaceStateMachine.CMD_TETHER_UNREQUESTED);
|
||||||
return ConnectivityManager.TETHER_ERROR_NO_ERROR;
|
return TETHER_ERROR_NO_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void untetherAll() {
|
public void untetherAll() {
|
||||||
stopTethering(ConnectivityManager.TETHERING_WIFI);
|
stopTethering(TETHERING_WIFI);
|
||||||
stopTethering(ConnectivityManager.TETHERING_USB);
|
stopTethering(TETHERING_USB);
|
||||||
stopTethering(ConnectivityManager.TETHERING_BLUETOOTH);
|
stopTethering(TETHERING_BLUETOOTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLastTetherError(String iface) {
|
public int getLastTetherError(String iface) {
|
||||||
@@ -667,7 +681,7 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
if (tetherState == null) {
|
if (tetherState == null) {
|
||||||
Log.e(TAG, "Tried to getLastTetherError on an unknown iface :" + iface +
|
Log.e(TAG, "Tried to getLastTetherError on an unknown iface :" + iface +
|
||||||
", ignoring");
|
", ignoring");
|
||||||
return ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE;
|
return TETHER_ERROR_UNKNOWN_IFACE;
|
||||||
}
|
}
|
||||||
return tetherState.lastError;
|
return tetherState.lastError;
|
||||||
}
|
}
|
||||||
@@ -675,7 +689,7 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
|
|
||||||
// TODO: Figure out how to update for local hotspot mode interfaces.
|
// TODO: Figure out how to update for local hotspot mode interfaces.
|
||||||
private void sendTetherStateChangedBroadcast() {
|
private void sendTetherStateChangedBroadcast() {
|
||||||
if (!getConnectivityManager().isTetheringSupported()) return;
|
if (!mDeps.isTetheringSupported()) return;
|
||||||
|
|
||||||
final ArrayList<String> availableList = new ArrayList<>();
|
final ArrayList<String> availableList = new ArrayList<>();
|
||||||
final ArrayList<String> tetherList = new ArrayList<>();
|
final ArrayList<String> tetherList = new ArrayList<>();
|
||||||
@@ -692,7 +706,7 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
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.lastError != ConnectivityManager.TETHER_ERROR_NO_ERROR) {
|
if (tetherState.lastError != TETHER_ERROR_NO_ERROR) {
|
||||||
erroredList.add(iface);
|
erroredList.add(iface);
|
||||||
} else if (tetherState.lastState == IControlsTethering.STATE_AVAILABLE) {
|
} else if (tetherState.lastState == IControlsTethering.STATE_AVAILABLE) {
|
||||||
availableList.add(iface);
|
availableList.add(iface);
|
||||||
@@ -710,13 +724,13 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final Intent bcast = new Intent(ConnectivityManager.ACTION_TETHER_STATE_CHANGED);
|
final Intent bcast = new Intent(ACTION_TETHER_STATE_CHANGED);
|
||||||
bcast.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING |
|
bcast.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING |
|
||||||
Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
|
Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
|
||||||
bcast.putStringArrayListExtra(ConnectivityManager.EXTRA_AVAILABLE_TETHER, availableList);
|
bcast.putStringArrayListExtra(EXTRA_AVAILABLE_TETHER, availableList);
|
||||||
bcast.putStringArrayListExtra(ConnectivityManager.EXTRA_ACTIVE_LOCAL_ONLY, localOnlyList);
|
bcast.putStringArrayListExtra(EXTRA_ACTIVE_LOCAL_ONLY, localOnlyList);
|
||||||
bcast.putStringArrayListExtra(ConnectivityManager.EXTRA_ACTIVE_TETHER, tetherList);
|
bcast.putStringArrayListExtra(EXTRA_ACTIVE_TETHER, tetherList);
|
||||||
bcast.putStringArrayListExtra(ConnectivityManager.EXTRA_ERRORED_TETHER, erroredList);
|
bcast.putStringArrayListExtra(EXTRA_ERRORED_TETHER, erroredList);
|
||||||
mContext.sendStickyBroadcastAsUser(bcast, UserHandle.ALL);
|
mContext.sendStickyBroadcastAsUser(bcast, UserHandle.ALL);
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Log.d(TAG, String.format(
|
Log.d(TAG, String.format(
|
||||||
@@ -839,7 +853,7 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
|
|
||||||
if (action.equals(UsbManager.ACTION_USB_STATE)) {
|
if (action.equals(UsbManager.ACTION_USB_STATE)) {
|
||||||
handleUsbAction(intent);
|
handleUsbAction(intent);
|
||||||
} else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
|
} else if (action.equals(CONNECTIVITY_ACTION)) {
|
||||||
handleConnectivityAction(intent);
|
handleConnectivityAction(intent);
|
||||||
} else if (action.equals(WifiManager.WIFI_AP_STATE_CHANGED_ACTION)) {
|
} else if (action.equals(WifiManager.WIFI_AP_STATE_CHANGED_ACTION)) {
|
||||||
handleWifiApAction(intent);
|
handleWifiApAction(intent);
|
||||||
@@ -850,8 +864,8 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleConnectivityAction(Intent intent) {
|
private void handleConnectivityAction(Intent intent) {
|
||||||
final NetworkInfo networkInfo = (NetworkInfo)intent.getParcelableExtra(
|
final NetworkInfo networkInfo =
|
||||||
ConnectivityManager.EXTRA_NETWORK_INFO);
|
(NetworkInfo) intent.getParcelableExtra(EXTRA_NETWORK_INFO);
|
||||||
if (networkInfo == null ||
|
if (networkInfo == null ||
|
||||||
networkInfo.getDetailedState() == NetworkInfo.DetailedState.FAILED) {
|
networkInfo.getDetailedState() == NetworkInfo.DetailedState.FAILED) {
|
||||||
return;
|
return;
|
||||||
@@ -887,14 +901,10 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
synchronized (Tethering.this.mPublicSync) {
|
synchronized (Tethering.this.mPublicSync) {
|
||||||
if (!usbConnected && mRndisEnabled) {
|
if (!usbConnected && mRndisEnabled) {
|
||||||
// Turn off tethering if it was enabled and there is a disconnect.
|
// Turn off tethering if it was enabled and there is a disconnect.
|
||||||
tetherMatchingInterfaces(
|
tetherMatchingInterfaces(IControlsTethering.STATE_AVAILABLE, TETHERING_USB);
|
||||||
IControlsTethering.STATE_AVAILABLE,
|
|
||||||
ConnectivityManager.TETHERING_USB);
|
|
||||||
} else if (usbConfigured && rndisEnabled) {
|
} else if (usbConfigured && rndisEnabled) {
|
||||||
// Tether if rndis is enabled and usb is configured.
|
// Tether if rndis is enabled and usb is configured.
|
||||||
tetherMatchingInterfaces(
|
tetherMatchingInterfaces(IControlsTethering.STATE_TETHERED, TETHERING_USB);
|
||||||
IControlsTethering.STATE_TETHERED,
|
|
||||||
ConnectivityManager.TETHERING_USB);
|
|
||||||
}
|
}
|
||||||
mRndisEnabled = usbConfigured && rndisEnabled;
|
mRndisEnabled = usbConfigured && rndisEnabled;
|
||||||
}
|
}
|
||||||
@@ -975,7 +985,7 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
|
|
||||||
for (int i = 0; i < mTetherStates.size(); i++) {
|
for (int i = 0; i < mTetherStates.size(); i++) {
|
||||||
TetherInterfaceStateMachine tism = mTetherStates.valueAt(i).stateMachine;
|
TetherInterfaceStateMachine tism = mTetherStates.valueAt(i).stateMachine;
|
||||||
if (tism.interfaceType() == ConnectivityManager.TETHERING_WIFI) {
|
if (tism.interfaceType() == TETHERING_WIFI) {
|
||||||
tism.unwanted();
|
tism.unwanted();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1003,7 +1013,7 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(ifname)) {
|
if (!TextUtils.isEmpty(ifname)) {
|
||||||
maybeTrackNewInterfaceLocked(ifname, ConnectivityManager.TETHERING_WIFI);
|
maybeTrackNewInterfaceLocked(ifname, TETHERING_WIFI);
|
||||||
changeInterfaceState(ifname, ipServingMode);
|
changeInterfaceState(ifname, ipServingMode);
|
||||||
} else {
|
} else {
|
||||||
mLog.e(String.format(
|
mLog.e(String.format(
|
||||||
@@ -1062,7 +1072,7 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
Log.wtf(TAG, "Unknown interface state: " + requestedState);
|
Log.wtf(TAG, "Unknown interface state: " + requestedState);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (result != ConnectivityManager.TETHER_ERROR_NO_ERROR) {
|
if (result != TETHER_ERROR_NO_ERROR) {
|
||||||
Log.e(TAG, "unable start or stop tethering on iface " + ifname);
|
Log.e(TAG, "unable start or stop tethering on iface " + ifname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1104,7 +1114,7 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
usbManager.setCurrentFunctions(enable ? UsbManager.FUNCTION_RNDIS
|
usbManager.setCurrentFunctions(enable ? UsbManager.FUNCTION_RNDIS
|
||||||
: UsbManager.FUNCTION_NONE);
|
: UsbManager.FUNCTION_NONE);
|
||||||
}
|
}
|
||||||
return ConnectivityManager.TETHER_ERROR_NO_ERROR;
|
return TETHER_ERROR_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO review API - figure out how to delete these entirely.
|
// TODO review API - figure out how to delete these entirely.
|
||||||
@@ -1143,7 +1153,7 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
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.lastError != ConnectivityManager.TETHER_ERROR_NO_ERROR) {
|
if (tetherState.lastError != TETHER_ERROR_NO_ERROR) {
|
||||||
list.add(mTetherStates.keyAt(i));
|
list.add(mTetherStates.keyAt(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1189,7 +1199,7 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
}
|
}
|
||||||
String iface = mTetherStates.keyAt(i);
|
String iface = mTetherStates.keyAt(i);
|
||||||
int interfaceType = ifaceNameToType(iface);
|
int interfaceType = ifaceNameToType(iface);
|
||||||
if (interfaceType != ConnectivityManager.TETHERING_INVALID) {
|
if (interfaceType != TETHERING_INVALID) {
|
||||||
tethered.add(interfaceType);
|
tethered.add(interfaceType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1439,7 +1449,7 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If this is a Wi-Fi interface, notify WifiManager of the active serving state.
|
// If this is a Wi-Fi interface, notify WifiManager of the active serving state.
|
||||||
if (who.interfaceType() == ConnectivityManager.TETHERING_WIFI) {
|
if (who.interfaceType() == TETHERING_WIFI) {
|
||||||
final WifiManager mgr = getWifiManager();
|
final WifiManager mgr = getWifiManager();
|
||||||
final String iface = who.interfaceName();
|
final String iface = who.interfaceName();
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
@@ -1463,8 +1473,8 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
mForwardedDownstreams.remove(who);
|
mForwardedDownstreams.remove(who);
|
||||||
|
|
||||||
// If this is a Wi-Fi interface, tell WifiManager of any errors.
|
// If this is a Wi-Fi interface, tell WifiManager of any errors.
|
||||||
if (who.interfaceType() == ConnectivityManager.TETHERING_WIFI) {
|
if (who.interfaceType() == TETHERING_WIFI) {
|
||||||
if (who.lastError() != ConnectivityManager.TETHER_ERROR_NO_ERROR) {
|
if (who.lastError() != TETHER_ERROR_NO_ERROR) {
|
||||||
getWifiManager().updateInterfaceIpState(
|
getWifiManager().updateInterfaceIpState(
|
||||||
who.interfaceName(), IFACE_IP_MODE_CONFIGURATION_ERROR);
|
who.interfaceName(), IFACE_IP_MODE_CONFIGURATION_ERROR);
|
||||||
}
|
}
|
||||||
@@ -1669,7 +1679,7 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
who.sendMessage(mErrorNotification);
|
who.sendMessage(mErrorNotification);
|
||||||
break;
|
break;
|
||||||
case CMD_CLEAR_ERROR:
|
case CMD_CLEAR_ERROR:
|
||||||
mErrorNotification = ConnectivityManager.TETHER_ERROR_NO_ERROR;
|
mErrorNotification = TETHER_ERROR_NO_ERROR;
|
||||||
transitionTo(mInitialState);
|
transitionTo(mInitialState);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -1931,7 +1941,7 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
// If TetherMasterSM is in ErrorState, TetherMasterSM stays there.
|
// If TetherMasterSM is in ErrorState, TetherMasterSM stays there.
|
||||||
// Thus we give a chance for TetherMasterSM to recover to InitialState
|
// Thus we give a chance for TetherMasterSM to recover to InitialState
|
||||||
// by sending CMD_CLEAR_ERROR
|
// by sending CMD_CLEAR_ERROR
|
||||||
if (error == ConnectivityManager.TETHER_ERROR_MASTER_ERROR) {
|
if (error == TETHER_ERROR_MASTER_ERROR) {
|
||||||
mTetherMasterSM.sendMessage(TetherMasterSM.CMD_CLEAR_ERROR, who);
|
mTetherMasterSM.sendMessage(TetherMasterSM.CMD_CLEAR_ERROR, who);
|
||||||
}
|
}
|
||||||
int which;
|
int which;
|
||||||
@@ -1975,7 +1985,7 @@ public class Tethering extends BaseNetworkObserver {
|
|||||||
private void maybeTrackNewInterfaceLocked(final String iface) {
|
private void maybeTrackNewInterfaceLocked(final String iface) {
|
||||||
// If we don't care about this type of interface, ignore.
|
// If we don't care about this type of interface, ignore.
|
||||||
final int interfaceType = ifaceNameToType(iface);
|
final int interfaceType = ifaceNameToType(iface);
|
||||||
if (interfaceType == ConnectivityManager.TETHERING_INVALID) {
|
if (interfaceType == TETHERING_INVALID) {
|
||||||
mLog.log(iface + " is not a tetherable iface, ignoring");
|
mLog.log(iface + " is not a tetherable iface, ignoring");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,4 +60,8 @@ public class TetheringDependencies {
|
|||||||
public INetd getNetdService() {
|
public INetd getNetdService() {
|
||||||
return NetdService.getInstance();
|
return NetdService.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isTetheringSupported() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,14 @@ package com.android.server.connectivity;
|
|||||||
import static android.hardware.usb.UsbManager.USB_CONFIGURED;
|
import static android.hardware.usb.UsbManager.USB_CONFIGURED;
|
||||||
import static android.hardware.usb.UsbManager.USB_CONNECTED;
|
import static android.hardware.usb.UsbManager.USB_CONNECTED;
|
||||||
import static android.hardware.usb.UsbManager.USB_FUNCTION_RNDIS;
|
import static android.hardware.usb.UsbManager.USB_FUNCTION_RNDIS;
|
||||||
|
import static android.net.ConnectivityManager.ACTION_TETHER_STATE_CHANGED;
|
||||||
|
import static android.net.ConnectivityManager.EXTRA_ACTIVE_LOCAL_ONLY;
|
||||||
|
import static android.net.ConnectivityManager.EXTRA_ACTIVE_TETHER;
|
||||||
|
import static android.net.ConnectivityManager.EXTRA_AVAILABLE_TETHER;
|
||||||
|
import static android.net.ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE;
|
||||||
import static android.net.ConnectivityManager.TETHERING_WIFI;
|
import static android.net.ConnectivityManager.TETHERING_WIFI;
|
||||||
import static android.net.ConnectivityManager.TETHERING_USB;
|
import static android.net.ConnectivityManager.TETHERING_USB;
|
||||||
|
import static android.net.ConnectivityManager.TYPE_MOBILE;
|
||||||
import static android.net.wifi.WifiManager.IFACE_IP_MODE_LOCAL_ONLY;
|
import static android.net.wifi.WifiManager.IFACE_IP_MODE_LOCAL_ONLY;
|
||||||
import static android.net.wifi.WifiManager.IFACE_IP_MODE_TETHERED;
|
import static android.net.wifi.WifiManager.IFACE_IP_MODE_TETHERED;
|
||||||
import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_INTERFACE_NAME;
|
import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_INTERFACE_NAME;
|
||||||
@@ -54,7 +60,6 @@ import android.content.IntentFilter;
|
|||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.hardware.usb.UsbManager;
|
import android.hardware.usb.UsbManager;
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.net.INetd;
|
import android.net.INetd;
|
||||||
import android.net.INetworkPolicyManager;
|
import android.net.INetworkPolicyManager;
|
||||||
import android.net.INetworkStatsService;
|
import android.net.INetworkStatsService;
|
||||||
@@ -125,7 +130,6 @@ public class TetheringTest {
|
|||||||
|
|
||||||
@Mock private ApplicationInfo mApplicationInfo;
|
@Mock private ApplicationInfo mApplicationInfo;
|
||||||
@Mock private Context mContext;
|
@Mock private Context mContext;
|
||||||
@Mock private ConnectivityManager mConnectivityManager;
|
|
||||||
@Mock private INetworkManagementService mNMService;
|
@Mock private INetworkManagementService mNMService;
|
||||||
@Mock private INetworkStatsService mStatsService;
|
@Mock private INetworkStatsService mStatsService;
|
||||||
@Mock private INetworkPolicyManager mPolicyManager;
|
@Mock private INetworkPolicyManager mPolicyManager;
|
||||||
@@ -173,7 +177,6 @@ public class TetheringTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getSystemService(String name) {
|
public Object getSystemService(String name) {
|
||||||
if (Context.CONNECTIVITY_SERVICE.equals(name)) return mConnectivityManager;
|
|
||||||
if (Context.WIFI_SERVICE.equals(name)) return mWifiManager;
|
if (Context.WIFI_SERVICE.equals(name)) return mWifiManager;
|
||||||
if (Context.USB_SERVICE.equals(name)) return mUsbManager;
|
if (Context.USB_SERVICE.equals(name)) return mUsbManager;
|
||||||
return super.getSystemService(name);
|
return super.getSystemService(name);
|
||||||
@@ -181,8 +184,15 @@ public class TetheringTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class MockTetheringDependencies extends TetheringDependencies {
|
public class MockTetheringDependencies extends TetheringDependencies {
|
||||||
private StateMachine upstreamNetworkMonitorMasterSM;
|
StateMachine upstreamNetworkMonitorMasterSM;
|
||||||
private ArrayList<TetherInterfaceStateMachine> ipv6CoordinatorNotifyList;
|
ArrayList<TetherInterfaceStateMachine> ipv6CoordinatorNotifyList;
|
||||||
|
int isTetheringSupportedCalls;
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
upstreamNetworkMonitorMasterSM = null;
|
||||||
|
ipv6CoordinatorNotifyList = null;
|
||||||
|
isTetheringSupportedCalls = 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OffloadHardwareInterface getOffloadHardwareInterface(Handler h, SharedLog log) {
|
public OffloadHardwareInterface getOffloadHardwareInterface(Handler h, SharedLog log) {
|
||||||
@@ -222,11 +232,17 @@ public class TetheringTest {
|
|||||||
return new InterfaceParams(ifName, index + IFINDEX_OFFSET,
|
return new InterfaceParams(ifName, index + IFINDEX_OFFSET,
|
||||||
MacAddress.ALL_ZEROS_ADDRESS);
|
MacAddress.ALL_ZEROS_ADDRESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isTetheringSupported() {
|
||||||
|
isTetheringSupportedCalls++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static NetworkState buildMobileUpstreamState(boolean withIPv4, boolean withIPv6,
|
private static NetworkState buildMobileUpstreamState(boolean withIPv4, boolean withIPv6,
|
||||||
boolean with464xlat) {
|
boolean with464xlat) {
|
||||||
final NetworkInfo info = new NetworkInfo(ConnectivityManager.TYPE_MOBILE, 0, null, null);
|
final NetworkInfo info = new NetworkInfo(TYPE_MOBILE, 0, null, null);
|
||||||
info.setDetailedState(NetworkInfo.DetailedState.CONNECTED, null, null);
|
info.setDetailedState(NetworkInfo.DetailedState.CONNECTED, null, null);
|
||||||
final LinkProperties prop = new LinkProperties();
|
final LinkProperties prop = new LinkProperties();
|
||||||
prop.setInterfaceName(TEST_MOBILE_IFNAME);
|
prop.setInterfaceName(TEST_MOBILE_IFNAME);
|
||||||
@@ -308,7 +324,8 @@ public class TetheringTest {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
mServiceContext.registerReceiver(mBroadcastReceiver,
|
mServiceContext.registerReceiver(mBroadcastReceiver,
|
||||||
new IntentFilter(ConnectivityManager.ACTION_TETHER_STATE_CHANGED));
|
new IntentFilter(ACTION_TETHER_STATE_CHANGED));
|
||||||
|
mTetheringDependencies.reset();
|
||||||
mTethering = new Tethering(mServiceContext, mNMService, mStatsService, mPolicyManager,
|
mTethering = new Tethering(mServiceContext, mNMService, mStatsService, mPolicyManager,
|
||||||
mLooper.getLooper(), mSystemProperties,
|
mLooper.getLooper(), mSystemProperties,
|
||||||
mTetheringDependencies);
|
mTetheringDependencies);
|
||||||
@@ -404,7 +421,7 @@ public class TetheringTest {
|
|||||||
private void verifyTetheringBroadcast(String ifname, String whichExtra) {
|
private void verifyTetheringBroadcast(String ifname, String whichExtra) {
|
||||||
// Verify that ifname is in the whichExtra array of the tether state changed broadcast.
|
// Verify that ifname is in the whichExtra array of the tether state changed broadcast.
|
||||||
final Intent bcast = mIntents.get(0);
|
final Intent bcast = mIntents.get(0);
|
||||||
assertEquals(ConnectivityManager.ACTION_TETHER_STATE_CHANGED, bcast.getAction());
|
assertEquals(ACTION_TETHER_STATE_CHANGED, bcast.getAction());
|
||||||
final ArrayList<String> ifnames = bcast.getStringArrayListExtra(whichExtra);
|
final ArrayList<String> ifnames = bcast.getStringArrayListExtra(whichExtra);
|
||||||
assertTrue(ifnames.contains(ifname));
|
assertTrue(ifnames.contains(ifname));
|
||||||
mIntents.remove(bcast);
|
mIntents.remove(bcast);
|
||||||
@@ -412,8 +429,6 @@ public class TetheringTest {
|
|||||||
|
|
||||||
public void failingLocalOnlyHotspotLegacyApBroadcast(
|
public void failingLocalOnlyHotspotLegacyApBroadcast(
|
||||||
boolean emulateInterfaceStatusChanged) throws Exception {
|
boolean emulateInterfaceStatusChanged) throws Exception {
|
||||||
when(mConnectivityManager.isTetheringSupported()).thenReturn(true);
|
|
||||||
|
|
||||||
// Emulate externally-visible WifiManager effects, causing the
|
// Emulate externally-visible WifiManager effects, causing the
|
||||||
// per-interface state machine to start up, and telling us that
|
// per-interface state machine to start up, and telling us that
|
||||||
// hotspot mode is to be started.
|
// hotspot mode is to be started.
|
||||||
@@ -427,16 +442,14 @@ public class TetheringTest {
|
|||||||
// then it creates a TetherInterfaceStateMachine and sends out a
|
// then it creates a TetherInterfaceStateMachine and sends out a
|
||||||
// broadcast indicating that the interface is "available".
|
// broadcast indicating that the interface is "available".
|
||||||
if (emulateInterfaceStatusChanged) {
|
if (emulateInterfaceStatusChanged) {
|
||||||
verify(mConnectivityManager, atLeastOnce()).isTetheringSupported();
|
assertEquals(1, mTetheringDependencies.isTetheringSupportedCalls);
|
||||||
verifyTetheringBroadcast(TEST_WLAN_IFNAME, ConnectivityManager.EXTRA_AVAILABLE_TETHER);
|
verifyTetheringBroadcast(TEST_WLAN_IFNAME, EXTRA_AVAILABLE_TETHER);
|
||||||
}
|
}
|
||||||
verifyNoMoreInteractions(mConnectivityManager);
|
|
||||||
verifyNoMoreInteractions(mNMService);
|
verifyNoMoreInteractions(mNMService);
|
||||||
verifyNoMoreInteractions(mWifiManager);
|
verifyNoMoreInteractions(mWifiManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prepareUsbTethering(NetworkState upstreamState) {
|
private void prepareUsbTethering(NetworkState upstreamState) {
|
||||||
when(mConnectivityManager.isTetheringSupported()).thenReturn(true);
|
|
||||||
when(mUpstreamNetworkMonitor.selectPreferredUpstreamType(any()))
|
when(mUpstreamNetworkMonitor.selectPreferredUpstreamType(any()))
|
||||||
.thenReturn(upstreamState);
|
.thenReturn(upstreamState);
|
||||||
|
|
||||||
@@ -454,7 +467,6 @@ public class TetheringTest {
|
|||||||
prepareUsbTethering(upstreamState);
|
prepareUsbTethering(upstreamState);
|
||||||
|
|
||||||
// This should produce no activity of any kind.
|
// This should produce no activity of any kind.
|
||||||
verifyNoMoreInteractions(mConnectivityManager);
|
|
||||||
verifyNoMoreInteractions(mNMService);
|
verifyNoMoreInteractions(mNMService);
|
||||||
|
|
||||||
// Pretend we then receive USB configured broadcast.
|
// Pretend we then receive USB configured broadcast.
|
||||||
@@ -481,8 +493,6 @@ public class TetheringTest {
|
|||||||
|
|
||||||
public void workingLocalOnlyHotspotEnrichedApBroadcast(
|
public void workingLocalOnlyHotspotEnrichedApBroadcast(
|
||||||
boolean emulateInterfaceStatusChanged) throws Exception {
|
boolean emulateInterfaceStatusChanged) throws Exception {
|
||||||
when(mConnectivityManager.isTetheringSupported()).thenReturn(true);
|
|
||||||
|
|
||||||
// Emulate externally-visible WifiManager effects, causing the
|
// Emulate externally-visible WifiManager effects, causing the
|
||||||
// per-interface state machine to start up, and telling us that
|
// per-interface state machine to start up, and telling us that
|
||||||
// hotspot mode is to be started.
|
// hotspot mode is to be started.
|
||||||
@@ -493,18 +503,17 @@ public class TetheringTest {
|
|||||||
mLooper.dispatchAll();
|
mLooper.dispatchAll();
|
||||||
|
|
||||||
verifyInterfaceServingModeStarted();
|
verifyInterfaceServingModeStarted();
|
||||||
verifyTetheringBroadcast(TEST_WLAN_IFNAME, ConnectivityManager.EXTRA_AVAILABLE_TETHER);
|
verifyTetheringBroadcast(TEST_WLAN_IFNAME, EXTRA_AVAILABLE_TETHER);
|
||||||
verify(mNMService, times(1)).setIpForwardingEnabled(true);
|
verify(mNMService, times(1)).setIpForwardingEnabled(true);
|
||||||
verify(mNMService, times(1)).startTethering(any(String[].class));
|
verify(mNMService, times(1)).startTethering(any(String[].class));
|
||||||
verifyNoMoreInteractions(mNMService);
|
verifyNoMoreInteractions(mNMService);
|
||||||
verify(mWifiManager).updateInterfaceIpState(
|
verify(mWifiManager).updateInterfaceIpState(
|
||||||
TEST_WLAN_IFNAME, WifiManager.IFACE_IP_MODE_LOCAL_ONLY);
|
TEST_WLAN_IFNAME, WifiManager.IFACE_IP_MODE_LOCAL_ONLY);
|
||||||
verifyNoMoreInteractions(mWifiManager);
|
verifyNoMoreInteractions(mWifiManager);
|
||||||
verifyTetheringBroadcast(TEST_WLAN_IFNAME, ConnectivityManager.EXTRA_ACTIVE_LOCAL_ONLY);
|
verifyTetheringBroadcast(TEST_WLAN_IFNAME, EXTRA_ACTIVE_LOCAL_ONLY);
|
||||||
verify(mUpstreamNetworkMonitor, times(1)).start();
|
verify(mUpstreamNetworkMonitor, times(1)).start();
|
||||||
// TODO: Figure out why this isn't exactly once, for sendTetherStateChangedBroadcast().
|
// TODO: Figure out why this isn't exactly once, for sendTetherStateChangedBroadcast().
|
||||||
verify(mConnectivityManager, atLeastOnce()).isTetheringSupported();
|
assertTrue(1 <= mTetheringDependencies.isTetheringSupportedCalls);
|
||||||
verifyNoMoreInteractions(mConnectivityManager);
|
|
||||||
|
|
||||||
// Emulate externally-visible WifiManager effects, when hotspot mode
|
// Emulate externally-visible WifiManager effects, when hotspot mode
|
||||||
// is being torn down.
|
// is being torn down.
|
||||||
@@ -523,8 +532,7 @@ public class TetheringTest {
|
|||||||
verifyNoMoreInteractions(mWifiManager);
|
verifyNoMoreInteractions(mWifiManager);
|
||||||
// Asking for the last error after the per-interface state machine
|
// Asking for the last error after the per-interface state machine
|
||||||
// has been reaped yields an unknown interface error.
|
// has been reaped yields an unknown interface error.
|
||||||
assertEquals(ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE,
|
assertEquals(TETHER_ERROR_UNKNOWN_IFACE, mTethering.getLastTetherError(TEST_WLAN_IFNAME));
|
||||||
mTethering.getLastTetherError(TEST_WLAN_IFNAME));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -648,7 +656,6 @@ public class TetheringTest {
|
|||||||
// TODO: Test with and without interfaceStatusChanged().
|
// TODO: Test with and without interfaceStatusChanged().
|
||||||
@Test
|
@Test
|
||||||
public void failingWifiTetheringLegacyApBroadcast() throws Exception {
|
public void failingWifiTetheringLegacyApBroadcast() throws Exception {
|
||||||
when(mConnectivityManager.isTetheringSupported()).thenReturn(true);
|
|
||||||
when(mWifiManager.startSoftAp(any(WifiConfiguration.class))).thenReturn(true);
|
when(mWifiManager.startSoftAp(any(WifiConfiguration.class))).thenReturn(true);
|
||||||
|
|
||||||
// Emulate pressing the WiFi tethering button.
|
// Emulate pressing the WiFi tethering button.
|
||||||
@@ -656,7 +663,6 @@ public class TetheringTest {
|
|||||||
mLooper.dispatchAll();
|
mLooper.dispatchAll();
|
||||||
verify(mWifiManager, times(1)).startSoftAp(null);
|
verify(mWifiManager, times(1)).startSoftAp(null);
|
||||||
verifyNoMoreInteractions(mWifiManager);
|
verifyNoMoreInteractions(mWifiManager);
|
||||||
verifyNoMoreInteractions(mConnectivityManager);
|
|
||||||
verifyNoMoreInteractions(mNMService);
|
verifyNoMoreInteractions(mNMService);
|
||||||
|
|
||||||
// Emulate externally-visible WifiManager effects, causing the
|
// Emulate externally-visible WifiManager effects, causing the
|
||||||
@@ -666,9 +672,8 @@ public class TetheringTest {
|
|||||||
sendWifiApStateChanged(WIFI_AP_STATE_ENABLED);
|
sendWifiApStateChanged(WIFI_AP_STATE_ENABLED);
|
||||||
mLooper.dispatchAll();
|
mLooper.dispatchAll();
|
||||||
|
|
||||||
verify(mConnectivityManager, atLeastOnce()).isTetheringSupported();
|
assertEquals(1, mTetheringDependencies.isTetheringSupportedCalls);
|
||||||
verifyTetheringBroadcast(TEST_WLAN_IFNAME, ConnectivityManager.EXTRA_AVAILABLE_TETHER);
|
verifyTetheringBroadcast(TEST_WLAN_IFNAME, EXTRA_AVAILABLE_TETHER);
|
||||||
verifyNoMoreInteractions(mConnectivityManager);
|
|
||||||
verifyNoMoreInteractions(mNMService);
|
verifyNoMoreInteractions(mNMService);
|
||||||
verifyNoMoreInteractions(mWifiManager);
|
verifyNoMoreInteractions(mWifiManager);
|
||||||
}
|
}
|
||||||
@@ -676,7 +681,6 @@ public class TetheringTest {
|
|||||||
// TODO: Test with and without interfaceStatusChanged().
|
// TODO: Test with and without interfaceStatusChanged().
|
||||||
@Test
|
@Test
|
||||||
public void workingWifiTetheringEnrichedApBroadcast() throws Exception {
|
public void workingWifiTetheringEnrichedApBroadcast() throws Exception {
|
||||||
when(mConnectivityManager.isTetheringSupported()).thenReturn(true);
|
|
||||||
when(mWifiManager.startSoftAp(any(WifiConfiguration.class))).thenReturn(true);
|
when(mWifiManager.startSoftAp(any(WifiConfiguration.class))).thenReturn(true);
|
||||||
|
|
||||||
// Emulate pressing the WiFi tethering button.
|
// Emulate pressing the WiFi tethering button.
|
||||||
@@ -684,7 +688,6 @@ public class TetheringTest {
|
|||||||
mLooper.dispatchAll();
|
mLooper.dispatchAll();
|
||||||
verify(mWifiManager, times(1)).startSoftAp(null);
|
verify(mWifiManager, times(1)).startSoftAp(null);
|
||||||
verifyNoMoreInteractions(mWifiManager);
|
verifyNoMoreInteractions(mWifiManager);
|
||||||
verifyNoMoreInteractions(mConnectivityManager);
|
|
||||||
verifyNoMoreInteractions(mNMService);
|
verifyNoMoreInteractions(mNMService);
|
||||||
|
|
||||||
// Emulate externally-visible WifiManager effects, causing the
|
// Emulate externally-visible WifiManager effects, causing the
|
||||||
@@ -695,21 +698,20 @@ public class TetheringTest {
|
|||||||
mLooper.dispatchAll();
|
mLooper.dispatchAll();
|
||||||
|
|
||||||
verifyInterfaceServingModeStarted();
|
verifyInterfaceServingModeStarted();
|
||||||
verifyTetheringBroadcast(TEST_WLAN_IFNAME, ConnectivityManager.EXTRA_AVAILABLE_TETHER);
|
verifyTetheringBroadcast(TEST_WLAN_IFNAME, EXTRA_AVAILABLE_TETHER);
|
||||||
verify(mNMService, times(1)).setIpForwardingEnabled(true);
|
verify(mNMService, times(1)).setIpForwardingEnabled(true);
|
||||||
verify(mNMService, times(1)).startTethering(any(String[].class));
|
verify(mNMService, times(1)).startTethering(any(String[].class));
|
||||||
verifyNoMoreInteractions(mNMService);
|
verifyNoMoreInteractions(mNMService);
|
||||||
verify(mWifiManager).updateInterfaceIpState(
|
verify(mWifiManager).updateInterfaceIpState(
|
||||||
TEST_WLAN_IFNAME, WifiManager.IFACE_IP_MODE_TETHERED);
|
TEST_WLAN_IFNAME, WifiManager.IFACE_IP_MODE_TETHERED);
|
||||||
verifyNoMoreInteractions(mWifiManager);
|
verifyNoMoreInteractions(mWifiManager);
|
||||||
verifyTetheringBroadcast(TEST_WLAN_IFNAME, ConnectivityManager.EXTRA_ACTIVE_TETHER);
|
verifyTetheringBroadcast(TEST_WLAN_IFNAME, EXTRA_ACTIVE_TETHER);
|
||||||
verify(mUpstreamNetworkMonitor, times(1)).start();
|
verify(mUpstreamNetworkMonitor, times(1)).start();
|
||||||
// In tethering mode, in the default configuration, an explicit request
|
// In tethering mode, in the default configuration, an explicit request
|
||||||
// for a mobile network is also made.
|
// for a mobile network is also made.
|
||||||
verify(mUpstreamNetworkMonitor, times(1)).registerMobileNetworkRequest();
|
verify(mUpstreamNetworkMonitor, times(1)).registerMobileNetworkRequest();
|
||||||
// TODO: Figure out why this isn't exactly once, for sendTetherStateChangedBroadcast().
|
// TODO: Figure out why this isn't exactly once, for sendTetherStateChangedBroadcast().
|
||||||
verify(mConnectivityManager, atLeastOnce()).isTetheringSupported();
|
assertTrue(1 <= mTetheringDependencies.isTetheringSupportedCalls);
|
||||||
verifyNoMoreInteractions(mConnectivityManager);
|
|
||||||
|
|
||||||
/////
|
/////
|
||||||
// We do not currently emulate any upstream being found.
|
// We do not currently emulate any upstream being found.
|
||||||
@@ -723,7 +725,6 @@ public class TetheringTest {
|
|||||||
mLooper.dispatchAll();
|
mLooper.dispatchAll();
|
||||||
verify(mWifiManager, times(1)).stopSoftAp();
|
verify(mWifiManager, times(1)).stopSoftAp();
|
||||||
verifyNoMoreInteractions(mWifiManager);
|
verifyNoMoreInteractions(mWifiManager);
|
||||||
verifyNoMoreInteractions(mConnectivityManager);
|
|
||||||
verifyNoMoreInteractions(mNMService);
|
verifyNoMoreInteractions(mNMService);
|
||||||
|
|
||||||
// Emulate externally-visible WifiManager effects, when tethering mode
|
// Emulate externally-visible WifiManager effects, when tethering mode
|
||||||
@@ -743,14 +744,12 @@ public class TetheringTest {
|
|||||||
verifyNoMoreInteractions(mWifiManager);
|
verifyNoMoreInteractions(mWifiManager);
|
||||||
// Asking for the last error after the per-interface state machine
|
// Asking for the last error after the per-interface state machine
|
||||||
// has been reaped yields an unknown interface error.
|
// has been reaped yields an unknown interface error.
|
||||||
assertEquals(ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE,
|
assertEquals(TETHER_ERROR_UNKNOWN_IFACE, mTethering.getLastTetherError(TEST_WLAN_IFNAME));
|
||||||
mTethering.getLastTetherError(TEST_WLAN_IFNAME));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Test with and without interfaceStatusChanged().
|
// TODO: Test with and without interfaceStatusChanged().
|
||||||
@Test
|
@Test
|
||||||
public void failureEnablingIpForwarding() throws Exception {
|
public void failureEnablingIpForwarding() throws Exception {
|
||||||
when(mConnectivityManager.isTetheringSupported()).thenReturn(true);
|
|
||||||
when(mWifiManager.startSoftAp(any(WifiConfiguration.class))).thenReturn(true);
|
when(mWifiManager.startSoftAp(any(WifiConfiguration.class))).thenReturn(true);
|
||||||
doThrow(new RemoteException()).when(mNMService).setIpForwardingEnabled(true);
|
doThrow(new RemoteException()).when(mNMService).setIpForwardingEnabled(true);
|
||||||
|
|
||||||
@@ -759,7 +758,6 @@ public class TetheringTest {
|
|||||||
mLooper.dispatchAll();
|
mLooper.dispatchAll();
|
||||||
verify(mWifiManager, times(1)).startSoftAp(null);
|
verify(mWifiManager, times(1)).startSoftAp(null);
|
||||||
verifyNoMoreInteractions(mWifiManager);
|
verifyNoMoreInteractions(mWifiManager);
|
||||||
verifyNoMoreInteractions(mConnectivityManager);
|
|
||||||
verifyNoMoreInteractions(mNMService);
|
verifyNoMoreInteractions(mNMService);
|
||||||
|
|
||||||
// Emulate externally-visible WifiManager effects, causing the
|
// Emulate externally-visible WifiManager effects, causing the
|
||||||
@@ -778,8 +776,9 @@ public class TetheringTest {
|
|||||||
verify(mNMService, times(1)).tetherInterface(TEST_WLAN_IFNAME);
|
verify(mNMService, times(1)).tetherInterface(TEST_WLAN_IFNAME);
|
||||||
verify(mWifiManager).updateInterfaceIpState(
|
verify(mWifiManager).updateInterfaceIpState(
|
||||||
TEST_WLAN_IFNAME, WifiManager.IFACE_IP_MODE_TETHERED);
|
TEST_WLAN_IFNAME, WifiManager.IFACE_IP_MODE_TETHERED);
|
||||||
verify(mConnectivityManager, atLeastOnce()).isTetheringSupported();
|
// TODO: Figure out why this isn't exactly once, for sendTetherStateChangedBroadcast().
|
||||||
verifyTetheringBroadcast(TEST_WLAN_IFNAME, ConnectivityManager.EXTRA_AVAILABLE_TETHER);
|
assertTrue(1 <= mTetheringDependencies.isTetheringSupportedCalls);
|
||||||
|
verifyTetheringBroadcast(TEST_WLAN_IFNAME, EXTRA_AVAILABLE_TETHER);
|
||||||
// This is called, but will throw.
|
// This is called, but will throw.
|
||||||
verify(mNMService, times(1)).setIpForwardingEnabled(true);
|
verify(mNMService, times(1)).setIpForwardingEnabled(true);
|
||||||
// This never gets called because of the exception thrown above.
|
// This never gets called because of the exception thrown above.
|
||||||
@@ -792,7 +791,6 @@ public class TetheringTest {
|
|||||||
TEST_WLAN_IFNAME, WifiManager.IFACE_IP_MODE_CONFIGURATION_ERROR);
|
TEST_WLAN_IFNAME, WifiManager.IFACE_IP_MODE_CONFIGURATION_ERROR);
|
||||||
|
|
||||||
verifyNoMoreInteractions(mWifiManager);
|
verifyNoMoreInteractions(mWifiManager);
|
||||||
verifyNoMoreInteractions(mConnectivityManager);
|
|
||||||
verifyNoMoreInteractions(mNMService);
|
verifyNoMoreInteractions(mNMService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user