Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the dreaded WRITE_SECURE_SETTINGS permission for my android app?

I need to be able to toggle the GPS receiver on and off, and WRITE_SECURE_SETTINGS is required to be able to access secure settings. I've searched around quite a bit, and every answer I saw pretty much said that no app outside of the system/firmware can get that permisssion.

However, that is simply untrue. There are several apps on the market that do exactly what I'm trying to (in regards to GPS), but there are a bunch more that have the WRITE_SECURE_SETTINGS permissions. For example:

Extended Controls

SwitchPro

Profile Flow

So, how can this be done?

like image 793
user496854 Avatar asked Feb 17 '11 20:02

user496854


2 Answers

I need to be able to toggle the GPS receiver on and off

For privacy reasons, if nothing else, enabling or disabling any sort of location-tracking needs to be solely in the hands of the user via trusted applications, not at the request of arbitrary third parties.

So, if you wish to enable and disable GPS, create your own firmware that does what you need and load that firmware on whatever devices you wish. Or, contribute your changes to existing firmware mods (e.g., Cyanogen).

WRITE_SECURE_SETTINGS is required to be able to access secure settings

Correct.

I've searched around quite a bit, and every answer I saw pretty much said that no app outside of the system/firmware can get that permisssion.

Correct.

However, that is simply untrue.

No, it's pretty true.

There are several apps on the market that do exactly what I'm trying to (in regards to GPS)

They found a security loophole. I will take steps to help ensure this hole gets fixed.

but there are a bunch more that have the WRITE_SECURE_SETTINGS permissions

No, there are a bunch who ask for them. You can ask for whatever permission you want. What you ask for is what shows up in these listings. What you get is a different story.

like image 116
CommonsWare Avatar answered Sep 20 '22 19:09

CommonsWare


Try this adb command, this will give permission at application run time

adb shell pm grant package android.permission.WRITE_SECURE_SETTINGS

Step to follow:

  1. Connect your device (Make sure USB Debugging enabled)

  2. Execute above adb command

  3. Install apk

It worked for me...

like image 35
Pradeep Avatar answered Sep 21 '22 19:09

Pradeep