Merge "[AWARE] Add new API to support instant communication mode"
This commit is contained in:
@@ -31853,6 +31853,7 @@ package android.net.wifi.aware {
|
||||
method public int getMaxServiceNameLength();
|
||||
method public int getMaxServiceSpecificInfoLength();
|
||||
method public int getSupportedCipherSuites();
|
||||
method public boolean isInstantCommunicationModeSupported();
|
||||
method public void writeToParcel(android.os.Parcel, int);
|
||||
field @NonNull public static final android.os.Parcelable.Creator<android.net.wifi.aware.Characteristics> CREATOR;
|
||||
field public static final int WIFI_AWARE_CIPHER_SUITE_NCS_SK_128 = 1; // 0x1
|
||||
@@ -31951,6 +31952,7 @@ package android.net.wifi.aware {
|
||||
method public android.net.wifi.aware.Characteristics getCharacteristics();
|
||||
method public boolean isAvailable();
|
||||
method public boolean isDeviceAttached();
|
||||
method public boolean isInstantCommunicationModeEnabled();
|
||||
field public static final String ACTION_WIFI_AWARE_STATE_CHANGED = "android.net.wifi.aware.action.WIFI_AWARE_STATE_CHANGED";
|
||||
field public static final int WIFI_AWARE_DATA_PATH_ROLE_INITIATOR = 0; // 0x0
|
||||
field public static final int WIFI_AWARE_DATA_PATH_ROLE_RESPONDER = 1; // 0x1
|
||||
|
||||
@@ -8040,6 +8040,10 @@ package android.net.wifi.aware {
|
||||
method @Deprecated public android.net.NetworkSpecifier createNetworkSpecifierPmk(@NonNull android.net.wifi.aware.PeerHandle, @NonNull byte[]);
|
||||
}
|
||||
|
||||
public class WifiAwareManager {
|
||||
method public void enableInstantCommunicationMode(boolean);
|
||||
}
|
||||
|
||||
public class WifiAwareSession implements java.lang.AutoCloseable {
|
||||
method public android.net.NetworkSpecifier createNetworkSpecifierPmk(int, @NonNull byte[], @NonNull byte[]);
|
||||
}
|
||||
|
||||
@@ -563,6 +563,7 @@ package android.net.wifi.aware {
|
||||
method public int getMaxServiceNameLength();
|
||||
method public int getMaxServiceSpecificInfoLength();
|
||||
method public int getSupportedCipherSuites();
|
||||
method public boolean isInstantCommunicationModeSupported();
|
||||
method public void writeToParcel(android.os.Parcel, int);
|
||||
field @NonNull public static final android.os.Parcelable.Creator<android.net.wifi.aware.Characteristics> CREATOR;
|
||||
field public static final int WIFI_AWARE_CIPHER_SUITE_NCS_SK_128 = 1; // 0x1
|
||||
@@ -661,6 +662,7 @@ package android.net.wifi.aware {
|
||||
method public android.net.wifi.aware.Characteristics getCharacteristics();
|
||||
method public boolean isAvailable();
|
||||
method public boolean isDeviceAttached();
|
||||
method public boolean isInstantCommunicationModeEnabled();
|
||||
field public static final String ACTION_WIFI_AWARE_STATE_CHANGED = "android.net.wifi.aware.action.WIFI_AWARE_STATE_CHANGED";
|
||||
field public static final int WIFI_AWARE_DATA_PATH_ROLE_INITIATOR = 0; // 0x0
|
||||
field public static final int WIFI_AWARE_DATA_PATH_ROLE_RESPONDER = 1; // 0x1
|
||||
|
||||
@@ -800,6 +800,10 @@ package android.net.wifi.aware {
|
||||
method @Deprecated public android.net.NetworkSpecifier createNetworkSpecifierPmk(@NonNull android.net.wifi.aware.PeerHandle, @NonNull byte[]);
|
||||
}
|
||||
|
||||
public class WifiAwareManager {
|
||||
method public void enableInstantCommunicationMode(boolean);
|
||||
}
|
||||
|
||||
public class WifiAwareSession implements java.lang.AutoCloseable {
|
||||
method public android.net.NetworkSpecifier createNetworkSpecifierPmk(int, @NonNull byte[], @NonNull byte[]);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package android.net.wifi.aware;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.net.wifi.util.SdkLevelUtil;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
@@ -37,6 +38,9 @@ public final class Characteristics implements Parcelable {
|
||||
public static final String KEY_MAX_MATCH_FILTER_LENGTH = "key_max_match_filter_length";
|
||||
/** @hide */
|
||||
public static final String KEY_SUPPORTED_CIPHER_SUITES = "key_supported_cipher_suites";
|
||||
/** @hide */
|
||||
public static final String KEY_IS_INSTANT_COMMUNICATION_MODE_SUPPORTED =
|
||||
"key_is_instant_communication_mode_supported";
|
||||
|
||||
private Bundle mCharacteristics = new Bundle();
|
||||
|
||||
@@ -83,6 +87,17 @@ public final class Characteristics implements Parcelable {
|
||||
return mCharacteristics.getInt(KEY_MAX_MATCH_FILTER_LENGTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if instant communication mode is supported by device.
|
||||
* @return True if supported, false otherwise.
|
||||
*/
|
||||
public boolean isInstantCommunicationModeSupported() {
|
||||
if (!SdkLevelUtil.isAtLeastS()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
return mCharacteristics.getBoolean(KEY_IS_INSTANT_COMMUNICATION_MODE_SUPPORTED);
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
@IntDef(flag = true, prefix = { "WIFI_AWARE_CIPHER_SUITE_" }, value = {
|
||||
WIFI_AWARE_CIPHER_SUITE_NCS_SK_128,
|
||||
|
||||
@@ -37,6 +37,8 @@ interface IWifiAwareManager
|
||||
boolean isUsageEnabled();
|
||||
Characteristics getCharacteristics();
|
||||
boolean isDeviceAttached();
|
||||
void enableInstantCommunicationMode(in String callingPackage, boolean enable);
|
||||
boolean isInstantCommunicationModeEnabled();
|
||||
|
||||
// client API
|
||||
void connect(in IBinder binder, in String callingPackage, in String callingFeatureId,
|
||||
|
||||
@@ -22,12 +22,14 @@ import android.annotation.Nullable;
|
||||
import android.annotation.RequiresPermission;
|
||||
import android.annotation.SdkConstant;
|
||||
import android.annotation.SdkConstant.SdkConstantType;
|
||||
import android.annotation.SystemApi;
|
||||
import android.annotation.SystemService;
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkRequest;
|
||||
import android.net.NetworkSpecifier;
|
||||
import android.net.wifi.util.HexEncoding;
|
||||
import android.net.wifi.util.SdkLevelUtil;
|
||||
import android.os.Binder;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
@@ -208,6 +210,9 @@ public class WifiAwareManager {
|
||||
* or not (false).
|
||||
*/
|
||||
public boolean isDeviceAttached() {
|
||||
if (!SdkLevelUtil.isAtLeastS()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
try {
|
||||
return mService.isDeviceAttached();
|
||||
} catch (RemoteException e) {
|
||||
@@ -215,6 +220,42 @@ public class WifiAwareManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the Wifi Aware Instant communication mode. If the device doesn't support this feature
|
||||
* calling this API will result no action.
|
||||
* @see Characteristics#isInstantCommunicationModeSupported()
|
||||
* @param enable true for enable, false otherwise.
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
public void enableInstantCommunicationMode(boolean enable) {
|
||||
if (!SdkLevelUtil.isAtLeastS()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
try {
|
||||
mService.enableInstantCommunicationMode(mContext.getOpPackageName(), enable);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current status of the Wifi Aware instant communication mode.
|
||||
* If the device doesn't support this feature, return will always be false.
|
||||
* @see Characteristics#isInstantCommunicationModeSupported()
|
||||
* @return true if it is enabled, false otherwise.
|
||||
*/
|
||||
public boolean isInstantCommunicationModeEnabled() {
|
||||
if (!SdkLevelUtil.isAtLeastS()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
try {
|
||||
return mService.isInstantCommunicationModeEnabled();
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the characteristics of the Wi-Fi Aware interface: a set of parameters which specify
|
||||
* limitations on configurations, e.g. the maximum service name length.
|
||||
|
||||
@@ -22,6 +22,7 @@ import static android.net.wifi.aware.WifiAwareNetworkSpecifier.NETWORK_SPECIFIER
|
||||
import static org.hamcrest.core.IsEqual.equalTo;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
@@ -38,6 +39,7 @@ import android.content.pm.PackageManager;
|
||||
import android.net.MacAddress;
|
||||
import android.net.wifi.RttManager;
|
||||
import android.net.wifi.util.HexEncoding;
|
||||
import android.net.wifi.util.SdkLevelUtil;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
@@ -156,6 +158,19 @@ public class WifiAwareManagerTest {
|
||||
verify(mockAwareService).isDeviceAttached();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate pass-through of isInstantCommunicationModeEnabled() and
|
||||
* enableInstantCommunicationMode() API
|
||||
*/
|
||||
@Test
|
||||
public void testEnableInstantCommunicationMode() throws Exception {
|
||||
assumeTrue(SdkLevelUtil.isAtLeastS());
|
||||
mDut.isInstantCommunicationModeEnabled();
|
||||
verify(mockAwareService).isInstantCommunicationModeEnabled();
|
||||
mDut.enableInstantCommunicationMode(true);
|
||||
verify(mockAwareService).enableInstantCommunicationMode(anyString(), eq(true));
|
||||
}
|
||||
|
||||
/*
|
||||
* WifiAwareEventCallbackProxy Tests
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user