Tuesday, 27 October 2015

USB debugging toggle widget

Like I told you few days back in this post, I made a widget for android to toggle USB Debugging - ADB (Android Debug Bridge). Today, I will tell you more about it.



There are many alternatives to this. However they either require you to make the app a system app or they simply open the settings page. As this was not exactly what I wanted, I made one myself that allows me to enable/ disable USB debugging on click. You can get the app from here.

Download ADB Toggle

Fork me on Github


You DON'T have to make this a system app!.


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.