summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorDavid Su <dysu@google.com>2019-10-25 14:23:10 -0700
committerDavid Su <dysu@google.com>2019-11-18 18:38:01 -0800
commitf4ab47bb93914976c5cef76bf6f2ab49aba5ea88 (patch)
tree40a9cfd887b2aa9a3ea7aabc4529766352d73fc6 /service
parent92b207156beffb163671c5e3bd9e9f4c4cba0b27 (diff)
Migrate WifiCommand to WifiShellCommand
Migrate `svc wifi` to `cmd wifi set-wifi-enabled` since WifiCommand can no longer access @hide IWifiManager.aidl. Bug: 138801922 Test: adb shell svc wifi [enable|disable|asdf|""] Test: adb shell cmd wifi set-wifi-enabled [enabled|disabled|asdf|""] Change-Id: I2b45c443c6b39004f7f1bb861cf8efe7bbe1578e
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/WifiShellCommand.java42
1 files changed, 37 insertions, 5 deletions
diff --git a/service/java/com/android/server/wifi/WifiShellCommand.java b/service/java/com/android/server/wifi/WifiShellCommand.java
index 8a7bd7581..e686cc70c 100644
--- a/service/java/com/android/server/wifi/WifiShellCommand.java
+++ b/service/java/com/android/server/wifi/WifiShellCommand.java
@@ -16,8 +16,11 @@
package com.android.server.wifi;
+import android.content.Context;
+import android.net.wifi.IWifiManager;
import android.net.wifi.WifiScanner;
import android.os.Binder;
+import android.os.ServiceManager;
import android.os.ShellCommand;
import com.android.server.wifi.util.ApConfigUtil;
@@ -38,10 +41,8 @@ import java.util.concurrent.TimeUnit;
* If additional state objects are necessary add them to the
* constructor.
*
- * Permissions: currently root permission is required for all
- * commands. If the requirement needs to be relaxed then modify
- * the onCommand method to check for specific permissions on
- * individual commands.
+ * Permissions: currently root permission is required for most
+ * commands, which is checked using {@link #checkRootPermission()}.
*/
public class WifiShellCommand extends ShellCommand {
private final ClientModeImpl mClientModeImpl;
@@ -66,7 +67,12 @@ public class WifiShellCommand extends ShellCommand {
@Override
public int onCommand(String cmd) {
- checkRootPermission();
+ // Explicit exclusion from root permission
+ // Do not require root permission to maintain backwards compatibility with
+ // `svc wifi [enable|disable]`.
+ if (!"set-wifi-enabled".equals(cmd)) {
+ checkRootPermission();
+ }
final PrintWriter pw = getOutPrintWriter();
try {
@@ -264,6 +270,30 @@ public class WifiShellCommand extends ShellCommand {
+ mWifiLastResortWatchdog.getWifiWatchdogFeature());
return 0;
}
+ case "set-wifi-enabled": {
+ // This command is explicitly exempted from checkRootPermission() (see beginning
+ // of this method).
+ // Do not require root permission to maintain backwards compatibility with
+ // `svc wifi [enable|disable]`.
+ // However, setWifiEnabled() does perform its own check for the
+ // android.Manifest.permission.CHANGE_WIFI_STATE permission.
+ boolean enabled;
+ String nextArg = getNextArgRequired();
+ if ("enabled".equals(nextArg)) {
+ enabled = true;
+ } else if ("disabled".equals(nextArg)) {
+ enabled = false;
+ } else {
+ pw.println(
+ "Invalid argument to 'set-wifi-enabled' - must be 'enabled'"
+ + " or 'disabled'");
+ return -1;
+ }
+ IWifiManager wifiManager = IWifiManager.Stub.asInterface(
+ ServiceManager.getService(Context.WIFI_SERVICE));
+ wifiManager.setWifiEnabled("com.android.shell", enabled);
+ return 0;
+ }
default:
return handleDefaultCommands(cmd);
}
@@ -367,6 +397,8 @@ public class WifiShellCommand extends ShellCommand {
pw.println(" Sets whether wifi watchdog should trigger recovery");
pw.println(" get-wifi-watchdog");
pw.println(" Gets setting of wifi watchdog trigger recovery.");
+ pw.println(" set-wifi-enabled enabled|disabled");
+ pw.println(" Enables/disables Wifi on this device.");
pw.println();
}
}