diff options
author | Etan Cohen <etancohen@google.com> | 2017-06-14 18:51:05 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-06-14 18:51:07 +0000 |
commit | ae733ef1ea87e66b1c02184434372103a19a5920 (patch) | |
tree | 6d7b750044aa936432cb7a1cdbcac6d04bb3eb54 | |
parent | 26e07d0ed09031f6f1e165b45e338f6ef632e344 (diff) | |
parent | 9a4b9d97dc46509222e6192596fbdb37a2b8fca6 (diff) |
Merge "[AWARE] Add command to reset parameters" into oc-dr1-dev
3 files changed, 77 insertions, 23 deletions
diff --git a/service/java/com/android/server/wifi/aware/WifiAwareNativeApi.java b/service/java/com/android/server/wifi/aware/WifiAwareNativeApi.java index b453f31d1..b9f3b4f88 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareNativeApi.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareNativeApi.java @@ -64,32 +64,30 @@ public class WifiAwareNativeApi implements WifiAwareShellCommand.DelegatedShellC public WifiAwareNativeApi(WifiAwareNativeManager wifiAwareNativeManager) { mHal = wifiAwareNativeManager; + onReset(); } /* * Parameters settable through the shell command. + * see wifi/1.0/types.hal NanBandSpecificConfig.discoveryWindowIntervalVal for description */ public static final String PARAM_DW_DEFAULT_24GHZ = "dw_default_24ghz"; + public static final int PARAM_DW_DEFAULT_24GHZ_DEFAULT = -1; // Firmware default public static final String PARAM_DW_DEFAULT_5GHZ = "dw_default_5ghz"; + public static final int PARAM_DW_DEFAULT_5GHZ_DEFAULT = -1; // Firmware default public static final String PARAM_DW_ON_INACTIVE_24GHZ = "dw_on_inactive_24ghz"; + public static final int PARAM_DW_ON_INACTIVE_24GHZ_DEFAULT = 4; // 4 -> DW=8, latency=4s public static final String PARAM_DW_ON_INACTIVE_5GHZ = "dw_on_inactive_5ghz"; + public static final int PARAM_DW_ON_INACTIVE_5GHZ_DEFAULT = 0; // 0 = disabled public static final String PARAM_DW_ON_IDLE_24GHZ = "dw_on_idle_24ghz"; + public static final int PARAM_DW_ON_IDLE_24GHZ_DEFAULT = -1; // NOP (but disabling on IDLE) public static final String PARAM_DW_ON_IDLE_5GHZ = "dw_on_idle_5ghz"; + public static final int PARAM_DW_ON_IDLE_5GHZ_DEFAULT = -1; // NOP (but disabling on IDLE) public static final String PARAM_MAC_RANDOM_INTERVAL_SEC = "mac_random_interval_sec"; + public static final int PARAM_MAC_RANDOM_INTERVAL_SEC_DEFAULT = 1800; // 30 minutes private Map<String, Integer> mSettableParameters = new HashMap<>(); - { - // see wifi/1.0/types.hal NanBandSpecificConfig.discoveryWindowIntervalVal for description - mSettableParameters.put(PARAM_DW_DEFAULT_24GHZ, -1); // Firmware default - mSettableParameters.put(PARAM_DW_DEFAULT_5GHZ, -1); // Firmware default - mSettableParameters.put(PARAM_DW_ON_INACTIVE_24GHZ, 4); // 4 = DW=8, latency 4s - mSettableParameters.put(PARAM_DW_ON_INACTIVE_5GHZ, 0); // 0 = disabled - mSettableParameters.put(PARAM_DW_ON_IDLE_24GHZ, -1); // NOP (but disabling on IDLE) - mSettableParameters.put(PARAM_DW_ON_IDLE_5GHZ, -1); // NOP (but disabling on IDLE) - - mSettableParameters.put(PARAM_MAC_RANDOM_INTERVAL_SEC, 1800); // 30 minutes - } /** * Interpreter of adb shell command 'adb shell wifiaware native_api ...'. @@ -123,6 +121,17 @@ public class WifiAwareNativeApi implements WifiAwareShellCommand.DelegatedShellC mSettableParameters.put(name, value); return 0; } + case "get": { + String name = parentShell.getNextArgRequired(); + if (VDBG) Log.v(TAG, "onCommand: name='" + name + "'"); + if (!mSettableParameters.containsKey(name)) { + pw.println("Unknown parameter name -- '" + name + "'"); + return -1; + } + + parentShell.getOutPrintWriter().println((int) mSettableParameters.get(name)); + return 0; + } default: pw.println("Unknown 'wifiaware native_api <cmd>'"); } @@ -131,12 +140,27 @@ public class WifiAwareNativeApi implements WifiAwareShellCommand.DelegatedShellC } @Override + public void onReset() { + mSettableParameters.put(PARAM_DW_DEFAULT_24GHZ, PARAM_DW_DEFAULT_24GHZ_DEFAULT); + mSettableParameters.put(PARAM_DW_DEFAULT_5GHZ, PARAM_DW_DEFAULT_5GHZ_DEFAULT); + mSettableParameters.put(PARAM_DW_ON_INACTIVE_24GHZ, PARAM_DW_ON_INACTIVE_24GHZ_DEFAULT); + mSettableParameters.put(PARAM_DW_ON_INACTIVE_5GHZ, PARAM_DW_ON_INACTIVE_5GHZ_DEFAULT); + mSettableParameters.put(PARAM_DW_ON_IDLE_24GHZ, PARAM_DW_ON_IDLE_24GHZ_DEFAULT); + mSettableParameters.put(PARAM_DW_ON_IDLE_5GHZ, PARAM_DW_ON_IDLE_5GHZ_DEFAULT); + + mSettableParameters.put(PARAM_MAC_RANDOM_INTERVAL_SEC, + PARAM_MAC_RANDOM_INTERVAL_SEC_DEFAULT); + } + + @Override public void onHelp(String command, ShellCommand parentShell) { final PrintWriter pw = parentShell.getOutPrintWriter(); pw.println(" " + command); pw.println(" set <name> <value>: sets named parameter to value. Names: " + mSettableParameters.keySet()); + pw.println(" get <name>: gets named parameter value. Names: " + + mSettableParameters.keySet()); } /** diff --git a/service/java/com/android/server/wifi/aware/WifiAwareShellCommand.java b/service/java/com/android/server/wifi/aware/WifiAwareShellCommand.java index 46b08634b..41eef6960 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareShellCommand.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareShellCommand.java @@ -51,15 +51,21 @@ public class WifiAwareShellCommand extends ShellCommand { final PrintWriter pw = getErrPrintWriter(); try { - DelegatedShellCommand delegatedCmd = null; - if (!TextUtils.isEmpty(cmd)) { - delegatedCmd = mDelegatedCommands.get(cmd); - } - - if (delegatedCmd != null) { - return delegatedCmd.onCommand(this); + if ("reset".equals(cmd)) { + for (DelegatedShellCommand dsc: mDelegatedCommands.values()) { + dsc.onReset(); + } } else { - return handleDefaultCommands(cmd); + DelegatedShellCommand delegatedCmd = null; + if (!TextUtils.isEmpty(cmd)) { + delegatedCmd = mDelegatedCommands.get(cmd); + } + + if (delegatedCmd != null) { + return delegatedCmd.onCommand(this); + } else { + return handleDefaultCommands(cmd); + } } } catch (Exception e) { pw.println("Exception: " + e); @@ -83,6 +89,8 @@ public class WifiAwareShellCommand extends ShellCommand { pw.println("Wi-Fi Aware (wifiaware) commands:"); pw.println(" help"); pw.println(" Print this help text."); + pw.println(" reset"); + pw.println(" Reset parameters to default values."); for (Map.Entry<String, DelegatedShellCommand> sce: mDelegatedCommands.entrySet()) { sce.getValue().onHelp(sce.getKey(), this); } @@ -101,10 +109,16 @@ public class WifiAwareShellCommand extends ShellCommand { int onCommand(ShellCommand parentShell); /** + * Reset all parameters to their default values. + */ + void onReset(); + + /** * Print out help for the delegated command. The name of the delegated command is passed * as a first argument as an assist (prevents hard-coding of that string in multiple * places). */ void onHelp(String command, ShellCommand parentShell); + } } diff --git a/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java b/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java index 671b99e1e..fd6303af6 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java @@ -214,7 +214,7 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe private byte[] mCurrentDiscoveryInterfaceMac = ALL_ZERO_MAC; public WifiAwareStateManager() { - // empty + onReset(); } /** @@ -231,11 +231,9 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe * parameters settable through shell command */ public static final String PARAM_ON_IDLE_DISABLE_AWARE = "on_idle_disable_aware"; + public static final int PARAM_ON_IDLE_DISABLE_AWARE_DEFAULT = 1; // 0 = false, 1 = true private Map<String, Integer> mSettableParameters = new HashMap<>(); - { - mSettableParameters.put(PARAM_ON_IDLE_DISABLE_AWARE, 1); // 0 = false, 1 = true - } /** * Interpreter of adb shell command 'adb shell wifiaware native_api ...'. @@ -270,6 +268,17 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe mSettableParameters.put(name, value); return 0; } + case "get": { + String name = parentShell.getNextArgRequired(); + if (VDBG) Log.v(TAG, "onCommand: name='" + name + "'"); + if (!mSettableParameters.containsKey(name)) { + pw_err.println("Unknown parameter name -- '" + name + "'"); + return -1; + } + + pw_out.println((int) mSettableParameters.get(name)); + return 0; + } case "get_capabilities": { JSONObject j = new JSONObject(); if (mCapabilities != null) { @@ -306,12 +315,19 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe } @Override + public void onReset() { + mSettableParameters.put(PARAM_ON_IDLE_DISABLE_AWARE, PARAM_ON_IDLE_DISABLE_AWARE_DEFAULT); + } + + @Override public void onHelp(String command, ShellCommand parentShell) { final PrintWriter pw = parentShell.getOutPrintWriter(); pw.println(" " + command); pw.println(" set <name> <value>: sets named parameter to value. Names: " + mSettableParameters.keySet()); + pw.println(" get <name>: gets named parameter value. Names: " + + mSettableParameters.keySet()); pw.println(" get_capabilities: prints out the capabilities as a JSON string"); } |