[NAN] Modify arguments from "array, length" to "array"
Arrays carry their own lengths. There's no need to provide mechanism to 'shave' the array - could be done explicitly by caller if needed. Bug: 29617160 Change-Id: Ib135aa04145f400163cd1a8908dfca4590b4480d
This commit is contained in:
@@ -49,8 +49,8 @@ interface IWifiNanManager
|
||||
// session API
|
||||
void updatePublish(int clientId, int sessionId, in PublishConfig publishConfig);
|
||||
void updateSubscribe(int clientId, int sessionId, in SubscribeConfig subscribeConfig);
|
||||
void sendMessage(int clientId, int sessionId, int peerId, in byte[] message, int messageLength,
|
||||
int messageId, int retryCount);
|
||||
void sendMessage(int clientId, int sessionId, int peerId, in byte[] message, int messageId,
|
||||
int retryCount);
|
||||
void terminateSession(int clientId, int sessionId);
|
||||
int startRanging(int clientId, int sessionId, in RttManager.ParcelableRttParams parms);
|
||||
}
|
||||
|
||||
@@ -28,10 +28,9 @@ oneway interface IWifiNanSessionCallback
|
||||
void onSessionConfigFail(int reason);
|
||||
void onSessionTerminated(int reason);
|
||||
|
||||
void onMatch(int peerId, in byte[] serviceSpecificInfo,
|
||||
int serviceSpecificInfoLength, in byte[] matchFilter, int matchFilterLength);
|
||||
void onMatch(int peerId, in byte[] serviceSpecificInfo, in byte[] matchFilter);
|
||||
|
||||
void onMessageSendSuccess(int messageId);
|
||||
void onMessageSendFail(int messageId, int reason);
|
||||
void onMessageReceived(int peerId, in byte[] message, int messageLength);
|
||||
void onMessageReceived(int peerId, in byte[] message);
|
||||
}
|
||||
|
||||
@@ -18,9 +18,12 @@ package android.net.wifi.nan;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import libcore.util.HexEncoding;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -61,31 +64,16 @@ public class PublishConfig implements Parcelable {
|
||||
*/
|
||||
public final byte[] mServiceName;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public final int mServiceSpecificInfoLength;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public final byte[] mServiceSpecificInfo;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public final int mTxFilterLength;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public final byte[] mTxFilter;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public final int mRxFilterLength;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
@@ -112,15 +100,11 @@ public class PublishConfig implements Parcelable {
|
||||
public final boolean mEnableTerminateNotification;
|
||||
|
||||
private PublishConfig(byte[] serviceName, byte[] serviceSpecificInfo,
|
||||
int serviceSpecificInfoLength, byte[] txFilter, int txFilterLength, byte[] rxFilter,
|
||||
int rxFilterLength, int publishType, int publichCount, int ttlSec,
|
||||
byte[] txFilter, byte[] rxFilter, int publishType, int publichCount, int ttlSec,
|
||||
boolean enableTerminateNotification) {
|
||||
mServiceName = serviceName;
|
||||
mServiceSpecificInfoLength = serviceSpecificInfoLength;
|
||||
mServiceSpecificInfo = serviceSpecificInfo;
|
||||
mTxFilterLength = txFilterLength;
|
||||
mTxFilter = txFilter;
|
||||
mRxFilterLength = rxFilterLength;
|
||||
mRxFilter = rxFilter;
|
||||
mPublishType = publishType;
|
||||
mPublishCount = publichCount;
|
||||
@@ -130,12 +114,10 @@ public class PublishConfig implements Parcelable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PublishConfig [mServiceName='" + mServiceName + "', mServiceSpecificInfo='"
|
||||
+ (new String(mServiceSpecificInfo, 0, mServiceSpecificInfoLength))
|
||||
+ "', mTxFilter="
|
||||
+ (new TlvBufferUtils.TlvIterable(0, 1, mTxFilter, mTxFilterLength)).toString()
|
||||
+ ", mRxFilter="
|
||||
+ (new TlvBufferUtils.TlvIterable(0, 1, mRxFilter, mRxFilterLength)).toString()
|
||||
return "PublishConfig [mServiceName='" + mServiceName + ", mServiceSpecificInfo='" + (
|
||||
(mServiceSpecificInfo == null) ? "null" : HexEncoding.encode(mServiceSpecificInfo))
|
||||
+ ", mTxFilter=" + (new TlvBufferUtils.TlvIterable(0, 1, mTxFilter)).toString()
|
||||
+ ", mRxFilter=" + (new TlvBufferUtils.TlvIterable(0, 1, mRxFilter)).toString()
|
||||
+ ", mPublishType=" + mPublishType + ", mPublishCount=" + mPublishCount
|
||||
+ ", mTtlSec=" + mTtlSec + ", mEnableTerminateNotification="
|
||||
+ mEnableTerminateNotification + "]";
|
||||
@@ -148,22 +130,10 @@ public class PublishConfig implements Parcelable {
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(mServiceName.length);
|
||||
if (mServiceName.length != 0) {
|
||||
dest.writeByteArray(mServiceName);
|
||||
}
|
||||
dest.writeInt(mServiceSpecificInfoLength);
|
||||
if (mServiceSpecificInfoLength != 0) {
|
||||
dest.writeByteArray(mServiceSpecificInfo, 0, mServiceSpecificInfoLength);
|
||||
}
|
||||
dest.writeInt(mTxFilterLength);
|
||||
if (mTxFilterLength != 0) {
|
||||
dest.writeByteArray(mTxFilter, 0, mTxFilterLength);
|
||||
}
|
||||
dest.writeInt(mRxFilterLength);
|
||||
if (mRxFilterLength != 0) {
|
||||
dest.writeByteArray(mRxFilter, 0, mRxFilterLength);
|
||||
}
|
||||
dest.writeByteArray(mServiceName);
|
||||
dest.writeByteArray(mServiceSpecificInfo);
|
||||
dest.writeByteArray(mTxFilter);
|
||||
dest.writeByteArray(mRxFilter);
|
||||
dest.writeInt(mPublishType);
|
||||
dest.writeInt(mPublishCount);
|
||||
dest.writeInt(mTtlSec);
|
||||
@@ -178,34 +148,17 @@ public class PublishConfig implements Parcelable {
|
||||
|
||||
@Override
|
||||
public PublishConfig createFromParcel(Parcel in) {
|
||||
int serviceNameLength = in.readInt();
|
||||
byte[] serviceName = new byte[serviceNameLength];
|
||||
if (serviceNameLength != 0) {
|
||||
in.readByteArray(serviceName);
|
||||
}
|
||||
int ssiLength = in.readInt();
|
||||
byte[] ssi = new byte[ssiLength];
|
||||
if (ssiLength != 0) {
|
||||
in.readByteArray(ssi);
|
||||
}
|
||||
int txFilterLength = in.readInt();
|
||||
byte[] txFilter = new byte[txFilterLength];
|
||||
if (txFilterLength != 0) {
|
||||
in.readByteArray(txFilter);
|
||||
}
|
||||
int rxFilterLength = in.readInt();
|
||||
byte[] rxFilter = new byte[rxFilterLength];
|
||||
if (rxFilterLength != 0) {
|
||||
in.readByteArray(rxFilter);
|
||||
}
|
||||
byte[] serviceName = in.createByteArray();
|
||||
byte[] ssi = in.createByteArray();
|
||||
byte[] txFilter = in.createByteArray();
|
||||
byte[] rxFilter = in.createByteArray();
|
||||
int publishType = in.readInt();
|
||||
int publishCount = in.readInt();
|
||||
int ttlSec = in.readInt();
|
||||
boolean enableTerminateNotification = in.readInt() != 0;
|
||||
|
||||
return new PublishConfig(serviceName, ssi, ssiLength, txFilter, txFilterLength,
|
||||
rxFilter, rxFilterLength, publishType, publishCount, ttlSec,
|
||||
enableTerminateNotification);
|
||||
return new PublishConfig(serviceName, ssi, txFilter, rxFilter, publishType,
|
||||
publishCount, ttlSec, enableTerminateNotification);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -221,45 +174,10 @@ public class PublishConfig implements Parcelable {
|
||||
|
||||
PublishConfig lhs = (PublishConfig) o;
|
||||
|
||||
if (!Arrays.equals(mServiceName, lhs.mServiceName)
|
||||
|| mServiceSpecificInfoLength != lhs.mServiceSpecificInfoLength
|
||||
|| mTxFilterLength != lhs.mTxFilterLength
|
||||
|| mRxFilterLength != lhs.mRxFilterLength) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mServiceSpecificInfo != null && lhs.mServiceSpecificInfo != null) {
|
||||
for (int i = 0; i < mServiceSpecificInfoLength; ++i) {
|
||||
if (mServiceSpecificInfo[i] != lhs.mServiceSpecificInfo[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else if (mServiceSpecificInfoLength != 0) {
|
||||
return false; // invalid != invalid
|
||||
}
|
||||
|
||||
if (mTxFilter != null && lhs.mTxFilter != null) {
|
||||
for (int i = 0; i < mTxFilterLength; ++i) {
|
||||
if (mTxFilter[i] != lhs.mTxFilter[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else if (mTxFilterLength != 0) {
|
||||
return false; // invalid != invalid
|
||||
}
|
||||
|
||||
if (mRxFilter != null && lhs.mRxFilter != null) {
|
||||
for (int i = 0; i < mRxFilterLength; ++i) {
|
||||
if (mRxFilter[i] != lhs.mRxFilter[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else if (mRxFilterLength != 0) {
|
||||
return false; // invalid != invalid
|
||||
}
|
||||
|
||||
return mPublishType == lhs.mPublishType && mPublishCount == lhs.mPublishCount
|
||||
&& mTtlSec == lhs.mTtlSec
|
||||
return Arrays.equals(mServiceName, lhs.mServiceName) && Arrays.equals(mServiceSpecificInfo,
|
||||
lhs.mServiceSpecificInfo) && Arrays.equals(mTxFilter, lhs.mTxFilter)
|
||||
&& Arrays.equals(mRxFilter, lhs.mRxFilter) && mPublishType == lhs.mPublishType
|
||||
&& mPublishCount == lhs.mPublishCount && mTtlSec == lhs.mTtlSec
|
||||
&& mEnableTerminateNotification == lhs.mEnableTerminateNotification;
|
||||
}
|
||||
|
||||
@@ -268,11 +186,8 @@ public class PublishConfig implements Parcelable {
|
||||
int result = 17;
|
||||
|
||||
result = 31 * result + Arrays.hashCode(mServiceName);
|
||||
result = 31 * result + mServiceSpecificInfoLength;
|
||||
result = 31 * result + Arrays.hashCode(mServiceSpecificInfo);
|
||||
result = 31 * result + mTxFilterLength;
|
||||
result = 31 * result + Arrays.hashCode(mTxFilter);
|
||||
result = 31 * result + mRxFilterLength;
|
||||
result = 31 * result + Arrays.hashCode(mRxFilter);
|
||||
result = 31 * result + mPublishType;
|
||||
result = 31 * result + mPublishCount;
|
||||
@@ -291,24 +206,11 @@ public class PublishConfig implements Parcelable {
|
||||
public void validate() throws IllegalArgumentException {
|
||||
WifiNanUtils.validateServiceName(mServiceName);
|
||||
|
||||
if (mServiceSpecificInfoLength != 0 && (mServiceSpecificInfo == null
|
||||
|| mServiceSpecificInfo.length < mServiceSpecificInfoLength)) {
|
||||
throw new IllegalArgumentException("Non-matching combination of "
|
||||
+ "serviceSpecificInfo and serviceSpecificInfoLength");
|
||||
}
|
||||
if (mTxFilterLength != 0 && (mTxFilter == null || mTxFilter.length < mTxFilterLength)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Non-matching combination of txFilter and txFilterLength");
|
||||
}
|
||||
if (!TlvBufferUtils.isValid(mTxFilter, mTxFilterLength, 0, 1)) {
|
||||
if (!TlvBufferUtils.isValid(mTxFilter, 0, 1)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid txFilter configuration - LV fields do not match up to length");
|
||||
}
|
||||
if (mRxFilterLength != 0 && (mRxFilter == null || mRxFilter.length < mRxFilterLength)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Non-matching combination of rxFilter and rxFilterLength");
|
||||
}
|
||||
if (!TlvBufferUtils.isValid(mRxFilter, mRxFilterLength, 0, 1)) {
|
||||
if (!TlvBufferUtils.isValid(mRxFilter, 0, 1)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid rxFilter configuration - LV fields do not match up to length");
|
||||
}
|
||||
@@ -321,11 +223,13 @@ public class PublishConfig implements Parcelable {
|
||||
if (mTtlSec < 0) {
|
||||
throw new IllegalArgumentException("Invalid ttlSec - must be non-negative");
|
||||
}
|
||||
if (mPublishType == PublishConfig.PUBLISH_TYPE_UNSOLICITED && mRxFilterLength != 0) {
|
||||
if (mPublishType == PublishConfig.PUBLISH_TYPE_UNSOLICITED && mRxFilter != null
|
||||
&& mRxFilter.length != 0) {
|
||||
throw new IllegalArgumentException("Invalid publish config: UNSOLICITED "
|
||||
+ "publishes (active) can't have an Rx filter");
|
||||
}
|
||||
if (mPublishType == PublishConfig.PUBLISH_TYPE_SOLICITED && mTxFilterLength != 0) {
|
||||
if (mPublishType == PublishConfig.PUBLISH_TYPE_SOLICITED && mTxFilter != null
|
||||
&& mTxFilter.length != 0) {
|
||||
throw new IllegalArgumentException("Invalid publish config: SOLICITED "
|
||||
+ "publishes (passive) can't have a Tx filter");
|
||||
}
|
||||
@@ -336,12 +240,9 @@ public class PublishConfig implements Parcelable {
|
||||
*/
|
||||
public static final class Builder {
|
||||
private byte[] mServiceName;
|
||||
private int mServiceSpecificInfoLength;
|
||||
private byte[] mServiceSpecificInfo = new byte[0];
|
||||
private int mTxFilterLength;
|
||||
private byte[] mTxFilter = new byte[0];
|
||||
private int mRxFilterLength;
|
||||
private byte[] mRxFilter = new byte[0];
|
||||
private byte[] mServiceSpecificInfo;
|
||||
private byte[] mTxFilter;
|
||||
private byte[] mRxFilter;
|
||||
private int mPublishType = PUBLISH_TYPE_UNSOLICITED;
|
||||
private int mPublishCount = 0;
|
||||
private int mTtlSec = 0;
|
||||
@@ -377,26 +278,17 @@ public class PublishConfig implements Parcelable {
|
||||
*
|
||||
* @param serviceSpecificInfo A byte-array for the service-specific
|
||||
* information field.
|
||||
* @param serviceSpecificInfoLength The length of the byte-array to be
|
||||
* used.
|
||||
* @return The builder to facilitate chaining
|
||||
* {@code builder.setXXX(..).setXXX(..)}.
|
||||
*/
|
||||
public Builder setServiceSpecificInfo(byte[] serviceSpecificInfo,
|
||||
int serviceSpecificInfoLength) {
|
||||
if (serviceSpecificInfoLength != 0 && (serviceSpecificInfo == null
|
||||
|| serviceSpecificInfo.length < serviceSpecificInfoLength)) {
|
||||
throw new IllegalArgumentException("Non-matching combination of "
|
||||
+ "serviceSpecificInfo and serviceSpecificInfoLength");
|
||||
}
|
||||
mServiceSpecificInfoLength = serviceSpecificInfoLength;
|
||||
public Builder setServiceSpecificInfo(@Nullable byte[] serviceSpecificInfo) {
|
||||
mServiceSpecificInfo = serviceSpecificInfo;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify service specific information for the publish session - same
|
||||
* as {@link PublishConfig.Builder#setServiceSpecificInfo(byte[], int)}
|
||||
* as {@link PublishConfig.Builder#setServiceSpecificInfo(byte[])}
|
||||
* but obtaining the data from a String.
|
||||
*
|
||||
* @param serviceSpecificInfoStr The service specific information string
|
||||
@@ -407,7 +299,6 @@ public class PublishConfig implements Parcelable {
|
||||
*/
|
||||
public Builder setServiceSpecificInfo(@NonNull String serviceSpecificInfoStr) {
|
||||
mServiceSpecificInfo = serviceSpecificInfoStr.getBytes();
|
||||
mServiceSpecificInfoLength = mServiceSpecificInfo.length;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -424,18 +315,11 @@ public class PublishConfig implements Parcelable {
|
||||
*
|
||||
* @param txFilter The byte-array containing the LV formatted transmit
|
||||
* filter.
|
||||
* @param txFilterLength The number of bytes in the transmit filter
|
||||
* argument.
|
||||
* @return The builder to facilitate chaining
|
||||
* {@code builder.setXXX(..).setXXX(..)}.
|
||||
*/
|
||||
public Builder setTxFilter(byte[] txFilter, int txFilterLength) {
|
||||
if (txFilterLength != 0 && (txFilter == null || txFilter.length < txFilterLength)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Non-matching combination of txFilter and txFilterLength");
|
||||
}
|
||||
public Builder setTxFilter(@Nullable byte[] txFilter) {
|
||||
mTxFilter = txFilter;
|
||||
mTxFilterLength = txFilterLength;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -452,18 +336,11 @@ public class PublishConfig implements Parcelable {
|
||||
*
|
||||
* @param rxFilter The byte-array containing the LV formatted receive
|
||||
* filter.
|
||||
* @param rxFilterLength The number of bytes in the receive filter
|
||||
* argument.
|
||||
* @return The builder to facilitate chaining
|
||||
* {@code builder.setXXX(..).setXXX(..)}.
|
||||
*/
|
||||
public Builder setRxFilter(byte[] rxFilter, int rxFilterLength) {
|
||||
if (rxFilterLength != 0 && (rxFilter == null || rxFilter.length < rxFilterLength)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Non-matching combination of rxFilter and rxFilterLength");
|
||||
}
|
||||
public Builder setRxFilter(@Nullable byte[] rxFilter) {
|
||||
mRxFilter = rxFilter;
|
||||
mRxFilterLength = rxFilterLength;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -547,9 +424,8 @@ public class PublishConfig implements Parcelable {
|
||||
* builder.
|
||||
*/
|
||||
public PublishConfig build() {
|
||||
return new PublishConfig(mServiceName, mServiceSpecificInfo, mServiceSpecificInfoLength,
|
||||
mTxFilter, mTxFilterLength, mRxFilter, mRxFilterLength, mPublishType,
|
||||
mPublishCount, mTtlSec, mEnableTerminateNotification);
|
||||
return new PublishConfig(mServiceName, mServiceSpecificInfo, mTxFilter, mRxFilter,
|
||||
mPublishType, mPublishCount, mTtlSec, mEnableTerminateNotification);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,12 @@ package android.net.wifi.nan;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import libcore.util.HexEncoding;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -79,31 +82,16 @@ public class SubscribeConfig implements Parcelable {
|
||||
*/
|
||||
public final byte[] mServiceName;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public final int mServiceSpecificInfoLength;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public final byte[] mServiceSpecificInfo;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public final int mTxFilterLength;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public final byte[] mTxFilter;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public final int mRxFilterLength;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
@@ -134,16 +122,12 @@ public class SubscribeConfig implements Parcelable {
|
||||
*/
|
||||
public final boolean mEnableTerminateNotification;
|
||||
|
||||
private SubscribeConfig(byte[] serviceName, byte[] serviceSpecificInfo,
|
||||
int serviceSpecificInfoLength, byte[] txFilter, int txFilterLength, byte[] rxFilter,
|
||||
int rxFilterLength, int subscribeType, int publichCount, int ttlSec, int matchStyle,
|
||||
private SubscribeConfig(byte[] serviceName, byte[] serviceSpecificInfo, byte[] txFilter,
|
||||
byte[] rxFilter, int subscribeType, int publichCount, int ttlSec, int matchStyle,
|
||||
boolean enableTerminateNotification) {
|
||||
mServiceName = serviceName;
|
||||
mServiceSpecificInfoLength = serviceSpecificInfoLength;
|
||||
mServiceSpecificInfo = serviceSpecificInfo;
|
||||
mTxFilterLength = txFilterLength;
|
||||
mTxFilter = txFilter;
|
||||
mRxFilterLength = rxFilterLength;
|
||||
mRxFilter = rxFilter;
|
||||
mSubscribeType = subscribeType;
|
||||
mSubscribeCount = publichCount;
|
||||
@@ -154,12 +138,10 @@ public class SubscribeConfig implements Parcelable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SubscribeConfig [mServiceName='" + mServiceName + "', mServiceSpecificInfo='"
|
||||
+ (new String(mServiceSpecificInfo, 0, mServiceSpecificInfoLength))
|
||||
+ "', mTxFilter="
|
||||
+ (new TlvBufferUtils.TlvIterable(0, 1, mTxFilter, mTxFilterLength)).toString()
|
||||
+ ", mRxFilter="
|
||||
+ (new TlvBufferUtils.TlvIterable(0, 1, mRxFilter, mRxFilterLength)).toString()
|
||||
return "SubscribeConfig [mServiceName='" + mServiceName + ", mServiceSpecificInfo='" + (
|
||||
(mServiceSpecificInfo == null) ? "null" : HexEncoding.encode(mServiceSpecificInfo))
|
||||
+ ", mTxFilter=" + (new TlvBufferUtils.TlvIterable(0, 1, mTxFilter)).toString()
|
||||
+ ", mRxFilter=" + (new TlvBufferUtils.TlvIterable(0, 1, mRxFilter)).toString()
|
||||
+ ", mSubscribeType=" + mSubscribeType + ", mSubscribeCount=" + mSubscribeCount
|
||||
+ ", mTtlSec=" + mTtlSec + ", mMatchType=" + mMatchStyle
|
||||
+ ", mEnableTerminateNotification=" + mEnableTerminateNotification + "]";
|
||||
@@ -172,22 +154,10 @@ public class SubscribeConfig implements Parcelable {
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(mServiceName.length);
|
||||
if (mServiceName.length != 0) {
|
||||
dest.writeByteArray(mServiceName);
|
||||
}
|
||||
dest.writeInt(mServiceSpecificInfoLength);
|
||||
if (mServiceSpecificInfoLength != 0) {
|
||||
dest.writeByteArray(mServiceSpecificInfo, 0, mServiceSpecificInfoLength);
|
||||
}
|
||||
dest.writeInt(mTxFilterLength);
|
||||
if (mTxFilterLength != 0) {
|
||||
dest.writeByteArray(mTxFilter, 0, mTxFilterLength);
|
||||
}
|
||||
dest.writeInt(mRxFilterLength);
|
||||
if (mRxFilterLength != 0) {
|
||||
dest.writeByteArray(mRxFilter, 0, mRxFilterLength);
|
||||
}
|
||||
dest.writeByteArray(mServiceName);
|
||||
dest.writeByteArray(mServiceSpecificInfo);
|
||||
dest.writeByteArray(mTxFilter);
|
||||
dest.writeByteArray(mRxFilter);
|
||||
dest.writeInt(mSubscribeType);
|
||||
dest.writeInt(mSubscribeCount);
|
||||
dest.writeInt(mTtlSec);
|
||||
@@ -203,35 +173,18 @@ public class SubscribeConfig implements Parcelable {
|
||||
|
||||
@Override
|
||||
public SubscribeConfig createFromParcel(Parcel in) {
|
||||
int serviceNameLength = in.readInt();
|
||||
byte[] serviceName = new byte[serviceNameLength];
|
||||
if (serviceNameLength != 0) {
|
||||
in.readByteArray(serviceName);
|
||||
}
|
||||
int ssiLength = in.readInt();
|
||||
byte[] ssi = new byte[ssiLength];
|
||||
if (ssiLength != 0) {
|
||||
in.readByteArray(ssi);
|
||||
}
|
||||
int txFilterLength = in.readInt();
|
||||
byte[] txFilter = new byte[txFilterLength];
|
||||
if (txFilterLength != 0) {
|
||||
in.readByteArray(txFilter);
|
||||
}
|
||||
int rxFilterLength = in.readInt();
|
||||
byte[] rxFilter = new byte[rxFilterLength];
|
||||
if (rxFilterLength != 0) {
|
||||
in.readByteArray(rxFilter);
|
||||
}
|
||||
byte[] serviceName = in.createByteArray();
|
||||
byte[] ssi = in.createByteArray();
|
||||
byte[] txFilter = in.createByteArray();
|
||||
byte[] rxFilter = in.createByteArray();
|
||||
int subscribeType = in.readInt();
|
||||
int subscribeCount = in.readInt();
|
||||
int ttlSec = in.readInt();
|
||||
int matchStyle = in.readInt();
|
||||
boolean enableTerminateNotification = in.readInt() != 0;
|
||||
|
||||
return new SubscribeConfig(serviceName, ssi, ssiLength, txFilter, txFilterLength,
|
||||
rxFilter, rxFilterLength, subscribeType, subscribeCount, ttlSec, matchStyle,
|
||||
enableTerminateNotification);
|
||||
return new SubscribeConfig(serviceName, ssi, txFilter, rxFilter, subscribeType,
|
||||
subscribeCount, ttlSec, matchStyle, enableTerminateNotification);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -247,45 +200,11 @@ public class SubscribeConfig implements Parcelable {
|
||||
|
||||
SubscribeConfig lhs = (SubscribeConfig) o;
|
||||
|
||||
if (!Arrays.equals(mServiceName, lhs.mServiceName)
|
||||
|| mServiceSpecificInfoLength != lhs.mServiceSpecificInfoLength
|
||||
|| mTxFilterLength != lhs.mTxFilterLength
|
||||
|| mRxFilterLength != lhs.mRxFilterLength) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mServiceSpecificInfo != null && lhs.mServiceSpecificInfo != null) {
|
||||
for (int i = 0; i < mServiceSpecificInfoLength; ++i) {
|
||||
if (mServiceSpecificInfo[i] != lhs.mServiceSpecificInfo[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else if (mServiceSpecificInfoLength != 0) {
|
||||
return false; // invalid != invalid
|
||||
}
|
||||
|
||||
if (mTxFilter != null && lhs.mTxFilter != null) {
|
||||
for (int i = 0; i < mTxFilterLength; ++i) {
|
||||
if (mTxFilter[i] != lhs.mTxFilter[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else if (mTxFilterLength != 0) {
|
||||
return false; // invalid != invalid
|
||||
}
|
||||
|
||||
if (mRxFilter != null && lhs.mRxFilter != null) {
|
||||
for (int i = 0; i < mRxFilterLength; ++i) {
|
||||
if (mRxFilter[i] != lhs.mRxFilter[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else if (mRxFilterLength != 0) {
|
||||
return false; // invalid != invalid
|
||||
}
|
||||
|
||||
return mSubscribeType == lhs.mSubscribeType && mSubscribeCount == lhs.mSubscribeCount
|
||||
&& mTtlSec == lhs.mTtlSec && mMatchStyle == lhs.mMatchStyle
|
||||
return Arrays.equals(mServiceName, lhs.mServiceName) && Arrays.equals(mServiceSpecificInfo,
|
||||
lhs.mServiceSpecificInfo) && Arrays.equals(mTxFilter, lhs.mTxFilter)
|
||||
&& Arrays.equals(mRxFilter, lhs.mRxFilter) && mSubscribeType == lhs.mSubscribeType
|
||||
&& mSubscribeCount == lhs.mSubscribeCount && mTtlSec == lhs.mTtlSec
|
||||
&& mMatchStyle == lhs.mMatchStyle
|
||||
&& mEnableTerminateNotification == lhs.mEnableTerminateNotification;
|
||||
}
|
||||
|
||||
@@ -294,11 +213,8 @@ public class SubscribeConfig implements Parcelable {
|
||||
int result = 17;
|
||||
|
||||
result = 31 * result + Arrays.hashCode(mServiceName);
|
||||
result = 31 * result + mServiceSpecificInfoLength;
|
||||
result = 31 * result + Arrays.hashCode(mServiceSpecificInfo);
|
||||
result = 31 * result + mTxFilterLength;
|
||||
result = 31 * result + Arrays.hashCode(mTxFilter);
|
||||
result = 31 * result + mRxFilterLength;
|
||||
result = 31 * result + Arrays.hashCode(mRxFilter);
|
||||
result = 31 * result + mSubscribeType;
|
||||
result = 31 * result + mSubscribeCount;
|
||||
@@ -318,24 +234,11 @@ public class SubscribeConfig implements Parcelable {
|
||||
public void validate() throws IllegalArgumentException {
|
||||
WifiNanUtils.validateServiceName(mServiceName);
|
||||
|
||||
if (mServiceSpecificInfoLength != 0 && (mServiceSpecificInfo == null
|
||||
|| mServiceSpecificInfo.length < mServiceSpecificInfoLength)) {
|
||||
throw new IllegalArgumentException("Non-matching combination of "
|
||||
+ "serviceSpecificInfo and serviceSpecificInfoLength");
|
||||
}
|
||||
if (mTxFilterLength != 0 && (mTxFilter == null || mTxFilter.length < mTxFilterLength)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Non-matching combination of txFilter and txFilterLength");
|
||||
}
|
||||
if (!TlvBufferUtils.isValid(mTxFilter, mTxFilterLength, 0, 1)) {
|
||||
if (!TlvBufferUtils.isValid(mTxFilter, 0, 1)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid txFilter configuration - LV fields do not match up to length");
|
||||
}
|
||||
if (mRxFilterLength != 0 && (mRxFilter == null || mRxFilter.length < mRxFilterLength)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Non-matching combination of rxFilter and rxFilterLength");
|
||||
}
|
||||
if (!TlvBufferUtils.isValid(mRxFilter, mRxFilterLength, 0, 1)) {
|
||||
if (!TlvBufferUtils.isValid(mRxFilter, 0, 1)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid rxFilter configuration - LV fields do not match up to length");
|
||||
}
|
||||
@@ -352,11 +255,13 @@ public class SubscribeConfig implements Parcelable {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid matchType - must be MATCH_FIRST_ONLY or MATCH_ALL");
|
||||
}
|
||||
if (mSubscribeType == SubscribeConfig.SUBSCRIBE_TYPE_ACTIVE && mRxFilterLength != 0) {
|
||||
if (mSubscribeType == SubscribeConfig.SUBSCRIBE_TYPE_ACTIVE && mRxFilter != null
|
||||
&& mRxFilter.length != 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid subscribe config: ACTIVE subscribes can't have an Rx filter");
|
||||
}
|
||||
if (mSubscribeType == SubscribeConfig.SUBSCRIBE_TYPE_PASSIVE && mTxFilterLength != 0) {
|
||||
if (mSubscribeType == SubscribeConfig.SUBSCRIBE_TYPE_PASSIVE && mTxFilter != null
|
||||
&& mTxFilter.length != 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid subscribe config: PASSIVE subscribes can't have a Tx filter");
|
||||
}
|
||||
@@ -367,12 +272,9 @@ public class SubscribeConfig implements Parcelable {
|
||||
*/
|
||||
public static final class Builder {
|
||||
private byte[] mServiceName;
|
||||
private int mServiceSpecificInfoLength;
|
||||
private byte[] mServiceSpecificInfo = new byte[0];
|
||||
private int mTxFilterLength;
|
||||
private byte[] mTxFilter = new byte[0];
|
||||
private int mRxFilterLength;
|
||||
private byte[] mRxFilter = new byte[0];
|
||||
private byte[] mServiceSpecificInfo;
|
||||
private byte[] mTxFilter;
|
||||
private byte[] mRxFilter;
|
||||
private int mSubscribeType = SUBSCRIBE_TYPE_PASSIVE;
|
||||
private int mSubscribeCount = 0;
|
||||
private int mTtlSec = 0;
|
||||
@@ -409,19 +311,10 @@ public class SubscribeConfig implements Parcelable {
|
||||
*
|
||||
* @param serviceSpecificInfo A byte-array for the service-specific
|
||||
* information field.
|
||||
* @param serviceSpecificInfoLength The length of the byte-array to be
|
||||
* used.
|
||||
* @return The builder to facilitate chaining
|
||||
* {@code builder.setXXX(..).setXXX(..)}.
|
||||
*/
|
||||
public Builder setServiceSpecificInfo(byte[] serviceSpecificInfo,
|
||||
int serviceSpecificInfoLength) {
|
||||
if (serviceSpecificInfoLength != 0 && (serviceSpecificInfo == null
|
||||
|| serviceSpecificInfo.length < serviceSpecificInfoLength)) {
|
||||
throw new IllegalArgumentException("Non-matching combination of "
|
||||
+ "serviceSpecificInfo and serviceSpecificInfoLength");
|
||||
}
|
||||
mServiceSpecificInfoLength = serviceSpecificInfoLength;
|
||||
public Builder setServiceSpecificInfo(@Nullable byte[] serviceSpecificInfo) {
|
||||
mServiceSpecificInfo = serviceSpecificInfo;
|
||||
return this;
|
||||
}
|
||||
@@ -429,7 +322,7 @@ public class SubscribeConfig implements Parcelable {
|
||||
/**
|
||||
* Specify service specific information for the subscribe session - same
|
||||
* as
|
||||
* {@link SubscribeConfig.Builder#setServiceSpecificInfo(byte[], int)}
|
||||
* {@link SubscribeConfig.Builder#setServiceSpecificInfo(byte[])}
|
||||
* but obtaining the data from a String.
|
||||
*
|
||||
* @param serviceSpecificInfoStr The service specific information string
|
||||
@@ -440,7 +333,6 @@ public class SubscribeConfig implements Parcelable {
|
||||
*/
|
||||
public Builder setServiceSpecificInfo(@NonNull String serviceSpecificInfoStr) {
|
||||
mServiceSpecificInfo = serviceSpecificInfoStr.getBytes();
|
||||
mServiceSpecificInfoLength = mServiceSpecificInfo.length;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -457,18 +349,11 @@ public class SubscribeConfig implements Parcelable {
|
||||
*
|
||||
* @param txFilter The byte-array containing the LV formatted transmit
|
||||
* filter.
|
||||
* @param txFilterLength The number of bytes in the transmit filter
|
||||
* argument.
|
||||
* @return The builder to facilitate chaining
|
||||
* {@code builder.setXXX(..).setXXX(..)}.
|
||||
*/
|
||||
public Builder setTxFilter(byte[] txFilter, int txFilterLength) {
|
||||
if (txFilterLength != 0 && (txFilter == null || txFilter.length < txFilterLength)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Non-matching combination of txFilter and txFilterLength");
|
||||
}
|
||||
public Builder setTxFilter(@Nullable byte[] txFilter) {
|
||||
mTxFilter = txFilter;
|
||||
mTxFilterLength = txFilterLength;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -484,18 +369,11 @@ public class SubscribeConfig implements Parcelable {
|
||||
*
|
||||
* @param rxFilter The byte-array containing the LV formatted receive
|
||||
* filter.
|
||||
* @param rxFilterLength The number of bytes in the receive filter
|
||||
* argument.
|
||||
* @return The builder to facilitate chaining
|
||||
* {@code builder.setXXX(..).setXXX(..)}.
|
||||
*/
|
||||
public Builder setRxFilter(byte[] rxFilter, int rxFilterLength) {
|
||||
if (rxFilterLength != 0 && (rxFilter == null || rxFilter.length < rxFilterLength)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Non-matching combination of rxFilter and rxFilterLength");
|
||||
}
|
||||
public Builder setRxFilter(@Nullable byte[] rxFilter) {
|
||||
mRxFilter = rxFilter;
|
||||
mRxFilterLength = rxFilterLength;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -563,7 +441,7 @@ public class SubscribeConfig implements Parcelable {
|
||||
* 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)}
|
||||
* {@link WifiNanSessionCallback#onMatch(int, byte[], byte[])}
|
||||
* ). 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}.
|
||||
@@ -601,9 +479,8 @@ public class SubscribeConfig implements Parcelable {
|
||||
* builder.
|
||||
*/
|
||||
public SubscribeConfig build() {
|
||||
return new SubscribeConfig(mServiceName, mServiceSpecificInfo,
|
||||
mServiceSpecificInfoLength, mTxFilter, mTxFilterLength, mRxFilter,
|
||||
mRxFilterLength, mSubscribeType, mSubscribeCount, mTtlSec, mMatchStyle,
|
||||
return new SubscribeConfig(mServiceName, mServiceSpecificInfo, mTxFilter, mRxFilter,
|
||||
mSubscribeType, mSubscribeCount, mTtlSec, mMatchStyle,
|
||||
mEnableTerminateNotification);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,13 @@
|
||||
|
||||
package android.net.wifi.nan;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
|
||||
import libcore.io.Memory;
|
||||
|
||||
import java.nio.BufferOverflowException;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
@@ -50,8 +53,7 @@ public class TlvBufferUtils {
|
||||
* Values are added to the structure using the {@code TlvConstructor.put*()}
|
||||
* methods.
|
||||
* <p>
|
||||
* The final byte array is obtained using {@link TlvConstructor#getArray()}
|
||||
* and {@link TlvConstructor#getActualLength()} methods.
|
||||
* The final byte array is obtained using {@link TlvConstructor#getArray()}.
|
||||
*/
|
||||
public static class TlvConstructor {
|
||||
private int mTypeSize;
|
||||
@@ -88,9 +90,9 @@ public class TlvBufferUtils {
|
||||
* @return The constructor to facilitate chaining
|
||||
* {@code ctr.putXXX(..).putXXX(..)}.
|
||||
*/
|
||||
public TlvConstructor wrap(byte[] array) {
|
||||
public TlvConstructor wrap(@Nullable byte[] array) {
|
||||
mArray = array;
|
||||
mArrayLength = array.length;
|
||||
mArrayLength = (array == null) ? 0 : array.length;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -137,10 +139,13 @@ public class TlvBufferUtils {
|
||||
* @return The constructor to facilitate chaining
|
||||
* {@code ctr.putXXX(..).putXXX(..)}.
|
||||
*/
|
||||
public TlvConstructor putByteArray(int type, byte[] array, int offset, int length) {
|
||||
public TlvConstructor putByteArray(int type, @Nullable byte[] array, int offset,
|
||||
int length) {
|
||||
checkLength(length);
|
||||
addHeader(type, length);
|
||||
System.arraycopy(array, offset, mArray, mPosition, length);
|
||||
if (length != 0) {
|
||||
System.arraycopy(array, offset, mArray, mPosition, length);
|
||||
}
|
||||
mPosition += length;
|
||||
return this;
|
||||
}
|
||||
@@ -155,8 +160,8 @@ public class TlvBufferUtils {
|
||||
* @return The constructor to facilitate chaining
|
||||
* {@code ctr.putXXX(..).putXXX(..)}.
|
||||
*/
|
||||
public TlvConstructor putByteArray(int type, byte[] array) {
|
||||
return putByteArray(type, array, 0, array.length);
|
||||
public TlvConstructor putByteArray(int type, @Nullable byte[] array) {
|
||||
return putByteArray(type, array, 0, (array == null) ? 0 : array.length);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -223,24 +228,25 @@ public class TlvBufferUtils {
|
||||
* @return The constructor to facilitate chaining
|
||||
* {@code ctr.putXXX(..).putXXX(..)}.
|
||||
*/
|
||||
public TlvConstructor putString(int type, String data) {
|
||||
byte[] bytes = data.getBytes();
|
||||
return putByteArray(type, bytes, 0, bytes.length);
|
||||
public TlvConstructor putString(int type, @Nullable String data) {
|
||||
byte[] bytes = null;
|
||||
int length = 0;
|
||||
if (data != null) {
|
||||
bytes = data.getBytes();
|
||||
length = bytes.length;
|
||||
}
|
||||
return putByteArray(type, bytes, 0, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the constructed TLV formatted byte-array. Note that the
|
||||
* returned array is the fully wrapped (
|
||||
* {@link TlvConstructor#wrap(byte[])}) or allocated (
|
||||
* {@link TlvConstructor#allocate(int)}) array - which isn't necessarily
|
||||
* the actual size of the formatted data. Use
|
||||
* {@link TlvConstructor#getActualLength()} to obtain the size of the
|
||||
* formatted data.
|
||||
* Returns the constructed TLV formatted byte-array. This array is a copy of the wrapped
|
||||
* or allocated array - truncated to just the significant bytes - i.e. those written into
|
||||
* the (T)LV.
|
||||
*
|
||||
* @return The byte array containing the TLV formatted structure.
|
||||
*/
|
||||
public byte[] getArray() {
|
||||
return mArray;
|
||||
return Arrays.copyOf(mArray, getActualLength());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -250,7 +256,7 @@ public class TlvBufferUtils {
|
||||
*
|
||||
* @return The size of the TLV formatted portion of the byte array.
|
||||
*/
|
||||
public int getActualLength() {
|
||||
private int getActualLength() {
|
||||
return mPosition;
|
||||
}
|
||||
|
||||
@@ -307,7 +313,7 @@ public class TlvBufferUtils {
|
||||
*/
|
||||
public int mOffset;
|
||||
|
||||
private TlvElement(int type, int length, byte[] refArray, int offset) {
|
||||
private TlvElement(int type, int length, @Nullable byte[] refArray, int offset) {
|
||||
mType = type;
|
||||
mLength = length;
|
||||
mRefArray = refArray;
|
||||
@@ -389,10 +395,8 @@ public class TlvBufferUtils {
|
||||
* @param lengthSize Number of bytes sued for the Length (L) field.
|
||||
* Values values are 1 or 2 bytes.
|
||||
* @param array The TLV formatted byte-array to parse.
|
||||
* @param length The number of bytes of the array to be used in the
|
||||
* parsing.
|
||||
*/
|
||||
public TlvIterable(int typeSize, int lengthSize, byte[] array, int length) {
|
||||
public TlvIterable(int typeSize, int lengthSize, @Nullable byte[] array) {
|
||||
if (typeSize < 0 || typeSize > 2 || lengthSize <= 0 || lengthSize > 2) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid sizes - typeSize=" + typeSize + ", lengthSize=" + lengthSize);
|
||||
@@ -400,7 +404,7 @@ public class TlvBufferUtils {
|
||||
mTypeSize = typeSize;
|
||||
mLengthSize = lengthSize;
|
||||
mArray = array;
|
||||
mArrayLength = length;
|
||||
mArrayLength = (array == null) ? 0 : array.length;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -494,12 +498,11 @@ public class TlvBufferUtils {
|
||||
* fields correctly fill the specified length (and do not overshoot).
|
||||
*
|
||||
* @param array The (T)LV array to verify.
|
||||
* @param length The number of bytes in the array to consider (starting at offset 0).
|
||||
* @param typeSize The size (in bytes) of the type field. Valid values are 0, 1, or 2.
|
||||
* @param lengthSize The size (in bytes) of the length field. Valid values are 1 or 2.
|
||||
* @return A boolean indicating whether the array is valid (true) or invalid (false).
|
||||
*/
|
||||
public static boolean isValid(byte[] array, int length, int typeSize, int lengthSize) {
|
||||
public static boolean isValid(@Nullable byte[] array, int typeSize, int lengthSize) {
|
||||
if (typeSize < 0 || typeSize > 2) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid arguments - typeSize must be 0, 1, or 2: typeSize=" + typeSize);
|
||||
@@ -508,14 +511,12 @@ public class TlvBufferUtils {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid arguments - lengthSize must be 1 or 2: lengthSize=" + lengthSize);
|
||||
}
|
||||
if (length < 0 || length > array.length) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid arguments - length must be non-negative and <= array.length: length="
|
||||
+ length + ", array.length=" + array.length);
|
||||
if (array == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int nextTlvIndex = 0;
|
||||
while (nextTlvIndex + typeSize + lengthSize <= length) {
|
||||
while (nextTlvIndex + typeSize + lengthSize <= array.length) {
|
||||
nextTlvIndex += typeSize;
|
||||
if (lengthSize == 1) {
|
||||
nextTlvIndex += lengthSize + array[nextTlvIndex];
|
||||
@@ -525,6 +526,6 @@ public class TlvBufferUtils {
|
||||
}
|
||||
}
|
||||
|
||||
return nextTlvIndex == length;
|
||||
return nextTlvIndex == array.length;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ import android.annotation.Nullable;
|
||||
import android.annotation.SdkConstant;
|
||||
import android.annotation.SdkConstant.SdkConstantType;
|
||||
import android.annotation.SystemApi;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkRequest;
|
||||
import android.net.wifi.RttManager;
|
||||
import android.os.Binder;
|
||||
import android.os.Bundle;
|
||||
@@ -205,15 +207,15 @@ public class WifiNanManager {
|
||||
|
||||
/**
|
||||
* Data-path creation role is that of INITIATOR. Used in
|
||||
* {@link #createNetworkSpecifier(int, byte[], byte[], int)} and
|
||||
* {@link WifiNanSession#createNetworkSpecifier(int, int, byte[], int)}.
|
||||
* {@link #createNetworkSpecifier(int, byte[], byte[])} and
|
||||
* {@link WifiNanSession#createNetworkSpecifier(int, int, byte[])}.
|
||||
*/
|
||||
public static final int WIFI_NAN_DATA_PATH_ROLE_INITIATOR = 0;
|
||||
|
||||
/**
|
||||
* Data-path creation role is that of RESPONDER. Used in
|
||||
* {@link #createNetworkSpecifier(int, byte[], byte[], int)} and
|
||||
* {@link WifiNanSession#createNetworkSpecifier(int, int, byte[], int)}.
|
||||
* {@link #createNetworkSpecifier(int, byte[], byte[])} and
|
||||
* {@link WifiNanSession#createNetworkSpecifier(int, int, byte[])}.
|
||||
*/
|
||||
|
||||
public static final int WIFI_NAN_DATA_PATH_ROLE_RESPONDER = 1;
|
||||
@@ -524,12 +526,11 @@ public class WifiNanManager {
|
||||
/**
|
||||
* {@hide}
|
||||
*/
|
||||
public void sendMessage(int sessionId, int peerId, byte[] message, int messageLength,
|
||||
int messageId, int retryCount) {
|
||||
public void sendMessage(int sessionId, int peerId, byte[] message, int messageId,
|
||||
int retryCount) {
|
||||
if (VDBG) {
|
||||
Log.v(TAG, "sendMessage(): sessionId=" + sessionId + ", peerId=" + peerId
|
||||
+ ", messageLength=" + messageLength + ", messageId=" + messageId
|
||||
+ ", retryCount=" + retryCount);
|
||||
+ ", messageId=" + messageId + ", retryCount=" + retryCount);
|
||||
}
|
||||
|
||||
int clientId;
|
||||
@@ -543,8 +544,7 @@ public class WifiNanManager {
|
||||
}
|
||||
|
||||
try {
|
||||
mService.sendMessage(clientId, sessionId, peerId, message, messageLength, messageId,
|
||||
retryCount);
|
||||
mService.sendMessage(clientId, sessionId, peerId, message, messageId, retryCount);
|
||||
} catch (RemoteException e) {
|
||||
e.rethrowAsRuntimeException();
|
||||
}
|
||||
@@ -587,10 +587,10 @@ public class WifiNanManager {
|
||||
* {@hide}
|
||||
*/
|
||||
public String createNetworkSpecifier(@DataPathRole int role, int sessionId, int peerId,
|
||||
byte[] token, int tokenLength) {
|
||||
byte[] token) {
|
||||
if (VDBG) {
|
||||
Log.v(TAG, "createNetworkSpecifier: role=" + role + ", sessionId=" + sessionId
|
||||
+ ", peerId=" + peerId + ", token=" + token + ", tokenLength=" + tokenLength);
|
||||
+ ", peerId=" + peerId + ", token=" + token);
|
||||
}
|
||||
|
||||
int type;
|
||||
@@ -621,10 +621,6 @@ public class WifiNanManager {
|
||||
+ "INITIATOR");
|
||||
}
|
||||
}
|
||||
if (tokenLength != 0 && (token == null || token.length < tokenLength)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Non-matching combination of token and tokenLength");
|
||||
}
|
||||
|
||||
int clientId;
|
||||
synchronized (mLock) {
|
||||
@@ -650,7 +646,7 @@ public class WifiNanManager {
|
||||
}
|
||||
if (token != null) {
|
||||
json.put(NETWORK_SPECIFIER_KEY_TOKEN,
|
||||
Base64.encodeToString(token, 0, tokenLength, Base64.DEFAULT));
|
||||
Base64.encodeToString(token, 0, token.length, Base64.DEFAULT));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
return "";
|
||||
@@ -674,19 +670,15 @@ public class WifiNanManager {
|
||||
* data-path setup process. On the RESPONDER a null token is permitted and
|
||||
* matches any peer token - an empty token requires the peer token to be empty
|
||||
* as well.
|
||||
* @param tokenLength The number of significant (usable) bytes from the {@code token} parameter.
|
||||
* @return A string to be used to construct
|
||||
* {@link android.net.NetworkRequest.Builder#setNetworkSpecifier(String)} to pass to {@link
|
||||
* android.net.ConnectivityManager#requestNetwork(NetworkRequest,
|
||||
* ConnectivityManager.NetworkCallback)}
|
||||
* [or other varierties of that API].
|
||||
* android.net.ConnectivityManager#requestNetwork(NetworkRequest, ConnectivityManager.NetworkCallback)}
|
||||
* [or other varieties of that API].
|
||||
*/
|
||||
public String createNetworkSpecifier(@DataPathRole int role, @Nullable byte[] peer,
|
||||
@Nullable byte[] token, int tokenLength) {
|
||||
@Nullable byte[] token) {
|
||||
if (VDBG) {
|
||||
Log.v(TAG,
|
||||
"createNetworkSpecifier: role=" + role + ", token=" + token + ", tokenLength="
|
||||
+ tokenLength);
|
||||
Log.v(TAG, "createNetworkSpecifier: role=" + role + ", token=" + token);
|
||||
}
|
||||
|
||||
int type;
|
||||
@@ -721,10 +713,6 @@ public class WifiNanManager {
|
||||
"createNetworkSpecifier: Invalid peer MAC address");
|
||||
}
|
||||
}
|
||||
if (tokenLength != 0 && (token == null || token.length < tokenLength)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Non-matching combination of token and tokenLength");
|
||||
}
|
||||
|
||||
int clientId;
|
||||
synchronized (mLock) {
|
||||
@@ -749,7 +737,7 @@ public class WifiNanManager {
|
||||
}
|
||||
if (token != null) {
|
||||
json.put(NETWORK_SPECIFIER_KEY_TOKEN,
|
||||
Base64.encodeToString(token, 0, tokenLength, Base64.DEFAULT));
|
||||
Base64.encodeToString(token, 0, token.length, Base64.DEFAULT));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
return "";
|
||||
@@ -932,7 +920,6 @@ public class WifiNanManager {
|
||||
private static final int CALLBACK_MESSAGE_SEND_FAIL = 6;
|
||||
private static final int CALLBACK_MESSAGE_RECEIVED = 7;
|
||||
|
||||
private static final String MESSAGE_BUNDLE_KEY_PEER_ID = "peer_id";
|
||||
private static final String MESSAGE_BUNDLE_KEY_MESSAGE = "message";
|
||||
private static final String MESSAGE_BUNDLE_KEY_MESSAGE2 = "message2";
|
||||
|
||||
@@ -983,11 +970,9 @@ public class WifiNanManager {
|
||||
break;
|
||||
case CALLBACK_MATCH:
|
||||
mOriginalCallback.onMatch(
|
||||
msg.getData().getInt(MESSAGE_BUNDLE_KEY_PEER_ID),
|
||||
msg.getData().getByteArray(MESSAGE_BUNDLE_KEY_MESSAGE),
|
||||
msg.arg1,
|
||||
msg.getData().getByteArray(MESSAGE_BUNDLE_KEY_MESSAGE2),
|
||||
msg.arg2);
|
||||
msg.getData().getByteArray(MESSAGE_BUNDLE_KEY_MESSAGE),
|
||||
msg.getData().getByteArray(MESSAGE_BUNDLE_KEY_MESSAGE2));
|
||||
break;
|
||||
case CALLBACK_MESSAGE_SEND_SUCCESS:
|
||||
mOriginalCallback.onMessageSendSuccess(msg.arg1);
|
||||
@@ -996,9 +981,7 @@ public class WifiNanManager {
|
||||
mOriginalCallback.onMessageSendFail(msg.arg1, msg.arg2);
|
||||
break;
|
||||
case CALLBACK_MESSAGE_RECEIVED:
|
||||
mOriginalCallback.onMessageReceived(msg.arg2,
|
||||
msg.getData().getByteArray(MESSAGE_BUNDLE_KEY_MESSAGE),
|
||||
msg.arg1);
|
||||
mOriginalCallback.onMessageReceived(msg.arg1, (byte[]) msg.obj);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1041,18 +1024,15 @@ public class WifiNanManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMatch(int peerId, byte[] serviceSpecificInfo,
|
||||
int serviceSpecificInfoLength, byte[] matchFilter, int matchFilterLength) {
|
||||
public void onMatch(int peerId, byte[] serviceSpecificInfo, byte[] matchFilter) {
|
||||
if (VDBG) Log.v(TAG, "onMatch: peerId=" + peerId);
|
||||
|
||||
Bundle data = new Bundle();
|
||||
data.putInt(MESSAGE_BUNDLE_KEY_PEER_ID, peerId);
|
||||
data.putByteArray(MESSAGE_BUNDLE_KEY_MESSAGE, serviceSpecificInfo);
|
||||
data.putByteArray(MESSAGE_BUNDLE_KEY_MESSAGE2, matchFilter);
|
||||
|
||||
Message msg = mHandler.obtainMessage(CALLBACK_MATCH);
|
||||
msg.arg1 = serviceSpecificInfoLength;
|
||||
msg.arg2 = matchFilterLength;
|
||||
msg.arg1 = peerId;
|
||||
msg.setData(data);
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
@@ -1077,19 +1057,14 @@ public class WifiNanManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(int peerId, byte[] message, int messageLength) {
|
||||
public void onMessageReceived(int peerId, byte[] message) {
|
||||
if (VDBG) {
|
||||
Log.v(TAG, "onMessageReceived: peerId='" + peerId + "', messageLength="
|
||||
+ messageLength);
|
||||
Log.v(TAG, "onMessageReceived: peerId='" + peerId);
|
||||
}
|
||||
|
||||
Bundle data = new Bundle();
|
||||
data.putByteArray(MESSAGE_BUNDLE_KEY_MESSAGE, message);
|
||||
|
||||
Message msg = mHandler.obtainMessage(CALLBACK_MESSAGE_RECEIVED);
|
||||
msg.arg1 = messageLength;
|
||||
msg.arg2 = peerId;
|
||||
msg.setData(data);
|
||||
msg.arg1 = peerId;
|
||||
msg.obj = message;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
|
||||
|
||||
@@ -108,12 +108,11 @@ public class WifiNanSession {
|
||||
/**
|
||||
* Sends a message to the specified destination. Message transmission is part of the current
|
||||
* discovery session - i.e. executed subsequent to a publish/subscribe
|
||||
* {@link WifiNanSessionCallback#onMatch(int, byte[], int, byte[], int)} event.
|
||||
* {@link WifiNanSessionCallback#onMatch(int, byte[], byte[])} event.
|
||||
*
|
||||
* @param peerId The peer's ID for the message. Must be a result of an
|
||||
* {@link WifiNanSessionCallback#onMatch(int, byte[], int, byte[], int)} event.
|
||||
* {@link WifiNanSessionCallback#onMatch(int, byte[], byte[])} event.
|
||||
* @param message The message to be transmitted.
|
||||
* @param messageLength The number of bytes from the {@code message} to be transmitted.
|
||||
* @param messageId An arbitrary integer used by the caller to identify the message. The same
|
||||
* integer ID will be returned in the callbacks indicated message send success or
|
||||
* failure.
|
||||
@@ -122,8 +121,7 @@ public class WifiNanSession {
|
||||
* (note: no retransmissions are attempted in other failure cases). A value of 0
|
||||
* indicates no retries. Max possible value is {@link #MAX_SEND_RETRY_COUNT}.
|
||||
*/
|
||||
public void sendMessage(int peerId, byte[] message, int messageLength, int messageId,
|
||||
int retryCount) {
|
||||
public void sendMessage(int peerId, @Nullable byte[] message, int messageId, int retryCount) {
|
||||
if (mTerminated) {
|
||||
Log.w(TAG, "sendMessage: called on terminated session");
|
||||
return;
|
||||
@@ -134,33 +132,32 @@ public class WifiNanSession {
|
||||
return;
|
||||
}
|
||||
|
||||
mgr.sendMessage(mSessionId, peerId, message, messageLength, messageId, retryCount);
|
||||
mgr.sendMessage(mSessionId, peerId, message, messageId, retryCount);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to the specified destination. Message transmission is part of the current
|
||||
* discovery session - i.e. executed subsequent to a publish/subscribe
|
||||
* {@link WifiNanSessionCallback#onMatch(int, byte[], int, byte[], int)} event. This is
|
||||
* equivalent to {@link #sendMessage(int, byte[], int, int, int)} with a {@code retryCount} of
|
||||
* {@link WifiNanSessionCallback#onMatch(int, byte[], byte[])} event. This is
|
||||
* equivalent to {@link #sendMessage(int, byte[], int, int)} with a {@code retryCount} of
|
||||
* 0.
|
||||
*
|
||||
* @param peerId The peer's ID for the message. Must be a result of an
|
||||
* {@link WifiNanSessionCallback#onMatch(int, byte[], int, byte[], int)} event.
|
||||
* {@link WifiNanSessionCallback#onMatch(int, byte[], byte[])} event.
|
||||
* @param message The message to be transmitted.
|
||||
* @param messageLength The number of bytes from the {@code message} to be transmitted.
|
||||
* @param messageId An arbitrary integer used by the caller to identify the message. The same
|
||||
* integer ID will be returned in the callbacks indicated message send success or
|
||||
* failure.
|
||||
*/
|
||||
public void sendMessage(int peerId, byte[] message, int messageLength, int messageId) {
|
||||
sendMessage(peerId, message, messageLength, messageId, 0);
|
||||
public void sendMessage(int peerId, @Nullable byte[] message, int messageId) {
|
||||
sendMessage(peerId, message, messageId, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a ranging operation with the specified peers. The peer IDs are obtained from an
|
||||
* {@link WifiNanSessionCallback#onMatch(int, byte[], int, byte[], int)} or
|
||||
* {@link WifiNanSessionCallback#onMessageReceived(int, byte[], int)} operation - i.e. can only
|
||||
* {@link WifiNanSessionCallback#onMatch(int, byte[], byte[])} or
|
||||
* {@link WifiNanSessionCallback#onMessageReceived(int, byte[])} operation - i.e. can only
|
||||
* range devices which are part of an ongoing discovery session.
|
||||
*
|
||||
* @param params RTT parameters - each corresponding to a specific peer ID (the array sizes
|
||||
@@ -194,22 +191,20 @@ public class WifiNanSession {
|
||||
* {@link WifiNanManager#WIFI_NAN_DATA_PATH_ROLE_INITIATOR} or
|
||||
* {@link WifiNanManager#WIFI_NAN_DATA_PATH_ROLE_RESPONDER}
|
||||
* @param peerId The peer ID obtained through
|
||||
* {@link WifiNanSessionCallback#onMatch(int, byte[], int, byte[], int)} or
|
||||
* {@link WifiNanSessionCallback#onMessageReceived(int, byte[], int)}. On the RESPONDER a
|
||||
* {@link WifiNanSessionCallback#onMatch(int, byte[], byte[])} or
|
||||
* {@link WifiNanSessionCallback#onMessageReceived(int, byte[])}. On the RESPONDER a
|
||||
* value of 0 is permitted which matches any peer.
|
||||
* @param token An arbitrary token (message) to be passed to the peer as part of the
|
||||
* data-path setup process. On the RESPONDER a null token is permitted and
|
||||
* matches any peer token - an empty token requires the peer token to be empty
|
||||
* as well.
|
||||
* @param tokenLength The number of significant (usable) bytes from the {@code token} parameter.
|
||||
* @return A string to be used to construct
|
||||
* {@link android.net.NetworkRequest.Builder#setNetworkSpecifier(String)} to pass to {@link
|
||||
* android.net.ConnectivityManager#requestNetwork(NetworkRequest,
|
||||
* ConnectivityManager.NetworkCallback)}
|
||||
* [or other varierties of that API].
|
||||
* ConnectivityManager.NetworkCallback)} [or other varieties of that API].
|
||||
*/
|
||||
public String createNetworkSpecifier(@WifiNanManager.DataPathRole int role, int peerId,
|
||||
@Nullable byte[] token, int tokenLength) {
|
||||
@Nullable byte[] token) {
|
||||
if (mTerminated) {
|
||||
Log.w(TAG, "createNetworkSpecifier: called on terminated session");
|
||||
return null;
|
||||
@@ -220,7 +215,7 @@ public class WifiNanSession {
|
||||
return null;
|
||||
}
|
||||
|
||||
return mgr.createNetworkSpecifier(role, mSessionId, peerId, token, tokenLength);
|
||||
return mgr.createNetworkSpecifier(role, mSessionId, peerId, token);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,14 +156,10 @@ public class WifiNanSessionCallback {
|
||||
* @param serviceSpecificInfo The service specific information (arbitrary
|
||||
* byte array) provided by the peer as part of its discovery
|
||||
* packet.
|
||||
* @param serviceSpecificInfoLength The length of the service specific
|
||||
* information array.
|
||||
* @param matchFilter The filter (Tx on advertiser and Rx on listener) which
|
||||
* resulted in this match.
|
||||
* @param matchFilterLength The length of the match filter array.
|
||||
*/
|
||||
public void onMatch(int peerId, byte[] serviceSpecificInfo,
|
||||
int serviceSpecificInfoLength, byte[] matchFilter, int matchFilterLength) {
|
||||
public void onMatch(int peerId, byte[] serviceSpecificInfo, byte[] matchFilter) {
|
||||
/* empty */
|
||||
}
|
||||
|
||||
@@ -204,10 +200,8 @@ public class WifiNanSessionCallback {
|
||||
*
|
||||
* @param peerId The ID of the peer sending the message.
|
||||
* @param message A byte array containing the message.
|
||||
* @param messageLength The length of the byte array containing the relevant
|
||||
* message bytes.
|
||||
*/
|
||||
public void onMessageReceived(int peerId, byte[] message, int messageLength) {
|
||||
public void onMessageReceived(int peerId, byte[] message) {
|
||||
/* empty */
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user