blob: d49d4b2c3278ef1866658dd76a0c03565e48d46b [file] [log] [blame]
Yohei Yukawafa6e0a82015-07-23 15:08:59 -07001/*
2 * Copyright (C) 2015 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
Yohei Yukawac3de83e2018-08-28 16:09:34 -070017package com.android.server.inputmethod;
Yohei Yukawafa6e0a82015-07-23 15:08:59 -070018
Yohei Yukawaa878b952019-01-10 19:36:24 -080019import android.annotation.NonNull;
20import android.annotation.UserIdInt;
lpeter133fce02020-03-05 20:32:16 +080021import android.os.IBinder;
Adam Hebc67f2e2019-11-13 14:34:56 -080022import android.view.inputmethod.InlineSuggestionsRequest;
Yohei Yukawaa878b952019-01-10 19:36:24 -080023import android.view.inputmethod.InputMethodInfo;
24
lumarkd85e1582019-12-29 20:20:41 +080025import com.android.internal.inputmethod.SoftInputShowHideReason;
Adam Hebc67f2e2019-11-13 14:34:56 -080026import com.android.internal.view.IInlineSuggestionsRequestCallback;
Feng Cao36960ee2020-02-18 18:23:30 -080027import com.android.internal.view.InlineSuggestionsRequestInfo;
Yohei Yukawaa878b952019-01-10 19:36:24 -080028import com.android.server.LocalServices;
29
30import java.util.Collections;
31import java.util.List;
Tarandeep Singh89a6c482017-11-21 14:26:11 -080032
Yohei Yukawafa6e0a82015-07-23 15:08:59 -070033/**
34 * Input method manager local system service interface.
Yohei Yukawafa6e0a82015-07-23 15:08:59 -070035 */
Yohei Yukawae24ed792018-08-28 19:10:32 -070036public abstract class InputMethodManagerInternal {
37 /**
Yuichiro Hanada34c4c0e2020-01-15 16:53:07 +090038 * Listener for input method list changed events.
39 */
40 public interface InputMethodListListener {
41 /**
42 * Called with the list of the installed IMEs when it's updated.
43 */
44 void onInputMethodListUpdated(List<InputMethodInfo> info, @UserIdInt int userId);
45 }
46
47 /**
Jorim Jaggi3c5d0f12016-05-24 19:04:30 -070048 * Hides the current input method, if visible.
49 */
lumarkd85e1582019-12-29 20:20:41 +080050 public abstract void hideCurrentInputMethod(@SoftInputShowHideReason int reason);
Tarandeep Singh89a6c482017-11-21 14:26:11 -080051
52 /**
Yohei Yukawaa878b952019-01-10 19:36:24 -080053 * Returns the list of installed input methods for the specified user.
54 *
55 * @param userId The user ID to be queried.
56 * @return A list of {@link InputMethodInfo}. VR-only IMEs are already excluded.
57 */
58 public abstract List<InputMethodInfo> getInputMethodListAsUser(@UserIdInt int userId);
59
60 /**
61 * Returns the list of installed input methods that are enabled for the specified user.
62 *
63 * @param userId The user ID to be queried.
64 * @return A list of {@link InputMethodInfo} that are enabled for {@code userId}.
65 */
66 public abstract List<InputMethodInfo> getEnabledInputMethodListAsUser(@UserIdInt int userId);
67
68 /**
Adam Hebc67f2e2019-11-13 14:34:56 -080069 * Called by the Autofill Frameworks to request an {@link InlineSuggestionsRequest} from
70 * the input method.
71 *
Feng Cao36960ee2020-02-18 18:23:30 -080072 * @param requestInfo information needed to create an {@link InlineSuggestionsRequest}.
Adam Hebc67f2e2019-11-13 14:34:56 -080073 * @param cb {@link IInlineSuggestionsRequestCallback} used to pass back the request object.
74 */
Feng Cao16b2de52020-01-09 17:27:27 -080075 public abstract void onCreateInlineSuggestionsRequest(@UserIdInt int userId,
Feng Cao36960ee2020-02-18 18:23:30 -080076 InlineSuggestionsRequestInfo requestInfo, IInlineSuggestionsRequestCallback cb);
Adam Hebc67f2e2019-11-13 14:34:56 -080077
78 /**
mincheli850892b2019-12-05 19:47:59 +080079 * Force switch to the enabled input method by {@code imeId} for current user. If the input
80 * method with {@code imeId} is not enabled or not installed, do nothing.
81 *
82 * @param imeId The input method ID to be switched to.
83 * @param userId The user ID to be queried.
84 * @return {@code true} if the current input method was successfully switched to the input
85 * method by {@code imeId}; {@code false} the input method with {@code imeId} is not available
86 * to be switched.
87 */
88 public abstract boolean switchToInputMethod(String imeId, @UserIdInt int userId);
89
90 /**
Yuichiro Hanada34c4c0e2020-01-15 16:53:07 +090091 * Registers a new {@link InputMethodListListener}.
92 */
93 public abstract void registerInputMethodListListener(InputMethodListListener listener);
94
95 /**
lpeter133fce02020-03-05 20:32:16 +080096 * Transfers input focus from a given input token to that of the IME window.
97 *
98 * @param sourceInputToken The source token.
99 * @param displayId The display hosting the IME window.
100 * @return {@code true} if the transfer is successful.
101 */
102 public abstract boolean transferTouchFocusToImeWindow(@NonNull IBinder sourceInputToken,
103 int displayId);
104
105 /**
Yohei Yukawae24ed792018-08-28 19:10:32 -0700106 * Fake implementation of {@link InputMethodManagerInternal}. All the methods do nothing.
107 */
Yohei Yukawaa878b952019-01-10 19:36:24 -0800108 private static final InputMethodManagerInternal NOP =
Yohei Yukawae24ed792018-08-28 19:10:32 -0700109 new InputMethodManagerInternal() {
110 @Override
lumarkd85e1582019-12-29 20:20:41 +0800111 public void hideCurrentInputMethod(@SoftInputShowHideReason int reason) {
Yohei Yukawae24ed792018-08-28 19:10:32 -0700112 }
113
114 @Override
Yohei Yukawaa878b952019-01-10 19:36:24 -0800115 public List<InputMethodInfo> getInputMethodListAsUser(int userId) {
116 return Collections.emptyList();
117 }
118
119 @Override
120 public List<InputMethodInfo> getEnabledInputMethodListAsUser(int userId) {
121 return Collections.emptyList();
122 }
Adam Hebc67f2e2019-11-13 14:34:56 -0800123
124 @Override
Feng Cao16b2de52020-01-09 17:27:27 -0800125 public void onCreateInlineSuggestionsRequest(int userId,
Feng Cao36960ee2020-02-18 18:23:30 -0800126 InlineSuggestionsRequestInfo requestInfo,
Feng Cao16b2de52020-01-09 17:27:27 -0800127 IInlineSuggestionsRequestCallback cb) {
Adam Hebc67f2e2019-11-13 14:34:56 -0800128 }
mincheli850892b2019-12-05 19:47:59 +0800129
130 @Override
131 public boolean switchToInputMethod(String imeId, int userId) {
132 return false;
133 }
Yuichiro Hanada34c4c0e2020-01-15 16:53:07 +0900134
135 @Override
136 public void registerInputMethodListListener(InputMethodListListener listener) {
137 }
lpeter133fce02020-03-05 20:32:16 +0800138
139 @Override
140 public boolean transferTouchFocusToImeWindow(@NonNull IBinder sourceInputToken,
141 int displayId) {
142 return false;
143 }
Yohei Yukawae24ed792018-08-28 19:10:32 -0700144 };
Yohei Yukawaa878b952019-01-10 19:36:24 -0800145
146 /**
147 * @return Global instance if exists. Otherwise, a dummy no-op instance.
148 */
149 @NonNull
150 public static InputMethodManagerInternal get() {
151 final InputMethodManagerInternal instance =
152 LocalServices.getService(InputMethodManagerInternal.class);
153 return instance != null ? instance : NOP;
154 }
Yohei Yukawafa6e0a82015-07-23 15:08:59 -0700155}