1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.inputmethod; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.UserIdInt; 22 import android.inputmethodservice.InputMethodService; 23 import android.os.IBinder; 24 import android.os.SystemClock; 25 import android.view.WindowManager; 26 import android.view.inputmethod.EditorInfo; 27 import android.view.inputmethod.InputConnection; 28 29 import com.android.internal.inputmethod.IInputMethod; 30 import com.android.internal.inputmethod.StartInputReason; 31 32 import java.util.concurrent.atomic.AtomicInteger; 33 34 /** 35 * Internal state snapshot when 36 * {@link IInputMethod#startInput(IInputMethod.StartInputParams)} is about to be called. 37 * 38 * <p>Calling that IPC endpoint basically means that 39 * {@link InputMethodService#doStartInput(InputConnection, EditorInfo, boolean)} will be called 40 * back in the current IME process shortly, which will also affect what the current IME starts 41 * receiving from {@link InputMethodService#getCurrentInputConnection()}. In other words, this 42 * snapshot will be taken every time when {@link InputMethodManagerService} is initiating a new 43 * logical input session between the client application and the current IME.</p> 44 * 45 * <p>Be careful to not keep strong references to this object forever, which can prevent 46 * {@link StartInputInfo#mImeToken} and {@link StartInputInfo#mTargetWindow} from being GC-ed. 47 * </p> 48 */ 49 final class StartInputInfo { 50 private static final AtomicInteger sSequenceNumber = new AtomicInteger(0); 51 52 final int mSequenceNumber; 53 final long mTimestamp; 54 final long mWallTime; 55 @UserIdInt 56 final int mImeUserId; 57 @NonNull 58 final IBinder mImeToken; 59 final int mImeDisplayId; 60 @NonNull 61 final String mImeId; 62 @StartInputReason 63 final int mStartInputReason; 64 final boolean mRestarting; 65 @UserIdInt 66 final int mTargetUserId; 67 final int mTargetDisplayId; 68 @Nullable 69 final IBinder mTargetWindow; 70 @NonNull 71 final EditorInfo mEditorInfo; 72 @WindowManager.LayoutParams.SoftInputModeFlags 73 final int mTargetWindowSoftInputMode; 74 final int mClientBindSequenceNumber; 75 StartInputInfo(@serIdInt int imeUserId, @NonNull IBinder imeToken, int imeDisplayId, @NonNull String imeId, @StartInputReason int startInputReason, boolean restarting, @UserIdInt int targetUserId, int targetDisplayId, @Nullable IBinder targetWindow, @NonNull EditorInfo editorInfo, @WindowManager.LayoutParams.SoftInputModeFlags int targetWindowSoftInputMode, int clientBindSequenceNumber)76 StartInputInfo(@UserIdInt int imeUserId, @NonNull IBinder imeToken, int imeDisplayId, 77 @NonNull String imeId, @StartInputReason int startInputReason, boolean restarting, 78 @UserIdInt int targetUserId, int targetDisplayId, @Nullable IBinder targetWindow, 79 @NonNull EditorInfo editorInfo, 80 @WindowManager.LayoutParams.SoftInputModeFlags int targetWindowSoftInputMode, 81 int clientBindSequenceNumber) { 82 mSequenceNumber = sSequenceNumber.getAndIncrement(); 83 mTimestamp = SystemClock.uptimeMillis(); 84 mWallTime = System.currentTimeMillis(); 85 mImeUserId = imeUserId; 86 mImeToken = imeToken; 87 mImeDisplayId = imeDisplayId; 88 mImeId = imeId; 89 mStartInputReason = startInputReason; 90 mRestarting = restarting; 91 mTargetUserId = targetUserId; 92 mTargetDisplayId = targetDisplayId; 93 mTargetWindow = targetWindow; 94 mEditorInfo = editorInfo; 95 mTargetWindowSoftInputMode = targetWindowSoftInputMode; 96 mClientBindSequenceNumber = clientBindSequenceNumber; 97 } 98 } 99