* commit '421daf8590cdbce7e41b7492608a985fe13c2033': Forget private partition keys.
This commit is contained in:
@@ -137,6 +137,7 @@ public class VolumeInfo implements Parcelable {
|
|||||||
public final String id;
|
public final String id;
|
||||||
public final int type;
|
public final int type;
|
||||||
public final DiskInfo disk;
|
public final DiskInfo disk;
|
||||||
|
public final String partGuid;
|
||||||
public int mountFlags = 0;
|
public int mountFlags = 0;
|
||||||
public int mountUserId = -1;
|
public int mountUserId = -1;
|
||||||
public int state = STATE_UNMOUNTED;
|
public int state = STATE_UNMOUNTED;
|
||||||
@@ -149,10 +150,11 @@ public class VolumeInfo implements Parcelable {
|
|||||||
/** Framework state */
|
/** Framework state */
|
||||||
public final int mtpIndex;
|
public final int mtpIndex;
|
||||||
|
|
||||||
public VolumeInfo(String id, int type, DiskInfo disk, int mtpIndex) {
|
public VolumeInfo(String id, int type, DiskInfo disk, String partGuid, int mtpIndex) {
|
||||||
this.id = Preconditions.checkNotNull(id);
|
this.id = Preconditions.checkNotNull(id);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.disk = disk;
|
this.disk = disk;
|
||||||
|
this.partGuid = partGuid;
|
||||||
this.mtpIndex = mtpIndex;
|
this.mtpIndex = mtpIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,6 +166,7 @@ public class VolumeInfo implements Parcelable {
|
|||||||
} else {
|
} else {
|
||||||
disk = null;
|
disk = null;
|
||||||
}
|
}
|
||||||
|
partGuid = parcel.readString();
|
||||||
mountFlags = parcel.readInt();
|
mountFlags = parcel.readInt();
|
||||||
mountUserId = parcel.readInt();
|
mountUserId = parcel.readInt();
|
||||||
state = parcel.readInt();
|
state = parcel.readInt();
|
||||||
@@ -385,6 +388,7 @@ public class VolumeInfo implements Parcelable {
|
|||||||
pw.increaseIndent();
|
pw.increaseIndent();
|
||||||
pw.printPair("type", DebugUtils.valueToString(getClass(), "TYPE_", type));
|
pw.printPair("type", DebugUtils.valueToString(getClass(), "TYPE_", type));
|
||||||
pw.printPair("diskId", getDiskId());
|
pw.printPair("diskId", getDiskId());
|
||||||
|
pw.printPair("partGuid", partGuid);
|
||||||
pw.printPair("mountFlags", DebugUtils.flagsToString(getClass(), "MOUNT_FLAG_", mountFlags));
|
pw.printPair("mountFlags", DebugUtils.flagsToString(getClass(), "MOUNT_FLAG_", mountFlags));
|
||||||
pw.printPair("mountUserId", mountUserId);
|
pw.printPair("mountUserId", mountUserId);
|
||||||
pw.printPair("state", DebugUtils.valueToString(getClass(), "STATE_", state));
|
pw.printPair("state", DebugUtils.valueToString(getClass(), "STATE_", state));
|
||||||
@@ -453,6 +457,7 @@ public class VolumeInfo implements Parcelable {
|
|||||||
} else {
|
} else {
|
||||||
parcel.writeInt(0);
|
parcel.writeInt(0);
|
||||||
}
|
}
|
||||||
|
parcel.writeString(partGuid);
|
||||||
parcel.writeInt(mountFlags);
|
parcel.writeInt(mountFlags);
|
||||||
parcel.writeInt(mountUserId);
|
parcel.writeInt(mountUserId);
|
||||||
parcel.writeInt(state);
|
parcel.writeInt(state);
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ public class VolumeRecord implements Parcelable {
|
|||||||
|
|
||||||
public final int type;
|
public final int type;
|
||||||
public final String fsUuid;
|
public final String fsUuid;
|
||||||
|
public String partGuid;
|
||||||
public String nickname;
|
public String nickname;
|
||||||
public int userFlags;
|
public int userFlags;
|
||||||
|
|
||||||
@@ -50,6 +51,7 @@ public class VolumeRecord implements Parcelable {
|
|||||||
public VolumeRecord(Parcel parcel) {
|
public VolumeRecord(Parcel parcel) {
|
||||||
type = parcel.readInt();
|
type = parcel.readInt();
|
||||||
fsUuid = parcel.readString();
|
fsUuid = parcel.readString();
|
||||||
|
partGuid = parcel.readString();
|
||||||
nickname = parcel.readString();
|
nickname = parcel.readString();
|
||||||
userFlags = parcel.readInt();
|
userFlags = parcel.readInt();
|
||||||
}
|
}
|
||||||
@@ -79,6 +81,8 @@ public class VolumeRecord implements Parcelable {
|
|||||||
pw.increaseIndent();
|
pw.increaseIndent();
|
||||||
pw.printPair("type", DebugUtils.valueToString(VolumeInfo.class, "TYPE_", type));
|
pw.printPair("type", DebugUtils.valueToString(VolumeInfo.class, "TYPE_", type));
|
||||||
pw.printPair("fsUuid", fsUuid);
|
pw.printPair("fsUuid", fsUuid);
|
||||||
|
pw.printPair("partGuid", partGuid);
|
||||||
|
pw.println();
|
||||||
pw.printPair("nickname", nickname);
|
pw.printPair("nickname", nickname);
|
||||||
pw.printPair("userFlags",
|
pw.printPair("userFlags",
|
||||||
DebugUtils.flagsToString(VolumeRecord.class, "USER_FLAG_", userFlags));
|
DebugUtils.flagsToString(VolumeRecord.class, "USER_FLAG_", userFlags));
|
||||||
@@ -133,6 +137,7 @@ public class VolumeRecord implements Parcelable {
|
|||||||
public void writeToParcel(Parcel parcel, int flags) {
|
public void writeToParcel(Parcel parcel, int flags) {
|
||||||
parcel.writeInt(type);
|
parcel.writeInt(type);
|
||||||
parcel.writeString(fsUuid);
|
parcel.writeString(fsUuid);
|
||||||
|
parcel.writeString(partGuid);
|
||||||
parcel.writeString(nickname);
|
parcel.writeString(nickname);
|
||||||
parcel.writeInt(userFlags);
|
parcel.writeInt(userFlags);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -465,6 +465,11 @@ public class TextUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@hide} */
|
||||||
|
public static String nullIfEmpty(@Nullable String str) {
|
||||||
|
return isEmpty(str) ? null : str;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the length that the specified CharSequence would have if
|
* Returns the length that the specified CharSequence would have if
|
||||||
* spaces and control characters were trimmed from the start and end,
|
* spaces and control characters were trimmed from the start and end,
|
||||||
|
|||||||
@@ -259,6 +259,7 @@ class MountService extends IMountService.Stub
|
|||||||
private static final String TAG_VOLUME = "volume";
|
private static final String TAG_VOLUME = "volume";
|
||||||
private static final String ATTR_TYPE = "type";
|
private static final String ATTR_TYPE = "type";
|
||||||
private static final String ATTR_FS_UUID = "fsUuid";
|
private static final String ATTR_FS_UUID = "fsUuid";
|
||||||
|
private static final String ATTR_PART_GUID = "partGuid";
|
||||||
private static final String ATTR_NICKNAME = "nickname";
|
private static final String ATTR_NICKNAME = "nickname";
|
||||||
private static final String ATTR_USER_FLAGS = "userFlags";
|
private static final String ATTR_USER_FLAGS = "userFlags";
|
||||||
|
|
||||||
@@ -689,7 +690,7 @@ class MountService extends IMountService.Stub
|
|||||||
|
|
||||||
// Create a stub volume that represents internal storage
|
// Create a stub volume that represents internal storage
|
||||||
final VolumeInfo internal = new VolumeInfo(VolumeInfo.ID_PRIVATE_INTERNAL,
|
final VolumeInfo internal = new VolumeInfo(VolumeInfo.ID_PRIVATE_INTERNAL,
|
||||||
VolumeInfo.TYPE_PRIVATE, null, 0);
|
VolumeInfo.TYPE_PRIVATE, null, null, 0);
|
||||||
internal.state = VolumeInfo.STATE_MOUNTED;
|
internal.state = VolumeInfo.STATE_MOUNTED;
|
||||||
internal.path = Environment.getDataDirectory().getAbsolutePath();
|
internal.path = Environment.getDataDirectory().getAbsolutePath();
|
||||||
mVolumes.put(internal.id, internal);
|
mVolumes.put(internal.id, internal);
|
||||||
@@ -900,10 +901,12 @@ class MountService extends IMountService.Stub
|
|||||||
case VoldResponseCode.VOLUME_CREATED: {
|
case VoldResponseCode.VOLUME_CREATED: {
|
||||||
final String id = cooked[1];
|
final String id = cooked[1];
|
||||||
final int type = Integer.parseInt(cooked[2]);
|
final int type = Integer.parseInt(cooked[2]);
|
||||||
final String diskId = (cooked.length == 4) ? cooked[3] : null;
|
final String diskId = TextUtils.nullIfEmpty(cooked[3]);
|
||||||
|
final String partGuid = TextUtils.nullIfEmpty(cooked[4]);
|
||||||
|
|
||||||
final DiskInfo disk = mDisks.get(diskId);
|
final DiskInfo disk = mDisks.get(diskId);
|
||||||
final int mtpIndex = allocateMtpIndex(id);
|
final int mtpIndex = allocateMtpIndex(id);
|
||||||
final VolumeInfo vol = new VolumeInfo(id, type, disk, mtpIndex);
|
final VolumeInfo vol = new VolumeInfo(id, type, disk, partGuid, mtpIndex);
|
||||||
mVolumes.put(id, vol);
|
mVolumes.put(id, vol);
|
||||||
onVolumeCreatedLocked(vol);
|
onVolumeCreatedLocked(vol);
|
||||||
break;
|
break;
|
||||||
@@ -1091,13 +1094,21 @@ class MountService extends IMountService.Stub
|
|||||||
// Remember that we saw this volume so we're ready to accept user
|
// Remember that we saw this volume so we're ready to accept user
|
||||||
// metadata, or so we can annoy them when a private volume is ejected
|
// metadata, or so we can annoy them when a private volume is ejected
|
||||||
if (vol.isMountedReadable() && !TextUtils.isEmpty(vol.fsUuid)) {
|
if (vol.isMountedReadable() && !TextUtils.isEmpty(vol.fsUuid)) {
|
||||||
if (!mRecords.containsKey(vol.fsUuid)) {
|
VolumeRecord rec = mRecords.get(vol.fsUuid);
|
||||||
final VolumeRecord rec = new VolumeRecord(vol.type, vol.fsUuid);
|
if (rec == null) {
|
||||||
|
rec = new VolumeRecord(vol.type, vol.fsUuid);
|
||||||
|
rec.partGuid = vol.partGuid;
|
||||||
if (vol.type == VolumeInfo.TYPE_PRIVATE) {
|
if (vol.type == VolumeInfo.TYPE_PRIVATE) {
|
||||||
rec.nickname = vol.disk.getDescription();
|
rec.nickname = vol.disk.getDescription();
|
||||||
}
|
}
|
||||||
mRecords.put(rec.fsUuid, rec);
|
mRecords.put(rec.fsUuid, rec);
|
||||||
writeSettingsLocked();
|
writeSettingsLocked();
|
||||||
|
} else {
|
||||||
|
// Handle upgrade case where we didn't store partition GUID
|
||||||
|
if (TextUtils.isEmpty(rec.partGuid)) {
|
||||||
|
rec.partGuid = vol.partGuid;
|
||||||
|
writeSettingsLocked();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1347,6 +1358,7 @@ class MountService extends IMountService.Stub
|
|||||||
final int type = readIntAttribute(in, ATTR_TYPE);
|
final int type = readIntAttribute(in, ATTR_TYPE);
|
||||||
final String fsUuid = readStringAttribute(in, ATTR_FS_UUID);
|
final String fsUuid = readStringAttribute(in, ATTR_FS_UUID);
|
||||||
final VolumeRecord meta = new VolumeRecord(type, fsUuid);
|
final VolumeRecord meta = new VolumeRecord(type, fsUuid);
|
||||||
|
meta.partGuid = readStringAttribute(in, ATTR_PART_GUID);
|
||||||
meta.nickname = readStringAttribute(in, ATTR_NICKNAME);
|
meta.nickname = readStringAttribute(in, ATTR_NICKNAME);
|
||||||
meta.userFlags = readIntAttribute(in, ATTR_USER_FLAGS);
|
meta.userFlags = readIntAttribute(in, ATTR_USER_FLAGS);
|
||||||
return meta;
|
return meta;
|
||||||
@@ -1356,6 +1368,7 @@ class MountService extends IMountService.Stub
|
|||||||
out.startTag(null, TAG_VOLUME);
|
out.startTag(null, TAG_VOLUME);
|
||||||
writeIntAttribute(out, ATTR_TYPE, rec.type);
|
writeIntAttribute(out, ATTR_TYPE, rec.type);
|
||||||
writeStringAttribute(out, ATTR_FS_UUID, rec.fsUuid);
|
writeStringAttribute(out, ATTR_FS_UUID, rec.fsUuid);
|
||||||
|
writeStringAttribute(out, ATTR_PART_GUID, rec.partGuid);
|
||||||
writeStringAttribute(out, ATTR_NICKNAME, rec.nickname);
|
writeStringAttribute(out, ATTR_NICKNAME, rec.nickname);
|
||||||
writeIntAttribute(out, ATTR_USER_FLAGS, rec.userFlags);
|
writeIntAttribute(out, ATTR_USER_FLAGS, rec.userFlags);
|
||||||
out.endTag(null, TAG_VOLUME);
|
out.endTag(null, TAG_VOLUME);
|
||||||
@@ -1573,9 +1586,11 @@ class MountService extends IMountService.Stub
|
|||||||
|
|
||||||
Preconditions.checkNotNull(fsUuid);
|
Preconditions.checkNotNull(fsUuid);
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
mRecords.remove(fsUuid);
|
final VolumeRecord rec = mRecords.remove(fsUuid);
|
||||||
|
if (rec != null && !TextUtils.isEmpty(rec.partGuid)) {
|
||||||
// TODO: tell vold to forget keys
|
forgetPartition(rec.partGuid);
|
||||||
|
}
|
||||||
|
mCallbacks.notifyVolumeForgotten(fsUuid);
|
||||||
|
|
||||||
// If this had been primary storage, revert back to internal and
|
// If this had been primary storage, revert back to internal and
|
||||||
// reset vold so we bind into new volume into place.
|
// reset vold so we bind into new volume into place.
|
||||||
@@ -1584,7 +1599,6 @@ class MountService extends IMountService.Stub
|
|||||||
resetIfReadyAndConnected();
|
resetIfReadyAndConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
mCallbacks.notifyVolumeForgotten(fsUuid);
|
|
||||||
writeSettingsLocked();
|
writeSettingsLocked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1597,6 +1611,10 @@ class MountService extends IMountService.Stub
|
|||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
for (int i = 0; i < mRecords.size(); i++) {
|
for (int i = 0; i < mRecords.size(); i++) {
|
||||||
final String fsUuid = mRecords.keyAt(i);
|
final String fsUuid = mRecords.keyAt(i);
|
||||||
|
final VolumeRecord rec = mRecords.valueAt(i);
|
||||||
|
if (!TextUtils.isEmpty(rec.partGuid)) {
|
||||||
|
forgetPartition(rec.partGuid);
|
||||||
|
}
|
||||||
mCallbacks.notifyVolumeForgotten(fsUuid);
|
mCallbacks.notifyVolumeForgotten(fsUuid);
|
||||||
}
|
}
|
||||||
mRecords.clear();
|
mRecords.clear();
|
||||||
@@ -1610,6 +1628,14 @@ class MountService extends IMountService.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void forgetPartition(String partGuid) {
|
||||||
|
try {
|
||||||
|
mConnector.execute("volume", "forget_partition", partGuid);
|
||||||
|
} catch (NativeDaemonConnectorException e) {
|
||||||
|
Slog.w(TAG, "Failed to forget key for " + partGuid + ": " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setDebugFlags(int flags, int mask) {
|
public void setDebugFlags(int flags, int mask) {
|
||||||
enforcePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
|
enforcePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
|
||||||
|
|||||||
Reference in New Issue
Block a user