Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 99038488 authored by Wilson Wu's avatar Wilson Wu Committed by Ming-Shin Lu
Browse files

Add ImeTargetVisibilityPolicy functions for applier

Add following utility methods into ImeVisibilityApplier:
  - showImeScreenshot
  - removeImeScreenshot

IMMS could use those API after this change. Also introduce new reasons
for those operations tracking.

This change only build the dependency between
ImeVisibilityApplier and ImeTargetVisibilityPolicy and didn't change
any behaviors.

Bug: 258048231
Test: atest DefaultImeVisibilityApplierTest

Change-Id: I2e1e4bc106fc14aa65825ee82dc09390422951c5
parent f8c63371
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -255,6 +255,10 @@ public final class InputMethodDebug {
                return "HIDE_SOFT_INPUT_IMM_DEPRECATION";
            case SoftInputShowHideReason.HIDE_WINDOW_GAINED_FOCUS_WITHOUT_EDITOR:
                return "HIDE_WINDOW_GAINED_FOCUS_WITHOUT_EDITOR";
            case SoftInputShowHideReason.SHOW_IME_SCREENSHOT_FROM_IMMS:
                return "SHOW_IME_SCREENSHOT_FROM_IMMS";
            case SoftInputShowHideReason.REMOVE_IME_SCREENSHOT_FROM_IMMS:
                return "REMOVE_IME_SCREENSHOT_FROM_IMMS";
            default:
                return "Unknown=" + reason;
        }
+13 −1
Original line number Diff line number Diff line
@@ -65,7 +65,9 @@ import java.lang.annotation.Retention;
        SoftInputShowHideReason.HIDE_SOFT_INPUT_IME_TOGGLE_SOFT_INPUT,
        SoftInputShowHideReason.HIDE_SOFT_INPUT_EXTRACT_INPUT_CHANGED,
        SoftInputShowHideReason.HIDE_SOFT_INPUT_IMM_DEPRECATION,
        SoftInputShowHideReason.HIDE_WINDOW_GAINED_FOCUS_WITHOUT_EDITOR
        SoftInputShowHideReason.HIDE_WINDOW_GAINED_FOCUS_WITHOUT_EDITOR,
        SoftInputShowHideReason.SHOW_IME_SCREENSHOT_FROM_IMMS,
        SoftInputShowHideReason.REMOVE_IME_SCREENSHOT_FROM_IMMS,
})
public @interface SoftInputShowHideReason {
    /** Show soft input by {@link android.view.inputmethod.InputMethodManager#showSoftInput}. */
@@ -259,4 +261,14 @@ public @interface SoftInputShowHideReason {
     */
    int HIDE_WINDOW_GAINED_FOCUS_WITHOUT_EDITOR =
            ImeProtoEnums.REASON_HIDE_WINDOW_GAINED_FOCUS_WITHOUT_EDITOR;

    /**
     * Shows ime screenshot by {@link com.android.server.inputmethod.InputMethodManagerService}.
     */
    int SHOW_IME_SCREENSHOT_FROM_IMMS = ImeProtoEnums.REASON_SHOW_IME_SCREENSHOT_FROM_IMMS;

    /**
     * Removes ime screenshot by {@link com.android.server.inputmethod.InputMethodManagerService}.
     */
    int REMOVE_IME_SCREENSHOT_FROM_IMMS = ImeProtoEnums.REASON_REMOVE_IME_SCREENSHOT_FROM_IMMS;
}
+31 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.server.inputmethod;

import static android.view.inputmethod.ImeTracker.DEBUG_IME_VISIBILITY;

import static com.android.internal.inputmethod.SoftInputShowHideReason.REMOVE_IME_SCREENSHOT_FROM_IMMS;
import static com.android.internal.inputmethod.SoftInputShowHideReason.SHOW_IME_SCREENSHOT_FROM_IMMS;
import static com.android.server.EventLogTags.IMF_HIDE_IME;
import static com.android.server.EventLogTags.IMF_SHOW_IME;
import static com.android.server.inputmethod.ImeVisibilityStateComputer.STATE_HIDE_IME;
@@ -26,6 +28,7 @@ import static com.android.server.inputmethod.ImeVisibilityStateComputer.STATE_HI
import static com.android.server.inputmethod.ImeVisibilityStateComputer.STATE_SHOW_IME;
import static com.android.server.inputmethod.ImeVisibilityStateComputer.STATE_SHOW_IME_IMPLICIT;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.IBinder;
import android.os.ResultReceiver;
@@ -38,6 +41,7 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.inputmethod.InputMethodDebug;
import com.android.internal.inputmethod.SoftInputShowHideReason;
import com.android.server.LocalServices;
import com.android.server.wm.ImeTargetVisibilityPolicy;
import com.android.server.wm.WindowManagerInternal;

import java.util.Objects;
@@ -56,10 +60,14 @@ final class DefaultImeVisibilityApplier implements ImeVisibilityApplier {

    private final WindowManagerInternal mWindowManagerInternal;

    @NonNull
    private final ImeTargetVisibilityPolicy mImeTargetVisibilityPolicy;


    DefaultImeVisibilityApplier(InputMethodManagerService service) {
        mService = service;
        mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
        mImeTargetVisibilityPolicy = LocalServices.getService(ImeTargetVisibilityPolicy.class);
    }

    @GuardedBy("ImfLock.class")
@@ -166,4 +174,27 @@ final class DefaultImeVisibilityApplier implements ImeVisibilityApplier {
                throw new IllegalArgumentException("Invalid IME visibility state: " + state);
        }
    }

    @GuardedBy("ImfLock.class")
    @Override
    public boolean showImeScreenshot(@NonNull IBinder imeTarget, int displayId,
            @Nullable ImeTracker.Token statsToken) {
        if (mImeTargetVisibilityPolicy.showImeScreenshot(imeTarget, displayId)) {
            mService.onShowHideSoftInputRequested(false /* show */, imeTarget,
                    SHOW_IME_SCREENSHOT_FROM_IMMS, statsToken);
            return true;
        }
        return false;
    }

    @GuardedBy("ImfLock.class")
    @Override
    public boolean removeImeScreenshot(int displayId) {
        if (mImeTargetVisibilityPolicy.removeImeScreenshot(displayId)) {
            mService.onShowHideSoftInputRequested(false /* show */, mService.mCurFocusedWindow,
                    REMOVE_IME_SCREENSHOT_FROM_IMMS, null);
            return true;
        }
        return false;
    }
}
+24 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.inputmethod;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.IBinder;
import android.os.ResultReceiver;
@@ -76,4 +77,27 @@ interface ImeVisibilityApplier {
        // 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 statsToken  A token that tracks the progress of an IME request.
     * @return {@code true} if success, {@code false} otherwise.
     */
    default boolean showImeScreenshot(@NonNull IBinder windowToken, int displayId,
            @Nullable ImeTracker.Token statsToken) {
        return false;
    }

    /**
     * Removes the IME screenshot on the given display.
     *
     * @param displayId The target display of showing IME screenshot.
     * @return {@code true} if success, {@code false} otherwise.
     */
    default boolean removeImeScreenshot(int displayId) {
        return false;
    }
}
+10 −1
Original line number Diff line number Diff line
@@ -4453,6 +4453,10 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
    }

    private void attachImeScreenshotOnTarget(WindowState imeTarget) {
        attachImeScreenshotOnTarget(imeTarget, false);
    }

    private void attachImeScreenshotOnTarget(WindowState imeTarget, boolean hideImeWindow) {
        final SurfaceControl.Transaction t = getPendingTransaction();
        // Remove the obsoleted IME snapshot first in case the new snapshot happens to
        // override the current one before the transition finish and the surface never be
@@ -4461,6 +4465,11 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        mImeScreenshot = new ImeScreenshot(
                mWmService.mSurfaceControlFactory.apply(null), imeTarget);
        mImeScreenshot.attachAndShow(t);
        if (mInputMethodWindow != null && hideImeWindow) {
            // Hide the IME window when deciding to show IME snapshot on demand.
            // InsetsController will make IME visible again before animating it.
            mInputMethodWindow.hide(false, false);
        }
    }

    /**
@@ -4478,7 +4487,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
     */
    @VisibleForTesting
    void showImeScreenshot(WindowState imeTarget) {
        attachImeScreenshotOnTarget(imeTarget);
        attachImeScreenshotOnTarget(imeTarget, true /* hideImeWindow */);
    }

    /**
Loading