[Tether13] Move TetheringManager into framework
Move tethering out of ConnectivityService. All client would
use TetheringManager to talk with TetheringService directly.
Bug: 144320246
Test: -build, flash, boot
-atest TetheringTests
Change-Id: Ib051bea724a256f9c4572b566e46ae7b9c4abe6e
This commit is contained in:
@@ -50,6 +50,7 @@ import android.os.RemoteException;
|
||||
import android.os.ResultReceiver;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.ServiceSpecificException;
|
||||
import android.os.SystemClock;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
@@ -57,7 +58,6 @@ import android.util.ArrayMap;
|
||||
import android.util.Log;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.internal.util.Preconditions;
|
||||
import com.android.internal.util.Protocol;
|
||||
|
||||
@@ -802,6 +802,7 @@ public class ConnectivityManager {
|
||||
|
||||
private INetworkManagementService mNMService;
|
||||
private INetworkPolicyManager mNPManager;
|
||||
private TetheringManager mTetheringManager;
|
||||
|
||||
/**
|
||||
* Tests if a given integer represents a valid network type.
|
||||
@@ -2339,6 +2340,28 @@ public class ConnectivityManager {
|
||||
return getInstanceOrNull();
|
||||
}
|
||||
|
||||
private static final int TETHERING_TIMEOUT_MS = 60_000;
|
||||
private final Object mTetheringLock = new Object();
|
||||
|
||||
private TetheringManager getTetheringManager() {
|
||||
synchronized (mTetheringLock) {
|
||||
if (mTetheringManager != null) {
|
||||
return mTetheringManager;
|
||||
}
|
||||
final long before = System.currentTimeMillis();
|
||||
while ((mTetheringManager = (TetheringManager) mContext.getSystemService(
|
||||
Context.TETHERING_SERVICE)) == null) {
|
||||
if (System.currentTimeMillis() - before > TETHERING_TIMEOUT_MS) {
|
||||
Log.e(TAG, "Timeout waiting tethering service not ready yet");
|
||||
throw new IllegalStateException("No tethering service yet");
|
||||
}
|
||||
SystemClock.sleep(100);
|
||||
}
|
||||
|
||||
return mTetheringManager;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the set of tetherable, available interfaces. This list is limited by
|
||||
* device configuration and current interface existence.
|
||||
@@ -2350,11 +2373,7 @@ public class ConnectivityManager {
|
||||
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
||||
@UnsupportedAppUsage
|
||||
public String[] getTetherableIfaces() {
|
||||
try {
|
||||
return mService.getTetherableIfaces();
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
return getTetheringManager().getTetherableIfaces();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2367,11 +2386,7 @@ public class ConnectivityManager {
|
||||
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
||||
@UnsupportedAppUsage
|
||||
public String[] getTetheredIfaces() {
|
||||
try {
|
||||
return mService.getTetheredIfaces();
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
return getTetheringManager().getTetheredIfaces();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2390,11 +2405,7 @@ public class ConnectivityManager {
|
||||
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
||||
@UnsupportedAppUsage
|
||||
public String[] getTetheringErroredIfaces() {
|
||||
try {
|
||||
return mService.getTetheringErroredIfaces();
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
return getTetheringManager().getTetheringErroredIfaces();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2405,11 +2416,7 @@ public class ConnectivityManager {
|
||||
*/
|
||||
@RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS)
|
||||
public String[] getTetheredDhcpRanges() {
|
||||
try {
|
||||
return mService.getTetheredDhcpRanges();
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
return getTetheringManager().getTetheredDhcpRanges();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2438,13 +2445,7 @@ public class ConnectivityManager {
|
||||
*/
|
||||
@UnsupportedAppUsage
|
||||
public int tether(String iface) {
|
||||
try {
|
||||
String pkgName = mContext.getOpPackageName();
|
||||
Log.i(TAG, "tether caller:" + pkgName);
|
||||
return mService.tether(iface, pkgName);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
return getTetheringManager().tether(iface);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2467,13 +2468,7 @@ public class ConnectivityManager {
|
||||
*/
|
||||
@UnsupportedAppUsage
|
||||
public int untether(String iface) {
|
||||
try {
|
||||
String pkgName = mContext.getOpPackageName();
|
||||
Log.i(TAG, "untether caller:" + pkgName);
|
||||
return mService.untether(iface, pkgName);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
return getTetheringManager().untether(iface);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2498,16 +2493,7 @@ public class ConnectivityManager {
|
||||
@RequiresPermission(anyOf = {android.Manifest.permission.TETHER_PRIVILEGED,
|
||||
android.Manifest.permission.WRITE_SETTINGS})
|
||||
public boolean isTetheringSupported() {
|
||||
String pkgName = mContext.getOpPackageName();
|
||||
try {
|
||||
return mService.isTetheringSupported(pkgName);
|
||||
} catch (SecurityException e) {
|
||||
// This API is not available to this caller, but for backward-compatibility
|
||||
// this will just return false instead of throwing.
|
||||
return false;
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
return getTetheringManager().isTetheringSupported();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2576,14 +2562,7 @@ public class ConnectivityManager {
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
String pkgName = mContext.getOpPackageName();
|
||||
Log.i(TAG, "startTethering caller:" + pkgName);
|
||||
mService.startTethering(type, wrappedCallback, showProvisioningUi, pkgName);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Exception trying to start tethering.", e);
|
||||
wrappedCallback.send(TETHER_ERROR_SERVICE_UNAVAIL, null);
|
||||
}
|
||||
getTetheringManager().startTethering(type, wrappedCallback, showProvisioningUi);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2599,13 +2578,7 @@ public class ConnectivityManager {
|
||||
@SystemApi
|
||||
@RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)
|
||||
public void stopTethering(int type) {
|
||||
try {
|
||||
String pkgName = mContext.getOpPackageName();
|
||||
Log.i(TAG, "stopTethering caller:" + pkgName);
|
||||
mService.stopTethering(type, pkgName);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
getTetheringManager().stopTethering(type);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2627,10 +2600,6 @@ public class ConnectivityManager {
|
||||
public void onUpstreamChanged(@Nullable Network network) {}
|
||||
}
|
||||
|
||||
@GuardedBy("mTetheringEventCallbacks")
|
||||
private final ArrayMap<OnTetheringEventCallback, ITetheringEventCallback>
|
||||
mTetheringEventCallbacks = new ArrayMap<>();
|
||||
|
||||
/**
|
||||
* Start listening to tethering change events. Any new added callback will receive the last
|
||||
* tethering status right away. If callback is registered when tethering has no upstream or
|
||||
@@ -2648,27 +2617,7 @@ public class ConnectivityManager {
|
||||
@NonNull final OnTetheringEventCallback callback) {
|
||||
Preconditions.checkNotNull(callback, "OnTetheringEventCallback cannot be null.");
|
||||
|
||||
synchronized (mTetheringEventCallbacks) {
|
||||
Preconditions.checkArgument(!mTetheringEventCallbacks.containsKey(callback),
|
||||
"callback was already registered.");
|
||||
ITetheringEventCallback remoteCallback = new ITetheringEventCallback.Stub() {
|
||||
@Override
|
||||
public void onUpstreamChanged(Network network) throws RemoteException {
|
||||
Binder.withCleanCallingIdentity(() ->
|
||||
executor.execute(() -> {
|
||||
callback.onUpstreamChanged(network);
|
||||
}));
|
||||
}
|
||||
};
|
||||
try {
|
||||
String pkgName = mContext.getOpPackageName();
|
||||
Log.i(TAG, "registerTetheringUpstreamCallback:" + pkgName);
|
||||
mService.registerTetheringEventCallback(remoteCallback, pkgName);
|
||||
mTetheringEventCallbacks.put(callback, remoteCallback);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
getTetheringManager().registerTetheringEventCallback(executor, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2682,17 +2631,7 @@ public class ConnectivityManager {
|
||||
@RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)
|
||||
public void unregisterTetheringEventCallback(
|
||||
@NonNull final OnTetheringEventCallback callback) {
|
||||
synchronized (mTetheringEventCallbacks) {
|
||||
ITetheringEventCallback remoteCallback = mTetheringEventCallbacks.remove(callback);
|
||||
Preconditions.checkNotNull(remoteCallback, "callback was not registered.");
|
||||
try {
|
||||
String pkgName = mContext.getOpPackageName();
|
||||
Log.i(TAG, "unregisterTetheringEventCallback:" + pkgName);
|
||||
mService.unregisterTetheringEventCallback(remoteCallback, pkgName);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
getTetheringManager().unregisterTetheringEventCallback(callback);
|
||||
}
|
||||
|
||||
|
||||
@@ -2709,11 +2648,7 @@ public class ConnectivityManager {
|
||||
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
||||
@UnsupportedAppUsage
|
||||
public String[] getTetherableUsbRegexs() {
|
||||
try {
|
||||
return mService.getTetherableUsbRegexs();
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
return getTetheringManager().getTetherableUsbRegexs();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2729,11 +2664,7 @@ public class ConnectivityManager {
|
||||
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
||||
@UnsupportedAppUsage
|
||||
public String[] getTetherableWifiRegexs() {
|
||||
try {
|
||||
return mService.getTetherableWifiRegexs();
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
return getTetheringManager().getTetherableWifiRegexs();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2749,11 +2680,7 @@ public class ConnectivityManager {
|
||||
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
||||
@UnsupportedAppUsage
|
||||
public String[] getTetherableBluetoothRegexs() {
|
||||
try {
|
||||
return mService.getTetherableBluetoothRegexs();
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
return getTetheringManager().getTetherableBluetoothRegexs();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2775,13 +2702,7 @@ public class ConnectivityManager {
|
||||
*/
|
||||
@UnsupportedAppUsage
|
||||
public int setUsbTethering(boolean enable) {
|
||||
try {
|
||||
String pkgName = mContext.getOpPackageName();
|
||||
Log.i(TAG, "setUsbTethering caller:" + pkgName);
|
||||
return mService.setUsbTethering(enable, pkgName);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
return getTetheringManager().setUsbTethering(enable);
|
||||
}
|
||||
|
||||
/** {@hide} */
|
||||
@@ -2829,11 +2750,7 @@ public class ConnectivityManager {
|
||||
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
||||
@UnsupportedAppUsage
|
||||
public int getLastTetherError(String iface) {
|
||||
try {
|
||||
return mService.getLastTetherError(iface);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
return getTetheringManager().getLastTetherError(iface);
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
@@ -2899,14 +2816,8 @@ public class ConnectivityManager {
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
String pkgName = mContext.getOpPackageName();
|
||||
Log.i(TAG, "getLatestTetheringEntitlementResult:" + pkgName);
|
||||
mService.getLatestTetheringEntitlementResult(type, wrappedListener,
|
||||
showEntitlementUi, pkgName);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
getTetheringManager().requestLatestTetheringEntitlementResult(type, wrappedListener,
|
||||
showEntitlementUi);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -4331,6 +4242,7 @@ public class ConnectivityManager {
|
||||
public void factoryReset() {
|
||||
try {
|
||||
mService.factoryReset();
|
||||
getTetheringManager().stopAllTethering();
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package android.net;
|
||||
import android.app.PendingIntent;
|
||||
import android.net.ConnectionInfo;
|
||||
import android.net.LinkProperties;
|
||||
import android.net.ITetheringEventCallback;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkInfo;
|
||||
@@ -78,41 +77,31 @@ interface IConnectivityManager
|
||||
|
||||
boolean requestRouteToHostAddress(int networkType, in byte[] hostAddress);
|
||||
|
||||
int tether(String iface, String callerPkg);
|
||||
|
||||
int untether(String iface, String callerPkg);
|
||||
|
||||
@UnsupportedAppUsage
|
||||
@UnsupportedAppUsage(maxTargetSdk = 29,
|
||||
publicAlternatives = "Use {@code TetheringManager#getLastTetherError} as alternative")
|
||||
int getLastTetherError(String iface);
|
||||
|
||||
boolean isTetheringSupported(String callerPkg);
|
||||
|
||||
void startTethering(int type, in ResultReceiver receiver, boolean showProvisioningUi,
|
||||
String callerPkg);
|
||||
|
||||
void stopTethering(int type, String callerPkg);
|
||||
|
||||
@UnsupportedAppUsage
|
||||
@UnsupportedAppUsage(maxTargetSdk = 29,
|
||||
publicAlternatives = "Use {@code TetheringManager#getTetherableIfaces} as alternative")
|
||||
String[] getTetherableIfaces();
|
||||
|
||||
@UnsupportedAppUsage
|
||||
@UnsupportedAppUsage(maxTargetSdk = 29,
|
||||
publicAlternatives = "Use {@code TetheringManager#getTetheredIfaces} as alternative")
|
||||
String[] getTetheredIfaces();
|
||||
|
||||
@UnsupportedAppUsage
|
||||
@UnsupportedAppUsage(maxTargetSdk = 29,
|
||||
publicAlternatives = "Use {@code TetheringManager#getTetheringErroredIfaces} "
|
||||
+ "as Alternative")
|
||||
String[] getTetheringErroredIfaces();
|
||||
|
||||
String[] getTetheredDhcpRanges();
|
||||
|
||||
@UnsupportedAppUsage
|
||||
@UnsupportedAppUsage(maxTargetSdk = 29,
|
||||
publicAlternatives = "Use {@code TetheringManager#getTetherableUsbRegexs} as alternative")
|
||||
String[] getTetherableUsbRegexs();
|
||||
|
||||
@UnsupportedAppUsage
|
||||
@UnsupportedAppUsage(maxTargetSdk = 29,
|
||||
publicAlternatives = "Use {@code TetheringManager#getTetherableWifiRegexs} as alternative")
|
||||
String[] getTetherableWifiRegexs();
|
||||
|
||||
String[] getTetherableBluetoothRegexs();
|
||||
|
||||
int setUsbTethering(boolean enable, String callerPkg);
|
||||
|
||||
@UnsupportedAppUsage(maxTargetSdk = 28)
|
||||
void reportInetCondition(int networkType, int percentage);
|
||||
|
||||
@@ -217,11 +206,5 @@ interface IConnectivityManager
|
||||
boolean isCallerCurrentAlwaysOnVpnApp();
|
||||
boolean isCallerCurrentAlwaysOnVpnLockdownApp();
|
||||
|
||||
void getLatestTetheringEntitlementResult(int type, in ResultReceiver receiver,
|
||||
boolean showEntitlementUi, String callerPkg);
|
||||
|
||||
void registerTetheringEventCallback(ITetheringEventCallback callback, String callerPkg);
|
||||
void unregisterTetheringEventCallback(ITetheringEventCallback callback, String callerPkg);
|
||||
|
||||
IBinder startOrGetTestNetworkService();
|
||||
}
|
||||
|
||||
@@ -77,7 +77,6 @@ import android.net.INetworkPolicyListener;
|
||||
import android.net.INetworkPolicyManager;
|
||||
import android.net.INetworkStatsService;
|
||||
import android.net.ISocketKeepaliveCallback;
|
||||
import android.net.ITetheringEventCallback;
|
||||
import android.net.InetAddresses;
|
||||
import android.net.IpMemoryStore;
|
||||
import android.net.IpPrefix;
|
||||
@@ -278,8 +277,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
|
||||
private MockableSystemProperties mSystemProperties;
|
||||
|
||||
private TetheringManager mTetheringManager;
|
||||
|
||||
@VisibleForTesting
|
||||
protected final PermissionMonitor mPermissionMonitor;
|
||||
|
||||
@@ -866,13 +863,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
return NetworkStackClient.getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a reference to the TetheringManager.
|
||||
*/
|
||||
public TetheringManager getTetheringManager() {
|
||||
return TetheringManager.getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ProxyTracker
|
||||
*/
|
||||
@@ -1072,8 +1062,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
|
||||
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
|
||||
mTetheringManager = mDeps.getTetheringManager();
|
||||
|
||||
mPermissionMonitor = new PermissionMonitor(mContext, mNetd);
|
||||
|
||||
// Set up the listener for user state for creating user VPNs.
|
||||
@@ -1887,14 +1875,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
}
|
||||
mHandler.sendMessage(mHandler.obtainMessage(
|
||||
EVENT_DATA_SAVER_CHANGED, restrictBackground ? 1 : 0, 0));
|
||||
|
||||
// TODO: relocate this specific callback in Tethering.
|
||||
if (restrictBackground) {
|
||||
log("onRestrictBackgroundChanged(true): disabling tethering");
|
||||
mTetheringManager.stopTethering(ConnectivityManager.TETHERING_WIFI);
|
||||
mTetheringManager.stopTethering(ConnectivityManager.TETHERING_USB);
|
||||
mTetheringManager.stopTethering(ConnectivityManager.TETHERING_BLUETOOTH);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2024,12 +2004,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, pid, uid);
|
||||
}
|
||||
|
||||
private void enforceTetherAccessPermission() {
|
||||
mContext.enforceCallingOrSelfPermission(
|
||||
android.Manifest.permission.ACCESS_NETWORK_STATE,
|
||||
"ConnectivityService");
|
||||
}
|
||||
|
||||
private void enforceControlAlwaysOnVpnPermission() {
|
||||
mContext.enforceCallingOrSelfPermission(
|
||||
android.Manifest.permission.CONTROL_ALWAYS_ON_VPN,
|
||||
@@ -2462,12 +2436,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
pw.println();
|
||||
mKeepaliveTracker.dump(pw);
|
||||
|
||||
pw.println();
|
||||
pw.println("TetheringManager logs:");
|
||||
pw.increaseIndent();
|
||||
TetheringManager.getInstance().dump(pw);
|
||||
pw.decreaseIndent();
|
||||
|
||||
pw.println();
|
||||
dumpAvoidBadWifiSettings(pw);
|
||||
|
||||
@@ -3993,183 +3961,55 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
}
|
||||
}
|
||||
|
||||
// javadoc from interface
|
||||
@Override
|
||||
public int tether(String iface, String callerPkg) {
|
||||
ConnectivityManager.enforceTetherChangePermission(mContext, callerPkg);
|
||||
if (isTetheringSupported()) {
|
||||
return mTetheringManager.tether(iface);
|
||||
} else {
|
||||
return ConnectivityManager.TETHER_ERROR_UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
// javadoc from interface
|
||||
@Override
|
||||
public int untether(String iface, String callerPkg) {
|
||||
ConnectivityManager.enforceTetherChangePermission(mContext, callerPkg);
|
||||
|
||||
if (isTetheringSupported()) {
|
||||
return mTetheringManager.untether(iface);
|
||||
} else {
|
||||
return ConnectivityManager.TETHER_ERROR_UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
// javadoc from interface
|
||||
@Override
|
||||
@Deprecated
|
||||
public int getLastTetherError(String iface) {
|
||||
enforceTetherAccessPermission();
|
||||
|
||||
if (isTetheringSupported()) {
|
||||
return mTetheringManager.getLastTetherError(iface);
|
||||
} else {
|
||||
return ConnectivityManager.TETHER_ERROR_UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO - proper iface API for selection by property, inspection, etc
|
||||
@Override
|
||||
public String[] getTetherableUsbRegexs() {
|
||||
enforceTetherAccessPermission();
|
||||
if (isTetheringSupported()) {
|
||||
return mTetheringManager.getTetherableUsbRegexs();
|
||||
} else {
|
||||
return new String[0];
|
||||
}
|
||||
final TetheringManager tm = (TetheringManager) mContext.getSystemService(
|
||||
Context.TETHERING_SERVICE);
|
||||
return tm.getLastTetherError(iface);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getTetherableWifiRegexs() {
|
||||
enforceTetherAccessPermission();
|
||||
if (isTetheringSupported()) {
|
||||
return mTetheringManager.getTetherableWifiRegexs();
|
||||
} else {
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getTetherableBluetoothRegexs() {
|
||||
enforceTetherAccessPermission();
|
||||
if (isTetheringSupported()) {
|
||||
return mTetheringManager.getTetherableBluetoothRegexs();
|
||||
} else {
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int setUsbTethering(boolean enable, String callerPkg) {
|
||||
ConnectivityManager.enforceTetherChangePermission(mContext, callerPkg);
|
||||
if (isTetheringSupported()) {
|
||||
return mTetheringManager.setUsbTethering(enable);
|
||||
} else {
|
||||
return ConnectivityManager.TETHER_ERROR_UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO - move iface listing, queries, etc to new module
|
||||
// javadoc from interface
|
||||
@Override
|
||||
@Deprecated
|
||||
public String[] getTetherableIfaces() {
|
||||
enforceTetherAccessPermission();
|
||||
return mTetheringManager.getTetherableIfaces();
|
||||
final TetheringManager tm = (TetheringManager) mContext.getSystemService(
|
||||
Context.TETHERING_SERVICE);
|
||||
return tm.getTetherableIfaces();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String[] getTetheredIfaces() {
|
||||
enforceTetherAccessPermission();
|
||||
return mTetheringManager.getTetheredIfaces();
|
||||
final TetheringManager tm = (TetheringManager) mContext.getSystemService(
|
||||
Context.TETHERING_SERVICE);
|
||||
return tm.getTetheredIfaces();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String[] getTetheringErroredIfaces() {
|
||||
enforceTetherAccessPermission();
|
||||
return mTetheringManager.getTetheringErroredIfaces();
|
||||
final TetheringManager tm = (TetheringManager) mContext.getSystemService(
|
||||
Context.TETHERING_SERVICE);
|
||||
|
||||
return tm.getTetheringErroredIfaces();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getTetheredDhcpRanges() {
|
||||
enforceSettingsPermission();
|
||||
return mTetheringManager.getTetheredDhcpRanges();
|
||||
@Deprecated
|
||||
public String[] getTetherableUsbRegexs() {
|
||||
final TetheringManager tm = (TetheringManager) mContext.getSystemService(
|
||||
Context.TETHERING_SERVICE);
|
||||
|
||||
return tm.getTetherableUsbRegexs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTetheringSupported(String callerPkg) {
|
||||
ConnectivityManager.enforceTetherChangePermission(mContext, callerPkg);
|
||||
return isTetheringSupported();
|
||||
}
|
||||
|
||||
// if ro.tether.denied = true we default to no tethering
|
||||
// gservices could set the secure setting to 1 though to enable it on a build where it
|
||||
// had previously been turned off.
|
||||
private boolean isTetheringSupported() {
|
||||
int defaultVal = encodeBool(!mSystemProperties.get("ro.tether.denied").equals("true"));
|
||||
boolean tetherSupported = toBool(Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.TETHER_SUPPORTED, defaultVal));
|
||||
boolean tetherEnabledInSettings = tetherSupported
|
||||
&& !mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING);
|
||||
|
||||
// Elevate to system UID to avoid caller requiring MANAGE_USERS permission.
|
||||
boolean adminUser = false;
|
||||
final long token = Binder.clearCallingIdentity();
|
||||
try {
|
||||
adminUser = mUserManager.isAdminUser();
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(token);
|
||||
}
|
||||
|
||||
return tetherEnabledInSettings && adminUser
|
||||
&& mTetheringManager.hasTetherableConfiguration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startTethering(int type, ResultReceiver receiver, boolean showProvisioningUi,
|
||||
String callerPkg) {
|
||||
ConnectivityManager.enforceTetherChangePermission(mContext, callerPkg);
|
||||
if (!isTetheringSupported()) {
|
||||
receiver.send(ConnectivityManager.TETHER_ERROR_UNSUPPORTED, null);
|
||||
return;
|
||||
}
|
||||
mTetheringManager.startTethering(type, receiver, showProvisioningUi);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopTethering(int type, String callerPkg) {
|
||||
ConnectivityManager.enforceTetherChangePermission(mContext, callerPkg);
|
||||
mTetheringManager.stopTethering(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the latest value of the tethering entitlement check.
|
||||
*
|
||||
* Note: Allow privileged apps who have TETHER_PRIVILEGED permission to access. If it turns
|
||||
* out some such apps are observed to abuse this API, change to per-UID limits on this API
|
||||
* if it's really needed.
|
||||
*/
|
||||
@Override
|
||||
public void getLatestTetheringEntitlementResult(int type, ResultReceiver receiver,
|
||||
boolean showEntitlementUi, String callerPkg) {
|
||||
ConnectivityManager.enforceTetherChangePermission(mContext, callerPkg);
|
||||
mTetheringManager.requestLatestTetheringEntitlementResult(
|
||||
type, receiver, showEntitlementUi);
|
||||
}
|
||||
|
||||
/** Register tethering event callback. */
|
||||
@Override
|
||||
public void registerTetheringEventCallback(ITetheringEventCallback callback,
|
||||
String callerPkg) {
|
||||
ConnectivityManager.enforceTetherChangePermission(mContext, callerPkg);
|
||||
mTetheringManager.registerTetheringEventCallback(callback);
|
||||
}
|
||||
|
||||
/** Unregister tethering event callback. */
|
||||
@Override
|
||||
public void unregisterTetheringEventCallback(ITetheringEventCallback callback,
|
||||
String callerPkg) {
|
||||
ConnectivityManager.enforceTetherChangePermission(mContext, callerPkg);
|
||||
mTetheringManager.unregisterTetheringEventCallback(callback);
|
||||
@Deprecated
|
||||
public String[] getTetherableWifiRegexs() {
|
||||
final TetheringManager tm = (TetheringManager) mContext.getSystemService(
|
||||
Context.TETHERING_SERVICE);
|
||||
return tm.getTetherableWifiRegexs();
|
||||
}
|
||||
|
||||
// Called when we lose the default network and have no replacement yet.
|
||||
@@ -7050,14 +6890,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
// Turn airplane mode off
|
||||
setAirplaneMode(false);
|
||||
|
||||
if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) {
|
||||
// Untether
|
||||
String pkgName = mContext.getOpPackageName();
|
||||
for (String tether : getTetheredIfaces()) {
|
||||
untether(tether, pkgName);
|
||||
}
|
||||
}
|
||||
|
||||
if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN)) {
|
||||
// Remove always-on package
|
||||
synchronized (mVpns) {
|
||||
|
||||
@@ -32,7 +32,6 @@ import android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET
|
||||
import android.net.NetworkCapabilities.TRANSPORT_CELLULAR
|
||||
import android.net.NetworkRequest
|
||||
import android.net.TestNetworkStackClient
|
||||
import android.net.TetheringManager
|
||||
import android.net.metrics.IpConnectivityLog
|
||||
import android.os.ConditionVariable
|
||||
import android.os.IBinder
|
||||
@@ -169,7 +168,6 @@ class ConnectivityServiceIntegrationTest {
|
||||
val deps = spy(ConnectivityService.Dependencies())
|
||||
doReturn(networkStackClient).`when`(deps).networkStack
|
||||
doReturn(metricsLogger).`when`(deps).metricsLogger
|
||||
doReturn(mock(TetheringManager::class.java)).`when`(deps).getTetheringManager()
|
||||
doReturn(mock(ProxyTracker::class.java)).`when`(deps).makeProxyTracker(any(), any())
|
||||
doReturn(mock(MockableSystemProperties::class.java)).`when`(deps).systemProperties
|
||||
doReturn(TestNetIdManager()).`when`(deps).makeNetIdManager()
|
||||
|
||||
@@ -164,7 +164,6 @@ import android.net.ProxyInfo;
|
||||
import android.net.ResolverParamsParcel;
|
||||
import android.net.RouteInfo;
|
||||
import android.net.SocketKeepalive;
|
||||
import android.net.TetheringManager;
|
||||
import android.net.UidRange;
|
||||
import android.net.metrics.IpConnectivityLog;
|
||||
import android.net.shared.NetworkMonitorUtils;
|
||||
@@ -1133,7 +1132,6 @@ public class ConnectivityServiceTest {
|
||||
doReturn(new TestNetIdManager()).when(deps).makeNetIdManager();
|
||||
doReturn(mNetworkStack).when(deps).getNetworkStack();
|
||||
doReturn(systemProperties).when(deps).getSystemProperties();
|
||||
doReturn(mock(TetheringManager.class)).when(deps).getTetheringManager();
|
||||
doReturn(mock(ProxyTracker.class)).when(deps).makeProxyTracker(any(), any());
|
||||
doReturn(mMetricsService).when(deps).getMetricsLogger();
|
||||
doReturn(true).when(deps).queryUserAccess(anyInt(), anyInt());
|
||||
|
||||
Reference in New Issue
Block a user