1

For project requirements (no root permissions), I need my device to allow USB debugging only on a given computer.

Since I have no root permissions I can't write on data/misc/adb_keys to delete all the keys that I don't know, so I thought I could dismiss the dialog with which a user allows USB debugging from a computer

enter image description here

I used android.intent.action.CLOSE_SYSTEM_DIALOGS to close system dialogs and it works with all other dialogs but not for this one:

override fun onWindowFocusChanged(hasFocus: Boolean) {
    super.onWindowFocusChanged(hasFocus)
        val closeDialog = Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)
        sendBroadcast(closeDialog)
    }
}

Since the dialog is not closed and the above code works with other dialogs, it seems to not be a system dialog closable with ACTION_CLOSE_SYSTEM_DIALOGS, what kind of dialog is the "Allow USB debugging?" one? How can I programmatically close it?

Cliff Burton
  • 3,414
  • 20
  • 33
  • 47
  • Does it go inside if(!hasFocus) condition? – Bo Z Jun 11 '19 at 15:32
  • I didn't try it but I tried sending the broadcast directly inside `onWindowFocusChanged()` and it still is not working so the dialog seems to not be a closable system dialog – Cliff Burton Jun 11 '19 at 15:40
  • 1
    There are three steps BEFORE sending broadcast. You have to be sure that it pass ALL of them. First that it is inside onWindowFocusChanged than inside BuildConfig.DEBUG and then inside !hasFocus. Only if it is inside !hasFocus we can figure out whats wrong with intent. So please check – Bo Z Jun 11 '19 at 15:46
  • Yes, I know. But as I said I tried sending the broadcast directly inside `onWindowFocusChanged()` which means outside of `if (BuildConfig.DEBUG)` which is `true` and outside of `if (!hasFocus)`. I'm going to describe better in my question for you. But I want to ask: did you ever tried closing that specific dialog? Did you succeed? – Cliff Burton Jun 12 '19 at 10:11
  • no i did not. But I am also interested in finding solution for that. I guess it might be not system dialog. The place if I were you I would go will be logs. Logs should help to understand what mechanism calls that dialog that could give an answer what could close it. Did you check logs? – Bo Z Jun 12 '19 at 14:51

0 Answers0