Merge "[AWARE] update API to comply the API guideline"

This commit is contained in:
TreeHugger Robot
2020-10-16 18:44:17 +00:00
committed by Android (Google) Code Review
5 changed files with 41 additions and 8 deletions

View File

@@ -31863,7 +31863,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 onServiceLost(@NonNull android.net.wifi.aware.PeerHandle, int);
method public void onSessionConfigFailed();
method public void onSessionConfigUpdated();
method public void onSessionTerminated();
@@ -31943,6 +31943,8 @@ package android.net.wifi.aware {
field public static final String ACTION_WIFI_AWARE_STATE_CHANGED = "android.net.wifi.aware.action.WIFI_AWARE_STATE_CHANGED";
field public static final int WIFI_AWARE_DATA_PATH_ROLE_INITIATOR = 0; // 0x0
field public static final int WIFI_AWARE_DATA_PATH_ROLE_RESPONDER = 1; // 0x1
field public static final int WIFI_AWARE_DISCOVERY_LOST_REASON_PEER_NOT_VISIBLE = 1; // 0x1
field public static final int WIFI_AWARE_DISCOVERY_LOST_REASON_UNKNOWN = 0; // 0x0
}
public final class WifiAwareNetworkInfo implements android.os.Parcelable android.net.TransportInfo {

View File

@@ -584,7 +584,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 onServiceLost(@NonNull android.net.wifi.aware.PeerHandle, int);
method public void onSessionConfigFailed();
method public void onSessionConfigUpdated();
method public void onSessionTerminated();
@@ -664,6 +664,8 @@ package android.net.wifi.aware {
field public static final String ACTION_WIFI_AWARE_STATE_CHANGED = "android.net.wifi.aware.action.WIFI_AWARE_STATE_CHANGED";
field public static final int WIFI_AWARE_DATA_PATH_ROLE_INITIATOR = 0; // 0x0
field public static final int WIFI_AWARE_DATA_PATH_ROLE_RESPONDER = 1; // 0x1
field public static final int WIFI_AWARE_DISCOVERY_LOST_REASON_PEER_NOT_VISIBLE = 1; // 0x1
field public static final int WIFI_AWARE_DISCOVERY_LOST_REASON_UNKNOWN = 0; // 0x0
}
public final class WifiAwareNetworkInfo implements android.os.Parcelable android.net.TransportInfo {

View File

@@ -191,14 +191,18 @@ public class DiscoverySessionCallback {
}
/**
* Called when the discovered peer is no longer visible. All further operations on this
* discovery session will fail. If the peer is visible again,
* Called when the discovered service is not available. All further operations on this
* discovery session will fail. If the service is available 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.
* @param reason Discovered service lost reason code. One of
* {@link WifiAwareManager#WIFI_AWARE_DISCOVERY_LOST_REASON_PEER_NOT_VISIBLE},
* {@link WifiAwareManager#WIFI_AWARE_DISCOVERY_LOST_REASON_UNKNOWN
*/
public void onServiceLost(@NonNull PeerHandle peerHandle) {
public void onServiceLost(@NonNull PeerHandle peerHandle,
@WifiAwareManager.DiscoveryLostReasonCode int reason) {
/* empty */
}
}

View File

@@ -151,6 +151,27 @@ public class WifiAwareManager {
*/
public static final int WIFI_AWARE_DATA_PATH_ROLE_RESPONDER = 1;
/** @hide */
@IntDef({
WIFI_AWARE_DISCOVERY_LOST_REASON_UNKNOWN,
WIFI_AWARE_DISCOVERY_LOST_REASON_PEER_NOT_VISIBLE})
@Retention(RetentionPolicy.SOURCE)
public @interface DiscoveryLostReasonCode {
}
/**
* Reason code provided in {@link DiscoverySessionCallback#onServiceLost(PeerHandle, int)}
* indicating that the service was lost for unknown reason.
*/
public static final int WIFI_AWARE_DISCOVERY_LOST_REASON_UNKNOWN = 0;
/**
* Reason code provided in {@link DiscoverySessionCallback#onServiceLost(PeerHandle, int)}
* indicating that the service advertised by the peer is no longer visible. This may be because
* the peer is out of range or because the peer stopped advertising this service.
*/
public static final int WIFI_AWARE_DISCOVERY_LOST_REASON_PEER_NOT_VISIBLE = 1;
private final Context mContext;
private final IWifiAwareManager mService;
@@ -695,7 +716,8 @@ public class WifiAwareManager {
break;
case CALLBACK_MATCH_EXPIRED:
mOriginalCallback
.onServiceLost(new PeerHandle(msg.arg1));
.onServiceLost(new PeerHandle(msg.arg1),
WIFI_AWARE_DISCOVERY_LOST_REASON_PEER_NOT_VISIBLE);
}
}
};

View File

@@ -16,6 +16,7 @@
package android.net.wifi.aware;
import static android.net.wifi.aware.WifiAwareManager.WIFI_AWARE_DISCOVERY_LOST_REASON_PEER_NOT_VISIBLE;
import static android.net.wifi.aware.WifiAwareNetworkSpecifier.NETWORK_SPECIFIER_TYPE_IB;
import static org.hamcrest.core.IsEqual.equalTo;
@@ -372,7 +373,8 @@ public class WifiAwareManagerTest {
// (5) discovery session is no longer visible
sessionProxyCallback.getValue().onMatchExpired(peerHandle.peerId);
mMockLooper.dispatchAll();
inOrder.verify(mockSessionCallback).onServiceLost(peerIdCaptor.capture());
inOrder.verify(mockSessionCallback).onServiceLost(peerIdCaptor.capture(),
eq(WIFI_AWARE_DISCOVERY_LOST_REASON_PEER_NOT_VISIBLE));
assertEquals(peerHandle.peerId, peerIdCaptor.getValue().peerId);
// (6) terminate
@@ -520,7 +522,8 @@ public class WifiAwareManagerTest {
// (5) discovery session is no longer visible
sessionProxyCallback.getValue().onMatchExpired(peerHandle.peerId);
mMockLooper.dispatchAll();
inOrder.verify(mockSessionCallback).onServiceLost(peerIdCaptor.capture());
inOrder.verify(mockSessionCallback).onServiceLost(peerIdCaptor.capture(),
eq(WIFI_AWARE_DISCOVERY_LOST_REASON_PEER_NOT_VISIBLE));
assertEquals(peerHandle.peerId, peerIdCaptor.getValue().peerId);
// (6) terminate