Optimize IMMS.MyPackageMonitor more
This CL is a follow up CL to my previous CL [1] that aimed to reduce false positives in InputMethodManagerService.MyPackageMonitor when deciding if InputMethodManagerService (IMMS) needs to rebuild the list of enabled IMEs or not. Currently IMMS.MyPackageMonitor#onSomePackagesChanged() gets called back to trigger IMMS#buildInputMethodListLocked() when either the following rule A or B is fulfiled. A. Intent with one of the following actions for any package name: - ACTION_PACKAGE_ADDED - ACTION_PACKAGE_REMOVED - ACTION_EXTERNAL_APPLICATIONS_AVAILABLE - ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE - ACTION_PACKAGES_SUSPENDED - ACTION_PACKAGES_UNSUSPENDED B. ACTION_PACKAGE_CHANGED with a package that is included in the known IME package list, which can be obtained from PackageManager. The previous CL [1] addressed Bug 28181208 by introducing the rule B, but we can actually apply the same optimization for A, except for one false negative case where an appearing package that is not in the known IME package list actually contains one or more InputMethodService. In short, we can reduce false positives by replacing the above two rules with the following two rules. A. Intent with one of the following actions for any package name that is in the known IME package list: - ACTION_PACKAGE_ADDED - ACTION_PACKAGE_CHANGED - ACTION_PACKAGE_REMOVED - ACTION_EXTERNAL_APPLICATIONS_AVAILABLE - ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE - ACTION_PACKAGES_SUSPENDED - ACTION_PACKAGES_UNSUSPENDED B. Intent with one of the following actions for any package that implements at least one InputMethodServivce. - ACTION_PACKAGE_ADDED - ACTION_EXTERNAL_APPLICATIONS_AVAILABLE Basically in the rule A PackageManager gives us the list of relevant package names that might contain IMEs regardless enabled/disabled state, and such a list works well to filter out irrelevant notifications except for one case where a new package is adding one or new IMEs that we did not know. This is why we also need the rule B. Even though the rule B requires a secondary query to PackageManager, it can be done outside of the state lock of IMMS. [1]: I7b69c349318ce06a48d03a4468cf2c45bfb73dc2 c4e44917 Test: Manually verified as follows. 1. tapas ShortcutDemo && make -j 2. Copy ShortcutDemo.apk to the current directory. 3. adb shell dumpsys input_method | grep mMethodMapUpdateCount= to check the "mMethodMapUpdateCount". 4. adb install -r ShortcutDemo.apk 5. adb shell dumpsys input_method | grep mMethodMapUpdateCount= to make sure "mMethodMapUpdateCount" remains unchanged. 6. adb install -r ShortcutDemo.apk 7. adb shell dumpsys input_method | grep mMethodMapUpdateCount= to make sure "mMethodMapUpdateCount" remains unchanged. 8. adb uninstall com.example.android.pm.shortcutdemo 9. adb shell dumpsys input_method | grep mMethodMapUpdateCount= to make sure "mMethodMapUpdateCount" remains unchanged. Test: Manually verified as follows. 1. tapas SoftKeyboard && make -j 2. Copy SoftKeyboard.apk to the current directory. 3. adb root 4. adb install -r SoftKeyboard.apk 5. adb shell dumpsys input_method Make sure that com.example.android.softkeyboard/.SoftKeyboard is recognized by IMMS. 6. adb shell pm disable com.example.android.softkeyboard/.SoftKeyboard 7. adb shell dumpsys input_method Make sure that com.example.android.softkeyboard/.SoftKeyboard is no longer recognized by IMMS. 8. adb shell pm enable com.example.android.softkeyboard/.SoftKeyboard 9. adb shell dumpsys input_method Make sure that com.example.android.softkeyboard/.SoftKeyboard is recognized by IMMS again. Fixes: 35361128 Change-Id: I063688297156188f68fe0b55a46d72f2e811dc88
Loading
Please register or sign in to comment