[AWARE] update API to comply the API guideline
Update onDataPathConfirm() with reason.
Bug: 168216007
Test: atest android.net.wifi
Change-Id: I70a88d2f017df13f9be6dd3686d663f13e995193
diff --git a/api/current.txt b/api/current.txt
index d20bff2..2bbb98d 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -31863,7 +31863,7 @@
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 @@
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 {
diff --git a/wifi/api/current.txt b/wifi/api/current.txt
index f706118..d6e8922 100644
--- a/wifi/api/current.txt
+++ b/wifi/api/current.txt
@@ -584,7 +584,7 @@
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 @@
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 {
diff --git a/wifi/java/android/net/wifi/aware/DiscoverySessionCallback.java b/wifi/java/android/net/wifi/aware/DiscoverySessionCallback.java
index e3800ad..da8e17e 100644
--- a/wifi/java/android/net/wifi/aware/DiscoverySessionCallback.java
+++ b/wifi/java/android/net/wifi/aware/DiscoverySessionCallback.java
@@ -191,14 +191,18 @@
}
/**
- * 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 */
}
}
diff --git a/wifi/java/android/net/wifi/aware/WifiAwareManager.java b/wifi/java/android/net/wifi/aware/WifiAwareManager.java
index d6e46fd..03f5f40 100644
--- a/wifi/java/android/net/wifi/aware/WifiAwareManager.java
+++ b/wifi/java/android/net/wifi/aware/WifiAwareManager.java
@@ -151,6 +151,27 @@
*/
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 @@
break;
case CALLBACK_MATCH_EXPIRED:
mOriginalCallback
- .onServiceLost(new PeerHandle(msg.arg1));
+ .onServiceLost(new PeerHandle(msg.arg1),
+ WIFI_AWARE_DISCOVERY_LOST_REASON_PEER_NOT_VISIBLE);
}
}
};
diff --git a/wifi/tests/src/android/net/wifi/aware/WifiAwareManagerTest.java b/wifi/tests/src/android/net/wifi/aware/WifiAwareManagerTest.java
index 5fe0cb4..d163fb0 100644
--- a/wifi/tests/src/android/net/wifi/aware/WifiAwareManagerTest.java
+++ b/wifi/tests/src/android/net/wifi/aware/WifiAwareManagerTest.java
@@ -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 @@
// (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 @@
// (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