Loading services/core/java/com/android/server/inputmethod/DefaultImeVisibilityApplier.java +53 −13 Original line number Diff line number Diff line Loading @@ -53,10 +53,10 @@ import com.android.server.wm.WindowManagerInternal; import java.util.Objects; /** * The default implementation of {@link ImeVisibilityApplier} used in * {@link InputMethodManagerService}. * A stateless helper class for IME visibility operations like show/hide and update Z-ordering * relative to the IME targeted window. */ final class DefaultImeVisibilityApplier implements ImeVisibilityApplier { final class DefaultImeVisibilityApplier { private static final String TAG = "DefaultImeVisibilityApplier"; Loading @@ -75,9 +75,18 @@ final class DefaultImeVisibilityApplier implements ImeVisibilityApplier { mImeTargetVisibilityPolicy = LocalServices.getService(ImeTargetVisibilityPolicy.class); } /** * Performs showing IME on top of the given window. * * @param showInputToken a token that represents the requester to show IME * @param statsToken the token tracking the current IME request * @param resultReceiver if non-null, this will be called back to the caller when * it has processed request to tell what it has done * @param reason yhe reason for requesting to show IME * @param userId the target user when performing show IME */ @GuardedBy("ImfLock.class") @Override public void performShowIme(IBinder showInputToken, @NonNull ImeTracker.Token statsToken, void performShowIme(IBinder showInputToken, @NonNull ImeTracker.Token statsToken, @InputMethod.ShowFlags int showFlags, ResultReceiver resultReceiver, @SoftInputShowHideReason int reason, @UserIdInt int userId) { final var bindingController = mService.getInputMethodBindingController(userId); Loading Loading @@ -105,9 +114,18 @@ final class DefaultImeVisibilityApplier implements ImeVisibilityApplier { } } /** * Performs hiding IME to the given window * * @param hideInputToken a token that represents the requester to hide IME * @param statsToken the token tracking the current IME request * @param resultReceiver if non-null, this will be called back to the caller when * it has processed request to tell what it has done * @param reason the reason for requesting to hide IME * @param userId the target user when performing hide IME */ @GuardedBy("ImfLock.class") @Override public void performHideIme(IBinder hideInputToken, @NonNull ImeTracker.Token statsToken, void performHideIme(IBinder hideInputToken, @NonNull ImeTracker.Token statsToken, ResultReceiver resultReceiver, @SoftInputShowHideReason int reason, @UserIdInt int userId) { final var bindingController = mService.getInputMethodBindingController(userId); Loading Loading @@ -139,9 +157,18 @@ final class DefaultImeVisibilityApplier implements ImeVisibilityApplier { } } /** * Applies the IME visibility from {@link android.inputmethodservice.InputMethodService} with * according to the given visibility state. * * @param windowToken the token of a window for applying the IME visibility * @param statsToken the token tracking the current IME request * @param state the new IME visibility state for the applier to handle * @param reason one of {@link SoftInputShowHideReason} * @param userId the target user when applying the IME visibility state */ @GuardedBy("ImfLock.class") @Override public void applyImeVisibility(IBinder windowToken, @Nullable ImeTracker.Token statsToken, void applyImeVisibility(IBinder windowToken, @Nullable ImeTracker.Token statsToken, @ImeVisibilityStateComputer.VisibilityState int state, @SoftInputShowHideReason int reason, @UserIdInt int userId) { final var bindingController = mService.getInputMethodBindingController(userId); Loading Loading @@ -211,9 +238,16 @@ final class DefaultImeVisibilityApplier implements ImeVisibilityApplier { } } /** * Shows the IME screenshot and attach it to the given IME target window. * * @param imeTarget the token of a window to show the IME screenshot * @param displayId the unique id to identify the display * @param userId the target user when when showing the IME screenshot * @return {@code true} if success, {@code false} otherwise */ @GuardedBy("ImfLock.class") @Override public boolean showImeScreenshot(@NonNull IBinder imeTarget, int displayId, boolean showImeScreenshot(@NonNull IBinder imeTarget, int displayId, @UserIdInt int userId) { if (mImeTargetVisibilityPolicy.showImeScreenshot(imeTarget, displayId)) { mService.onShowHideSoftInputRequested(false /* show */, imeTarget, Loading @@ -223,9 +257,15 @@ final class DefaultImeVisibilityApplier implements ImeVisibilityApplier { return false; } /** * Removes the IME screenshot on the given display. * * @param displayId the target display of showing IME screenshot * @param userId the target user of showing IME screenshot * @return {@code true} if success, {@code false} otherwise */ @GuardedBy("ImfLock.class") @Override public boolean removeImeScreenshot(int displayId, @UserIdInt int userId) { boolean removeImeScreenshot(int displayId, @UserIdInt int userId) { final var userData = mService.getUserData(userId); if (mImeTargetVisibilityPolicy.removeImeScreenshot(displayId)) { mService.onShowHideSoftInputRequested(false /* show */, Loading services/core/java/com/android/server/inputmethod/ImeVisibilityApplier.javadeleted 100644 → 0 +0 −114 Original line number Diff line number Diff line /* * 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 android.annotation.NonNull; import android.annotation.UserIdInt; import android.os.IBinder; import android.os.ResultReceiver; import android.view.inputmethod.ImeTracker; import android.view.inputmethod.InputMethod; import com.android.internal.inputmethod.SoftInputShowHideReason; /** * Interface for IME visibility operations like show/hide and update Z-ordering relative to the IME * targeted window. */ interface ImeVisibilityApplier { /** * Performs showing IME on top of the given window. * * @param showInputToken a token that represents the requester to show IME * @param statsToken the token tracking the current IME request * @param resultReceiver if non-null, this will be called back to the caller when * it has processed request to tell what it has done * @param reason yhe reason for requesting to show IME * @param userId the target user when performing show IME */ default void performShowIme(IBinder showInputToken, @NonNull ImeTracker.Token statsToken, @InputMethod.ShowFlags int showFlags, ResultReceiver resultReceiver, @SoftInputShowHideReason int reason, @UserIdInt int userId) { } /** * Performs hiding IME to the given window * * @param hideInputToken a token that represents the requester to hide IME * @param statsToken the token tracking the current IME request * @param resultReceiver if non-null, this will be called back to the caller when * it has processed request to tell what it has done * @param reason the reason for requesting to hide IME * @param userId the target user when performing hide IME */ default void performHideIme(IBinder hideInputToken, @NonNull ImeTracker.Token statsToken, ResultReceiver resultReceiver, @SoftInputShowHideReason int reason, @UserIdInt int userId) { } /** * Applies the IME visibility from {@link android.inputmethodservice.InputMethodService} with * according to the given visibility state. * * @param windowToken the token of a window for applying the IME visibility * @param statsToken the token tracking the current IME request * @param state the new IME visibility state for the applier to handle * @param reason the reason why the input window is visible or hidden * @param userId the target user when applying the IME visibility state */ default void applyImeVisibility(IBinder windowToken, @NonNull ImeTracker.Token statsToken, @ImeVisibilityStateComputer.VisibilityState int state, @SoftInputShowHideReason int reason, @UserIdInt int userId) { } /** * Updates the IME Z-ordering relative to the given window. * * This used to adjust the IME relative layer of the window during * {@link InputMethodManagerService} is in switching IME clients. * * @param windowToken the token of a window to update the Z-ordering relative to the IME */ default void updateImeLayeringByTarget(IBinder windowToken) { // TODO: add a method in WindowManagerInternal to call DC#updateImeInputAndControlTarget // here to end up updating IME layering after IMMS#attachNewInputLocked called. } /** * Shows the IME screenshot and attach it to the given IME target window. * * @param windowToken the token of a window to show the IME screenshot * @param displayId the unique id to identify the display * @param userId the target user when when showing the IME screenshot * @return {@code true} if success, {@code false} otherwise */ default boolean showImeScreenshot(@NonNull IBinder windowToken, int displayId, @UserIdInt int userId) { return false; } /** * Removes the IME screenshot on the given display. * * @param displayId the target display of showing IME screenshot * @param userId the target user of showing IME screenshot * @return {@code true} if success, {@code false} otherwise */ default boolean removeImeScreenshot(int displayId, @UserIdInt int userId) { return false; } } services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +3 −4 Original line number Diff line number Diff line Loading @@ -4824,12 +4824,11 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. } } @GuardedBy("ImfLock.class") @VisibleForTesting ImeVisibilityApplier getVisibilityApplier() { synchronized (ImfLock.class) { DefaultImeVisibilityApplier getVisibilityApplierLocked() { return mVisibilityApplier; } } void onApplyImeVisibilityFromComputer(IBinder windowToken, @NonNull ImeTracker.Token statsToken, @NonNull ImeVisibilityResult result) { Loading services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/DefaultImeVisibilityApplierTest.java +1 −2 Original line number Diff line number Diff line Loading @@ -74,9 +74,8 @@ public class DefaultImeVisibilityApplierTest extends InputMethodManagerServiceTe @Before public void setUp() throws RemoteException { super.setUp(); mVisibilityApplier = (DefaultImeVisibilityApplier) mInputMethodManagerService.getVisibilityApplier(); synchronized (ImfLock.class) { mVisibilityApplier = mInputMethodManagerService.getVisibilityApplierLocked(); mUserId = mInputMethodManagerService.getCurrentImeUserIdLocked(); mInputMethodManagerService.setAttachedClientForTesting(requireNonNull( mInputMethodManagerService.getClientStateLocked(mMockInputMethodClient))); Loading services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/ImeVisibilityStateComputerTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -58,8 +58,8 @@ import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; /** * Test the behavior of {@link ImeVisibilityStateComputer} and {@link ImeVisibilityApplier} when * requesting the IME visibility. * Test the behavior of {@link ImeVisibilityStateComputer} and {@link DefaultImeVisibilityApplier} * when requesting the IME visibility. * * <p> Build/Install/Run: * atest FrameworksInputMethodSystemServerTests:ImeVisibilityStateComputerTest Loading Loading
services/core/java/com/android/server/inputmethod/DefaultImeVisibilityApplier.java +53 −13 Original line number Diff line number Diff line Loading @@ -53,10 +53,10 @@ import com.android.server.wm.WindowManagerInternal; import java.util.Objects; /** * The default implementation of {@link ImeVisibilityApplier} used in * {@link InputMethodManagerService}. * A stateless helper class for IME visibility operations like show/hide and update Z-ordering * relative to the IME targeted window. */ final class DefaultImeVisibilityApplier implements ImeVisibilityApplier { final class DefaultImeVisibilityApplier { private static final String TAG = "DefaultImeVisibilityApplier"; Loading @@ -75,9 +75,18 @@ final class DefaultImeVisibilityApplier implements ImeVisibilityApplier { mImeTargetVisibilityPolicy = LocalServices.getService(ImeTargetVisibilityPolicy.class); } /** * Performs showing IME on top of the given window. * * @param showInputToken a token that represents the requester to show IME * @param statsToken the token tracking the current IME request * @param resultReceiver if non-null, this will be called back to the caller when * it has processed request to tell what it has done * @param reason yhe reason for requesting to show IME * @param userId the target user when performing show IME */ @GuardedBy("ImfLock.class") @Override public void performShowIme(IBinder showInputToken, @NonNull ImeTracker.Token statsToken, void performShowIme(IBinder showInputToken, @NonNull ImeTracker.Token statsToken, @InputMethod.ShowFlags int showFlags, ResultReceiver resultReceiver, @SoftInputShowHideReason int reason, @UserIdInt int userId) { final var bindingController = mService.getInputMethodBindingController(userId); Loading Loading @@ -105,9 +114,18 @@ final class DefaultImeVisibilityApplier implements ImeVisibilityApplier { } } /** * Performs hiding IME to the given window * * @param hideInputToken a token that represents the requester to hide IME * @param statsToken the token tracking the current IME request * @param resultReceiver if non-null, this will be called back to the caller when * it has processed request to tell what it has done * @param reason the reason for requesting to hide IME * @param userId the target user when performing hide IME */ @GuardedBy("ImfLock.class") @Override public void performHideIme(IBinder hideInputToken, @NonNull ImeTracker.Token statsToken, void performHideIme(IBinder hideInputToken, @NonNull ImeTracker.Token statsToken, ResultReceiver resultReceiver, @SoftInputShowHideReason int reason, @UserIdInt int userId) { final var bindingController = mService.getInputMethodBindingController(userId); Loading Loading @@ -139,9 +157,18 @@ final class DefaultImeVisibilityApplier implements ImeVisibilityApplier { } } /** * Applies the IME visibility from {@link android.inputmethodservice.InputMethodService} with * according to the given visibility state. * * @param windowToken the token of a window for applying the IME visibility * @param statsToken the token tracking the current IME request * @param state the new IME visibility state for the applier to handle * @param reason one of {@link SoftInputShowHideReason} * @param userId the target user when applying the IME visibility state */ @GuardedBy("ImfLock.class") @Override public void applyImeVisibility(IBinder windowToken, @Nullable ImeTracker.Token statsToken, void applyImeVisibility(IBinder windowToken, @Nullable ImeTracker.Token statsToken, @ImeVisibilityStateComputer.VisibilityState int state, @SoftInputShowHideReason int reason, @UserIdInt int userId) { final var bindingController = mService.getInputMethodBindingController(userId); Loading Loading @@ -211,9 +238,16 @@ final class DefaultImeVisibilityApplier implements ImeVisibilityApplier { } } /** * Shows the IME screenshot and attach it to the given IME target window. * * @param imeTarget the token of a window to show the IME screenshot * @param displayId the unique id to identify the display * @param userId the target user when when showing the IME screenshot * @return {@code true} if success, {@code false} otherwise */ @GuardedBy("ImfLock.class") @Override public boolean showImeScreenshot(@NonNull IBinder imeTarget, int displayId, boolean showImeScreenshot(@NonNull IBinder imeTarget, int displayId, @UserIdInt int userId) { if (mImeTargetVisibilityPolicy.showImeScreenshot(imeTarget, displayId)) { mService.onShowHideSoftInputRequested(false /* show */, imeTarget, Loading @@ -223,9 +257,15 @@ final class DefaultImeVisibilityApplier implements ImeVisibilityApplier { return false; } /** * Removes the IME screenshot on the given display. * * @param displayId the target display of showing IME screenshot * @param userId the target user of showing IME screenshot * @return {@code true} if success, {@code false} otherwise */ @GuardedBy("ImfLock.class") @Override public boolean removeImeScreenshot(int displayId, @UserIdInt int userId) { boolean removeImeScreenshot(int displayId, @UserIdInt int userId) { final var userData = mService.getUserData(userId); if (mImeTargetVisibilityPolicy.removeImeScreenshot(displayId)) { mService.onShowHideSoftInputRequested(false /* show */, Loading
services/core/java/com/android/server/inputmethod/ImeVisibilityApplier.javadeleted 100644 → 0 +0 −114 Original line number Diff line number Diff line /* * 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 android.annotation.NonNull; import android.annotation.UserIdInt; import android.os.IBinder; import android.os.ResultReceiver; import android.view.inputmethod.ImeTracker; import android.view.inputmethod.InputMethod; import com.android.internal.inputmethod.SoftInputShowHideReason; /** * Interface for IME visibility operations like show/hide and update Z-ordering relative to the IME * targeted window. */ interface ImeVisibilityApplier { /** * Performs showing IME on top of the given window. * * @param showInputToken a token that represents the requester to show IME * @param statsToken the token tracking the current IME request * @param resultReceiver if non-null, this will be called back to the caller when * it has processed request to tell what it has done * @param reason yhe reason for requesting to show IME * @param userId the target user when performing show IME */ default void performShowIme(IBinder showInputToken, @NonNull ImeTracker.Token statsToken, @InputMethod.ShowFlags int showFlags, ResultReceiver resultReceiver, @SoftInputShowHideReason int reason, @UserIdInt int userId) { } /** * Performs hiding IME to the given window * * @param hideInputToken a token that represents the requester to hide IME * @param statsToken the token tracking the current IME request * @param resultReceiver if non-null, this will be called back to the caller when * it has processed request to tell what it has done * @param reason the reason for requesting to hide IME * @param userId the target user when performing hide IME */ default void performHideIme(IBinder hideInputToken, @NonNull ImeTracker.Token statsToken, ResultReceiver resultReceiver, @SoftInputShowHideReason int reason, @UserIdInt int userId) { } /** * Applies the IME visibility from {@link android.inputmethodservice.InputMethodService} with * according to the given visibility state. * * @param windowToken the token of a window for applying the IME visibility * @param statsToken the token tracking the current IME request * @param state the new IME visibility state for the applier to handle * @param reason the reason why the input window is visible or hidden * @param userId the target user when applying the IME visibility state */ default void applyImeVisibility(IBinder windowToken, @NonNull ImeTracker.Token statsToken, @ImeVisibilityStateComputer.VisibilityState int state, @SoftInputShowHideReason int reason, @UserIdInt int userId) { } /** * Updates the IME Z-ordering relative to the given window. * * This used to adjust the IME relative layer of the window during * {@link InputMethodManagerService} is in switching IME clients. * * @param windowToken the token of a window to update the Z-ordering relative to the IME */ default void updateImeLayeringByTarget(IBinder windowToken) { // TODO: add a method in WindowManagerInternal to call DC#updateImeInputAndControlTarget // here to end up updating IME layering after IMMS#attachNewInputLocked called. } /** * Shows the IME screenshot and attach it to the given IME target window. * * @param windowToken the token of a window to show the IME screenshot * @param displayId the unique id to identify the display * @param userId the target user when when showing the IME screenshot * @return {@code true} if success, {@code false} otherwise */ default boolean showImeScreenshot(@NonNull IBinder windowToken, int displayId, @UserIdInt int userId) { return false; } /** * Removes the IME screenshot on the given display. * * @param displayId the target display of showing IME screenshot * @param userId the target user of showing IME screenshot * @return {@code true} if success, {@code false} otherwise */ default boolean removeImeScreenshot(int displayId, @UserIdInt int userId) { return false; } }
services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +3 −4 Original line number Diff line number Diff line Loading @@ -4824,12 +4824,11 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. } } @GuardedBy("ImfLock.class") @VisibleForTesting ImeVisibilityApplier getVisibilityApplier() { synchronized (ImfLock.class) { DefaultImeVisibilityApplier getVisibilityApplierLocked() { return mVisibilityApplier; } } void onApplyImeVisibilityFromComputer(IBinder windowToken, @NonNull ImeTracker.Token statsToken, @NonNull ImeVisibilityResult result) { Loading
services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/DefaultImeVisibilityApplierTest.java +1 −2 Original line number Diff line number Diff line Loading @@ -74,9 +74,8 @@ public class DefaultImeVisibilityApplierTest extends InputMethodManagerServiceTe @Before public void setUp() throws RemoteException { super.setUp(); mVisibilityApplier = (DefaultImeVisibilityApplier) mInputMethodManagerService.getVisibilityApplier(); synchronized (ImfLock.class) { mVisibilityApplier = mInputMethodManagerService.getVisibilityApplierLocked(); mUserId = mInputMethodManagerService.getCurrentImeUserIdLocked(); mInputMethodManagerService.setAttachedClientForTesting(requireNonNull( mInputMethodManagerService.getClientStateLocked(mMockInputMethodClient))); Loading
services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/ImeVisibilityStateComputerTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -58,8 +58,8 @@ import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; /** * Test the behavior of {@link ImeVisibilityStateComputer} and {@link ImeVisibilityApplier} when * requesting the IME visibility. * Test the behavior of {@link ImeVisibilityStateComputer} and {@link DefaultImeVisibilityApplier} * when requesting the IME visibility. * * <p> Build/Install/Run: * atest FrameworksInputMethodSystemServerTests:ImeVisibilityStateComputerTest Loading