WRITE_SECURE_SETTINGS permission error even when added in Manifest
Asked Answered
G

7

18

I have added "android.permission.WRITE_SECURE_SETTINGS" in the Manifest. But still i get an error message saying - required "WRITE_SECURE_SETTINGS".

I have seen a lot of talks about this, and that this setting is prevented for third party software.

It is any other way that i can add my application can gain this permission?

I have see this adb command, but i not so familiar how to use this to add my application to my device, is below command is require root my device before it can be use because it failed to copy by Read-only file system?

adb remount
adb push app.apk /system/app/
Goods answered 24/10, 2012 at 8:17 Comment(2)
Some applications somehow use that setting. Possibly via reflection? The permission can be added via adb shell pm family of commands.Mylonite
I had to unselect Developer Settings > Apps > Enable Permission Monitoring, temporarily.Gilgilba
H
17

Firstly, as you have read before, WRITE_SECURE_SETTINGS is NOT available to applications! So you cannot use this permission regardless whether you are on rooted or production builds.

So, if you wish to enable this setting, 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).

Some other applications use techniques like Reflection using Java to gain access to functions not exposed via API, you can probably try the same.

Secondly, adb remount does not work as is with production builds unless the phone is rooted or firmware enables it by default.

Hydrogeology answered 24/10, 2012 at 8:53 Comment(2)
Just a note on this, many secure settings are available for dedicated cosu devices; developer.android.com/work/cosuLacedaemon
For those viewing this "Accepted" answer: it is, and has always been, patently false. See https://mcmap.net/q/392186/-write_secure_settings-permission-error-even-when-added-in-manifest (the top-most voted answer to this question at the time of this coment).Scenography
F
28

I would like to add that WRITE_SECURE_SETTINGS permission can be granted over adb and this approach does NOT require root. Here is a command:

adb shell pm grant your.package.name android.permission.WRITE_SECURE_SETTINGS
Forfeiture answered 21/1, 2019 at 0:49 Comment(7)
Worked for me dude. Can we run this ADB command programmatically inside the app?Jambeau
No you can't. User has to run it manually, but after that your app will have WRITE_SECURE_SETTINGS until it is uninstalled or app data is erasedForfeiture
Thanks @Forfeiture for the reply. The will permission remove after updating the app itself or will remain?Jambeau
Does not work on Xiaomi Redmi Note 6 (Android Oreo):Nonchalance
Does anyone know if asking users to do this is ok for Google Play policy? I am afraid of being banned if I ask users to do things against their policy.Nadene
it works for remit 8T adb is not in my path so I used full path /Users/user_name/Library/Android/sdk/platform-tools/adb shell pm grant your.package.name android.permission.WRITE_SECURE_SETTINGSCaseworm
What do you enter in place of "your.package.name" when you are getting the error from wm overscan? I.e. you're getting the error when WindowManagerService.setOverscan(...) is called.Pontonier
H
17

Firstly, as you have read before, WRITE_SECURE_SETTINGS is NOT available to applications! So you cannot use this permission regardless whether you are on rooted or production builds.

So, if you wish to enable this setting, 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).

Some other applications use techniques like Reflection using Java to gain access to functions not exposed via API, you can probably try the same.

Secondly, adb remount does not work as is with production builds unless the phone is rooted or firmware enables it by default.

Hydrogeology answered 24/10, 2012 at 8:53 Comment(2)
Just a note on this, many secure settings are available for dedicated cosu devices; developer.android.com/work/cosuLacedaemon
For those viewing this "Accepted" answer: it is, and has always been, patently false. See https://mcmap.net/q/392186/-write_secure_settings-permission-error-even-when-added-in-manifest (the top-most voted answer to this question at the time of this coment).Scenography
F
13

I recently struggled with this very thing. My client wanted an app that would turn NFC off when the device was charging (wireless charger) and then on when it was removed from the charger. I was running KitKat on my Nexus 7, and even though I had WRITE_SECURE_SETTINGS in the Manifest, and the app in /system/app/, it would not work.

Turns out, that in 4.4 they added additional security. In 4.3 however, it works if three things are true:

  1. Manifest has WRITE_SECURE_SETTINGS
  2. App is in /system/app/
  3. The package is signed by a key (any key)

I rooted the device using the awesome Nexus Root Toolkit (NRT) from http://www.wugfresh.com/nrt/ then installed BusyBox and system app mover from:

https://play.google.com/store/apps/details?id=stericson.busybox https://play.google.com/store/apps/details?id=de.j4velin.systemappmover

I installed my custom signed APK and moved it into place using system app mover, which then restarted the device. It worked perfectly. Hope this helps.

Fredel answered 8/12, 2013 at 3:58 Comment(6)
Do you know what additional security is in 4.4?Laroche
It's been 6+ months, but as I recall for apps to run as root in /system/app in 4.4 they have to be signed by the same APK signing key as the one that signed the system.Fredel
I know it's been a while, but do you have any link or reference that states this? I haven't found anything online but I have read about /system/priv-app as the new location to put system apps... although that doesn't seem to work for me either.Laroche
I had inquired at intangibleobject.com regarding their Secure Settings plugin for Tasker. One of the authors, Corey Z, replied with some information about it. I haven't seen it documented online.Fredel
in android 4.4 place a apk on /system/priv-appReprise
@DavidS.can this be done now on Android 7.1.2 ?Doretha
G
6

For the api that I used, which required WRITE_SECURE_SETTINGS privileges, I had to include this in the manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...
coreApp="true"
android:sharedUserId="android.uid.system">

<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
...

ref: https://github.com/android/platform_packages_apps_settings/blob/master/AndroidManifest.xml

I also had to run the application as a system app (under: /system/app). Here is an how to: http://www.addictivetips.com/mobile/how-to-install-any-app-as-system-app-on-android/

Gine answered 23/5, 2014 at 8:23 Comment(0)
M
0

I met this situation too,and then i follow the rules below: 1.add WRITE_SECURE_SETTINGS in manifest 2.make my own firmware 3.add LOCAL_CERTIRICATE := platform

Meade answered 26/5, 2017 at 8:2 Comment(0)
C
0

Try this,

adb shell pm grant your.package.name android.permission.WRITE_SECURE_SETTINGS
Charybdis answered 23/11, 2021 at 15:42 Comment(0)
S
-6

I was able to fix this problem by enabling notification access.

go to settings
click on sound and notification
scroll down
click on notification access
Spirituous answered 13/3, 2016 at 9:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.