theappbusiness / android-proxy-toggle

Small application to help android developers to quickly enable and disable proxy settings
MIT License
425 stars 59 forks source link

App crash when enabling proxy in Android 5.1 #25

Closed ericksli closed 3 years ago

ericksli commented 3 years ago

Using Motorola XT1033, Android 5.1 and First stable release of the app.

Already executed adb shell pm grant com.kinandcarta.create.proxytoggle android.permission.WRITE_SECURE_SETTINGS

After filling in the IP address and port number, click on the enable button and then the app crashed:

02-04 12:11:13.236 6803-6803/com.kinandcarta.create.proxytoggle E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.kinandcarta.create.proxytoggle, PID: 6803
    java.lang.SecurityException: Permission denial: writing to settings requires android.permission.WRITE_SETTINGS
        at android.os.Parcel.readException(Parcel.java:1546)
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
        at android.content.ContentProviderProxy.call(ContentProviderNative.java:645)
        at android.provider.Settings$NameValueCache.putStringForUser(Settings.java:1094)
        at android.provider.Settings$Global.putStringForUser(Settings.java:6744)
        at android.provider.Settings$Global.putString(Settings.java:6728)
        at com.kinandcarta.create.proxytoggle.android.DeviceSettingsManager.enableProxy(DeviceSettingsManager.kt:32)
        at com.kinandcarta.create.proxytoggle.feature.manager.viewmodel.ProxyManagerViewModel.enableProxy(ProxyManagerViewModel.kt:42)
        at com.kinandcarta.create.proxytoggle.feature.manager.view.ProxyManagerFragment$showProxyDisabled$$inlined$with$lambda$1.onClick(ProxyManagerFragment.kt:107)
        at android.view.View.performClick(View.java:4785)
        at android.view.View$PerformClick.run(View.java:19884)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5343)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
02-04 12:11:26.262 6803-6803/com.kinandcarta.create.proxytoggle I/Process: Sending signal. PID: 6803 SIG: 9
kleinsenberg commented 3 years ago

hi @ericksli - did you go through the readme and grant the app the required permissions to work?

Please check this in the "Caveats" section for reference: https://github.com/theappbusiness/android-proxy-toggle#write_secure_settings-permission

ericksli commented 3 years ago

Already executed adb shell pm grant com.kinandcarta.create.proxytoggle android.permission.WRITE_SECURE_SETTINGS but still crash.

➜  ~ adb devices
List of devices attached
TA93302A6T  device

➜  ~ adb shell pm grant com.kinandcarta.create.proxytoggle android.permission.WRITE_SECURE_SETTINGS
➜  ~
fmontesino commented 3 years ago

Hey @ericksli thanks for raising this. I had a deeper look and it turns out I didn't test the app pre-API 23 😬 and you're using API 22. My fault!

The error appears to be the old android permission system. For some reason, on API 22 and below, apart from the WRITE_SECURE_SETTINGS permission, you also need the WRITE_SETTINGS permission. Apparently, this was dropped on API 23 onwards.

The quickest way to make it work for you is to get this modified apk.zip and install it with the provided command. If that still fails, you'll need to grant the secure permission manually:

$ adb shell pm grant com.kinandcarta.create.proxytoggle android.permission.WRITE_SECURE_SETTINGS

Alternatively, you can clone the project, add the WRITE_SETTINGS permission in the AndroidManifest.xml and build the app from there.

I will try to fix this and make a new release to support older Android versions ASAP.

Many thanks again and apologies for the inconveniences!

kleinsenberg commented 3 years ago

@ericksli thanks to @fmontesino there's a new release (https://github.com/theappbusiness/android-proxy-toggle/releases/tag/v1.0.1) that addresses the issue, and new instructions in the readme for 5.x devices: https://github.com/theappbusiness/android-proxy-toggle#android-5x 🎉