Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent users from turning off GPS, Wifi and Bluetooth?

I'm developing a tracking application and I need to prevent users from turning off the basic sensors used to determine the location. I can not modify the devices ROM or have root access (or at least it would be very desirable to had not), but I thought of using the Device Administration API to perform these functions through the Profile Owner or Device Owner modes. I'm basically looking for a method to block these functions in Android settings.

I'm unsure about whether this is possible and how to do it, I have not found examples in GitHub for applications that have implemented this. Could anyone give me a light, some example or specific documentation?

I tried to follow these three documentations, without success in finding a solution to this specific feature:

https://source.android.com/devices/tech/admin https://developer.android.com/guide/topics/admin/device-admin https://developers.google.com/android/management/introduction

This is an excerpt from what I've been trying:

setUserRestriction(UserManager.DISALLOW_CONFIG_WIFI, true);
setUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS, active);
setUserRestriction(UserManager.DISALLOW_CONFIG_BLUETOOTH, active);

private void setUserRestriction(String restriction, boolean disallow){
    if (disallow) {
        mDevicePolicyManager.addUserRestriction(mAdminComponentName, restriction);
    } else {
        mDevicePolicyManager.clearUserRestriction(mAdminComponentName,
restriction);
    }
}

DISALLOW_CONFIG_BLUETOOTH Added in API level 18 public static final String DISALLOW_CONFIG_BLUETOOTH

Specifies if a user is disallowed from configuring bluetooth. This does not restrict the user from turning bluetooth on or off. The default value is false.

This restriction doesn't prevent the user from using bluetooth. For disallowing usage of bluetooth completely on the device, use DISALLOW_BLUETOOTH.

This restriction has no effect in a managed profile.

Key for user restrictions.

Type: Boolean

like image 589
Lucas Cleto Avatar asked May 29 '19 16:05

Lucas Cleto


People also ask

Can I prevent my child from turning off location services Android?

Click on Create Profile and select Android Profile from the dropdown. Provide the required details and create the profile. Click on Restrictions and select Location settings. For the restriction Location Services, select the option Always On.

How to keep GPS always on in Android?

Open your phone's Settings app. Under "Personal," tap Location access. At the top of the screen, turn Access to my location on or off.

How to disable turn off GPS Android?

The easiest way to turn off GPS on Android is by finding the toggle in your Quick Settings. Swipe down twice from the top of your screen to view the full Quick Settings menu. Once open, find the 'Location' toggle and tap it. This immediately disables all location/GPS access on your phone.

Why does my location keeps turning on by itself Android?

These apps are known as GPS-driven apps and mostly, they seek users' permission to turn on their device's location. Moreover, the location turns on whenever you connect your device with Wi-Fi even if the “Remotely locate this device” option is disabled.


3 Answers

You cannot prevent them from turning GPS, WIFI and Bluetooth off. What you can do is have an implementation as below or use this library.

https://github.com/KI-labs/gps-permission-checks-livedata

like image 56
SRBhagwat Avatar answered Oct 11 '22 04:10

SRBhagwat


You can't, obviously for security reasons. If you want to achive something like that you'll probably need to modify the devices ROM. You should create a BroadcastReceiver and keep tracking Internet and Bluetooth connection changes, than you can properly handle it when user disconnect them pausing the service, showing a dialog, finishing the application or whatever you need to do.
It would be pretty weird if an app could have some control of user settings, imagine if you install an app, then suddently you can't disable wi-fi anymore until you unistall it. You can't do that for a good reason

like image 40
Shermano Avatar answered Oct 11 '22 06:10

Shermano


Preventing bluetooth/wifi disconnection will also prevent usage of aircraft mode, that is a security issue bounded in the ROM and not overridable. As suggested above your option is to monitor for wifi/bluetooth/gps deactivations and prompt the user with an alert. By the way, GPS is not affected by aircraft mode, as it's a pure receiver and doesn't make active transmissions. In that case GPS will be always active and collecting informations (if active and the phone is not in power save mode, aka relying on wifi location). I suggest you to check if the user activated aircraft mode, in order to be less annoying with your alerts (air mode is mandatory in same situations, and should be considered "legal" by your application, and maybe less critical than an user voluntary disconnection

like image 43
Daniele Pistollato Avatar answered Oct 11 '22 04:10

Daniele Pistollato