Improve ACTION_PACKAGE_CHANGED handling in IMMS
This CL fixes a false negative case when handling ACTION_PACKAGE_CHANGED in IMMS#MyPackageMonitor with greatly reducing unnecessary false positives cases as well. PackageMonitor#onPackageChanged(), which is the default handler of ACTION_PACKAGE_CHANGED, returns true when and only when the entire package state is changed to let InputMethodManagerService (IMMS) rebuild the list of available IMEs when it returns true. Here we have a false negative case and false positive cases. Case 1 - false negative (Bug 28181208) If ACTION_PACKAGE_CHANGED was about some components not the entire package itself, currently MyPackageMonitor#onPackageChanged() returns false and IMMS fails to rebuild the list of available IMEs. Case 2 - false positive (contributing to Bug 32343335) Even if ACTION_PACKAGE_CHANGED was about a package that implements no IME service at all, currently MyPackageMonitor#onPackageChanged() returns true and IMMS ends up with rebuilding the list of avilable IMEs unnecessarily. Note that package replacement is a different story that should be dealt with ACTION_PACKAGE_{ADDED, REMOVED}. For both cases, luckily we can easily ask PackageManager to give the list of relevant package names that might contain IMEs regardless of enabled/disabled state, which is exactly what we want to use the watch list for ACTION_PACKAGE_CHANGED events. For the case 3, we can just check the current user ID. Test: Manually verified as follows. 1. adb root 2. adb install -r LatinIME.apk 3. adb shell dumpsys input_method Make sure that com.android.inputmethod.latin/.LatinIME is recognized by IMMS. 4. adb shell pm disable com.android.inputmethod.latin/.LatinIME 5. adb shell dumpsys input_method Make sure that com.android.inputmethod.latin/.LatinIME is no longer recognized by IMMS. 6. adb shell pm enable com.android.inputmethod.latin/.LatinIME 7. adb shell dumpsys input_method Make sure that com.android.inputmethod.latin/.LatinIME is recognized by IMMS again. Test: Manually verified as follows. 1. Build a custom APK LatinIME_no_ime.apk that has no input method service. 2. adb install -r LatinIME_no_ime.apk 3. adb shell dumpsys input_method Make sure that com.android.inputmethod.latin/.LatinIME is not recognized by IMMS. 4. adb install -r LatinIME.apk 5. adb shell dumpsys input_method Make sure that com.android.inputmethod.latin/.LatinIME is recognized by IMMS. 6. adb install -r LatinIME_no_ime.apk 7. adb shell dumpsys input_method Make sure that com.android.inputmethod.latin/.LatinIME is no longer recognized by IMMS. Bug: 32343335 Fixes: 28181208 Change-Id: I7b69c349318ce06a48d03a4468cf2c45bfb73dc2
Loading
Please register or sign in to comment