Settings app changes spell checker settings directly without TSM APIs

Previously, Settings application was using TextServicesManager APIs to
update any of the spell checker settings (i.e., enabled/disabled, spell
checker, subtype). Since these APIs are used only by the Settings
application, there is no need to expose it to other services and the
Settings application can directly write them to secure settings since it
has the WRITE_SECURE_SETTINGS permission.

Bug: 62950392
Test: Manually as follows.
      1. Build and flash an OS image.
      2. Complete the setup wizard (if any).
      3. Make sure AOSP Keyboard (com.android.inputmethod.latin) is installed
      4. Install SampleSpellCheckerService
       4.1 tapas SampleSpellCheckerService
       4.2. make -j
       4.3. adb install -r out/target/product/generic/system/app/SampleSpellCheckerService/SampleSpellCheckerService.apk
      5. Go to spell checker settings in the system settings
      6. Select 'SampleSpellCheckerService' through Settings app
      7. Run
           adb shell settings get secure selected_spell_checker
         and make sure it returns the following value
           com.example.android.samplespellcheckerservice/.SampleSpellCheckerService
      8. Run
           adb shell settings get secure selected_spell_checker_subtype
         and make sure it returns '0'
      9. Select 'Android Spell Checker (AOSP)' through Settings app
     10. Run
           adb shell settings get secure selected_spell_checker
         and make sure it returns the following value
           com.android.inputmethod.latin/.spellcheck.AndroidSpellCheckerService
     11. Run
           adb shell settings get secure selected_spell_checker_subtype
         and make sure it returns '0'
     12. Tap 'Languages' on the spell checker settings to select 'French'
     13. Run
           adb shell settings get secure selected_spell_checker_subtype
         and make sure it returns '102517'
     14. Select 'SampleSpellCheckerService' again through Settings app
     15. Run
           adb shell settings get secure selected_spell_checker
         and make sure it returns the following value
           com.example.android.samplespellcheckerservice/.SampleSpellCheckerService
     16. Run
           adb shell settings get secure selected_spell_checker_subtype
         and make sure it returns '0'
Test: Manually as follows.
      1. Build and flash an OS image.
      2. Complete the setup wizard (if any).
      3. Make sure AOSP Keyboard (com.android.inputmethod.latin) is installed
      4. Install SampleSpellCheckerService
       4.1 tapas SampleSpellCheckerService
       4.2. make -j
       4.3. adb install -r out/target/product/generic/system/app/SampleSpellCheckerService/SampleSpellCheckerService.apk
      5. Set the current spell checker service to be AOSP SCS by
       adb shell settings put secure selected_spell_checker com.android.inputmethod.latin/.spellcheck.AndroidSpellCheckerService
      6. Run a test program that has TextView and tap on one of the
       TextViews and type some text.
      7. Observe that there is a connection to AOSP SCS by
       adb shell dumpsys textservices
      8. Set the current spell checker service to be
      SampleSpellCheckerService SCS by
adb shell settings put secure selected_spell_checker com.example.android.samplespellcheckerservice/.SampleSpellCheckerService
      9. Tap on the same TextView as in Step 6
      10. Observe that there is a connection to SampleSpellCheckerService
      SCS (for this TextView) by
       adb shell dumpsys textservices
Change-Id: I2f3d5282a342bcb42abf995d6e7834241e11cd4f
This commit is contained in:
Guliz Tuncay
2017-06-22 16:25:23 -07:00
parent c85c84f12b
commit 04ac51b23c

View File

@@ -21,6 +21,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.ApplicationInfo;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v7.preference.Preference;
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
import android.support.v7.preference.Preference.OnPreferenceClickListener;
@@ -105,7 +106,8 @@ public class SpellCheckersSettings extends SettingsPreferenceFragment
@Override
public void onSwitchChanged(final Switch switchView, final boolean isChecked) {
mTsm.setSpellCheckerEnabled(isChecked);
Settings.Secure.putInt(getContentResolver(), Settings.Secure.SPELL_CHECKER_ENABLED,
isChecked ? 1 : 0);
updatePreferenceScreen();
}
@@ -203,12 +205,17 @@ public class SpellCheckersSettings extends SettingsPreferenceFragment
builder.setSingleChoiceItems(items, checkedItemId, new AlertDialog.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int item) {
final int subtypeId;
if (item == ITEM_ID_USE_SYSTEM_LANGUAGE) {
mTsm.setSpellCheckerSubtype(null);
subtypeId = SpellCheckerSubtype.SUBTYPE_ID_NONE;
} else {
final int index = convertDialogItemIdToSubtypeIndex(item);
mTsm.setSpellCheckerSubtype(currentSci.getSubtypeAt(index));
subtypeId = currentSci.getSubtypeAt(index).hashCode();
}
Settings.Secure.putInt(getContentResolver(),
Settings.Secure.SELECTED_SPELL_CHECKER_SUBTYPE, subtypeId);
if (DBG) {
final SpellCheckerSubtype subtype = mTsm.getCurrentSpellCheckerSubtype(
true /* allowImplicitlySelectedSubtype */);
@@ -248,7 +255,11 @@ public class SpellCheckersSettings extends SettingsPreferenceFragment
}
private void changeCurrentSpellChecker(final SpellCheckerInfo sci) {
mTsm.setCurrentSpellChecker(sci);
Settings.Secure.putString(getContentResolver(), Settings.Secure.SELECTED_SPELL_CHECKER,
sci.getId());
// Reset the spell checker subtype
Settings.Secure.putInt(getContentResolver(), Settings.Secure.SELECTED_SPELL_CHECKER_SUBTYPE,
SpellCheckerSubtype.SUBTYPE_ID_NONE);
if (DBG) {
Log.d(TAG, "Current spell check is " + mTsm.getCurrentSpellChecker().getId());
}