Loading services/core/java/com/android/server/ConnectivityService.java +1 −2 Original line number Diff line number Diff line Loading @@ -3090,8 +3090,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); Loading services/core/java/com/android/server/connectivity/Tethering.java +44 −51 Original line number Diff line number Diff line Loading @@ -78,8 +78,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; Loading @@ -103,8 +103,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; Loading @@ -116,48 +115,43 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering private static final SparseArray<String> sMagicDecoderRing = MessageUtils.findMessageNames(messageClasses); private volatile TetheringConfiguration mConfig; // used to synchronize public access to members private final Object mPublicSync; private final INetworkManagementService mNMService; private final INetworkStatsService mStatsService; private final INetworkPolicyManager mPolicyManager; private final Looper mLooper; private final MockableSystemProperties mSystemProperties; // {@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 mStateMachine; public int mLastState; public int mLastError; public final TetherInterfaceStateMachine stateMachine; public int lastState; public int lastError; public TetherState(TetherInterfaceStateMachine sm) { mStateMachine = sm; stateMachine = sm; // Assume all state machines start out available and with no errors. mLastState = IControlsTethering.STATE_AVAILABLE; mLastError = ConnectivityManager.TETHER_ERROR_NO_ERROR; lastState = IControlsTethering.STATE_AVAILABLE; lastError = ConnectivityManager.TETHER_ERROR_NO_ERROR; } } private final ArrayMap<String, TetherState> mTetherStates; // 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; // {@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 INetworkManagementService mNMService; private final INetworkStatsService mStatsService; private final INetworkPolicyManager mPolicyManager; private final Looper mLooper; private final MockableSystemProperties mSystemProperties; 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; Loading Loading @@ -228,7 +222,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 { Loading Loading @@ -290,13 +284,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; Loading Loading @@ -528,11 +521,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; } } Loading @@ -545,11 +538,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; } Loading @@ -569,7 +562,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering ", ignoring"); return ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE; } return tetherState.mLastError; return tetherState.lastError; } } Loading @@ -590,11 +583,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)) { Loading Loading @@ -768,7 +761,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); Loading Loading @@ -883,7 +876,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)); } } Loading @@ -896,7 +889,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)); } } Loading @@ -913,7 +906,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)); } } Loading Loading @@ -1315,7 +1308,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); Loading Loading @@ -1603,7 +1596,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; Loading @@ -1617,7 +1610,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering pw.print("UnknownState"); break; } pw.println(" - lastError = " + tetherState.mLastError); pw.println(" - lastError = " + tetherState.lastError); } pw.decreaseIndent(); } Loading @@ -1629,9 +1622,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); } Loading Loading @@ -1675,7 +1668,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) { Loading Loading
services/core/java/com/android/server/ConnectivityService.java +1 −2 Original line number Diff line number Diff line Loading @@ -3090,8 +3090,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); Loading
services/core/java/com/android/server/connectivity/Tethering.java +44 −51 Original line number Diff line number Diff line Loading @@ -78,8 +78,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; Loading @@ -103,8 +103,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; Loading @@ -116,48 +115,43 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering private static final SparseArray<String> sMagicDecoderRing = MessageUtils.findMessageNames(messageClasses); private volatile TetheringConfiguration mConfig; // used to synchronize public access to members private final Object mPublicSync; private final INetworkManagementService mNMService; private final INetworkStatsService mStatsService; private final INetworkPolicyManager mPolicyManager; private final Looper mLooper; private final MockableSystemProperties mSystemProperties; // {@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 mStateMachine; public int mLastState; public int mLastError; public final TetherInterfaceStateMachine stateMachine; public int lastState; public int lastError; public TetherState(TetherInterfaceStateMachine sm) { mStateMachine = sm; stateMachine = sm; // Assume all state machines start out available and with no errors. mLastState = IControlsTethering.STATE_AVAILABLE; mLastError = ConnectivityManager.TETHER_ERROR_NO_ERROR; lastState = IControlsTethering.STATE_AVAILABLE; lastError = ConnectivityManager.TETHER_ERROR_NO_ERROR; } } private final ArrayMap<String, TetherState> mTetherStates; // 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; // {@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 INetworkManagementService mNMService; private final INetworkStatsService mStatsService; private final INetworkPolicyManager mPolicyManager; private final Looper mLooper; private final MockableSystemProperties mSystemProperties; 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; Loading Loading @@ -228,7 +222,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 { Loading Loading @@ -290,13 +284,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; Loading Loading @@ -528,11 +521,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; } } Loading @@ -545,11 +538,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; } Loading @@ -569,7 +562,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering ", ignoring"); return ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE; } return tetherState.mLastError; return tetherState.lastError; } } Loading @@ -590,11 +583,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)) { Loading Loading @@ -768,7 +761,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); Loading Loading @@ -883,7 +876,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)); } } Loading @@ -896,7 +889,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)); } } Loading @@ -913,7 +906,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)); } } Loading Loading @@ -1315,7 +1308,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); Loading Loading @@ -1603,7 +1596,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; Loading @@ -1617,7 +1610,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering pw.print("UnknownState"); break; } pw.println(" - lastError = " + tetherState.mLastError); pw.println(" - lastError = " + tetherState.lastError); } pw.decreaseIndent(); } Loading @@ -1629,9 +1622,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); } Loading Loading @@ -1675,7 +1668,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) { Loading