Permalink
Browse files

Show additional toast when SD card has finished being shared.

Change-Id: I614188bd902e9a4dabcbd3a26c1b6f9dd7b78edf
  • Loading branch information...
1 parent 516d7f7 commit 6f3eee67eaea400af45f69a25c354d3c81edcf39 @maniac103 maniac103 committed Aug 24, 2011
Showing with 49 additions and 16 deletions.
  1. +2 −0 res/values-de/strings.xml
  2. +2 −0 res/values/strings.xml
  3. +45 −16 src/com/motorola/usb/UsbService.java
@@ -14,4 +14,6 @@
<string name="usb_mode_modem">Telefon als Modem</string>
<string name="usb_mode_none">Nur Laden</string>
<string name="usb_error_message">Die USB-Verbindung kann nicht zu \'%s\' geändert werden.</string>
+ <string name="preparing_ums">Die Speicherkarte wird vorbereitet.</string>
+ <string name="ums_ready">Auf die Speicherkarte kann nun via USB zugegriffen werden.</string>
</resources>
View
@@ -14,4 +14,6 @@
<string name="usb_mode_modem">Phone as Modem</string>
<string name="usb_mode_none">Charge Only</string>
<string name="usb_error_message">The USB connection cannot be changed to %s.</string>
+ <string name="preparing_ums">Preparing storage card.</string>
+ <string name="ums_ready">The storage card is shared via USB.</string>
</resources>
@@ -35,6 +35,7 @@
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.UEventObserver;
+import android.os.storage.StorageEventListener;
import android.os.storage.StorageManager;
import android.util.Log;
import android.widget.Toast;
@@ -212,6 +213,7 @@ public ModeInfo(String name, String mode, String adbMode) {
private boolean mRndisServiceStopped = false;
private int mADBStatusChangeMissedNumber = 0;
private boolean mMediaMountedReceiverRegistered = false;
+ private boolean mPreparingUms = false;
private UsbListener mUsbListener;
private File mCurrentStateFile;
@@ -224,6 +226,7 @@ public ModeInfo(String name, String mode, String adbMode) {
private NotificationManager mNotifManager;
private Handler mStorageHandler;
+ private Toast mConnectedToast;
private Handler mHandler = new Handler() {
@Override
@@ -294,6 +297,21 @@ public void onReceive(Context context, Intent intent) {
}
};
+ private StorageEventListener mStorageListener = new StorageEventListener() {
+ @Override
+ public void onStorageStateChanged(String path, String oldState, String newState) {
+ if (mPreparingUms && newState.equals(Environment.MEDIA_SHARED)) {
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ Toast.makeText(UsbService.this, R.string.ums_ready, Toast.LENGTH_SHORT).show();
+ mPreparingUms = false;
+ }
+ });
+ }
+ }
+ };
+
private BroadcastReceiver mMediaMountedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@@ -371,15 +389,18 @@ public void onCreate() {
storageThread.start();
mStorageHandler = new Handler(storageThread.getLooper());
+ mStorageManager.registerListener(mStorageListener);
+
mUsbListener = new UsbListener(mHandler);
new Thread(mUsbListener, UsbListener.class.getName()).start();
mUEventObserver.startObserving("DEVPATH=/devices/virtual/misc/usbnet_enable");
}
@Override
public void onDestroy() {
- onDestroy();
unregisterReceiver(mUsbServiceReceiver);
+ mStorageManager.unregisterListener(mStorageListener);
+ super.onDestroy();
}
private synchronized void handleUsbEvent(int event) {
@@ -444,7 +465,7 @@ private synchronized void handleUsbEvent(int event) {
case USB_STATE_SERVICE_STARTUP:
if (event == EVENT_START_SERVICE) {
deviceEnumPostAction();
- mUsbState = USB_STATE_SERVICE_STARTUP;
+ showConnectedToast(currentMode);
} else if (event == EVENT_CABLE_REMOVED) {
mUsbState = USB_STATE_DETACH_DEVNOD_CLOSE;
deviceEnumPreAction();
@@ -740,6 +761,7 @@ private int getStringResForMode(int mode) {
private void changeMassStorageMode(final boolean enable) {
Log.d(TAG, "changeMassStorageMode(), enable " + enable);
+ mPreparingUms = enable;
mStorageHandler.post(new Runnable() {
@Override
public void run() {
@@ -865,11 +887,24 @@ private void showConnectedToast(int mode) {
}
String toast = getString(R.string.usb_toast_connecting, getString(resId));
- if (getCurrentUsbMode() == USB_MODE_MODEM) {
+ int currentMode = getCurrentUsbMode();
+
+ if (currentMode == USB_MODE_MODEM) {
toast += " ";
toast += getString(R.string.usb_toast_phone_data_disabled);
+ } else if (currentMode == USB_MODE_MSC && mPreparingUms) {
+ toast += " ";
+ toast += getString(R.string.preparing_ums);
+ }
+
+ if (mConnectedToast == null) {
+ mConnectedToast = Toast.makeText(UsbService.this, toast, Toast.LENGTH_LONG);
+ } else {
+ mConnectedToast.cancel();
+ mConnectedToast.setText(toast);
}
- Toast.makeText(UsbService.this, toast, Toast.LENGTH_LONG).show();
+
+ mConnectedToast.show();
}
private void setUsbModeFromUI(int mode) {
@@ -909,18 +944,12 @@ public void handleGetDescriptor() {
Log.d(TAG, "handleGetDescriptor()");
mUsbCableAttached = true;
- try {
- int currentMode = getCurrentUsbMode();
- showConnectedToast(currentMode);
- setUsbConnectionNotificationVisibility(true, true);
- enableInternalDataConnectivity(currentMode != USB_MODE_MODEM);
- sendBroadcast(new Intent(ACTION_CABLE_ATTACHED));
- emitReconfigurationIntent(true);
- updateUsbStateFile(true, currentMode);
- } catch (IllegalStateException ex) {
- Log.d(TAG, "handleGetDescriptor(), show toast exception");
- SystemClock.sleep(500);
- }
+ int currentMode = getCurrentUsbMode();
+ setUsbConnectionNotificationVisibility(true, true);
+ enableInternalDataConnectivity(currentMode != USB_MODE_MODEM);
+ sendBroadcast(new Intent(ACTION_CABLE_ATTACHED));
+ emitReconfigurationIntent(true);
+ updateUsbStateFile(true, currentMode);
}
public void handleStartService(String event) {

0 comments on commit 6f3eee6

Please sign in to comment.