In this article we cover how to use Termux in combination with Rish to get extended properties about a package such as the last visible package, is a specific package visible; this could be use to trigger additional actions from Tasker when the running state chanages.
Table of Contents
Required: If you haven’t already configured Shizuku (Rish) with Termux there is a guide available at: Termux, Shizuku and Rish configuration for Android 14
Rish variants for ADB commands
Note the following table assume that you have installed Rish within Termux at path: /data/data/com.termux/files/usr/bin/rish_auto
if you have installed Rish with a different Shell or path ensure you update it here.
In the example below replace: <package-name>
with the desired package you are targeting.
Description | Command | Example results |
---|---|---|
Is package in the foreground/background or not running | rish_auto -c "dumpsys activity activities | grep -A 40 'packageName=<package-name>'" | grep nowVisible= | tr -s ' ' | cut -d' ' -f2 | cut -d'=' -f2 | Returns empty if app is not running. True if in the foreground. False if in background. |
Remove a system app from the battery optimisation whitelist | rish_auto -c "dumpsys deviceidle sys-whitelist - | |
Remove a system app from the battery optimisation whitelist | rish_auto -c "dumpsys deviceidle sys-whitelist + | |
Remove a user app from battery optimisations whitelist | rish_auto -c "dumpsys deviceidle whitelist - | |
Add a user app to battery optimisations whitelist | rish_auto -c "dumpsys deviceidle whitelist + |
These commands open up the possibility to automate a device beyond typical scenarios using Tasker and Termux. For example triggering a task or specific action when a app is in the foreground or background.