diff options
author | Etan Cohen <etancohen@google.com> | 2017-06-21 17:01:43 -0700 |
---|---|---|
committer | Etan Cohen <etancohen@google.com> | 2017-06-23 09:20:59 -0700 |
commit | 9572e8b6de6cb7912df530ae2376452bf1469b33 (patch) | |
tree | 0e3a9c86b5797cf9b51a0b5df35b5cfba60630a8 /service | |
parent | efadd5383b5a98dcc249d3b8700142d3d748989f (diff) |
[AWARE] Add debug hooks to obtain count of event callbacks
Count Aware event callbacks and provide a shell command to
retrieve and reset data.
While callbacks may be percolated up through the framework and
detected - that is not always the case. Some of the callbacks are
masked by the framework. It is still interesting to know when
callbacks occur - to detect invalid wakeups of the host.
Bug: 31940045
Test: manual shell cmd execution validates data
Change-Id: I35d96419342c330f2d64a422b9b39369311aa09e
Diffstat (limited to 'service')
3 files changed, 114 insertions, 1 deletions
diff --git a/service/java/com/android/server/wifi/aware/WifiAwareNativeCallback.java b/service/java/com/android/server/wifi/aware/WifiAwareNativeCallback.java index 267459a56..35773210b 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareNativeCallback.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareNativeCallback.java @@ -26,17 +26,25 @@ import android.hardware.wifi.V1_0.NanFollowupReceivedInd; import android.hardware.wifi.V1_0.NanMatchInd; import android.hardware.wifi.V1_0.NanStatusType; import android.hardware.wifi.V1_0.WifiNanStatus; +import android.os.ShellCommand; import android.util.Log; +import android.util.SparseIntArray; import libcore.util.HexEncoding; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.FileDescriptor; +import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; /** * Manages the callbacks from Wi-Fi Aware HIDL (HAL). */ -public class WifiAwareNativeCallback extends IWifiNanIfaceEventCallback.Stub { +public class WifiAwareNativeCallback extends IWifiNanIfaceEventCallback.Stub implements + WifiAwareShellCommand.DelegatedShellCommand { private static final String TAG = "WifiAwareNativeCallback"; private static final boolean DBG = false; private static final boolean VDBG = false; @@ -47,6 +55,89 @@ public class WifiAwareNativeCallback extends IWifiNanIfaceEventCallback.Stub { mWifiAwareStateManager = wifiAwareStateManager; } + /* + * Counts of callbacks from HAL. Retrievable through shell command. + */ + private static final int CB_EV_CLUSTER = 0; + private static final int CB_EV_DISABLED = 1; + private static final int CB_EV_PUBLISH_TERMINATED = 2; + private static final int CB_EV_SUBSCRIBE_TERMINATED = 3; + private static final int CB_EV_MATCH = 4; + private static final int CB_EV_MATCH_EXPIRED = 5; + private static final int CB_EV_FOLLOWUP_RECEIVED = 6; + private static final int CB_EV_TRANSMIT_FOLLOWUP = 7; + private static final int CB_EV_DATA_PATH_REQUEST = 8; + private static final int CB_EV_DATA_PATH_CONFIRM = 9; + private static final int CB_EV_DATA_PATH_TERMINATED = 10; + + private SparseIntArray mCallbackCounter = new SparseIntArray(); + + private void incrementCbCount(int callbackId) { + mCallbackCounter.put(callbackId, mCallbackCounter.get(callbackId) + 1); + } + + /** + * Interpreter of adb shell command 'adb shell wifiaware native_cb ...'. + * + * @return -1 if parameter not recognized or invalid value, 0 otherwise. + */ + @Override + public int onCommand(ShellCommand parentShell) { + final PrintWriter pwe = parentShell.getErrPrintWriter(); + final PrintWriter pwo = parentShell.getOutPrintWriter(); + + String subCmd = parentShell.getNextArgRequired(); + if (VDBG) Log.v(TAG, "onCommand: subCmd='" + subCmd + "'"); + switch (subCmd) { + case "get_cb_count": { + String option = parentShell.getNextOption(); + Log.v(TAG, "option='" + option + "'"); + boolean reset = false; + if (option != null) { + if ("--reset".equals(option)) { + reset = true; + } else { + pwe.println("Unknown option to 'get_cb_count'"); + return -1; + } + } + + JSONObject j = new JSONObject(); + try { + for (int i = 0; i < mCallbackCounter.size(); ++i) { + j.put(Integer.toString(mCallbackCounter.keyAt(i)), + mCallbackCounter.valueAt(i)); + } + } catch (JSONException e) { + Log.e(TAG, "onCommand: get_cb_count e=" + e); + } + pwo.println(j.toString()); + if (reset) { + mCallbackCounter.clear(); + } + return 0; + } + default: + pwe.println("Unknown 'wifiaware native_cb <cmd>'"); + } + + return -1; + } + + @Override + public void onReset() { + // NOP (onReset is intended for configuration reset - not data reset) + } + + @Override + public void onHelp(String command, ShellCommand parentShell) { + final PrintWriter pw = parentShell.getOutPrintWriter(); + + pw.println(" " + command); + pw.println(" get_cb_count [--reset]: gets the number of callbacks (and optionally reset " + + "count)"); + } + @Override public void notifyCapabilitiesResponse(short id, WifiNanStatus status, NanCapabilities capabilities) { @@ -254,6 +345,7 @@ public class WifiAwareNativeCallback extends IWifiNanIfaceEventCallback.Stub { Log.v(TAG, "eventClusterEvent: eventType=" + event.eventType + ", addr=" + String.valueOf(HexEncoding.encode(event.addr))); } + incrementCbCount(CB_EV_CLUSTER); if (event.eventType == NanClusterEventType.DISCOVERY_MAC_ADDRESS_CHANGED) { mWifiAwareStateManager.onInterfaceAddressChangeNotification(event.addr); @@ -271,6 +363,7 @@ public class WifiAwareNativeCallback extends IWifiNanIfaceEventCallback.Stub { @Override public void eventDisabled(WifiNanStatus status) { if (VDBG) Log.v(TAG, "eventDisabled: status=" + statusString(status)); + incrementCbCount(CB_EV_DISABLED); mWifiAwareStateManager.onAwareDownNotification(status.status); } @@ -281,6 +374,7 @@ public class WifiAwareNativeCallback extends IWifiNanIfaceEventCallback.Stub { Log.v(TAG, "eventPublishTerminated: sessionId=" + sessionId + ", status=" + statusString(status)); } + incrementCbCount(CB_EV_PUBLISH_TERMINATED); mWifiAwareStateManager.onSessionTerminatedNotification(sessionId, status.status, true); } @@ -291,6 +385,7 @@ public class WifiAwareNativeCallback extends IWifiNanIfaceEventCallback.Stub { Log.v(TAG, "eventSubscribeTerminated: sessionId=" + sessionId + ", status=" + statusString(status)); } + incrementCbCount(CB_EV_SUBSCRIBE_TERMINATED); mWifiAwareStateManager.onSessionTerminatedNotification(sessionId, status.status, false); } @@ -307,6 +402,7 @@ public class WifiAwareNativeCallback extends IWifiNanIfaceEventCallback.Stub { convertArrayListToNativeByteArray(event.matchFilter)) + ", mf.size()=" + ( event.matchFilter == null ? 0 : event.matchFilter.size())); } + incrementCbCount(CB_EV_MATCH); mWifiAwareStateManager.onMatchNotification(event.discoverySessionId, event.peerId, event.addr, convertArrayListToNativeByteArray(event.serviceSpecificInfo), @@ -319,6 +415,7 @@ public class WifiAwareNativeCallback extends IWifiNanIfaceEventCallback.Stub { Log.v(TAG, "eventMatchExpired: discoverySessionId=" + discoverySessionId + ", peerId=" + peerId); } + incrementCbCount(CB_EV_MATCH_EXPIRED); // NOP } @@ -332,6 +429,7 @@ public class WifiAwareNativeCallback extends IWifiNanIfaceEventCallback.Stub { convertArrayListToNativeByteArray(event.serviceSpecificInfo)) + ", ssi.size()=" + (event.serviceSpecificInfo == null ? 0 : event.serviceSpecificInfo.size())); } + incrementCbCount(CB_EV_FOLLOWUP_RECEIVED); mWifiAwareStateManager.onMessageReceivedNotification(event.discoverySessionId, event.peerId, event.addr, convertArrayListToNativeByteArray(event.serviceSpecificInfo)); @@ -342,6 +440,7 @@ public class WifiAwareNativeCallback extends IWifiNanIfaceEventCallback.Stub { if (VDBG) { Log.v(TAG, "eventTransmitFollowup: id=" + id + ", status=" + statusString(status)); } + incrementCbCount(CB_EV_TRANSMIT_FOLLOWUP); if (status.status == NanStatusType.SUCCESS) { mWifiAwareStateManager.onMessageSendSuccessNotification(id); @@ -358,6 +457,7 @@ public class WifiAwareNativeCallback extends IWifiNanIfaceEventCallback.Stub { HexEncoding.encode(event.peerDiscMacAddr)) + ", ndpInstanceId=" + event.ndpInstanceId); } + incrementCbCount(CB_EV_DATA_PATH_REQUEST); mWifiAwareStateManager.onDataPathRequestNotification(event.discoverySessionId, event.peerDiscMacAddr, event.ndpInstanceId); @@ -371,6 +471,7 @@ public class WifiAwareNativeCallback extends IWifiNanIfaceEventCallback.Stub { + ", dataPathSetupSuccess=" + event.dataPathSetupSuccess + ", reason=" + event.status.status); } + incrementCbCount(CB_EV_DATA_PATH_CONFIRM); mWifiAwareStateManager.onDataPathConfirmNotification(event.ndpInstanceId, event.peerNdiMacAddr, event.dataPathSetupSuccess, event.status.status, @@ -380,10 +481,20 @@ public class WifiAwareNativeCallback extends IWifiNanIfaceEventCallback.Stub { @Override public void eventDataPathTerminated(int ndpInstanceId) { if (VDBG) Log.v(TAG, "eventDataPathTerminated: ndpInstanceId=" + ndpInstanceId); + incrementCbCount(CB_EV_DATA_PATH_TERMINATED); mWifiAwareStateManager.onDataPathEndNotification(ndpInstanceId); } + /** + * Dump the internal state of the class. + */ + public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { + pw.println("WifiAwareNativeCallback:"); + pw.println(" mCallbackCounter: " + mCallbackCounter); + } + + // utilities /** diff --git a/service/java/com/android/server/wifi/aware/WifiAwareNativeManager.java b/service/java/com/android/server/wifi/aware/WifiAwareNativeManager.java index 47f3030ec..4997d5088 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareNativeManager.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareNativeManager.java @@ -171,6 +171,7 @@ public class WifiAwareNativeManager { public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { pw.println("WifiAwareNativeManager:"); pw.println(" mWifiNanIface: " + mWifiNanIface); + mWifiAwareNativeCallback.dump(fd, pw, args); mHalDeviceManager.dump(fd, pw, args); } } diff --git a/service/java/com/android/server/wifi/aware/WifiAwareService.java b/service/java/com/android/server/wifi/aware/WifiAwareService.java index 40baf7eed..b8bd52a1b 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareService.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareService.java @@ -64,6 +64,7 @@ public final class WifiAwareService extends SystemService { wifiAwareStateManager.setNative(wifiAwareNativeManager, wifiAwareNativeApi); WifiAwareShellCommand wifiAwareShellCommand = new WifiAwareShellCommand(); wifiAwareShellCommand.register("native_api", wifiAwareNativeApi); + wifiAwareShellCommand.register("native_cb", wifiAwareNativeCallback); wifiAwareShellCommand.register("state_mgr", wifiAwareStateManager); HandlerThread awareHandlerThread = wifiInjector.getWifiAwareHandlerThread(); |