is there any utility which can make an (non-Play Store, non-rooted) Android device power off after a period of inactivity? my Quest likes to drain battery when not in use and it would be better if it just knew to power down when I don't touch it for a couple of hours

beginning with the main problem of "shutdown from user space”∗, there appears to be no API for this in Android

your only option is to call reboot -p in the shell, which requires either root or ADB access

root is off the table, so, let's have a quick look at ADB - there's a neat tool called Shizuku which effectively (ab)uses the ADB network socket to shell in to the local device with somewhat elevated privileges. it's like a halfway to root solution

via Shizuku, it is possible to call reboot -p from userspace! there are apps which can do this! I can install them on my Quest via F-Droid!

however, Shizuku does not maintain its connection to ADB between reboots without root

meaning that, in my case, where I am looking to use it to automatically shut off the device, it requires manual intervention in order to then be able to do it again on the next boot

so, ADB and reboot -p seem like they need to be shelved

what else is there? well, there's one potential vector, though it feels like it would be fragile; accessibility services

Android lets apps request access to view and control the screen, effectively allowing for screen readers and automation apps in one fell swoop

one application which permits this is AutoInput, which can be plugged into Tasker to automate UI inputs, and indeed, it is seemingly possible with this combination to open the power menu and click the "power off" button

however

this combination of apps cannot be installed on a device which isn't connected to the Google Play Store∗∗, and Meta in their wisdom do not include the Play Store on the Quest

so close and yet so far

∗: The other issue, of course, being detecting when the user hasn't used the device in a while. There don't seem to be any automation apps which can do this specific thing from what I've seen.
∗∗: Tasker can in fact be bought individually if you back the author's Patreon, but AutoInput is not, seemingly, included in that, and the author does not make any means of contact available on their website to ask for a way around that.

long, random ideas! 

@ticky ooh! this is a tricky one. my first thought is pretty messy, but maybe pieces of it might be usable~

so, shizuku uses the same permission as tasker's adb wifi in order to do privileged actions, which means you can actually use tasker to shut down your stuff too! (it's the "restart" action set to "shutdown")

that doesn't get around the reboot permission issue of course--it just means you might need one fewer puzzle piece to get what you're hoping for

as for the adb permission reset on reboot; save for attaching a pi zero to your quest to accept adb connections, i feel like your best bet probably is to find a way to get autoinput, unfortunately (but i could give you the tasker author's email if you wanted to try that!)

that said, if you don't wanna do that, and are okay with possibly a lot of extra work, another option could be to grab a wireless mouse/keyboard app, sniff its traffic, and then just replay it to simulate the input to shut down maybe? if you can't find any of those, vnc servers or other remote access apps may work too

if you grab a capture from one of those, it might literally only be a matter of redirecting the input file into netcat pointed at localhost in termux

if you find you need to manually start something like this on boot, you could start the activity from tasker on boot--or run apktool d --force-manifest on the app apk to extract the manifest xml and see what intents you can use to poke at it to script it to start

if you don't want to need to simulate input for all privileged actions, and just want the adb permission on boot, you could also create a set of inputs to enable adb over wifi in dev settings and to screenshot the qr code it tells you to connect with

if you trigger an action like this with an intent from termux:boot (intents can be sent from termux with "am broadcast --user 0 -a net.dinglish.tasker.enable-adb-plz" or something similar), you can make the script wait for a screenshot to pop up, decode the qr with zbarimg or something similar, and then use that info to establish a local adb connection

that way, you could just use a normal adb command later with termux:tasker when you want to do something more privileged in general (of course, including shutting down without needing to rely on the existence of any external input at all)

that said, this still relies on still finding an app that would let you script/intercept input

if you can't find any of those, while it's only a slight step-up from having a pi zero, an inputstick might also do the trick since you could use it to script keyboard and mouse inputs to be sent through an actual usb input that looks indistinguishable from using the actual hardware, so it would be guaranteed to do anything you could with an actual keyboard and mouse (and as a bonus, they are also just generally useful for keepass2android reasons if you use that on another phone and need to type a 256 character random password into the nintendo switch or something)

· · Web · 0 · 0 · 0
Sign in to participate in the conversation
Awoo Space

Awoo.space is a Mastodon instance where members can rely on a team of moderators to help resolve conflict, and limits federation with other instances using a specific access list to minimize abuse.

While mature content is allowed here, we strongly believe in being able to choose to engage with content on your own terms, so please make sure to put mature and potentially sensitive content behind the CW feature with enough description that people know what it's about.

Before signing up, please read our community guidelines. While it's a very broad swath of topics it covers, please do your best! We believe that as long as you're putting forth genuine effort to limit harm you might cause – even if you haven't read the document – you'll be okay!