adb shell svc 詳解
這個(gè)命令可以用來(lái)控制電源管理,wifi開(kāi)關(guān),數(shù)據(jù)開(kāi)關(guān)(就是上網(wǎng)流量),注意需要root權(quán)限。
有興趣的可以一起學(xué)習(xí)一下。
一、svc 常用命令:
1、屏幕相關(guān)
adb shell svc power stayon [true|false|usb|ac]
設(shè)置屏幕的常亮,true保持常亮,false不保持,usb當(dāng)插入usb時(shí)常亮,ac當(dāng)插入電源時(shí)常亮
2、移動(dòng)數(shù)據(jù)(sim卡網(wǎng)絡(luò))
adb shell svc data enable/打開(kāi)移動(dòng)數(shù)據(jù)
adb shell svc data disable/關(guān)閉移動(dòng)數(shù)據(jù)
adb shell svc data prefer/設(shè)置移動(dòng)數(shù)據(jù)優(yōu)先
3、wifi相關(guān)
adb shell svc wifi enable/打開(kāi)wifi
adb shell svc wifi disable/關(guān)閉wifi
adb shell svc wifi prefer/設(shè)置wifi優(yōu)先
4、藍(lán)牙相關(guān)
adb shell svc bluetooth enable/打開(kāi)wifi
adb shell svc bluetooth disable/關(guān)閉wifi
此命令可以用作4G/wifi穩(wěn)定性測(cè)試
其實(shí)還有其他svc 命令,如果想深入了解可以往后看看。
二、svc 命令和使用示例:
查看系統(tǒng)是否安裝了svc
路徑 /system/bin/svc
1|console:/ # ls -l /system/bin/svc
-rwxr-xr-x 1 root shell 1697 2023-09-08 09:06 /system/bin/svc
console:/ #
如果存在這個(gè) svc 文件,那就就可以執(zhí)行 svc 命令了。
其實(shí)可以cat看到 svc 文件的代碼,具體是哪里生成和怎么編輯修改,這里不做具體分析。
1、svc
在串口或者adb shell 命令行,輸入svc 就可以看到相關(guān)功能,
也可能看不全,可能跟系統(tǒng)或者svc文件相關(guān)。
console:/ # svc
Available commands:
help Show information about the subcommands
power Control the power manager
usb Control Usb state
nfc Control NFC functions
system-server System server process related command
console:/ #
console:/ #
在串口輸入 svc 就能看到相關(guān)指令功能。但是不一定顯示全。
2、svc help
console:/ # svc help
Available commands:
help Show information about the subcommands
power Control the power manager
usb Control Usb state
nfc Control NFC functions
system-server System server process related command
console:/ #
輸入 svc help ,查看其實(shí)沒(méi)啥用,和 svc 一樣的顯示功能列表。
3、svc power
console:/ # svc power
Control the power manager
usage: svc power stayon [true|false|usb|ac|wireless]
Set the 'keep awake while plugged in' setting.
svc power reboot [reason]
Perform a runtime shutdown and reboot device with specified reason.
svc power shutdown
Perform a runtime shutdown and power off the device.
svc power forcesuspend [t]
Force the system into suspend, ignoring all wakelocks.
t - Number of milliseconds to wait before issuing force-suspend.
Helps with devices that can't suspend while plugged in.
Defaults to 0.
When using a delay, you must use the nohup shell modifier:
'adb shell nohup svc power forcesuspend [time]'
Use caution; this is dangerous. It puts the device to sleep
immediately without giving apps or the system an opportunity to
save their state.
console:/ #
這里能看到 avc power 包含下面幾個(gè)功能:
svc power stayon [true|false|usb|ac|wireless] //對(duì)應(yīng)的意義:[長(zhǎng)亮|長(zhǎng)暗|usb接入長(zhǎng)亮|充電長(zhǎng)亮|連接wifi長(zhǎng)亮]
svc power reboot [reason] //[reason] 可以隨便寫(xiě)或者不寫(xiě),底層估計(jì)是會(huì)記錄
svc power shutdown //關(guān)機(jī)
svc power forcesuspend [time]// 定時(shí)關(guān)機(jī),其實(shí)也是關(guān)機(jī),time 是多久后關(guān)機(jī),單位是毫秒。未設(shè)置time,就是馬上關(guān)機(jī)。
3、svc usb
console:/ #
console:/ # svc usb
Control Usb state
usage: svc usb setFunctions [function]
Set the current usb function. If function is blank, sets to charging.
svc usb setScreenUnlockedFunctions [function]
Sets the functions which, if the device was charging,
become current on screen unlock.
If function is blank, turn off this feature.
svc usb getFunctions
Gets the list of currently enabled functions
possible values of [function] are any of 'mtp', 'ptp', 'rndis',
'midi', 'ncm (if supporting gadget hal v1.2)'
svc usb resetUsbGadget
Reset usb gadget
svc usb getUsbSpeed
Gets current USB speed
possible values of USB speed are any of 'low speed', 'full speed',
'high speed', 'super speed', 'super speed (10G)',
'super speed (20G)', or higher (future extension)
svc usb getGadgetHalVersion
Gets current Gadget Hal Version
possible values of Hal version are any of 'unknown', 'V1_0', 'V1_1',
'V1_2'
svc usb getUsbHalVersion
Gets current USB Hal Version
possible values of Hal version are any of 'unknown', 'V1_0', 'V1_1',
'V1_2', 'V1_3'
svc usb resetUsbPort [port number]
Reset the specified connected usb port
default: the first connected usb port
console:/ #
console:/ #
這上面看 svc usb 看起來(lái)太復(fù)雜了吧!
梳理下,主要包含下面幾個(gè)功能:
svc usb setFunctions [function] //設(shè)置充電,還是文件等模式
svc usb setScreenUnlockedFunctions [function]
svc usb resetUsbGadget
svc usb getUsbSpeed
svc usb getGadgetHalVersion
svc usb getUsbHalVersion
svc usb resetUsbPort [port number]
其實(shí)上面svc usb執(zhí)行后,都在UsbCommand 里面被接收,部分方法調(diào)用是 UsbDeviceManager 里面執(zhí)行。
framework\base\cmds\svc\src\com\android\commands\svc\UsbCommand.java
framework\base\services\usb\java\com\android\server\usb\UsbDeviceManager.java
想要仔細(xì)研究的可以自己看看。
4、svc nfc
console:/ # svc nfc
Got a null NfcAdapter, is the system running?
console:/ #
這里看到,設(shè)備沒(méi)有安裝ngc,所以未查詢到任何信息。
5、svc wifi
127|console:/ # svc wifi
Control the Wi-Fi manager
usage: svc wifi [enable|disable]
Turn Wi-Fi on or off.
1|console:/ #
這里看到, avc wifi 可以通過(guò) enable/disable 控制wifi開(kāi)關(guān)。
這里沒(méi)看到 svc wifi prefer/設(shè)置wifi優(yōu)先!
我這是tv平臺(tái),不會(huì)插sim卡,可能去除了相關(guān)設(shè)置,入需要具體研究可以看svc文件和 wifi 命令相關(guān)文件。
packages\modules\Wifi\service\java\com\android\server\wifi\WifiShellCommand.java
6、svc bluetooth
1|console:/ # svc bluetooth
Control the Bluetooth manager
usage: svc bluetooth [enable|disable]
Turn Bluetooth on or off.
1|console:/ #
這里看到, avc bluetooth 可以通過(guò) enable/disable 控制 藍(lán)牙 開(kāi)關(guān)。
7、svc system-server
console:/ # svc system-server
System server process related command
usage: system-server wait-for-crash
Wait until the system server process crashes.
console:/ #
這里顯示等下系統(tǒng)崩潰,估計(jì)系統(tǒng)崩潰過(guò)情況才有日志打印。
8、svc data
1|console:/ # svc data
Enable/Disable Mobile Data Connectivity
usage: svc data [enable|disable]
1|console:/ #
可以通過(guò)svc data enable或svc data disable來(lái)打開(kāi)或關(guān)閉移動(dòng)數(shù)據(jù)連接。這個(gè)命令可以用來(lái)控制手機(jī)的數(shù)據(jù)連接狀態(tài)。
這里沒(méi)有查詢命令,只能通過(guò)實(shí)際測(cè)試看看,是否有沒(méi)有生效。
9、svc volume
網(wǎng)上查看svc 還可以控制變量:
adb shell svc volume music +10 // 將音樂(lè)音量增加10個(gè)單位
但是實(shí)際測(cè)試,并不能識(shí)別 volume 命令,估計(jì)和Android 系統(tǒng)代碼相關(guān)
console:/ # svc volume music +10
Available commands:
help Show information about the subcommands
power Control the power manager
usb Control Usb state
nfc Control NFC functions
system-server System server process related command
console:/ # svc volume music
Available commands:
help Show information about the subcommands
power Control the power manager
usb Control Usb state
nfc Control NFC functions
system-server System server process related command
console:/ # svc volume
Available commands:
help Show information about the subcommands
power Control the power manager
usb Control Usb state
nfc Control NFC functions
system-server System server process related command
console:/ #
console:/ #
這里看到是識(shí)別不到 svc volume命令的,其實(shí)就是系統(tǒng)代碼未配置,想要了解可以繼續(xù)往下看。
二、svc 命令相關(guān)源碼分析
1、cat svc文件
console:/ #
console:/ # cat /system/bin/svc
#!/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
if [ "x$1" == "xdata" ]; then
if [ "x$2" == "xenable" ]; then
exec cmd phone data enable
elif [ "x$2" == "xdisable" ]; then
exec cmd phone data disable
else
echo "Enable/Disable Mobile Data Connectivity"
echo ""
echo "usage: svc data [enable|disable]"
echo ""
fi
exit 1
fi
# `svc bluetooth` has been migrated to BluetoothShellCommand,
# simply perform translation to `cmd bluetooth set-bluetooth-enabled` here.
if [ "x$1" == "xbluetooth" ]; then
# `cmd wifi` by convention uses enabled/disabled
# instead of enable/disable
if [ "x$2" == "xenable" ]; then
exec cmd bluetooth_manager enable
elif [ "x$2" == "xdisable" ]; then
exec cmd bluetooth_manager disable
else
echo "Control the Bluetooth manager"
echo ""
echo "usage: svc bluetooth [enable|disable]"
echo " Turn Bluetooth on or off."
echo ""
fi
exit 1
fi
export CLASSPATH=/system/framework/svc.jar
exec app_process /system/bin com.android.commands.svc.Svc "$@"
console:/ #
這里看到了有wifi和bluetooth的簡(jiǎn)單判斷,以及關(guān)聯(lián)了svc.jar
Android 系統(tǒng)源碼里面也是有這個(gè)svc文件存在的,文件目錄:
framework\base\cmds\svc\svc
svc相關(guān)功能的接收處理都在 framework\base\cmds\svc 文件夾下
2、svc 相關(guān)源碼文件
主要相關(guān)文件:
framework\base\cmds\svc\src\com\android\commands\svc\Svc.java
framework\base\cmds\svc\src\com\android\commands\svc\NfcCommand.java
framework\base\cmds\svc\src\com\android\commands\svc\PowerCommand.java
framework\base\cmds\svc\src\com\android\commands\svc\SystemServerCommand.java
framework\base\cmds\svc\src\com\android\commands\svc\UsbCommand.java
packages\modules\Wifi\service\java\com\android\server\wifi\WifiShellCommand.java // Android13
packages\modules\Bluetooth\service\java\com\android\server\bluetooth\BluetoothShellCommand.java //Android13
別人分析的svc相關(guān)文件 過(guò)程:
https://blog.csdn.net/zhangqi6627/article/details/121496414
(1)接收所有svc命令的文件 Svc.java
public class Svc {
public static abstract class Command { // 所有command 子類(lèi)都是會(huì)繼承這個(gè)抽象接口,后面會(huì)看到
private String mName;
public Command(String name) { //設(shè)置Command 名稱
mName = name;
}
public String name() { //查詢Command名稱
return mName;
}
public abstract String shortHelp(); // should fit on one short line, //svc help看到的各個(gè)Command 的信息
public abstract String longHelp(); // take as much space as you need, 75 col max // svc 具體命令后,看到的具體提示信息
public abstract void run(String[] args); // run the command //執(zhí)行接收輸入的命令
}
// (1)執(zhí)行入口
public static void main(String[] args) {
if (args.length >= 1) {
Command c = lookupCommand(args[0]); //(2)根據(jù)輸入的字符串,返回Command 對(duì)象
if (c != null) {
c.run(args);
return;
}
}
COMMAND_HELP.run(args); // (3)如果只輸入 avc,顯示help 提示的字符串
}
// (4)根據(jù)字符串查找 Command 對(duì)象,其實(shí)就是USB、Wifi那些控制對(duì)象
private static Command lookupCommand(String name) {
final int N = COMMANDS.length;
for (int i=0; i<N; i++) { // (5)遍歷所有Command對(duì)象進(jìn)行匹配
Command c = COMMANDS[i];
if (c.name().equals(name)) {
return c;
}
}
return null;
}
// (5)定義所有的 Command 對(duì)象
public static final Command[] COMMANDS = new Command[] {
COMMAND_HELP, // (6)help 是自身
new PowerCommand(), // (7) power相關(guān)命令處理
// `svc wifi` has been migrated to WifiShellCommand // (8)wifi 相關(guān)命令處理,svc 文件已經(jīng)說(shuō)明了,會(huì)在 WifiShellCommand 進(jìn)行處理。
new UsbCommand(), // (9) usb相關(guān)命令處理
new NfcCommand(), // (10)nfc相關(guān)命令處理
// `svc bluetooth` has been migrated to BluetoothShellCommand // (11)bluetooth相關(guān)命令處理
new SystemServerCommand(), // (11)system-server 命令處理
};
}
(2)接收所有svc power 命令的文件 PowerCommand.java
這里只說(shuō)明一下 avc power 命令的接收和處理,其他命令的 Command 命令類(lèi)的分析也是類(lèi)似的,可以參考。
public class PowerCommand extends Svc.Command { //(1) svc 命令都是要繼承 Command抽象類(lèi)
private static final int FORCE_SUSPEND_DELAY_DEFAULT_MILLIS = 0;
public PowerCommand() {
super("power"); // (2)父類(lèi)的構(gòu)成方法,設(shè)置Command 對(duì)象名稱,也是svc 后面對(duì)應(yīng)的功能名稱
}
public String shortHelp() { // (3)svc 顯示的 power 功能簡(jiǎn)單提示
return "Control the power manager";
}
public String longHelp() { // (4)svc power 顯示的 power 功能具體提示,這個(gè)也說(shuō)明文本提示因供參考,真正的實(shí)現(xiàn)還是要看代碼邏輯
return shortHelp() + "\n"
+ "\n"
+ "usage: svc power stayon [true|false|usb|ac|wireless]\n"
+ " Set the 'keep awake while plugged in' setting.\n"
+ " svc power reboot [reason]\n"
+ " Perform a runtime shutdown and reboot device with specified reason.\n"
+ " svc power shutdown\n"
+ " Perform a runtime shutdown and power off the device.\n"
+ " svc power forcesuspend [t]\n"
+ " Force the system into suspend, ignoring all wakelocks.\n"
+ " t - Number of milliseconds to wait before issuing force-suspend.\n"
+ " Helps with devices that can't suspend while plugged in.\n"
+ " Defaults to " + FORCE_SUSPEND_DELAY_DEFAULT_MILLIS + ".\n"
+ " When using a delay, you must use the nohup shell modifier:\n"
+ " 'adb shell nohup svc power forcesuspend [time]'\n"
+ " Use caution; this is dangerous. It puts the device to sleep\n"
+ " immediately without giving apps or the system an opportunity to\n"
+ " save their state.\n";
}
//(5)這個(gè)就是 svc power 功能的具體處理代碼了,也是最重要的部分
public void run(String[] args) {
fail: {
if (args.length >= 2) { //(6)命令字符串大于等于2 才有意義, args[0] = power, args[1] = 某個(gè)功能,比如 stayon ,args[2] = 某個(gè)功能的參數(shù)
IPowerManager pm = IPowerManager.Stub.asInterface(
ServiceManager.getService(Context.POWER_SERVICE)); //(7)具體實(shí)現(xiàn)其實(shí)也是調(diào)用到了PowerManager對(duì)于的Service 服務(wù)里面,也就是說(shuō)avc 里面的實(shí)現(xiàn)基本都是調(diào)用系統(tǒng)api的操作
if ("stayon".equals(args[1]) && args.length == 3) { // (8)avc power stayon 功能的判斷
int val;
if ("true".equals(args[2])) { //(9)avc power stayon true 的判斷,長(zhǎng)亮
val = BatteryManager.BATTERY_PLUGGED_AC |
BatteryManager.BATTERY_PLUGGED_USB |
BatteryManager.BATTERY_PLUGGED_WIRELESS;
}
else if ("false".equals(args[2])) { //(10)avc power stayon false 的判斷,長(zhǎng)暗
val = 0;
} else if ("usb".equals(args[2])) { //(11)avc power stayon usb 的判斷,插入usb長(zhǎng)亮
val = BatteryManager.BATTERY_PLUGGED_USB;
} else if ("ac".equals(args[2])) { //(12)avc power stayon ac 的判斷,插入ac電源長(zhǎng)亮
val = BatteryManager.BATTERY_PLUGGED_AC;
} else if ("wireless".equals(args[2])) { //(13)avc power stayon wireless 的判斷,連接wifi 長(zhǎng)亮
val = BatteryManager.BATTERY_PLUGGED_WIRELESS;
} else { //(14)avc power 其他參數(shù)都是,錯(cuò)誤情況,進(jìn)行提示
break fail;
}
try {
if (val != 0) {
// if the request is not to set it to false, wake up the screen so that
// it can stay on as requested
pm.wakeUp(SystemClock.uptimeMillis(),
PowerManager.WAKE_REASON_UNKNOWN, "PowerCommand", null);
}
pm.setStayOnSetting(val); //(15)根據(jù) avc power 設(shè)置的功能,調(diào)用相關(guān)api,設(shè)置相關(guān)參數(shù),
}
catch (RemoteException e) {
System.err.println("Faild to set setting: " + e);
}
return;
} else if ("reboot".equals(args[1])) { //(16)后面的流程就不一一分析了,參數(shù)長(zhǎng)度和具體調(diào)用的api不同而已。
String mode = null;
if (args.length == 3) {
mode = args[2];
}
try {
// no confirm, wait till device is rebooted
pm.reboot(false, mode, true);
} catch (RemoteException e) {
maybeLogRemoteException("Failed to reboot.");
} catch (Exception e) {
System.err.println("Failed to reboot: " + e.getMessage());
}
return;
} else if ("shutdown".equals(args[1])) {
try {
// no confirm, wait till device is off
pm.shutdown(false, null, true);
} catch (RemoteException e) {
maybeLogRemoteException("Failed to shutdown.");
}
return;
} else if ("forcesuspend".equals(args[1])) {
int delayMillis = args.length > 2
? Integer.parseInt(args[2]) : FORCE_SUSPEND_DELAY_DEFAULT_MILLIS;
try {
Thread.sleep(delayMillis);
if (!pm.forceSuspend()) {
System.err.println("Failed to force suspend.");
}
} catch (InterruptedException e) {
System.err.println("Failed to force suspend: " + e);
} catch (RemoteException e) {
maybeLogRemoteException("Failed to force-suspend with exception: " + e);
}
return;
}
}
}
System.err.println(longHelp()); // (17)如果參數(shù)錯(cuò)誤的情況,就顯示avc power 的具體命令提示。
}
三、系統(tǒng)源碼中添加自定義的svc 命令實(shí)現(xiàn)
1、系統(tǒng)源碼中加入新的svc 只需要做下面兩步即可:
(1)創(chuàng)建一個(gè)自己 Command 對(duì)象,可以參考同目錄下的其他Command對(duì)象,比如 PowerCommand 的代碼;
(2)在 Svc.java 文件中 COMMANDS列表對(duì)象中添加自定義的 Command 對(duì)象,svc 遍歷的時(shí)候就會(huì)判斷是否包含你的命令
2、在 Svc.java 中的修改
public static final Command[] COMMANDS = new Command[] {
COMMAND_HELP,
new LwzCommand(), //這里添加自定定義的 Command 對(duì)象
new PowerCommand(),
// `svc wifi` has been migrated to WifiShellCommand
new UsbCommand(),
new NfcCommand(),
// `svc bluetooth` has been migrated to BluetoothShellCommand
new SystemServerCommand(),
};
輸入svc 命令的時(shí)候,就會(huì)去遍歷所有的 Command 對(duì)象的名稱,
哪個(gè)符合就返回那個(gè)具體的Command對(duì)象,具體的處理都在 某個(gè)Command對(duì)象里面。
3、創(chuàng)建自定義的 Command 對(duì)象
package com.android.commands.svc;
import android.content.Context;
public class LwzCommand extends Svc.Command { //(1)自定義Command對(duì)象,需要繼承 Svc.Command
private static final int FORCE_SUSPEND_DELAY_DEFAULT_MILLIS = 0;
public LwzCommand() { //(2)自定義對(duì)象的命令名稱,這個(gè)也是cmd 窗口中的功能命令,Java那個(gè)對(duì)象命名是無(wú)所謂的
super("lwz");
}
public String shortHelp() { //(3)簡(jiǎn)短的介紹,avc 、avc help 會(huì)出現(xiàn)該提示
return "lwz Control the test command";
}
public String longHelp() { //(4)詳細(xì)的介紹,avc lwz 或者 avc lwz help ,會(huì)打印該提示
return shortHelp() + "\n"
+ "\n"
+ "usage: svc lwz stayon [true|false|usb|ac|wireless]\n"
+ " Set the 'keep awake while plugged in' setting.\n"
+ " svc lwz reboot [reason]\n"
+ " Perform a runtime shutdown and reboot device with specified reason.\n"
+ " svc lwz shutdown\n";
}
public void run(String[] args) { //(4)avc lwz XXX 的具體處理
fail: {
if (args.length >= 2) { //(5)avc lwz stayon 的具體處理,這里只是做了一些打印,未調(diào)用具體的api實(shí)現(xiàn)
if ("stayon".equals(args[1]) && args.length == 3) {
int val;
if ("true".equals(args[2])) {
val = 100;
}
else if ("false".equals(args[2])) {
val = 0;
} else if ("usb".equals(args[2])) {
val = 1;
} else if ("ac".equals(args[2])) {
val = 2;
} else if ("wireless".equals(args[2])) {
val = 3;
} else {
break fail;
}
System.err.println("test avc lwz command :" + args[2] + ", val = " + val); //添加了自定義打印
return;
} else if ("reboot".equals(args[1])) { //(6)avc lwz reboot 的具體處理,這里只是做了一些打印,未調(diào)用具體的api實(shí)現(xiàn)
String mode = null;
if (args.length == 3) {
mode = args[2];
}
System.err.println("test avc lwz command :" + args[1] + ", mode = " + mode);
return;
}
//(6)avc lwz XXX 其他輸入的處理,打印具體介紹字符串
System.err.println(longHelp());
}
}
System.err.println(longHelp());
}
}
上面自定義的Command對(duì)象,未調(diào)用具體的api。
實(shí)際應(yīng)用中是可以調(diào)用系統(tǒng)api的,可以打印返回的數(shù)據(jù),寫(xiě)線程訪問(wèn)網(wǎng)絡(luò)都是沒(méi)有問(wèn)題的。
4、添加自定義Command命令后,串口操作的顯示
下面是添加了自定義LwzCommand.java 文件后,串口的打印日志:
console:/ #
console:/ # svc //(1)輸入svc 可以看到添加了 自定義的 lwz 功能命令
Available commands:
help Show information about the subcommands
lwz lwz Control the test command
power Control the power manager
usb Control Usb state
nfc Control NFC functions
system-server System server process related command
console:/ #
console:/ # svc lwz //(2)自定義的功能簡(jiǎn)介,參考 svc power 的功能編寫(xiě)的
lwz Control the test command //(3)添加的打印
usage: svc lwz stayon [true|false|usb|ac|wireless]
Set the 'keep awake while plugged in' setting.
svc lwz reboot [reason]
Perform a runtime shutdown and reboot device with specified reason.
svc lwz shutdown
console:/ #
console:/ #
console:/ # svc lwz shutdown // (4)avc lwz shutdown 實(shí)際代碼未實(shí)現(xiàn),代碼中打印了Help提示
lwz Control the test command
usage: svc lwz stayon [true|false|usb|ac|wireless]
Set the 'keep awake while plugged in' setting.
svc lwz reboot [reason]
Perform a runtime shutdown and reboot device with specified reason.
svc lwz shutdown
console:/ #
console:/ #
console:/ # svc lwz reboot // (5)avc lwz reboot 代碼中只是添加了打印,未做處理
test avc lwz command :reboot, mode = null
console:/ #
console:/ #
console:/ # svc lwz stayon true // (6)avc lwz stayon true 代碼中只是添加了打印,未做其他處理
test avc lwz command :true, val = 100
console:/ #
console:/ #
console:/ # svc lwz stayon false // (7)avc lwz stayon false 代碼中只是添加了打印,未做其他處理
test avc lwz command :false, val = 0
console:/ #
這里看效果還是比較ok 的。
即學(xué)到了 svc 的相關(guān)內(nèi)容,還學(xué)會(huì)了自定義擴(kuò)展知識(shí)。
四、總結(jié)
1、svc 的使用
svc 主要命令:
adb shell svc power/wifi/bluetooth/usb/nfc
從上面介紹可以知道,其實(shí)只要記住 svc,那么就是提示其他相關(guān)命令,然后再輸入功能命令,就會(huì)顯示具體參數(shù)介紹。
2、svc 設(shè)計(jì)自定義命令
其實(shí)不難,一個(gè)是編寫(xiě)自定義的Command類(lèi),還有就是把這個(gè)類(lèi)對(duì)象加入到Svc.java中。
涉及到的修改:
framework\base\cmds\svc\src\com\android\commands\svc\Svc.java
framework\base\cmds\svc\src\com\android\commands\svc\XXXCommand.java
3、其他相關(guān)知識(shí)
(1)有些串口上顯示,svc 是無(wú)效的
在串口中的打印如下:
1|console:/ # svc
CANNOT LINK EXECUTABLE "app_process": library "libnativeloader.so" not found: needed by main executable
1|console:/ #
1|console:/ #
我這里的311D2 13系統(tǒng)是這樣提示的,其他的系統(tǒng)不清楚是怎么的提示。
但是svc文件是存在的,adb shell 的cmd 窗口是ok 的;這個(gè)不清楚和哪里相關(guān)。
(2)cmd 其他的命令延伸說(shuō)明
其實(shí)系統(tǒng)源碼里面除了 svc 還有非常多的串口調(diào)試命令。
在系統(tǒng)源碼目錄 frameworks\base\cmds 可以看到:
Android13-IFP/release$
Android13-IFP/release$ cd frameworks/base/cmds
Android13-IFP/release/frameworks/base/cmds$ ls
abx appops appwidget bmgr bu device_config hid ime incidentd input locksettings requestsync settings svc uiautomator vr
am app_process backup bootanimation content dpm idmap2 incident incident_helper interrupter pm screencap sm telecom uinput wm
Android13-IFP/release/frameworks/base/cmds$
這里看到里面還有30多個(gè) cmd 命令。比如控制應(yīng)用的 am/pm 命令,控制顯示的 wm 命令等等。
這些命令有些是需要 root 權(quán)限,有些是不需要的.
但是也不是所有的 cmd 命名都定義在這里,比如 ifconfig 這個(gè)命令就不知道是在哪里實(shí)現(xiàn)的。文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-703554.html
到這里,svc 和相關(guān)知識(shí)已經(jīng)是了解比如深入了的。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-703554.html
到了這里,關(guān)于Android adb shell svc 知識(shí)詳解的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!