From 8ef74534169bd3f3296e2ee42c0fda95c8518383 Mon Sep 17 00:00:00 2001 From: Etan Cohen Date: Wed, 9 Mar 2016 11:16:45 -0800 Subject: [NAN] Expose match style configuration as public API. [DO NOT MERGE] Match style allows apps to configure getting a single notification or continuous notifications (for all matches). Bug: 27568256 Change-Id: I9b7bd2e4e58af5c73188267d11c1288a93cf64ed --- wifi/java/android/net/wifi/nan/PublishConfig.java | 10 ++-- .../java/android/net/wifi/nan/SubscribeConfig.java | 70 ++++++++++++++++++---- .../net/wifi/nan/WifiNanPublishSession.java | 4 +- .../net/wifi/nan/WifiNanSubscribeSession.java | 4 +- 4 files changed, 66 insertions(+), 22 deletions(-) diff --git a/wifi/java/android/net/wifi/nan/PublishConfig.java b/wifi/java/android/net/wifi/nan/PublishConfig.java index cf5251c19200..fd1585b103eb 100644 --- a/wifi/java/android/net/wifi/nan/PublishConfig.java +++ b/wifi/java/android/net/wifi/nan/PublishConfig.java @@ -24,7 +24,7 @@ import java.util.Arrays; /** * Defines the configuration of a NAN publish session. Built using * {@link PublishConfig.Builder}. Publish is done using - * {@link WifiNanManager#publish(PublishConfig, WifiNanSessionListener, int)} or + * {@link WifiNanManager#publish(PublishConfig, WifiNanSessionCallback, int)} or * {@link WifiNanPublishSession#publish(PublishConfig)}. * * @hide PROPOSED_NAN_API @@ -402,8 +402,8 @@ public class PublishConfig implements Parcelable { * Sets the number of times a solicited ( * {@link PublishConfig.Builder#setPublishType(int)}) publish session * will transmit a packet. When the count is reached an event will be - * generated for {@link WifiNanSessionListener#onPublishTerminated(int)} - * with reason={@link WifiNanSessionListener#TERMINATE_REASON_DONE}. + * generated for {@link WifiNanSessionCallback#onPublishTerminated(int)} + * with reason={@link WifiNanSessionCallback#TERMINATE_REASON_DONE}. * * @param publishCount Number of publish packets to transmit. * @return The builder to facilitate chaining @@ -422,8 +422,8 @@ public class PublishConfig implements Parcelable { * {@link PublishConfig.Builder#setPublishCount(int)}) publish session * will be alive - i.e. transmitting a packet. When the TTL is reached * an event will be generated for - * {@link WifiNanSessionListener#onPublishTerminated(int)} with reason= - * {@link WifiNanSessionListener#TERMINATE_REASON_DONE}. + * {@link WifiNanSessionCallback#onPublishTerminated(int)} with reason= + * {@link WifiNanSessionCallback#TERMINATE_REASON_DONE}. * * @param ttlSec Lifetime of a publish session in seconds. * @return The builder to facilitate chaining diff --git a/wifi/java/android/net/wifi/nan/SubscribeConfig.java b/wifi/java/android/net/wifi/nan/SubscribeConfig.java index 479829331421..514eaa1a27d5 100644 --- a/wifi/java/android/net/wifi/nan/SubscribeConfig.java +++ b/wifi/java/android/net/wifi/nan/SubscribeConfig.java @@ -24,7 +24,7 @@ import java.util.Arrays; /** * Defines the configuration of a NAN subscribe session. Built using * {@link SubscribeConfig.Builder}. Subscribe is done using - * {@link WifiNanManager#subscribe(SubscribeConfig, WifiNanSessionListener, int)} + * {@link WifiNanManager#subscribe(SubscribeConfig, WifiNanSessionCallback, int)} * or {@link WifiNanSubscribeSession#subscribe(SubscribeConfig)}. * * @hide PROPOSED_NAN_API @@ -46,6 +46,18 @@ public class SubscribeConfig implements Parcelable { */ public static final int SUBSCRIBE_TYPE_ACTIVE = 1; + /** + * Specifies that only the first match of a set of identical matches (same + * publish) will be reported to the subscriber. + */ + public static final int MATCH_STYLE_FIRST_ONLY = 0; + + /** + * Specifies that all matches of a set of identical matches (same publish) + * will be reported to the subscriber. + */ + public static final int MATCH_STYLE_ALL = 1; + /** * @hide */ @@ -96,9 +108,14 @@ public class SubscribeConfig implements Parcelable { */ public final int mTtlSec; + /** + * @hide + */ + public final int mMatchStyle; + private SubscribeConfig(String serviceName, byte[] serviceSpecificInfo, int serviceSpecificInfoLength, byte[] txFilter, int txFilterLength, byte[] rxFilter, - int rxFilterLength, int subscribeType, int publichCount, int ttlSec) { + int rxFilterLength, int subscribeType, int publichCount, int ttlSec, int matchStyle) { mServiceName = serviceName; mServiceSpecificInfoLength = serviceSpecificInfoLength; mServiceSpecificInfo = serviceSpecificInfo; @@ -109,6 +126,7 @@ public class SubscribeConfig implements Parcelable { mSubscribeType = subscribeType; mSubscribeCount = publichCount; mTtlSec = ttlSec; + mMatchStyle = matchStyle; } @Override @@ -120,7 +138,7 @@ public class SubscribeConfig implements Parcelable { + ", mRxFilter=" + (new TlvBufferUtils.TlvIterable(0, 1, mRxFilter, mRxFilterLength)).toString() + ", mSubscribeType=" + mSubscribeType + ", mSubscribeCount=" + mSubscribeCount - + ", mTtlSec=" + mTtlSec + "']"; + + ", mTtlSec=" + mTtlSec + ", mMatchType=" + mMatchStyle + "']"; } @Override @@ -146,6 +164,7 @@ public class SubscribeConfig implements Parcelable { dest.writeInt(mSubscribeType); dest.writeInt(mSubscribeCount); dest.writeInt(mTtlSec); + dest.writeInt(mMatchStyle); } public static final Creator CREATOR = new Creator() { @@ -175,8 +194,9 @@ public class SubscribeConfig implements Parcelable { int subscribeType = in.readInt(); int subscribeCount = in.readInt(); int ttlSec = in.readInt(); + int matchStyle = in.readInt(); return new SubscribeConfig(serviceName, ssi, ssiLength, txFilter, txFilterLength, - rxFilter, rxFilterLength, subscribeType, subscribeCount, ttlSec); + rxFilter, rxFilterLength, subscribeType, subscribeCount, ttlSec, matchStyle); } }; @@ -230,7 +250,7 @@ public class SubscribeConfig implements Parcelable { } return mSubscribeType == lhs.mSubscribeType && mSubscribeCount == lhs.mSubscribeCount - && mTtlSec == lhs.mTtlSec; + && mTtlSec == lhs.mTtlSec && mMatchStyle == lhs.mMatchStyle; } @Override @@ -247,6 +267,7 @@ public class SubscribeConfig implements Parcelable { result = 31 * result + mSubscribeType; result = 31 * result + mSubscribeCount; result = 31 * result + mTtlSec; + result = 31 * result + mMatchStyle; return result; } @@ -262,9 +283,10 @@ public class SubscribeConfig implements Parcelable { private byte[] mTxFilter = new byte[0]; private int mRxFilterLength; private byte[] mRxFilter = new byte[0]; - private int mSubscribeType; - private int mSubscribeCount; - private int mTtlSec; + private int mSubscribeType = SUBSCRIBE_TYPE_PASSIVE; + private int mSubscribeCount = 0; + private int mTtlSec = 0; + private int mMatchStyle = MATCH_STYLE_ALL; /** * Specify the service name of the subscribe session. The actual on-air @@ -390,8 +412,8 @@ public class SubscribeConfig implements Parcelable { * {@link SubscribeConfig.Builder#setSubscribeType(int)}) subscribe * session will transmit a packet. When the count is reached an event * will be generated for - * {@link WifiNanSessionListener#onSubscribeTerminated(int)} with - * reason= {@link WifiNanSessionListener#TERMINATE_REASON_DONE}. + * {@link WifiNanSessionCallback#onSubscribeTerminated(int)} with + * reason= {@link WifiNanSessionCallback#TERMINATE_REASON_DONE}. * * @param subscribeCount Number of subscribe packets to transmit. * @return The builder to facilitate chaining @@ -410,8 +432,8 @@ public class SubscribeConfig implements Parcelable { * {@link SubscribeConfig.Builder#setSubscribeType(int)}) subscribe * session will be alive - i.e. transmitting a packet. When the TTL is * reached an event will be generated for - * {@link WifiNanSessionListener#onSubscribeTerminated(int)} with - * reason= {@link WifiNanSessionListener#TERMINATE_REASON_DONE}. + * {@link WifiNanSessionCallback#onSubscribeTerminated(int)} with + * reason= {@link WifiNanSessionCallback#TERMINATE_REASON_DONE}. * * @param ttlSec Lifetime of a subscribe session in seconds. * @return The builder to facilitate chaining @@ -425,6 +447,28 @@ public class SubscribeConfig implements Parcelable { return this; } + /** + * Sets the match style of the subscription - how are matches from a + * single match session (corresponding to the same publish action on the + * peer) reported to the host (using the + * {@link WifiNanSessionCallback#onMatch(int, byte[], int, byte[], int)} + * ). The options are: only report the first match and ignore the rest + * {@link SubscribeConfig#MATCH_STYLE_FIRST_ONLY} or report every single + * match {@link SubscribeConfig#MATCH_STYLE_ALL}. + * + * @param matchStyle The reporting style for the discovery match. + * @return The builder to facilitate chaining + * {@code builder.setXXX(..).setXXX(..)}. + */ + public Builder setMatchStyle(int matchStyle) { + if (matchStyle != MATCH_STYLE_FIRST_ONLY && matchStyle != MATCH_STYLE_ALL) { + throw new IllegalArgumentException( + "Invalid matchType - must be MATCH_FIRST_ONLY or MATCH_ALL"); + } + mMatchStyle = matchStyle; + return this; + } + /** * Build {@link SubscribeConfig} given the current requests made on the * builder. @@ -432,7 +476,7 @@ public class SubscribeConfig implements Parcelable { public SubscribeConfig build() { return new SubscribeConfig(mServiceName, mServiceSpecificInfo, mServiceSpecificInfoLength, mTxFilter, mTxFilterLength, mRxFilter, - mRxFilterLength, mSubscribeType, mSubscribeCount, mTtlSec); + mRxFilterLength, mSubscribeType, mSubscribeCount, mTtlSec, mMatchStyle); } } } diff --git a/wifi/java/android/net/wifi/nan/WifiNanPublishSession.java b/wifi/java/android/net/wifi/nan/WifiNanPublishSession.java index eae9c653b341..af1cf7d900a3 100644 --- a/wifi/java/android/net/wifi/nan/WifiNanPublishSession.java +++ b/wifi/java/android/net/wifi/nan/WifiNanPublishSession.java @@ -18,7 +18,7 @@ package android.net.wifi.nan; /** * A representation of a NAN publish session. Created when - * {@link WifiNanManager#publish(PublishConfig, WifiNanSessionListener, int)} is + * {@link WifiNanManager#publish(PublishConfig, WifiNanSessionCallback, int)} is * executed. The object can be used to stop and re-start (re-configure) the * publish session. * @@ -34,7 +34,7 @@ public class WifiNanPublishSession extends WifiNanSession { /** * Restart/re-configure the publish session. Note that the - * {@link WifiNanSessionListener} is not replaced - the same listener used + * {@link WifiNanSessionCallback} is not replaced - the same listener used * at creation is still used. * * @param publishConfig The configuration ({@link PublishConfig}) of the diff --git a/wifi/java/android/net/wifi/nan/WifiNanSubscribeSession.java b/wifi/java/android/net/wifi/nan/WifiNanSubscribeSession.java index d2f13c85e4a6..aa128a47ce3b 100644 --- a/wifi/java/android/net/wifi/nan/WifiNanSubscribeSession.java +++ b/wifi/java/android/net/wifi/nan/WifiNanSubscribeSession.java @@ -18,7 +18,7 @@ package android.net.wifi.nan; /** * A representation of a NAN subscribe session. Created when - * {@link WifiNanManager#subscribe(SubscribeConfig, WifiNanSessionListener, int)} + * {@link WifiNanManager#subscribe(SubscribeConfig, WifiNanSessionCallback, int)} * is executed. The object can be used to stop and re-start (re-configure) the * subscribe session. * @@ -34,7 +34,7 @@ public class WifiNanSubscribeSession extends WifiNanSession { /** * Restart/re-configure the subscribe session. Note that the - * {@link WifiNanSessionListener} is not replaced - the same listener used + * {@link WifiNanSessionCallback} is not replaced - the same listener used * at creation is still used. * * @param subscribeConfig The configuration ({@link SubscribeConfig}) of the -- cgit v1.2.3-59-g8ed1b