adb: tap and input text - android

I'm trying to use "input tap" and "input text" via ADB:
input tap 400 730
input tap 60 410
input tap 150 490
input tap 120 300
input tap 120 420
input tap 130 180
input tap 130 180
input text name_of_the_apn
Tapping works fine, but the execution of the scripts gives back an error when it tries to input the text (see below). However, when I try to send the text outside of the script, it works fine. I already tried adding sleep between tapping and the text - with no effect.
Any hints? Thanks!
/mnt/.lfs: Function not implemented
/data/ste-debug/stedump: Operation not permitted
[1] Killed input text name_of_the_apn

I know it's nearly 7 years now, but I have to escape any spaces in the text when I use type from the commnand line (as opposed to being in the shell):
adb shell input text "Hi\ there\ this\ is\ dog"
and also be weary if it's a variable in bash
TEXT="Hi\ there\ this\ is\ dog"
adb shell input text "$TEXT" #make sure it's in quotes
I also think that maybe you had a variable on your terminal name_of_vpn but you were in the adb shell at the time, and the variable was not present, or you are not accessing that with $
It could also be that this has been fixed now.

Related

Adb sleep function working on adb but not in a .sh file

i am trying to make a simple "tap and wait" script to run on my Android device through adb.
Opening adb on Powershell with the command ./adb shell works, running input tap 300 300 works, and running sleep 1does sleep for a second.
However, if I run a test.sh script with the Powershell command ./adb shell "sh /sdcard/Download/test.sh" the tapping part still works, but the sleep call gives me this instead: 'sdcard/Download/MIOPROGRAMMA.sh[2]: sleep: syntax error: Invalid argument '1 .
Any idea why this happen?
Just add ; after the int, i.e.:
input tap 250 250
sleep 3;
input tap 350 250
sleep 3;
input tap 450 250
sleep 3;
input tap 550 250
sleep 3;
input tap 650 250
sleep 3;
Why not use powershell's Start-Sleep cmdlet ? Have all your logic in the powershell script.
$sendTapCmd = "adb shell `"input tap 250 250`" "
$numberOfTaps = 5
for ($i=0;$i -lt $numberOfTaps;$i++) {
$output = Invoke-Expression $sendTapCmd
Start-Sleep -Milliseconds 3
}

How to make monkeyrunner simulate a drag following a custom path on the android screen?

The MonkeyDevice.drag currently can takes only 2 sets of co-ordinates which means I can move from (x1,y1) to (x2,y2). Is there a way I could make the monkey runner simulate a drag from (x1,y1) to (x3,y3) and then to (x2,y2) without breaking the same drag function?
Monkeyrunner is kind of deprecated.
You can use uiautomator instead. More details can be found here:
http://developer.android.com/tools/testing/testing_ui.html
This tool has a method for what you seek, a custom swipe using an array of points (x, y coordinates). More on that here:
http://developer.android.com/tools/help/uiautomator/UiDevice.html#swipe(android.graphics.Point[], int)
I would use Get/Send Event.
Get an event, e.g. touch screen:
issue command: adb shell getevent | grep event2 > CaptureEvent.txt
do the touchscreen activity
stop the recording with CTRL+C
Convert the event:
e.g.: /dev/input/event1 3 47 0
Send an event:
issue commands, e.g.: adb shell sendevent /dev/input/event1 3 47 0

Android - how to paste File.txt content into adb Shell

I am writing a small code to search for a number in whatsapp and send a text message.
I am able to send text message if I type in the script itself, but I wanted to paste the message from a file.
Is there any way to copy the content from a file instead os using the adb shell input text command.
My code below.
adb shell input keyevent 82
adb shell am force-stop com.whatsapp
adb shell am start -n com.whatsapp/.Main
adb shell input text "9800000000"
adb shell input keyevent 66
adb shell input text 'This%sis%sa%stest%smessage'
adb shell input keyevent 66
adb shell input text 'I%sam%schecking%slots%sof%sthings'
adb shell input keyevent 61
adb shell input keyevent 61
adb shell input keyevent 66
adb shell am force-stop com.whatsapp
Thanks,
Deepak
You don't say which scripting language you are using.
You can do it from a Native binary (written in C/C++).
1. Open the file for reading.
2. LOOP
3. Read a line into a string.
4. convert all special characters to escape strings
5. Use the command system to send the text:
system("input "text Hello%sWorld");
6. LOOP
I wrote such a binary called inputer. pasting into it works quite well, but
each line is fork/exec'd so big files can get out of order, you need to test for each line completing or send as one huge call.
Yes, you actually can do this. It's kind of kludgy looking when you inspect the clipboard, but it works just fine.
First off, you can inspect the current clipboard contents with service call clipboard 1 from an adb shell (or, without shelling in first, adb shell service call clipboard 1). It may start out initially blank after a reboot, for example:
service call clipboard 1
Result: Parcel(
0x00000000: 00000000 00000001 00000000 00000000 '................'
0x00000010: 00000000 00000000 '........ ')
#
You can put text into the clipboard using service call clipboard 2, which basically takes 3 parameters - two ints and the string you want to put on the clipboard:
# service call clipboard 2 i32 1 i32 0 s16 "Hi there"
Result: Parcel(00000000 '....')
To be honest, I'm not sure what the first two parameters are. One answer on Stack Overflow has suggested the first int is "number of items in the parcel" (one in this case) and that the second is the length of the string. However, I've used 0 for the second parameter and it works fine, and I can't find any documentation that matches up with this particular function...so take that for what it's worth.
In any case, it's basically creating a Parcel object with 3 fields, then passing it into the clipboard. The clipboard then unpacks the Parcel and sets the string value passed in as the clipboard's contents. You can see this when you go to retrieve the value afterwards:
# service call clipboard 1
Result: Parcel(
0x00000000: 00000000 00000001 00000000 00000008 '................'
0x00000010: 00690048 00740020 00650068 00650072 'H.i. .t.h.e.r.e.'
0x00000020: 00000000 00000000 '........ ')
#
Similarly, if you long-press on a text entry field and hit "Paste" after doing this, you will get the text that was set via the call service clipboard 2 line above (and it will look completely normal).
(The above examples come from my HTC EVO, running CyanogenMod 7)
Reference : https://android.stackexchange.com/questions/19710/is-it-possible-to-write-to-a-devices-clipboard-using-adb

Android Touchscreen IDC

I'm struggling with calibration of a touchscreen on Android plataform.
It is an USB Single-Touch Touchscreen from vendor 0dfc and product 0001 as checked with dmesg:
<6>[ 4118.091541] input: USB Touchscreen 0dfc:0001 as /devices/platform/usb20_host/usb2/2-1/2-1.3/2-1.3:1.0/input/input23
I'm pushing the Vendor_0dfc_Product_0001.idc file /data/system/devices/idc/ (following the documentation from android source - IDC
I got the touch device with all requirements for single touch events:
root#android:/ # getevent -il /dev/input/event3
add device 1: /dev/input/event3
bus: 0003
vendor 0dfc
product 0001
version 0202
name: "USB Touchscreen 0dfc:0001"
location: "usb-usb20_host-1.3/input0"
id: ""
version: 1.0.1
events:
KEY (0001): BTN_TOUCH
ABS (0003): ABS_X : value 540, min 0, max 32767, fuzz 0, flat 0, resolution 0
ABS_Y : value 289, min 0, max 32767, fuzz 0, flat 0, resolution 0
input props:
<none>
I also enabled the Pointer Location option from Developer options (Android settings) in order to debug this stage of calibration.
Setup 1
touch.deviceType = touchScreen
With this setup (1) all the gestures on the touchscreen take place at the up-left corner - just a few pixels left/right/up/down no matter the gesture (swipe). All the touchscreen get events. All the gestures are reversed - when swipe left the pointer goes right; when swipe up, the pointer goes down.
Setup 2
touch.deviceType = pointer
touch.gestureMode = pointer
With this setup (2), as expected, it shows a pointer, placed at the position from the last pointer device left (mouse). All the gestures on the touchscreen (no matter the swipe size) keep beaving like setup 1 - move only a few pixels with each swipe event, and with reversed axis.
Setup 3
touch.deviceType = pointer
touch.gestureMode = spots
With this setup (3) the result is the same as setup 2. I just did that to prove that the IDC file is being interpreted correctly.
At this stage, as you can check by now, I have a working IDC file (setup 1) requiring calibration for this touch device.
I tried a lot of combinations from other IDC files (internet samples) and from android source - IDC - ANY OTHER PROPERTY TOOK EFFECT (NOT A SINGLE ONE) - raw.*, output.*, touch.size.*
Does anyone knows how to calibrate properly a touch screen in Android that could guide me in this process?
Same here,
but my calibration app did't do anything.
After a while, reading /system/etc/init.sh i found the following:
mkdir -p /data/misc/tscal
touch /data/misc/tscal/pointercal
chown 1000.1000 /data/misc/tscal /data/misc/tscal/*
chmod 775 /data/misc/tscal
chmod 664 /data/misc/tscal/pointercal
Just run those commands manually, reboot, and start the calibration app

How to set brightness through ADB on nexus 7

I found some info on the web:
echo 1 /sys/devices/platform/flashlight.0/leds/flashlight/brightness
But on my Nexus 7 (flashed an AOSP), I couldn't find that directory.
Any idea about which file should I write to? Is this doable?
After ls /sys/devices/platform, I got:
LID
alarm
arm-pmu.0
bcm4330_rfkill
bcmdhd_wlan.1
bluesleep
fiq_debugger.0
fsl-tegra-udc
gpio-keys.0
grouper_misc
leds-gpio
oprofile-perf.0
power
power.0
pwm-backlight
ram_console
reg-dummy
reg-fixed-voltage.1
reg-fixed-voltage.10
reg-fixed-voltage.11
reg-fixed-voltage.2
reg-fixed-voltage.3
reg-fixed-voltage.4
reg-fixed-voltage.6
reg-fixed-voltage.8
regulatory.0
sdhci-tegra.2
sdhci-tegra.3
serial8250
snd-soc-dummy
spdif-dit.0
spdif-dit.1
spi_tegra.0
spi_tegra.3
tegra-ehci.1
tegra-i2c.0
tegra-i2c.1
tegra-i2c.2
tegra-i2c.3
tegra-i2c.4
tegra-nvmap
tegra-otg
tegra-pcm-audio
tegra-se
tegra-snd-rt5640.0
tegra30-ahub
tegra30-dam.0
tegra30-dam.1
tegra30-dam.2
tegra30-hda
tegra30-i2s.1
tegra30-i2s.3
tegra30-i2s.4
tegra30-spdif
tegra_camera
tegra_pwm.0
tegra_rtc
tegra_smmu
tegra_uart.1
tegra_uart.2
tegra_uart.3
tegra_uart.4
tegra_wdt
uevent
There is a new binary shipping with Android Jellybean 4.2, which can be used to directly read/write to the system settings provider, accessible via command line.
For example: in order to increase brightness of the screen, use below command:
adb shell settings put system screen_brightness 200
Read more about SCREEN_BRIGHTNESS Note that the range of values is [0 - 255]
The range of values is not necessarily from 0 - 255. On my OnePlus for example
it ranges from 0-2047. If you want to know yours just set the brightness slider to max and
then type: adb shell settings get system screen_brightness.
You should use the pwm-backlight!
You can use this adb command to set screen brightness
adb shell settings put system screen_brightness 255
and if your device has auto brightness setting then use this command first
adb shell settings put system screen_brightness_mode 0
This did not work for the latest Nexus 7 (2013) for me. But this answer explains the way to find what you are looking for on any version: https://stackoverflow.com/a/13492336
However we need to note that in order to change any of this you need to have root access.

Categories

Resources