From 2fe2dbca530fba05e4b10ee5f088ffbdd9f4bdd2 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Wed, 19 Dec 2018 14:12:35 -0800 Subject: [PATCH] Let the absence of subtype.xml mean there is no additional subtype Historically, we have always created a stub subtype.xml for each user even when there is no additional subtype. Instead of having such a stub XML files, no subtype will be represented by the absence of subtype.xml with this CL. If there has already been such a stub XML, it will be deleted automatically when InputMethodFileManager#writeAdditionalInputMethodSubtypes() gets called next time. Note that this method is called from InputMethodManagerService#onFinishPackageChangesInternal(), which is called when some IME package is updated. This is completely about how internal data is persisted. There should be no developer-visible behavior change. Fix: 121223050 Test: Manually verified as follows 1. Build and flash aosp_taimen-userdebug into taimen 2. Wait until the device fully boots up 3. adb reboot # to avoid Bug 121259290 4. adb root 5. adb shell cat /data/system/inputmethod/subtypes.xml -> make sure the content looks as follows: 6. Open AOSP Keyboard settings 7. Go to "Appearance & Layouts" -> "Custom input styles" 8. Remove all layouts 9. adb shell cat /data/system/inputmethod/subtypes.xml -> make sure the file no longer exists Change-Id: If06e1b5967443157d1a7606190d721ae8983be08 --- .../InputMethodManagerService.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 47c5f492a7e09..597d81ffab5c6 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -4304,14 +4304,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } final File subtypeFile = new File(inputMethodDir, ADDITIONAL_SUBTYPES_FILE_NAME); mAdditionalInputMethodSubtypeFile = new AtomicFile(subtypeFile, "input-subtypes"); - if (!subtypeFile.exists()) { - // If "subtypes.xml" doesn't exist, create a blank file. - writeAdditionalInputMethodSubtypes( - mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile, methodMap); - } else { - readAdditionalInputMethodSubtypes( - mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile); - } + readAdditionalInputMethodSubtypes(mAdditionalSubtypesMap, + mAdditionalInputMethodSubtypeFile); } private void deleteAllInputMethodSubtypes(String imiId) { @@ -4351,6 +4345,13 @@ public class InputMethodManagerService extends IInputMethodManager.Stub private static void writeAdditionalInputMethodSubtypes( ArrayMap> allSubtypes, AtomicFile subtypesFile, ArrayMap methodMap) { + if (allSubtypes.isEmpty()) { + if (subtypesFile.exists()) { + subtypesFile.delete(); + } + return; + } + // Safety net for the case that this function is called before methodMap is set. final boolean isSetMethodMap = methodMap != null && methodMap.size() > 0; FileOutputStream fos = null; @@ -4407,6 +4408,10 @@ public class InputMethodManagerService extends IInputMethodManager.Stub ArrayMap> allSubtypes, AtomicFile subtypesFile) { if (allSubtypes == null || subtypesFile == null) return; allSubtypes.clear(); + if (!subtypesFile.exists()) { + // Not having the file means there is no additional subtype. + return; + } try (final FileInputStream fis = subtypesFile.openRead()) { final XmlPullParser parser = Xml.newPullParser(); parser.setInput(fis, StandardCharsets.UTF_8.name());