Skip to content

Commit 6c04826

Browse files
Ben KomaloAndroid (Google) Code Review
authored andcommitted
Merge "Revert encryption mapping for device wipes."
2 parents 48b3914 + 13c7197 commit 6c04826

File tree

7 files changed

+43
-23
lines changed

7 files changed

+43
-23
lines changed

core/java/android/os/storage/IMountService.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,15 @@ public int mountVolume(String mountPoint) throws RemoteException {
169169
* is an asynchronous operation. Applications should register
170170
* StorageEventListener for storage related status changes.
171171
*/
172-
public void unmountVolume(String mountPoint, boolean force) throws RemoteException {
172+
public void unmountVolume(String mountPoint, boolean force, boolean removeEncryption)
173+
throws RemoteException {
173174
Parcel _data = Parcel.obtain();
174175
Parcel _reply = Parcel.obtain();
175176
try {
176177
_data.writeInterfaceToken(DESCRIPTOR);
177178
_data.writeString(mountPoint);
178179
_data.writeInt((force ? 1 : 0));
180+
_data.writeInt((removeEncryption ? 1 : 0));
179181
mRemote.transact(Stub.TRANSACTION_unmountVolume, _data, _reply, 0);
180182
_reply.readException();
181183
} finally {
@@ -842,9 +844,9 @@ public boolean onTransact(int code, Parcel data, Parcel reply,
842844
data.enforceInterface(DESCRIPTOR);
843845
String mountPoint;
844846
mountPoint = data.readString();
845-
boolean force;
846-
force = 0 != data.readInt();
847-
unmountVolume(mountPoint, force);
847+
boolean force = 0 != data.readInt();
848+
boolean removeEncrypt = 0 != data.readInt();
849+
unmountVolume(mountPoint, force, removeEncrypt);
848850
reply.writeNoException();
849851
return true;
850852
}
@@ -1234,8 +1236,14 @@ public void unmountObb(String filename, boolean force, IObbActionListener token,
12341236
* Safely unmount external storage at given mount point. The unmount is an
12351237
* asynchronous operation. Applications should register StorageEventListener
12361238
* for storage related status changes.
1239+
* @param mountPoint the mount point
1240+
* @param force whether or not to forcefully unmount it (e.g. even if programs are using this
1241+
* data currently)
1242+
* @param removeEncryption whether or not encryption mapping should be removed from the volume.
1243+
* This value implies {@code force}.
12371244
*/
1238-
public void unmountVolume(String mountPoint, boolean force) throws RemoteException;
1245+
public void unmountVolume(String mountPoint, boolean force, boolean removeEncryption)
1246+
throws RemoteException;
12391247

12401248
/**
12411249
* Unregisters an IMountServiceListener

core/java/com/android/internal/os/storage/ExternalStorageFormatter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ void updateProgressState() {
152152
Environment.getExternalStorageDirectory().toString() :
153153
mStorageVolume.getPath();
154154
try {
155-
mountService.unmountVolume(extStoragePath, true);
155+
// Remove encryption mapping if this is an unmount for a factory reset.
156+
mountService.unmountVolume(extStoragePath, true, mFactoryReset);
156157
} catch (RemoteException e) {
157158
Log.w(TAG, "Failed talking with mount service", e);
158159
}

core/tests/coretests/src/android/content/pm/PackageManagerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ private boolean unmountMedia() {
10571057
try {
10581058
// Wait on observer
10591059
synchronized(observer) {
1060-
getMs().unmountVolume(path, true);
1060+
getMs().unmountVolume(path, true, false);
10611061
long waitTime = 0;
10621062
while((!observer.isDone()) && (waitTime < MAX_WAIT_TIME) ) {
10631063
observer.wait(WAIT_TIME_INCR);

core/tests/coretests/src/android/os/storage/AsecTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ private boolean unmountMedia() {
421421
try {
422422
// Wait on observer
423423
synchronized(observer) {
424-
getMs().unmountVolume(path, false);
424+
getMs().unmountVolume(path, false, false);
425425
long waitTime = 0;
426426
while((!observer.isDone()) && (waitTime < MAX_WAIT_TIME) ) {
427427
observer.wait(WAIT_TIME_INCR);
@@ -486,7 +486,7 @@ public void testUnmountMultiple() {
486486
// Wait on observer
487487
synchronized(observer) {
488488
for (int i = 0; i < 5; i++) {
489-
getMs().unmountVolume(path, false);
489+
getMs().unmountVolume(path, false, false);
490490
}
491491
long waitTime = 0;
492492
while((!observer.isDone()) && (waitTime < MAX_WAIT_TIME) ) {

include/storage/IMountService.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class IMountService: public IInterface {
3737
virtual void setUsbMassStorageEnabled(const bool enable) = 0;
3838
virtual bool isUsbMassStorageEnabled() = 0;
3939
virtual int32_t mountVolume(const String16& mountPoint) = 0;
40-
virtual int32_t
41-
unmountVolume(const String16& mountPoint, const bool force) = 0;
40+
virtual int32_t unmountVolume(
41+
const String16& mountPoint, const bool force, const bool removeEncryption) = 0;
4242
virtual int32_t formatVolume(const String16& mountPoint) = 0;
4343
virtual int32_t
4444
getStorageUsers(const String16& mountPoint, int32_t** users) = 0;

libs/storage/IMountService.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,13 @@ class BpMountService: public BpInterface<IMountService>
157157
return reply.readInt32();
158158
}
159159

160-
int32_t unmountVolume(const String16& mountPoint, const bool force)
160+
int32_t unmountVolume(const String16& mountPoint, const bool force, const bool removeEncryption)
161161
{
162162
Parcel data, reply;
163163
data.writeInterfaceToken(IMountService::getInterfaceDescriptor());
164164
data.writeString16(mountPoint);
165165
data.writeInt32(force ? 1 : 0);
166+
data.writeInt32(removeEncryption ? 1 : 0);
166167
if (remote()->transact(TRANSACTION_unmountVolume, data, &reply) != NO_ERROR) {
167168
LOGD("unmountVolume could not contact remote\n");
168169
return -1;

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -304,25 +304,27 @@ public void onServiceDisconnected(ComponentName name) {
304304
class UnmountCallBack {
305305
final String path;
306306
final boolean force;
307+
final boolean removeEncryption;
307308
int retries;
308309

309-
UnmountCallBack(String path, boolean force) {
310+
UnmountCallBack(String path, boolean force, boolean removeEncryption) {
310311
retries = 0;
311312
this.path = path;
312313
this.force = force;
314+
this.removeEncryption = removeEncryption;
313315
}
314316

315317
void handleFinished() {
316318
if (DEBUG_UNMOUNT) Slog.i(TAG, "Unmounting " + path);
317-
doUnmountVolume(path, true);
319+
doUnmountVolume(path, true, removeEncryption);
318320
}
319321
}
320322

321323
class UmsEnableCallBack extends UnmountCallBack {
322324
final String method;
323325

324326
UmsEnableCallBack(String path, String method, boolean force) {
325-
super(path, force);
327+
super(path, force, false);
326328
this.method = method;
327329
}
328330

@@ -336,13 +338,13 @@ void handleFinished() {
336338
class ShutdownCallBack extends UnmountCallBack {
337339
IMountShutdownObserver observer;
338340
ShutdownCallBack(String path, IMountShutdownObserver observer) {
339-
super(path, true);
341+
super(path, true, false);
340342
this.observer = observer;
341343
}
342344

343345
@Override
344346
void handleFinished() {
345-
int ret = doUnmountVolume(path, true);
347+
int ret = doUnmountVolume(path, true, removeEncryption);
346348
if (observer != null) {
347349
try {
348350
observer.onShutDownComplete(ret);
@@ -888,8 +890,10 @@ private int doMountVolume(String path) {
888890
* This might even take a while and might be retried after timed delays
889891
* to make sure we dont end up in an instable state and kill some core
890892
* processes.
893+
* If removeEncryption is set, force is implied, and the system will remove any encryption
894+
* mapping set on the volume when unmounting.
891895
*/
892-
private int doUnmountVolume(String path, boolean force) {
896+
private int doUnmountVolume(String path, boolean force, boolean removeEncryption) {
893897
if (!getVolumeState(path).equals(Environment.MEDIA_MOUNTED)) {
894898
return VoldResponseCode.OpFailedVolNotMounted;
895899
}
@@ -905,8 +909,10 @@ private int doUnmountVolume(String path, boolean force) {
905909
// Redundant probably. But no harm in updating state again.
906910
mPms.updateExternalMediaStatus(false, false);
907911
try {
908-
mConnector.doCommand(String.format(
909-
"volume unmount %s%s", path, (force ? " force" : "")));
912+
String arg = removeEncryption
913+
? " force_and_revert"
914+
: (force ? " force" : "");
915+
mConnector.doCommand(String.format("volume unmount %s%s", path, arg));
910916
// We unmounted the volume. None of the asec containers are available now.
911917
synchronized (mAsecMountSet) {
912918
mAsecMountSet.clear();
@@ -1371,12 +1377,16 @@ public int mountVolume(String path) {
13711377
return doMountVolume(path);
13721378
}
13731379

1374-
public void unmountVolume(String path, boolean force) {
1380+
public void unmountVolume(String path, boolean force, boolean removeEncryption) {
13751381
validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
13761382
waitForReady();
13771383

13781384
String volState = getVolumeState(path);
1379-
if (DEBUG_UNMOUNT) Slog.i(TAG, "Unmounting " + path + " force = " + force);
1385+
if (DEBUG_UNMOUNT) {
1386+
Slog.i(TAG, "Unmounting " + path
1387+
+ " force = " + force
1388+
+ " removeEncryption = " + removeEncryption);
1389+
}
13801390
if (Environment.MEDIA_UNMOUNTED.equals(volState) ||
13811391
Environment.MEDIA_REMOVED.equals(volState) ||
13821392
Environment.MEDIA_SHARED.equals(volState) ||
@@ -1385,7 +1395,7 @@ public void unmountVolume(String path, boolean force) {
13851395
// TODO return valid return code when adding observer call back.
13861396
return;
13871397
}
1388-
UnmountCallBack ucb = new UnmountCallBack(path, force);
1398+
UnmountCallBack ucb = new UnmountCallBack(path, force, removeEncryption);
13891399
mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_PM_UPDATE, ucb));
13901400
}
13911401

0 commit comments

Comments
 (0)