SmartUnlock

Share and discuss your flows and ideas with other users.

Moderator: Martin

valzi
Posts: 10
Joined: 07 Jul 2016 19:00

Re: SmartUnlock

Post by valzi » 21 Aug 2016 21:43

Thank you! Just checking in.

User avatar
heilong
Posts: 77
Joined: 18 Oct 2016 15:20

Re: SmartUnlock

Post by heilong » 29 Oct 2016 20:42

Used to use Delayed Lock app. Your flow blows it out of the water,works great and so many useful options!
I just started using Automagic and didn't know it could be used to create such capable flows, feels like an entire app.
Thanks, you're a genius!

What would be the best way to hook up some custom flows to execute when SmartUnlock locks/unlocks the device?
E.g. when device is unlocked, I'd like to see all notification content (including sensitive) on the lock screen, but when it's locked, I'd like to hide the sensitive notification content. This is accomplished (I'm using CM13) by set system settings: lock_screen_allow_private_notifications to 1 or 0.

I'm trying to create a flow which uses global variable global_SmartUnlock_locked as a trigger, then set the system setting to 1 or 0 if global_SmartUnlock_locked is false or true respectively. But for some reason my flow doesn't get executed when I lock/unlock.

Another question is: if I want to disable lockscreen altogether while in the car, what would be the best way to do this?

User avatar
heilong
Posts: 77
Joined: 18 Oct 2016 15:20

Re: SmartUnlock

Post by heilong » 29 Oct 2016 22:50

My initial happiness didn't last for very long - phone freezes for ~10 seconds when I unlock the screen (whether it was actually PIN-locked or not).
I'm using CM13, full disk encryption is enabled. If I manually change my PIN in system settings, the phone also freezes for ~10 seconds, so I think the cause is the same. I think the device encryption keys get re-encrypted when the PIN is changed, blocking all I/O until done (my theory).
Just manually executing SmartUnlock_unlockDevice results in a 10-second freezing as well.

For now I've setup a "Trusted" CM profile - all settings unchanged, except lockscreen: "Don't ask for PIN or Password" (there's also "Disable lockscreen" available, removing even the Slide lock). I modified SmartUnlock_setPin and SmartUnlock_unlockDevice to set respectively Default and Trusted CM profiles. It works but seems like overkill since I'm not using any other features of CM profiles - and can't use other profiles since now my modified SmartUnlock depends on them.

Any ideas?

User avatar
kintrupf
Posts: 257
Joined: 10 Sep 2013 08:59

Re: SmartUnlock

Post by kintrupf » 02 Nov 2016 20:32

heilong wrote:Used to use Delayed Lock app. Your flow blows it out of the water,works great and so many useful options!
I just started using Automagic and didn't know it could be used to create such capable flows, feels like an entire app.
Thanks, you're a genius!
Thank you very much for your praise 8-)
heilong wrote:What would be the best way to hook up some custom flows to execute when SmartUnlock locks/unlocks the device?
I'm trying to create a flow which uses global variable global_SmartUnlock_locked as a trigger, then set the system setting to 1 or 0 if global_SmartUnlock_locked is false or true respectively. But for some reason my flow doesn't get executed when I lock/unlock.
Right now this is difficult without modifying the flows itself. The global variable global_SmartUnlock_locked wont work because it's a remnant of a previous version and is no longer set or cleared when the phone is locked or unlocked.
You would need to check if the the map variable global_SmartUnlock_trustedStates is empty to determine if the phone should be locked. Unfortunately, changes to the contents of a map variable do not trigger a Global Variable trigger, so there is no easy way to keep track of changes.
For some time now I plan to update SmartUnlock with some features, having a simple global variable for the status (which can be triggered) will be among them.
heilong wrote:Another question is: if I want to disable lockscreen altogether while in the car, what would be the best way to do this?
That would depend on how you would identify your car. If you connect to your car via Bluetooth use a Bluetooth device connected trigger. I also had some success with a User activity trigger.

User avatar
kintrupf
Posts: 257
Joined: 10 Sep 2013 08:59

Re: SmartUnlock

Post by kintrupf » 02 Nov 2016 20:47

heilong wrote:My initial happiness didn't last for very long - phone freezes for ~10 seconds when I unlock the screen (whether it was actually PIN-locked or not).
I'm using CM13, full disk encryption is enabled. If I manually change my PIN in system settings, the phone also freezes for ~10 seconds, so I think the cause is the same. I think the device encryption keys get re-encrypted when the PIN is changed, blocking all I/O until done (my theory).
Just manually executing SmartUnlock_unlockDevice results in a 10-second freezing as well.

For now I've setup a "Trusted" CM profile - all settings unchanged, except lockscreen: "Don't ask for PIN or Password" (there's also "Disable lockscreen" available, removing even the Slide lock). I modified SmartUnlock_setPin and SmartUnlock_unlockDevice to set respectively Default and Trusted CM profiles. It works but seems like overkill since I'm not using any other features of CM profiles - and can't use other profiles since now my modified SmartUnlock depends on them.

Any ideas?
Although I have a tablet running CM13, I do not use device encryption, so I can't check anything. But since you say that setting the PIN in the system settings also results in a 10 second delay it seems indeed to be a system problem or "feature".

It may seem to be overkill to use an entire CM profile for locked or unlocked, but if it works, why not?
I see no other way around it since there are is no action "disable PIN but keep current PIN for later" ;)

There are other possible benefits for using CM profiles like changing to a different wallpaper when the phone is locked and something like that.
To make things easier I can add direct support for CM profiles, so that you won't need to edit the flows directly.

User avatar
heilong
Posts: 77
Joined: 18 Oct 2016 15:20

Re: SmartUnlock

Post by heilong » 04 Nov 2016 12:57

Thanks for your replies.
I don't have/need a car at the moment, so my interest is purely theoretical for now. If I buy a car I will for sure use Bluetooth.

I think the slowdown when changing the PIN is a "feature" indeed, or rather an unavoidable security-related nuisance.
I feel OK about devoting entire CM profile system to be SmartUnlock's "back-end". CM profiles are better than nothing, but their functionality is still quite limited, compared to what can be done with Automagic. I think the trust agent is the only feature they have that Automagic can't exactly match.

I've done a few more modifications now, to the point I'm quite satisfied with the result.
- 3 CM profiles: SecureLock (default LockScreen settings), InsecureLock (don't ask for PIN/Password) = swipe lockscreen, NoLock (disable keyguard)
- global_SmartUnlock_unlockedLockType controls whether InsecureLock or NoLock profile will be used when lock is disabled
- Added "Disable swipe lock"/"Enable swipe lock" entry to the SmartUnlock settings dialog, which toggled between InsecureLock and NoLock
- Lock/unlock logic handled by SmartUnlock_lockDevice and SmartUnlock_unlockDevice
- Update global_SmartUnlock_locked variable to reflect the current state
- SmartUnlock_updateLock does the actual switching of the CM profile based on global_SmartUnlock_locked and global_SmartUnlock_unlockedLockType. it is called manually when needed (maybe add listening to global variable changes, for now I prefer manual control)
- SmartUnlock_updateLock also modifies some lockscreen-related system settings, depending on profile. E.g. in InsecureLock, sensitive notifications, status bar and power menu are available on the (swipe) lock screen, but in SecureLock they are disabled.
- Listen to CM profile change broadcasts and display a warning notification in the status bar if the current profile doesn't match one set by SmartUnlock (in case user or another app accidentally change the CM profile)
- Added SmartUnlock_Trigger_Shutdown and extra actions to SmartUnlock_Trigger_Startup to try to ensure that on reboot the device is locked and all lockscreen-related system settings are set to safe values

- Fixed some minor typos (e.g. "tab to unlock" should be "tap to unlock"; the "lock after timeout" notification says "tap to unlock" but it actually locks)
- Fixed SmartUnlock_Trigger_WiFi condition "ssid == null" (or else sleep), it should be "ssid != null" (as other Triggers)
- Removed "Lock" button from the notification since tapping the notification itself does the same. Otherwise, the other actions become "MANU..." and "SETTI...", which bothered me.
- Modified the notification text to my liking
- Modified the notification trigger to: lock device if not locked, unlock and add "manual" trusted state if locked (activated by double-tapping the notification on the lockscreen, then entering PIN).
- When testing, if I unlocked/lock too many times in a minute, sometimes Automagic would Emergency Stop and disable SmartUnlock_checkNotification, which executed too many actions per minute. Increased limit from 60 to 120 actions per minute for this flow.

TODO/questions:
- Audit for race conditions, change some flows' options to disable parallel execution?
- Does SmartUnlock_Trigger_Timeout reliably fire when using Aggressive Doze (Greenify)? Maybe the phone goes to doze mode and the trigger is missed. Enable "Trigger immediately on missed events" and/or "Allow in device idle/doze" trigger options?

I'm attaching my flows in case you'd like to take a look on your CM-powered tablet. It might be in wrong state after initially imported, if so, try executing SmartUnlock_lockDevice first. Like I said, 3 CM profiles called SecureLock, InsecureLock, NoLock are expected. Mine don't modify any settings besides the lock screen option - Default, Don't ask for PIN/Password, Disable keyguard respectively.

By the way, what exactly is gracePeriod sleeping for, 5 seconds is good value?
Attachments
SmartUnlock-CM.xml
(209.16 KiB) Downloaded 1287 times

User avatar
heilong
Posts: 77
Joined: 18 Oct 2016 15:20

Re: SmartUnlock

Post by heilong » 04 Nov 2016 13:10

I still sometimes find my phone locked itself. At first I was using my home's WiFi as the only trusted state. But for some reason (even with stock ROM after factory reset) with WiFi enabled my phone would stay awake all the time, unless "keep WiFi on during sleep" is set to "only when plugged in". So since I use this option, WiFi automatically disconnects when phone is unplugged and sleeping - this locks it.
I enabled Location as available trusted state, and added my exact location. But - sometimes it still locks anyway, and sometimes I go out (definitely over 500 m away) and many times I checked and the phone was still unlocked (maybe location trigger doesn't fire since I'm using "Aggressive Doze"?). Anyway location is really not that accurate, and having to set 500 m radius to compensate feels quite insecure. What if I lose my phone / it is stolen when I take a family walk walk close to the house?
Besides using a BT device (I don't have any that I use all the time), any ideas about how my situation could be improved?
I wonder if there's a way to distinguish WiFi disconnect because of power saving from WiFi disconnect because the AP is now out of reach. Maybe start a timeout on WiFi disconnect, and check if the AP is still around, if so - don't remove from trusted states. But afraid it might be not reliable and/or not secure.

saqwarrior
Posts: 1
Joined: 16 Mar 2018 17:20

Re: SmartUnlock

Post by saqwarrior » 20 Mar 2018 16:27

Am I correct in my assumption that this flow no longer works? I downloaded it and set it up but it just gives me the error message from Automagic about PIN disabling not being supported on Android 7+.

User avatar
heilong
Posts: 77
Joined: 18 Oct 2016 15:20

Re: SmartUnlock

Post by heilong » 20 Mar 2018 20:09

Well I'm still using Android 6 and it works on Android 6 :)

User avatar
Autumn-Leigh
Posts: 67
Joined: 15 Mar 2018 19:23
Location: UK
Contact:

Re: SmartUnlock

Post by Autumn-Leigh » 23 Mar 2018 13:59

May i ask if this works with Wifi Near please? or as automagic has it "wifi available"
YouTube Channel - https://youtu.be/fui3RO9EmNU
If anyone wants a shoutout, or has a flow they want me to do, be it theirs or a new one, let me know :)

Post Reply