diff options
| author | markchien <markchien@google.com> | 2022-03-23 14:28:59 +0800 |
|---|---|---|
| committer | markchien <markchien@google.com> | 2022-04-20 00:41:41 +0800 |
| commit | ae3d303344f0d9b4df5e36df93c585a0dc8343f3 (patch) | |
| tree | 1b74b4905a3104670b3944cbbfd7fa73e231f317 /Tethering/common/TetheringLib/src/android/net/TetheringManager.java | |
| parent | ac8935bee7769d4c4418cdd48d525ebdc6a2667a (diff) | |
Add onSupportedTetheringType callback
This new callback could tell caller Tethering is supported for what tethering
types.
Bug: 184996041
Test: atest TetheringTests
atest EthernetTetheringTest
CTS-Coverage-Bug: 223340235
Change-Id: Ib80ed8d7f73f4a098b8965db186d24d8cf1884d3
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}. * |
