Loading Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -225,6 +225,7 @@ java_defaults { "core/java/android/net/INetworkScoreService.aidl", "core/java/android/net/INetworkStatsService.aidl", "core/java/android/net/INetworkStatsSession.aidl", "core/java/android/net/ITetheringEventCallback.aidl", "core/java/android/net/ITetheringStatsProvider.aidl", "core/java/android/net/nsd/INsdManager.aidl", "core/java/android/nfc/IAppCallback.aidl", Loading api/system-current.txt +7 −0 Original line number Diff line number Diff line Loading @@ -4038,11 +4038,13 @@ package android.net { method @RequiresPermission(android.Manifest.permission.LOCAL_MAC_ADDRESS) public String getCaptivePortalServerUrl(); method @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void getLatestTetheringEntitlementResult(int, boolean, @NonNull java.util.concurrent.Executor, @NonNull android.net.ConnectivityManager.OnTetheringEntitlementResultListener); method @RequiresPermission(anyOf={android.Manifest.permission.TETHER_PRIVILEGED, android.Manifest.permission.WRITE_SETTINGS}) public boolean isTetheringSupported(); method @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void registerTetheringEventCallback(@NonNull java.util.concurrent.Executor, @NonNull android.net.ConnectivityManager.OnTetheringEventCallback); method @RequiresPermission(anyOf={"android.permission.NETWORK_SETTINGS", android.Manifest.permission.NETWORK_SETUP_WIZARD, "android.permission.NETWORK_STACK"}) public void setAirplaneMode(boolean); method @RequiresPermission(android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK) public void startCaptivePortalApp(android.net.Network, android.os.Bundle); method @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void startTethering(int, boolean, android.net.ConnectivityManager.OnStartTetheringCallback); method @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void startTethering(int, boolean, android.net.ConnectivityManager.OnStartTetheringCallback, android.os.Handler); method @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void stopTethering(int); method @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void unregisterTetheringEventCallback(@NonNull android.net.ConnectivityManager.OnTetheringEventCallback); field public static final String EXTRA_CAPTIVE_PORTAL_PROBE_SPEC = "android.net.extra.CAPTIVE_PORTAL_PROBE_SPEC"; field public static final String EXTRA_CAPTIVE_PORTAL_USER_AGENT = "android.net.extra.CAPTIVE_PORTAL_USER_AGENT"; field public static final int TETHERING_BLUETOOTH = 2; // 0x2 Loading @@ -4063,6 +4065,11 @@ package android.net { method public void onEntitlementResult(int); } public abstract static class ConnectivityManager.OnTetheringEventCallback { ctor public ConnectivityManager.OnTetheringEventCallback(); method public void onUpstreamChanged(@Nullable android.net.Network); } public final class IpPrefix implements android.os.Parcelable { ctor public IpPrefix(java.net.InetAddress, int); ctor public IpPrefix(String); Loading core/java/android/net/ConnectivityManager.java +89 −0 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ import android.util.ArrayMap; import android.util.Log; import android.util.SparseIntArray; import com.android.internal.annotations.GuardedBy; import com.android.internal.telephony.ITelephony; import com.android.internal.telephony.PhoneConstants; import com.android.internal.util.Preconditions; Loading Loading @@ -2541,6 +2542,94 @@ public class ConnectivityManager { } } /** * Callback for use with {@link registerTetheringEventCallback} to find out tethering * upstream status. * *@hide */ @SystemApi public abstract static class OnTetheringEventCallback { /** * Called when tethering upstream changed. This can be called multiple times and can be * called any time. * * @param network the {@link Network} of tethering upstream. Null means tethering doesn't * have any upstream. */ 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 loses its upstream or * disabled, {@link OnTetheringEventCallback#onUpstreamChanged} will immediately be called * with a null argument. The same callback object cannot be registered twice. * * @param executor the executor on which callback will be invoked. * @param callback the callback to be called when tethering has change events. * @hide */ @SystemApi @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void registerTetheringEventCallback( @NonNull @CallbackExecutor Executor executor, @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(); } } } /** * Remove tethering event callback previously registered with * {@link #registerTetheringEventCallback}. * * @param callback previously registered callback. * @hide */ @SystemApi @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(); } } } /** * Get the list of regular expressions that define any tetherable * USB network interfaces. If USB tethering is not supported by the Loading core/java/android/net/IConnectivityManager.aidl +4 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ 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; Loading Loading @@ -214,4 +215,7 @@ interface IConnectivityManager void getLatestTetheringEntitlementResult(int type, in ResultReceiver receiver, boolean showEntitlementUi, String callerPkg); void registerTetheringEventCallback(ITetheringEventCallback callback, String callerPkg); void unregisterTetheringEventCallback(ITetheringEventCallback callback, String callerPkg); } core/java/android/net/ITetheringEventCallback.aidl 0 → 100644 +28 −0 Original line number Diff line number Diff line /* * 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); } Loading
Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -225,6 +225,7 @@ java_defaults { "core/java/android/net/INetworkScoreService.aidl", "core/java/android/net/INetworkStatsService.aidl", "core/java/android/net/INetworkStatsSession.aidl", "core/java/android/net/ITetheringEventCallback.aidl", "core/java/android/net/ITetheringStatsProvider.aidl", "core/java/android/net/nsd/INsdManager.aidl", "core/java/android/nfc/IAppCallback.aidl", Loading
api/system-current.txt +7 −0 Original line number Diff line number Diff line Loading @@ -4038,11 +4038,13 @@ package android.net { method @RequiresPermission(android.Manifest.permission.LOCAL_MAC_ADDRESS) public String getCaptivePortalServerUrl(); method @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void getLatestTetheringEntitlementResult(int, boolean, @NonNull java.util.concurrent.Executor, @NonNull android.net.ConnectivityManager.OnTetheringEntitlementResultListener); method @RequiresPermission(anyOf={android.Manifest.permission.TETHER_PRIVILEGED, android.Manifest.permission.WRITE_SETTINGS}) public boolean isTetheringSupported(); method @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void registerTetheringEventCallback(@NonNull java.util.concurrent.Executor, @NonNull android.net.ConnectivityManager.OnTetheringEventCallback); method @RequiresPermission(anyOf={"android.permission.NETWORK_SETTINGS", android.Manifest.permission.NETWORK_SETUP_WIZARD, "android.permission.NETWORK_STACK"}) public void setAirplaneMode(boolean); method @RequiresPermission(android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK) public void startCaptivePortalApp(android.net.Network, android.os.Bundle); method @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void startTethering(int, boolean, android.net.ConnectivityManager.OnStartTetheringCallback); method @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void startTethering(int, boolean, android.net.ConnectivityManager.OnStartTetheringCallback, android.os.Handler); method @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void stopTethering(int); method @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void unregisterTetheringEventCallback(@NonNull android.net.ConnectivityManager.OnTetheringEventCallback); field public static final String EXTRA_CAPTIVE_PORTAL_PROBE_SPEC = "android.net.extra.CAPTIVE_PORTAL_PROBE_SPEC"; field public static final String EXTRA_CAPTIVE_PORTAL_USER_AGENT = "android.net.extra.CAPTIVE_PORTAL_USER_AGENT"; field public static final int TETHERING_BLUETOOTH = 2; // 0x2 Loading @@ -4063,6 +4065,11 @@ package android.net { method public void onEntitlementResult(int); } public abstract static class ConnectivityManager.OnTetheringEventCallback { ctor public ConnectivityManager.OnTetheringEventCallback(); method public void onUpstreamChanged(@Nullable android.net.Network); } public final class IpPrefix implements android.os.Parcelable { ctor public IpPrefix(java.net.InetAddress, int); ctor public IpPrefix(String); Loading
core/java/android/net/ConnectivityManager.java +89 −0 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ import android.util.ArrayMap; import android.util.Log; import android.util.SparseIntArray; import com.android.internal.annotations.GuardedBy; import com.android.internal.telephony.ITelephony; import com.android.internal.telephony.PhoneConstants; import com.android.internal.util.Preconditions; Loading Loading @@ -2541,6 +2542,94 @@ public class ConnectivityManager { } } /** * Callback for use with {@link registerTetheringEventCallback} to find out tethering * upstream status. * *@hide */ @SystemApi public abstract static class OnTetheringEventCallback { /** * Called when tethering upstream changed. This can be called multiple times and can be * called any time. * * @param network the {@link Network} of tethering upstream. Null means tethering doesn't * have any upstream. */ 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 loses its upstream or * disabled, {@link OnTetheringEventCallback#onUpstreamChanged} will immediately be called * with a null argument. The same callback object cannot be registered twice. * * @param executor the executor on which callback will be invoked. * @param callback the callback to be called when tethering has change events. * @hide */ @SystemApi @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void registerTetheringEventCallback( @NonNull @CallbackExecutor Executor executor, @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(); } } } /** * Remove tethering event callback previously registered with * {@link #registerTetheringEventCallback}. * * @param callback previously registered callback. * @hide */ @SystemApi @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(); } } } /** * Get the list of regular expressions that define any tetherable * USB network interfaces. If USB tethering is not supported by the Loading
core/java/android/net/IConnectivityManager.aidl +4 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ 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; Loading Loading @@ -214,4 +215,7 @@ interface IConnectivityManager void getLatestTetheringEntitlementResult(int type, in ResultReceiver receiver, boolean showEntitlementUi, String callerPkg); void registerTetheringEventCallback(ITetheringEventCallback callback, String callerPkg); void unregisterTetheringEventCallback(ITetheringEventCallback callback, String callerPkg); }
core/java/android/net/ITetheringEventCallback.aidl 0 → 100644 +28 −0 Original line number Diff line number Diff line /* * 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); }