adb shell input touchscreen tap is not working - python

I am trying to simulate tap and swipe gesture from adb to my android device. I've tried to run the following command
adb shell input tap 500 500 and adb shell input touchscreen tap 500 500 from windows command prompt. It is giving me the following error,
java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission
at android.os.Parcel.createException(Parcel.java:2074)
at android.os.Parcel.readException(Parcel.java:2042)
at android.os.Parcel.readException(Parcel.java:1990)
at android.hardware.input.IInputManager$Stub$Proxy.injectInputEvent(IInputManager.java:925)
at android.hardware.input.InputManager.injectInputEvent(InputManager.java:886)
at com.android.commands.input.Input.injectMotionEvent(Input.java:428)
at com.android.commands.input.Input.access$200(Input.java:41)
at com.android.commands.input.Input$InputTap.sendTap(Input.java:224)
at com.android.commands.input.Input$InputTap.run(Input.java:218)
at com.android.commands.input.Input.onRun(Input.java:108)
at com.android.internal.os.BaseCommand.run(BaseCommand.java:56)
at com.android.commands.input.Input.main(Input.java:71)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:380)
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.input.InputManagerService.injectInputEventInternal(InputManagerService.java:732)
at com.android.server.input.InputManagerService.injectInputEvent(InputManagerService.java:706)
at android.hardware.input.IInputManager$Stub.onTransact(IInputManager.java:422)
at android.os.Binder.execTransactInternal(Binder.java:1021)
at android.os.Binder.execTransact(Binder.java:994)
I've also tried to execute the same command from python script with the pure-python-adb package. The following is script I've exucted.
from ppadb.client import Client
adb = Client()
devices = adb.devices()
if len(devices) == 0:
print("No devices attached")
quit()
device = devices[0]
print(device)
device.shell('input touchscreen tap 700 1453')
I got the following output with no tap noticed on device and no error from the script.
<ppadb.device.Device object at 0x02B30E50>
Am I missing anything (Might be in developer's option setting for android)?
I am on windows 10 machine with adb version 1.0.41. And using an android device with Android 10 (Android Q) over a usb.

Look for a "USB debugging (Security Settings)" or something similar in your developer options in the debugging section -- This is where you grant ADB special permissions and allow input.
Best of luck; I hope you find it.

I tried this to tap a xy coordinate using adb command. Enabling the "USB debugging (Security Settings)" is worked for me. But the phone should connect to the internet inorder to enable the settings.
Thanks #Meer

Related

Get application version name using adb for several devices

Is there an easy way to get the version name of an application on Android devices using adb shell?
I've already find this command from here:
adb shell dumpsys package my.package | grep versionName
But I don't know how can I use it for more that one device?!
You cannot run an adb command on multiple devices in my experience but if you have multiple devices then adb command to run on specific devices becomes as follows:
adb [-d|-e|-s <serialNumber>] <command>
-d means run on the connected device (results in error for more than one connected device)
-e means run on the simulator (results in error for more than one simulator)
-s means use specific serial number
serial number used in -s is obtained with adb devices command.
a sample output of this command is:
List of devices attached
cf264b8f device
emulator-5554 device
for no device connected the first line is only printed
Output format is [serialNumber] [state], serialNumber that is, we often say that the SN, state the following categories:
Offline: indicates that the device is not connected to the success or unresponsive.
Device: device is connected. Note that this state does not identify the Android system has been fully activated and operational in the device during startup device instance can be connected to the adb, but after boot the system before it becomes operational.
No device: no device / emulator connection.

Automate android using python

I am trying to automate android mobile using python's pure-python-adb package but when I run the following code:
from ppadb.client import Client as AdbClient
# Default is "127.0.0.1" and 5037
client = AdbClient(host="127.0.0.1", port=5037)
print(client.version())
I get error in Pycharm as:
RuntimeError: ERROR: connecting to 127.0.0.1:5037 [WinError 10061] No connection could be made because the target machine actively refused it.
Is adb running on your computer?
Please can anyone help me with it
Switch on developer mode in your phone and connect it to your laptop using a physical data transfer (or changing) cable.
REMEMBER: Switch on 'USB debugging' on your phone.
Then go to cmd terminal and make sure you have adb requirements from android studio installed. Once that's there, go to terminal and type.
adb devices
if your phone shows up, you should be connected. You can then type
adb shell
or:
adb connect tcpip 5555
to connect over the internet

: cannot connect to X server python cv2

When I am using cv2.imshow() while running SLIC, I get the below error.
: cannot connect to X server
I am running this program on a remote machine with GPU access. I have seen this answer and a few other related answers but none of them solve my issue. Can you suggest on how to proceed with this.
This helped me :
In your python script add these lines :
import os
os.environ['DISPLAY'] = ':0'
This problem means that your code is trying (and failing) to connect to an X server -- a GUI environment -- presumably being forwarded over your SSH session.
You have to allow the root user access to the X Server which some remote machines wont allow. Try this
xhost local:root
sudo DISPLAY=$DISPLAY gedit /etc/profile

How to remote debug in PyCharm

The issue I'm facing right now:
I deploy Python code on a remote host via SSH
the scripts are passed some arguments and must be ran by a specific user
the PyCharm run/debug configuration that I create connects through SSH via a different user (can't connect with the user that actually runs the scripts)
I want to remote debug this code via PyCharm...I managed to do all configuration, I just get permission errors.
Are there any ways on how I can run/debug the scripts as a specific user (like sudo su - user)?
I've read about specifying some Python Interpeter options in PyCharm's remote/debug configuration, but didn't manage to get a working solution.
If you want an easy and more flexible way to get into the PyCharm debugger, rather than necessarily having a one-click "play" button in PyCharm, you can use the debug server functionality. I've used this in situations where running some Python code isn't as simple as running python ....
See the Remote debug with a Python Debug Server docs for more details, but here's a rough summary of how it works:
Upload & install remote debugging helper egg on your server (On OSX, these are found under /Applications/PyCharm.app/Contents/debug-eggs)
Setup remote debug server run configuration: click on the drop-down run configuration menu, select Edit configurations..., hit the + button, choose Python remote debug.
The details entered here (somewhat confusingly) tell the remote server running the Python script how to connect to your laptop's PyCharm instance.
set Local host name to your laptop's IP address
set port to any free port that you can use on your laptop (e.g. 8888)
Now follow the remaining instructions in that dialog box: copy-paste the import and pydevd.settrace(...) statements into your code, specifically where you want your code to "hit a breakpoint". This is basically the PyCharm equivalent of import pdb; pdb.set_trace(). Make sure the changed code is sync'ed to your server.
Hit the bug button (next to play; this starts the PyCharm debug server), and run your Python script just like you'd normally do, under whatever user, environment etc. When the breakpoint is hit, PyCharm should drop into debug mode.
I have this (finally) working with ssh RemoteForward open, like so:
ssh -R 5678:localhost:5678 user#<remotehost>
Then start the script in this ssh session. The python script host must connect to localhost:5678 and of course your local pycharm debugger must listen to 5678
(or whatever port you choose)

Pygame.display.init() error: "No available video device", on VPS Server

I'm trying to run a pygame script on a vps server, and I'm receiving an error on the pygame.display.init().
Following the directions found here http://www.pygame.org/docs/ref/display.html#pygame.display.init and in other sources, I used all this configurations before the init():
os.environ["​​SDL_VIDEODRIVER"]="dummy"
os.environ["SDL_VIDEODRIVER"]="x11"
os.environ["SDL_VIDEODRIVER"]="dga"
os.environ["SDL_VIDEODRIVER"]="fbcon"
os.environ["SDL_VIDEODRIVER"]="directfb"
os.environ["SDL_VIDEODRIVER"]="ggi"
os.environ["SDL_VIDEODRIVER"]="vgl"
os.environ["SDL_VIDEODRIVER"]="svgalib"
os.environ["SDL_VIDEODRIVER"]="aalib"
So, the "dummy" option causes the script to go into a loop. Any other option give me the error:
<class 'pygame.error'>: No available video device
I have x11 installed. I'm calling the python script from a php file, so, I would expect the graphic output to go inside the browser, or, the "video device" to be set automatically as the user browser. Not happening.
Are you ssh'd into the vps server? Have you tried x forwarding, ssh -X user#server.com then when you run the script from the command line it should open on your window

Categories