diff options
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/usb/UsbDebuggingActivity.java | 40 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/usb/UsbDebuggingSecondaryUserActivity.java | 20 |
2 files changed, 54 insertions, 6 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/usb/UsbDebuggingActivity.java b/packages/SystemUI/src/com/android/systemui/usb/UsbDebuggingActivity.java index 6e041f6f9ee0..bc2a55c8d5c4 100644 --- a/packages/SystemUI/src/com/android/systemui/usb/UsbDebuggingActivity.java +++ b/packages/SystemUI/src/com/android/systemui/usb/UsbDebuggingActivity.java @@ -51,6 +51,7 @@ public class UsbDebuggingActivity extends AlertActivity private UsbDisconnectedReceiver mDisconnectedReceiver; private final BroadcastDispatcher mBroadcastDispatcher; private String mKey; + private boolean mServiceNotified; @Inject public UsbDebuggingActivity(BroadcastDispatcher broadcastDispatcher) { @@ -118,6 +119,7 @@ public class UsbDebuggingActivity extends AlertActivity } boolean connected = intent.getBooleanExtra(UsbManager.USB_CONNECTED, false); if (!connected) { + notifyService(false); mActivity.finish(); } } @@ -126,8 +128,10 @@ public class UsbDebuggingActivity extends AlertActivity @Override public void onStart() { super.onStart(); - IntentFilter filter = new IntentFilter(UsbManager.ACTION_USB_STATE); - mBroadcastDispatcher.registerReceiver(mDisconnectedReceiver, filter); + if (mDisconnectedReceiver != null) { + IntentFilter filter = new IntentFilter(UsbManager.ACTION_USB_STATE); + mBroadcastDispatcher.registerReceiver(mDisconnectedReceiver, filter); + } } @Override @@ -135,6 +139,12 @@ public class UsbDebuggingActivity extends AlertActivity if (mDisconnectedReceiver != null) { mBroadcastDispatcher.unregisterReceiver(mDisconnectedReceiver); } + // 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.onStop(); } @@ -142,6 +152,30 @@ public class UsbDebuggingActivity extends AlertActivity public void onClick(DialogInterface dialog, int which) { boolean allow = (which == AlertDialog.BUTTON_POSITIVE); boolean alwaysAllow = allow && mAlwaysAllow.isChecked(); + notifyService(allow, alwaysAllow); + finish(); + } + + /** + * Notifies the ADB service as to whether the current ADB request should be allowed; if the + * request is allowed it is only allowed for this session, and the user should be prompted again + * on subsequent requests from this key. + * + * @param allow whether the connection should be allowed for this session + */ + private void notifyService(boolean allow) { + notifyService(allow, false); + } + + /** + * Notifies the ADB service as to whether the current ADB request should be allowed, and if + * subsequent requests from this key should be allowed without user consent. + * + * @param allow whether the connection should be allowed + * @param alwaysAllow whether subsequent requests from this key should be allowed without user + * consent + */ + private void notifyService(boolean allow, boolean alwaysAllow) { try { IBinder b = ServiceManager.getService(ADB_SERVICE); IAdbManager service = IAdbManager.Stub.asInterface(b); @@ -150,9 +184,9 @@ public class UsbDebuggingActivity extends AlertActivity } else { service.denyDebugging(); } + mServiceNotified = true; } catch (Exception e) { Log.e(TAG, "Unable to notify Usb service", e); } - finish(); } } diff --git a/packages/SystemUI/src/com/android/systemui/usb/UsbDebuggingSecondaryUserActivity.java b/packages/SystemUI/src/com/android/systemui/usb/UsbDebuggingSecondaryUserActivity.java index 8d3428a52e3b..4850a025b684 100644 --- a/packages/SystemUI/src/com/android/systemui/usb/UsbDebuggingSecondaryUserActivity.java +++ b/packages/SystemUI/src/com/android/systemui/usb/UsbDebuggingSecondaryUserActivity.java @@ -22,9 +22,14 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; +import android.debug.IAdbManager; import android.hardware.usb.UsbManager; import android.os.Bundle; +import android.os.IBinder; +import android.os.RemoteException; +import android.os.ServiceManager; import android.os.SystemProperties; +import android.util.Log; import com.android.internal.app.AlertActivity; import com.android.internal.app.AlertController; @@ -35,6 +40,7 @@ import javax.inject.Inject; public class UsbDebuggingSecondaryUserActivity extends AlertActivity implements DialogInterface.OnClickListener { + private static final String TAG = "UsbDebuggingSecondaryUserActivity"; private UsbDisconnectedReceiver mDisconnectedReceiver; private final BroadcastDispatcher mBroadcastDispatcher; @@ -81,9 +87,10 @@ public class UsbDebuggingSecondaryUserActivity extends AlertActivity @Override public void onStart() { super.onStart(); - - IntentFilter filter = new IntentFilter(UsbManager.ACTION_USB_STATE); - mBroadcastDispatcher.registerReceiver(mDisconnectedReceiver, filter); + if (mDisconnectedReceiver != null) { + IntentFilter filter = new IntentFilter(UsbManager.ACTION_USB_STATE); + mBroadcastDispatcher.registerReceiver(mDisconnectedReceiver, filter); + } } @Override @@ -91,6 +98,13 @@ public class UsbDebuggingSecondaryUserActivity extends AlertActivity if (mDisconnectedReceiver != null) { mBroadcastDispatcher.unregisterReceiver(mDisconnectedReceiver); } + try { + IBinder b = ServiceManager.getService(ADB_SERVICE); + IAdbManager service = IAdbManager.Stub.asInterface(b); + service.denyDebugging(); + } catch (RemoteException e) { + Log.e(TAG, "Unable to notify Usb service", e); + } super.onStop(); } |