[Android Head-Units] rigattoni:
Device needs to be rooted!

This does not work with apps from the supplier as radio, phone, player, video etc. These are nearly all included in the com.car.ui and I did not yet find a way to get them "catched".... may be there is another way... Would be nice if someone could point it to me.

Target of this script with Tasker:

I just wanted to reduce touch screen using while driving.

To start may be a player with a click on a button is one thing, but I may don´t want to stay in this app.

In this case I need to click the Home button and choose another app. On a head unit without hardware buttons sometimes hard to get the home button clicked.

But If I need to play around with the settings of the app, I don´t want to get rejected to the home screen during changing the app settings....

So the target was to create a task which:

Moves the app to background after a short time

To not move the app to background while touching the screen

To move the app to background if there is no touch within a predefined time.

I found a way to get back to the home screen if I opened a player (in this case DAB-Z from realzoulou) by using shell commands.

Example:

DAB_RETURN (3)
A1: Variable Clear [ Name:%Touch Pattern Matching:eek:ff Local Variables Only:eek:ff ]
A2: Wait [ MS:100 Seconds:0 Minutes:0 Hours:0 Days:0 ]
A3: Variable Clear [ Name:%Dab Pattern Matching:eek:ff Local Variables Only:eek:ff ]
A4: Wait [ MS:0 Seconds:5 Minutes:0 Hours:0 Days:0 ]
A5: Run Shell [ Command:cat /proc/$(pidof -s com.zoulou.dab)/oom_adj Timeout (Seconds):0 Use Root:eek:n Store Output In:%Dab Store Errors In:%Dab_false Store Result In: Continue Task After Error:eek:n ]
A6: Wait [ MS:100 Seconds:0 Minutes:0 Hours:0 Days:0 ]
A7: Run Shell [ Command:getevent -c 1 /dev/input/event1 Timeout (Seconds):5 Use Root:eek:n Store Output In:%Touch Store Errors In:%Touch_false Store Result In: Continue Task After Error:eek:n ]
A8: If [ %Touch Set ]
A9: Goto [ Type:Action Number Number:1 Label: ]
A10: Else
A11: Run Shell [ Command:cat /proc/$(pidof -s com.zoulou.dab)/oom_adj Timeout (Seconds):0 Use Root:eek:n Store Output In:%Dab Store Errors In:%Dab_false Store Result In: Continue Task After Error:eek:n ]
A12: Wait [ MS:100 Seconds:0 Minutes:0 Hours:0 Days:0 ]
A13: If [ %Dab !~ 3 ]
A14: Go Home [ Page:1 ]
A15: Else
A16: End If
A17: End If

To use it for other apps you need to find the package name by using the shell:

Open ADB on your PC, connect to your Android in the same WiFi by:

adb connect [IP-Addresse]

adb shell

top (this command does not stop. You need to press "q" on your keyboard to stop it)

The output shows all running apps on your device. You need to search for the app name you want to use with this script.

cat /proc/$(pidof -s [app-name])/oom_adj

For DAB-Z it is:

cat /proc/$(pidof -s com.zoulou.dab)/oom_adj

This command returns the status of DAB-Z:

1 = App in foreground

0= App not running, or in background

Other apps can show different states. You need to find the status by using your PC for each app you want to get managed by this task.

The shell command:

getevent -c 1 /dev/input/event1

fetches touch events on the screen....

and waits in my script 5 sec, stores a touch in %Dab and keeps it empty if there was no touch on the screen.

If you touch it, the variable will be filled with a "0" (zero), otherwise the shell throws an exception which is the trigger to go back to the home screen.

Have fun with it.