Macrodroid restarting itself.

Alan 643228485

New member
I have a pretty simple macro that triggers when a notification comes in and the device is locked.
It flashes the torch until it sees that the device has been unlocked - no LED on this phone
(it's based on the 'Flash notifications' macro in the templates).

It works fine usually, but if I leave it flashing and the phone is not on charge, MacroDroid restarts itself after about 30 minutes.
It seems to keep running if the phone is plugged in.

It checks for device unlocked every second and flashes the torch every 10 seconds,
In the log file I see this ...

02-09-21 09:29:01 - MacroDroid Initialised
02-09-21 09:28:58 - Wait 1 second
02-09-21 09:28:58 - A: If (Device Unlocked) did not invoke because constraint failed: Device Unlocked (Flash notifications ⚡)
02-09-21 09:28:58 - If (Device Unlocked)
02-09-21 09:28:57 - Wait 1 second
02-09-21 09:28:57 - A: If (Device Unlocked) did not invoke because constraint failed: Device Unlocked (Flash notifications ⚡)
02-09-21 09:28:57 - If (Device Unlocked)
02-09-21 09:28:57 - Torch Off
02-09-21 09:28:57 - Torch On
02-09-21 09:28:56 - Wait 1 second
02-09-21 09:28:56 - A: If (Device Unlocked) did not invoke because constraint failed: Device Unlocked (Flash notifications ⚡)
02-09-21 09:28:56 - If (Device Unlocked)
02-09-21 09:28:55 - Wait 1 second

Any idea why it's doing this?
The phone is a Xiaomi Redmi and I know it has aggressive power management, but I've turned it all off for MacroDroid.

Thanks.
 

Jacob L

Moderator (Lawsonator)
Sounds like Android Doze node kicking in. Follow steps at dontkillmyapp.com and make sure to update MacroDroid as there's lots of bugs fixed in the latest versions. Does it need to check if the device is unlocked every second, does this need to occur at all? Maybe reducing the frequency will help.

Maybe other apps are crashing, to find out you can enable show all ANRs, this will show other apps that are not responding. Also some devices have a performance mode.
 

Alan 643228485

New member
Thanks for the quick reply.

I'm running Adndroid 11 / MIUI 12, I'm not sure that has the doze mode in it specifically?

I hope I have the latest version of MD - 5.16.2

I'd already done pretty much every thing on dontkillmyapp, there were just a couple of 'Other permission' not set but they don't sound like they would cause this. Anyway, I've set them and will give it a try.

The original macro from the template checks for device unlocked every 10 seconds when it flashes the torch.
I found I would 'beat it' by unlocking the phone, checking the screen and locking it again within 10 seconds, so I put in an inner loop that check every second to catch that.
 

MacroDroidDev

Administrator
Staff member
Does this restarting prevent the macro running? The Android OS is always at liberty to kill a service whenever it decides too, the most important thing is that the app restarts correctly when this happens.
 

420

Active member
I have a pretty simple macro that triggers when a notification comes in and the device is locked.
It flashes the torch until it sees that the device has been unlocked - no LED on this phone
(it's based on the 'Flash notifications' macro in the templates).

It works fine usually, but if I leave it flashing and the phone is not on charge, MacroDroid restarts itself after about 30 minutes.
It seems to keep running if the phone is plugged in.

It checks for device unlocked every second and flashes the torch every 10 seconds,
In the log file I see this ...

02-09-21 09:29:01 - MacroDroid Initialised
02-09-21 09:28:58 - Wait 1 second
02-09-21 09:28:58 - A: If (Device Unlocked) did not invoke because constraint failed: Device Unlocked (Flash notifications ⚡)
02-09-21 09:28:58 - If (Device Unlocked)
02-09-21 09:28:57 - Wait 1 second
02-09-21 09:28:57 - A: If (Device Unlocked) did not invoke because constraint failed: Device Unlocked (Flash notifications ⚡)
02-09-21 09:28:57 - If (Device Unlocked)
02-09-21 09:28:57 - Torch Off
02-09-21 09:28:57 - Torch On
02-09-21 09:28:56 - Wait 1 second
02-09-21 09:28:56 - A: If (Device Unlocked) did not invoke because constraint failed: Device Unlocked (Flash notifications ⚡)
02-09-21 09:28:56 - If (Device Unlocked)
02-09-21 09:28:55 - Wait 1 second

Any idea why it's doing this?
The phone is a Xiaomi Redmi and I know it has aggressive power management, but I've turned it all off for MacroDroid.

Thanks.
I would recommend you remove the "checking if device is unlocked every second" , because that really is not neccesary, and instead add a "screen unlocked" trigger and a "cancel macro actions" action.
 

Alan 643228485

New member
I would recommend you remove the "checking if device is unlocked every second" , because that really is not neccesary, and instead add a "screen unlocked" trigger and a "cancel macro actions" action.

Ah - I didn't know that, I'll give it a try.
 

Alan 643228485

New member
Yeah, that's pretty much what I've got (it also checks for battery > 20%)

But you still need the separate macro that catches 'screen unlocked' and stops the loop.
Otherwise it's possible to do [ unlock, view the notification, lock again ] within the 9 seconds wait so the loop doesn't stop.
 

420

Active member
Yeah, that's pretty much what I've got (it also checks for battery > 20%)

But you still need the separate macro that catches 'screen unlocked' and stops the loop.
Otherwise it's possible to do [ unlock, view the notification, lock again ] within the 9 seconds wait so the loop doesn't stop.
Yes sorry you are right, also if you unlock the screen while the macro i shared has just turned the toch on, then the torch off will no longer happen because of the general constraint..

This should work, you can't see it in this screenshot but i removed the general "device locked" constraint.

Screenshot_20210902-181902.png
 

Alan 643228485

New member
I think you need another 'Torch off', just after the 'Cancel macro actions'.
Otherwise you can still leave the torch on if you get the timing wrong.

(Does that work, or does it stop immediately and not carry on?)
 

420

Active member
I think you need another 'Torch off', just after the 'Cancel macro actions'.
Otherwise you can still leave the torch on if you get the timing wrong.

(Does that work, or does it stop immediately and not carry on?)
Hmm... you are right again!

It does work but you will have to place it ABOVE the "cancel macro actions" action, because that action does indeed stop the macro immediately.
 

Alan 643228485

New member
Just thought I'd report back on this, the macro works fine on my phone now, I guess MIUI didn't like it waking up every second to check if the device was unlocked, seems to tolerate the 10 second loop to flash the torch fine.

BUT - it still gets stopped on my partners phone (same model and OS version), but she 'uses' the phone much more than me, is always on messenger or various other apps. I guess MIUI decides it just can't spare the CPU time.

I solved the problem my keeping a 'FlashRunning' global variable updated and catching 'MacroDroid initialised' as a trigger. If the macro was running, it just restarts it. Seems to work fine.

I wonder what causes MacroDroid to get restarted if MIUI stops it, does it detect it and restart itself, or what?
 

MacroDroidDev

Administrator
Staff member
MacroDroid starts it's foreground service with a flag that says please restart me as soon as possible if it gets killed.

One workaround would be to use the macrodroid initialised trigger and have a boolean flag set when it's in the flashing state which can be checked to decide if to do the flashing.
 
Top