Merge "[AWARE] Add ranging API to discovery configuration"
This commit is contained in:
@@ -112,6 +112,32 @@ public class DiscoverySessionCallback {
|
||||
/* empty */
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a discovery (publish or subscribe) operation results in a
|
||||
* service discovery. Called when a Subscribe service was configured with a range requirement
|
||||
* {@link SubscribeConfig.Builder#setMinDistanceMm(int)} and/or
|
||||
* {@link SubscribeConfig.Builder#setMaxDistanceMm(int)}. A discovery will only be declared
|
||||
* (i.e. this callback called) if the range of the publisher is within the specified distance
|
||||
* constraints.
|
||||
*
|
||||
* @param peerHandle An opaque handle to the peer matching our discovery operation.
|
||||
* @param serviceSpecificInfo The service specific information (arbitrary
|
||||
* byte array) provided by the peer as part of its discovery
|
||||
* configuration.
|
||||
* @param matchFilter The filter which resulted in this service discovery. For
|
||||
* {@link PublishConfig#PUBLISH_TYPE_UNSOLICITED},
|
||||
* {@link SubscribeConfig#SUBSCRIBE_TYPE_PASSIVE} discovery sessions this is the publisher's
|
||||
* match filter. For {@link PublishConfig#PUBLISH_TYPE_SOLICITED},
|
||||
* {@link SubscribeConfig#SUBSCRIBE_TYPE_ACTIVE} discovery sessions this
|
||||
* is the subscriber's match filter.
|
||||
* @param distanceMm The measured distance to the Publisher in mm.
|
||||
* @hide
|
||||
*/
|
||||
public void onServiceDiscoveredWithinRange(PeerHandle peerHandle,
|
||||
byte[] serviceSpecificInfo, List<byte[]> matchFilter, int distanceMm) {
|
||||
/* empty */
|
||||
}
|
||||
|
||||
/**
|
||||
* Called in response to
|
||||
* {@link DiscoverySession#sendMessage(PeerHandle, int, byte[])}
|
||||
|
||||
@@ -29,6 +29,8 @@ oneway interface IWifiAwareDiscoverySessionCallback
|
||||
void onSessionTerminated(int reason);
|
||||
|
||||
void onMatch(int peerId, in byte[] serviceSpecificInfo, in byte[] matchFilter);
|
||||
void onMatchWithDistance(int peerId, in byte[] serviceSpecificInfo, in byte[] matchFilter,
|
||||
int distanceMm);
|
||||
|
||||
void onMessageSendSuccess(int messageId);
|
||||
void onMessageSendFail(int messageId, int reason);
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Defines the configuration of a Aware publish session. Built using
|
||||
@@ -80,15 +81,20 @@ public final class PublishConfig implements Parcelable {
|
||||
/** @hide */
|
||||
public final boolean mEnableTerminateNotification;
|
||||
|
||||
/** @hide */
|
||||
public final boolean mEnableRanging;
|
||||
|
||||
/** @hide */
|
||||
public PublishConfig(byte[] serviceName, byte[] serviceSpecificInfo, byte[] matchFilter,
|
||||
int publishType, int ttlSec, boolean enableTerminateNotification) {
|
||||
int publishType, int ttlSec, boolean enableTerminateNotification,
|
||||
boolean enableRanging) {
|
||||
mServiceName = serviceName;
|
||||
mServiceSpecificInfo = serviceSpecificInfo;
|
||||
mMatchFilter = matchFilter;
|
||||
mPublishType = publishType;
|
||||
mTtlSec = ttlSec;
|
||||
mEnableTerminateNotification = enableTerminateNotification;
|
||||
mEnableRanging = enableRanging;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,7 +109,8 @@ public final class PublishConfig implements Parcelable {
|
||||
+ (new TlvBufferUtils.TlvIterable(0, 1, mMatchFilter)).toString()
|
||||
+ ", mMatchFilter.length=" + (mMatchFilter == null ? 0 : mMatchFilter.length)
|
||||
+ ", mPublishType=" + mPublishType + ", mTtlSec=" + mTtlSec
|
||||
+ ", mEnableTerminateNotification=" + mEnableTerminateNotification + "]";
|
||||
+ ", mEnableTerminateNotification=" + mEnableTerminateNotification
|
||||
+ ", mEnableRanging=" + mEnableRanging + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -119,6 +126,7 @@ public final class PublishConfig implements Parcelable {
|
||||
dest.writeInt(mPublishType);
|
||||
dest.writeInt(mTtlSec);
|
||||
dest.writeInt(mEnableTerminateNotification ? 1 : 0);
|
||||
dest.writeInt(mEnableRanging ? 1 : 0);
|
||||
}
|
||||
|
||||
public static final Creator<PublishConfig> CREATOR = new Creator<PublishConfig>() {
|
||||
@@ -135,9 +143,10 @@ public final class PublishConfig implements Parcelable {
|
||||
int publishType = in.readInt();
|
||||
int ttlSec = in.readInt();
|
||||
boolean enableTerminateNotification = in.readInt() != 0;
|
||||
boolean enableRanging = in.readInt() != 0;
|
||||
|
||||
return new PublishConfig(serviceName, ssi, matchFilter, publishType,
|
||||
ttlSec, enableTerminateNotification);
|
||||
ttlSec, enableTerminateNotification, enableRanging);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -157,21 +166,14 @@ public final class PublishConfig implements Parcelable {
|
||||
lhs.mServiceSpecificInfo) && Arrays.equals(mMatchFilter, lhs.mMatchFilter)
|
||||
&& mPublishType == lhs.mPublishType
|
||||
&& mTtlSec == lhs.mTtlSec
|
||||
&& mEnableTerminateNotification == lhs.mEnableTerminateNotification;
|
||||
&& mEnableTerminateNotification == lhs.mEnableTerminateNotification
|
||||
&& mEnableRanging == lhs.mEnableRanging;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 17;
|
||||
|
||||
result = 31 * result + Arrays.hashCode(mServiceName);
|
||||
result = 31 * result + Arrays.hashCode(mServiceSpecificInfo);
|
||||
result = 31 * result + Arrays.hashCode(mMatchFilter);
|
||||
result = 31 * result + mPublishType;
|
||||
result = 31 * result + mTtlSec;
|
||||
result = 31 * result + (mEnableTerminateNotification ? 1 : 0);
|
||||
|
||||
return result;
|
||||
return Objects.hash(mServiceName, mServiceSpecificInfo, mMatchFilter, mPublishType, mTtlSec,
|
||||
mEnableTerminateNotification, mEnableRanging);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -226,6 +228,7 @@ public final class PublishConfig implements Parcelable {
|
||||
private int mPublishType = PUBLISH_TYPE_UNSOLICITED;
|
||||
private int mTtlSec = 0;
|
||||
private boolean mEnableTerminateNotification = true;
|
||||
private boolean mEnableRanging = false;
|
||||
|
||||
/**
|
||||
* Specify the service name of the publish session. The actual on-air
|
||||
@@ -351,13 +354,36 @@ public final class PublishConfig implements Parcelable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure whether the publish discovery session supports ranging and allows peers to
|
||||
* measure distance to it. This API is used in conjunction with
|
||||
* {@link SubscribeConfig.Builder#setMinDistanceMm(int)} and
|
||||
* {@link SubscribeConfig.Builder#setMaxDistanceMm(int)} to specify a minimum and/or
|
||||
* maximum distance at which discovery will be triggered.
|
||||
* <p>
|
||||
* Optional. Disabled by default - i.e. any peer which attempts to measure distance to this
|
||||
* device will be refused. If the peer has ranging enabled (using the
|
||||
* {@link SubscribeConfig} APIs listed above, it will never discover this device.
|
||||
*
|
||||
* @param enable If true, ranging is supported on request of the peer.
|
||||
*
|
||||
* @return The builder to facilitate chaining
|
||||
* {@code builder.setXXX(..).setXXX(..)}.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public Builder setRangingEnabled(boolean enable) {
|
||||
mEnableRanging = enable;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build {@link PublishConfig} given the current requests made on the
|
||||
* builder.
|
||||
*/
|
||||
public PublishConfig build() {
|
||||
return new PublishConfig(mServiceName, mServiceSpecificInfo, mMatchFilter, mPublishType,
|
||||
mTtlSec, mEnableTerminateNotification);
|
||||
mTtlSec, mEnableTerminateNotification, mEnableRanging);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Defines the configuration of a Aware subscribe session. Built using
|
||||
@@ -78,16 +79,33 @@ public final class SubscribeConfig implements Parcelable {
|
||||
/** @hide */
|
||||
public final boolean mEnableTerminateNotification;
|
||||
|
||||
/** @hide */
|
||||
public final boolean mMinDistanceMmSet;
|
||||
|
||||
/** @hide */
|
||||
public final int mMinDistanceMm;
|
||||
|
||||
/** @hide */
|
||||
public final boolean mMaxDistanceMmSet;
|
||||
|
||||
/** @hide */
|
||||
public final int mMaxDistanceMm;
|
||||
|
||||
/** @hide */
|
||||
public SubscribeConfig(byte[] serviceName, byte[] serviceSpecificInfo, byte[] matchFilter,
|
||||
int subscribeType, int ttlSec,
|
||||
boolean enableTerminateNotification) {
|
||||
int subscribeType, int ttlSec, boolean enableTerminateNotification,
|
||||
boolean minDistanceMmSet, int minDistanceMm, boolean maxDistanceMmSet,
|
||||
int maxDistanceMm) {
|
||||
mServiceName = serviceName;
|
||||
mServiceSpecificInfo = serviceSpecificInfo;
|
||||
mMatchFilter = matchFilter;
|
||||
mSubscribeType = subscribeType;
|
||||
mTtlSec = ttlSec;
|
||||
mEnableTerminateNotification = enableTerminateNotification;
|
||||
mMinDistanceMm = minDistanceMm;
|
||||
mMinDistanceMmSet = minDistanceMmSet;
|
||||
mMaxDistanceMm = maxDistanceMm;
|
||||
mMaxDistanceMmSet = maxDistanceMmSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,7 +120,11 @@ public final class SubscribeConfig implements Parcelable {
|
||||
+ (new TlvBufferUtils.TlvIterable(0, 1, mMatchFilter)).toString()
|
||||
+ ", mMatchFilter.length=" + (mMatchFilter == null ? 0 : mMatchFilter.length)
|
||||
+ ", mSubscribeType=" + mSubscribeType + ", mTtlSec=" + mTtlSec
|
||||
+ ", mEnableTerminateNotification=" + mEnableTerminateNotification + "]";
|
||||
+ ", mEnableTerminateNotification=" + mEnableTerminateNotification
|
||||
+ ", mMinDistanceMm=" + mMinDistanceMm
|
||||
+ ", mMinDistanceMmSet=" + mMinDistanceMmSet
|
||||
+ ", mMaxDistanceMm=" + mMaxDistanceMm
|
||||
+ ", mMaxDistanceMmSet=" + mMaxDistanceMmSet + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -118,6 +140,10 @@ public final class SubscribeConfig implements Parcelable {
|
||||
dest.writeInt(mSubscribeType);
|
||||
dest.writeInt(mTtlSec);
|
||||
dest.writeInt(mEnableTerminateNotification ? 1 : 0);
|
||||
dest.writeInt(mMinDistanceMm);
|
||||
dest.writeInt(mMinDistanceMmSet ? 1 : 0);
|
||||
dest.writeInt(mMaxDistanceMm);
|
||||
dest.writeInt(mMaxDistanceMmSet ? 1 : 0);
|
||||
}
|
||||
|
||||
public static final Creator<SubscribeConfig> CREATOR = new Creator<SubscribeConfig>() {
|
||||
@@ -134,9 +160,14 @@ public final class SubscribeConfig implements Parcelable {
|
||||
int subscribeType = in.readInt();
|
||||
int ttlSec = in.readInt();
|
||||
boolean enableTerminateNotification = in.readInt() != 0;
|
||||
int minDistanceMm = in.readInt();
|
||||
boolean minDistanceMmSet = in.readInt() != 0;
|
||||
int maxDistanceMm = in.readInt();
|
||||
boolean maxDistanceMmSet = in.readInt() != 0;
|
||||
|
||||
return new SubscribeConfig(serviceName, ssi, matchFilter, subscribeType,
|
||||
ttlSec, enableTerminateNotification);
|
||||
return new SubscribeConfig(serviceName, ssi, matchFilter, subscribeType, ttlSec,
|
||||
enableTerminateNotification, minDistanceMmSet, minDistanceMm, maxDistanceMmSet,
|
||||
maxDistanceMm);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -152,23 +183,37 @@ public final class SubscribeConfig implements Parcelable {
|
||||
|
||||
SubscribeConfig lhs = (SubscribeConfig) o;
|
||||
|
||||
return Arrays.equals(mServiceName, lhs.mServiceName) && Arrays.equals(mServiceSpecificInfo,
|
||||
lhs.mServiceSpecificInfo) && Arrays.equals(mMatchFilter, lhs.mMatchFilter)
|
||||
&& mSubscribeType == lhs.mSubscribeType
|
||||
&& mTtlSec == lhs.mTtlSec
|
||||
&& mEnableTerminateNotification == lhs.mEnableTerminateNotification;
|
||||
if (!(Arrays.equals(mServiceName, lhs.mServiceName) && Arrays.equals(
|
||||
mServiceSpecificInfo, lhs.mServiceSpecificInfo) && Arrays.equals(mMatchFilter,
|
||||
lhs.mMatchFilter) && mSubscribeType == lhs.mSubscribeType && mTtlSec == lhs.mTtlSec
|
||||
&& mEnableTerminateNotification == lhs.mEnableTerminateNotification
|
||||
&& mMinDistanceMmSet == lhs.mMinDistanceMmSet
|
||||
&& mMaxDistanceMmSet == lhs.mMaxDistanceMmSet)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mMinDistanceMmSet && mMinDistanceMm != lhs.mMinDistanceMm) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mMaxDistanceMmSet && mMaxDistanceMm != lhs.mMaxDistanceMm) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 17;
|
||||
int result = Objects.hash(mServiceName, mServiceSpecificInfo, mMatchFilter, mSubscribeType,
|
||||
mTtlSec, mEnableTerminateNotification, mMinDistanceMmSet, mMaxDistanceMmSet);
|
||||
|
||||
result = 31 * result + Arrays.hashCode(mServiceName);
|
||||
result = 31 * result + Arrays.hashCode(mServiceSpecificInfo);
|
||||
result = 31 * result + Arrays.hashCode(mMatchFilter);
|
||||
result = 31 * result + mSubscribeType;
|
||||
result = 31 * result + mTtlSec;
|
||||
result = 31 * result + (mEnableTerminateNotification ? 1 : 0);
|
||||
if (mMinDistanceMmSet) {
|
||||
result = Objects.hash(result, mMinDistanceMm);
|
||||
}
|
||||
if (mMaxDistanceMmSet) {
|
||||
result = Objects.hash(result, mMaxDistanceMm);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -213,6 +258,17 @@ public final class SubscribeConfig implements Parcelable {
|
||||
"Match filter longer than supported by device characteristics");
|
||||
}
|
||||
}
|
||||
|
||||
if (mMinDistanceMmSet && mMinDistanceMm < 0) {
|
||||
throw new IllegalArgumentException("Minimum distance must be non-negative");
|
||||
}
|
||||
if (mMaxDistanceMmSet && mMaxDistanceMm < 0) {
|
||||
throw new IllegalArgumentException("Maximum distance must be non-negative");
|
||||
}
|
||||
if (mMinDistanceMmSet && mMaxDistanceMmSet && mMaxDistanceMm <= mMinDistanceMm) {
|
||||
throw new IllegalArgumentException(
|
||||
"Maximum distance must be greater than minimum distance");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -225,6 +281,10 @@ public final class SubscribeConfig implements Parcelable {
|
||||
private int mSubscribeType = SUBSCRIBE_TYPE_PASSIVE;
|
||||
private int mTtlSec = 0;
|
||||
private boolean mEnableTerminateNotification = true;
|
||||
private boolean mMinDistanceMmSet = false;
|
||||
private int mMinDistanceMm;
|
||||
private boolean mMaxDistanceMmSet = false;
|
||||
private int mMaxDistanceMm;
|
||||
|
||||
/**
|
||||
* Specify the service name of the subscribe session. The actual on-air
|
||||
@@ -349,14 +409,70 @@ public final class SubscribeConfig implements Parcelable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the minimum distance to a discovered publisher at which to trigger a discovery
|
||||
* notification. I.e. discovery will only be triggered if we've found a matching publisher
|
||||
* (based on the other criteria in this configuration) <b>and</b> the distance to the
|
||||
* publisher is > the value specified in this API.
|
||||
* <p>
|
||||
* Can be used in conjunction with {@link #setMaxDistanceMm(int)} to specify a geo-fence,
|
||||
* i.e. discovery with min < distance < max.
|
||||
* <p>
|
||||
* If this API is called, the subscriber requires ranging. In such a case, the publisher
|
||||
* peer must enable ranging using
|
||||
* {@link PublishConfig.Builder#setRangingEnabled(boolean)}. Otherwise discovery will
|
||||
* never be triggered.
|
||||
*
|
||||
* @param minDistanceMm Minimum distance, in mm, to the publisher above which to trigger
|
||||
* discovery.
|
||||
*
|
||||
* @return The builder to facilitate chaining
|
||||
* {@code builder.setXXX(..).setXXX(..)}.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public Builder setMinDistanceMm(int minDistanceMm) {
|
||||
mMinDistanceMm = minDistanceMm;
|
||||
mMinDistanceMmSet = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the maximum distance to a discovered publisher at which to trigger a discovery
|
||||
* notification. I.e. discovery will only be triggered if we've found a matching publisher
|
||||
* (based on the other criteria in this configuration) <b>and</b> the distance to the
|
||||
* publisher is < the value specified in this API.
|
||||
* <p>
|
||||
* Can be used in conjunction with {@link #setMinDistanceMm(int)} to specify a geo-fence,
|
||||
* i.e. discovery with min < distance < max.
|
||||
* <p>
|
||||
* If this API is called, the subscriber requires ranging. In such a case, the publisher
|
||||
* peer must enable ranging using
|
||||
* {@link PublishConfig.Builder#setRangingEnabled(boolean)}. Otherwise discovery will
|
||||
* never be triggered.
|
||||
*
|
||||
* @param maxDistanceMm Maximum distance, in mm, to the publisher below which to trigger
|
||||
* discovery.
|
||||
*
|
||||
* @return The builder to facilitate chaining
|
||||
* {@code builder.setXXX(..).setXXX(..)}.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public Builder setMaxDistanceMm(int maxDistanceMm) {
|
||||
mMaxDistanceMm = maxDistanceMm;
|
||||
mMaxDistanceMmSet = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build {@link SubscribeConfig} given the current requests made on the
|
||||
* builder.
|
||||
*/
|
||||
public SubscribeConfig build() {
|
||||
return new SubscribeConfig(mServiceName, mServiceSpecificInfo, mMatchFilter,
|
||||
mSubscribeType, mTtlSec,
|
||||
mEnableTerminateNotification);
|
||||
mSubscribeType, mTtlSec, mEnableTerminateNotification,
|
||||
mMinDistanceMmSet, mMinDistanceMm, mMaxDistanceMmSet, mMaxDistanceMm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ import android.annotation.IntDef;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.SdkConstant;
|
||||
import android.annotation.SystemService;
|
||||
import android.annotation.SdkConstant.SdkConstantType;
|
||||
import android.annotation.SystemService;
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkRequest;
|
||||
@@ -564,6 +564,7 @@ public class WifiAwareManager {
|
||||
private static final int CALLBACK_MESSAGE_SEND_SUCCESS = 5;
|
||||
private static final int CALLBACK_MESSAGE_SEND_FAIL = 6;
|
||||
private static final int CALLBACK_MESSAGE_RECEIVED = 7;
|
||||
private static final int CALLBACK_MATCH_WITH_DISTANCE = 8;
|
||||
|
||||
private static final String MESSAGE_BUNDLE_KEY_MESSAGE = "message";
|
||||
private static final String MESSAGE_BUNDLE_KEY_MESSAGE2 = "message2";
|
||||
@@ -618,7 +619,9 @@ public class WifiAwareManager {
|
||||
case CALLBACK_SESSION_TERMINATED:
|
||||
onProxySessionTerminated(msg.arg1);
|
||||
break;
|
||||
case CALLBACK_MATCH: {
|
||||
case CALLBACK_MATCH:
|
||||
case CALLBACK_MATCH_WITH_DISTANCE:
|
||||
{
|
||||
List<byte[]> matchFilter = null;
|
||||
byte[] arg = msg.getData().getByteArray(MESSAGE_BUNDLE_KEY_MESSAGE2);
|
||||
try {
|
||||
@@ -629,9 +632,16 @@ public class WifiAwareManager {
|
||||
+ new String(HexEncoding.encode(arg))
|
||||
+ "' - cannot be parsed: e=" + e);
|
||||
}
|
||||
mOriginalCallback.onServiceDiscovered(new PeerHandle(msg.arg1),
|
||||
msg.getData().getByteArray(MESSAGE_BUNDLE_KEY_MESSAGE),
|
||||
matchFilter);
|
||||
if (msg.what == CALLBACK_MATCH) {
|
||||
mOriginalCallback.onServiceDiscovered(new PeerHandle(msg.arg1),
|
||||
msg.getData().getByteArray(MESSAGE_BUNDLE_KEY_MESSAGE),
|
||||
matchFilter);
|
||||
} else {
|
||||
mOriginalCallback.onServiceDiscoveredWithinRange(
|
||||
new PeerHandle(msg.arg1),
|
||||
msg.getData().getByteArray(MESSAGE_BUNDLE_KEY_MESSAGE),
|
||||
matchFilter, msg.arg2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CALLBACK_MESSAGE_SEND_SUCCESS:
|
||||
@@ -684,20 +694,37 @@ public class WifiAwareManager {
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMatch(int peerId, byte[] serviceSpecificInfo, byte[] matchFilter) {
|
||||
if (VDBG) Log.v(TAG, "onMatch: peerId=" + peerId);
|
||||
|
||||
private void onMatchCommon(int messageType, int peerId, byte[] serviceSpecificInfo,
|
||||
byte[] matchFilter, int distanceMm) {
|
||||
Bundle data = new Bundle();
|
||||
data.putByteArray(MESSAGE_BUNDLE_KEY_MESSAGE, serviceSpecificInfo);
|
||||
data.putByteArray(MESSAGE_BUNDLE_KEY_MESSAGE2, matchFilter);
|
||||
|
||||
Message msg = mHandler.obtainMessage(CALLBACK_MATCH);
|
||||
Message msg = mHandler.obtainMessage(messageType);
|
||||
msg.arg1 = peerId;
|
||||
msg.arg2 = distanceMm;
|
||||
msg.setData(data);
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMatch(int peerId, byte[] serviceSpecificInfo, byte[] matchFilter) {
|
||||
if (VDBG) Log.v(TAG, "onMatch: peerId=" + peerId);
|
||||
|
||||
onMatchCommon(CALLBACK_MATCH, peerId, serviceSpecificInfo, matchFilter, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMatchWithDistance(int peerId, byte[] serviceSpecificInfo, byte[] matchFilter,
|
||||
int distanceMm) {
|
||||
if (VDBG) {
|
||||
Log.v(TAG, "onMatchWithDistance: peerId=" + peerId + ", distanceMm=" + distanceMm);
|
||||
}
|
||||
|
||||
onMatchCommon(CALLBACK_MATCH_WITH_DISTANCE, peerId, serviceSpecificInfo, matchFilter,
|
||||
distanceMm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageSendSuccess(int messageId) {
|
||||
if (VDBG) Log.v(TAG, "onMessageSendSuccess");
|
||||
|
||||
@@ -19,20 +19,17 @@ package android.net.wifi.aware;
|
||||
import static org.hamcrest.core.IsEqual.equalTo;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.isNull;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.wifi.RttManager;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Parcel;
|
||||
import android.os.RemoteException;
|
||||
import android.os.test.TestLooper;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
@@ -407,6 +404,7 @@ public class WifiAwareManagerTest {
|
||||
final byte[] matchFilter = { 1, 12, 3, 31, 32 }; // bad data!
|
||||
final int messageId = 2123;
|
||||
final int reason = AWARE_STATUS_ERROR;
|
||||
final int distanceMm = 100;
|
||||
|
||||
InOrder inOrder = inOrder(mockCallback, mockSessionCallback, mockAwareService,
|
||||
mockSubscribeSession);
|
||||
@@ -442,6 +440,8 @@ public class WifiAwareManagerTest {
|
||||
// (3) ...
|
||||
subscribeSession.getValue().sendMessage(peerHandle, messageId, string1.getBytes());
|
||||
sessionProxyCallback.getValue().onMatch(peerHandle.peerId, string1.getBytes(), matchFilter);
|
||||
sessionProxyCallback.getValue().onMatchWithDistance(peerHandle.peerId, string1.getBytes(),
|
||||
matchFilter, distanceMm);
|
||||
sessionProxyCallback.getValue().onMessageReceived(peerHandle.peerId, string1.getBytes());
|
||||
sessionProxyCallback.getValue().onMessageSendFail(messageId, reason);
|
||||
sessionProxyCallback.getValue().onMessageSendSuccess(messageId);
|
||||
@@ -450,7 +450,9 @@ public class WifiAwareManagerTest {
|
||||
inOrder.verify(mockAwareService).sendMessage(eq(clientId), eq(sessionId),
|
||||
eq(peerHandle.peerId), eq(string1.getBytes()), eq(messageId), eq(0));
|
||||
inOrder.verify(mockSessionCallback).onServiceDiscovered(peerIdCaptor.capture(),
|
||||
eq(string1.getBytes()), (List<byte[]>) isNull());
|
||||
eq(string1.getBytes()), isNull());
|
||||
inOrder.verify(mockSessionCallback).onServiceDiscoveredWithinRange(peerIdCaptor.capture(),
|
||||
eq(string1.getBytes()), isNull(), eq(distanceMm));
|
||||
assertEquals((peerIdCaptor.getValue()).peerId, peerHandle.peerId);
|
||||
inOrder.verify(mockSessionCallback).onMessageReceived(peerIdCaptor.capture(),
|
||||
eq(string1.getBytes()));
|
||||
@@ -685,11 +687,18 @@ public class WifiAwareManagerTest {
|
||||
SubscribeConfig subscribeConfig = new SubscribeConfig.Builder().build();
|
||||
|
||||
collector.checkThat("mServiceName", subscribeConfig.mServiceName, equalTo(null));
|
||||
collector.checkThat("mServiceSpecificInfo", subscribeConfig.mServiceSpecificInfo,
|
||||
equalTo(null));
|
||||
collector.checkThat("mMatchFilter", subscribeConfig.mMatchFilter, equalTo(null));
|
||||
collector.checkThat("mSubscribeType", subscribeConfig.mSubscribeType,
|
||||
equalTo(SubscribeConfig.SUBSCRIBE_TYPE_PASSIVE));
|
||||
collector.checkThat("mTtlSec", subscribeConfig.mTtlSec, equalTo(0));
|
||||
collector.checkThat("mEnableTerminateNotification",
|
||||
subscribeConfig.mEnableTerminateNotification, equalTo(true));
|
||||
collector.checkThat("mMinDistanceCmSet", subscribeConfig.mMinDistanceMmSet, equalTo(false));
|
||||
collector.checkThat("mMinDistanceMm", subscribeConfig.mMinDistanceMm, equalTo(0));
|
||||
collector.checkThat("mMaxDistanceMmSet", subscribeConfig.mMaxDistanceMmSet, equalTo(false));
|
||||
collector.checkThat("mMaxDistanceMm", subscribeConfig.mMaxDistanceMm, equalTo(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -698,16 +707,19 @@ public class WifiAwareManagerTest {
|
||||
final String serviceSpecificInfo = "long arbitrary string with some info";
|
||||
final byte[] matchFilter = { 1, 16, 1, 22 };
|
||||
final int subscribeType = SubscribeConfig.SUBSCRIBE_TYPE_PASSIVE;
|
||||
final int subscribeCount = 10;
|
||||
final int subscribeTtl = 15;
|
||||
final boolean enableTerminateNotification = false;
|
||||
final int minDistance = 10;
|
||||
final int maxDistance = 50;
|
||||
|
||||
SubscribeConfig subscribeConfig = new SubscribeConfig.Builder().setServiceName(serviceName)
|
||||
.setServiceSpecificInfo(serviceSpecificInfo.getBytes()).setMatchFilter(
|
||||
new TlvBufferUtils.TlvIterable(0, 1, matchFilter).toList())
|
||||
new TlvBufferUtils.TlvIterable(0, 1, matchFilter).toList())
|
||||
.setSubscribeType(subscribeType)
|
||||
.setTtlSec(subscribeTtl)
|
||||
.setTerminateNotificationEnabled(enableTerminateNotification).build();
|
||||
.setTerminateNotificationEnabled(enableTerminateNotification)
|
||||
.setMinDistanceMm(minDistance)
|
||||
.setMaxDistanceMm(maxDistance).build();
|
||||
|
||||
collector.checkThat("mServiceName", serviceName.getBytes(),
|
||||
equalTo(subscribeConfig.mServiceName));
|
||||
@@ -719,6 +731,10 @@ public class WifiAwareManagerTest {
|
||||
collector.checkThat("mTtlSec", subscribeTtl, equalTo(subscribeConfig.mTtlSec));
|
||||
collector.checkThat("mEnableTerminateNotification", enableTerminateNotification,
|
||||
equalTo(subscribeConfig.mEnableTerminateNotification));
|
||||
collector.checkThat("mMinDistanceMmSet", true, equalTo(subscribeConfig.mMinDistanceMmSet));
|
||||
collector.checkThat("mMinDistanceMm", minDistance, equalTo(subscribeConfig.mMinDistanceMm));
|
||||
collector.checkThat("mMaxDistanceMmSet", true, equalTo(subscribeConfig.mMaxDistanceMmSet));
|
||||
collector.checkThat("mMaxDistanceMm", maxDistance, equalTo(subscribeConfig.mMaxDistanceMm));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -729,13 +745,17 @@ public class WifiAwareManagerTest {
|
||||
final int subscribeType = SubscribeConfig.SUBSCRIBE_TYPE_PASSIVE;
|
||||
final int subscribeTtl = 15;
|
||||
final boolean enableTerminateNotification = true;
|
||||
final int minDistance = 10;
|
||||
final int maxDistance = 50;
|
||||
|
||||
SubscribeConfig subscribeConfig = new SubscribeConfig.Builder().setServiceName(serviceName)
|
||||
.setServiceSpecificInfo(serviceSpecificInfo.getBytes()).setMatchFilter(
|
||||
new TlvBufferUtils.TlvIterable(0, 1, matchFilter).toList())
|
||||
.setSubscribeType(subscribeType)
|
||||
.setTtlSec(subscribeTtl)
|
||||
.setTerminateNotificationEnabled(enableTerminateNotification).build();
|
||||
.setTerminateNotificationEnabled(enableTerminateNotification)
|
||||
.setMinDistanceMm(minDistance)
|
||||
.setMaxDistanceMm(maxDistance).build();
|
||||
|
||||
Parcel parcelW = Parcel.obtain();
|
||||
subscribeConfig.writeToParcel(parcelW, 0);
|
||||
@@ -769,11 +789,15 @@ public class WifiAwareManagerTest {
|
||||
PublishConfig publishConfig = new PublishConfig.Builder().build();
|
||||
|
||||
collector.checkThat("mServiceName", publishConfig.mServiceName, equalTo(null));
|
||||
collector.checkThat("mServiceSpecificInfo", publishConfig.mServiceSpecificInfo,
|
||||
equalTo(null));
|
||||
collector.checkThat("mMatchFilter", publishConfig.mMatchFilter, equalTo(null));
|
||||
collector.checkThat("mPublishType", publishConfig.mPublishType,
|
||||
equalTo(PublishConfig.PUBLISH_TYPE_UNSOLICITED));
|
||||
collector.checkThat("mTtlSec", publishConfig.mTtlSec, equalTo(0));
|
||||
collector.checkThat("mEnableTerminateNotification",
|
||||
publishConfig.mEnableTerminateNotification, equalTo(true));
|
||||
collector.checkThat("mEnableRanging", publishConfig.mEnableRanging, equalTo(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -782,16 +806,17 @@ public class WifiAwareManagerTest {
|
||||
final String serviceSpecificInfo = "long arbitrary string with some info";
|
||||
final byte[] matchFilter = { 1, 16, 1, 22 };
|
||||
final int publishType = PublishConfig.PUBLISH_TYPE_SOLICITED;
|
||||
final int publishCount = 10;
|
||||
final int publishTtl = 15;
|
||||
final boolean enableTerminateNotification = false;
|
||||
final boolean enableRanging = true;
|
||||
|
||||
PublishConfig publishConfig = new PublishConfig.Builder().setServiceName(serviceName)
|
||||
.setServiceSpecificInfo(serviceSpecificInfo.getBytes()).setMatchFilter(
|
||||
new TlvBufferUtils.TlvIterable(0, 1, matchFilter).toList())
|
||||
.setPublishType(publishType)
|
||||
.setTtlSec(publishTtl)
|
||||
.setTerminateNotificationEnabled(enableTerminateNotification).build();
|
||||
.setTerminateNotificationEnabled(enableTerminateNotification)
|
||||
.setRangingEnabled(enableRanging).build();
|
||||
|
||||
collector.checkThat("mServiceName", serviceName.getBytes(),
|
||||
equalTo(publishConfig.mServiceName));
|
||||
@@ -802,6 +827,7 @@ public class WifiAwareManagerTest {
|
||||
collector.checkThat("mTtlSec", publishTtl, equalTo(publishConfig.mTtlSec));
|
||||
collector.checkThat("mEnableTerminateNotification", enableTerminateNotification,
|
||||
equalTo(publishConfig.mEnableTerminateNotification));
|
||||
collector.checkThat("mEnableRanging", enableRanging, equalTo(publishConfig.mEnableRanging));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -810,16 +836,17 @@ public class WifiAwareManagerTest {
|
||||
final String serviceSpecificInfo = "long arbitrary string with some info";
|
||||
final byte[] matchFilter = { 1, 16, 1, 22 };
|
||||
final int publishType = PublishConfig.PUBLISH_TYPE_SOLICITED;
|
||||
final int publishCount = 10;
|
||||
final int publishTtl = 15;
|
||||
final boolean enableTerminateNotification = false;
|
||||
final boolean enableRanging = true;
|
||||
|
||||
PublishConfig publishConfig = new PublishConfig.Builder().setServiceName(serviceName)
|
||||
.setServiceSpecificInfo(serviceSpecificInfo.getBytes()).setMatchFilter(
|
||||
new TlvBufferUtils.TlvIterable(0, 1, matchFilter).toList())
|
||||
.setPublishType(publishType)
|
||||
.setTtlSec(publishTtl)
|
||||
.setTerminateNotificationEnabled(enableTerminateNotification).build();
|
||||
.setTerminateNotificationEnabled(enableTerminateNotification)
|
||||
.setRangingEnabled(enableRanging).build();
|
||||
|
||||
Parcel parcelW = Parcel.obtain();
|
||||
publishConfig.writeToParcel(parcelW, 0);
|
||||
|
||||
Reference in New Issue
Block a user