summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorNate Jiang <qiangjiang@google.com>2020-07-20 23:30:37 -0700
committerNate Jiang <qiangjiang@google.com>2020-07-22 22:07:21 +0000
commite123f5b971d31eb9a660f1a8050128988061eb8e (patch)
tree636df17e658e3e176cc059a6912ecc30fe08c6fc /service
parent725979457913e7addc8c6ffbd921b82011effe1e (diff)
[Aware] dynamic enabled ranging with discovery session
Only enable aware ranging when at least one of the discovery session has ranging enabled. Bug: 159163836 Test: atest com.android.server.wifi Merged-In: Iad58972e881cb44b3aabcd6235d5b8a7901e6c71 Change-Id: Iad58972e881cb44b3aabcd6235d5b8a7901e6c71 (cherry picked from commit 6a9bedadbd0629786167ef23cc145f4f3cddfb7b)
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/aware/WifiAwareClientState.java13
-rw-r--r--service/java/com/android/server/wifi/aware/WifiAwareDiscoverySessionState.java4
-rw-r--r--service/java/com/android/server/wifi/aware/WifiAwareNativeApi.java5
-rw-r--r--service/java/com/android/server/wifi/aware/WifiAwareStateManager.java91
4 files changed, 82 insertions, 31 deletions
diff --git a/service/java/com/android/server/wifi/aware/WifiAwareClientState.java b/service/java/com/android/server/wifi/aware/WifiAwareClientState.java
index b71546639..c96cf2843 100644
--- a/service/java/com/android/server/wifi/aware/WifiAwareClientState.java
+++ b/service/java/com/android/server/wifi/aware/WifiAwareClientState.java
@@ -283,6 +283,19 @@ public class WifiAwareClientState {
}
/**
+ * Check if client needs ranging enabled.
+ * @return True if one of the discovery session has ranging enabled, false otherwise.
+ */
+ public boolean isRangingEnabled() {
+ for (int i = 0; i < mSessions.size(); ++i) {
+ if (mSessions.valueAt(i).isRangingEnabled()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
* Dump the internal state of the class.
*/
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
diff --git a/service/java/com/android/server/wifi/aware/WifiAwareDiscoverySessionState.java b/service/java/com/android/server/wifi/aware/WifiAwareDiscoverySessionState.java
index 9af954557..bfd3e2c19 100644
--- a/service/java/com/android/server/wifi/aware/WifiAwareDiscoverySessionState.java
+++ b/service/java/com/android/server/wifi/aware/WifiAwareDiscoverySessionState.java
@@ -103,6 +103,10 @@ public class WifiAwareDiscoverySessionState {
return mIsRangingEnabled;
}
+ public void setRangingEnabled(boolean enabled) {
+ mIsRangingEnabled = enabled;
+ }
+
public long getCreationTime() {
return mCreationTime;
}
diff --git a/service/java/com/android/server/wifi/aware/WifiAwareNativeApi.java b/service/java/com/android/server/wifi/aware/WifiAwareNativeApi.java
index 4e6f08613..38400223a 100644
--- a/service/java/com/android/server/wifi/aware/WifiAwareNativeApi.java
+++ b/service/java/com/android/server/wifi/aware/WifiAwareNativeApi.java
@@ -355,10 +355,11 @@ public class WifiAwareNativeApi implements WifiAwareShellCommand.DelegatedShellC
* (true) or an update (false) to the configuration.
* @param isInteractive PowerManager.isInteractive
* @param isIdle PowerManager.isIdle
+ * @param rangingEnabled Indicates whether or not enable ranging.
*/
public boolean enableAndConfigure(short transactionId, ConfigRequest configRequest,
boolean notifyIdentityChange, boolean initialConfiguration, boolean isInteractive,
- boolean isIdle) {
+ boolean isIdle, boolean rangingEnabled) {
if (mDbg) {
Log.v(TAG, "enableAndConfigure: transactionId=" + transactionId + ", configRequest="
+ configRequest + ", notifyIdentityChange=" + notifyIdentityChange
@@ -379,7 +380,7 @@ public class WifiAwareNativeApi implements WifiAwareShellCommand.DelegatedShellC
configSupplemental12.discoveryBeaconIntervalMs = 0;
configSupplemental12.numberOfSpatialStreamsInDiscovery = 0;
configSupplemental12.enableDiscoveryWindowEarlyTermination = false;
- configSupplemental12.enableRanging = true;
+ configSupplemental12.enableRanging = rangingEnabled;
}
NanBandSpecificConfig config24 = new NanBandSpecificConfig();
diff --git a/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java b/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java
index 73e2d043a..baa822e11 100644
--- a/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java
+++ b/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java
@@ -226,6 +226,7 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe
private final SparseArray<WifiAwareClientState> mClients = new SparseArray<>();
private ConfigRequest mCurrentAwareConfiguration = null;
private boolean mCurrentIdentityNotification = false;
+ private boolean mCurrentRangingEnabled = false;
private static final byte[] ALL_ZERO_MAC = new byte[] {0, 0, 0, 0, 0, 0};
private byte[] mCurrentDiscoveryInterfaceMac = ALL_ZERO_MAC;
@@ -642,7 +643,7 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe
Message msg = mSm.obtainMessage(MESSAGE_TYPE_COMMAND);
msg.arg1 = COMMAND_TYPE_UPDATE_PUBLISH;
msg.arg2 = clientId;
- msg.obj = publishConfig;
+ msg.getData().putParcelable(MESSAGE_BUNDLE_KEY_CONFIG, publishConfig);
msg.getData().putInt(MESSAGE_BUNDLE_KEY_SESSION_ID, sessionId);
mSm.sendMessage(msg);
}
@@ -669,7 +670,7 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe
Message msg = mSm.obtainMessage(MESSAGE_TYPE_COMMAND);
msg.arg1 = COMMAND_TYPE_UPDATE_SUBSCRIBE;
msg.arg2 = clientId;
- msg.obj = subscribeConfig;
+ msg.getData().putParcelable(MESSAGE_BUNDLE_KEY_CONFIG, subscribeConfig);
msg.getData().putInt(MESSAGE_BUNDLE_KEY_SESSION_ID, sessionId);
mSm.sendMessage(msg);
}
@@ -1615,8 +1616,8 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe
case COMMAND_TYPE_UPDATE_PUBLISH: {
int clientId = msg.arg2;
int sessionId = msg.getData().getInt(MESSAGE_BUNDLE_KEY_SESSION_ID);
- PublishConfig publishConfig = (PublishConfig) msg.obj;
-
+ PublishConfig publishConfig = (PublishConfig) msg.getData()
+ .getParcelable(MESSAGE_BUNDLE_KEY_CONFIG);
waitForResponse = updatePublishLocal(mCurrentTransactionId, clientId, sessionId,
publishConfig);
break;
@@ -1635,7 +1636,8 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe
case COMMAND_TYPE_UPDATE_SUBSCRIBE: {
int clientId = msg.arg2;
int sessionId = msg.getData().getInt(MESSAGE_BUNDLE_KEY_SESSION_ID);
- SubscribeConfig subscribeConfig = (SubscribeConfig) msg.obj;
+ SubscribeConfig subscribeConfig = (SubscribeConfig) msg.getData()
+ .getParcelable(MESSAGE_BUNDLE_KEY_CONFIG);
waitForResponse = updateSubscribeLocal(mCurrentTransactionId, clientId,
sessionId, subscribeConfig);
@@ -2247,7 +2249,8 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe
boolean success = mWifiAwareNativeApi.enableAndConfigure(transactionId, merged,
notificationRequired, mCurrentAwareConfiguration == null,
- mPowerManager.isInteractive(), mPowerManager.isDeviceIdleMode());
+ mPowerManager.isInteractive(), mPowerManager.isDeviceIdleMode(),
+ mCurrentRangingEnabled);
if (!success) {
try {
callback.onConnectFail(NanStatusType.INTERNAL_FAILURE);
@@ -2292,13 +2295,16 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe
return false;
}
boolean notificationReqs = doesAnyClientNeedIdentityChangeNotifications();
+ boolean rangingEnabled = doesAnyClientNeedRanging();
if (merged.equals(mCurrentAwareConfiguration)
- && mCurrentIdentityNotification == notificationReqs) {
+ && mCurrentIdentityNotification == notificationReqs
+ && mCurrentRangingEnabled == rangingEnabled) {
return false;
}
return mWifiAwareNativeApi.enableAndConfigure(transactionId, merged, notificationReqs,
- false, mPowerManager.isInteractive(), mPowerManager.isDeviceIdleMode());
+ false, mPowerManager.isInteractive(), mPowerManager.isDeviceIdleMode(),
+ rangingEnabled);
}
private boolean reconfigureLocal(short transactionId) {
@@ -2310,10 +2316,11 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe
}
boolean notificationReqs = doesAnyClientNeedIdentityChangeNotifications();
+ boolean rangingEnabled = doesAnyClientNeedRanging();
return mWifiAwareNativeApi.enableAndConfigure(transactionId, mCurrentAwareConfiguration,
notificationReqs, false, mPowerManager.isInteractive(),
- mPowerManager.isDeviceIdleMode());
+ mPowerManager.isDeviceIdleMode(), rangingEnabled);
}
private void terminateSessionLocal(int clientId, int sessionId) {
@@ -2329,6 +2336,10 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe
}
WifiAwareDiscoverySessionState session = client.terminateSession(sessionId);
+ // If Ranging enabled require changes, reconfigure.
+ if (mCurrentRangingEnabled != doesAnyClientNeedRanging()) {
+ reconfigure();
+ }
if (session != null) {
mAwareMetrics.recordDiscoverySessionDuration(session.getCreationTime(),
session.isPublishSession());
@@ -2624,6 +2635,7 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe
Log.wtf(TAG, "onConfigCompletedLocal: got a null merged configuration after config!?");
}
mCurrentIdentityNotification = doesAnyClientNeedIdentityChangeNotifications();
+ mCurrentRangingEnabled = doesAnyClientNeedRanging();
}
private void onConfigFailedLocal(Message failedCommand, int reason) {
@@ -2685,6 +2697,26 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe
+ ", pubSubId=" + pubSubId + ", isPublish=" + isPublish);
}
+ boolean isRangingEnabled = false;
+ int minRange = -1;
+ int maxRange = -1;
+ if (isPublish) {
+ PublishConfig publishConfig = completedCommand.getData().getParcelable(
+ MESSAGE_BUNDLE_KEY_CONFIG);
+ isRangingEnabled = publishConfig.mEnableRanging;
+ } else {
+ SubscribeConfig subscribeConfig = completedCommand.getData().getParcelable(
+ MESSAGE_BUNDLE_KEY_CONFIG);
+ isRangingEnabled =
+ subscribeConfig.mMinDistanceMmSet || subscribeConfig.mMaxDistanceMmSet;
+ if (subscribeConfig.mMinDistanceMmSet) {
+ minRange = subscribeConfig.mMinDistanceMm;
+ }
+ if (subscribeConfig.mMaxDistanceMmSet) {
+ maxRange = subscribeConfig.mMaxDistanceMm;
+ }
+ }
+
if (completedCommand.arg1 == COMMAND_TYPE_PUBLISH
|| completedCommand.arg1 == COMMAND_TYPE_SUBSCRIBE) {
int clientId = completedCommand.arg2;
@@ -2706,26 +2738,6 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe
return;
}
- boolean isRangingEnabled = false;
- int minRange = -1;
- int maxRange = -1;
- if (completedCommand.arg1 == COMMAND_TYPE_PUBLISH) {
- PublishConfig publishConfig = completedCommand.getData().getParcelable(
- MESSAGE_BUNDLE_KEY_CONFIG);
- isRangingEnabled = publishConfig.mEnableRanging;
- } else {
- SubscribeConfig subscribeConfig = completedCommand.getData().getParcelable(
- MESSAGE_BUNDLE_KEY_CONFIG);
- isRangingEnabled =
- subscribeConfig.mMinDistanceMmSet || subscribeConfig.mMaxDistanceMmSet;
- if (subscribeConfig.mMinDistanceMmSet) {
- minRange = subscribeConfig.mMinDistanceMm;
- }
- if (subscribeConfig.mMaxDistanceMmSet) {
- maxRange = subscribeConfig.mMaxDistanceMm;
- }
- }
-
WifiAwareDiscoverySessionState session = new WifiAwareDiscoverySessionState(
mWifiAwareNativeApi, sessionId, pubSubId, callback, isPublish, isRangingEnabled,
SystemClock.elapsedRealtime());
@@ -2767,11 +2779,17 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe
Log.e(TAG, "onSessionConfigSuccessLocal: onSessionConfigSuccess() RemoteException="
+ e);
}
+ session.setRangingEnabled(isRangingEnabled);
mAwareMetrics.recordDiscoveryStatus(client.getUid(), NanStatusType.SUCCESS,
completedCommand.arg1 == COMMAND_TYPE_UPDATE_PUBLISH);
} else {
Log.wtf(TAG,
"onSessionConfigSuccessLocal: unexpected completedCommand=" + completedCommand);
+ return;
+ }
+ // If ranging require changes, reconfigure.
+ if (mCurrentRangingEnabled != doesAnyClientNeedRanging()) {
+ reconfigure();
}
}
@@ -2829,6 +2847,9 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe
if (reason == NanStatusType.INVALID_SESSION_ID) {
client.removeSession(sessionId);
+ if (mCurrentRangingEnabled != doesAnyClientNeedRanging()) {
+ reconfigure();
+ }
}
} else {
Log.wtf(TAG, "onSessionConfigFailLocal: unexpected failedCommand=" + failedCommand);
@@ -3059,6 +3080,9 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe
"onSessionTerminatedLocal onSessionTerminated(): RemoteException (FYI): " + e);
}
data.first.removeSession(data.second.getSessionId());
+ if (mCurrentRangingEnabled != doesAnyClientNeedRanging()) {
+ reconfigure();
+ }
mAwareMetrics.recordDiscoverySessionDuration(data.second.getCreationTime(),
data.second.isPublishSession());
}
@@ -3228,6 +3252,15 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe
return false;
}
+ private boolean doesAnyClientNeedRanging() {
+ for (int i = 0; i < mClients.size(); ++i) {
+ if (mClients.valueAt(i).isRangingEnabled()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
private static String messageToString(Message msg) {
StringBuilder sb = new StringBuilder();