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.