Search code examples
androidbroadcastreceiveradbusb-debugging

Android - Detect when developer option or USB debugging mode is being turned on


Basically I can get the data from this

import android.provider.Settings;

Settings.System.getString(getContentResolver(), Settings.Global.ADB_ENABLED)

But my application need a toggle listener. Is there any way I could listen when the setting is being toggled while the app is running either in foreground or background, or do I need to implement a background timer to manually checking for it?.


Just some additional informations for any workaround suggestion. I'm building an Android application (using Flutter but the question is more generic) which is vulnerable to data stealing if running with rooted device or at least USB debugging mode turned on. I've managed to prevent it from launched if the device is detected as rooted. The problem is the sensitive unencrypted data can still be viewed via ADB proxy (I'm not a hacker to know much about it) when the app is running. The solution came to my head is by listening when developer option or USB debugging is being turned on on the device before closing the app.


Solution

  • Since there's no way for an unrooted device to turn the debugging mode on from background while other application is running on the front including by user action for example by clicking on a toggle button on the notification bar, I can just do the checking on the application resume without using any timer