Watch for changing enabled IMEs

This CL watches a change to Settings.Secure.ENABLED_INPUT_METHODS and
updates search index of IMEs.

Bug: 32643633
Test: After installing AOSP LatinIME.apk, enabling/disabling the IME
      and searching "AOSP", then verify the search landing page is
      correct depending on the IME's enabling state.
Test: Update robolectric test.

Change-Id: I85fa845238b89375e56b207a014af6432f9db647
This commit is contained in:
Tadashi G. Takaoka
2017-01-10 18:28:10 +09:00
parent e776821a8d
commit fd7b98c5ca
2 changed files with 28 additions and 3 deletions

View File

@@ -36,6 +36,7 @@ import android.os.UserManager;
import android.print.PrintManager; import android.print.PrintManager;
import android.print.PrintServicesLoader; import android.print.PrintServicesLoader;
import android.printservice.PrintServiceInfo; import android.printservice.PrintServiceInfo;
import android.provider.Settings;
import android.provider.UserDictionary; import android.provider.UserDictionary;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting; import android.support.annotation.VisibleForTesting;
@@ -382,6 +383,9 @@ public final class DynamicIndexableContentMonitor implements
// Also it monitors user dictionary changes and updates search index. // Also it monitors user dictionary changes and updates search index.
private static class InputMethodServicesMonitor extends ContentObserver { private static class InputMethodServicesMonitor extends ContentObserver {
private static final Uri ENABLED_INPUT_METHODS_CONTENT_URI =
Settings.Secure.getUriFor(Settings.Secure.ENABLED_INPUT_METHODS);
// Null if not initialized. // Null if not initialized.
@Nullable private Index mIndex; @Nullable private Index mIndex;
private PackageManager mPackageManager; private PackageManager mPackageManager;
@@ -439,8 +443,9 @@ public final class DynamicIndexableContentMonitor implements
// Watch for related content URIs. // Watch for related content URIs.
mContentResolver.registerContentObserver(UserDictionary.Words.CONTENT_URI, mContentResolver.registerContentObserver(UserDictionary.Words.CONTENT_URI,
true /* notifyForDescendants */, this /* observer */); true /* notifyForDescendants */, this /* observer */);
// TODO: Should monitor android.provider.Settings.Secure.ENABLED_INPUT_METHODS and // Watch for changing enabled IMEs.
// update index of AvailableVirtualKeyboardFragment and VirtualKeyboardFragment. mContentResolver.registerContentObserver(ENABLED_INPUT_METHODS_CONTENT_URI,
false /* notifyForDescendants */, this /* observer */);
} }
private void buildIndex(Class<?> indexClass, boolean rebuild) { private void buildIndex(Class<?> indexClass, boolean rebuild) {
@@ -470,7 +475,10 @@ public final class DynamicIndexableContentMonitor implements
@Override @Override
public void onChange(boolean selfChange, Uri uri) { public void onChange(boolean selfChange, Uri uri) {
if (UserDictionary.Words.CONTENT_URI.equals(uri)) { if (ENABLED_INPUT_METHODS_CONTENT_URI.equals(uri)) {
buildIndex(VirtualKeyboardFragment.class, true /* rebuild */);
buildIndex(AvailableVirtualKeyboardFragment.class, true /* rebuild */);
} else if (UserDictionary.Words.CONTENT_URI.equals(uri)) {
buildIndex(InputMethodAndLanguageSettings.class, true /* rebuild */); buildIndex(InputMethodAndLanguageSettings.class, true /* rebuild */);
} }
} }

View File

@@ -49,6 +49,7 @@ import android.os.Bundle;
import android.print.PrintManager; import android.print.PrintManager;
import android.print.PrintServicesLoader; import android.print.PrintServicesLoader;
import android.printservice.PrintServiceInfo; import android.printservice.PrintServiceInfo;
import android.provider.Settings;
import android.provider.UserDictionary; import android.provider.UserDictionary;
import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodInfo;
@@ -340,6 +341,12 @@ public class DynamicIndexableContentMonitorTest {
verifyRebuildIndexing(VirtualKeyboardFragment.class); verifyRebuildIndexing(VirtualKeyboardFragment.class);
verifyRebuildIndexing(AvailableVirtualKeyboardFragment.class); verifyRebuildIndexing(AvailableVirtualKeyboardFragment.class);
final Uri enabledInputMethodsContentUri = Settings.Secure.getUriFor(
Settings.Secure.ENABLED_INPUT_METHODS);
// Content observer should be registered.
final ContentObserver observer = extractContentObserver(enabledInputMethodsContentUri);
assertThat(observer).isNotNull();
/* /*
* When an input method service package is installed, incremental indexing happen. * When an input method service package is installed, incremental indexing happen.
*/ */
@@ -411,6 +418,16 @@ public class DynamicIndexableContentMonitorTest {
verifyNoIndexing(VirtualKeyboardFragment.class); verifyNoIndexing(VirtualKeyboardFragment.class);
verifyNoIndexing(AvailableVirtualKeyboardFragment.class); verifyNoIndexing(AvailableVirtualKeyboardFragment.class);
/*
* When enabled IMEs list is changed, rebuild indexing happens.
*/
reset(mIndex);
observer.onChange(false /* selfChange */, enabledInputMethodsContentUri);
verifyRebuildIndexing(VirtualKeyboardFragment.class);
verifyRebuildIndexing(AvailableVirtualKeyboardFragment.class);
} }
@Test @Test