diff options
author | Daniel Sandler <dsandler@android.com> | 2010-11-02 21:43:11 -0400 |
---|---|---|
committer | Daniel Sandler <dsandler@android.com> | 2010-11-02 21:47:22 -0400 |
commit | 010704f95de534214cd7b86f93e22050a595dce3 (patch) | |
tree | d594deb6f0337237cc98bd15809bcd9903b9851d /packages/SystemUI/src/com/android/systemui/usb | |
parent | 4e4d0d5f207421b0a2ce134fe17d7c78defc9dac (diff) | |
download | frameworks_base-010704f95de534214cd7b86f93e22050a595dce3.zip frameworks_base-010704f95de534214cd7b86f93e22050a595dce3.tar.gz frameworks_base-010704f95de534214cd7b86f93e22050a595dce3.tar.bz2 |
UMS: Avoid SystemUI ANRs during long vold operations.
Stop handling StorageEventListener callbacks on the main
thread, where calls back into StorageManager could take a
while (i.e., during a long fsck).
Bug: 3138068
Change-Id: Icf2a836b69ff60606edce7c5575ad64dc24698c6
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/usb')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java b/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java index 47ed7da..fde62d5 100644 --- a/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java +++ b/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java @@ -23,6 +23,8 @@ import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.os.Environment; +import android.os.Handler; +import android.os.HandlerThread; import android.os.storage.StorageEventListener; import android.os.storage.StorageManager; import android.provider.Settings; @@ -60,6 +62,8 @@ public class StorageNotification extends StorageEventListener { private boolean mUmsAvailable; private StorageManager mStorageManager; + private Handler mAsyncEventHandler; + public StorageNotification(Context context) { mContext = context; @@ -67,6 +71,11 @@ public class StorageNotification extends StorageEventListener { final boolean connected = mStorageManager.isUsbMassStorageConnected(); Slog.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); } @@ -74,7 +83,16 @@ public class StorageNotification extends StorageEventListener { * @override com.android.os.storage.StorageEventListener */ @Override - public void onUsbMassStorageConnectionChanged(boolean connected) { + public void onUsbMassStorageConnectionChanged(final boolean connected) { + mAsyncEventHandler.post(new Runnable() { + @Override + public void run() { + onUsbMassStorageConnectionChangedAsync(connected); + } + }); + } + + private void onUsbMassStorageConnectionChangedAsync(boolean connected) { mUmsAvailable = connected; /* * Even though we may have a UMS host connected, we the SD card @@ -98,7 +116,16 @@ public class StorageNotification extends StorageEventListener { * @override com.android.os.storage.StorageEventListener */ @Override - public void onStorageStateChanged(String path, String oldState, String newState) { + public void onStorageStateChanged(final String path, final String oldState, final String newState) { + mAsyncEventHandler.post(new Runnable() { + @Override + public void run() { + onStorageStateChanged(path, oldState, newState); + } + }); + } + + private void onStorageStateChangedAsync(String path, String oldState, String newState) { Slog.i(TAG, String.format( "Media {%s} state changed from {%s} -> {%s}", path, oldState, newState)); if (newState.equals(Environment.MEDIA_SHARED)) { |