在哪里可以找到有关 Android 的“服务调用”shell 命令的信息?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20227326/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where to find info on Android's "service call" shell command?
提问by Corey Ogburn
Using adb shell
or a terminal emulator on the device, entering this will clear all notifications (requires su
)
adb shell
在设备上使用或 终端模拟器,输入此项将清除所有通知(需要su
)
service call notification 1
This will send an sms (doesn't require su
)
这将发送一条短信(不需要su
)
service call isms 5 s16 "PhoneNumber" i32 0 i32 0 s16 "BodyText"
Where can I learn more about service call
? I've found this questionand appreciate the answer's breakdown as to what everything means. But where can I find info on what method notification 2
might be trying to call?
我可以在哪里了解更多信息service call
?我发现了这个问题,并感谢答案对一切含义的细分。但是我在哪里可以找到有关notification 2
可能尝试调用的方法的信息?
Running service call
was incomplete and printed this usage:
运行service call
不完整,打印了这个用法:
Usage: service [-h|-?]
service list
service check SERVICE
service call SERVICE CODE [i32 INT | s16 STR] ...
Options:
i32: Write the integer INT into the send parcel.
s16: Write the UTF-16 string STR into the send parcel.
I ran service list
and it came back with 78 services for my device including isms
and notification
and for most services will print what seems to be a namespace (com.android.internal.telephony.ISms
for isms
and android.app.INotificationManager
for notification
). How can I use this information to find out what I can do with each of these services?
我跑了service list
,它为我的设备返回了 78 个服务,包括isms
andnotification
并且大多数服务将打印似乎是命名空间的内容(com.android.internal.telephony.ISms
forisms
和android.app.INotificationManager
for notification
)。我如何使用这些信息来了解我可以使用这些服务中的每一个做什么?
回答by royatirek
In Short
简而言之
Code related to service call command are just the arguments of the function and order at which the function occur in the aidl file of that service.Here is a syntax
service call <your_service_name> <number at which the function appears in your_service_name.aidl> <type of the argument like i32 or i64> <argument>
与服务调用命令相关的代码只是函数的参数和函数在该服务的aidl文件中出现的顺序。这里是一个语法
service call <your_service_name> <number at which the function appears in your_service_name.aidl> <type of the argument like i32 or i64> <argument>
In Detail
I faced a lot of problems to know about it and hence I will share the solution with the help of clipboard service.
First you need to know about the service you are interested in -
For that you need to look for all the service that is there for particular android system by typing
详细地说,
我遇到了很多问题来了解它,因此我将在剪贴板服务的帮助下分享解决方案。
首先,您需要了解您感兴趣的服务 -
为此,您需要通过键入来查找针对特定 android 系统的所有服务
adb shell service list
Here is what you will get -
这是你会得到的——
.
.
.
59 ethernet: [android.net.IEthernetManager]
60 wifip2p: [android.net.wifi.p2p.IWifiP2pManager]
61 rttmanager: [android.net.wifi.IRttManager]
62 wifiscanner: [android.net.wifi.IWifiScanner]
63 wifi: [android.net.wifi.IWifiManager]
64 overlay: [android.content.om.IOverlayManager]
65 netpolicy: [android.net.INetworkPolicyManager]
66 netstats: [android.net.INetworkStatsService]
67 network_score: [android.net.INetworkScoreService]
68 textservices: [com.android.internal.textservice.ITextServicesManager]
69 network_management: [android.os.INetworkManagementService]
70 clipboard: [android.content.IClipboard]
71 statusbar: [com.android.internal.statusbar.IStatusBarService]
.
.
.
As I am interested in clipboard service, here is how it look
由于我对剪贴板服务感兴趣,因此它的外观如下
70 clipboard: [android.content.IClipboard]
So from here we can summarise that the service name is clipboard service and the package path is android.content.IClipboard
所以从这里我们可以总结出服务名是clipboard service,包路径是android.content.IClipboard
Then you need to know the complete path where the IClipboard.aidl is.
To know that you need to search on google for IClipboard.aidl.
You need to look for something from android.googlesource.com website in the results, like in my case-
然后你需要知道IClipboard.aidl所在的完整路径。
要知道您需要在谷歌上搜索 IClipboard.aidl。
您需要在结果中从 android.googlesource.com 网站查找某些内容,例如我的情况-
https://android.googlesource.com/platform/frameworks/base.git/+/android-4.2.2_r1/core/java/android/content/IClipboard.aidl
So after +/android-4.2.2_r1 is where your path lies.Let that path be path_of_clipboard.aidl=
所以在 +/android-4.2.2_r1 之后就是你的路径所在。让那个路径是 path_of_clipboard.aidl=
/core/java/android/content/IClipboard.aidl
As these service call codes are dependent on the android system, hence you need to know your android os name-
In my case it is 8.1.0
So I will go to the following website where google puts there code and select my os version from the left hand side for the page -
由于这些服务调用代码依赖于 android 系统,因此您需要知道您的 android 操作系统名称 - 在我的情况下它是 8.1.0
所以我将访问以下网站,谷歌在那里放置代码并从页面左侧 -
https://android.googlesource.com/platform/frameworks/base/
https://android.googlesource.com/platform/frameworks/base/
In my case it is android-8.1.0_r50. Here r50 is not important. You can choose any revision. Now I will click on the link and then after that my url will look like this
就我而言,它是 android-8.1.0_r50。这里 r50 并不重要。您可以选择任何版本。现在我将点击链接,然后我的网址将如下所示
https://android.googlesource.com/platform/frameworks/base/+/android-8.1.0_r51
And then after adding path_of_clipboard.aidl, my complete url will look like
然后在添加 path_of_clipboard.aidl 之后,我的完整 url 将如下所示
https://android.googlesource.com/platform/frameworks/base/+/android-8.1.0_r51/core/java/android/content/IClipboard.aidl
Here there will be many methods in the interface.Like in my case
这里接口中会有很多方法。就像我的情况
void setPrimaryClip(in ClipData clip, String callingPackage);
ClipData getPrimaryClip(String pkg);
ClipDescription getPrimaryClipDescription(String callingPackage);
boolean hasPrimaryClip(String callingPackage);
void addPrimaryClipChangedListener(in IOnPrimaryClipChangedListener listener,
String callingPackage);
void removePrimaryClipChangedListener(in IOnPrimaryClipChangedListener listener);
/**
* Returns true if the clipboard contains text; false otherwise.
*/
boolean hasClipboardText(String callingPackage);
So the code for the first method i.e. setPrimaryClip will be 1 as it occured at first place and that for the last method i.e hasClipboardText will be 7 as it occured at seventh place in the aidl file. Similarly for the other methods.
So if I want to call the seventh method I will type
因此,第一个方法(即 setPrimaryClip)的代码将是 1,因为它出现在第一个位置,而最后一个方法(即 hasClipboardText)的代码将是 7,因为它出现在 aidl 文件中的第七个位置。其他方法类似。
所以如果我想调用第七个方法,我会输入
adb shell service call clipboard 7
As you might have seen that I have not put the callingPackage name as it is not required.
正如您可能已经看到的,我没有输入调用包名称,因为它不是必需的。
If the method need arguments, then you can pass it like as show in this example.
Let us assume a method whose code is 8 in clipboard and that looks like this -
如果该方法需要参数,那么您可以像本示例中所示那样传递它。
让我们假设一个方法,其剪贴板中的代码为 8,看起来像这样 -
getDemo(String arg1, int arg2, boolean arg3)
So I will call it like this
所以我会这样称呼它
adb shell call clipboard 8 s16 "first_argument" i32 12 i32 1
Here i32 stands for 32 bit integer and s16 for the string. We can, even pass boolean value as an integer as shown in the example.
In boolean integer 1 stands for true and 0 for false.
Source
这里 i32 代表 32 位整数,s16 代表字符串。我们甚至可以将布尔值作为整数传递,如示例所示。
在布尔整数中,1 代表真,0 代表假。
来源
TIPKeep the logcat open(like in android studio) to check for any error that occured while executing that adb command.
提示保持 logcat 打开(如在 android studio 中)以检查在执行该 adb 命令时发生的任何错误。
回答by Alex P.
Here is my post about Calling Android services from ADB shell. It includes a small bash script I use to automatically download the proper version of service source code for my specific device and then parse it to find out the transaction codes for all methods.
这是我关于从 ADB shell 调用 Android 服务的帖子。它包含一个小的 bash 脚本,我用它来为我的特定设备自动下载正确版本的服务源代码,然后解析它以找出所有方法的事务代码。
回答by msobolak
My first answer here so I hope will be useful for you.
我的第一个答案在这里,所以我希望对你有用。
To explain this small riddle let me use android 4.3.1. Thislink could be essential in your case. Scroll down the java code to line 669. There is waiting for you TRANSACTION block strictly related with com.android.internal.telephony.ISms
service and probably your answer what you can do more.
为了解释这个小谜语,让我使用 android 4.3.1。在您的情况下,此链接可能是必不可少的。将 Java 代码向下滚动到第 669 行。 等待您的是与com.android.internal.telephony.ISms
服务严格相关的 TRANSACTION 块,以及您可以做的更多事情的答案。
In your case you are invoking TRANSACTION_sendText. Explanation is in line 673 where you can find
在您的情况下,您正在调用 TRANSACTION_sendText。说明在第 673 行,您可以在其中找到
static final int TRANSACTION_sendText = (android.os.IBinder.FIRST_CALL_TRANSACTION + 4);
The last part of code consist digit "4". Each TRANSACTION number + 1 = the proper one. That is why service call isms 5
is responsible for sendText
and not for sendMultipartText
.
代码的最后一部分由数字“4”组成。每个 TRANSACTION 编号 + 1 = 正确的编号。这就是为什么service call isms 5
负责sendText
而不是负责sendMultipartText
。
The same rule applies for all services.
相同的规则适用于所有服务。
I am sure that you find out how to check TRANSACTIONs for notification service now. Good fun.
我相信您现在已经了解了如何检查 TRANSACTIONs 以获取通知服务。好开心。