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
This commit is contained in:
@@ -36,4 +36,5 @@ oneway interface ITetheringEventCallback
|
||||
void onTetherStatesChanged(in TetherStatesParcel states);
|
||||
void onTetherClientsChanged(in List<TetheredClient> clients);
|
||||
void onOffloadStatusChanged(int status);
|
||||
void onSupportedTetheringTypes(long supportedBitmap);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import android.net.TetherStatesParcel;
|
||||
* @hide
|
||||
*/
|
||||
parcelable TetheringCallbackStartedParcel {
|
||||
boolean tetheringSupported;
|
||||
long supportedTypes;
|
||||
Network upstreamNetwork;
|
||||
TetheringConfigurationParcel config;
|
||||
TetherStatesParcel states;
|
||||
|
||||
@@ -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 = {
|
||||
@@ -519,6 +525,9 @@ public class TetheringManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSupportedTetheringTypes(long supportedBitmap) { }
|
||||
|
||||
@Override
|
||||
public void onUpstreamChanged(Network network) { }
|
||||
|
||||
@@ -1030,6 +1039,19 @@ public class TetheringManager {
|
||||
* upstream status.
|
||||
*/
|
||||
public interface TetheringEventCallback {
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
@@ -1039,9 +1061,10 @@ public class TetheringManager {
|
||||
* <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,
|
||||
@@ -1395,6 +1426,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}.
|
||||
|
||||
Reference in New Issue
Block a user