Merge "Create /data/system/inputmethod/ directory lazily"
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
index 4a32f75..fb6eaa0 100644
--- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
+++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
@@ -73,6 +73,7 @@
import android.os.Bundle;
import android.os.Debug;
import android.os.Environment;
+import android.os.FileUtils;
import android.os.Handler;
import android.os.IBinder;
import android.os.IInterface;
@@ -4300,9 +4301,6 @@
? new File(Environment.getDataDirectory(), SYSTEM_PATH)
: Environment.getUserSystemDirectory(userId);
final File inputMethodDir = new File(systemDir, INPUT_METHOD_PATH);
- if (!inputMethodDir.exists() && !inputMethodDir.mkdirs()) {
- Slog.w(TAG, "Couldn't create dir.: " + inputMethodDir.getAbsolutePath());
- }
final File subtypeFile = new File(inputMethodDir, ADDITIONAL_SUBTYPES_FILE_NAME);
mAdditionalInputMethodSubtypeFile = new AtomicFile(subtypeFile, "input-subtypes");
readAdditionalInputMethodSubtypes(mAdditionalSubtypesMap,
@@ -4350,6 +4348,18 @@
if (subtypesFile.exists()) {
subtypesFile.delete();
}
+ final File parentDir = subtypesFile.getBaseFile().getParentFile();
+ if (parentDir != null && FileUtils.listFilesOrEmpty(parentDir).length == 0) {
+ if (!parentDir.delete()) {
+ Slog.e(TAG, "Failed to delete the empty parent directory " + parentDir);
+ }
+ }
+ return;
+ }
+
+ final File parentDir = subtypesFile.getBaseFile().getParentFile();
+ if (!parentDir.exists() && !parentDir.mkdirs()) {
+ Slog.e(TAG, "Failed to create a parent directory " + parentDir);
return;
}