Sunday, 25 October 2015

Using WRITE_SECURE_SETTINGS permission on non system apps

I happen to frequently use an app that doesn't work if USB Debugging - ADB (Android Debug Bridge) is enabled. It is very cumbersome to go to settings and enable or disable the setting every time I need to use the app.
I checked if there are any widgets that could do this in a click and returned empty handed. So, I did what every developer would do - build it myself!

In order to change the adb settings, I had to use WRITE_SECURE_SETTINGS permission. But there was one major problem! This permission is not available for non system apps!!

The easiest solution to this was to move the apk to /system partition. Except that I didn't want to do this as I frequently keep flashing /system partition.

Another solution was to use pm and grant permission to the app like this:

adb pm grant <package name> android.permission.WRITE_SECURE_SETTINGS

This was great! However I didn't want users who were gonna use the app to go through all this pain. I had to figure out a way to do the same programmatically. So I did the next best thing! To run the command after opening a root shell in the code.

Here is how I did it.
This requires root. But that's ok.


  1. In this manner my associate Wesley Virgin's autobiography starts in this shocking and controversial VIDEO.

    Wesley was in the military-and soon after leaving-he revealed hidden, "SELF MIND CONTROL" tactics that the CIA and others used to obtain everything they want.

    THESE are the EXACT same tactics tons of famous people (especially those who "became famous out of nothing") and top business people used to become rich and successful.

    You've heard that you use less than 10% of your brain.

    That's really because most of your BRAINPOWER is UNCONSCIOUS.

    Maybe this conversation has even occurred INSIDE your own head... as it did in my good friend Wesley Virgin's head seven years back, while driving an unlicensed, garbage bucket of a car with a suspended license and $3.20 on his banking card.

    "I'm so frustrated with going through life check to check! When will I finally succeed?"

    You've been a part of those those questions, right?

    Your success story is waiting to start. You just need to take a leap of faith in YOURSELF.

    Learn How To Become A MILLIONAIRE Fast

  2. Strange "water hack" burns 2 lbs overnight

    More than 160000 men and women are trying a simple and SECRET "liquid hack" to drop 2 lbs every night while they sleep.

    It is very simple and it works on anybody.

    This is how to do it yourself:

    1) Hold a glass and fill it up half glass

    2) Proceed to do this crazy HACK

    and become 2 lbs skinnier the next day!