Is it possible to use the android api functions from the adb? If its possible, what is the syntax to do so?
For example I'd like to call the "DATA_CONNECTED" function from android.telephony and get its return value. Link: http://developer.android.com/reference/android/telephony/TelephonyManager.html#CALL_STATE_OFFHOOK
There is no DATA_CONNECTED function in Android TelephonyManager. It is a 0x00000002 constant - one of possible response codes to the getDataState() function.
The way you call getDataState() from adb shell is:
service call phone 32
Update: if your phone runs anything older than jb-mr2, the command should be:
service call phone 31
P.S. just finished my write-up on Calling Android services from ADB shell - it includes a small bash script to look up calling codes for any service/method for a specific device.
Related
So I have a python script to test an android app with the monkeyrunner tool and at a certain point in the script, I have command to launch the application on the mobile phone. The command is: device.shell('monkey -p com.blah.blah -v 500') and it works perfect. But my question is: "What is the meaning of the number 500?"
I found this command on a forum and some users are using the value 300 instead of 500 or other values.. For me it works with all of them but not without it. I just need to understand what the number does so I can fully understand what I do.
As per Android Documentation this command will launch your application and send 500/300/200(as specified by you) pseudo-random events to it such as clicks, touches, or gestures.
I have a Xiaomi Mi6, which supports two SIMs. I need to figure out how I can switch the second SIM (SIM2) off outside business hours using Tasker.
I've got as far as figuring out how to open the settings page for SIM2 with Tasker:
Action: android.intent.action.MAIN
Cat: Launcher
Extra 1: subscription_id:1
Extra 2: slot_id:1
Package: com.android.phone
Class: com.android.phone.settings.MultiSimInfoEditorActivity
Target: Activity
which brings up the settings page for SIM2, like so. However, I can't figure out how to toggle the SIM on or off.
In hope of finding something useful I have decompiled com.android.phone (TeleService.apk) but as I don't know Java I haven't an idea where to go from here. I know there is a Java solution already on SO here but I have no idea if it works or how to adapt it to Tasker.
The decompiled MultiSimInfoEditorActivity can be found here. I have also taken a logcat of what occurs when the SIM is switched off and on again.
I greatly appreciate any help!
I've solved the issue, although it may not work for all versions of Android. I've only tested it with my Mi6 running MIUI v9, Android build 8.0.0. It requires root.
After studying the SO solution linked above in my question I noticed that the code was retrieving the index number of a particular telephony function, which it would then use to run a command to switch off mobile data. Using this, I've found a way to actually switch the SIM off.
Googling produced this page from Haotian Deng that showed these indexes for the service call function were listed inside the ITelephony.aidl file. These are what were being fetched by the Java code . None of these worked for the Mi6, but linked to this page which explained the service call command:
# service
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.
Armed with this I found that the indexes were listed in com.android.internal.telephony.ITelephony in the devices' framework.jar.
So, to get the required index out of your device, you'll need to run the following commands from command prompt:
Download jadx from here
ADB pull the devices framework.jar (adb pull /system/framework/framework.jar)
Open the .jar file with 7-Zip and extract the *.dex files.
Open each .dex file with jadx-gui until you find the one with the following tree: com.android.internal.telephony.ITelephony
Search for the item TRANSACTION_setSimPowerStateForSlot. Note the = x after it; this is the index number.
Now you have the index number you can test the following command in adb shell (or Tasker, with the "run shell" function). You will need to "su" in shell, or set Tasker to "Use Root".
service call phone x i32 y i32 z
Where:
x = index number you fetched previously,
y = your subscription ID (generally, SIM1 = 0, SIM2 = 1)
z = whether on (1) or off (0)
Of course, now that you can execute it in Tasker you can now switch either SIM off at specific times.
I've verified that it does indeed switch the SIM off (calls go straight to voicemail right after this command is executed) but I'm unsure of any further effects this switch has.
Enjoy!
I'm working on a non phone device that run Android 2.3.3. We have a custom Android version (with some additionnal driver) and my application has "system" privileges since we build our apps with the same key used to build android.
I had unlocked full Android API (including com.android.internal.*) following this post : https://devmaze.wordpress.com/2011/01/18/using-com-android-internal-part-1-introduction/.
I deleted the Phone.apk from the device to ensure that no process is using rild.
I can instanciate a GSMPhone from my app, but after, I'm unable to execute any commands like supplyPin or getImei. I always have the same error :
CommandException: RADIO_NOT_AVAILABLE.
I'm really stuck here, any help would be precious.
CommandException: RADIO_NOT_AVAILABLE indicates that the rild socket is not opened. In other words, the rild service is not attached to the underlying basebane/modem you are using.
Run ps in adb shell to check if rild service is in the list. If it is in the list, run ls -l /dev/tty* and check if the modem device attached with the Android platform exists here or not. If it does not exist, it means that the Kernel is unable to enumerate your modem device and you need to add support in kernel for it. If it exists, run adb logcat -b radio and check the radio logs output which would really be helpful to diagnose the issue further.
adb shell ps | grep rild to check if RILD is in runing.
Since you can access all the api, do some initialization like PhoneApp do in Phone application OnCreate(mostly like setting params to modem, set radio power which will power on/off the modem, etc)
Is it possible to execute AT commands on my Android phone? I want to extract layer-3 signaling information about the serving GSM network (MTP-3, RRC, ARFCN, channel type, RxQual, RxLev, etc). I did a lot of Google search but couldn't find anything useful.
Android telephony API seems very restrictive (only CGI, LAI, signal strength, etc) can be obtained. It is unreliable too, for example, getBitErrorRate() always returns -1, even in dedicated mode.
I read somewhere that it is possible to snoop-out some low level system information from UART interface between application processor (hosting Android OS) and baseband processor (hosting basic telephony applications). But I'm really not sure how to do that! Sorry, if the question seems out of place, but I'm hoping to get a workaround. I'm willing to root my phone!
First of all try to find information about invoking AT commands through adb interface.
Then if you get satisfying results you can root your phone and try to get the same results using code like this:
Process process = Runtime.getRuntime().exec("su -c " + command);
Where command is exactly the same you invoked in adb interface.
Monitor both:
process.getInputStream();
process.getErrorStream();
for the result of the command.
I have monkeyrunner up and running: I install my .apk using monkeyrunner and have a device object ready. In other words
device.press('KEYCODE_MENU', 'DOWN_AND_UP')
works perfectly.
I use expect to telnet to an android emulator of mine and do gsm call SOME_NUMBER to simulate and incoming call.
I try to reject this call in the following manner:
device.press('KEYCODE_ENDCALL', 'DOWN_AND_UP')
But it does nothing... What do i do wrong ?
If you are using
gsm call SOME_NUMBER
to start the call.
you can use either
gsm cancel SOME_NUMBER
to reject the call or
gsm accept SOME_NUMBER
to accept it.
As far as I can tell, there is no reliable way way to end calls using MonkeyRunner. I'm not sure why this is the case.
The question here offers some solutions.
You could also try doing:
device.press('KEYCODE_HEADSETHOOK', 'DOWN_AND_UP')
Using the headset hook keycode has worked for me on some devices but not others.
The most reliable method that I've found for ending calls using MonkeyRunner is to use menu button. This is talked about in the answers to the question that I linked to above.