diff options
| author | Mark Chien <markchien@google.com> | 2019-12-20 13:43:46 +0000 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-12-20 13:43:46 +0000 |
| commit | 2410d673574109275e8dda0fdb3bfb3cce304afd (patch) | |
| tree | 27ec54e84c90520daa86639086968b6f572c969e /core/java/android | |
| parent | ad2026640c03749ee20d867e362a773f9e8f6197 (diff) | |
| parent | 6d06f6d51a568b5578584cc91340dbc2f2b0e6ac (diff) | |
Merge "[Tether13] Move TetheringManager into framework"
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/app/SystemServiceRegistry.java | 12 | ||||
| -rw-r--r-- | core/java/android/content/Context.java | 9 | ||||
| -rw-r--r-- | core/java/android/net/ConnectivityManager.java | 174 | ||||
| -rw-r--r-- | core/java/android/net/IConnectivityManager.aidl | 43 | ||||
| -rw-r--r-- | core/java/android/net/ITetheringEventCallback.aidl | 28 | ||||
| -rw-r--r-- | core/java/android/provider/Settings.java | 54 |
6 files changed, 105 insertions, 215 deletions
diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java index c56e8d86bfa3..82df702eb7e5 100644 --- a/core/java/android/app/SystemServiceRegistry.java +++ b/core/java/android/app/SystemServiceRegistry.java @@ -111,6 +111,7 @@ import android.net.NetworkPolicyManager; import android.net.NetworkScoreManager; import android.net.NetworkWatchlistManager; import android.net.TestNetworkManager; +import android.net.TetheringManager; import android.net.lowpan.ILowpanManager; import android.net.lowpan.LowpanManager; import android.net.nsd.INsdManager; @@ -340,6 +341,17 @@ final class SystemServiceRegistry { } }); + registerService(Context.TETHERING_SERVICE, TetheringManager.class, + new CachedServiceFetcher<TetheringManager>() { + @Override + public TetheringManager createService(ContextImpl ctx) throws ServiceNotFoundException { + IBinder b = ServiceManager.getService(Context.TETHERING_SERVICE); + if (b == null) return null; + + return new TetheringManager(ctx, b); + }}); + + registerService(Context.IPSEC_SERVICE, IpSecManager.class, new CachedServiceFetcher<IpSecManager>() { @Override diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index 39a711524cf3..902c6b9dd36d 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -3858,6 +3858,15 @@ public abstract class Context { public static final String NETWORK_STACK_SERVICE = "network_stack"; /** + * Use with {@link android.os.ServiceManager.getService()} to retrieve a + * {@link ITetheringConnector} IBinder for communicating with the tethering service + * @hide + * @see TetheringClient + */ + @SystemApi + public static final String TETHERING_SERVICE = "tethering"; + + /** * Use with {@link #getSystemService(String)} to retrieve a * {@link android.net.IpSecManager} for encrypting Sockets or Networks with * IPSec. diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index a6e070e54e87..82cecb6f20ad 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -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. @@ -2340,6 +2341,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. @@ -2351,11 +2374,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(); } /** @@ -2368,11 +2387,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(); } /** @@ -2391,11 +2406,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(); } /** @@ -2406,11 +2417,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(); } /** @@ -2439,13 +2446,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); } /** @@ -2468,13 +2469,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); } /** @@ -2499,16 +2494,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(); } /** @@ -2577,14 +2563,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); } /** @@ -2600,13 +2579,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); } /** @@ -2628,10 +2601,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 @@ -2649,27 +2618,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); } /** @@ -2683,17 +2632,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); } @@ -2710,11 +2649,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(); } /** @@ -2730,11 +2665,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(); } /** @@ -2750,11 +2681,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(); } /** @@ -2776,13 +2703,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} */ @@ -2830,11 +2751,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 */ @@ -2900,14 +2817,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); } /** @@ -4332,6 +4243,7 @@ public class ConnectivityManager { public void factoryReset() { try { mService.factoryReset(); + getTetheringManager().stopAllTethering(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } diff --git a/core/java/android/net/IConnectivityManager.aidl b/core/java/android/net/IConnectivityManager.aidl index 5f662f914919..09c02efbcfc4 100644 --- a/core/java/android/net/IConnectivityManager.aidl +++ b/core/java/android/net/IConnectivityManager.aidl @@ -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(); } diff --git a/core/java/android/net/ITetheringEventCallback.aidl b/core/java/android/net/ITetheringEventCallback.aidl deleted file mode 100644 index d502088542a6..000000000000 --- a/core/java/android/net/ITetheringEventCallback.aidl +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net; - -import android.net.Network; - -/** - * Callback class for receiving tethering changed events - * @hide - */ -oneway interface ITetheringEventCallback -{ - void onUpstreamChanged(in Network network); -} diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index da4bd27995c6..e348b5f63a46 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -10402,35 +10402,37 @@ public final class Settings { */ public static final String SMS_SHORT_CODE_RULE = "sms_short_code_rule"; - /** - * Used to select TCP's default initial receiver window size in segments - defaults to a build config value - * @hide - */ - public static final String TCP_DEFAULT_INIT_RWND = "tcp_default_init_rwnd"; + /** + * Used to select TCP's default initial receiver window size in segments - defaults to a + * build config value. + * @hide + */ + public static final String TCP_DEFAULT_INIT_RWND = "tcp_default_init_rwnd"; - /** - * Used to disable Tethering on a device - defaults to true - * @hide - */ - public static final String TETHER_SUPPORTED = "tether_supported"; + /** + * Used to disable Tethering on a device - defaults to true. + * @hide + */ + @SystemApi + public static final String TETHER_SUPPORTED = "tether_supported"; - /** - * Used to require DUN APN on the device or not - defaults to a build config value - * which defaults to false - * @hide - */ - public static final String TETHER_DUN_REQUIRED = "tether_dun_required"; + /** + * Used to require DUN APN on the device or not - defaults to a build config value + * which defaults to false. + * @hide + */ + public static final String TETHER_DUN_REQUIRED = "tether_dun_required"; - /** - * Used to hold a gservices-provisioned apn value for DUN. If set, or the - * corresponding build config values are set it will override the APN DB - * values. - * Consists of a comma seperated list of strings: - * "name,apn,proxy,port,username,password,server,mmsc,mmsproxy,mmsport,mcc,mnc,auth,type" - * note that empty fields can be omitted: "name,apn,,,,,,,,,310,260,,DUN" - * @hide - */ - public static final String TETHER_DUN_APN = "tether_dun_apn"; + /** + * Used to hold a gservices-provisioned apn value for DUN. If set, or the + * corresponding build config values are set it will override the APN DB + * values. + * Consists of a comma separated list of strings: + * "name,apn,proxy,port,username,password,server,mmsc,mmsproxy,mmsport,mcc,mnc,auth,type" + * note that empty fields can be omitted: "name,apn,,,,,,,,,310,260,,DUN" + * @hide + */ + public static final String TETHER_DUN_APN = "tether_dun_apn"; /** * Used to disable trying to talk to any available tethering offload HAL. |
