Merge "ExternalStorageFormatter takes an optional StorageVolume target." into honeycomb-mr2
This commit is contained in:
committed by
Android (Google) Code Review
commit
24de44a187
@@ -16,16 +16,6 @@
|
|||||||
|
|
||||||
package android.content;
|
package android.content;
|
||||||
|
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
|
||||||
import org.xmlpull.v1.XmlSerializer;
|
|
||||||
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@@ -37,6 +27,15 @@ import android.util.Printer;
|
|||||||
|
|
||||||
import com.android.internal.util.XmlUtils;
|
import com.android.internal.util.XmlUtils;
|
||||||
|
|
||||||
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
import org.xmlpull.v1.XmlSerializer;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Structured description of Intent values to be matched. An IntentFilter can
|
* Structured description of Intent values to be matched. An IntentFilter can
|
||||||
* match against actions, categories, and data (either via its type, scheme,
|
* match against actions, categories, and data (either via its type, scheme,
|
||||||
@@ -755,7 +754,7 @@ public class IntentFilter implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new Intent data oath to match against. The filter must
|
* Add a new Intent data path to match against. The filter must
|
||||||
* include one or more schemes (via {@link #addDataScheme}) <em>and</em>
|
* include one or more schemes (via {@link #addDataScheme}) <em>and</em>
|
||||||
* one or more authorities (via {@link #addDataAuthority}) for the
|
* one or more authorities (via {@link #addDataAuthority}) for the
|
||||||
* path to be considered. If any paths are
|
* path to be considered. If any paths are
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import android.os.Parcelable;
|
|||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Slog;
|
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
@@ -100,10 +99,11 @@ public class StorageManager
|
|||||||
private final ObbActionListener mObbActionListener = new ObbActionListener();
|
private final ObbActionListener mObbActionListener = new ObbActionListener();
|
||||||
|
|
||||||
private class ObbActionListener extends IObbActionListener.Stub {
|
private class ObbActionListener extends IObbActionListener.Stub {
|
||||||
|
@SuppressWarnings("hiding")
|
||||||
private SparseArray<ObbListenerDelegate> mListeners = new SparseArray<ObbListenerDelegate>();
|
private SparseArray<ObbListenerDelegate> mListeners = new SparseArray<ObbListenerDelegate>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onObbResult(String filename, int nonce, int status) throws RemoteException {
|
public void onObbResult(String filename, int nonce, int status) {
|
||||||
final ObbListenerDelegate delegate;
|
final ObbListenerDelegate delegate;
|
||||||
synchronized (mListeners) {
|
synchronized (mListeners) {
|
||||||
delegate = mListeners.get(nonce);
|
delegate = mListeners.get(nonce);
|
||||||
@@ -147,8 +147,8 @@ public class StorageManager
|
|||||||
mHandler = new Handler(mTgtLooper) {
|
mHandler = new Handler(mTgtLooper) {
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(Message msg) {
|
||||||
final OnObbStateChangeListener listener = getListener();
|
final OnObbStateChangeListener changeListener = getListener();
|
||||||
if (listener == null) {
|
if (changeListener == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,7 +156,7 @@ public class StorageManager
|
|||||||
|
|
||||||
if (msg.what == StorageEvent.EVENT_OBB_STATE_CHANGED) {
|
if (msg.what == StorageEvent.EVENT_OBB_STATE_CHANGED) {
|
||||||
ObbStateChangedStorageEvent ev = (ObbStateChangedStorageEvent) e;
|
ObbStateChangedStorageEvent ev = (ObbStateChangedStorageEvent) e;
|
||||||
listener.onObbStateChange(ev.path, ev.state);
|
changeListener.onObbStateChange(ev.path, ev.state);
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "Unsupported event " + msg.what);
|
Log.e(TAG, "Unsupported event " + msg.what);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,8 @@
|
|||||||
|
|
||||||
package android.os.storage;
|
package android.os.storage;
|
||||||
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class representing a storage volume
|
* A class representing a storage volume
|
||||||
@@ -27,7 +25,7 @@ import android.util.Log;
|
|||||||
*/
|
*/
|
||||||
public class StorageVolume implements Parcelable {
|
public class StorageVolume implements Parcelable {
|
||||||
|
|
||||||
private static final String TAG = "StorageVolume";
|
//private static final String TAG = "StorageVolume";
|
||||||
|
|
||||||
private final String mPath;
|
private final String mPath;
|
||||||
private final String mDescription;
|
private final String mDescription;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import android.os.ServiceManager;
|
|||||||
import android.os.storage.IMountService;
|
import android.os.storage.IMountService;
|
||||||
import android.os.storage.StorageEventListener;
|
import android.os.storage.StorageEventListener;
|
||||||
import android.os.storage.StorageManager;
|
import android.os.storage.StorageManager;
|
||||||
|
import android.os.storage.StorageVolume;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@@ -32,6 +33,9 @@ public class ExternalStorageFormatter extends Service
|
|||||||
|
|
||||||
public static final String EXTRA_ALWAYS_RESET = "always_reset";
|
public static final String EXTRA_ALWAYS_RESET = "always_reset";
|
||||||
|
|
||||||
|
// If non-null, the volume to format. Otherwise, will use the default external storage directory
|
||||||
|
private StorageVolume mStorageVolume;
|
||||||
|
|
||||||
public static final ComponentName COMPONENT_NAME
|
public static final ComponentName COMPONENT_NAME
|
||||||
= new ComponentName("android", ExternalStorageFormatter.class.getName());
|
= new ComponentName("android", ExternalStorageFormatter.class.getName());
|
||||||
|
|
||||||
@@ -80,6 +84,8 @@ public class ExternalStorageFormatter extends Service
|
|||||||
mAlwaysReset = true;
|
mAlwaysReset = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mStorageVolume = intent.getParcelableExtra(StorageVolume.EXTRA_STORAGE_VOLUME);
|
||||||
|
|
||||||
if (mProgressDialog == null) {
|
if (mProgressDialog == null) {
|
||||||
mProgressDialog = new ProgressDialog(this);
|
mProgressDialog = new ProgressDialog(this);
|
||||||
mProgressDialog.setIndeterminate(true);
|
mProgressDialog.setIndeterminate(true);
|
||||||
@@ -115,7 +121,9 @@ public class ExternalStorageFormatter extends Service
|
|||||||
@Override
|
@Override
|
||||||
public void onCancel(DialogInterface dialog) {
|
public void onCancel(DialogInterface dialog) {
|
||||||
IMountService mountService = getMountService();
|
IMountService mountService = getMountService();
|
||||||
String extStoragePath = Environment.getExternalStorageDirectory().toString();
|
String extStoragePath = mStorageVolume == null ?
|
||||||
|
Environment.getExternalStorageDirectory().toString() :
|
||||||
|
mStorageVolume.getPath();
|
||||||
try {
|
try {
|
||||||
mountService.mountVolume(extStoragePath);
|
mountService.mountVolume(extStoragePath);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
@@ -133,12 +141,16 @@ public class ExternalStorageFormatter extends Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
void updateProgressState() {
|
void updateProgressState() {
|
||||||
String status = Environment.getExternalStorageState();
|
String status = mStorageVolume == null ?
|
||||||
|
Environment.getExternalStorageState() :
|
||||||
|
mStorageManager.getVolumeState(mStorageVolume.getPath());
|
||||||
if (Environment.MEDIA_MOUNTED.equals(status)
|
if (Environment.MEDIA_MOUNTED.equals(status)
|
||||||
|| Environment.MEDIA_MOUNTED_READ_ONLY.equals(status)) {
|
|| Environment.MEDIA_MOUNTED_READ_ONLY.equals(status)) {
|
||||||
updateProgressDialog(R.string.progress_unmounting);
|
updateProgressDialog(R.string.progress_unmounting);
|
||||||
IMountService mountService = getMountService();
|
IMountService mountService = getMountService();
|
||||||
String extStoragePath = Environment.getExternalStorageDirectory().toString();
|
final String extStoragePath = mStorageVolume == null ?
|
||||||
|
Environment.getExternalStorageDirectory().toString() :
|
||||||
|
mStorageVolume.getPath();
|
||||||
try {
|
try {
|
||||||
mountService.unmountVolume(extStoragePath, true);
|
mountService.unmountVolume(extStoragePath, true);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
@@ -149,9 +161,12 @@ public class ExternalStorageFormatter extends Service
|
|||||||
|| Environment.MEDIA_UNMOUNTABLE.equals(status)) {
|
|| Environment.MEDIA_UNMOUNTABLE.equals(status)) {
|
||||||
updateProgressDialog(R.string.progress_erasing);
|
updateProgressDialog(R.string.progress_erasing);
|
||||||
final IMountService mountService = getMountService();
|
final IMountService mountService = getMountService();
|
||||||
final String extStoragePath = Environment.getExternalStorageDirectory().toString();
|
final String extStoragePath = mStorageVolume == null ?
|
||||||
|
Environment.getExternalStorageDirectory().toString() :
|
||||||
|
mStorageVolume.getPath();
|
||||||
if (mountService != null) {
|
if (mountService != null) {
|
||||||
new Thread() {
|
new Thread() {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
try {
|
try {
|
||||||
@@ -185,7 +200,7 @@ public class ExternalStorageFormatter extends Service
|
|||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
} else {
|
} else {
|
||||||
Log.w("MediaFormat", "Unable to locate IMountService");
|
Log.w(TAG, "Unable to locate IMountService");
|
||||||
}
|
}
|
||||||
} else if (Environment.MEDIA_BAD_REMOVAL.equals(status)) {
|
} else if (Environment.MEDIA_BAD_REMOVAL.equals(status)) {
|
||||||
fail(R.string.media_bad_removal);
|
fail(R.string.media_bad_removal);
|
||||||
|
|||||||
Reference in New Issue
Block a user