diff options
Diffstat (limited to 'Tethering/common/TetheringLib/src/android/net/TetheringManager.java')
| -rw-r--r-- | Tethering/common/TetheringLib/src/android/net/TetheringManager.java | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/Tethering/common/TetheringLib/src/android/net/TetheringManager.java b/Tethering/common/TetheringLib/src/android/net/TetheringManager.java index 6f9b33e96a..b3f0cf2715 100644 --- a/Tethering/common/TetheringLib/src/android/net/TetheringManager.java +++ b/Tethering/common/TetheringLib/src/android/net/TetheringManager.java @@ -183,6 +183,12 @@ public class TetheringManager { */ public static final int TETHERING_WIGIG = 6; + /** + * The int value of last tethering type. + * @hide + */ + public static final int MAX_TETHERING_TYPE = TETHERING_WIGIG; + /** @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef(value = { @@ -520,6 +526,9 @@ public class TetheringManager { } @Override + public void onSupportedTetheringTypes(long supportedBitmap) { } + + @Override public void onUpstreamChanged(Network network) { } @Override @@ -1033,15 +1042,29 @@ public class TetheringManager { /** * Called when tethering supported status changed. * + * <p>This callback will be called immediately after the callback is + * registered, and never be called if there is changes afterward. + * + * <p>Tethering may be disabled via system properties, device configuration, or device + * policy restrictions. + * + * @param supported whether any tethering type is supported. + */ + default void onTetheringSupported(boolean supported) {} + + /** + * Called when tethering supported status changed. + * * <p>This will be called immediately after the callback is registered, and may be called * multiple times later upon changes. * * <p>Tethering may be disabled via system properties, device configuration, or device * policy restrictions. * - * @param supported The new supported status + * @param supportedTypes a set of @TetheringType which is supported. + * @hide */ - default void onTetheringSupported(boolean supported) {} + default void onSupportedTetheringTypes(@NonNull Set<Integer> supportedTypes) {} /** * Called when tethering upstream changed. @@ -1339,7 +1362,8 @@ public class TetheringManager { @Override public void onCallbackStarted(TetheringCallbackStartedParcel parcel) { executor.execute(() -> { - callback.onTetheringSupported(parcel.tetheringSupported); + callback.onSupportedTetheringTypes(unpackBits(parcel.supportedTypes)); + callback.onTetheringSupported(parcel.supportedTypes != 0); callback.onUpstreamChanged(parcel.upstreamNetwork); sendErrorCallbacks(parcel.states); sendRegexpsChanged(parcel.config); @@ -1358,6 +1382,13 @@ public class TetheringManager { }); } + @Override + public void onSupportedTetheringTypes(long supportedBitmap) { + executor.execute(() -> { + callback.onSupportedTetheringTypes(unpackBits(supportedBitmap)); + }); + } + private void sendRegexpsChanged(TetheringConfigurationParcel parcel) { callback.onTetherableInterfaceRegexpsChanged(new TetheringInterfaceRegexps( parcel.tetherableBluetoothRegexs, @@ -1396,6 +1427,23 @@ public class TetheringManager { } /** + * Unpack bitmap to a set of bit position intergers. + * @hide + */ + public static ArraySet<Integer> unpackBits(long val) { + final ArraySet<Integer> result = new ArraySet<>(Long.bitCount(val)); + int bitPos = 0; + while (val != 0) { + if ((val & 1) == 1) result.add(bitPos); + + val = val >>> 1; + bitPos++; + } + + return result; + } + + /** * Remove tethering event callback previously registered with * {@link #registerTetheringEventCallback}. * |
