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.os.IBinder;
20 import android.util.SparseArray;
21 import android.view.inputmethod.InputBinding;
22 
23 import com.android.internal.annotations.GuardedBy;
24 import com.android.internal.inputmethod.IRemoteInputConnection;
25 
26 final class ClientState {
27     final IInputMethodClientInvoker mClient;
28     final IRemoteInputConnection mFallbackInputConnection;
29     final int mUid;
30     final int mPid;
31     final int mSelfReportedDisplayId;
32     final InputBinding mBinding;
33     final IBinder.DeathRecipient mClientDeathRecipient;
34 
35     @GuardedBy("ImfLock.class")
36     boolean mSessionRequested;
37 
38     @GuardedBy("ImfLock.class")
39     boolean mSessionRequestedForAccessibility;
40 
41     @GuardedBy("ImfLock.class")
42     InputMethodManagerService.SessionState mCurSession;
43 
44     @GuardedBy("ImfLock.class")
45     SparseArray<InputMethodManagerService.AccessibilitySessionState> mAccessibilitySessions =
46             new SparseArray<>();
47 
48     @Override
toString()49     public String toString() {
50         return "ClientState{" + Integer.toHexString(
51                 System.identityHashCode(this)) + " mUid=" + mUid
52                 + " mPid=" + mPid + " mSelfReportedDisplayId=" + mSelfReportedDisplayId + "}";
53     }
54 
ClientState(IInputMethodClientInvoker client, IRemoteInputConnection fallbackInputConnection, int uid, int pid, int selfReportedDisplayId, IBinder.DeathRecipient clientDeathRecipient)55     ClientState(IInputMethodClientInvoker client,
56             IRemoteInputConnection fallbackInputConnection,
57             int uid, int pid, int selfReportedDisplayId,
58             IBinder.DeathRecipient clientDeathRecipient) {
59         mClient = client;
60         mFallbackInputConnection = fallbackInputConnection;
61         mUid = uid;
62         mPid = pid;
63         mSelfReportedDisplayId = selfReportedDisplayId;
64         mBinding = new InputBinding(null /*conn*/, mFallbackInputConnection.asBinder(), mUid,
65                 mPid);
66         mClientDeathRecipient = clientDeathRecipient;
67     }
68 }
69