am 92630c78: Merge "SystemUI: Use new USB notifications to detect USB disconnect." into gingerbread
Merge commit '92630c787d0ae34c7ae3cb29c2d261f1acaf18b9' into gingerbread-plus-aosp * commit '92630c787d0ae34c7ae3cb29c2d261f1acaf18b9': SystemUI: Use new USB notifications to detect USB disconnect.
This commit is contained in:
@@ -30,6 +30,7 @@ import android.content.DialogInterface.OnCancelListener;
|
|||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
|
import android.hardware.Usb;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@@ -70,11 +71,11 @@ public class UsbStorageActivity extends Activity
|
|||||||
static final boolean localLOGV = false;
|
static final boolean localLOGV = false;
|
||||||
|
|
||||||
/** Used to detect when the USB cable is unplugged, so we can call finish() */
|
/** 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
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (intent.getAction() == Intent.ACTION_BATTERY_CHANGED) {
|
if (intent.getAction().equals(Usb.ACTION_USB_STATE)) {
|
||||||
handleBatteryChanged(intent);
|
handleUsbStateChanged(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -139,7 +140,7 @@ public class UsbStorageActivity extends Activity
|
|||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
mStorageManager.registerListener(mStorageListener);
|
mStorageManager.registerListener(mStorageListener);
|
||||||
registerReceiver(mBatteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
registerReceiver(mUsbStateReceiver, new IntentFilter(Usb.ACTION_USB_STATE));
|
||||||
try {
|
try {
|
||||||
switchDisplay(mStorageManager.isUsbMassStorageEnabled());
|
switchDisplay(mStorageManager.isUsbMassStorageEnabled());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@@ -151,15 +152,15 @@ public class UsbStorageActivity extends Activity
|
|||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
|
||||||
unregisterReceiver(mBatteryReceiver);
|
unregisterReceiver(mUsbStateReceiver);
|
||||||
if (mStorageManager == null && mStorageListener != null) {
|
if (mStorageManager == null && mStorageListener != null) {
|
||||||
mStorageManager.unregisterListener(mStorageListener);
|
mStorageManager.unregisterListener(mStorageListener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleBatteryChanged(Intent intent) {
|
private void handleUsbStateChanged(Intent intent) {
|
||||||
int pluggedType = intent.getIntExtra("plugged", 0);
|
boolean connected = intent.getExtras().getBoolean(Usb.USB_CONNECTED);
|
||||||
if (pluggedType == 0) {
|
if (!connected) {
|
||||||
// It was disconnected from the plug, so finish
|
// It was disconnected from the plug, so finish
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user