@@ -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