Send multi-touch events to Android emulator - android

I need to test an Android application that takes multi-touch input, such as pinch and rotate. I'd like to test this using the emulator if possible. Is there a way to send Linux input events, via ADB or otherwise, without modifying the Android source?
https://source.android.com/devices/tech/input/touch-devices.html
Events such as ABS_MT_POSITION_X, ABS_MT_POSITION_Y, and ABS_MT_TRACKING_ID.

Old question but still open.
Indeed there are options:
1.) Send commands via telnet (https://developer.android.com/studio/run/emulator-console)
2.) Use adb like (input tap X Y), e.g.
adb shell input tap 100 100

Related

adb + android: access app-produced clipboard data programmatically in Linux terminal

Setup
I'm on an Android 10 device and have an app (henceforth generator) that generates data it can copy to the device's clipboard (this involves swipes, taps, etc.). I need to do that repeatedly, as many times as possible (hundreds, thousands, whatever), and retrieve that data programmatically (presumably through a bash or perl script wrapped around adb commands).
Question
What would be some effective ways of achieving this?
Elaboration on what I've tried
I actually have a solution, I am just not sure it's the "best" one can do (whatever that means). generator is closed-source so I can't alter its behavior in any way, but I can repeatedly
start generator and/or switch focus to it with
adb shell monkey -p <generator-app> 1
mimic the tapping actions that produce the data and copy it to the clipboard with various
adb shell input tap x y
commands;
open/switch focus to the Termux terminal emulator (on the Android device):
adb shell monkey -p com.termux 1
access the clipboard via its Termux:API add-on, by running the termux-clipboard-get command in the termux terminal (again, on the Android device). I control this through adb with
adb shell input text 'termux-clipboard-get\>\>file-on-android-gadget.txt' && adb shell input keyevent 66
(keyevent 66 means ENTER, and the \>\> means append, >>, with escaped characters).
repeat the whole shebang.
This gives me many instances of the desired output in file-on-android-gadget.txt, saved locally on the phone (I'm OK retrieving it later, etc.).
Alternative routes?
What bothers me is the need to switch back and forth between two apps. I don't know that I have much choice over how I interact with generator, as it's closed-source and does not expose its internals, but perhaps one can do better at "the other end", i.e. when retrieving the clipboard data.
Newer Android APIs have locked down access to the clipboard, rendering it difficult to interact with programmatically, through adb. This SO thread points to a repo for a (Kotlin + gradle) app that sets the clipboard via a service runnable through adb, but my attempts to get the clipboard have been unsuccessful (i.e. getPrimaryClip() returns empty). I believe this is because, as per the docs:
getPrimaryClip
public ClipData getPrimaryClip ()
Returns the current primary clip on the clipboard. If the application
is not the default IME or does not have input focus this return null.
So there might just be no way around having to focus on a second app before the clipboard can be retrieved. But I have no experience programming apps, hence the question.
A further reference
During my peregrinations I found another repo for an Android app (Java + maven) that both gets and sets the clipboard. Same caveat though: as of Android 10, it needs to be in focus for the broadcast receiver to retrieve the clipboard data (other than that it works fine; I have it on my Android 10 device as we speak). So this would fare no better than my currently-working termux-based solution detailed above.

Android SMS limit on Android 4.0.4

I am working with phone with Android 4.0.4 (I know, the old one)
Now I need to override limit of 100 sms send per hour (Below android 4.1 there should be limit 100 sms per hour. Since android 4.1 there is limit 30 sms per 30 minutes).
Since Android 4.2 it is possible via adb shell settings put global sms_outgoing_check_max_count.
But I have no idea how to do it on Android 4.0.4 without rooting because there is no "adb shell settings" command. Any idea?
P.S. I am not creating app. I need to override this limit ideally in android settings via adb or by using another app for this (if it exists)
You could do it by creating the application and overriding the SmsUsageMonitor:
com.android.internal.telephony.SmsUsageMonitor
It should basically work on any phone, without rooting it first.
Could you try to follow theses steps via ADB :
1.Open Command Terminal
2.Type in adb shell hit enter
3.Type in su hit enter
4.Type in sqlite3 /data/data/com.android.providers.settings/databases/settings.db hit enter
5.Type in INSERT INTO secure (name, value) VALUES('sms_outgoing_check_max_count’, 9999); hit enter
6.Type in INSERT INTO system (name, value) VALUES('sms_outgoing_check_max_count’, 9999); hit enter
7.Type in .exit hit enter (you should now see a hash tag again instead of sqlite>. If not conitune typing in .exit and hitting enter until you are)
8.Type in sqlite3 /data/data/com.google.android.gsf/databases/gservices.db
9.Type in INSERT INTO main (name, value) VALUES('sms_outgoing_check_max_count’, 9999); hit enter
10.Again exit back to where the command line has a hashtag
11.Type in reboot and hit enter.
I don't have a phone with Android 4.0.4, so i can't confirm that it will work
Happy testing !
you have to use abd command to open that restrictions here is the link for tutorial change sms limit
1.Go to the android platform tool directory
`(C:\Users\username\AppData\Local\Android\Sdk\platform-tools)``enter code here`
open command shell by using Shift+mouserightclick and enter this command
adb shell settings put global sms_outgoing_check_max_count 5
settings put global sms_outgoing_check_interval_ms 9000000
I am actually reducing the number so Android warns me if I have sent more than 5 SMS messages within 30(9000000) minutes. Change “5” to whatever number you want
What exactly do you want to acheive with over 100 SMS per hour?
I am sure there is a way more efficient way of sending your data for example through
a wireless network or mobile data. You would hardly manage to reach the data limits of
those networks.
Just saying ... try only to do it over SMS if there really is NO other way of sending it.
Good luck!

Invoke fingerprint touch on emulator from code by shell

I am trying to make integration tests which test Fingerprint.
According to google doc to invoke finger touch on emulator from terminal you need to use:
adb -e emu finger touch < finger_id >
And this works for me. In my case id is 45146572. However in test you cannot input this command on your own as it should be done automatically.
I've been trying various things to make a workaround (eg. trying to understand how app is receiving information from sensor - maybe by some kind of broadcast intent etc.) and for now I still don't know how to do it.
I know that UiAutomation and UiAutomator's class - UiDevice has method
executeShellCommand
and I think that this might be helpful. But even if I do something like:
getUiDevice().executeShellCommand("-e emu finger touch 45146572");
My device won't react to it (I've tried on both classes and various threads). I believe this is caused by the fact executeShellCommand is running already inside shell. So it's like I've typed to terminal
Kamils-MacBook-Pro:~ F1sherKK$ adb shell
root#generic_x86_64:/ #
And I guess that's the problem, because google wants:
adb -e emu finger touch
not
adb shell -e emu finger touch
My knowledge about shell might be not enough maybe. I've looked through all documentation many times.
Do you have any idea how to call finger touch from shell?
I believe you have to be using different format of password. It should be "aa11aa" which is LetterLetterNumberNumberLetterLetter.

How can I add an existing google account on an Android device from command line?

I have a large set of devices that I want to add google accounts to. The google accounts are already setup so I just want to add these existing accounts to the devices through a command line script.
There are two possible ways (Non-Root):
#1 Develop an app that implements the Account Manager and facilates the login process.
#2 Use a series of ADB commands to pass the input strings and stimulate the touch events.
ADB Command Example:
Start the native add account settings screen
ADB shell am start -a android.settings.ADD_ACCOUNT_SETTINGS \
-n com.android.settings/.accounts.AddAccountSettings
Select the absolute coordinates of the screen where the Google account is located. Each device has different screen sizes, so you have to figure out the exact position of your device. If you have multiple apps with login accounts they will also appear here. E.g., Microsoft Office, Reddit, and WhatsApp.
adb shell input tap X Y
Tips: You can enable the Show taps and Pointer location from
Developer Option. This will give you the precious location of the
touch input.
Set the desired input text
adb shell input text "account#gmail.com"
If you want select a keyboard event, pass the event code from the KeyEvent constants
adb shell input keyevent 66
Here, 66 is the event code of "KEYCODE_ENTER"
Repeat the input/touch process until you successfully login to the system.

how can i use 'adb shell' command to know application response or current activity

I have created a batch file that fires adb shell command to start activity, send events to enter text into username and password text fields & click login buttons to navigate to other activity(screen).
how can i know that application navigate to other activity or want to know the response that tell me if login successful or not using shell commands.
Thanks,
Bhushan
Dollop, where I work, provides a record-and-play-back tool for Android that will do the things you suggest and save you the hassle of interacting with low-level shell commands. (It is currently limited to running on Windows in communication with Android devices). It's easy to configure and use, requires no programming, runs against real devices (which do NOT have to be rooted) and automatically saves screenshots as it plays tests. I'd love to hear your feedback.
try to get process (ps aux | grep xxxxx ) information to know the activity running or not

Categories

Resources