Turn device off instead of rebooting as device owner - android

With the Android device owner API it is possible to reboot the device (https://developer.android.com/reference/android/app/admin/DevicePolicyManager.html#reboot(android.content.ComponentName)) which to me is permission wise pretty much the same as shutting the device down.
Still I can't find any mentioning of the possibility to shut down a device programmatically as a device owner. Is that today in any way possible without root?
There are a few old questions discussing this but since then quite a lot has changed in Android, rebooting without root f.e. was not possible back then so I was hoping a full shut down might be possible now as well.

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.

How can i turn on the debugging? ADB if my phone is locked and i forgot the PIN

Im locked out of my phone and there are ways to bypass through ADB, but the ADB is not turned on and i know there should be a way to turn it on somehow.
Recovery the PIN through the FindMyDevice site. Log in select the device then chose to lock it. This will prompt you to enter new details i.e. a password or PIN to unlock the device with. All you should need is the associated Google account.
You most likely should be out of luck unless you got i.e. Device Manager enabled and can control your device from there. If not then maybe you are rooted or at least have bootloader unlocked? If so, then you can install i.e. TWRP and "tweak" your device from there disabling i.e. pattern or pin lock from its terminal. If not, then your chances are getting low, however in similar situation I faced once, I managed to exercise some desing bugs of android and get out of it. But that was years ago, so perhaps this is no longer the case, yet you may want to take a look at this post Unlocking pattern locked network-less LG G-Slate v909

Android App Hangs When Running While Not USB Connected

My Android application runs perfectly normal when connected to the computer. However, when run while USB is disconnected, the application will hang indefinitely.This sounds like a dumb question, but I was wondering if being plugged in gives any kind of advantages that I may be missing. Would threading act differently while connected to a computer?
I had the same problem. And it was caused by application managing in battery optimization (settings->battery->app launch). My application was automatically managed by system, and launch of some features was prevented in the name of saving battery. After switching to "Manage manually", and giving all permissions app is working fine.

Android overheating disconnects from OTG

I'm encountering a very strange problem while developing on android. My project is a bit unorthodox, so please bear with me.
I'm developing a game that uses an external controller that's connected to the phone using an OTG cable. All works OK, until the phone's temperature crosses a certain threshold, In which case the operating system shuts down the communication with the OTG and I'm unable to restart it in any way other then disconnecting the OTG cable, and reconnecting it, which is a process I would really like to avoid.
So my question is does anyone know what part of the operating system is the one performing this action of shutting down the USB input when the device gets overheated, and where can I control\reboot it?
Would very much appreciate your help, as I don't even know where to start looking, just please avoid answers like "just unplug and plug back the otg", or "just make sure your device doesn't overheat"
Much obliged
It's probably a hardware issue. If it's actually implemented in the OS itself, then you should probably look in the kernel code. It's not the standard behavior in all android devices, so you should try using another device.

How to set the Usb connection mode?

I'm writing an application which is supposed to dump data on the SD card and then another application on a pc which should read the data when the device is connected to the pc (in disc drive mode).
On my HTC Legend there is a dialog to choose between: Charge only, HTC Sync, Disk drive..
Is there a possibility to set the mode with which the device is connecting to the pc
or at least an intent to ask the user to switch the mode?
I haven't found a way of setting the mode programmatically, but I believe you can bring up the settings menu programmatically by invoking the same activity that the system invokes from the notification area. Unfortunately this appears to be manufacturer-specific: on my phone it is com.htc.android.psclient.SwitchUsbSettings.
On HTC devices, open the ConnectToPC service (whilst USB is not plugged in) in Manage Apps (ICS - probably applies to Gingerbread too; don't remember), and hit Clear Data. Then, plug the USB back again, and you should have the option to "Don't ask again" available. Select your desired mode, check the box, and accept.
CompanionLink does this when you request a USB sync in their android app: it flushes data to SD, then exports the SD as storage (a "disk drive") on the USB, then waits for the user to manually signal the android app when the PC is finished using the SD, and then undoes the SD export to USB again. Though the CompanionLink app can be very frustrating to use, at least this part of it is (largely) reliable.
Unfortunately I don't know the technical details, may well need to figure them out myself one of these months. If you can't get any traction with android docs, perhaps you could study what CompanionLink does on android to implement this. The sequence I describe above is when it is configured to sync over USB against a (PC-based) Palm Desktop.
As an aside, it appears that the reason for this highly-convoluted process is that the SD card's FS is accessed directly and at least the presently-used card FAT FS can only support a single client: the phone itself or USB. imo it would be extremely helpful if concurrent shared access to the SD were possible, but this would likely require deep android changes.
For anyone having this issue with an HTC One M8, this is a bit off the wall, but makes the point to think outside the box. A USB connection resulted in the device charging, that was it.
The solution was the combination of a different USB cable, uninstalling an application called Battery Doctor (which apparently likes to manage everything around your battery), AND USB Network Setting - turn ON Smart Network Sharing...Seemingly unrelated...but this combination got my connected with MobileGo for Android to manage and back up files,contacts and settings.
Hope this helps someone.
Yes .In Android there is a way to change the behaviour of the devices`s USB mode when the device is connected with the PC.
I used a Motorola Milestone[running 2.1] and i was able to switch between the following modes :
PC Suite[developed by Motorola],MemoryCardAccess and Charge alone.
If you need to access phone memory I think you should turn ON "USB Debugging Mode " in your device.Am not sure about it though,I feel it may be handy !!

Categories

Resources