From a97ad615016db2ee19b8918d8f37baf6a65a310a Mon Sep 17 00:00:00 2001 From: Ming-Shin Lu Date: Wed, 9 Feb 2022 23:05:42 +0800 Subject: [PATCH] Introduce ImePlatformCompatUtils To easier maintain more platform compat behavior changes in IMF side, with wrapping IPlatformCompat checkings into a new utility class that used by IMMS to check if the given state is valid to enable/disable IME behaviors on the platform side. This is a mechanical refactoring and should not have any behavior changes. Bug: 16825711 Test: Build Test: atest CtsInputMethodTestCases Change-Id: Icc19e52567de58cd72f2abba1b0aa6dd176995fd --- .../inputmethod/ImePlatformCompatUtils.java | 53 +++++++++++++++++++ .../InputMethodManagerService.java | 18 ++----- 2 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 services/core/java/com/android/server/inputmethod/ImePlatformCompatUtils.java diff --git a/services/core/java/com/android/server/inputmethod/ImePlatformCompatUtils.java b/services/core/java/com/android/server/inputmethod/ImePlatformCompatUtils.java new file mode 100644 index 0000000000000..ae77b9dc5c821 --- /dev/null +++ b/services/core/java/com/android/server/inputmethod/ImePlatformCompatUtils.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.inputmethod; + +import static android.inputmethodservice.InputMethodService.FINISH_INPUT_NO_FALLBACK_CONNECTION; + +import android.content.Context; +import android.os.RemoteException; +import android.os.ServiceManager; + +import com.android.internal.compat.IPlatformCompat; + +/** + * A utility class used by {@link InputMethodManagerService} to manage the platform + * compatibility changes on IMF (Input Method Framework) side. + */ +final class ImePlatformCompatUtils { + private final IPlatformCompat mPlatformCompat = IPlatformCompat.Stub.asInterface( + ServiceManager.getService(Context.PLATFORM_COMPAT_SERVICE)); + + /** + * Whether to finish the {@link android.view.inputmethod.InputConnection} when the device + * becomes {@link android.os.PowerManager#isInteractive non-interactive}. + * + * @param imeUid The uid of the IME application + */ + public boolean shouldFinishInputWithReportToIme(int imeUid) { + return isChangeEnabledByUid(FINISH_INPUT_NO_FALLBACK_CONNECTION, imeUid); + } + + private boolean isChangeEnabledByUid(long changeFlag, int uid) { + boolean result = false; + try { + result = mPlatformCompat.isChangeEnabledByUid(changeFlag, uid); + } catch (RemoteException e) { + } + return result; + } +} diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 0b7e39136feb3..afcbd8984e1da 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -15,7 +15,6 @@ package com.android.server.inputmethod; -import static android.inputmethodservice.InputMethodService.FINISH_INPUT_NO_FALLBACK_CONNECTION; import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_CRITICAL; import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_NORMAL; import static android.os.IServiceManager.DUMP_FLAG_PROTO; @@ -148,7 +147,6 @@ import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodSubtype; import com.android.internal.annotations.GuardedBy; -import com.android.internal.compat.IPlatformCompat; import com.android.internal.content.PackageMonitor; import com.android.internal.infra.AndroidFuture; import com.android.internal.inputmethod.DirectBootAwareness; @@ -279,6 +277,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub final WindowManagerInternal mWindowManagerInternal; final PackageManagerInternal mPackageManagerInternal; final InputManagerInternal mInputManagerInternal; + final ImePlatformCompatUtils mImePlatformCompatUtils; final boolean mHasFeature; private final ArrayMap> mAdditionalSubtypeMap = new ArrayMap<>(); @@ -691,8 +690,6 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub */ boolean mIsInteractive = true; - private final IPlatformCompat mPlatformCompat; - int mBackDisposition = InputMethodService.BACK_DISPOSITION_DEFAULT; /** @@ -1627,6 +1624,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); mPackageManagerInternal = LocalServices.getService(PackageManagerInternal.class); mInputManagerInternal = LocalServices.getService(InputManagerInternal.class); + mImePlatformCompatUtils = new ImePlatformCompatUtils(); mImeDisplayValidator = mWindowManagerInternal::getDisplayImePolicy; mAppOpsManager = mContext.getSystemService(AppOpsManager.class); mUserManager = mContext.getSystemService(UserManager.class); @@ -1634,8 +1632,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub mAccessibilityManager = AccessibilityManager.getInstance(context); mHasFeature = context.getPackageManager().hasSystemFeature( PackageManager.FEATURE_INPUT_METHODS); - mPlatformCompat = IPlatformCompat.Stub.asInterface( - ServiceManager.getService(Context.PLATFORM_COMPAT_SERVICE)); + mSlotIme = mContext.getString(com.android.internal.R.string.status_bar_ime); Bundle extras = new Bundle(); @@ -4728,14 +4725,9 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub // Inform the current client of the change in active status if (mCurClient != null && mCurClient.client != null) { - boolean reportToImeController = false; - try { - reportToImeController = mPlatformCompat.isChangeEnabledByUid( - FINISH_INPUT_NO_FALLBACK_CONNECTION, getCurMethodUidLocked()); - } catch (RemoteException e) { - } scheduleSetActiveToClient(mCurClient, mIsInteractive, mInFullscreenMode, - reportToImeController); + mImePlatformCompatUtils.shouldFinishInputWithReportToIme( + getCurMethodUidLocked())); } } }