android - 在哪里可以找到有关 Android 的 "service call"shell 命令的信息?

标签 android shell service adb

使用 adb shell 或设备上的终端模拟器,输入此将清除所有通知(需要 su)

service call notification 1

这将发送一条短信(不需要su)

service call isms 5 s16 "PhoneNumber" i32 0 i32 0 s16 "BodyText"

在哪里可以了解有关服务调用的更多信息?我找到了this question并欣赏答案对所有含义的分割。但是我在哪里可以找到关于 notification 2 可能试图调用的方法的信息?

运行 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.

我运行了 service list,它为我的设备返回了 78 项服务,包括 ismsnotification,并且大多数服务将打印看起来的内容成为一个命名空间(com.android.internal.telephony.ISms for ismsandroid.app.INotificationManager for notification)。我如何使用这些信息来了解我可以使用这些服务做什么?

最佳答案

简而言之

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>

详细介绍
我遇到了很多问题需要了解,因此我将在剪贴板服务的帮助下分享解决方案。
首先你需要了解你感兴趣的服务-
为此,您需要通过键入来查找特定 android 系统的所有服务

adb shell service list

这就是你会得到的-

.
.
.
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]
.
.
.

因为我对剪贴板服务感兴趣,所以它看起来是这样的

70  clipboard: [android.content.IClipboard]

所以从这里我们可以总结出服务名是剪贴板服务,包路径是android.content.IClipboard

那你需要知道IClipboard.aidl所在的完整路径。
要知道您需要在 google 上搜索 IClipboard.aidl。
您需要在结果中从 android.googlesource.com 网站中查找某些内容,例如我的情况-

https://android.googlesource.com/platform/frameworks/base.git/+/android-4.2.2_r1/core/java/android/content/IClipboard.aidl

所以在 +/android-4.2.2_r1 之后是你的路径所在。让路径为 path_of_clipboard.aidl=

/core/java/android/content/IClipboard.aidl

由于这些服务调用代码依赖于 android 系统,因此您需要知道您的 android 操作系统名称- 就我而言,它是 8.1.0
所以我会去下面的网站,谷歌在那里放代码,然后从页面的左侧选择我的操作系统版本-

https://android.googlesource.com/platform/frameworks/base/

就我而言,它是 android-8.1.0_r50。这里 r50 并不重要。您可以选择任何修订。现在我将点击链接,然后我的网址将如下所示

https://android.googlesource.com/platform/frameworks/base/+/android-8.1.0_r51

然后在添加 path_of_clipboard.aidl 之后,我的完整 url 会是这样的

https://android.googlesource.com/platform/frameworks/base/+/android-8.1.0_r51/core/java/android/content/IClipboard.aidl

这里会有很多接口(interface)中的方法。就像我的情况

    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);

因此,第一个方法(即 setPrimaryClip)的代码将是 1,因为它出现在第一个位置,而最后一个方法(即 hasClipboardText)的代码将是 7,因为它出现在aidl 文件中的第七个位置。对于其他方法也是如此。
所以如果我想调用第七个方法,我会输入

adb shell service call clipboard 7 

您可能已经看到,我没有输入调用包名称,因为它不是必需的。

如果方法需要参数,那么你可以像这个例子中那样传递它。
让我们假设一个方法,它的代码是剪贴板中的 8,看起来像这样 -

getDemo(String arg1, int arg2, boolean arg3)

所以我会这样调用它

adb shell call clipboard 8 s16 "first_argument" i32 12 i32 1

这里 i32 代表 32 位整数,s16 代表字符串。我们甚至可以将 bool 值作为整数传递,如示例所示。
在 bool 整数中,1 代表真,0 代表假。
Source

提示 保持 logcat 处于打开状态(就像在 android studio 中一样)以检查执行该 adb 命令时发生的任何错误。

关于android - 在哪里可以找到有关 Android 的 "service call"shell 命令的信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20227326/

相关文章:

linux - 停止或重新启动网络会导致 GUI 更改

linux - 通过 shell 脚本拆分字符串变量

bash - 如何在 shell 脚本中以 %Y%m%d 格式打印两个日期之间的日期?

java - Android Room - 处理对象中的对象列表和查询结果

android - 如何更新Android中NotificationCompat中Action的图标

shell - sed中如何匹配空格?

javascript - 在我自己的 Angular 服务中,如何将返回值返回给调用该服务的 Controller ?

android - 在 AndroidManifest 中有条件地声明服务

android - 如何在android studio中打开另一个项目

android - 检测点击android后退按钮以关闭键盘