summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/settings/deviceinfo/UsbModeChooserActivity.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/com/android/settings/deviceinfo/UsbModeChooserActivity.java b/src/com/android/settings/deviceinfo/UsbModeChooserActivity.java
index 77fc388..1105718 100644
--- a/src/com/android/settings/deviceinfo/UsbModeChooserActivity.java
+++ b/src/com/android/settings/deviceinfo/UsbModeChooserActivity.java
@@ -20,7 +20,12 @@ import android.annotation.Nullable;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
+import android.content.BroadcastReceiver;
+import android.content.Context;
import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.hardware.usb.UsbManager;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@@ -49,6 +54,19 @@ public class UsbModeChooserActivity extends Activity {
private AlertDialog mDialog;
private LayoutInflater mLayoutInflater;
+ private BroadcastReceiver mDisconnectedReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ if (UsbManager.ACTION_USB_STATE.equals(action)) {
+ boolean connected = intent.getBooleanExtra(UsbManager.USB_CONNECTED, false);
+ if (!connected) {
+ mDialog.dismiss();
+ }
+ }
+ }
+ };
+
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -84,6 +102,20 @@ public class UsbModeChooserActivity extends Activity {
}
}
+ @Override
+ public void onStart() {
+ super.onStart();
+
+ IntentFilter filter = new IntentFilter(UsbManager.ACTION_USB_STATE);
+ registerReceiver(mDisconnectedReceiver, filter);
+ }
+
+ @Override
+ protected void onStop() {
+ unregisterReceiver(mDisconnectedReceiver);
+ super.onStop();
+ }
+
private void inflateOption(final int mode, boolean selected, LinearLayout container) {
View v = mLayoutInflater.inflate(R.layout.radio_with_summary, container, false);