Skip to content

Commit 0100625

Browse files
Fabrice Di MeglioAndroid (Google) Code Review
authored andcommitted
Merge "Fix bug #6522190 MountService should respond to configuration changes ("INTERNAL STORAGE" string should be translated dynamically)" into jb-dev
2 parents 222f561 + 13fe2a5 commit 0100625

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

core/java/android/os/storage/StorageVolume.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package android.os.storage;
1818

19+
import android.content.Context;
1920
import android.os.Parcel;
2021
import android.os.Parcelable;
2122

@@ -28,7 +29,7 @@ public class StorageVolume implements Parcelable {
2829
//private static final String TAG = "StorageVolume";
2930

3031
private final String mPath;
31-
private final String mDescription;
32+
private final int mDescriptionId;
3233
private final boolean mRemovable;
3334
private final boolean mEmulated;
3435
private final int mMtpReserveSpace;
@@ -42,10 +43,10 @@ public class StorageVolume implements Parcelable {
4243
// ACTION_MEDIA_BAD_REMOVAL, ACTION_MEDIA_UNMOUNTABLE and ACTION_MEDIA_EJECT broadcasts.
4344
public static final String EXTRA_STORAGE_VOLUME = "storage_volume";
4445

45-
public StorageVolume(String path, String description, boolean removable,
46+
public StorageVolume(String path, int descriptionId, boolean removable,
4647
boolean emulated, int mtpReserveSpace, boolean allowMassStorage, long maxFileSize) {
4748
mPath = path;
48-
mDescription = description;
49+
mDescriptionId = descriptionId;
4950
mRemovable = removable;
5051
mEmulated = emulated;
5152
mMtpReserveSpace = mtpReserveSpace;
@@ -54,11 +55,11 @@ public StorageVolume(String path, String description, boolean removable,
5455
}
5556

5657
// for parcelling only
57-
private StorageVolume(String path, String description, boolean removable,
58+
private StorageVolume(String path, int descriptionId, boolean removable,
5859
boolean emulated, int mtpReserveSpace, int storageId,
5960
boolean allowMassStorage, long maxFileSize) {
6061
mPath = path;
61-
mDescription = description;
62+
mDescriptionId = descriptionId;
6263
mRemovable = removable;
6364
mEmulated = emulated;
6465
mMtpReserveSpace = mtpReserveSpace;
@@ -81,8 +82,12 @@ public String getPath() {
8182
*
8283
* @return the volume description
8384
*/
84-
public String getDescription() {
85-
return mDescription;
85+
public String getDescription(Context context) {
86+
return context.getResources().getString(mDescriptionId);
87+
}
88+
89+
public int getDescriptionId() {
90+
return mDescriptionId;
8691
}
8792

8893
/**
@@ -172,8 +177,8 @@ public int hashCode() {
172177

173178
@Override
174179
public String toString() {
175-
return "StorageVolume [mAllowMassStorage=" + mAllowMassStorage + ", mDescription="
176-
+ mDescription + ", mEmulated=" + mEmulated + ", mMaxFileSize=" + mMaxFileSize
180+
return "StorageVolume [mAllowMassStorage=" + mAllowMassStorage + ", mDescriptionId="
181+
+ mDescriptionId + ", mEmulated=" + mEmulated + ", mMaxFileSize=" + mMaxFileSize
177182
+ ", mMtpReserveSpace=" + mMtpReserveSpace + ", mPath=" + mPath + ", mRemovable="
178183
+ mRemovable + ", mStorageId=" + mStorageId + "]";
179184
}
@@ -182,14 +187,14 @@ public String toString() {
182187
new Parcelable.Creator<StorageVolume>() {
183188
public StorageVolume createFromParcel(Parcel in) {
184189
String path = in.readString();
185-
String description = in.readString();
190+
int descriptionId = in.readInt();
186191
int removable = in.readInt();
187192
int emulated = in.readInt();
188193
int storageId = in.readInt();
189194
int mtpReserveSpace = in.readInt();
190195
int allowMassStorage = in.readInt();
191196
long maxFileSize = in.readLong();
192-
return new StorageVolume(path, description,
197+
return new StorageVolume(path, descriptionId,
193198
removable == 1, emulated == 1, mtpReserveSpace,
194199
storageId, allowMassStorage == 1, maxFileSize);
195200
}
@@ -205,7 +210,7 @@ public int describeContents() {
205210

206211
public void writeToParcel(Parcel parcel, int flags) {
207212
parcel.writeString(mPath);
208-
parcel.writeString(mDescription);
213+
parcel.writeInt(mDescriptionId);
209214
parcel.writeInt(mRemovable ? 1 : 0);
210215
parcel.writeInt(mEmulated ? 1 : 0);
211216
parcel.writeInt(mStorageId);

media/java/android/mtp/MtpStorage.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package android.mtp;
1818

19+
import android.content.Context;
1920
import android.os.storage.StorageVolume;
2021

2122
/**
@@ -34,10 +35,10 @@ public class MtpStorage {
3435
private final boolean mRemovable;
3536
private final long mMaxFileSize;
3637

37-
public MtpStorage(StorageVolume volume) {
38+
public MtpStorage(StorageVolume volume, Context context) {
3839
mStorageId = volume.getStorageId();
3940
mPath = volume.getPath();
40-
mDescription = volume.getDescription();
41+
mDescription = context.getResources().getString(volume.getDescriptionId());
4142
mReserveSpace = volume.getMtpReserveSpace();
4243
mRemovable = volume.isRemovable();
4344
mMaxFileSize = volume.getMaxFileSize();

services/java/com/android/server/MountService.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,9 @@ private void validatePermission(String perm) {
10651065
private static final String TAG_STORAGE_LIST = "StorageList";
10661066
private static final String TAG_STORAGE = "storage";
10671067

1068-
private void readStorageList(Resources resources) {
1068+
private void readStorageList() {
1069+
Resources resources = mContext.getResources();
1070+
10691071
int id = com.android.internal.R.xml.storage_list;
10701072
XmlResourceParser parser = resources.getXml(id);
10711073
AttributeSet attrs = Xml.asAttributeSet(parser);
@@ -1084,6 +1086,8 @@ private void readStorageList(Resources resources) {
10841086

10851087
CharSequence path = a.getText(
10861088
com.android.internal.R.styleable.Storage_mountPoint);
1089+
int descriptionId = a.getResourceId(
1090+
com.android.internal.R.styleable.Storage_storageDescription, -1);
10871091
CharSequence description = a.getText(
10881092
com.android.internal.R.styleable.Storage_storageDescription);
10891093
boolean primary = a.getBoolean(
@@ -1110,7 +1114,7 @@ private void readStorageList(Resources resources) {
11101114
} else {
11111115
String pathString = path.toString();
11121116
StorageVolume volume = new StorageVolume(pathString,
1113-
description.toString(), removable, emulated,
1117+
descriptionId, removable, emulated,
11141118
mtpReserve, allowMassStorage, maxFileSize);
11151119
if (primary) {
11161120
if (mPrimaryVolume == null) {
@@ -1151,8 +1155,7 @@ private void readStorageList(Resources resources) {
11511155
*/
11521156
public MountService(Context context) {
11531157
mContext = context;
1154-
Resources resources = context.getResources();
1155-
readStorageList(resources);
1158+
readStorageList();
11561159

11571160
if (mPrimaryVolume != null) {
11581161
mExternalStoragePath = mPrimaryVolume.getPath();

0 commit comments

Comments
 (0)