在哪里可以找到有关Android的“服务调用”shell命令的信息?

ve7v8dk2  于 2023-02-13  发布在  Shell
关注(0)|答案(5)|浏览(148)

使用adb shell或设备上的终端仿真程序,输入此命令将清除所有通知(需要su

service call notification 1

这将发送短信(不需要su

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

我在哪里可以了解到更多关于service call的信息?我已经找到了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用于ismsandroid.app.INotificationManager用于notification)。我如何使用此信息来了解我可以使用这些服务中的每一个来做什么?

9bfwbjaz

9bfwbjaz1#

简而言之

与服务调用命令相关的代码只是函数的参数以及函数在该服务的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>

详细信息

我面临了很多问题,了解它,因此我将分享与剪贴板服务的帮助下的解决方案。
首先,您需要了解您感兴趣的服务-
为此,你需要寻找所有的服务,是有特定的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]

从这里我们可以总结出服务名称为clipboard service,包路径为android.content.IClipboard
然后您需要知道IClipboard.aidl所在的完整路径。
要知道,你需要在谷歌上搜索IClipboard. aidl.
你需要在结果中从www.example.com网站上寻找一些东西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

这里接口中会有很多方法,就像我的例子

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,因为它出现在aidl文件中的第一个位置,而最后一个方法(即hasClipboardText)的代码将为7,因为它出现在第七个位置。
如果我想调用第七个方法我会输入

adb shell service call clipboard 7

正如您可能已经看到的,我没有输入callingPackage名称,因为它不是必需的。
如果这个方法需要参数,那么你可以像这个例子中所示的那样传递它。
让我们假设一个方法的代码是8在剪贴板和它看起来像这样-

getDemo(String arg1, int arg2, boolean arg3)

所以我就这么叫它

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

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

提示保持logcat打开(如在android studio中)以检查执行adb命令时发生的任何错误。

jrcvhitl

jrcvhitl2#

下面是我关于Calling Android services from ADB shell的文章,其中包含一个小的bash脚本,我使用它自动下载适合我的特定设备的服务源代码的正确版本,然后解析它以找出所有方法的事务代码。

w3nuxt5m

w3nuxt5m3#

我的第一个答案在这里,所以我希望会对你有用。
为了解释这个小谜语,让我使用android 4.3.1. This链接可能是必不可少的在您的情况下。向下滚动java代码到第669行。有等待您的TRANSACTION块与com.android.internal.telephony.ISms服务严格相关,可能你的答案,你可以做更多。
在您的示例中,您调用的是TRANSACTION_sendText。解释在第673行,您可以找到

static final int TRANSACTION_sendText = (android.os.IBinder.FIRST_CALL_TRANSACTION + 4);

代码的最后一部分由数字“4”组成。每个交易编号+1 =正确的交易编号。这就是为什么service call isms 5负责sendText而不是sendMultipartText
同样的规则适用于所有服务。
我相信你现在已经知道如何检查通知服务的交易了。很有趣。

mzmfm0qo

mzmfm0qo4#

使用service call notification 1等是不安全的,因为它可能会做一些完全不同的任何设备上运行它。
您可以使用android-svc代替。例如,拨打一个号码(无需呼叫):

android-svc --adb call 'phone.dial("555-0199")'

它还为您提供有关数据类型的信息。

android-svc --adb method-signature 'phone.dial'

将打印:

void dial(String number);

它还可以首先列出给定服务的方法...
此gif取自the repository

请注意,在最新版本的Android中,您发送短信的isms调用不再起作用,因为isms服务不再有sendText方法。您现在可能必须使用sendTextForSubscriber,这将更难调用,因为它需要更多的参数。
此外,要直接回答您的问题 * 在哪里可以找到有关Android的"service call" shell命令的信息?*:Look at the source code.

Usage: service [-h|-?]
       service list
       service check SERVICE
       service call SERVICE CODE [i32 N | i64 N | f N | d N | s16 STR | null | fd f | nfd n | afd f ] ...
Options:
   i32: Write the 32-bit integer N into the send parcel.
   s16: Write the UTF-16 string STR into the send parcel.

自安卓6起提供:

i64: Write the 64-bit integer N into the send parcel.
   f:   Write the 32-bit single-precision number N into the send parcel.
   d:   Write the 64-bit double-precision number N into the send parcel.

自安卓11起提供:

null: Write a null binder into the send parcel.
    fd: Write a file descriptor for the file f to the send parcel.
   nfd: Write file descriptor n to the send parcel.
   afd: Write an ashmem file descriptor for a region containing the data from file f to the send parcel.

始终可用的隐藏选项:

intent: Write and Intent int the send parcel. ARGS can be action=STR data=STR type=STR launchFlags=INT component=STR categories=STR[,STR,...]
ifmq2ha2

ifmq2ha25#

我没有足够的声誉来评论亚历克斯P的答案(https://stackoverflow.com/a/25987165/16725644),但为他竖起大拇指!
他的bash链接脚本非常棒,虽然与当前的Android版本相比已经过时。我已经更新了他的脚本,并将其发布在这里:https://pastebin.com/xQ21EZJh至少在a10和a11上运行良好!但我想它在最新版本上也运行良好。
我一直在使用它来捕获服务呼叫号码,以增加后台进程限制,在A11上使用以下命令:

service call activity 43 i32 xxx

谢谢亚历克斯!

相关问题