Merge changes from topic "clear_show_forced_tm_dev" into tm-dev

* changes:
  Clear SHOW_FORCED flag when the app's targetSdk >= T
  Introduce ImePlatformCompatUtils
This commit is contained in:
TreeHugger Robot
2022-02-23 15:05:49 +00:00
committed by Android (Google) Code Review
5 changed files with 103 additions and 14 deletions

View File

@@ -53119,7 +53119,7 @@ package android.view.inputmethod {
field public static final int RESULT_SHOWN = 2; // 0x2
field public static final int RESULT_UNCHANGED_HIDDEN = 1; // 0x1
field public static final int RESULT_UNCHANGED_SHOWN = 0; // 0x0
field public static final int SHOW_FORCED = 2; // 0x2
field @Deprecated public static final int SHOW_FORCED = 2; // 0x2
field public static final int SHOW_IMPLICIT = 1; // 0x1
}

View File

@@ -3082,6 +3082,7 @@ package android.view.inputmethod {
method @NonNull @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) public java.util.List<android.view.inputmethod.InputMethodInfo> getInputMethodListAsUser(int);
method public boolean hasActiveInputConnection(@Nullable android.view.View);
method public boolean isInputMethodPickerShown();
field public static final long CLEAR_SHOW_FORCED_FLAG_WHEN_LEAVING = 214016041L; // 0xcc1a029L
}
}

View File

@@ -46,6 +46,8 @@ import android.annotation.SystemService;
import android.annotation.TestApi;
import android.annotation.UserIdInt;
import android.app.ActivityThread;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledSince;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.ComponentName;
import android.content.ContentResolver;
@@ -356,6 +358,21 @@ public final class InputMethodManager {
/** @hide */
public static final int SHOW_IM_PICKER_MODE_EXCLUDE_AUXILIARY_SUBTYPES = 2;
/**
* Clear {@link #SHOW_FORCED} flag when the next IME focused application changed.
*
* <p>
* Note that when this flag enabled in server side, {@link #SHOW_FORCED} will no longer
* affect the next focused application to keep showing IME, in case of unexpected IME visible
* when the next focused app isn't be the IME requester. </p>
*
* @hide
*/
@TestApi
@ChangeId
@EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
public static final long CLEAR_SHOW_FORCED_FLAG_WHEN_LEAVING = 214016041L; // This is a bug id.
@UnsupportedAppUsage
final IInputMethodManager mService;
final Looper mMainLooper;
@@ -1646,7 +1663,14 @@ public final class InputMethodManager {
* Flag for {@link #showSoftInput} to indicate that the user has forced
* the input method open (such as by long-pressing menu) so it should
* not be closed until they explicitly do so.
*
* @deprecated Use {@link #showSoftInput} without this flag instead. Using this flag can lead
* to the soft input remaining visible even when the calling application is closed. The
* use of this flag can make the soft input remains visible globally. Starting in
* {@link Build.VERSION_CODES#TIRAMISU Android T}, this flag only has an effect while the
* caller is currently focused.
*/
@Deprecated
public static final int SHOW_FORCED = 0x0002;
/**

View File

@@ -0,0 +1,64 @@
/*
* 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 static android.view.inputmethod.InputMethodManager.CLEAR_SHOW_FORCED_FLAG_WHEN_LEAVING;
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);
}
/**
* Whether to clear {@link android.view.inputmethod.InputMethodManager#SHOW_FORCED} flag
* when the next IME focused application changed.
*
* @param clientUid The uid of the app
*/
public boolean shouldClearShowForcedFlag(int clientUid) {
return isChangeEnabledByUid(CLEAR_SHOW_FORCED_FLAG_WHEN_LEAVING, clientUid);
}
private boolean isChangeEnabledByUid(long changeFlag, int uid) {
boolean result = false;
try {
result = mPlatformCompat.isChangeEnabledByUid(changeFlag, uid);
} catch (RemoteException e) {
}
return result;
}
}

View File

@@ -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<String, List<InputMethodSubtype>> 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();
@@ -3620,6 +3617,14 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
return InputBindResult.INVALID_USER;
}
final boolean shouldClearFlag = mImePlatformCompatUtils.shouldClearShowForcedFlag(cs.uid);
// In case mShowForced flag affects the next client to keep IME visible, when the current
// client is leaving due to the next focused client, we clear mShowForced flag when the
// next client's targetSdkVersion is T or higher.
if (mCurFocusedWindow != windowToken && mShowForced && shouldClearFlag) {
mShowForced = false;
}
// cross-profile access is always allowed here to allow profile-switching.
if (!mSettings.isCurrentProfile(userId)) {
Slog.w(TAG, "A background user is requesting window. Hiding IME.");
@@ -4728,14 +4733,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()));
}
}
}