blob: de13bd86a41552f34003bd977926878d9acc3e7c [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 /**
Ming-Shin Lu2c6e80b2020-05-13 00:12:26 +080048 * Called by the power manager to tell the input method manager whether it
49 * should start watching for wake events.
50 */
51 public abstract void setInteractive(boolean interactive);
52
53 /**
Jorim Jaggi3c5d0f12016-05-24 19:04:30 -070054 * Hides the current input method, if visible.
55 */
lumarkd85e1582019-12-29 20:20:41 +080056 public abstract void hideCurrentInputMethod(@SoftInputShowHideReason int reason);
Tarandeep Singh89a6c482017-11-21 14:26:11 -080057
58 /**
Yohei Yukawaa878b952019-01-10 19:36:24 -080059 * Returns the list of installed input methods for the specified user.
60 *
61 * @param userId The user ID to be queried.
62 * @return A list of {@link InputMethodInfo}. VR-only IMEs are already excluded.
63 */
64 public abstract List<InputMethodInfo> getInputMethodListAsUser(@UserIdInt int userId);
65
66 /**
67 * Returns the list of installed input methods that are enabled for the specified user.
68 *
69 * @param userId The user ID to be queried.
70 * @return A list of {@link InputMethodInfo} that are enabled for {@code userId}.
71 */
72 public abstract List<InputMethodInfo> getEnabledInputMethodListAsUser(@UserIdInt int userId);
73
74 /**
Adam Hebc67f2e2019-11-13 14:34:56 -080075 * Called by the Autofill Frameworks to request an {@link InlineSuggestionsRequest} from
76 * the input method.
77 *
Feng Cao36960ee2020-02-18 18:23:30 -080078 * @param requestInfo information needed to create an {@link InlineSuggestionsRequest}.
Adam Hebc67f2e2019-11-13 14:34:56 -080079 * @param cb {@link IInlineSuggestionsRequestCallback} used to pass back the request object.
80 */
Feng Cao16b2de52020-01-09 17:27:27 -080081 public abstract void onCreateInlineSuggestionsRequest(@UserIdInt int userId,
Feng Cao36960ee2020-02-18 18:23:30 -080082 InlineSuggestionsRequestInfo requestInfo, IInlineSuggestionsRequestCallback cb);
Adam Hebc67f2e2019-11-13 14:34:56 -080083
84 /**
mincheli850892b2019-12-05 19:47:59 +080085 * Force switch to the enabled input method by {@code imeId} for current user. If the input
86 * method with {@code imeId} is not enabled or not installed, do nothing.
87 *
88 * @param imeId The input method ID to be switched to.
89 * @param userId The user ID to be queried.
90 * @return {@code true} if the current input method was successfully switched to the input
91 * method by {@code imeId}; {@code false} the input method with {@code imeId} is not available
92 * to be switched.
93 */
94 public abstract boolean switchToInputMethod(String imeId, @UserIdInt int userId);
95
96 /**
Yuichiro Hanada34c4c0e2020-01-15 16:53:07 +090097 * Registers a new {@link InputMethodListListener}.
98 */
99 public abstract void registerInputMethodListListener(InputMethodListListener listener);
100
101 /**
lpeter133fce02020-03-05 20:32:16 +0800102 * Transfers input focus from a given input token to that of the IME window.
103 *
104 * @param sourceInputToken The source token.
105 * @param displayId The display hosting the IME window.
106 * @return {@code true} if the transfer is successful.
107 */
108 public abstract boolean transferTouchFocusToImeWindow(@NonNull IBinder sourceInputToken,
109 int displayId);
110
111 /**
Yohei Yukawae24ed792018-08-28 19:10:32 -0700112 * Fake implementation of {@link InputMethodManagerInternal}. All the methods do nothing.
113 */
Yohei Yukawaa878b952019-01-10 19:36:24 -0800114 private static final InputMethodManagerInternal NOP =
Yohei Yukawae24ed792018-08-28 19:10:32 -0700115 new InputMethodManagerInternal() {
116 @Override
Ming-Shin Lu2c6e80b2020-05-13 00:12:26 +0800117 public void setInteractive(boolean interactive) {
118 }
119
120 @Override
lumarkd85e1582019-12-29 20:20:41 +0800121 public void hideCurrentInputMethod(@SoftInputShowHideReason int reason) {
Yohei Yukawae24ed792018-08-28 19:10:32 -0700122 }
123
124 @Override
Yohei Yukawaa878b952019-01-10 19:36:24 -0800125 public List<InputMethodInfo> getInputMethodListAsUser(int userId) {
126 return Collections.emptyList();
127 }
128
129 @Override
130 public List<InputMethodInfo> getEnabledInputMethodListAsUser(int userId) {
131 return Collections.emptyList();
132 }
Adam Hebc67f2e2019-11-13 14:34:56 -0800133
134 @Override
Feng Cao16b2de52020-01-09 17:27:27 -0800135 public void onCreateInlineSuggestionsRequest(int userId,
Feng Cao36960ee2020-02-18 18:23:30 -0800136 InlineSuggestionsRequestInfo requestInfo,
Feng Cao16b2de52020-01-09 17:27:27 -0800137 IInlineSuggestionsRequestCallback cb) {
Adam Hebc67f2e2019-11-13 14:34:56 -0800138 }
mincheli850892b2019-12-05 19:47:59 +0800139
140 @Override
141 public boolean switchToInputMethod(String imeId, int userId) {
142 return false;
143 }
Yuichiro Hanada34c4c0e2020-01-15 16:53:07 +0900144
145 @Override
146 public void registerInputMethodListListener(InputMethodListListener listener) {
147 }
lpeter133fce02020-03-05 20:32:16 +0800148
149 @Override
150 public boolean transferTouchFocusToImeWindow(@NonNull IBinder sourceInputToken,
151 int displayId) {
152 return false;
153 }
Yohei Yukawae24ed792018-08-28 19:10:32 -0700154 };
Yohei Yukawaa878b952019-01-10 19:36:24 -0800155
156 /**
157 * @return Global instance if exists. Otherwise, a dummy no-op instance.
158 */
159 @NonNull
160 public static InputMethodManagerInternal get() {
161 final InputMethodManagerInternal instance =
162 LocalServices.getService(InputMethodManagerInternal.class);
163 return instance != null ? instance : NOP;
164 }
Yohei Yukawafa6e0a82015-07-23 15:08:59 -0700165}