diff options
author | Mike Lockwood <lockwood@android.com> | 2010-09-21 11:17:27 -0400 |
---|---|---|
committer | Mike Lockwood <lockwood@android.com> | 2010-09-21 11:17:27 -0400 |
commit | 77bc30d232633eb36323245bc5d0cbf144a3bd26 (patch) | |
tree | cd60f87d76ca54af908a405c96ebe558d0c2646f /packages/SystemUI/src/com/android/systemui/usb | |
parent | 307aef01257cbba42f095f7020a4a3b753f3807b (diff) | |
download | frameworks_base-77bc30d232633eb36323245bc5d0cbf144a3bd26.zip frameworks_base-77bc30d232633eb36323245bc5d0cbf144a3bd26.tar.gz frameworks_base-77bc30d232633eb36323245bc5d0cbf144a3bd26.tar.bz2 |
SystemUI: Use new USB notifications to detect USB disconnect.
This fixes a bug that prevented the USB mass storage activity from closing
when USB is disconnected.
The bug was actually due to using == for a string compare instead of equals(),
but using the new notifications is a better solution than using battery events
since it will work for devices that do not charge over USB.
BUG: 3018954
Change-Id: Ia447974726a52cd865e59df5af79e828b5134b6c
Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/usb')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/usb/UsbStorageActivity.java | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/usb/UsbStorageActivity.java b/packages/SystemUI/src/com/android/systemui/usb/UsbStorageActivity.java index 55d31ec..29df28e 100644 --- a/packages/SystemUI/src/com/android/systemui/usb/UsbStorageActivity.java +++ b/packages/SystemUI/src/com/android/systemui/usb/UsbStorageActivity.java @@ -30,6 +30,7 @@ import android.content.DialogInterface.OnCancelListener; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; +import android.hardware.Usb; import android.os.Bundle; import android.os.Environment; import android.os.Handler; @@ -70,11 +71,11 @@ public class UsbStorageActivity extends Activity static final boolean localLOGV = false; /** Used to detect when the USB cable is unplugged, so we can call finish() */ - private BroadcastReceiver mBatteryReceiver = new BroadcastReceiver() { + private BroadcastReceiver mUsbStateReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - if (intent.getAction() == Intent.ACTION_BATTERY_CHANGED) { - handleBatteryChanged(intent); + if (intent.getAction().equals(Usb.ACTION_USB_STATE)) { + handleUsbStateChanged(intent); } } }; @@ -139,7 +140,7 @@ public class UsbStorageActivity extends Activity super.onResume(); mStorageManager.registerListener(mStorageListener); - registerReceiver(mBatteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); + registerReceiver(mUsbStateReceiver, new IntentFilter(Usb.ACTION_USB_STATE)); try { switchDisplay(mStorageManager.isUsbMassStorageEnabled()); } catch (Exception ex) { @@ -151,15 +152,15 @@ public class UsbStorageActivity extends Activity protected void onPause() { super.onPause(); - unregisterReceiver(mBatteryReceiver); + unregisterReceiver(mUsbStateReceiver); if (mStorageManager == null && mStorageListener != null) { mStorageManager.unregisterListener(mStorageListener); } } - private void handleBatteryChanged(Intent intent) { - int pluggedType = intent.getIntExtra("plugged", 0); - if (pluggedType == 0) { + private void handleUsbStateChanged(Intent intent) { + boolean connected = intent.getExtras().getBoolean(Usb.USB_CONNECTED); + if (!connected) { // It was disconnected from the plug, so finish finish(); } |