Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fd7b98c5 authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka
Browse files

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
parent e776821a
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.os.UserManager;
import android.print.PrintManager;
import android.print.PrintServicesLoader;
import android.printservice.PrintServiceInfo;
import android.provider.Settings;
import android.provider.UserDictionary;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
@@ -382,6 +383,9 @@ public final class DynamicIndexableContentMonitor implements
    // Also it monitors user dictionary changes and updates search index.
    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.
        @Nullable private Index mIndex;
        private PackageManager mPackageManager;
@@ -439,8 +443,9 @@ public final class DynamicIndexableContentMonitor implements
            // Watch for related content URIs.
            mContentResolver.registerContentObserver(UserDictionary.Words.CONTENT_URI,
                    true /* notifyForDescendants */, this /* observer */);
            // TODO: Should monitor android.provider.Settings.Secure.ENABLED_INPUT_METHODS and
            // update index of AvailableVirtualKeyboardFragment and VirtualKeyboardFragment.
            // Watch for changing enabled IMEs.
            mContentResolver.registerContentObserver(ENABLED_INPUT_METHODS_CONTENT_URI,
                    false /* notifyForDescendants */, this /* observer */);
        }

        private void buildIndex(Class<?> indexClass, boolean rebuild) {
@@ -470,7 +475,10 @@ public final class DynamicIndexableContentMonitor implements

        @Override
        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 */);
            }
        }
+17 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import android.os.Bundle;
import android.print.PrintManager;
import android.print.PrintServicesLoader;
import android.printservice.PrintServiceInfo;
import android.provider.Settings;
import android.provider.UserDictionary;
import android.view.inputmethod.InputMethodInfo;

@@ -340,6 +341,12 @@ public class DynamicIndexableContentMonitorTest {
        verifyRebuildIndexing(VirtualKeyboardFragment.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.
         */
@@ -411,6 +418,16 @@ public class DynamicIndexableContentMonitorTest {

        verifyNoIndexing(VirtualKeyboardFragment.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