Merge "Prevent system_server shutdown when trying to format external storage"

This commit is contained in:
Jeff Sharkey
2014-08-12 22:12:17 +00:00
committed by Gerrit Code Review
2 changed files with 23 additions and 0 deletions

View File

@ -25,6 +25,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.storage.StorageVolume;
import android.util.Log;
/**
@ -95,6 +96,10 @@ public class ExternalMediaFormatActivity extends AlertActivity implements Dialog
if (which == POSITIVE_BUTTON) {
Intent intent = new Intent(ExternalStorageFormatter.FORMAT_ONLY);
intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME);
// Transfer the storage volume to the new intent
final StorageVolume storageVolume = getIntent().getParcelableExtra(
StorageVolume.EXTRA_STORAGE_VOLUME);
intent.putExtra(StorageVolume.EXTRA_STORAGE_VOLUME, storageVolume);
startService(intent);
}

View File

@ -28,6 +28,7 @@ import android.os.HandlerThread;
import android.os.UserHandle;
import android.os.storage.StorageEventListener;
import android.os.storage.StorageManager;
import android.os.storage.StorageVolume;
import android.provider.Settings;
import android.util.Log;
@ -198,6 +199,8 @@ public class StorageNotification extends SystemUI {
*/
Intent intent = new Intent();
intent.setClass(mContext, com.android.internal.app.ExternalMediaFormatActivity.class);
intent.putExtra(StorageVolume.EXTRA_STORAGE_VOLUME,
getVolumeByPath(mStorageManager.getVolumeList(), path));
PendingIntent pi = PendingIntent.getActivity(mContext, 0, intent, 0);
setMediaStorageNotification(
@ -212,6 +215,8 @@ public class StorageNotification extends SystemUI {
*/
Intent intent = new Intent();
intent.setClass(mContext, com.android.internal.app.ExternalMediaFormatActivity.class);
intent.putExtra(StorageVolume.EXTRA_STORAGE_VOLUME,
getVolumeByPath(mStorageManager.getVolumeList(), path));
PendingIntent pi = PendingIntent.getActivity(mContext, 0, intent, 0);
setMediaStorageNotification(
@ -246,6 +251,19 @@ public class StorageNotification extends SystemUI {
}
}
/**
* Get the corresponding StorageVolume object for a specific path.
*/
private final StorageVolume getVolumeByPath(StorageVolume[] volumes, String path) {
for (StorageVolume volume : volumes) {
if (volume.getPath().equals(path)) {
return volume;
}
}
Log.w(TAG, "No storage found");
return null;
}
/**
* Update the state of the USB mass storage notification
*/