How to Enable a Location-based Smart Lock Feature on Huawei/Honor Devices Running EMUI

How to Enable a Location-based Smart Lock Feature on Huawei/Honor Devices Running EMUI

If you’ve never owned a Huawei or Honor device, then you’re probably looking at the title and going “huh?” After all, Smart Lock is a feature introduced back in Android 5.0 Lollipop to make it easier to quickly access your device under certain conditions such as location, when connected to certain devices, while in your pocket, or when recognizing your voice.

Such a feature is normally hardly worth discussing given that it’s been over two years since Lollipop was released, and the fact that approximately 65% of all Android devices are running on Android 5.0+. We suspect the proportion of users on our forums who are running at least Lollipop to be much, much higher, though we don’t have any exact statistics on that. In any case, Google’s Smart Lock feature has become so commonplace among Android devices that third-party applications offering this functionality have largely been abandoned, because they don’t see the point in competing with the feature.

But there’s one set of users who are left with a neutered version of Smart Lock: users with a Huawei or Honor device running EMUI. For whatever reason, EMUI does not provide the same Smart Lock features that most other Android 5.0+ devices offer. Instead, EMUI only allows you to automatically unlock your device if connected to certain Bluetooth devices.

While certainly useful if you own a Bluetooth wearable such as a smartwatch or fitness band, not everyone has a wearable device always connected to their smartphone. Huawei’s exclusion of Google’s Smart Lock feature is clearly deliberate, because even if you enable Smart Lock as a “trusted agent” in Android, you are unable to actually use the feature.

Basically, you’re stuck with Huawei’s “Smart” Lock feature, which offers less features than Google’s Smart Lock. Your only options as a Huawei/Honor device owner are to try one of the many options on the Play Store that claim to add this feature (none of which have ever worked on my device), or to root your phone and download an Xposed Module. The lack of decent options for EMUI has of course driven me to write this tutorial. With a little bit of Tasker magic and a plug-in called AutoTools, we can automatically unlock any Huawei or Honor device based on location without needing root.


Smart Lock for Huawei/Honor Devices

There are only two applications necessary to get this feature up and running. The first is Tasker, the incredibly popular Android automation tool that we at XDA frequently feature to solve issues ranging from the most mundane to incredibly complex. At $2.99, it might seem unnecessary to purchase this application for something so simple, but the value that this application can provide is enormous, if you’re willing to sit through a few tutorials. Next up, you’ll need the beta version of a Tasker plug-in known as AutoTools. This plug-in adds in a ton of useful features to Tasker’s native toolkit, and in particular we will need a function of AutoTools known as Secure Settings to accomplish our goal.

What we’ll be doing is modifying a property on our device that controls the timer that Android uses to determine when to show the lock screen after the phone has timed out. A “time out” here refers to either when your phone’s screen turns off after X minutes of inactivity or when the user manually turns the display off by pressing the power button. After a set amount of time (ranging from immediately after the device enters sleep up to 30 minutes after entering sleep mode), Android will display the lock screen.

The problem with these two features is that by default, increasing the “automatically lock” timer can potentially be a security issue, because if your device is swiped within the window of time where the lock screen hasn’t yet activated, a thief will have access to the full contents of your device. To mitigate this, Android offers a “power button instantly locks device” option so you can immediately activate the lock screen by pressing the power button. However, and especially if you’ve set a short screen timeout, it’s easy to forget to do this, so you’re still open to having your device accessed by malicious third-parties if you accidentally let the device timeout on a table or in your pocket without manually pressing the power button.

Hence, our solution to this problem is to tie a longer “automatically lock” timer not to the power button, which requires manual intervention, but instead to location/WiFi. That way, you can enjoy using your device without a lock screen while in the comfort of your own home, but be assured that the lock screen pin/password will always be visible while away from home. Now that we’ve explained what we’re doing, here’s how it’s actually done.


Tutorial

As mentioned before, we’re going to be modifying a certain system property. This property is defined under the Settings.Secure class with the name lock_screen_lock_after_timeout, and it accepts integer values in the milliseconds. In order to modify this value, we will need to grant AutoTools a particular permission so it can write to these settings without needing root access.

Step 1 – Granting Secure Settings Permission to AutoTools

Under Android’s permission management system, applications define the permissions they want to be granted in the Manifest file. Users can then grant or deny permissions on installation (pre-Marshmallow) or on demand (Marshmallow+). However, there are certain permissions that applications cannot be granted even if they request it in the Manifest, such as WRITE_SECURE_SETTINGS. This is because granting any application a permission as powerful as this would give that app a ton of control over your device.

But there is one workaround that we can use to grant the WRITE_SECURE_SETTINGS permission to any app we want. By using ADB’s package manager (pm) tool, we can grant almost any permission to any application we want (provided that application requests that permission in the Manifest file).

The first thing you’ll need to do is install the ADB binary onto your computer followed by the right driver for your device. Then, enable USB Debugging in Developer Options (go to Settings –> About Phone and tap on Build number 7 times if you haven’t already) and connect your phone to your computer. Finally, send the following command once you’ve opened up a terminal:

adb shell pm grant com.joaomgcd.autotools android.permission.WRITE_SECURE_SETTINGS

Now AutoTools will have the ability to change any Global, Secure, or System setting on your device. There are various ways you can play around with these settings, and the list of available settings in each category completely depends on your device and software build, but that discussion is for another time. In any case, we’ll move on show you how to use AutoTools to control the lock screen timeout.

Step 2 – Setting up Tasker

Open up Tasker and press the + icon in the bottom right hand corner to create a new profile. Name your new profile something like “Automatic Lock” or whatever you want, really. For the type of Context we will use, select State. Go to Net –> WiFi Connected. Here, we will select the WiFi networks that we want to white-list for automatically unlocking the device. Hit the magnifying glass icon and select all of the WiFi networks you want white-listed.

Optional: If you want to make a truly-Location based Smart Lock (rather than just based on WiFi networks), then you can use the “Location” context in Tasker instead of the State –> Net –> WiFi Connected feature. Note that Tasker doesn’t create geo-fences, so the battery drain will be worse with this method. If you want to have Tasker react to more battery efficient geo-fences, then you will need to install the AutoLocation plug-in.

Back out, and you will next be asked to create a Task. Enter any name (or none is fine) to get to the Task creation screen. Press the + icon in the bottom middle to add a new Action. Go to Plugin –> AutoTools –> Secure Settings. Hit the pencil icon to open the AutoTools Secure Setting configuration screen. Go to Lock Screen –> Automatic Lock and for the value enter any sufficiently high value such as ‘9001‘. This is the value, in seconds, that AutoTools will set the automatic lock screen timer to. Fortunately for us, we don’t have to mess with manually setting a command to modify the lock_screen_lock_after_timeout value, as the developer of AutoTools has implemented this feature for us in a nice GUI.

Save this setting by pressing on the checkmark icon up top, then pressing the back key once back in Tasker, and finally by exiting from the Task creation screen. Once you’ve done that, Tasker will now automatically keep your device unlocked for a really long time while you’re at home. Make sure that “power button instantly locks device” is disabled in secure lock settings, otherwise when you press the power button while at home, your phone’s lock screen will activate which is not what you want!

Finally, we will need to add another Task that triggers when we leave any of the white-listed WiFi networks. On the Tasker main page, long-press on the Task you just created and tap add exit task in the pop-up menu. Name this Task anything, and once again enter the Task creation screen. Here, tap on the + icon and again go to Plugin –> AutoTools –> Secure Settings. In the same Automatic Lock option, this time enter a value of 0. Once you leave your WiFi network, Tasker will no longer delay the lock screen showing up after the phone times out.

Optional: Add a second Action by pressing on the + icon but this time go to Display –> System Lock. This action will automatically lock your phone when you exit the range of your white-listed WiFi networks, just in case you have a really long display timeout and your phone never goes to sleep when you leave home. If you do this, you will have to make Tasker a Device administrator by going to Settings. Just search for the option and grant Tasker the permission.

And that’s it! While this tutorial seems long, in actuality the Tasker script itself is very simple. A grand total of up to 3 Actions is necessary to enable this feature. Give this a shot and let us know how it works for you!

Discuss This Story

You might also like