Remove the dependency on InputMethodSettings

InputMethodUtils.InputMethodSetting is a quite complicated inernal
class of InputMethodUtils and PhysicalKeyboardFragment's depending on
it just for getting/setting SHOW_IME_WITH_HARD_KEYBOARD is overkill.

With this CL, PhysicalKeyboardFragment just uses Secure Settings APIs
directly.

There should be no user-visible behavior change.

Bug: 77730201
Test: Manually verified as follows:
 1. Open system settings.
 2. Tap "System" -> "Languages & input" -> "Physical keyboard"
 3. Make sure "Show virtual keyboard" is unchecked
 4. Make sure the following command shows 0
      adb shell settings get secure show_ime_with_hard_keyboard
 5. Check "Show virtual keyboard"
 6. Make sure the following command shows 1
      adb shell settings get secure show_ime_with_hard_keyboard
 7. Run the following command
      adb shell settings put secure show_ime_with_hard_keyboard 0
 8. Make sure "Show virtual keyboard" is chenged to unchecked
Change-Id: I956da5dad27313d6edf141f2320bb0a7954fbbea
This commit is contained in:
Yohei Yukawa
2018-04-13 18:13:09 -07:00
parent d628116e2f
commit 9f172540b1

View File

@@ -38,7 +38,6 @@ import android.support.v7.preference.PreferenceScreen;
import android.text.TextUtils;
import android.view.InputDevice;
import com.android.internal.inputmethod.InputMethodUtils;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.util.Preconditions;
import com.android.settings.R;
@@ -52,7 +51,6 @@ import com.android.settingslib.utils.ThreadUtils;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
@@ -73,8 +71,6 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
private PreferenceCategory mKeyboardAssistanceCategory;
@NonNull
private SwitchPreference mShowVirtualKeyboardSwitch;
@NonNull
private InputMethodUtils.InputMethodSettings mSettings;
private Intent mIntentWaitingForResult;
@@ -83,13 +79,6 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
Activity activity = Preconditions.checkNotNull(getActivity());
addPreferencesFromResource(R.xml.physical_keyboard_settings);
mIm = Preconditions.checkNotNull(activity.getSystemService(InputManager.class));
mSettings = new InputMethodUtils.InputMethodSettings(
activity.getResources(),
getContentResolver(),
new HashMap<>(),
new ArrayList<>(),
UserHandle.myUserId(),
false /* copyOnWrite */);
mKeyboardAssistanceCategory = Preconditions.checkNotNull(
(PreferenceCategory) findPreference(KEYBOARD_ASSISTANCE_CATEGORY));
mShowVirtualKeyboardSwitch = Preconditions.checkNotNull(
@@ -210,7 +199,8 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
}
private void updateShowVirtualKeyboardSwitch() {
mShowVirtualKeyboardSwitch.setChecked(mSettings.isShowImeWithHardKeyboardEnabled());
mShowVirtualKeyboardSwitch.setChecked(
Secure.getInt(getContentResolver(), Secure.SHOW_IME_WITH_HARD_KEYBOARD, 0) != 0);
}
private void toggleKeyboardShortcutsMenu() {
@@ -218,12 +208,10 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
}
private final OnPreferenceChangeListener mShowVirtualKeyboardSwitchPreferenceChangeListener =
new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mSettings.setShowImeWithHardKeyboard((Boolean) newValue);
return true;
}
(preference, newValue) -> {
Secure.putInt(getContentResolver(), Secure.SHOW_IME_WITH_HARD_KEYBOARD,
((Boolean) newValue) ? 1 : 0);
return true;
};
private final ContentObserver mContentObserver = new ContentObserver(new Handler(true)) {