am 0100625b: Merge "Fix bug #6522190 MountService should respond to configuration changes ("INTERNAL STORAGE" string should be translated dynamically)" into jb-dev

* commit '0100625bb316ecbd99873b72756ffba8613c3456':
  Fix bug #6522190 MountService should respond to configuration changes ("INTERNAL STORAGE" string should be translated dynamically)
This commit is contained in:
Fabrice Di Meglio
2012-05-24 10:45:54 -07:00
committed by Android Git Automerger
3 changed files with 27 additions and 18 deletions

View File

@@ -16,6 +16,7 @@
package android.os.storage; package android.os.storage;
import android.content.Context;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
@@ -28,7 +29,7 @@ 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 int mDescriptionId;
private final boolean mRemovable; private final boolean mRemovable;
private final boolean mEmulated; private final boolean mEmulated;
private final int mMtpReserveSpace; private final int mMtpReserveSpace;
@@ -42,10 +43,10 @@ public class StorageVolume implements Parcelable {
// ACTION_MEDIA_BAD_REMOVAL, ACTION_MEDIA_UNMOUNTABLE and ACTION_MEDIA_EJECT broadcasts. // ACTION_MEDIA_BAD_REMOVAL, ACTION_MEDIA_UNMOUNTABLE and ACTION_MEDIA_EJECT broadcasts.
public static final String EXTRA_STORAGE_VOLUME = "storage_volume"; public static final String EXTRA_STORAGE_VOLUME = "storage_volume";
public StorageVolume(String path, String description, boolean removable, public StorageVolume(String path, int descriptionId, boolean removable,
boolean emulated, int mtpReserveSpace, boolean allowMassStorage, long maxFileSize) { boolean emulated, int mtpReserveSpace, boolean allowMassStorage, long maxFileSize) {
mPath = path; mPath = path;
mDescription = description; mDescriptionId = descriptionId;
mRemovable = removable; mRemovable = removable;
mEmulated = emulated; mEmulated = emulated;
mMtpReserveSpace = mtpReserveSpace; mMtpReserveSpace = mtpReserveSpace;
@@ -54,11 +55,11 @@ public class StorageVolume implements Parcelable {
} }
// for parcelling only // for parcelling only
private StorageVolume(String path, String description, boolean removable, private StorageVolume(String path, int descriptionId, boolean removable,
boolean emulated, int mtpReserveSpace, int storageId, boolean emulated, int mtpReserveSpace, int storageId,
boolean allowMassStorage, long maxFileSize) { boolean allowMassStorage, long maxFileSize) {
mPath = path; mPath = path;
mDescription = description; mDescriptionId = descriptionId;
mRemovable = removable; mRemovable = removable;
mEmulated = emulated; mEmulated = emulated;
mMtpReserveSpace = mtpReserveSpace; mMtpReserveSpace = mtpReserveSpace;
@@ -81,8 +82,12 @@ public class StorageVolume implements Parcelable {
* *
* @return the volume description * @return the volume description
*/ */
public String getDescription() { public String getDescription(Context context) {
return mDescription; return context.getResources().getString(mDescriptionId);
}
public int getDescriptionId() {
return mDescriptionId;
} }
/** /**
@@ -172,8 +177,8 @@ public class StorageVolume implements Parcelable {
@Override @Override
public String toString() { public String toString() {
return "StorageVolume [mAllowMassStorage=" + mAllowMassStorage + ", mDescription=" return "StorageVolume [mAllowMassStorage=" + mAllowMassStorage + ", mDescriptionId="
+ mDescription + ", mEmulated=" + mEmulated + ", mMaxFileSize=" + mMaxFileSize + mDescriptionId + ", mEmulated=" + mEmulated + ", mMaxFileSize=" + mMaxFileSize
+ ", mMtpReserveSpace=" + mMtpReserveSpace + ", mPath=" + mPath + ", mRemovable=" + ", mMtpReserveSpace=" + mMtpReserveSpace + ", mPath=" + mPath + ", mRemovable="
+ mRemovable + ", mStorageId=" + mStorageId + "]"; + mRemovable + ", mStorageId=" + mStorageId + "]";
} }
@@ -182,14 +187,14 @@ public class StorageVolume implements Parcelable {
new Parcelable.Creator<StorageVolume>() { new Parcelable.Creator<StorageVolume>() {
public StorageVolume createFromParcel(Parcel in) { public StorageVolume createFromParcel(Parcel in) {
String path = in.readString(); String path = in.readString();
String description = in.readString(); int descriptionId = in.readInt();
int removable = in.readInt(); int removable = in.readInt();
int emulated = in.readInt(); int emulated = in.readInt();
int storageId = in.readInt(); int storageId = in.readInt();
int mtpReserveSpace = in.readInt(); int mtpReserveSpace = in.readInt();
int allowMassStorage = in.readInt(); int allowMassStorage = in.readInt();
long maxFileSize = in.readLong(); long maxFileSize = in.readLong();
return new StorageVolume(path, description, return new StorageVolume(path, descriptionId,
removable == 1, emulated == 1, mtpReserveSpace, removable == 1, emulated == 1, mtpReserveSpace,
storageId, allowMassStorage == 1, maxFileSize); storageId, allowMassStorage == 1, maxFileSize);
} }
@@ -205,7 +210,7 @@ public class StorageVolume implements Parcelable {
public void writeToParcel(Parcel parcel, int flags) { public void writeToParcel(Parcel parcel, int flags) {
parcel.writeString(mPath); parcel.writeString(mPath);
parcel.writeString(mDescription); parcel.writeInt(mDescriptionId);
parcel.writeInt(mRemovable ? 1 : 0); parcel.writeInt(mRemovable ? 1 : 0);
parcel.writeInt(mEmulated ? 1 : 0); parcel.writeInt(mEmulated ? 1 : 0);
parcel.writeInt(mStorageId); parcel.writeInt(mStorageId);

View File

@@ -16,6 +16,7 @@
package android.mtp; package android.mtp;
import android.content.Context;
import android.os.storage.StorageVolume; import android.os.storage.StorageVolume;
/** /**
@@ -34,10 +35,10 @@ public class MtpStorage {
private final boolean mRemovable; private final boolean mRemovable;
private final long mMaxFileSize; private final long mMaxFileSize;
public MtpStorage(StorageVolume volume) { public MtpStorage(StorageVolume volume, Context context) {
mStorageId = volume.getStorageId(); mStorageId = volume.getStorageId();
mPath = volume.getPath(); mPath = volume.getPath();
mDescription = volume.getDescription(); mDescription = context.getResources().getString(volume.getDescriptionId());
mReserveSpace = volume.getMtpReserveSpace(); mReserveSpace = volume.getMtpReserveSpace();
mRemovable = volume.isRemovable(); mRemovable = volume.isRemovable();
mMaxFileSize = volume.getMaxFileSize(); mMaxFileSize = volume.getMaxFileSize();

View File

@@ -1065,7 +1065,9 @@ class MountService extends IMountService.Stub
private static final String TAG_STORAGE_LIST = "StorageList"; private static final String TAG_STORAGE_LIST = "StorageList";
private static final String TAG_STORAGE = "storage"; private static final String TAG_STORAGE = "storage";
private void readStorageList(Resources resources) { private void readStorageList() {
Resources resources = mContext.getResources();
int id = com.android.internal.R.xml.storage_list; int id = com.android.internal.R.xml.storage_list;
XmlResourceParser parser = resources.getXml(id); XmlResourceParser parser = resources.getXml(id);
AttributeSet attrs = Xml.asAttributeSet(parser); AttributeSet attrs = Xml.asAttributeSet(parser);
@@ -1084,6 +1086,8 @@ class MountService extends IMountService.Stub
CharSequence path = a.getText( CharSequence path = a.getText(
com.android.internal.R.styleable.Storage_mountPoint); com.android.internal.R.styleable.Storage_mountPoint);
int descriptionId = a.getResourceId(
com.android.internal.R.styleable.Storage_storageDescription, -1);
CharSequence description = a.getText( CharSequence description = a.getText(
com.android.internal.R.styleable.Storage_storageDescription); com.android.internal.R.styleable.Storage_storageDescription);
boolean primary = a.getBoolean( boolean primary = a.getBoolean(
@@ -1110,7 +1114,7 @@ class MountService extends IMountService.Stub
} else { } else {
String pathString = path.toString(); String pathString = path.toString();
StorageVolume volume = new StorageVolume(pathString, StorageVolume volume = new StorageVolume(pathString,
description.toString(), removable, emulated, descriptionId, removable, emulated,
mtpReserve, allowMassStorage, maxFileSize); mtpReserve, allowMassStorage, maxFileSize);
if (primary) { if (primary) {
if (mPrimaryVolume == null) { if (mPrimaryVolume == null) {
@@ -1151,8 +1155,7 @@ class MountService extends IMountService.Stub
*/ */
public MountService(Context context) { public MountService(Context context) {
mContext = context; mContext = context;
Resources resources = context.getResources(); readStorageList();
readStorageList(resources);
if (mPrimaryVolume != null) { if (mPrimaryVolume != null) {
mExternalStoragePath = mPrimaryVolume.getPath(); mExternalStoragePath = mPrimaryVolume.getPath();