Permalink
Browse files

Asynchronously talk to storage manager.

Change-Id: I6ca18926b97a0e2913c1cf2825be140a4460fafb
  • Loading branch information...
1 parent ab33eff commit 516d7f7a081ff6ebbba6531c5f89a46cf84748eb @maniac103 maniac103 committed Aug 24, 2011
Showing with 19 additions and 7 deletions.
  1. +19 −7 src/com/motorola/usb/UsbService.java
@@ -28,6 +28,7 @@
import android.content.res.Resources;
import android.os.Environment;
import android.os.Handler;
+import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Message;
import android.os.RemoteException;
@@ -222,6 +223,8 @@ public ModeInfo(String name, String mode, String adbMode) {
private StorageManager mStorageManager;
private NotificationManager mNotifManager;
+ private Handler mStorageHandler;
+
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
@@ -364,6 +367,10 @@ public void onCreate() {
mStorageManager = (StorageManager) getSystemService(STORAGE_SERVICE);
mNotifManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+ HandlerThread storageThread = new HandlerThread("Usb switching storage handler");
+ storageThread.start();
+ mStorageHandler = new Handler(storageThread.getLooper());
+
mUsbListener = new UsbListener(mHandler);
new Thread(mUsbListener, UsbListener.class.getName()).start();
mUEventObserver.startObserving("DEVPATH=/devices/virtual/misc/usbnet_enable");
@@ -730,15 +737,20 @@ private int getStringResForMode(int mode) {
return -1;
}
- private void changeMassStorageMode(boolean enable) {
+ private void changeMassStorageMode(final boolean enable) {
Log.d(TAG, "changeMassStorageMode(), enable " + enable);
- if (enable) {
- mStorageManager.enableUsbMassStorage();
- } else {
- mStorageManager.disableUsbMassStorage();
- }
- sendBroadcast(new Intent(enable ? ACTION_ENTER_MSC : ACTION_EXIT_MSC));
+ mStorageHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ if (enable) {
+ mStorageManager.enableUsbMassStorage();
+ } else {
+ mStorageManager.disableUsbMassStorage();
+ }
+ sendBroadcast(new Intent(enable ? ACTION_ENTER_MSC : ACTION_EXIT_MSC));
+ }
+ });
}
private void enableInternalDataConnectivity(boolean enable) {

0 comments on commit 516d7f7

Please sign in to comment.