Support multiple users

228 views
Skip to first unread message

metat...@gmail.com

unread,
Sep 13, 2015, 3:29:50 PM9/13/15
to Automate
Hello,

I started to use Automate and I find it very powerful yet easier to configure than some well-known alternatives...

I found one small incompatibility with the way my tablet is configured.
Since Android 5.x it is possible to define secondary users ("full, "restricted", or "guest").
I would like to create an Automate flow that performs an action, only if the user currently using the device is the "primary" user and a specific notification exists for this user.
The flow can run also in the background, when the secondary user is using the device.

When I use the "Notification posted ?" block, it works good as long as I stay connected under the same user.
When I switch to second user, the execution stops at this block with a "java.lang.IllegalStateException".
This exception is only transient, because when I log in again as the primary user, this exception is not generated anymore.
However, Automate seems to consider this exception as fatal and automatically disables the "Enable notification access" permission, and also stops the flow.
I need to re-add the permission again everytime that I switch users.

Also, it would be great to create flows based on the event generated when a user switch happens (Intent.ACTION_USER_BACKGROUND).

Is there a way to support this multiple users configuration ?

Thanks in advance,
Best regards,

metatech

Automate developer

unread,
Sep 13, 2015, 8:42:01 PM9/13/15
to Automate
Hardly any API in Android support multiple users, so i can't control as which user a notification is posted, for example.
Please user the Help & feedback menu to send me a system log after you've gotten the java.lang.
IllegalStateException.

Use the Broadcast receive block to await a ACTION_USER_BACKGROUND broadcast.

metat...@gmail.com

unread,
Sep 14, 2015, 3:30:42 PM9/14/15
to Automate
Thanks for your quick reply.

Here is the full stack trace (see below).

Also, I found a solution thanks to the "user background" and "user foreground" intents : I created 2 secondary flows :
- one which is triggered by the "background" event and which stops my main flow
- one which is triggered by the "foreground" event which starts my main flow.

Up to now, this works fine.

Thanks for your help !

metatech

E/AutomateService( 5505): onExecuteFailure
E/AutomateService( 5505): java.lang.IllegalStateException: Notification service not running
E/AutomateService( 5505):     at com.llamalab.automate.stmt.NotificationPosted.a(Unknown Source)
E/AutomateService( 5505):     at com.llamalab.automate.stmt.NotificationPosted.b(Unknown Source)
E/AutomateService( 5505):     at com.llamalab.automate.AutomateService.b(Unknown Source)
E/AutomateService( 5505):     at com.llamalab.automate.AutomateService.e(Unknown Source)
E/AutomateService( 5505):     at com.llamalab.automate.AutomateService.handleMessage(Unknown Source)
E/AutomateService( 5505):     at android.os.Handler.dispatchMessage(Handler.java:98)
E/AutomateService( 5505):     at com.llamalab.android.os.i.dispatchMessage(Unknown Source)
E/AutomateService( 5505):     at android.os.Looper.loop(Looper.java:145)
E/AutomateService( 5505):     at com.llamalab.android.os.f.run(Unknown Source)

Automate developer

unread,
Sep 14, 2015, 5:31:54 PM9/14/15
to Automate
Did you have the notification service running for both users?

metat...@gmail.com

unread,
Sep 15, 2015, 3:59:44 PM9/15/15
to Automate
Hi,

Yes the notification service is running for each user, but from the exception, I understand that the notification service is stopped when a user goes into background.

Also, in the "foreground" event, I had to add a delay of 2 seconds, otherwise the notification service was not restarted yet, and I was also receiving the IllegalStateException in the "Has notification" block

I had a similar problem with the "App in foreground" block : when the user goes into background, I receive an exception "java.lang.IllegalStateException : Accessibility service not running".

I understand very well that the "user switching" feature of Android 5 is only integrated superficially into the API, and that any application can face those kind of difficulties.

Maybe Automate itself (not flows created with it) could register to receive "user foreground" and "user background" events, and ignore the IllegalStateException received by a flow when the user is in the background ?

Regards,

metatech

metatech

Automate developer

unread,
Sep 15, 2015, 8:56:39 PM9/15/15
to Automate
Yes, i've also noticed that the notification and accessibility services may not have full started before the Automate service. It's a bug i've got to fix.

metat...@gmail.com

unread,
Sep 26, 2015, 11:11:52 AM9/26/15
to Automate
Hello,

After some long investigation, I found out that the "IllegalStateException" is only due to a bug in the Samsung Android official ROM for this tablet.
I configured another application ("Notification history"), which also has the "notification access" permission.
When the IllegalStateException occurs (in about 30% of cases), both applications have lost their "notification access" permission in the Android UI.
I assume that this setting cannot be changed programmatically in the application itself, and the system UI has to be used.
It is hard to tell whether all the IllegalStateException are caused by the Samsung Android, or whether some special care has be taken during a "user switch".

Regards,

metatech

Automate developer

unread,
Sep 26, 2015, 1:17:36 PM9/26/15
to Automate
Thanks for the investigation.
I'll try to implement some delayed retry strategy, so Automate will wait for the notification service to start.
Apps can't enable notification services, user interaction is required. Maybe with root, but that wouldn't be useful for blocks that doesn't otherwise need it.
Reply all
Reply to author
Forward
0 new messages