1 /*
2  * Copyright (C) 2021 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 android.inputmethodservice;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.SuppressLint;
22 import android.content.Context;
23 import android.os.Bundle;
24 import android.view.inputmethod.InputConnection;
25 import android.view.inputmethod.InputContentInfo;
26 
27 import java.io.FileDescriptor;
28 import java.io.PrintWriter;
29 
30 /**
31  * A set of internal methods exposed by {@link InputMethodService} to be called only from other
32  * framework classes for internal use.
33  *
34  * <p>CAVEATS: {@link AbstractInputMethodService} does not support all the methods here.</p>
35  */
36 interface InputMethodServiceInternal {
37     /**
38      * @return {@link Context} associated with the service.
39      */
40     @NonNull
getContext()41     Context getContext();
42 
43     /**
44      * Allow the receiver of {@link InputContentInfo} to obtain a temporary read-only access
45      * permission to the content.
46      *
47      * @param inputContentInfo Content to be temporarily exposed from the input method to the
48      *                         application. This cannot be {@code null}.
49      * @param inputConnection {@link InputConnection} with which
50      *                        {@link InputConnection#commitContent(InputContentInfo, int, Bundle)}
51      *                        will be called.
52      */
exposeContent(@onNull InputContentInfo inputContentInfo, @NonNull InputConnection inputConnection)53     default void exposeContent(@NonNull InputContentInfo inputContentInfo,
54             @NonNull InputConnection inputConnection) {
55     }
56 
57     /**
58      * Called when the user took some actions that should be taken into consideration to update the
59      * MRU list for input method rotation.
60      */
notifyUserActionIfNecessary()61     default void notifyUserActionIfNecessary() {
62     }
63 
64     /**
65      * Called when the system is asking the IME to dump its information for debugging.
66      *
67      * <p>The caller is responsible for checking {@link android.Manifest.permission.DUMP}.</p>
68      *
69      * @param fd The raw file descriptor that the dump is being sent to.
70      * @param fout The file to which you should dump your state.  This will be
71      * closed for you after you return.
72      * @param args additional arguments to the dump request.
73      */
dump(@uppressLint"UseParcelFileDescriptor") @onNull FileDescriptor fd, @NonNull PrintWriter fout, @NonNull String[] args)74     default void dump(@SuppressLint("UseParcelFileDescriptor") @NonNull FileDescriptor fd,
75             @NonNull PrintWriter fout, @NonNull String[] args) {
76     }
77 
78     /**
79      * Called with {@link com.android.internal.inputmethod.ImeTracing#triggerServiceDump(String,
80      * com.android.internal.inputmethod.ImeTracing.ServiceDumper, byte[])} needs to be triggered
81      * with the given parameters.
82      *
83      * @param where {@code where} parameter to be passed.
84      * @param icProto {@code icProto} parameter to be passed.
85      */
triggerServiceDump(@onNull String where, @Nullable byte[] icProto)86     default void triggerServiceDump(@NonNull String where, @Nullable byte[] icProto) {
87     }
88 
89     /**
90      * @return {@code true} if {@link InputMethodService} is destroyed.
91      */
isServiceDestroyed()92     default boolean isServiceDestroyed() {
93         return false;
94     };
95 }
96