Merge "Make the constructor of InputMethodSubtype hidden."
diff --git a/core/java/android/net/NetworkStats.java b/core/java/android/net/NetworkStats.java
index e5f3273..3918cfd 100644
--- a/core/java/android/net/NetworkStats.java
+++ b/core/java/android/net/NetworkStats.java
@@ -320,15 +320,36 @@
* checking if a {@link #subtract(NetworkStats)} delta passes a threshold.
*/
public long getTotalBytes() {
- long totalBytes = 0;
+ final Entry entry = getTotal(null);
+ return entry.rxBytes + entry.txBytes;
+ }
+
+ /**
+ * Return total of all fields represented by this snapshot object.
+ */
+ public Entry getTotal(Entry recycle) {
+ final Entry entry = recycle != null ? recycle : new Entry();
+
+ entry.iface = IFACE_ALL;
+ entry.uid = UID_ALL;
+ entry.set = SET_ALL;
+ entry.tag = TAG_NONE;
+ entry.rxBytes = 0;
+ entry.rxPackets = 0;
+ entry.txBytes = 0;
+ entry.txPackets = 0;
+
for (int i = 0; i < size; i++) {
// skip specific tags, since already counted in TAG_NONE
if (tag[i] != TAG_NONE) continue;
- totalBytes += rxBytes[i];
- totalBytes += txBytes[i];
+ entry.rxBytes += rxBytes[i];
+ entry.rxPackets += rxPackets[i];
+ entry.txBytes += txBytes[i];
+ entry.txPackets += txPackets[i];
+ entry.operations += operations[i];
}
- return totalBytes;
+ return entry;
}
/**
diff --git a/services/java/com/android/server/EventLogTags.logtags b/services/java/com/android/server/EventLogTags.logtags
index 5429c0c..f0b5958 100644
--- a/services/java/com/android/server/EventLogTags.logtags
+++ b/services/java/com/android/server/EventLogTags.logtags
@@ -137,3 +137,10 @@
# [ 8- 3] Detailed state ordinal (as defined by NetworkInfo.DetailedState)
# [ 2- 0] Network type (as defined by ConnectivityManager)
50020 connectivity_state_changed (custom|1|5)
+
+
+# ---------------------------
+# NetworkStatsService.java
+# ---------------------------
+51100 netstats_mobile_sample (iface_rx|2|2),(iface_tx|2|2),(uid_rx|2|2),(uid_tx|2|2)
+51101 netstats_wifi_sample (iface_rx|2|2),(iface_tx|2|2),(uid_rx|2|2),(uid_tx|2|2)
diff --git a/services/java/com/android/server/NetworkManagementService.java b/services/java/com/android/server/NetworkManagementService.java
index 85d8cece..1497511 100644
--- a/services/java/com/android/server/NetworkManagementService.java
+++ b/services/java/com/android/server/NetworkManagementService.java
@@ -1033,6 +1033,38 @@
final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 6);
final NetworkStats.Entry entry = new NetworkStats.Entry();
+ final HashSet<String> knownIfaces = Sets.newHashSet();
+ final HashSet<String> activeIfaces = Sets.newHashSet();
+
+ // collect any historical stats and active state
+ // TODO: migrate to reading from single file
+ if (mBandwidthControlEnabled) {
+ for (String iface : fileListWithoutNull(mStatsXtIface)) {
+ final File ifacePath = new File(mStatsXtIface, iface);
+
+ final long active = readSingleLongFromFile(new File(ifacePath, "active"));
+ if (active == 1) {
+ knownIfaces.add(iface);
+ activeIfaces.add(iface);
+ } else if (active == 0) {
+ knownIfaces.add(iface);
+ } else {
+ continue;
+ }
+
+ entry.iface = iface;
+ entry.uid = UID_ALL;
+ entry.set = SET_DEFAULT;
+ entry.tag = TAG_NONE;
+ entry.rxBytes = readSingleLongFromFile(new File(ifacePath, "rx_bytes"));
+ entry.rxPackets = readSingleLongFromFile(new File(ifacePath, "rx_packets"));
+ entry.txBytes = readSingleLongFromFile(new File(ifacePath, "tx_bytes"));
+ entry.txPackets = readSingleLongFromFile(new File(ifacePath, "tx_packets"));
+
+ stats.addValues(entry);
+ }
+ }
+
final ArrayList<String> values = Lists.newArrayList();
BufferedReader reader = null;
@@ -1058,7 +1090,13 @@
entry.txBytes = Long.parseLong(values.get(9));
entry.txPackets = Long.parseLong(values.get(10));
- stats.addValues(entry);
+ if (activeIfaces.contains(entry.iface)) {
+ // combine stats when iface is active
+ stats.combineValues(entry);
+ } else if (!knownIfaces.contains(entry.iface)) {
+ // add stats when iface is unknown
+ stats.addValues(entry);
+ }
} catch (NumberFormatException e) {
Slog.w(TAG, "problem parsing stats row '" + line + "': " + e);
}
@@ -1073,24 +1111,6 @@
IoUtils.closeQuietly(reader);
}
- // splice in historical stats not reflected in mStatsIface
- if (mBandwidthControlEnabled) {
- for (String iface : fileListWithoutNull(mStatsXtIface)) {
- final File ifacePath = new File(mStatsXtIface, iface);
-
- entry.iface = iface;
- entry.uid = UID_ALL;
- entry.set = SET_DEFAULT;
- entry.tag = TAG_NONE;
- entry.rxBytes = readSingleLongFromFile(new File(ifacePath, "rx_bytes"));
- entry.rxPackets = readSingleLongFromFile(new File(ifacePath, "rx_packets"));
- entry.txBytes = readSingleLongFromFile(new File(ifacePath, "tx_bytes"));
- entry.txPackets = readSingleLongFromFile(new File(ifacePath, "tx_packets"));
-
- stats.combineValues(entry);
- }
- }
-
return stats;
}
diff --git a/services/java/com/android/server/net/NetworkStatsService.java b/services/java/com/android/server/net/NetworkStatsService.java
index e0dc96f..4d54fd4 100644
--- a/services/java/com/android/server/net/NetworkStatsService.java
+++ b/services/java/com/android/server/net/NetworkStatsService.java
@@ -31,6 +31,8 @@
import static android.net.NetworkStats.SET_FOREGROUND;
import static android.net.NetworkStats.TAG_NONE;
import static android.net.NetworkStats.UID_ALL;
+import static android.net.NetworkTemplate.buildTemplateMobileAll;
+import static android.net.NetworkTemplate.buildTemplateWifi;
import static android.net.TrafficStats.UID_REMOVED;
import static android.provider.Settings.Secure.NETSTATS_NETWORK_BUCKET_DURATION;
import static android.provider.Settings.Secure.NETSTATS_NETWORK_MAX_HISTORY;
@@ -76,6 +78,7 @@
import android.os.SystemClock;
import android.provider.Settings;
import android.telephony.TelephonyManager;
+import android.util.EventLog;
import android.util.NtpTrustedTime;
import android.util.Slog;
import android.util.SparseIntArray;
@@ -83,6 +86,7 @@
import com.android.internal.os.AtomicFile;
import com.android.internal.util.Objects;
+import com.android.server.EventLogTags;
import com.google.android.collect.Lists;
import com.google.android.collect.Maps;
import com.google.android.collect.Sets;
@@ -387,7 +391,9 @@
entry.uid = UID_ALL;
entry.tag = TAG_NONE;
entry.rxBytes = historyEntry.rxBytes;
+ entry.rxPackets = historyEntry.rxPackets;
entry.txBytes = historyEntry.txBytes;
+ entry.txPackets = historyEntry.txPackets;
stats.combineValues(entry);
}
@@ -716,6 +722,11 @@
Slog.v(TAG, "performPollLocked() took " + duration + "ms");
}
+ // sample stats after detailed poll
+ if (detailedPoll) {
+ performSample();
+ }
+
// finally, dispatch updated event to any listeners
final Intent updatedIntent = new Intent(ACTION_NETWORK_STATS_UPDATED);
updatedIntent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
@@ -809,6 +820,33 @@
}
/**
+ * Sample recent statistics summary into {@link EventLog}.
+ */
+ private void performSample() {
+ // take sample as total over last 4 hours
+ final long end = mTime.hasCache() ? mTime.currentTimeMillis() : System.currentTimeMillis();
+ final long start = end - (4 * HOUR_IN_MILLIS);
+
+ NetworkTemplate template = null;
+ NetworkStats.Entry ifaceTotal = null;
+ NetworkStats.Entry uidTotal = null;
+
+ // collect mobile sample
+ template = buildTemplateMobileAll(getActiveSubscriberId(mContext));
+ ifaceTotal = getSummaryForNetwork(template, start, end).getTotal(ifaceTotal);
+ uidTotal = getSummaryForAllUid(template, start, end, false).getTotal(uidTotal);
+ EventLogTags.writeNetstatsMobileSample(
+ ifaceTotal.rxBytes, ifaceTotal.txBytes, uidTotal.rxBytes, uidTotal.txBytes);
+
+ // collect wifi sample
+ template = buildTemplateWifi();
+ ifaceTotal = getSummaryForNetwork(template, start, end).getTotal(ifaceTotal);
+ uidTotal = getSummaryForAllUid(template, start, end, false).getTotal(uidTotal);
+ EventLogTags.writeNetstatsWifiSample(
+ ifaceTotal.rxBytes, ifaceTotal.txBytes, uidTotal.rxBytes, uidTotal.txBytes);
+ }
+
+ /**
* Clean up {@link #mUidStats} after UID is removed.
*/
private void removeUidLocked(int uid) {
@@ -1249,6 +1287,12 @@
}
};
+ private static String getActiveSubscriberId(Context context) {
+ final TelephonyManager telephony = (TelephonyManager) context.getSystemService(
+ Context.TELEPHONY_SERVICE);
+ return telephony.getSubscriberId();
+ }
+
/**
* Key uniquely identifying a {@link NetworkStatsHistory} for a UID.
*/
diff --git a/services/tests/servicestests/src/com/android/server/NetworkManagementServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkManagementServiceTest.java
index ecf78d9..2a25866 100644
--- a/services/tests/servicestests/src/com/android/server/NetworkManagementServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/NetworkManagementServiceTest.java
@@ -106,6 +106,7 @@
public void testNetworkStatsSummaryDown() throws Exception {
stageFile(R.raw.net_dev_typical, new File(mTestProc, "net/dev"));
+ stageLong(1L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/active"));
stageLong(1024L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/rx_bytes"));
stageLong(128L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/rx_packets"));
stageLong(2048L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/tx_bytes"));
@@ -119,6 +120,7 @@
public void testNetworkStatsCombined() throws Exception {
stageFile(R.raw.net_dev_typical, new File(mTestProc, "net/dev"));
+ stageLong(1L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/active"));
stageLong(10L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/rx_bytes"));
stageLong(20L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/rx_packets"));
stageLong(30L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/tx_bytes"));
@@ -129,6 +131,18 @@
2205L + 20L, 489339L + 30L, 2237L + 40L);
}
+ public void testNetworkStatsCombinedInactive() throws Exception {
+ stageFile(R.raw.net_dev_typical, new File(mTestProc, "net/dev"));
+ stageLong(0L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/active"));
+ stageLong(10L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/rx_bytes"));
+ stageLong(20L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/rx_packets"));
+ stageLong(30L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/tx_bytes"));
+ stageLong(40L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/tx_packets"));
+
+ final NetworkStats stats = mService.getNetworkStatsSummary();
+ assertStatsEntry(stats, "rmnet0", UID_ALL, SET_DEFAULT, TAG_NONE, 10L, 20L, 30L, 40L);
+ }
+
public void testKernelTags() throws Exception {
assertEquals("0", tagToKernel(0x0));
assertEquals("214748364800", tagToKernel(0x32));
diff --git a/wifi/java/android/net/wifi/WpsConfiguration.java b/wifi/java/android/net/wifi/WpsConfiguration.java
index 2e7689a..0c2adfd 100644
--- a/wifi/java/android/net/wifi/WpsConfiguration.java
+++ b/wifi/java/android/net/wifi/WpsConfiguration.java
@@ -46,16 +46,21 @@
public Setup setup;
+ /** @hide */
public String BSSID;
public String pin;
+ /** @hide */
public IpAssignment ipAssignment;
+ /** @hide */
public ProxySettings proxySettings;
+ /** @hide */
public LinkProperties linkProperties;
+ /** @hide */
public WpsConfiguration() {
setup = Setup.INVALID;
BSSID = null;
@@ -65,6 +70,7 @@
linkProperties = new LinkProperties();
}
+ /** @hide */
public String toString() {
StringBuffer sbuf = new StringBuffer();
sbuf.append(" setup: ").append(setup.toString());
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pConfig.java b/wifi/java/android/net/wifi/p2p/WifiP2pConfig.java
index 2d57363..686d698 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pConfig.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pConfig.java
@@ -28,11 +28,6 @@
public class WifiP2pConfig implements Parcelable {
/**
- * Device name
- */
- public String deviceName;
-
- /**
* Device address
*/
public String deviceAddress;
@@ -53,6 +48,7 @@
/**
* Indicates whether the configuration is saved
+ * @hide
*/
public enum Persist {
SYSTEM_DEFAULT,
@@ -60,6 +56,7 @@
NO
}
+ /** @hide */
public Persist persist = Persist.SYSTEM_DEFAULT;
public WifiP2pConfig() {
@@ -110,7 +107,6 @@
public String toString() {
StringBuffer sbuf = new StringBuffer();
- sbuf.append("Device: ").append(deviceName);
sbuf.append("\n address: ").append(deviceAddress);
sbuf.append("\n wps: ").append(wpsConfig);
sbuf.append("\n groupOwnerIntent: ").append(groupOwnerIntent);
@@ -132,7 +128,6 @@
/** Implement the Parcelable interface {@hide} */
public void writeToParcel(Parcel dest, int flags) {
- dest.writeString(deviceName);
dest.writeString(deviceAddress);
dest.writeParcelable(wpsConfig, flags);
dest.writeInt(groupOwnerIntent);
@@ -144,7 +139,6 @@
new Creator<WifiP2pConfig>() {
public WifiP2pConfig createFromParcel(Parcel in) {
WifiP2pConfig config = new WifiP2pConfig();
- config.deviceName = in.readString();
config.deviceAddress = in.readString();
config.wpsConfig = (WpsConfiguration) in.readParcelable(null);
config.groupOwnerIntent = in.readInt();
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pGroup.java b/wifi/java/android/net/wifi/p2p/WifiP2pGroup.java
index ca6e4d5..14246b4 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pGroup.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pGroup.java
@@ -69,7 +69,7 @@
}
/**
- * @param string formats supported include
+ * @param supplicantEvent formats supported include
*
* P2P-GROUP-STARTED p2p-wlan0-0 [client|GO] ssid="DIRECT-W8" freq=2437
* [psk=2182b2e50e53f260d04f3c7b25ef33c965a3291b9b36b455a82d77fd82ca15bc|
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pInfo.java b/wifi/java/android/net/wifi/p2p/WifiP2pInfo.java
index 9dc2fbf..a02175e 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pInfo.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pInfo.java
@@ -34,9 +34,11 @@
public InetAddress groupOwnerAddress;
- public WifiP2pInfo() {
+ /** @hide */
+ WifiP2pInfo() {
}
+ /** @hide */
public String toString() {
StringBuffer sbuf = new StringBuffer();
sbuf.append("groupFormed: ").append(groupFormed)
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pManager.java b/wifi/java/android/net/wifi/p2p/WifiP2pManager.java
index 25daf1c..0bdd269 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pManager.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pManager.java
@@ -35,25 +35,64 @@
import com.android.internal.util.Protocol;
/**
- * This class provides the API for managing Wi-Fi p2p
- * connectivity. Get an instance of this class by calling
- * {@link android.content.Context#getSystemService(String)
+ * This class provides the API for managing Wi-Fi peer-to-peer connectivity. This lets an
+ * application discover available peers, setup connection to peers and query for the list of peers.
+ * When a p2p connection is formed over wifi, the device continues to maintain the uplink
+ * connection over mobile or any other available network for internet connectivity on the device.
+ *
+ * <p> The API is asynchronous and response to a request from an application is sent in the form
+ * of a {@link android.os.Message} on a {@link android.os.Handler} that needs to be initialized
+ * by the application right at the beginning before any p2p operations are performed via
+ * {@link #initialize}.
+ *
+ * <p> An application can request for the current list of peers using {@link #requestPeers}. The
+ * {@link #RESPONSE_PEERS} message on the handler indicates that the peer list is available.
+ * Use {@link #peersInResponse} to extract the peer device list upon the receiving the
+ * {@link #RESPONSE_PEERS} message.
+ *
+ * <p> If an application needs to initiate a discovery, use {@link #discoverPeers} and listen
+ * to {@link #WIFI_P2P_PEERS_CHANGED_ACTION} intent action to initiate a request to fetch
+ * list of peers with {@link #requestPeers}. An initiated discovery request from an application
+ * stays active until the device starts connecting to a peer or forms a p2p group.
+ *
+ * <p> An application can initiate a connection request to a peer through {@link #connect}. See
+ * {@link WifiP2pConfig} for details on setting up the configuration. For communication with legacy
+ * Wi-Fi devices that do not support p2p, an app can create a group using {@link #createGroup}
+ * which creates an access point whose details can be fetched with {@link #requestGroupInfo}.
+ *
+ * <p> After a successful group formation through {@link #createGroup} or through {@link #connect},
+ * use {@link #requestConnectionInfo} to fetch the connection details. Connection information
+ * can be obtained with {@link #connectionInfoInResponse} on a {@link #RESPONSE_CONNECTION_INFO}
+ * message. The connection info {@link WifiP2pInfo} contains the address of the group owner
+ * {@link WifiP2pInfo#groupOwnerAddress} and a flag {@link #WifiP2pInfo#isGroupOwner} to indicate
+ * if the current device is a p2p group owner. A p2p client can thus communicate with
+ * the p2p group owner through a socket connection.
+ *
+ * <p> Android has no platform support for service discovery yet, so applications could
+ * run a service discovery protocol to discover services on the peer-to-peer netework.
+ *
+ * <p class="note"><strong>Note:</strong>
+ * Registering an application handler with {@link #initialize} requires the permissions
+ * {@link android.Manifest.permission#ACCESS_WIFI_STATE} and
+ * {@link android.Manifest.permission#CHANGE_WIFI_STATE} to perform any further peer-to-peer
+ * operations.
+ *
+ * Get an instance of this class by calling {@link android.content.Context#getSystemService(String)
* Context.getSystemService(Context.WIFI_P2P_SERVICE)}.
*
- * It deals with the following:
- * <ul>
- * <li>Wi-Fi peer discovery and connection setup. Allows applications to initiate a discovery to
- * find available peers and then setup a connection </li>
- * <li>Configuration and status query. Allows applications to fetch the current list
- * of available and connected peers and query connection status </li>
- * <li>Intent actions that are broadcast to track operations
- * on a p2p connection</li>
- * </ul>
+ * {@see WifiP2pConfig}
+ * {@see WifiP2pInfo}
+ * {@see WifiP2pGroup}
+ * {@see WifiP2pDevice}
+ * {@see WifiP2pDeviceList}
* @hide
*/
public class WifiP2pManager {
/**
- * Broadcast intent action to indicate whether Wi-Fi p2p is enabled or disabled.
+ * Broadcast intent action to indicate whether Wi-Fi p2p is enabled or disabled. An
+ * extra {@link #EXTRA_WIFI_STATE} provides the state information as int.
+ *
+ * @see #EXTRA_WIFI_STATE
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String WIFI_P2P_STATE_CHANGED_ACTION =
@@ -72,7 +111,6 @@
* Wi-Fi p2p is disabled.
*
* @see #WIFI_P2P_STATE_CHANGED_ACTION
- * @see #getWifiP2pState()
*/
public static final int WIFI_P2P_STATE_DISABLED = 1;
@@ -80,14 +118,16 @@
* Wi-Fi p2p is enabled.
*
* @see #WIFI_P2P_STATE_CHANGED_ACTION
- * @see #getWifiP2pState()
*/
public static final int WIFI_P2P_STATE_ENABLED = 2;
/**
* Broadcast intent action indicating that the state of Wi-Fi p2p connectivity
- * has changed. One extra provides the new state
- * in the form of a {@link android.net.NetworkInfo} object.
+ * has changed. One extra {@link #EXTRA_WIFI_P2P_INFO} provides the p2p connection info in
+ * the form of a {@link WifiP2pInfo} object. Another extra {@link #EXTRA_NETWORK_INFO} provides
+ * the network info in the form of a {@link android.net.NetworkInfo}.
+ *
+ * @see #EXTRA_WIFI_P2P_INFO
* @see #EXTRA_NETWORK_INFO
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
@@ -124,7 +164,8 @@
public static final String EXTRA_LINK_CAPABILITIES = "linkCapabilities";
/**
- * Broadcast intent action indicating that the available peer list has changed
+ * Broadcast intent action indicating that the available peer list has changed. Fetch
+ * the changed list of peers with {@link #requestPeers}
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String WIFI_P2P_PEERS_CHANGED_ACTION =
@@ -134,6 +175,7 @@
* Activity Action: Pick a Wi-Fi p2p network to connect to.
* <p>Input: Nothing.
* <p>Output: Nothing.
+ * @hide
*/
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
public static final String ACTION_PICK_WIFI_P2P_NETWORK =
@@ -141,47 +183,169 @@
IWifiP2pManager mService;
- /* AsyncChannel notifications to apps */
- public static final int HANDLER_CONNECTION = AsyncChannel.CMD_CHANNEL_HALF_CONNECTED;
+ /**
+ * Message {@link android.os.Message#what} sent on the application handler specified
+ * at {@link #initialize} indicating the asynchronous channel has disconnected. An
+ * application could choose to reconnect with {@link #initialize}
+ */
public static final int HANDLER_DISCONNECTION = AsyncChannel.CMD_CHANNEL_DISCONNECTED;
private static final int BASE = Protocol.BASE_WIFI_P2P_MANAGER;
+ /** @hide */
public static final int ENABLE_P2P = BASE + 1;
+ /** @hide */
public static final int ENABLE_P2P_FAILED = BASE + 2;
+ /** @hide */
public static final int ENABLE_P2P_SUCCEEDED = BASE + 3;
+ /** @hide */
public static final int DISABLE_P2P = BASE + 4;
+ /** @hide */
public static final int DISABLE_P2P_FAILED = BASE + 5;
+ /** @hide */
public static final int DISABLE_P2P_SUCCEEDED = BASE + 6;
+ /** @hide */
public static final int DISCOVER_PEERS = BASE + 7;
+
+ /**
+ * Message {@link android.os.Message#what} value indicating that the {@link #discoverPeers}
+ * operation failed.
+ * <p> The reason for failure could be one of {@link #P2P_UNSUPPORTED}, {@link #P2P_DISABLED}
+ * or {@link #ALREADY_IN_EFFECT}
+ */
public static final int DISCOVER_PEERS_FAILED = BASE + 8;
+ /**
+ * Message {@link android.os.Message#what} value indicating that the {@link #discoverPeers}
+ * operation succeeded.
+ * <p> The application can register for {@link #WIFI_P2P_PEERS_CHANGED_ACTION} intent
+ * to listen for changes in the peer list as a result of the discovery process.
+ */
public static final int DISCOVER_PEERS_SUCCEEDED = BASE + 9;
+ /** @hide */
public static final int CONNECT = BASE + 10;
+
+ /**
+ * Message {@link android.os.Message#what} value indicating that the {@link #connect}
+ * operation failed.
+ * <p> The reason for failure could be one of {@link #P2P_UNSUPPORTED}, {@link #P2P_DISABLED}
+ * or {@link #ALREADY_IN_EFFECT}
+ */
public static final int CONNECT_FAILED = BASE + 11;
+ /**
+ * Message {@link android.os.Message#what} value indicating that the {@link #connect}
+ * operation succeeded.
+ * <p> The application can register for {@link #WIFI_P2P_CONNECTION_CHANGED_ACTION} intent
+ * to listen for connectivity change as a result of the connect operation
+ */
public static final int CONNECT_SUCCEEDED = BASE + 12;
+ /** @hide */
public static final int CREATE_GROUP = BASE + 13;
+
+ /**
+ * Message {@link android.os.Message#what} value indicating that the {@link #createGroup}
+ * operation failed.
+ * <p> The reason for failure could be one of {@link #P2P_UNSUPPORTED}, {@link #P2P_DISABLED}
+ * or {@link #ALREADY_IN_EFFECT}
+ */
public static final int CREATE_GROUP_FAILED = BASE + 14;
+ /**
+ * Message {@link android.os.Message#what} value indicating that the {@link #createGroup}
+ * operation succeeded.
+ * <p> The application can request the group details with {@link #requestGroupInfo}
+ */
public static final int CREATE_GROUP_SUCCEEDED = BASE + 15;
+ /** @hide */
public static final int REMOVE_GROUP = BASE + 16;
+ /**
+ * Message {@link android.os.Message#what} value indicating that the {@link #removeGroup}
+ * operation failed.
+ * <p> The reason for failure could be one of {@link #P2P_UNSUPPORTED}, {@link #P2P_DISABLED}
+ * or {@link #ALREADY_IN_EFFECT}
+ */
public static final int REMOVE_GROUP_FAILED = BASE + 17;
+ /**
+ * Message {@link android.os.Message#what} value indicating that the {@link #removeGroup}
+ * operation succeeded.
+ */
public static final int REMOVE_GROUP_SUCCEEDED = BASE + 18;
- public static final int REQUEST_PEERS = BASE + 19;
- public static final int RESPONSE_PEERS = BASE + 20;
-
- public static final int REQUEST_CONNECTION_INFO = BASE + 21;
- public static final int RESPONSE_CONNECTION_INFO = BASE + 22;
-
- /* arg1 values on response messages from the framework */
+ /**
+ * Supported {@link android.os.Message#arg1} value on the following response messages:
+ * {@link #DISCOVER_PEERS_FAILED}, {@link #CONNECT_FAILED}, {@link #CREATE_GROUP_FAILED}
+ * and {@link #REMOVE_GROUP_FAILED}
+ *
+ * <p> This indicates that the reason for failure is because p2p is unsupported on the
+ * device
+ */
public static final int P2P_UNSUPPORTED = 1;
+ /**
+ * Supported {@link android.os.Message#arg1} value on the following response messages:
+ * {@link #DISCOVER_PEERS_FAILED}, {@link #CONNECT_FAILED}, {@link #CREATE_GROUP_FAILED}
+ * and {@link #REMOVE_GROUP_FAILED}
+ *
+ * <p> This indicates that the reason for failure is because p2p is currently disabled
+ * by the user
+ */
+ public static final int P2P_DISABLED = 2;
+
+ /**
+ * Supported {@link android.os.Message#arg1} value on the following response messages:
+ * {@link #DISCOVER_PEERS_FAILED}, {@link #CONNECT_FAILED}, {@link #CREATE_GROUP_FAILED}
+ * and {@link #REMOVE_GROUP_FAILED}
+ *
+ * <p> This indicates that the reason for failure is because the operation is already in
+ * effect
+ */
+ public static final int ALREADY_IN_EFFECT = 3;
+
+
+ /** @hide */
+ public static final int REQUEST_PEERS = BASE + 19;
+ /**
+ * Message {@link android.os.Message#what} delivered on the application hander
+ * in response to a {@link #requestPeers} call from the application.
+ *
+ * <p> Extract a {@link WifiP2pDeviceList} object by calling {@link #peersInResponse}
+ * on the message object
+ */
+ public static final int RESPONSE_PEERS = BASE + 20;
+
+ /** @hide */
+ public static final int REQUEST_CONNECTION_INFO = BASE + 21;
+
+ /**
+ * Message {@link android.os.Message#what} delivered on the application hander
+ * in response to a {@link #requestConnectionInfo} call from the application.
+ *
+ * <p> Extract a {@link WifiP2pInfo} object by calling {@link #connectionInfoInResponse}
+ * on the message object
+ */
+ public static final int RESPONSE_CONNECTION_INFO = BASE + 22;
+
+ /** @hide */
+ public static final int REQUEST_GROUP_INFO = BASE + 23;
+
+ /**
+ * Message {@link android.os.Message#what} delivered on the application hander
+ * in response to a {@link #requestGroupInfo} call from the application.
+ *
+ * <p> Extract a {@link WifiP2pGroup} object by calling {@link #groupInfoInResponse}
+ * on the message object
+ */
+
+ public static final int RESPONSE_GROUP_INFO = BASE + 24;
+
+ /** @hide */
public static final int WPS_PBC = BASE + 23;
+ /** @hide */
public static final int WPS_PIN = BASE + 24;
+ /** @hide */
public static final int WPS_PIN_AVAILABLE = BASE + 25;
/**
@@ -199,7 +363,8 @@
/**
* A channel that connects the application handler to the Wifi framework.
- * All p2p operations are performed on a channel.
+ * Most p2p operations require a Channel as an argument. An instance of Channel is obtained
+ * by doing a call on {@link #initialize}
*/
public class Channel {
Channel(AsyncChannel c) {
@@ -210,10 +375,17 @@
/**
* Registers the application handler with the Wi-Fi framework. This function
- * must be the first to be called before any p2p control or query operations can be performed.
+ * must be the first to be called before any p2p operations are performed.
+ *
+ * <p class="note"><strong>Note:</strong>
+ * The handler registered with the framework should only handle messages
+ * with {@link android.os.Message#what} values defined in this file. Adding application
+ * specific private {@link android.os.Message#what} types should be done on a seperate handler
+ *
* @param srcContext is the context of the source
- * @param srcHandler is the handler on which the source receives messages
- * @return Channel instance that is necessary for performing p2p operations
+ * @param srcHandler is the handler on which the source will receive message responses
+ * asynchronously
+ * @return Channel instance that is necessary for performing any further p2p operations
*/
public Channel initialize(Context srcContext, Handler srcHandler) {
Messenger messenger = getMessenger();
@@ -229,6 +401,7 @@
}
}
+ /** @hide */
public boolean isP2pSupported() {
try {
return mService.isP2pSupported();
@@ -240,6 +413,7 @@
/**
* Sends in a request to the system to enable p2p. This will pop up a dialog
* to the user and upon authorization will enable p2p.
+ * @hide
*/
public void enableP2p(Channel c) {
if (c == null) return;
@@ -249,6 +423,7 @@
/**
* Sends in a request to the system to disable p2p. This will pop up a dialog
* to the user and upon authorization will enable p2p.
+ * @hide
*/
public void disableP2p(Channel c) {
if (c == null) return;
@@ -256,7 +431,22 @@
}
/**
- * Initiates peer discovery
+ * Initiate peer discovery. A discovery process involves scanning for available Wi-Fi peers
+ * for the purpose of establishing a connection.
+ *
+ * <p> The function call immediately returns after sending a discovery request
+ * to the framework. The application handler is notified of a success or failure to initiate
+ * discovery with {@link #DISCOVER_PEERS_SUCCEEDED} or {@link #DISCOVER_PEERS_FAILED}.
+ *
+ * <p> The discovery remains active until a connection is initiated or
+ * a p2p group is formed. Register for {@link #WIFI_P2P_PEERS_CHANGED_ACTION} intent to
+ * determine when the framework notifies of a change as peers are discovered.
+ *
+ * <p> Upon receiving a {@link #WIFI_P2P_PEERS_CHANGED_ACTION} intent, an application
+ * can request for the list of peers using {@link #requestPeers} which will deliver a
+ * {@link #RESPONSE_PEERS} message on the application handler. The application can then
+ * extract a {@link WifiP2pDeviceList} object by calling {@link #peersInResponse}
+ * on the message.
*/
public void discoverPeers(Channel c) {
if (c == null) return;
@@ -264,9 +454,23 @@
}
/**
- * Start a p2p connection
+ * Start a p2p connection to a device with the specified configuration.
*
- * @param peer Configuration described in a {@link WifiP2pConfig} object.
+ * <p> The function call immediately returns after sending a connection request
+ * to the framework. The application handler is notified of a success or failure to initiate
+ * connectivity with {@link #CONNECT_SUCCEEDED} or {@link #CONNECT_FAILED}.
+ *
+ * <p> Register for {@link #WIFI_P2P_CONNECTION_CHANGED_ACTION} intent to
+ * determine when the framework notifies of a change in connectivity.
+ *
+ * <p> If the current device is not part of a p2p group, a connect request initiates
+ * a group negotiation with the peer.
+ *
+ * <p> If the current device is part of an existing p2p group or has created
+ * a p2p group with {@link #createGroup}, an invitation to join the group is sent to
+ * the peer device.
+ *
+ * @param config options as described in {@link WifiP2pConfig} class.
*/
public void connect(Channel c, WifiP2pConfig config) {
if (c == null) return;
@@ -274,8 +478,20 @@
}
/**
- * Create a p2p group. This is essentially an access point that can accept
- * client connections.
+ * Create a p2p group with the current device as the group owner. This essentially creates
+ * an access point that can accept connections from legacy clients as well as other p2p
+ * devices.
+ * <p> For p2p operation, this would normally not be used unless the current device needs
+ * to form a p2p connection with a legacy client
+ *
+ * <p> The function call immediately returns after sending a group creation request
+ * to the framework. The application handler is notified of a success or failure to create
+ * group with {@link #CREATE_GROUP_SUCCEEDED} or {@link #CREATE_GROUP_FAILED}.
+ *
+ * <p> Application can request for the group details with {@link #requestGroupInfo} which will
+ * deliver a {@link #RESPONSE_GROUP_INFO} message on the application handler. The application
+ * can then extract a {@link WifiP2pGroup} object by calling {@link #groupInfoInResponse}
+ * on the message.
*/
public void createGroup(Channel c) {
if (c == null) return;
@@ -283,8 +499,11 @@
}
/**
- * Remove the current group. This also removes the p2p interface created
- * during group formation.
+ * Remove the current p2p group.
+ *
+ * <p> The function call immediately returns after sending a group removal request
+ * to the framework. The application handler is notified of a success or failure to remove
+ * a group with {@link #REMOVE_GROUP_SUCCEEDED} or {@link #REMOVE_GROUP_FAILED}.
*/
public void removeGroup(Channel c) {
if (c == null) return;
@@ -292,8 +511,9 @@
}
/**
- * Request the list of peers. This returns a RESPONSE_PEERS on the source
- * handler.
+ * Request the current list of peers. This returns a {@link #RESPONSE_PEERS} on the application
+ * handler. The {@link #RESPONSE_PEERS} message on the handler indicates that the peer list is
+ * available. Use {@link #peersInResponse} to extract {@link WifiP2pDeviceList} from the message
*/
public void requestPeers(Channel c) {
if (c == null) return;
@@ -301,15 +521,18 @@
}
/**
- * Fetch device list from a RESPONSE_PEERS message
+ * Upon receiving a {@link #RESPONSE_PEERS} on the application handler, an application
+ * can extract the peer device list using this function.
*/
public WifiP2pDeviceList peersInResponse(Message msg) {
return (WifiP2pDeviceList) msg.obj;
}
/**
- * Request device connection info. This returns a RESPONSE_CONNECTION_INFO on
- * the source handler.
+ * Request device connection info. This returns a {@link #RESPONSE_CONNECTION_INFO} on
+ * the application handler. The {@link #RESPONSE_CONNECTION_INFO} message on the handler
+ * indicates that connection info is available. Use {@link #connectionInfoInResponse} to
+ * extract {@link WifiP2pInfo} from the message.
*/
public void requestConnectionInfo(Channel c) {
if (c == null) return;
@@ -317,12 +540,31 @@
}
/**
- * Fetch p2p connection status from a RESPONSE_CONNECTION_INFO message
+ * Upon receiving a {@link #RESPONSE_CONNECTION_INFO} on the application handler, an application
+ * can extract the connection info using this function.
*/
public WifiP2pInfo connectionInfoInResponse(Message msg) {
return (WifiP2pInfo) msg.obj;
}
+ /**
+ * Request p2p group info. This returns a {@link #RESPONSE_GROUP_INFO} on
+ * the application handler. The {@link #RESPONSE_GROUP_INFO} message on the handler
+ * indicates that group info is available. Use {@link #groupInfoInResponse} to
+ * extract {@link WifiP2pGroup} from the message.
+ */
+ public void requestGroupInfo(Channel c) {
+ if (c == null) return;
+ c.mAsyncChannel.sendMessage(REQUEST_GROUP_INFO);
+ }
+
+ /**
+ * Upon receiving a {@link #RESPONSE_GROUP_INFO} on the application handler, an application
+ * can extract the group info using this function.
+ */
+ public WifiP2pGroup groupInfoInResponse(Message msg) {
+ return (WifiP2pGroup) msg.obj;
+ }
/**
* Get a reference to WifiP2pService handler. This is used to establish
@@ -339,7 +581,6 @@
}
}
-
/**
* Setup DNS connectivity on the current process to the connected Wi-Fi p2p peers
*