summaryrefslogtreecommitdiff
path: root/cmds/svc
diff options
context:
space:
mode:
authorDavid Su <dysu@google.com>2019-10-25 14:28:32 -0700
committerDavid Su <dysu@google.com>2019-11-21 14:46:10 -0800
commit9e365a6d5e37edad307b2f7d8e75517f48342e84 (patch)
treeca51db8691237d0b9ec3ebe075d0ec82c1605e04 /cmds/svc
parent2cf38fe7e9ac612929986a81d84083eca4735faf (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: I28d1cb2f33eb9e2890a3208a26a0ccc8fc25840b
Diffstat (limited to 'cmds/svc')
-rw-r--r--cmds/svc/src/com/android/commands/svc/Svc.java2
-rw-r--r--cmds/svc/src/com/android/commands/svc/WifiCommand.java69
-rwxr-xr-xcmds/svc/svc21
3 files changed, 22 insertions, 70 deletions
diff --git a/cmds/svc/src/com/android/commands/svc/Svc.java b/cmds/svc/src/com/android/commands/svc/Svc.java
index 68fb8e694e6f..e602e2abbe03 100644
--- a/cmds/svc/src/com/android/commands/svc/Svc.java
+++ b/cmds/svc/src/com/android/commands/svc/Svc.java
@@ -94,7 +94,7 @@ public class Svc {
COMMAND_HELP,
new PowerCommand(),
new DataCommand(),
- new WifiCommand(),
+ // `svc wifi` has been migrated to WifiShellCommand
new UsbCommand(),
new NfcCommand(),
new BluetoothCommand(),
diff --git a/cmds/svc/src/com/android/commands/svc/WifiCommand.java b/cmds/svc/src/com/android/commands/svc/WifiCommand.java
deleted file mode 100644
index e31cb5381afc..000000000000
--- a/cmds/svc/src/com/android/commands/svc/WifiCommand.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.commands.svc;
-
-import android.os.ServiceManager;
-import android.os.RemoteException;
-import android.net.wifi.IWifiManager;
-import android.content.Context;
-
-public class WifiCommand extends Svc.Command {
- public WifiCommand() {
- super("wifi");
- }
-
- public String shortHelp() {
- return "Control the Wi-Fi manager";
- }
-
- public String longHelp() {
- return shortHelp() + "\n"
- + "\n"
- + "usage: svc wifi [enable|disable]\n"
- + " Turn Wi-Fi on or off.\n\n";
- }
-
- public void run(String[] args) {
- boolean validCommand = false;
- if (args.length >= 2) {
- boolean flag = false;
- if ("enable".equals(args[1])) {
- flag = true;
- validCommand = true;
- } else if ("disable".equals(args[1])) {
- flag = false;
- validCommand = true;
- }
- if (validCommand) {
- IWifiManager wifiMgr
- = IWifiManager.Stub.asInterface(ServiceManager.getService(Context.WIFI_SERVICE));
- if (wifiMgr == null) {
- System.err.println("Wi-Fi service is not ready");
- return;
- }
- try {
- wifiMgr.setWifiEnabled("com.android.shell", flag);
- }
- catch (RemoteException e) {
- System.err.println("Wi-Fi operation failed: " + e);
- }
- return;
- }
- }
- System.err.println(longHelp());
- }
-}
diff --git a/cmds/svc/svc b/cmds/svc/svc
index c122e981e4c7..60c95c7ec855 100755
--- a/cmds/svc/svc
+++ b/cmds/svc/svc
@@ -1,3 +1,24 @@
#!/system/bin/sh
+
+# `svc wifi` has been migrated to WifiShellCommand,
+# simply perform translation to `cmd wifi set-wifi-enabled` here.
+if [ "x$1" == "xwifi" ]; then
+ # `cmd wifi` by convention uses enabled/disabled
+ # instead of enable/disable
+ if [ "x$2" == "xenable" ]; then
+ exec cmd wifi set-wifi-enabled enabled
+ elif [ "x$2" == "xdisable" ]; then
+ exec cmd wifi set-wifi-enabled disabled
+ else
+ echo "Control the Wi-Fi manager"
+ echo ""
+ echo "usage: svc wifi [enable|disable]"
+ echo " Turn Wi-Fi on or off."
+ echo ""
+ fi
+ exit 1
+fi
+
export CLASSPATH=/system/framework/svc.jar
exec app_process /system/bin com.android.commands.svc.Svc "$@"
+