Decouple storage notification from status bar.
Hoist the usb storage notification listener to a top-level
system ui service, not dependent on a status bar implementation.
Change-Id: Ic9e7fba1e5bfd758d72226f6d796c2f04f6b17e6
diff --git a/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java b/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java
index a3eeb47..b75f8b3 100644
--- a/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java
+++ b/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java
@@ -31,18 +31,15 @@
import android.provider.Settings;
import android.util.Log;
-public class StorageNotification extends StorageEventListener {
+import com.android.systemui.SystemUI;
+
+public class StorageNotification extends SystemUI {
private static final String TAG = "StorageNotification";
private static final boolean DEBUG = false;
private static final boolean POP_UMS_ACTIVITY_ON_CONNECT = true;
/**
- * Binder context for this service
- */
- private Context mContext;
-
- /**
* The notification that is shown when a USB mass storage host
* is connected.
* <p>
@@ -66,32 +63,40 @@
private Handler mAsyncEventHandler;
- public StorageNotification(Context context) {
- mContext = context;
+ private class StorageNotificationEventListener extends StorageEventListener {
+ public void onUsbMassStorageConnectionChanged(final boolean connected) {
+ mAsyncEventHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ onUsbMassStorageConnectionChangedAsync(connected);
+ }
+ });
+ }
+ public void onStorageStateChanged(final String path,
+ final String oldState, final String newState) {
+ mAsyncEventHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ onStorageStateChangedAsync(path, oldState, newState);
+ }
+ });
+ }
+ }
- mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
+ @Override
+ public void start() {
+ mStorageManager = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
final boolean connected = mStorageManager.isUsbMassStorageConnected();
if (DEBUG) Log.d(TAG, String.format( "Startup with UMS connection %s (media state %s)",
mUmsAvailable, Environment.getExternalStorageState()));
-
+
HandlerThread thr = new HandlerThread("SystemUI StorageNotification");
thr.start();
mAsyncEventHandler = new Handler(thr.getLooper());
- onUsbMassStorageConnectionChanged(connected);
- }
-
- /*
- * @override com.android.os.storage.StorageEventListener
- */
- @Override
- public void onUsbMassStorageConnectionChanged(final boolean connected) {
- mAsyncEventHandler.post(new Runnable() {
- @Override
- public void run() {
- onUsbMassStorageConnectionChangedAsync(connected);
- }
- });
+ StorageNotificationEventListener listener = new StorageNotificationEventListener();
+ listener.onUsbMassStorageConnectionChanged(connected);
+ mStorageManager.registerListener(listener);
}
private void onUsbMassStorageConnectionChangedAsync(boolean connected) {
@@ -115,19 +120,6 @@
updateUsbMassStorageNotification(connected);
}
- /*
- * @override com.android.os.storage.StorageEventListener
- */
- @Override
- public void onStorageStateChanged(final String path, final String oldState, final String newState) {
- mAsyncEventHandler.post(new Runnable() {
- @Override
- public void run() {
- onStorageStateChangedAsync(path, oldState, newState);
- }
- });
- }
-
private void onStorageStateChangedAsync(String path, String oldState, String newState) {
if (DEBUG) Log.i(TAG, String.format(
"Media {%s} state changed from {%s} -> {%s}", path, oldState, newState));