diff options
| author | TreeHugger Robot <treehugger-gerrit@google.com> | 2021-03-11 19:56:38 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2021-03-11 19:56:38 +0000 |
| commit | dd00a6a6cce9258e5524c1431dc5142d2a6f721c (patch) | |
| tree | 68ff81b829da0f72ecbaa47a35052f940e325db0 | |
| parent | e4e5fe959cc693f8dd2c24a478829999c4e6046d (diff) | |
| parent | b2d29b15c66ac7ebb60e3f2e1e6c6716394892a0 (diff) | |
| download | platform_packages_apps_Car_RotaryController-dd00a6a6cce9258e5524c1431dc5142d2a6f721c.tar.gz platform_packages_apps_Car_RotaryController-dd00a6a6cce9258e5524c1431dc5142d2a6f721c.tar.bz2 platform_packages_apps_Car_RotaryController-dd00a6a6cce9258e5524c1431dc5142d2a6f721c.zip | |
Merge "Fix wrong IME issue when RotaryService got killed" into rvc-qpr-dev
| -rw-r--r-- | src/com/android/car/rotary/L.java | 9 | ||||
| -rw-r--r-- | src/com/android/car/rotary/RotaryService.java | 41 |
2 files changed, 30 insertions, 20 deletions
diff --git a/src/com/android/car/rotary/L.java b/src/com/android/car/rotary/L.java index da46ba7..6c712c5 100644 --- a/src/com/android/car/rotary/L.java +++ b/src/com/android/car/rotary/L.java @@ -61,4 +61,13 @@ class L { Log.e(TAG, msg); } } + + /** Logs conditional logs if loggable or on a debug build. */ + static void successOrFailure(@NonNull String msg, boolean success) { + if (success) { + d(msg + " succeeded"); + } else { + w(msg + " failed"); + } + } } diff --git a/src/com/android/car/rotary/RotaryService.java b/src/com/android/car/rotary/RotaryService.java index 4c2ab4b..78a30ad 100644 --- a/src/com/android/car/rotary/RotaryService.java +++ b/src/com/android/car/rotary/RotaryService.java @@ -677,6 +677,11 @@ public class RotaryService extends AccessibilityService implements if (mCar != null) { mCar.disconnect(); } + + // Reset to touch IME if the current IME is rotary IME. + mInRotaryMode = false; + updateIme(); + super.onDestroy(); } @@ -844,11 +849,9 @@ public class RotaryService extends AccessibilityService implements } private void onTouchEvent() { - if (!mInRotaryMode) { - return; - } - - // Enter touch mode once the user touches the screen. + // The user touched the screen, so exit rotary mode. Do this even if mInRotaryMode is + // already false because this service might have crashed causing mInRotaryMode to be reset + // without a corresponding change to the IME. setInRotaryMode(false); // Set mFocusedNode to null when user uses touch. @@ -2241,14 +2244,15 @@ public class RotaryService extends AccessibilityService implements } private void setInRotaryMode(boolean inRotaryMode) { - if (inRotaryMode == mInRotaryMode) { - return; - } mInRotaryMode = inRotaryMode; + if (!mInRotaryMode) { + setEditNode(null); + } + updateIme(); // If we're controlling direct manipulation mode (i.e., the focused node supports rotate // directly), exit the mode when the user touches the screen. - if (!inRotaryMode && mInDirectManipulationMode) { + if (!mInRotaryMode && mInDirectManipulationMode) { if (mFocusedNode == null) { L.e("mFocused is null in direct manipulation mode"); } else if (DirectManipulationHelper.supportRotateDirectly(mFocusedNode)) { @@ -2262,8 +2266,9 @@ public class RotaryService extends AccessibilityService implements L.d("The client app should exit direct manipulation mode"); } } + } - // Update IME. + private void updateIme() { if (TextUtils.isEmpty(mRotaryInputMethod)) { L.w("No rotary IME configured"); return; @@ -2272,20 +2277,16 @@ public class RotaryService extends AccessibilityService implements L.w("No touch IME configured"); return; } - if (!inRotaryMode) { - setEditNode(null); - } - // Switch to the rotary IME or the touch IME. - String newIme = inRotaryMode ? mRotaryInputMethod : mTouchInputMethod; - if (!isValidIme(newIme)) { - L.w("Invalid IME: " + newIme); + // Switch to the rotary IME or the touch IME if needed. + String newIme = mInRotaryMode ? mRotaryInputMethod : mTouchInputMethod; + String oldIme = Settings.Secure.getString(getContentResolver(), DEFAULT_INPUT_METHOD); + if (newIme.equals(oldIme)) { + L.v("No need to switch IME: " + newIme); return; } boolean result = Settings.Secure.putString(getContentResolver(), DEFAULT_INPUT_METHOD, newIme); - if (!result) { - L.w("Failed to switch IME: " + newIme); - } + L.successOrFailure("Switching to IME: " + newIme, result); } /** |
