blob: d40db8cb54439fd6de3ca3790069e9c9aad8c99f [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
Winson Chung6463c362017-09-25 16:23:26 -070019import android.os.IBinder;
Dianne Hackborndf89e652011-10-06 22:35:11 -070020import android.os.Process;
Winson Chung6463c362017-09-25 16:23:26 -070021import android.os.RemoteException;
22import android.os.UserHandle;
Craig Mautner59c00972012-07-30 12:10:24 -070023import android.view.Display;
Dianne Hackborndf89e652011-10-06 22:35:11 -070024import android.view.InputChannel;
Selim Cinekf83e8242015-05-19 18:08:14 -070025import android.view.WindowManager;
Selim Cinekf83e8242015-05-19 18:08:14 -070026import com.android.server.input.InputApplicationHandle;
27import com.android.server.input.InputWindowHandle;
28
Winson Chung6463c362017-09-25 16:23:26 -070029import java.io.PrintWriter;
30
31class InputConsumerImpl implements IBinder.DeathRecipient {
Dianne Hackborndf89e652011-10-06 22:35:11 -070032 final WindowManagerService mService;
33 final InputChannel mServerChannel, mClientChannel;
34 final InputApplicationHandle mApplicationHandle;
35 final InputWindowHandle mWindowHandle;
Dianne Hackborndf89e652011-10-06 22:35:11 -070036
Winson Chung6463c362017-09-25 16:23:26 -070037 final IBinder mToken;
38 final String mName;
39 final int mClientPid;
40 final UserHandle mClientUser;
41
42 InputConsumerImpl(WindowManagerService service, IBinder token, String name,
43 InputChannel inputChannel, int clientPid, UserHandle clientUser) {
Dianne Hackborndf89e652011-10-06 22:35:11 -070044 mService = service;
Winson Chung6463c362017-09-25 16:23:26 -070045 mToken = token;
46 mName = name;
47 mClientPid = clientPid;
48 mClientUser = clientUser;
Dianne Hackborndf89e652011-10-06 22:35:11 -070049
50 InputChannel[] channels = InputChannel.openInputChannelPair(name);
51 mServerChannel = channels[0];
Vladislav Kaznacheev0d50d862016-03-29 15:43:28 -070052 if (inputChannel != null) {
53 channels[1].transferTo(inputChannel);
54 channels[1].dispose();
55 mClientChannel = inputChannel;
56 } else {
57 mClientChannel = channels[1];
58 }
Dianne Hackborndf89e652011-10-06 22:35:11 -070059 mService.mInputManager.registerInputChannel(mServerChannel, null);
Jeff Brown32cbc38552011-12-01 14:01:49 -080060
Dianne Hackborndf89e652011-10-06 22:35:11 -070061 mApplicationHandle = new InputApplicationHandle(null);
62 mApplicationHandle.name = name;
63 mApplicationHandle.dispatchingTimeoutNanos =
64 WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
65
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -080066 mWindowHandle = new InputWindowHandle(mApplicationHandle, null, null,
67 Display.DEFAULT_DISPLAY);
Dianne Hackborndf89e652011-10-06 22:35:11 -070068 mWindowHandle.name = name;
69 mWindowHandle.inputChannel = mServerChannel;
Selim Cinekf83e8242015-05-19 18:08:14 -070070 mWindowHandle.layoutParamsType = WindowManager.LayoutParams.TYPE_INPUT_CONSUMER;
Vladislav Kaznacheev0d50d862016-03-29 15:43:28 -070071 mWindowHandle.layer = getLayerLw(mWindowHandle.layoutParamsType);
Selim Cinekf83e8242015-05-19 18:08:14 -070072 mWindowHandle.layoutParamsFlags = 0;
Dianne Hackborndf89e652011-10-06 22:35:11 -070073 mWindowHandle.dispatchingTimeoutNanos =
74 WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
75 mWindowHandle.visible = true;
Selim Cinekf83e8242015-05-19 18:08:14 -070076 mWindowHandle.canReceiveKeys = false;
77 mWindowHandle.hasFocus = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -070078 mWindowHandle.hasWallpaper = false;
79 mWindowHandle.paused = false;
80 mWindowHandle.ownerPid = Process.myPid();
81 mWindowHandle.ownerUid = Process.myUid();
82 mWindowHandle.inputFeatures = 0;
83 mWindowHandle.scaleFactor = 1.0f;
Dianne Hackborndf89e652011-10-06 22:35:11 -070084 }
85
Winson Chung6463c362017-09-25 16:23:26 -070086 void linkToDeathRecipient() {
87 if (mToken == null) {
88 return;
89 }
90
91 try {
92 mToken.linkToDeath(this, 0);
93 } catch (RemoteException e) {
94 // Client died, do nothing
95 }
96 }
97
98 void unlinkFromDeathRecipient() {
99 if (mToken == null) {
100 return;
101 }
102
103 mToken.unlinkToDeath(this, 0);
104 }
105
Dianne Hackborndf89e652011-10-06 22:35:11 -0700106 void layout(int dw, int dh) {
Selim Cinekf83e8242015-05-19 18:08:14 -0700107 mWindowHandle.touchableRegion.set(0, 0, dw, dh);
Dianne Hackborndf89e652011-10-06 22:35:11 -0700108 mWindowHandle.frameLeft = 0;
109 mWindowHandle.frameTop = 0;
110 mWindowHandle.frameRight = dw;
111 mWindowHandle.frameBottom = dh;
112 }
113
Dianne Hackborndf89e652011-10-06 22:35:11 -0700114 private int getLayerLw(int windowType) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800115 return mService.mPolicy.getWindowLayerFromTypeLw(windowType)
Dianne Hackborndf89e652011-10-06 22:35:11 -0700116 * WindowManagerService.TYPE_LAYER_MULTIPLIER
117 + WindowManagerService.TYPE_LAYER_OFFSET;
118 }
Vladislav Kaznacheev0d50d862016-03-29 15:43:28 -0700119
120 void disposeChannelsLw() {
121 mService.mInputManager.unregisterInputChannel(mServerChannel);
122 mClientChannel.dispose();
123 mServerChannel.dispose();
Winson Chung6463c362017-09-25 16:23:26 -0700124 unlinkFromDeathRecipient();
125 }
126
127 @Override
128 public void binderDied() {
129 synchronized (mService.getWindowManagerLock()) {
130 // Clean up the input consumer
131 mService.mInputMonitor.destroyInputConsumer(mName);
132 unlinkFromDeathRecipient();
133 }
134 }
135
136 void dump(PrintWriter pw, String name, String prefix) {
137 pw.println(prefix + " name=" + name + " pid=" + mClientPid + " user=" + mClientUser);
Vladislav Kaznacheev0d50d862016-03-29 15:43:28 -0700138 }
Dianne Hackborndf89e652011-10-06 22:35:11 -0700139}