summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Michael Groover <mpgroover@google.com> 2020-07-22 19:26:53 -0700
committer Michael Groover <mpgroover@google.com> 2020-07-22 19:26:53 -0700
commit1fc831d5780d831e2fc2766c7b6ff126eede4c55 (patch)
tree400e11fa719699e421f98098b19b175c695c1dd9
parent8c8fa3588dba295a264a94f40e149b3e8fdb7eb1 (diff)
Keep USB disconnected receiver active when ADB activity in bg
When a new adb connection is attempted adbd will send the system's key to the framework to prompt the user for consent to authorize the connection. If another app is displayed over the adb prompt and the user is not able to switch foreground apps (for instance during setup wizard) the user will not be able to authorize the connection. This commit keeps the USB disconnected receiver active even when the ADB activity is in the background; if the user reseats the USB cable the existing activity will be able to notify adbd and terminate, and a new activity can be displayed in the foreground allowing the user to authorize the connection. Fixes: 152630548 Test: Manually verified the activity terminated and a new prompt was displayed after reseating the cable with the ADB activity in bg Change-Id: I3293536639a20557982113ff9f6ac2bf6f7c1975
-rw-r--r--packages/SystemUI/src/com/android/systemui/usb/UsbDebuggingActivity.java34
1 files changed, 14 insertions, 20 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/usb/UsbDebuggingActivity.java b/packages/SystemUI/src/com/android/systemui/usb/UsbDebuggingActivity.java
index 7561af770298..b1241b160d70 100644
--- a/packages/SystemUI/src/com/android/systemui/usb/UsbDebuggingActivity.java
+++ b/packages/SystemUI/src/com/android/systemui/usb/UsbDebuggingActivity.java
@@ -70,6 +70,8 @@ public class UsbDebuggingActivity extends AlertActivity
if (SystemProperties.getInt("service.adb.tcp.port", 0) == 0) {
mDisconnectedReceiver = new UsbDisconnectedReceiver(this);
+ IntentFilter filter = new IntentFilter(UsbManager.ACTION_USB_STATE);
+ mBroadcastDispatcher.registerReceiver(mDisconnectedReceiver, filter);
}
Intent intent = getIntent();
@@ -119,6 +121,7 @@ public class UsbDebuggingActivity extends AlertActivity
}
boolean connected = intent.getBooleanExtra(UsbManager.USB_CONNECTED, false);
if (!connected) {
+ Log.d(TAG, "USB disconnected, notifying service");
notifyService(false);
mActivity.finish();
}
@@ -126,29 +129,20 @@ public class UsbDebuggingActivity extends AlertActivity
}
@Override
- public void onStart() {
- super.onStart();
- if (mDisconnectedReceiver != null) {
- IntentFilter filter = new IntentFilter(UsbManager.ACTION_USB_STATE);
- mBroadcastDispatcher.registerReceiver(mDisconnectedReceiver, filter);
- }
- }
-
- @Override
- protected void onStop() {
+ protected void onDestroy() {
if (mDisconnectedReceiver != null) {
mBroadcastDispatcher.unregisterReceiver(mDisconnectedReceiver);
}
- super.onStop();
- }
-
- @Override
- protected void onDestroy() {
- // If the ADB service has not yet been notified due to this dialog being closed in some
- // other way then notify the service to deny the connection to ensure system_server sends
- // a response to adbd.
- if (!mServiceNotified) {
- notifyService(false);
+ // Only notify the service if the activity is finishing; if onDestroy has been called due to
+ // a configuration change then allow the user to still authorize the connection the next
+ // time the activity is in the foreground.
+ if (isFinishing()) {
+ // If the ADB service has not yet been notified due to this dialog being closed in some
+ // other way then notify the service to deny the connection to ensure system_server
+ // sends a response to adbd.
+ if (!mServiceNotified) {
+ notifyService(false);
+ }
}
super.onDestroy();
}