diff options
author | Nate Jiang <qiangjiang@google.com> | 2020-07-20 23:30:37 -0700 |
---|---|---|
committer | Nate Jiang <qiangjiang@google.com> | 2020-07-22 22:07:21 +0000 |
commit | e123f5b971d31eb9a660f1a8050128988061eb8e (patch) | |
tree | 636df17e658e3e176cc059a6912ecc30fe08c6fc | |
parent | 725979457913e7addc8c6ffbd921b82011effe1e (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)
8 files changed, 159 insertions, 83 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(); diff --git a/tests/wifitests/src/com/android/server/wifi/aware/TestUtils.java b/tests/wifitests/src/com/android/server/wifi/aware/TestUtils.java index 555e89115..351bb9895 100644 --- a/tests/wifitests/src/com/android/server/wifi/aware/TestUtils.java +++ b/tests/wifitests/src/com/android/server/wifi/aware/TestUtils.java @@ -49,7 +49,7 @@ public class TestUtils { public boolean enableAndConfigure(short transactionId, ConfigRequest configRequest, boolean notifyIdentityChange, boolean initialConfiguration, boolean isInteractive, - boolean isIdle) { + boolean isIdle, boolean rangingEnabled) { addTransactionId(transactionId); return true; } diff --git a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java index f496b1c95..a21442f6c 100644 --- a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java @@ -1846,7 +1846,7 @@ public class WifiAwareDataPathStateManagerTest extends WifiBaseTest { if (startUpSequence) { inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), - eq(configRequest), eq(false), eq(true), eq(true), eq(false)); + eq(configRequest), eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); } diff --git a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareNativeApiTest.java b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareNativeApiTest.java index 0a30228cf..08eae1d36 100644 --- a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareNativeApiTest.java +++ b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareNativeApiTest.java @@ -595,7 +595,7 @@ public class WifiAwareNativeApiTest extends WifiBaseTest { mIsInterface12 = isHal12; mDut.enableAndConfigure(transactionId, configRequest, notifyIdentityChange, - initialConfiguration, isInteractive, isIdle); + initialConfiguration, isInteractive, isIdle, false); ArgumentCaptor<NanEnableRequest> enableReqCaptor = ArgumentCaptor.forClass( NanEnableRequest.class); diff --git a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareStateManagerTest.java b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareStateManagerTest.java index f5da0b2f1..7292fca36 100644 --- a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareStateManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareStateManagerTest.java @@ -268,7 +268,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), - eq(configRequest), eq(false), eq(true), eq(true), eq(false)); + eq(configRequest), eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback1).onConnectSuccess(clientId1); @@ -369,7 +369,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), - eq(false), eq(true), eq(true), eq(false)); + eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -466,7 +466,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), - eq(false), eq(true), eq(true), eq(false)); + eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -512,7 +512,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), - eq(false), eq(true), eq(true), eq(false)); + eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -540,7 +540,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { InOrder inOrder = inOrder(mMockContext, mMockNative, mockCallback); when(mMockNative.enableAndConfigure(anyShort(), any(), anyBoolean(), - anyBoolean(), eq(true), eq(false))).thenReturn(false); + anyBoolean(), eq(true), eq(false), eq(false))).thenReturn(false); // (1) check initial state mDut.enableUsage(); @@ -555,7 +555,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), - eq(false), eq(true), eq(true), eq(false)); + eq(false), eq(true), eq(true), eq(false), eq(false)); inOrder.verify(mockCallback).onConnectFail(NanStatusType.INTERNAL_FAILURE); validateInternalClientInfoCleanedUp(clientId); @@ -601,7 +601,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionIdCapture.capture(), - eq(configRequest), eq(false), eq(true), eq(true), eq(false)); + eq(configRequest), eq(false), eq(true), eq(true), eq(false), eq(false)); short transactionId = transactionIdCapture.getValue(); mDut.onConfigSuccessResponse(transactionId); mMockLooper.dispatchAll(); @@ -611,7 +611,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, true); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionIdCapture.capture(), - eq(configRequest), eq(true), eq(false), eq(true), eq(false)); + eq(configRequest), eq(true), eq(false), eq(true), eq(false), eq(false)); transactionId = transactionIdCapture.getValue(); mDut.onConfigSuccessResponse(transactionId); mMockLooper.dispatchAll(); @@ -689,7 +689,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), - eq(false), eq(true), eq(true), eq(false)); + eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -755,7 +755,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), - eq(configRequest), eq(false), eq(true), eq(true), eq(false)); + eq(configRequest), eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -828,7 +828,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), - eq(configRequest), eq(false), eq(true), eq(true), eq(false)); + eq(configRequest), eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -912,7 +912,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), - eq(false), eq(true), eq(true), eq(false)); + eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -931,6 +931,12 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { inOrderM.verify(mAwareMetricsMock).recordDiscoverySessionWithRanging(eq(uid), eq(false), eq(-1), eq(-1), any()); inOrderM.verify(mAwareMetricsMock).recordDiscoveryStatus(uid, NanStatusType.SUCCESS, true); + mMockLooper.dispatchAll(); + // Verify reconfigure aware to enable ranging. + inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), + eq(false), eq(false), eq(true), eq(false), eq(true)); + mDut.onConfigSuccessResponse(transactionId.getValue()); + mMockLooper.dispatchAll(); // (3) update publish mDut.updatePublish(clientId, sessionId.getValue(), publishConfig); @@ -979,6 +985,12 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { inOrder.verify(mockSessionCallback).onSessionConfigFail(NanStatusType.INVALID_SESSION_ID); inOrderM.verify(mAwareMetricsMock).recordDiscoveryStatus(uid, NanStatusType.INVALID_SESSION_ID, true); + // Verify reconfigure aware to disable ranging. + mMockLooper.dispatchAll(); + inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), + eq(false), eq(false), eq(true), eq(false), eq(false)); + mDut.onConfigSuccessResponse(transactionId.getValue()); + mMockLooper.dispatchAll(); // (9) try updating again - do nothing/get nothing mDut.updatePublish(clientId, sessionId.getValue(), publishConfig); @@ -1024,7 +1036,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), - eq(false), eq(true), eq(true), eq(false)); + eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -1092,7 +1104,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), - eq(false), eq(true), eq(true), eq(false)); + eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -1166,7 +1178,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), - eq(false), eq(true), eq(true), eq(false)); + eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -1250,7 +1262,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), - eq(false), eq(true), eq(true), eq(false)); + eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -1269,6 +1281,12 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { inOrderM.verify(mAwareMetricsMock).recordDiscoverySessionWithRanging(eq(uid), eq(true), eq(-1), eq(rangeMax), any()); inOrderM.verify(mAwareMetricsMock).recordDiscoveryStatus(uid, NanStatusType.SUCCESS, false); + // Verify reconfigure aware to enable ranging. + mMockLooper.dispatchAll(); + inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), + eq(false), eq(false), eq(true), eq(false), eq(true)); + mDut.onConfigSuccessResponse(transactionId.getValue()); + mMockLooper.dispatchAll(); // (3) update subscribe mDut.updateSubscribe(clientId, sessionId.getValue(), subscribeConfig); @@ -1343,7 +1361,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), - eq(false), eq(true), eq(true), eq(false)); + eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -1426,7 +1444,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), - eq(configRequest), eq(false), eq(true), eq(true), eq(false)); + eq(configRequest), eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -1443,6 +1461,13 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { inOrderM.verify(mAwareMetricsMock).recordDiscoverySessionWithRanging(eq(uid), eq(true), eq(rangeMin), eq(rangeMax), any()); inOrderM.verify(mAwareMetricsMock).recordDiscoveryStatus(uid, NanStatusType.SUCCESS, false); + // Verify reconfigure aware to enable ranging. + mMockLooper.dispatchAll(); + inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), + eq(false), eq(false), eq(true), eq(false), eq(true)); + mDut.onConfigSuccessResponse(transactionId.getValue()); + mMockLooper.dispatchAll(); + // (2) 2 matches : with and w/o range mDut.onMatchNotification(subscribeId, requestorId, peerMac, peerSsi.getBytes(), @@ -1554,7 +1579,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), - eq(false), eq(true), eq(true), eq(false)); + eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -1658,7 +1683,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), - eq(false), eq(true), eq(true), eq(false)); + eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -1752,7 +1777,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), - eq(false), eq(true), eq(true), eq(false)); + eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -1823,7 +1848,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), - eq(false), eq(true), eq(true), eq(false)); + eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -1951,7 +1976,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), - eq(false), eq(true), eq(true), eq(false)); + eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -2040,7 +2065,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), - eq(false), eq(true), eq(true), eq(false)); + eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -2130,7 +2155,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), - eq(configRequest), eq(false), eq(true), eq(true), eq(false)); + eq(configRequest), eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -2244,7 +2269,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest1, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), - eq(configRequest1), eq(false), eq(true), eq(true), eq(false)); + eq(configRequest1), eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId1); @@ -2379,7 +2404,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), - eq(configRequest), eq(false), eq(true), eq(true), eq(false)); + eq(configRequest), eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -2513,7 +2538,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), - eq(configRequest), eq(false), eq(true), eq(true), eq(false)); + eq(configRequest), eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -2746,7 +2771,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest1, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), - crCapture.capture(), eq(false), eq(true), eq(true), eq(false)); + crCapture.capture(), eq(false), eq(true), eq(true), eq(false), eq(false)); collector.checkThat("merge: stage 1", crCapture.getValue(), equalTo(configRequest1)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); @@ -2764,7 +2789,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest3, true); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), - crCapture.capture(), eq(true), eq(false), eq(true), eq(false)); + crCapture.capture(), eq(true), eq(false), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback3).onConnectSuccess(clientId3); @@ -2786,7 +2811,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); validateInternalClientInfoCleanedUp(clientId3); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), - crCapture.capture(), eq(false), eq(false), eq(true), eq(false)); + crCapture.capture(), eq(false), eq(false), eq(true), eq(false), eq(false)); collector.checkThat("configRequest1", configRequest1, equalTo(crCapture.getValue())); @@ -2837,7 +2862,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), - any(ConfigRequest.class), eq(false), eq(true), eq(true), eq(false)); + any(ConfigRequest.class), eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -2855,7 +2880,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, true); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), - any(ConfigRequest.class), eq(true), eq(false), eq(true), eq(false)); + any(ConfigRequest.class), eq(true), eq(false), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -2918,7 +2943,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), - eq(false), eq(true), eq(true), eq(false)); + eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -2995,7 +3020,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), - eq(false), eq(true), eq(true), eq(false)); + eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -3041,7 +3066,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), - eq(false), eq(true), eq(true), eq(false)); + eq(false), eq(true), eq(true), eq(false), eq(false)); verifyNoMoreInteractions(mMockNative, mockCallback, mockSessionCallback); } @@ -3077,7 +3102,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), - eq(false), eq(true), eq(true), eq(false)); + eq(false), eq(true), eq(true), eq(false), eq(false)); short transactionIdConfig = transactionId.getValue(); mDut.onConfigSuccessResponse(transactionIdConfig); mMockLooper.dispatchAll(); @@ -3135,7 +3160,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest), - eq(false), eq(true), eq(true), eq(false)); + eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -3192,7 +3217,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), - eq(configRequest), eq(false), eq(true), eq(true), eq(false)); + eq(configRequest), eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -3247,7 +3272,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), - eq(configRequest), eq(false), eq(true), eq(true), eq(false)); + eq(configRequest), eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -3303,7 +3328,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), - eq(configRequest), eq(false), eq(true), eq(true), eq(false)); + eq(configRequest), eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -3312,7 +3337,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { simulatePowerStateChangeInteractive(false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), - eq(configRequest), eq(false), eq(false), eq(false), eq(false)); + eq(configRequest), eq(false), eq(false), eq(false), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); @@ -3320,7 +3345,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { simulatePowerStateChangeDoze(true); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), - eq(configRequest), eq(false), eq(false), eq(false), eq(true)); + eq(configRequest), eq(false), eq(false), eq(false), eq(true), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); @@ -3328,7 +3353,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { simulatePowerStateChangeInteractive(true); // effectively treated as no-doze mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), - eq(configRequest), eq(false), eq(false), eq(true), eq(true)); + eq(configRequest), eq(false), eq(false), eq(true), eq(true), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); @@ -3371,7 +3396,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); inOrder.verify(mMockNativeManager).tryToGetAware(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), - eq(configRequest), eq(false), eq(true), eq(true), eq(false)); + eq(configRequest), eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -3448,7 +3473,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); inOrder.verify(mMockNativeManager).tryToGetAware(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), - eq(configRequest), eq(false), eq(true), eq(true), eq(false)); + eq(configRequest), eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -3521,7 +3546,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { mMockLooper.dispatchAll(); inOrder.verify(mMockNativeManager).tryToGetAware(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), - eq(configRequest), eq(false), eq(true), eq(true), eq(false)); + eq(configRequest), eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -3591,7 +3616,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), - eq(configRequest), eq(false), eq(true), eq(true), eq(false)); + eq(configRequest), eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); @@ -3607,7 +3632,7 @@ public class WifiAwareStateManagerTest extends WifiBaseTest { configRequest, false); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), - eq(configRequest), eq(false), eq(true), eq(true), eq(false)); + eq(configRequest), eq(false), eq(true), eq(true), eq(false), eq(false)); mDut.onConfigSuccessResponse(transactionId.getValue()); mMockLooper.dispatchAll(); inOrder.verify(mockCallback).onConnectSuccess(clientId); |