Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.wm; |
| 18 | |
Robert Carr | a80ad04 | 2018-08-14 12:54:20 -0700 | [diff] [blame] | 19 | import android.graphics.Rect; |
Robert Carr | 0bcbe64 | 2018-10-11 19:07:43 -0700 | [diff] [blame] | 20 | import android.os.Binder; |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 21 | import android.os.IBinder; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 22 | import android.os.Process; |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 23 | import android.os.RemoteException; |
| 24 | import android.os.UserHandle; |
Jorim Jaggi | f6ef183 | 2019-01-31 14:42:44 +0100 | [diff] [blame] | 25 | import android.view.InputApplicationHandle; |
Chavi Weingarten | 6ef9cc6 | 2019-02-07 16:28:45 +0000 | [diff] [blame] | 26 | import android.view.InputChannel; |
Robert Carr | 788f574 | 2018-07-30 17:46:45 -0700 | [diff] [blame] | 27 | import android.view.InputWindowHandle; |
Robert Carr | a80ad04 | 2018-08-14 12:54:20 -0700 | [diff] [blame] | 28 | import android.view.SurfaceControl; |
Chavi Weingarten | 6ef9cc6 | 2019-02-07 16:28:45 +0000 | [diff] [blame] | 29 | import android.view.WindowManager; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 30 | |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 31 | import java.io.PrintWriter; |
| 32 | |
| 33 | class InputConsumerImpl implements IBinder.DeathRecipient { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 34 | final WindowManagerService mService; |
| 35 | final InputChannel mServerChannel, mClientChannel; |
| 36 | final InputApplicationHandle mApplicationHandle; |
| 37 | final InputWindowHandle mWindowHandle; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 38 | |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 39 | final IBinder mToken; |
| 40 | final String mName; |
| 41 | final int mClientPid; |
| 42 | final UserHandle mClientUser; |
| 43 | |
Robert Carr | a80ad04 | 2018-08-14 12:54:20 -0700 | [diff] [blame] | 44 | final SurfaceControl mInputSurface; |
| 45 | Rect mTmpClipRect = new Rect(); |
| 46 | |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 47 | InputConsumerImpl(WindowManagerService service, IBinder token, String name, |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 48 | InputChannel inputChannel, int clientPid, UserHandle clientUser, int displayId) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 49 | mService = service; |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 50 | mToken = token; |
| 51 | mName = name; |
| 52 | mClientPid = clientPid; |
| 53 | mClientUser = clientUser; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 54 | |
| 55 | InputChannel[] channels = InputChannel.openInputChannelPair(name); |
| 56 | mServerChannel = channels[0]; |
Vladislav Kaznacheev | 0d50d86 | 2016-03-29 15:43:28 -0700 | [diff] [blame] | 57 | if (inputChannel != null) { |
| 58 | channels[1].transferTo(inputChannel); |
| 59 | channels[1].dispose(); |
| 60 | mClientChannel = inputChannel; |
| 61 | } else { |
| 62 | mClientChannel = channels[1]; |
| 63 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 64 | mService.mInputManager.registerInputChannel(mServerChannel, null); |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 65 | |
Robert Carr | 0bcbe64 | 2018-10-11 19:07:43 -0700 | [diff] [blame] | 66 | mApplicationHandle = new InputApplicationHandle(new Binder()); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 67 | mApplicationHandle.name = name; |
| 68 | mApplicationHandle.dispatchingTimeoutNanos = |
| 69 | WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 70 | |
Robert Carr | e0a353c | 2018-08-02 16:38:04 -0700 | [diff] [blame] | 71 | mWindowHandle = new InputWindowHandle(mApplicationHandle, null, displayId); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 72 | mWindowHandle.name = name; |
Robert Carr | eadae82 | 2018-10-11 19:07:03 -0700 | [diff] [blame] | 73 | mWindowHandle.token = mServerChannel.getToken(); |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 74 | mWindowHandle.layoutParamsType = WindowManager.LayoutParams.TYPE_INPUT_CONSUMER; |
Vladislav Kaznacheev | 0d50d86 | 2016-03-29 15:43:28 -0700 | [diff] [blame] | 75 | mWindowHandle.layer = getLayerLw(mWindowHandle.layoutParamsType); |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 76 | mWindowHandle.layoutParamsFlags = 0; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 77 | mWindowHandle.dispatchingTimeoutNanos = |
| 78 | WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 79 | mWindowHandle.visible = true; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 80 | mWindowHandle.canReceiveKeys = false; |
| 81 | mWindowHandle.hasFocus = false; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 82 | 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 Carr | a80ad04 | 2018-08-14 12:54:20 -0700 | [diff] [blame] | 88 | |
| 89 | mInputSurface = mService.makeSurfaceBuilder(mService.mRoot.getDisplayContent(displayId) |
Chavi Weingarten | 6ef9cc6 | 2019-02-07 16:28:45 +0000 | [diff] [blame] | 90 | .getSession()).setContainerLayer().setName("Input Consumer " + name) |
Robert Carr | a80ad04 | 2018-08-14 12:54:20 -0700 | [diff] [blame] | 91 | .build(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 94 | 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 Carr | a80ad04 | 2018-08-14 12:54:20 -0700 | [diff] [blame] | 114 | 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 Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Robert Carr | b600bc2 | 2018-08-21 15:05:16 -0700 | [diff] [blame] | 137 | void show(SurfaceControl.Transaction t, int layer) { |
| 138 | t.show(mInputSurface); |
| 139 | t.setInputWindowInfo(mInputSurface, mWindowHandle); |
| 140 | t.setLayer(mInputSurface, layer); |
| 141 | } |
| 142 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 143 | private int getLayerLw(int windowType) { |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 144 | return mService.mPolicy.getWindowLayerFromTypeLw(windowType) |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 145 | * WindowManagerService.TYPE_LAYER_MULTIPLIER |
| 146 | + WindowManagerService.TYPE_LAYER_OFFSET; |
| 147 | } |
Vladislav Kaznacheev | 0d50d86 | 2016-03-29 15:43:28 -0700 | [diff] [blame] | 148 | |
| 149 | void disposeChannelsLw() { |
| 150 | mService.mInputManager.unregisterInputChannel(mServerChannel); |
| 151 | mClientChannel.dispose(); |
| 152 | mServerChannel.dispose(); |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 153 | unlinkFromDeathRecipient(); |
| 154 | } |
| 155 | |
| 156 | @Override |
| 157 | public void binderDied() { |
| 158 | synchronized (mService.getWindowManagerLock()) { |
| 159 | // Clean up the input consumer |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 160 | final InputMonitor inputMonitor = |
| 161 | mService.mRoot.getDisplayContent(mWindowHandle.displayId).getInputMonitor(); |
| 162 | inputMonitor.destroyInputConsumer(mName); |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 163 | unlinkFromDeathRecipient(); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | void dump(PrintWriter pw, String name, String prefix) { |
| 168 | pw.println(prefix + " name=" + name + " pid=" + mClientPid + " user=" + mClientUser); |
Vladislav Kaznacheev | 0d50d86 | 2016-03-29 15:43:28 -0700 | [diff] [blame] | 169 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 170 | } |