1 /*
2  * Copyright (C) 2014 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.input;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.UserIdInt;
22 import android.graphics.PointF;
23 import android.hardware.display.DisplayViewport;
24 import android.os.IBinder;
25 import android.view.InputChannel;
26 import android.view.inputmethod.InputMethodSubtype;
27 
28 import com.android.internal.inputmethod.InputMethodSubtypeHandle;
29 
30 import java.util.List;
31 
32 /**
33  * Input manager local system service interface.
34  *
35  * @hide Only for use within the system server.
36  */
37 public abstract class InputManagerInternal {
38 
39     /**
40      * Called by the display manager to set information about the displays as needed
41      * by the input system.  The input system must copy this information to retain it.
42      */
setDisplayViewports(List<DisplayViewport> viewports)43     public abstract void setDisplayViewports(List<DisplayViewport> viewports);
44 
45     /**
46      * Called by the power manager to tell the input manager whether it should start
47      * watching for wake events.
48      */
setInteractive(boolean interactive)49     public abstract void setInteractive(boolean interactive);
50 
51     /**
52      * Toggles Caps Lock state for input device with specific id.
53      *
54      * @param deviceId The id of input device.
55      */
toggleCapsLock(int deviceId)56     public abstract void toggleCapsLock(int deviceId);
57 
58     /**
59      * Set whether the input stack should deliver pulse gesture events when the device is asleep.
60      */
setPulseGestureEnabled(boolean enabled)61     public abstract void setPulseGestureEnabled(boolean enabled);
62 
63     /**
64      * Atomically transfers touch focus from one window to another as identified by
65      * their input channels.  It is possible for multiple windows to have
66      * touch focus if they support split touch dispatch
67      * {@link android.view.WindowManager.LayoutParams#FLAG_SPLIT_TOUCH} but this
68      * method only transfers touch focus of the specified window without affecting
69      * other windows that may also have touch focus at the same time.
70      *
71      * @param fromChannelToken The channel token of a window that currently has touch focus.
72      * @param toChannelToken The channel token of the window that should receive touch focus in
73      * place of the first.
74      * @return {@code true} if the transfer was successful. {@code false} if the window with the
75      * specified channel did not actually have touch focus at the time of the request.
76      */
transferTouchFocus(@onNull IBinder fromChannelToken, @NonNull IBinder toChannelToken)77     public abstract boolean transferTouchFocus(@NonNull IBinder fromChannelToken,
78             @NonNull IBinder toChannelToken);
79 
80     /**
81      * Sets the display id that the MouseCursorController will be forced to target. Pass
82      * {@link android.view.Display#INVALID_DISPLAY} to clear the override.
83      *
84      * Note: This method generally blocks until the pointer display override has propagated.
85      * When setting a new override, the caller should ensure that an input device that can control
86      * the mouse pointer is connected. If a new override is set when no such input device is
87      * connected, the caller may be blocked for an arbitrary period of time.
88      *
89      * @return true if the pointer displayId was set successfully, or false if it fails.
90      */
setVirtualMousePointerDisplayId(int pointerDisplayId)91     public abstract boolean setVirtualMousePointerDisplayId(int pointerDisplayId);
92 
93     /**
94      * Gets the display id that the MouseCursorController is being forced to target. Returns
95      * {@link android.view.Display#INVALID_DISPLAY} if there is no override
96      */
getVirtualMousePointerDisplayId()97     public abstract int getVirtualMousePointerDisplayId();
98 
99     /**
100      * Gets the current position of the mouse cursor.
101      *
102      * Returns NaN-s as the coordinates if the cursor is not available.
103      */
getCursorPosition()104     public abstract PointF getCursorPosition();
105 
106     /**
107      * Sets the pointer acceleration.
108      * See {@code frameworks/native/include/input/VelocityControl.h#VelocityControlParameters}.
109      */
setPointerAcceleration(float acceleration, int displayId)110     public abstract void setPointerAcceleration(float acceleration, int displayId);
111 
112     /**
113      * Sets the eligibility of windows on a given display for pointer capture. If a display is
114      * marked ineligible, requests to enable pointer capture for windows on that display will be
115      * ignored.
116      */
setDisplayEligibilityForPointerCapture(int displayId, boolean isEligible)117     public abstract void setDisplayEligibilityForPointerCapture(int displayId, boolean isEligible);
118 
119     /** Sets the visibility of the cursor. */
setPointerIconVisible(boolean visible, int displayId)120     public abstract void setPointerIconVisible(boolean visible, int displayId);
121 
122     /** Registers the {@link LidSwitchCallback} to begin receiving notifications. */
registerLidSwitchCallback(@onNull LidSwitchCallback callbacks)123     public abstract void registerLidSwitchCallback(@NonNull LidSwitchCallback callbacks);
124 
125     /**
126      * Unregisters a {@link LidSwitchCallback callback} previously registered with
127      * {@link #registerLidSwitchCallback(LidSwitchCallback)}.
128      */
unregisterLidSwitchCallback(@onNull LidSwitchCallback callbacks)129     public abstract void unregisterLidSwitchCallback(@NonNull LidSwitchCallback callbacks);
130 
131     /** Callback interface for notifications relating to the lid switch. */
132     public interface LidSwitchCallback {
133         /**
134          * This callback is invoked when the lid switch changes state. Will be triggered once on
135          * registration of the callback with a {@code whenNanos} of 0 and then on every subsequent
136          * change in lid switch state.
137          *
138          * @param whenNanos the time when the change occurred
139          * @param lidOpen true if the lid is open
140          */
notifyLidSwitchChanged(long whenNanos, boolean lidOpen)141         void notifyLidSwitchChanged(long whenNanos, boolean lidOpen);
142     }
143 
144     /** Create an {@link InputChannel} that is registered to InputDispatcher. */
createInputChannel(String inputChannelName)145     public abstract InputChannel createInputChannel(String inputChannelName);
146 
147     /**
148      * Pilfer pointers from the input channel with the given token so that ongoing gestures are
149      * canceled for all other channels.
150      */
pilferPointers(IBinder token)151     public abstract void pilferPointers(IBinder token);
152 
153     /**
154      * Called when the current input method and/or {@link InputMethodSubtype} is updated.
155      *
156      * @param userId User ID to be notified about.
157      * @param subtypeHandle A {@link InputMethodSubtypeHandle} corresponds to {@code subtype}.
158      * @param subtype A {@link InputMethodSubtype} object, or {@code null} when the current
159      *                {@link InputMethodSubtype} is not suitable for the physical keyboard layout
160      *                mapping.
161      * @see InputMethodSubtype#isSuitableForPhysicalKeyboardLayoutMapping()
162      */
onInputMethodSubtypeChangedForKeyboardLayoutMapping(@serIdInt int userId, @Nullable InputMethodSubtypeHandle subtypeHandle, @Nullable InputMethodSubtype subtype)163     public abstract void onInputMethodSubtypeChangedForKeyboardLayoutMapping(@UserIdInt int userId,
164             @Nullable InputMethodSubtypeHandle subtypeHandle,
165             @Nullable InputMethodSubtype subtype);
166 
167     /**
168      * Increments keyboard backlight level if the device has an associated keyboard backlight
169      * {@see Light.LIGHT_TYPE_KEYBOARD_BACKLIGHT}
170      */
incrementKeyboardBacklight(int deviceId)171     public abstract void incrementKeyboardBacklight(int deviceId);
172 
173     /**
174      * Decrements keyboard backlight level if the device has an associated keyboard backlight
175      * {@see Light.LIGHT_TYPE_KEYBOARD_BACKLIGHT}
176      */
decrementKeyboardBacklight(int deviceId)177     public abstract void decrementKeyboardBacklight(int deviceId);
178 
179     /**
180      * Add a runtime association between the input port and device type. Input ports are expected to
181      * be unique.
182      * @param inputPort The port of the input device.
183      * @param type The type of the device. E.g. "touchNavigation".
184      */
setTypeAssociation(@onNull String inputPort, @NonNull String type)185     public abstract void setTypeAssociation(@NonNull String inputPort, @NonNull String type);
186 
187     /**
188      * Removes a runtime association between the input device and type.
189      *
190      * @param inputPort The port of the input device.
191      */
unsetTypeAssociation(@onNull String inputPort)192     public abstract void unsetTypeAssociation(@NonNull String inputPort);
193 
194     /**
195      * Add a mapping from the input port and a keyboard layout, by unique id. Input
196      * ports are expected to be unique.
197      *
198      * @param inputPort   The port of the input device.
199      * @param languageTag the language of the input device as an IETF
200      *                    <a href="https://tools.ietf.org/html/bcp47">BCP-47</a>
201      *                    conformant tag.
202      * @param layoutType  the layout type such as "qwerty" or "azerty".
203      */
addKeyboardLayoutAssociation(@onNull String inputPort, @NonNull String languageTag, @NonNull String layoutType)204     public abstract void addKeyboardLayoutAssociation(@NonNull String inputPort,
205             @NonNull String languageTag, @NonNull String layoutType);
206 
207     /**
208      * Removes the mapping from input port to the keyboard layout identifier.
209      *
210      * @param inputPort The port of the input device.
211      */
removeKeyboardLayoutAssociation(@onNull String inputPort)212     public abstract void removeKeyboardLayoutAssociation(@NonNull String inputPort);
213 
214     /**
215      * Set whether stylus button reporting through motion events should be enabled.
216      *
217      * @param enabled When true, stylus buttons will not be reported through motion events.
218      */
setStylusButtonMotionEventsEnabled(boolean enabled)219     public abstract void setStylusButtonMotionEventsEnabled(boolean enabled);
220 
221     /**
222      * Notify whether any user activity occurred. This includes any input activity on any
223      * display, external peripherals, fingerprint sensor, etc.
224      */
notifyUserActivity()225     public abstract void notifyUserActivity();
226 }
227