Merge "[AWARE] API indicating when a Service is no longer visible"
This commit is contained in:
committed by
Android (Google) Code Review
commit
f52bdb9c83
@@ -31738,6 +31738,7 @@ package android.net.wifi.aware {
|
||||
method public void onPublishStarted(@NonNull android.net.wifi.aware.PublishDiscoverySession);
|
||||
method public void onServiceDiscovered(android.net.wifi.aware.PeerHandle, byte[], java.util.List<byte[]>);
|
||||
method public void onServiceDiscoveredWithinRange(android.net.wifi.aware.PeerHandle, byte[], java.util.List<byte[]>, int);
|
||||
method public void onServiceLost(@NonNull android.net.wifi.aware.PeerHandle);
|
||||
method public void onSessionConfigFailed();
|
||||
method public void onSessionConfigUpdated();
|
||||
method public void onSessionTerminated();
|
||||
|
||||
@@ -579,6 +579,7 @@ package android.net.wifi.aware {
|
||||
method public void onPublishStarted(@NonNull android.net.wifi.aware.PublishDiscoverySession);
|
||||
method public void onServiceDiscovered(android.net.wifi.aware.PeerHandle, byte[], java.util.List<byte[]>);
|
||||
method public void onServiceDiscoveredWithinRange(android.net.wifi.aware.PeerHandle, byte[], java.util.List<byte[]>, int);
|
||||
method public void onServiceLost(@NonNull android.net.wifi.aware.PeerHandle);
|
||||
method public void onSessionConfigFailed();
|
||||
method public void onSessionConfigUpdated();
|
||||
method public void onSessionTerminated();
|
||||
|
||||
@@ -189,4 +189,16 @@ public class DiscoverySessionCallback {
|
||||
public void onMessageReceived(PeerHandle peerHandle, byte[] message) {
|
||||
/* empty */
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the discovered peer is no longer visible. All further operations on this
|
||||
* discovery session will fail. If the peer is visible again,
|
||||
* {@link #onServiceDiscovered(PeerHandle, byte[], List)} or
|
||||
* {@link #onServiceDiscoveredWithinRange(PeerHandle, byte[], List, int)} will be called.
|
||||
*
|
||||
* @param peerHandle An opaque handle to the peer matching our discovery operation.
|
||||
*/
|
||||
public void onServiceLost(@NonNull PeerHandle peerHandle) {
|
||||
/* empty */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,4 +35,5 @@ oneway interface IWifiAwareDiscoverySessionCallback
|
||||
void onMessageSendSuccess(int messageId);
|
||||
void onMessageSendFail(int messageId, int reason);
|
||||
void onMessageReceived(int peerId, in byte[] message);
|
||||
void onMatchExpired(int peerId);
|
||||
}
|
||||
|
||||
@@ -587,6 +587,7 @@ public class WifiAwareManager {
|
||||
private static final int CALLBACK_MESSAGE_SEND_FAIL = 6;
|
||||
private static final int CALLBACK_MESSAGE_RECEIVED = 7;
|
||||
private static final int CALLBACK_MATCH_WITH_DISTANCE = 8;
|
||||
private static final int CALLBACK_MATCH_EXPIRED = 9;
|
||||
|
||||
private static final String MESSAGE_BUNDLE_KEY_MESSAGE = "message";
|
||||
private static final String MESSAGE_BUNDLE_KEY_MESSAGE2 = "message2";
|
||||
@@ -676,6 +677,9 @@ public class WifiAwareManager {
|
||||
mOriginalCallback.onMessageReceived(new PeerHandle(msg.arg1),
|
||||
(byte[]) msg.obj);
|
||||
break;
|
||||
case CALLBACK_MATCH_EXPIRED:
|
||||
mOriginalCallback
|
||||
.onServiceLost(new PeerHandle(msg.arg1));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -746,6 +750,15 @@ public class WifiAwareManager {
|
||||
onMatchCommon(CALLBACK_MATCH_WITH_DISTANCE, peerId, serviceSpecificInfo, matchFilter,
|
||||
distanceMm);
|
||||
}
|
||||
@Override
|
||||
public void onMatchExpired(int peerId) {
|
||||
if (VDBG) {
|
||||
Log.v(TAG, "onMatchExpired: peerId=" + peerId);
|
||||
}
|
||||
Message msg = mHandler.obtainMessage(CALLBACK_MATCH_EXPIRED);
|
||||
msg.arg1 = peerId;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageSendSuccess(int messageId) {
|
||||
|
||||
@@ -360,12 +360,18 @@ public class WifiAwareManagerTest {
|
||||
eq(publishConfig));
|
||||
inOrder.verify(mockSessionCallback).onSessionConfigFailed();
|
||||
|
||||
// (5) terminate
|
||||
// (5) discovery session is no longer visible
|
||||
sessionProxyCallback.getValue().onMatchExpired(peerHandle.peerId);
|
||||
mMockLooper.dispatchAll();
|
||||
inOrder.verify(mockSessionCallback).onServiceLost(peerIdCaptor.capture());
|
||||
assertEquals(peerHandle.peerId, peerIdCaptor.getValue().peerId);
|
||||
|
||||
// (6) terminate
|
||||
publishSession.getValue().close();
|
||||
mMockLooper.dispatchAll();
|
||||
inOrder.verify(mockAwareService).terminateSession(clientId, sessionId);
|
||||
|
||||
// (6) try an update (nothing)
|
||||
// (7) try an update (nothing)
|
||||
publishSession.getValue().updatePublish(publishConfig);
|
||||
mMockLooper.dispatchAll();
|
||||
|
||||
@@ -502,12 +508,18 @@ public class WifiAwareManagerTest {
|
||||
eq(subscribeConfig));
|
||||
inOrder.verify(mockSessionCallback).onSessionConfigFailed();
|
||||
|
||||
// (5) terminate
|
||||
// (5) discovery session is no longer visible
|
||||
sessionProxyCallback.getValue().onMatchExpired(peerHandle.peerId);
|
||||
mMockLooper.dispatchAll();
|
||||
inOrder.verify(mockSessionCallback).onServiceLost(peerIdCaptor.capture());
|
||||
assertEquals(peerHandle.peerId, peerIdCaptor.getValue().peerId);
|
||||
|
||||
// (6) terminate
|
||||
subscribeSession.getValue().close();
|
||||
mMockLooper.dispatchAll();
|
||||
inOrder.verify(mockAwareService).terminateSession(clientId, sessionId);
|
||||
|
||||
// (6) try an update (nothing)
|
||||
// (7) try an update (nothing)
|
||||
subscribeSession.getValue().updateSubscribe(subscribeConfig);
|
||||
mMockLooper.dispatchAll();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user