Merge "[RTT2] Remove Aware RTT code"
This commit is contained in:
committed by
Android (Google) Code Review
commit
2ffdadb8fe
@@ -20,7 +20,6 @@ import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.SystemApi;
|
||||
import android.net.NetworkSpecifier;
|
||||
import android.net.wifi.RttManager;
|
||||
import android.util.Log;
|
||||
|
||||
import dalvik.system.CloseGuard;
|
||||
@@ -223,37 +222,6 @@ public class DiscoverySession implements AutoCloseable {
|
||||
sendMessage(peerHandle, messageId, message, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a ranging operation with the specified peers. The peer IDs are obtained from an
|
||||
* {@link DiscoverySessionCallback#onServiceDiscovered(PeerHandle,
|
||||
* byte[], java.util.List)} or
|
||||
* {@link DiscoverySessionCallback#onMessageReceived(PeerHandle,
|
||||
* byte[])} operation - 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
|
||||
* must be identical). The
|
||||
* {@link android.net.wifi.RttManager.RttParams#bssid} member must be set to
|
||||
* a peer ID - not to a MAC address.
|
||||
* @param listener The listener to receive the results of the ranging session.
|
||||
* @hide
|
||||
* [TODO: b/28847998 - track RTT API & visilibity]
|
||||
*/
|
||||
public void startRanging(RttManager.RttParams[] params, RttManager.RttListener listener) {
|
||||
if (mTerminated) {
|
||||
Log.w(TAG, "startRanging: called on terminated session");
|
||||
return;
|
||||
}
|
||||
|
||||
WifiAwareManager mgr = mMgr.get();
|
||||
if (mgr == null) {
|
||||
Log.w(TAG, "startRanging: called post GC on WifiAwareManager");
|
||||
return;
|
||||
}
|
||||
|
||||
mgr.startRanging(mClientId, mSessionId, params, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link android.net.NetworkRequest.Builder#setNetworkSpecifier(NetworkSpecifier)} for
|
||||
* an unencrypted WiFi Aware connection (link) to the specified peer. The
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package android.net.wifi.aware;
|
||||
|
||||
import android.net.wifi.aware.ConfigRequest;
|
||||
import android.net.wifi.RttManager;
|
||||
|
||||
/**
|
||||
* Callback interface that WifiAwareManager implements
|
||||
@@ -29,8 +28,4 @@ oneway interface IWifiAwareEventCallback
|
||||
void onConnectSuccess(int clientId);
|
||||
void onConnectFail(int reason);
|
||||
void onIdentityChanged(in byte[] mac);
|
||||
|
||||
void onRangingSuccess(int rangingId, in RttManager.ParcelableRttResults results);
|
||||
void onRangingFailure(int rangingId, int reason, in String description);
|
||||
void onRangingAborted(int rangingId);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import android.net.wifi.aware.IWifiAwareEventCallback;
|
||||
import android.net.wifi.aware.PublishConfig;
|
||||
import android.net.wifi.aware.SubscribeConfig;
|
||||
import android.net.wifi.aware.Characteristics;
|
||||
import android.net.wifi.RttManager;
|
||||
|
||||
/**
|
||||
* Interface that WifiAwareService implements
|
||||
@@ -53,5 +52,4 @@ interface IWifiAwareManager
|
||||
void sendMessage(int clientId, int discoverySessionId, int peerId, in byte[] message,
|
||||
int messageId, int retryCount);
|
||||
void terminateSession(int clientId, int discoverySessionId);
|
||||
int startRanging(int clientId, int discoverySessionId, in RttManager.ParcelableRttParams parms);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkRequest;
|
||||
import android.net.NetworkSpecifier;
|
||||
import android.net.wifi.RttManager;
|
||||
import android.os.Binder;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
@@ -35,9 +34,6 @@ import android.os.Message;
|
||||
import android.os.Process;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
|
||||
import libcore.util.HexEncoding;
|
||||
|
||||
@@ -45,7 +41,6 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.nio.BufferOverflowException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -172,9 +167,6 @@ public class WifiAwareManager {
|
||||
|
||||
private final Object mLock = new Object(); // lock access to the following vars
|
||||
|
||||
@GuardedBy("mLock")
|
||||
private SparseArray<RttManager.RttListener> mRangingListeners = new SparseArray<>();
|
||||
|
||||
/** @hide */
|
||||
public WifiAwareManager(Context context, IWifiAwareManager service) {
|
||||
mContext = context;
|
||||
@@ -400,27 +392,6 @@ public class WifiAwareManager {
|
||||
}
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public void startRanging(int clientId, int sessionId, RttManager.RttParams[] params,
|
||||
RttManager.RttListener listener) {
|
||||
if (VDBG) {
|
||||
Log.v(TAG, "startRanging: clientId=" + clientId + ", sessionId=" + sessionId + ", "
|
||||
+ "params=" + Arrays.toString(params) + ", listener=" + listener);
|
||||
}
|
||||
|
||||
int rangingKey = 0;
|
||||
try {
|
||||
rangingKey = mService.startRanging(clientId, sessionId,
|
||||
new RttManager.ParcelableRttParams(params));
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
|
||||
synchronized (mLock) {
|
||||
mRangingListeners.put(rangingKey, listener);
|
||||
}
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public NetworkSpecifier createNetworkSpecifier(int clientId, int role, int sessionId,
|
||||
PeerHandle peerHandle, @Nullable byte[] pmk, @Nullable String passphrase) {
|
||||
@@ -500,29 +471,12 @@ public class WifiAwareManager {
|
||||
private static final int CALLBACK_CONNECT_SUCCESS = 0;
|
||||
private static final int CALLBACK_CONNECT_FAIL = 1;
|
||||
private static final int CALLBACK_IDENTITY_CHANGED = 2;
|
||||
private static final int CALLBACK_RANGING_SUCCESS = 3;
|
||||
private static final int CALLBACK_RANGING_FAILURE = 4;
|
||||
private static final int CALLBACK_RANGING_ABORTED = 5;
|
||||
|
||||
private final Handler mHandler;
|
||||
private final WeakReference<WifiAwareManager> mAwareManager;
|
||||
private final Binder mBinder;
|
||||
private final Looper mLooper;
|
||||
|
||||
RttManager.RttListener getAndRemoveRangingListener(int rangingId) {
|
||||
WifiAwareManager mgr = mAwareManager.get();
|
||||
if (mgr == null) {
|
||||
Log.w(TAG, "getAndRemoveRangingListener: called post GC");
|
||||
return null;
|
||||
}
|
||||
|
||||
synchronized (mgr.mLock) {
|
||||
RttManager.RttListener listener = mgr.mRangingListeners.get(rangingId);
|
||||
mgr.mRangingListeners.delete(rangingId);
|
||||
return listener;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a {@link AttachCallback} using the specified looper.
|
||||
* All callbacks will delivered on the thread of the specified looper.
|
||||
@@ -567,37 +521,6 @@ public class WifiAwareManager {
|
||||
identityChangedListener.onIdentityChanged((byte[]) msg.obj);
|
||||
}
|
||||
break;
|
||||
case CALLBACK_RANGING_SUCCESS: {
|
||||
RttManager.RttListener listener = getAndRemoveRangingListener(msg.arg1);
|
||||
if (listener == null) {
|
||||
Log.e(TAG, "CALLBACK_RANGING_SUCCESS rangingId=" + msg.arg1
|
||||
+ ": no listener registered (anymore)");
|
||||
} else {
|
||||
listener.onSuccess(
|
||||
((RttManager.ParcelableRttResults) msg.obj).mResults);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CALLBACK_RANGING_FAILURE: {
|
||||
RttManager.RttListener listener = getAndRemoveRangingListener(msg.arg1);
|
||||
if (listener == null) {
|
||||
Log.e(TAG, "CALLBACK_RANGING_SUCCESS rangingId=" + msg.arg1
|
||||
+ ": no listener registered (anymore)");
|
||||
} else {
|
||||
listener.onFailure(msg.arg2, (String) msg.obj);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CALLBACK_RANGING_ABORTED: {
|
||||
RttManager.RttListener listener = getAndRemoveRangingListener(msg.arg1);
|
||||
if (listener == null) {
|
||||
Log.e(TAG, "CALLBACK_RANGING_SUCCESS rangingId=" + msg.arg1
|
||||
+ ": no listener registered (anymore)");
|
||||
} else {
|
||||
listener.onAborted();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -629,43 +552,6 @@ public class WifiAwareManager {
|
||||
msg.obj = mac;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRangingSuccess(int rangingId, RttManager.ParcelableRttResults results) {
|
||||
if (VDBG) {
|
||||
Log.v(TAG, "onRangingSuccess: rangingId=" + rangingId + ", results=" + results);
|
||||
}
|
||||
|
||||
Message msg = mHandler.obtainMessage(CALLBACK_RANGING_SUCCESS);
|
||||
msg.arg1 = rangingId;
|
||||
msg.obj = results;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRangingFailure(int rangingId, int reason, String description) {
|
||||
if (VDBG) {
|
||||
Log.v(TAG, "onRangingSuccess: rangingId=" + rangingId + ", reason=" + reason
|
||||
+ ", description=" + description);
|
||||
}
|
||||
|
||||
Message msg = mHandler.obtainMessage(CALLBACK_RANGING_FAILURE);
|
||||
msg.arg1 = rangingId;
|
||||
msg.arg2 = reason;
|
||||
msg.obj = description;
|
||||
mHandler.sendMessage(msg);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRangingAborted(int rangingId) {
|
||||
if (VDBG) Log.v(TAG, "onRangingAborted: rangingId=" + rangingId);
|
||||
|
||||
Message msg = mHandler.obtainMessage(CALLBACK_RANGING_ABORTED);
|
||||
msg.arg1 = rangingId;
|
||||
mHandler.sendMessage(msg);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static class WifiAwareDiscoverySessionCallbackProxy extends
|
||||
|
||||
@@ -844,88 +844,6 @@ public class WifiAwareManagerTest {
|
||||
new PublishConfig.Builder().setTtlSec(-10);
|
||||
}
|
||||
|
||||
/*
|
||||
* Ranging tests
|
||||
*/
|
||||
|
||||
/**
|
||||
* Validate ranging + success flow: (1) connect, (2) create a (publish) session, (3) start
|
||||
* ranging, (4) ranging success callback, (5) ranging aborted callback ignored (since
|
||||
* listener removed).
|
||||
*/
|
||||
@Test
|
||||
public void testRangingCallbacks() throws Exception {
|
||||
final int clientId = 4565;
|
||||
final int sessionId = 123;
|
||||
final int rangingId = 3482;
|
||||
final ConfigRequest configRequest = new ConfigRequest.Builder().build();
|
||||
final PublishConfig publishConfig = new PublishConfig.Builder().build();
|
||||
final RttManager.RttParams rttParams = new RttManager.RttParams();
|
||||
rttParams.deviceType = RttManager.RTT_PEER_NAN;
|
||||
rttParams.bssid = Integer.toString(1234);
|
||||
final RttManager.RttResult rttResults = new RttManager.RttResult();
|
||||
rttResults.distance = 10;
|
||||
|
||||
when(mockAwareService.startRanging(anyInt(), anyInt(), any())).thenReturn(rangingId);
|
||||
|
||||
InOrder inOrder = inOrder(mockCallback, mockSessionCallback, mockAwareService,
|
||||
mockPublishSession, mockRttListener);
|
||||
ArgumentCaptor<WifiAwareSession> sessionCaptor = ArgumentCaptor.forClass(
|
||||
WifiAwareSession.class);
|
||||
ArgumentCaptor<IWifiAwareEventCallback> clientProxyCallback = ArgumentCaptor
|
||||
.forClass(IWifiAwareEventCallback.class);
|
||||
ArgumentCaptor<IWifiAwareDiscoverySessionCallback> sessionProxyCallback = ArgumentCaptor
|
||||
.forClass(IWifiAwareDiscoverySessionCallback.class);
|
||||
ArgumentCaptor<PublishDiscoverySession> publishSession = ArgumentCaptor
|
||||
.forClass(PublishDiscoverySession.class);
|
||||
ArgumentCaptor<RttManager.ParcelableRttParams> rttParamCaptor = ArgumentCaptor
|
||||
.forClass(RttManager.ParcelableRttParams.class);
|
||||
ArgumentCaptor<RttManager.RttResult[]> rttResultsCaptor = ArgumentCaptor
|
||||
.forClass(RttManager.RttResult[].class);
|
||||
|
||||
// (1) connect successfully
|
||||
mDut.attach(mMockLooperHandler, configRequest, mockCallback, null);
|
||||
inOrder.verify(mockAwareService).connect(any(), any(), clientProxyCallback.capture(),
|
||||
eq(configRequest), eq(false));
|
||||
clientProxyCallback.getValue().onConnectSuccess(clientId);
|
||||
mMockLooper.dispatchAll();
|
||||
inOrder.verify(mockCallback).onAttached(sessionCaptor.capture());
|
||||
WifiAwareSession session = sessionCaptor.getValue();
|
||||
|
||||
// (2) publish successfully
|
||||
session.publish(publishConfig, mockSessionCallback, mMockLooperHandler);
|
||||
inOrder.verify(mockAwareService).publish(eq(clientId), eq(publishConfig),
|
||||
sessionProxyCallback.capture());
|
||||
sessionProxyCallback.getValue().onSessionStarted(sessionId);
|
||||
mMockLooper.dispatchAll();
|
||||
inOrder.verify(mockSessionCallback).onPublishStarted(publishSession.capture());
|
||||
|
||||
// (3) start ranging
|
||||
publishSession.getValue().startRanging(new RttManager.RttParams[]{rttParams},
|
||||
mockRttListener);
|
||||
inOrder.verify(mockAwareService).startRanging(eq(clientId), eq(sessionId),
|
||||
rttParamCaptor.capture());
|
||||
collector.checkThat("RttParams.deviceType", rttParams.deviceType,
|
||||
equalTo(rttParamCaptor.getValue().mParams[0].deviceType));
|
||||
collector.checkThat("RttParams.bssid", rttParams.bssid,
|
||||
equalTo(rttParamCaptor.getValue().mParams[0].bssid));
|
||||
|
||||
// (4) ranging success callback
|
||||
clientProxyCallback.getValue().onRangingSuccess(rangingId,
|
||||
new RttManager.ParcelableRttResults(new RttManager.RttResult[] { rttResults }));
|
||||
mMockLooper.dispatchAll();
|
||||
inOrder.verify(mockRttListener).onSuccess(rttResultsCaptor.capture());
|
||||
collector.checkThat("RttResult.distance", rttResults.distance,
|
||||
equalTo(rttResultsCaptor.getValue()[0].distance));
|
||||
|
||||
// (5) ranging aborted callback (should be ignored since listener cleared on first callback)
|
||||
clientProxyCallback.getValue().onRangingAborted(rangingId);
|
||||
mMockLooper.dispatchAll();
|
||||
|
||||
verifyNoMoreInteractions(mockCallback, mockSessionCallback, mockAwareService,
|
||||
mockPublishSession, mockRttListener);
|
||||
}
|
||||
|
||||
/*
|
||||
* Data-path tests
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user