[NAN] Removed NAN event registration - dispatch all callbacks. [DO NOT MERGE]

All events dispatched by default - there's no reason to ignore events.
The specific identity changed events for which there are use-cases to
get or ignore is controlled through a new configuration.

Bug: 27607613
Change-Id: I289a36157b55270c58311a016ef79f8746e0e0a0
This commit is contained in:
Etan Cohen
2016-03-11 12:50:56 -08:00
parent 8414f5cf2b
commit a5ed693788
4 changed files with 71 additions and 76 deletions

View File

@@ -73,19 +73,28 @@ public class ConfigRequest implements Parcelable {
*/
public final int mClusterHigh;
/**
* Indicates whether we want to get callbacks when our identity is changed.
*
* @hide
*/
public final boolean mEnableIdentityChangeCallback;
private ConfigRequest(boolean support5gBand, int masterPreference, int clusterLow,
int clusterHigh) {
int clusterHigh, boolean enableIdentityChangeCallback) {
mSupport5gBand = support5gBand;
mMasterPreference = masterPreference;
mClusterLow = clusterLow;
mClusterHigh = clusterHigh;
mEnableIdentityChangeCallback = enableIdentityChangeCallback;
}
@Override
public String toString() {
return "ConfigRequest [mSupport5gBand=" + mSupport5gBand + ", mMasterPreference="
+ mMasterPreference + ", mClusterLow=" + mClusterLow + ", mClusterHigh="
+ mClusterHigh + "]";
+ mClusterHigh + ", mEnableIdentityChangeCallback=" + mEnableIdentityChangeCallback
+ "]";
}
@Override
@@ -99,6 +108,7 @@ public class ConfigRequest implements Parcelable {
dest.writeInt(mMasterPreference);
dest.writeInt(mClusterLow);
dest.writeInt(mClusterHigh);
dest.writeInt(mEnableIdentityChangeCallback ? 1 : 0);
}
public static final Creator<ConfigRequest> CREATOR = new Creator<ConfigRequest>() {
@@ -113,7 +123,9 @@ public class ConfigRequest implements Parcelable {
int masterPreference = in.readInt();
int clusterLow = in.readInt();
int clusterHigh = in.readInt();
return new ConfigRequest(support5gBand, masterPreference, clusterLow, clusterHigh);
boolean enableIdentityChangeCallback = in.readInt() != 0;
return new ConfigRequest(support5gBand, masterPreference, clusterLow, clusterHigh,
enableIdentityChangeCallback);
}
};
@@ -130,7 +142,8 @@ public class ConfigRequest implements Parcelable {
ConfigRequest lhs = (ConfigRequest) o;
return mSupport5gBand == lhs.mSupport5gBand && mMasterPreference == lhs.mMasterPreference
&& mClusterLow == lhs.mClusterLow && mClusterHigh == lhs.mClusterHigh;
&& mClusterLow == lhs.mClusterLow && mClusterHigh == lhs.mClusterHigh
&& mEnableIdentityChangeCallback == lhs.mEnableIdentityChangeCallback;
}
@Override
@@ -141,6 +154,7 @@ public class ConfigRequest implements Parcelable {
result = 31 * result + mMasterPreference;
result = 31 * result + mClusterLow;
result = 31 * result + mClusterHigh;
result = 31 * result + (mEnableIdentityChangeCallback ? 1 : 0);
return result;
}
@@ -149,20 +163,11 @@ public class ConfigRequest implements Parcelable {
* Builder used to build {@link ConfigRequest} objects.
*/
public static final class Builder {
private boolean mSupport5gBand;
private int mMasterPreference;
private int mClusterLow;
private int mClusterHigh;
/**
* Default constructor for the Builder.
*/
public Builder() {
mSupport5gBand = false;
mMasterPreference = 0;
mClusterLow = 0;
mClusterHigh = CLUSTER_ID_MAX;
}
private boolean mSupport5gBand = false;
private int mMasterPreference = 0;
private int mClusterLow = CLUSTER_ID_MIN;
private int mClusterHigh = CLUSTER_ID_MAX;
private boolean mEnableIdentityChangeCallback = false;
/**
* Specify whether 5G band support is required in this request.
@@ -246,6 +251,25 @@ public class ConfigRequest implements Parcelable {
return this;
}
/**
* Indicate whether or not we want to enable the callback to the
* listener on the event when the NAN device identity is changed. A
* device identity is it's Discovery MAC address. Depending on use-case
* we may want to perform some activity (e.g. re-publish). In other
* use-cases (typically where we're silent) there's no reason to be
* woken up repeatedly. Note that the MAC address is randomized at
* regular intervals - so do not enable unless specifically required.
*
* @param enableIdentityChangeCallback Enable the callback informing
* listener when identity is changed.
* @return The builder to facilitate chaining
* {@code builder.setXXX(..).setXXX(..)}.
*/
public Builder setEnableIdentityChangeCallback(boolean enableIdentityChangeCallback) {
mEnableIdentityChangeCallback = enableIdentityChangeCallback;
return this;
}
/**
* Build {@link ConfigRequest} given the current requests made on the
* builder.
@@ -256,7 +280,8 @@ public class ConfigRequest implements Parcelable {
"Invalid argument combination - must have Cluster Low <= Cluster High");
}
return new ConfigRequest(mSupport5gBand, mMasterPreference, mClusterLow, mClusterHigh);
return new ConfigRequest(mSupport5gBand, mMasterPreference, mClusterLow, mClusterHigh,
mEnableIdentityChangeCallback);
}
}
}

View File

@@ -32,7 +32,7 @@ import android.net.wifi.nan.SubscribeConfig;
interface IWifiNanManager
{
// client API
int connect(in IBinder binder, in IWifiNanEventCallback callback, int events);
int connect(in IBinder binder, in IWifiNanEventCallback callback);
void disconnect(int clientId, in IBinder binder);
void requestConfig(int clientId, in ConfigRequest configRequest);

View File

@@ -26,11 +26,6 @@ import android.util.Log;
* wanting notifications. These are callbacks applying to the NAN connection as
* a whole - not to specific publish or subscribe sessions - for that see
* {@link WifiNanSessionCallback}.
* <p>
* During registration specify which specific events are desired using a set of
* {@code NanEventCallback.LISTEN_*} flags OR'd together. Only those events will
* be delivered to the registered callback. Override those callbacks
* {@code WifiNanEventCallback.on*} for the registered events.
*
* @hide PROPOSED_NAN_API
*/
@@ -39,34 +34,14 @@ public class WifiNanEventCallback {
private static final boolean DBG = false;
private static final boolean VDBG = false; // STOPSHIP if true
/**
* Configuration completion callback event registration flag. Corresponding
* callback is {@link WifiNanEventCallback#onConfigCompleted(ConfigRequest)}
* .
*/
public static final int FLAG_LISTEN_CONFIG_COMPLETED = 0x1 << 0;
/**
* Configuration failed callback event registration flag. Corresponding
* callback is
* {@link WifiNanEventCallback#onConfigFailed(ConfigRequest, int)}.
*/
public static final int FLAG_LISTEN_CONFIG_FAILED = 0x1 << 1;
/**
* NAN cluster is down callback event registration flag. Corresponding
* callback is {@link WifiNanEventCallback#onNanDown(int)}.
*/
public static final int FLAG_LISTEN_NAN_DOWN = 0x1 << 2;
/**
* NAN identity has changed event registration flag. This may be due to
* joining a cluster, starting a cluster, or discovery interface change. The
* implication is that peers you've been communicating with may no longer
* recognize you and you need to re-establish your identity. Corresponding
* callback is {@link WifiNanEventCallback#onIdentityChanged()}.
*/
public static final int FLAG_LISTEN_IDENTITY_CHANGED = 0x1 << 3;
/** @hide */
public static final int CALLBACK_CONFIG_COMPLETED = 0;
/** @hide */
public static final int CALLBACK_CONFIG_FAILED = 1;
/** @hide */
public static final int CALLBACK_NAN_DOWN = 2;
/** @hide */
public static final int CALLBACK_IDENTITY_CHANGED = 3;
private final Handler mHandler;
@@ -91,16 +66,16 @@ public class WifiNanEventCallback {
public void handleMessage(Message msg) {
if (DBG) Log.d(TAG, "What=" + msg.what + ", msg=" + msg);
switch (msg.what) {
case FLAG_LISTEN_CONFIG_COMPLETED:
case CALLBACK_CONFIG_COMPLETED:
WifiNanEventCallback.this.onConfigCompleted((ConfigRequest) msg.obj);
break;
case FLAG_LISTEN_CONFIG_FAILED:
case CALLBACK_CONFIG_FAILED:
WifiNanEventCallback.this.onConfigFailed((ConfigRequest) msg.obj, msg.arg1);
break;
case FLAG_LISTEN_NAN_DOWN:
case CALLBACK_NAN_DOWN:
WifiNanEventCallback.this.onNanDown(msg.arg1);
break;
case FLAG_LISTEN_IDENTITY_CHANGED:
case CALLBACK_IDENTITY_CHANGED:
WifiNanEventCallback.this.onIdentityChanged();
break;
}
@@ -110,9 +85,10 @@ public class WifiNanEventCallback {
/**
* Called when NAN configuration is completed. Event will only be delivered
* if registered using {@link WifiNanEventCallback#FLAG_LISTEN_CONFIG_COMPLETED}.
* A dummy (empty implementation printing out a warning). Make sure to
* override if registered.
* if registered using
* {@link WifiNanEventCallback#CALLBACK_CONFIG_COMPLETED}. A dummy (empty
* implementation printing out a warning). Make sure to override if
* registered.
*
* @param completedConfig The actual configuration request which was
* completed. Note that it may be different from that requested
@@ -125,7 +101,7 @@ public class WifiNanEventCallback {
/**
* Called when NAN configuration failed. Event will only be delivered if
* registered using {@link WifiNanEventCallback#FLAG_LISTEN_CONFIG_FAILED}. A
* registered using {@link WifiNanEventCallback#CALLBACK_CONFIG_FAILED}. A
* dummy (empty implementation printing out a warning). Make sure to
* override if registered.
*
@@ -138,7 +114,7 @@ public class WifiNanEventCallback {
/**
* Called when NAN cluster is down. Event will only be delivered if
* registered using {@link WifiNanEventCallback#FLAG_LISTEN_NAN_DOWN}. A dummy
* registered using {@link WifiNanEventCallback#CALLBACK_NAN_DOWN}. A dummy
* (empty implementation printing out a warning). Make sure to override if
* registered.
*
@@ -155,7 +131,7 @@ public class WifiNanEventCallback {
* implication is that peers you've been communicating with may no longer
* recognize you and you need to re-establish your identity. Event will only
* be delivered if registered using
* {@link WifiNanEventCallback#FLAG_LISTEN_IDENTITY_CHANGED}. A dummy (empty
* {@link WifiNanEventCallback#CALLBACK_IDENTITY_CHANGED}. A dummy (empty
* implementation printing out a warning). Make sure to override if
* registered.
*/
@@ -171,7 +147,7 @@ public class WifiNanEventCallback {
public void onConfigCompleted(ConfigRequest completedConfig) {
if (VDBG) Log.v(TAG, "onConfigCompleted: configRequest=" + completedConfig);
Message msg = mHandler.obtainMessage(FLAG_LISTEN_CONFIG_COMPLETED);
Message msg = mHandler.obtainMessage(CALLBACK_CONFIG_COMPLETED);
msg.obj = completedConfig;
mHandler.sendMessage(msg);
}
@@ -182,7 +158,7 @@ public class WifiNanEventCallback {
Log.v(TAG, "onConfigFailed: failedConfig=" + failedConfig + ", reason=" + reason);
}
Message msg = mHandler.obtainMessage(FLAG_LISTEN_CONFIG_FAILED);
Message msg = mHandler.obtainMessage(CALLBACK_CONFIG_FAILED);
msg.arg1 = reason;
msg.obj = failedConfig;
mHandler.sendMessage(msg);
@@ -192,7 +168,7 @@ public class WifiNanEventCallback {
public void onNanDown(int reason) {
if (VDBG) Log.v(TAG, "onNanDown: reason=" + reason);
Message msg = mHandler.obtainMessage(FLAG_LISTEN_NAN_DOWN);
Message msg = mHandler.obtainMessage(CALLBACK_NAN_DOWN);
msg.arg1 = reason;
mHandler.sendMessage(msg);
}
@@ -201,7 +177,7 @@ public class WifiNanEventCallback {
public void onIdentityChanged() {
if (VDBG) Log.v(TAG, "onIdentityChanged");
Message msg = mHandler.obtainMessage(FLAG_LISTEN_IDENTITY_CHANGED);
Message msg = mHandler.obtainMessage(CALLBACK_IDENTITY_CHANGED);
mHandler.sendMessage(msg);
}
};

View File

@@ -54,17 +54,11 @@ public class WifiNanManager {
/**
* Re-connect to the Wi-Fi NAN service - enabling the application to execute
* {@link WifiNanManager} APIs. Application don't normally need to call this
* API since it is executed in the constructor. However, applications which
* have explicitly {@link WifiNanManager#disconnect()} need to call this
* function to re-connect.
* {@link WifiNanManager} APIs.
*
* @param callback A callback extended from {@link WifiNanEventCallback}.
* @param events The set of events to be delivered to the {@code callback}.
* OR'd event flags from {@link WifiNanEventCallback
* WifiNanEventCallback.LISTEN*}.
*/
public void connect(WifiNanEventCallback callback, int events) {
public void connect(WifiNanEventCallback callback) {
try {
if (VDBG) Log.v(TAG, "connect()");
if (callback == null) {
@@ -77,7 +71,7 @@ public class WifiNanManager {
if (mBinder == null) {
mBinder = new Binder();
}
mClientId = mService.connect(mBinder, callback.callback, events);
mClientId = mService.connect(mBinder, callback.callback);
} catch (RemoteException e) {
Log.w(TAG, "connect RemoteException (FYI - ignoring): " + e);
}