Emulation fixes: mics dirs, recover after disable.

Add new misc directories to list of paths that we lock/unlock in
emulation mode.  When booting a device without native-FBE and without
emulation, make sure we "unlock" any emulated settings on user 0;
MountService handles this for secondary users later during boot.

Bug: 27069522
Change-Id: I15c7cf00a7231ce99b2e4e11a25106d7b87e70cc
diff --git a/Ext4Crypt.cpp b/Ext4Crypt.cpp
index d66fdc6..9558838 100644
--- a/Ext4Crypt.cpp
+++ b/Ext4Crypt.cpp
@@ -414,6 +414,13 @@
         LOG(ERROR) << "Failed to prepare user 0 storage";
         return -1;
     }
+
+    // If this is a non-FBE device that recently left an emulated mode,
+    // restore user data directories to known-good state.
+    if (!e4crypt_is_native() && !e4crypt_is_emulated()) {
+        e4crypt_unlock_user_key(0, 0, nullptr);
+    }
+
     return 0;
 }
 
@@ -509,6 +516,7 @@
         // unlock directories when not in emulation mode, to bring devices
         // back into a known-good state.
         if (emulated_unlock(android::vold::BuildDataSystemCePath(user_id), 0771) ||
+                emulated_unlock(android::vold::BuildDataMiscCePath(user_id), 01771) ||
                 emulated_unlock(android::vold::BuildDataMediaPath(nullptr, user_id), 0770) ||
                 emulated_unlock(android::vold::BuildDataUserPath(nullptr, user_id), 0771)) {
             LOG(ERROR) << "Failed to unlock user " << user_id;
@@ -525,6 +533,7 @@
     } else if (e4crypt_is_emulated()) {
         // When in emulation mode, we just use chmod
         if (emulated_lock(android::vold::BuildDataSystemCePath(user_id)) ||
+                emulated_lock(android::vold::BuildDataMiscCePath(user_id)) ||
                 emulated_lock(android::vold::BuildDataMediaPath(nullptr, user_id)) ||
                 emulated_lock(android::vold::BuildDataUserPath(nullptr, user_id))) {
             PLOG(ERROR) << "Failed to lock user " << user_id;