by Joseph Vassiloudis
Version 1 (July 24, 2018)
Download (98 downloads)
Simple script that locks the device when the screen is covered with a flip case's cover.
Needs cover with magnetics and rooted device.
If you haven' t rooted your device you can change the Superuser command input keyevent 26 to the simple Lock device action block but that would mean you can't use the fingerprint scanner to unlock your device.
If you don't have a flip cover with magnetics you can remove the sensor for that and try to use only the other sensors.
The script uses light, magnet and proximity sensors, in that order because it goes from the most energy efficient to the least one.
First it checks if the device is locked. If it is the script is paused until changed to keep battery usage.
Because the first check is the light sensor I put a time window restriction because after some hours the surrounding light is low enough to keep triggering the check. This could waste battery or could trigger an unintended lock. So long as the device is locked none of this should happen.
The first check, the light sensor is set as "When changed" to save on battery usage so it may not be 100% responsive.
After every sensor check the locked state is checked.
That is to avoid lighting the screen if the device is already locked due to a button press or inactivity.
The light, magnet and proximity values work for my device, it may need some tweaking for your device and flip cover.