Is it possible for an Android app to restrict other apps to WiFi only (without root)?

470 views Asked by At

I was wondering if it was possible to make an android app (that does not require root) that could enable and disable the use of mobile data for other apps? I know there's a function to toggle background services per app inside the native Android settings, so maybe there's some public methods for me to do so with my own app.

Basically, I want my app to control whether other apps could access data via mobile data or WiFi only.

Pointing me to the right direction would be greatly appreciated as well.

1

There are 1 answers

0
soulseekah On

Theoretically, yes.

See: https://github.com/android/platform_frameworks_base/blob/dbc51de44fe4f9a7f81528204250de32ec405d39/cmds/svc/src/com/android/commands/svc/DataCommand.java

This is the svc tool that can be launched via adb shell. It did error out with code 137 for me (unrooted Nexus 5), though. But from the code you see how this should theoretically work.

You retrieve the TelephonyManager and enableDataConnectivity, which is, of course, a hidden API (see: https://github.com/android/platform_frameworks_base/blob/6b8a3a52acf1c2722551f1ea1ce47831f87939cd/telephony/java/com/android/internal/telephony/ITelephony.aidl). Accessing hidden APIs is possible by recompiling the android.jar that you build against, or by using reflection (see: How do I build the Android SDK with hidden and internal APIs available?).

Hope this helps.