Inject touch events android - android

I've been playing around with adb and adb shell input <some input> for the last few hours (building funny little batch scripts that can basically controll my phone.
Since I cannot execute these commands on the device itself without a PC with ADB and I don't want to root my phone I have been looking for an alternative on how to automate user input on the device.
I found a great Tutorial here, however it states that I need a system level permission in order to inject input events into other apps.
Again, I don't want to root my phone and I want the app to be compatible with different devices, so I can't sign it with the platform-key.
Beginning to think it was impossible, I remembered an app that could do such a thing. The anti virus app CM Security is capable of starting the chrome browser and clearing the browser data.
I assume this is done with input injection, but I am not sure about it.

Related

Android Management API - boot device when power is conncted

So, as the title describes, I'm looking for a way to boot an Android device when the power charger is connected. We are making dedicated devices, in kiosk mode, and are using the Android Management API to setup everything on the device.
This covers most of our requirements, like preinstalling apps, disabling everything else, hooking it up to Managed Google Play, getting device reports etc... But for this power thing, I can't find any solutions in the docs.
The problem is that the physical power button isn't accessible to the user (don't ask my why :)), and when the battery drains they have to be able to power it up again, without unscrewing the case to get to the physical button.
I know this can be done in different ways, but I can't find anything that would work with Android Management API. I'm looking at this "fastboot" approach, since it seems pretty simple https://source.android.com/devices/bootloader/unlock-trusty#off-mode-charging
Initially, I though I could run this somehow using the devices/issueCommand endpoint https://developers.google.com/android/management/reference/rest/v1/enterprises.devices/issueCommand, but that seems to support only some predefined commands like: LOCK, RESET_PASSWORD and REBOOT.
Maybe I'm just missing something. If someone has another approach in mind, please share.
If it's any help, we also have the Android Management API hooked up to the PubSub API, and a topic there that the pulls the reports of the devices. Theoretically, I could listed to the "power connected" event there, and run some command on the device. But again, the problem is how to run this command on the device remotely.
Maybe a solution would be to make another app that will run as a background process that runs this command. I guess I would need to add it as "receiverActivity" in the policy. But the same problem remains... how to invoke this activity from the Android Management API.
The bottom line is that this needs to be fully automated. Running this command on each device manually is not an option.
Also, worth mentioning, this is an Ionic app. Although it's probably not impossible, we would like to keep this logic outside of the app itself. Ideal solution would be just to run some adb command remotely using the Android Management API.
Or maybe there is a good 3rd party app that does this, and I could install that app in the policy and invoke it somehow.
All suggestions are welcome. Maybe there is a simple solution that I've missed.
UPDATE AFTER COMMENTS: I'm not looking how the actual app can do this. I'm looking for a way to execute some "native" command when the device is initially setup from the Android Management API policy. So it should execute only once. When it sets up everything initially. It should edit some file on the device (or run some command) to enable this feature. Later, it shouldn't care if the device is turned on or not, or what apps are running on it. There are a few different ways how to do this suggested here https://android.stackexchange.com/questions/20021/automatically-power-on-android-when-the-charger-is-connected. I'm looking for a way to trigger one of these commands when the device is setup initially (only once). In other words, this should execute only when the device is enrolled. It shouldn't care about any apps running on the device.
So the "free" way to do this is using the fastboot commands. But from the AMA API this is currently not (and most likely ever) possible. This problem will always be hardware specific, since the bootloader is controlling the boot process, and the bootloader is custom made for each device.
There are options for different manufacturers though. Look into OEMConfig apps (which you can get in the Play Store for Work or from the manufacturer themselves).
Samsung has it's KNOX API, and the paid ProKiosk mode supports controlling Power Control.
Regarding the post in your question solving the problem, you will not be able to modify any files in the system since that's restricted to root. This will also never work for Managed Devices.
You could "half-automate" the process by setting up a raspberry pi or some other device with a script that waits for fastboot devices to get connected and executing the command. That way you just visit every device and put it into fastboot and plug in the device and you're off to the next one.
For clarification: adb and fastboot are two entirely different things. Fastboot is running while the device is in it's bootloader. Adb is running while the device has started android. It should technically be not possible to execute fastboot commands while android is started since the bootloader has already exited.

Is it possible to control Android bluetooth device pairing via adb?

I'm looking into automating certain Bluetooth activities via adb.
I have been able to successfully enable and disable Bluetooth using information found here:
android enable disable bluetooth via command line
but need more capabilities and control than just enable/disable.
While looking for solutions I came across this post:
Need ADB command line to start a youtube video using browser
where chrome is controlled via intents/activities.
I've attempted a similar solution with Bluetooth by unpacking (using apktool) the Settings apk and the bluetooth apk, looking at their AndroidManifest.xml files for a list of their intents and activities - then using those intents and activities via adb,
e.g. (running shell as superuser)
am start -n "com.android.settings.bluetooth.RequestPermissionActivity/android.bluetooth.adapter.action.REQUEST_DISCOVERABLE"
Thus far, commands of this nature have either:
1) Failed outright, "unable to resolve intent" or similar issues
2) Led to a ">" prompt wherein I'm expected to give more input (though I'm not sure what I would enter there)
Ultimately, I'm seeking to control BT connections using adb (so as to be able to automate those tasks via scripts in the future).
I am using a Google Pixel 2 (rooted).
If I am on the right track, any guidance or advice would be appreciated.
If I'm going about this completely wrong, feel free to let me know (and hopefully let me know where I should be looking instead).

Connect to RS232 from Android - No permission dialog or shell command

Objective
I'm developing a custom app for internal use on a rooted android mini-pc.
The goal (between others... so...many...others...) is to be able to turn on and off a tv using the serial port embeeded on the tv.
I'm using an FTDI UART RS232 serial usb cable for it.
Status
The application is working right now, using an android library (serial-driver) i can communicate with the tv, but the problem is that the device asks for permissions every install (and sometimes, weirdly, again on the same device), so it needs to be improved.
Issue
Since the device doesn't have mouse or keyboard by default, when this happens someone has to click the buttons, and since the device is normally hidden behind the screen, it can be really annoying.
My two bits
This problem, i feel, can be solved by two methods, but i still haven't been able to make them work.
Since the device is rooted, i might be able to modify an unknown (to me) parameter that allows me to bypass the permission request. For this i have tried to make an intent filter for the usb device, and to rewrite the interface that controlls this behaviour, both without success. Is there a way to make this android version more lenient about permissions?
I use for other reasons SuperSU inside the app, so i can use the full width of the might shell power. Using this i've been trying to send commands manually to the device (/dev/bus/usb/00X/00Y), but this haven't worked. My theory is that it's beacuse of the permissions of the device path, but even doing an unhealthy chmod 777 i cannot have them working.
So, that's my problem right now. I hope someone here can help me.
Additional data
Running: Custom Android 4.4.2 (Cannot be changed)
Needs to be doable solely from within the apk (but it can use shell commands)
We don't have the manufacturer signature to install it as a system app
We can use only one app, so i cannot have another one to move this one to /sys/apps, and i don't know if an app can do that to itself.
using Busybox stty -F /dev/.../ returns "Operation not permitted"

Unlock patterns using adb sendevent in Android

After checking some answers:
Is there a way to unlock android phone via adb, if I KNOW the pattern and
Unlock Screen Galaxy Nexus ADB
Im trying to unlock a pattern using adb commands using this script https://github.com/mattwilson1024/android-pattern-unlock/blob/master/unlock.sh (for automation purpose).
Unfortunately the events arent working but I noticed that if I turn on the screen by myself (without using adb shell input keyevent 26) while the script is running, the events work and the pattern unlock.
Could someone explain me why this is happening and if there is another way to unlock patterns? maybe without using events (like I wrote before is for automation purpose, not for a phone that was locked).
Can you please try following capabilities in your code?
We can use capabilities, where we can directly set the unlockType and unlockKey..
unlockType: ['pin', 'password', 'pattern', 'fingerprint']
unlockKey; If you want to draw suppose 'L', then it would be 1478 in key section.
Let me know if this doesn't work.
Appium version - 1.6.4
Reference - https://github.com/appium/appium-android-driver/blob/master/docs/UNLOCK.md
This feature is available in latest appium release.
If you, for some reason, need to use Matt Wilson's script, this is not going to help you, but if your goal is to unlock your phone with a pattern lock via your computer, try Vysor, a Chrome extension that displays your phone's screen (including the lock screen) on your computer, allowing you to enter your lock pattern using the mouse or (if you have a touch display) your finger. For me, it worked fine, as I explain in more detail here.

Android debugging via Bluetooth

I was using earlier adb to debug Android applications over wifi, usb - it was great.
Right now I am wondering if it is possible to connect phone with adb via bluetooth.
I did a quick research but didn't find anything - have you tried it already ?
It is not supported by the current adb software, however you could probably make it possible if you have a rooted device (or possibly even if not - see below) either by modifying adb or by using bluetooth to tunnel a channel it does support, such as tcp.
You would need to obtain the source for the adb program - the same source is used to build both the PC and the device versions. First step is to just build it with unmodified functionality, which may take a fair amount of build system modification unless you do so as a part of a complete android source build (the way it was intended to be done)
Then you would modify it to add a bluetooth channel as an option and install it on the device (why you need root) and in your path on the PC. You'd think you could run it from an alternate location on the PC, and you likely can as long as you use it from the command line, but if your fire up DDMS it may kill off the running adb server and launch a new one using the default in the path, so ultimately you'll have to put your modified version there.
IF you can already get your device to accept adb connections over tcp (possible with root, perhaps possible in some cases without) there is another option, which is to not modify ADB (or at least not modify the device side) and instead come up with something running on the device which accepts bluetooth connections and forwards the traffic via local loopback to the tcp port on which the stock adb is operating. This would save the trouble of having to rebuild adb.
If you have some kind of tethering or similar network-over-bluetooth solution, you might even be able to leverage that to carry adb-over-tcp-over-bluetooth without writing any code.
Finally note that it is not 100% essential that the adb daemon run as a more privileged userid or be installed in place of the official one - you can run an adb daemon as an ordinary application and do many of the expected things with it. However, whichever adb daemon is running first will grab the unix domain java debug socket, and so only that adb daemon will be able to provide the full java debug services. More primitive things like logcat, shell, running process list, push/pull, etc will at least partially work without this, provided that your adb daemon doesn't quit (modification may be required) when it is unable to claim the debug socket. If you can kill the official adb daemon and exploit a race condition, you may be able to get an unofficial one started before it restarts - you would probably need to have a script or program to do this and run it with setsid from the official adb shell, meaning you'd need to connect via USB first. At that point, you'd also be able to start your unofficial adb daemon running as the same userid as the official one.
You may want to spend some time estimating or testing if the performance (speed) will be satisfactory before investing in a lot of time setting this up for real.
I know this is a bit old but I seem to have found a post that does this. All credit goes to the author of fomori.org for finding this and making the information available. Today it helped me, maybe tomorrow I'll help you by making it easier to find.
Source

Categories

Resources