2

I'm trying to send messages using adb shell commands. I sent on Android 10 but not on Android 11. I tried everything but without success. I found source code of isms service for android 11 here. I have 2 more Android 11 phones and when I test them the result is the same. To test that my shell commands are working on the device, I tried the input command and it does. I read this and still it didn't help.

The command I use:

adb shell service call isms 7 i32 0 s16 "com.android.mms.service" s16 "%number%" s16 "null" s16 "%message%" s16 "null" s16 "null"

Output of this command:

Result: Parcel(00000000 '....')

Can someone help, how do I send messages with adb shell commands on Android 11?

(I tried on Android 12 and result is same)

  • 1
    Following [this answer](https://stackoverflow.com/a/30224091) and notes in its comments, this works on my 11 emulator: `adb shell service call isms 5 i32 1 s16 "com.android.mms.service" s16 "null" s16 "NUMBER" s16 "null" s16 "MESSAGE" s16 "null" s16 "null" i32 0 i64 0`. I'm having trouble getting a 12 running atm, but I'm pretty sure it should be the same thing on that version, or at least very similar. – Mike M. Mar 27 '22 at 04:16
  • Yes, you right it's working right now. Post it and I'll give your bounty award. Thank you! – Abdulkadir Can Kinsiz Mar 28 '22 at 12:26
  • No kiddin'? Gotta say, I didn't really expect it to work anywhere else. That's nifty. Anyhoo, I don't post answers here anymore, so please feel free to finish this up however you'd like; e.g., if you wanna post an answer yourself, or whatever. Thank you, though; I appreciate the offer. Glad I could help. Cheers! – Mike M. Mar 28 '22 at 14:37

4 Answers4

3

After Android 10:

adb shell service call isms 5 i32 1 s16 "com.android.mms" s16 "null" s16 "number" s16 "null" s16 "message" s16 "null" s16 "null" i32 0 i64 0

Before Android 10:

adb shell service call isms 7 i32 1 s16 "com.android.mms" s16 "number" s16 "null" s16 "message" s16 "null" s16 "null"
3

For a future proof way - since the numbers (5,7) change, you're better off using the isms AIDL directly. Looking at the isms as an example, we see:

redfin:/ $ service list | grep isms                                                                                         
104 isms: [com.android.internal.telephony.ISms]

So, looking at the isms.aidl (frameworks/base/telephony/java/com/android/internal/telephony/ISms.aidl) you'll see that '5' is now

   void sendTextForSubscriber(in int subId, String callingPkg, String callingAttributionTag,
            in String destAddr, in String scAddr, in String text, in PendingIntent sentIntent,
            in PendingIntent deliveryIntent, in boolean persistMessageForNonDefaultSmsApp,
            in long messageId);

so the suggested answer:

call isms 5 i32 1 s16 "com.android.mms" s16 "null" s16 "number" s16 "null" s16 "message" s16 "null" s16 "null" i32 0 i64 0

basically fakes the arguments (and not exactly right):

in int subId = 1
String callingPkg = "com.android.mms"
String callingAttributionTag = "null"
in String destAddr = "number"
in String scAddr = "16"
in String text = "text"
in PendingIntent sentIntent ="null" (should be i32 0)
in PendingIntent deliveryIntent = "null" (should be i32 0 also)
in boolean persistMessageForNonDefaultSmsApp = 0 = false, 
in long messageId = 0 (the i64) 

When you can, refer to the AIDL. It's MUCH safer, and also makes sure that you serialize the right arguments. Unfortunately, these change frequently between versions.

(source: "Android Internals", Volume II (http://NewAndroidBook.com))

Technologeeks
  • 7,674
  • 25
  • 36
  • That arguments list is a bit off for given method. The last two – `priority` and `expectMore` – aren't there; should be the `long messageId` instead, which is why it's `i64`. Just FYI. – Mike M. Mar 31 '22 at 01:49
  • Yes, you are somewhat right. But your command is not working properly on Android 11 and Android 12. Thank you anyway. Your article is very informative. – Abdulkadir Can Kinsiz Mar 31 '22 at 20:50
  • I beg to differ. It works perfectly on 11 and 12. You just need to get the right AIDL for it. The number changed from 7 to 5 ,and might change again in 13 – Technologeeks Apr 01 '22 at 00:55
  • and per Mike M's observation - I was using the Android 12.0 AIDL for this. So if it's not message ID anymore it's not me, it's Google having changed the interface (which vindicates the point I'm trying to make). It just so happens that priority and expectMore are two i32, so putting one i64 in their place works :-) – Technologeeks Apr 01 '22 at 00:55
  • Uh, no, sorry, I was pointing out that the last two argument descriptions in that final list are wrong for `sendTextForSubscriber()`, which is used for both 11 and 12. There is no `priority` or `expectMore` parameters in that method; those parameters are from `sendTextForSubscriberWithOptions()`. The final parameter in `sendTextForSubscriber()` is `messageId` which is a `long`, which is why it's an `i64`. – Mike M. Apr 01 '22 at 01:10
  • Oi. Yes. I agree. I was cutting pasting the other AIDL method for that. Good catch. My bad - serves me right for doing this with little sleep ;-P I'll edit and fix, but really the answer as a whole is fine and I believe this is a better method since it is future proof, and less prone to mistakes cutting/pasting when people just copy commands blindly and remain unaware of what the args mean. – Technologeeks Apr 02 '22 at 02:09
0

If you just want to send a few test messages to your emulator and don't want to deal with adb, you can do this via the emulator itself

enter image description here

Alex Styl
  • 3,982
  • 2
  • 28
  • 47
-3

The following will write the SMS message using the default messaging app but won't send it: adb shell am start -a android.intent.action.SENDTO -d sms:+1234567890 --es sms_body "Test" --ez exit_on_sent false. This won't help if you want to send the message entirely in the background.

Devlpr
  • 165
  • 2
  • 5