blob: ab95e4b52dc6d1860d3e94687b705441f1ad4b1e [file] [log] [blame]
Dianne Hackborndf89e652011-10-06 22:35:11 -07001/*
2 * Copyright (C) 2011 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
17package com.android.server.wm;
18
Robert Carra80ad042018-08-14 12:54:20 -070019import android.graphics.Rect;
Robert Carr0bcbe642018-10-11 19:07:43 -070020import android.os.Binder;
Winson Chung6463c362017-09-25 16:23:26 -070021import android.os.IBinder;
Dianne Hackborndf89e652011-10-06 22:35:11 -070022import android.os.Process;
Winson Chung6463c362017-09-25 16:23:26 -070023import android.os.RemoteException;
24import android.os.UserHandle;
Jorim Jaggif6ef1832019-01-31 14:42:44 +010025import android.view.InputApplicationHandle;
Chavi Weingarten6ef9cc62019-02-07 16:28:45 +000026import android.view.InputChannel;
Robert Carr788f5742018-07-30 17:46:45 -070027import android.view.InputWindowHandle;
Robert Carra80ad042018-08-14 12:54:20 -070028import android.view.SurfaceControl;
Chavi Weingarten6ef9cc62019-02-07 16:28:45 +000029import android.view.WindowManager;
Selim Cinekf83e8242015-05-19 18:08:14 -070030
Winson Chung6463c362017-09-25 16:23:26 -070031import java.io.PrintWriter;
32
33class InputConsumerImpl implements IBinder.DeathRecipient {
Dianne Hackborndf89e652011-10-06 22:35:11 -070034 final WindowManagerService mService;
35 final InputChannel mServerChannel, mClientChannel;
36 final InputApplicationHandle mApplicationHandle;
37 final InputWindowHandle mWindowHandle;
Dianne Hackborndf89e652011-10-06 22:35:11 -070038
Winson Chung6463c362017-09-25 16:23:26 -070039 final IBinder mToken;
40 final String mName;
41 final int mClientPid;
42 final UserHandle mClientUser;
43
Robert Carra80ad042018-08-14 12:54:20 -070044 final SurfaceControl mInputSurface;
45 Rect mTmpClipRect = new Rect();
46
Winson Chung6463c362017-09-25 16:23:26 -070047 InputConsumerImpl(WindowManagerService service, IBinder token, String name,
Arthur Hung95b38a92018-07-20 18:56:12 +080048 InputChannel inputChannel, int clientPid, UserHandle clientUser, int displayId) {
Dianne Hackborndf89e652011-10-06 22:35:11 -070049 mService = service;
Winson Chung6463c362017-09-25 16:23:26 -070050 mToken = token;
51 mName = name;
52 mClientPid = clientPid;
53 mClientUser = clientUser;
Dianne Hackborndf89e652011-10-06 22:35:11 -070054
55 InputChannel[] channels = InputChannel.openInputChannelPair(name);
56 mServerChannel = channels[0];
Vladislav Kaznacheev0d50d862016-03-29 15:43:28 -070057 if (inputChannel != null) {
58 channels[1].transferTo(inputChannel);
59 channels[1].dispose();
60 mClientChannel = inputChannel;
61 } else {
62 mClientChannel = channels[1];
63 }
Dianne Hackborndf89e652011-10-06 22:35:11 -070064 mService.mInputManager.registerInputChannel(mServerChannel, null);
Jeff Brown32cbc38552011-12-01 14:01:49 -080065
Robert Carr0bcbe642018-10-11 19:07:43 -070066 mApplicationHandle = new InputApplicationHandle(new Binder());
Dianne Hackborndf89e652011-10-06 22:35:11 -070067 mApplicationHandle.name = name;
68 mApplicationHandle.dispatchingTimeoutNanos =
69 WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
70
Robert Carre0a353c2018-08-02 16:38:04 -070071 mWindowHandle = new InputWindowHandle(mApplicationHandle, null, displayId);
Dianne Hackborndf89e652011-10-06 22:35:11 -070072 mWindowHandle.name = name;
Robert Carreadae822018-10-11 19:07:03 -070073 mWindowHandle.token = mServerChannel.getToken();
Selim Cinekf83e8242015-05-19 18:08:14 -070074 mWindowHandle.layoutParamsType = WindowManager.LayoutParams.TYPE_INPUT_CONSUMER;
Vladislav Kaznacheev0d50d862016-03-29 15:43:28 -070075 mWindowHandle.layer = getLayerLw(mWindowHandle.layoutParamsType);
Selim Cinekf83e8242015-05-19 18:08:14 -070076 mWindowHandle.layoutParamsFlags = 0;
Dianne Hackborndf89e652011-10-06 22:35:11 -070077 mWindowHandle.dispatchingTimeoutNanos =
78 WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
79 mWindowHandle.visible = true;
Selim Cinekf83e8242015-05-19 18:08:14 -070080 mWindowHandle.canReceiveKeys = false;
81 mWindowHandle.hasFocus = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -070082 mWindowHandle.hasWallpaper = false;
83 mWindowHandle.paused = false;
84 mWindowHandle.ownerPid = Process.myPid();
85 mWindowHandle.ownerUid = Process.myUid();
86 mWindowHandle.inputFeatures = 0;
87 mWindowHandle.scaleFactor = 1.0f;
Robert Carra80ad042018-08-14 12:54:20 -070088
89 mInputSurface = mService.makeSurfaceBuilder(mService.mRoot.getDisplayContent(displayId)
Chavi Weingarten6ef9cc62019-02-07 16:28:45 +000090 .getSession()).setContainerLayer().setName("Input Consumer " + name)
Robert Carra80ad042018-08-14 12:54:20 -070091 .build();
Dianne Hackborndf89e652011-10-06 22:35:11 -070092 }
93
Winson Chung6463c362017-09-25 16:23:26 -070094 void linkToDeathRecipient() {
95 if (mToken == null) {
96 return;
97 }
98
99 try {
100 mToken.linkToDeath(this, 0);
101 } catch (RemoteException e) {
102 // Client died, do nothing
103 }
104 }
105
106 void unlinkFromDeathRecipient() {
107 if (mToken == null) {
108 return;
109 }
110
111 mToken.unlinkToDeath(this, 0);
112 }
113
Robert Carra80ad042018-08-14 12:54:20 -0700114 void layout(SurfaceControl.Transaction t, int dw, int dh) {
115 t.setPosition(mInputSurface, 0, 0);
116
117 mTmpClipRect.set(0, 0, dw, dh);
118 t.setWindowCrop(mInputSurface, mTmpClipRect);
119 }
120
121 void layout(SurfaceControl.Transaction t, Rect r) {
122 t.setPosition(mInputSurface, r.left, r.top);
123 mTmpClipRect.set(0, 0, r.width(), r.height());
124 t.setWindowCrop(mInputSurface, mTmpClipRect);
125 }
126
127 void hide(SurfaceControl.Transaction t) {
128 t.hide(mInputSurface);
129 }
130
131 void show(SurfaceControl.Transaction t, WindowState w) {
132 t.show(mInputSurface);
133 t.setInputWindowInfo(mInputSurface, mWindowHandle);
134 t.setRelativeLayer(mInputSurface, w.getSurfaceControl(), 1);
Dianne Hackborndf89e652011-10-06 22:35:11 -0700135 }
136
Robert Carrb600bc22018-08-21 15:05:16 -0700137 void show(SurfaceControl.Transaction t, int layer) {
138 t.show(mInputSurface);
139 t.setInputWindowInfo(mInputSurface, mWindowHandle);
140 t.setLayer(mInputSurface, layer);
141 }
142
Dianne Hackborndf89e652011-10-06 22:35:11 -0700143 private int getLayerLw(int windowType) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800144 return mService.mPolicy.getWindowLayerFromTypeLw(windowType)
Dianne Hackborndf89e652011-10-06 22:35:11 -0700145 * WindowManagerService.TYPE_LAYER_MULTIPLIER
146 + WindowManagerService.TYPE_LAYER_OFFSET;
147 }
Vladislav Kaznacheev0d50d862016-03-29 15:43:28 -0700148
149 void disposeChannelsLw() {
150 mService.mInputManager.unregisterInputChannel(mServerChannel);
151 mClientChannel.dispose();
152 mServerChannel.dispose();
Winson Chung6463c362017-09-25 16:23:26 -0700153 unlinkFromDeathRecipient();
154 }
155
156 @Override
157 public void binderDied() {
158 synchronized (mService.getWindowManagerLock()) {
159 // Clean up the input consumer
Arthur Hung95b38a92018-07-20 18:56:12 +0800160 final InputMonitor inputMonitor =
161 mService.mRoot.getDisplayContent(mWindowHandle.displayId).getInputMonitor();
162 inputMonitor.destroyInputConsumer(mName);
Winson Chung6463c362017-09-25 16:23:26 -0700163 unlinkFromDeathRecipient();
164 }
165 }
166
167 void dump(PrintWriter pw, String name, String prefix) {
168 pw.println(prefix + " name=" + name + " pid=" + mClientPid + " user=" + mClientUser);
Vladislav Kaznacheev0d50d862016-03-29 15:43:28 -0700169 }
Dianne Hackborndf89e652011-10-06 22:35:11 -0700170}