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 | |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 19 | import android.os.IBinder; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 20 | import android.os.Process; |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 21 | import android.os.RemoteException; |
| 22 | import android.os.UserHandle; |
Siarhei Vishniakou | 9628308 | 2018-08-13 18:55:55 +0000 | [diff] [blame] | 23 | import android.view.Display; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 24 | import android.view.InputChannel; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 25 | import android.view.WindowManager; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 26 | import com.android.server.input.InputApplicationHandle; |
| 27 | import com.android.server.input.InputWindowHandle; |
| 28 | |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 29 | import java.io.PrintWriter; |
| 30 | |
| 31 | class InputConsumerImpl implements IBinder.DeathRecipient { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 32 | final WindowManagerService mService; |
| 33 | final InputChannel mServerChannel, mClientChannel; |
| 34 | final InputApplicationHandle mApplicationHandle; |
| 35 | final InputWindowHandle mWindowHandle; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 36 | |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 37 | final IBinder mToken; |
| 38 | final String mName; |
| 39 | final int mClientPid; |
| 40 | final UserHandle mClientUser; |
| 41 | |
| 42 | InputConsumerImpl(WindowManagerService service, IBinder token, String name, |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 43 | InputChannel inputChannel, int clientPid, UserHandle clientUser, int displayId) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 44 | mService = service; |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 45 | mToken = token; |
| 46 | mName = name; |
| 47 | mClientPid = clientPid; |
| 48 | mClientUser = clientUser; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 49 | |
| 50 | InputChannel[] channels = InputChannel.openInputChannelPair(name); |
| 51 | mServerChannel = channels[0]; |
Vladislav Kaznacheev | 0d50d86 | 2016-03-29 15:43:28 -0700 | [diff] [blame] | 52 | if (inputChannel != null) { |
| 53 | channels[1].transferTo(inputChannel); |
| 54 | channels[1].dispose(); |
| 55 | mClientChannel = inputChannel; |
| 56 | } else { |
| 57 | mClientChannel = channels[1]; |
| 58 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 59 | mService.mInputManager.registerInputChannel(mServerChannel, null); |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 60 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 61 | mApplicationHandle = new InputApplicationHandle(null); |
| 62 | mApplicationHandle.name = name; |
| 63 | mApplicationHandle.dispatchingTimeoutNanos = |
| 64 | WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 65 | |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 66 | mWindowHandle = new InputWindowHandle(mApplicationHandle, null, null, displayId); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 67 | mWindowHandle.name = name; |
| 68 | mWindowHandle.inputChannel = mServerChannel; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 69 | mWindowHandle.layoutParamsType = WindowManager.LayoutParams.TYPE_INPUT_CONSUMER; |
Vladislav Kaznacheev | 0d50d86 | 2016-03-29 15:43:28 -0700 | [diff] [blame] | 70 | mWindowHandle.layer = getLayerLw(mWindowHandle.layoutParamsType); |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 71 | mWindowHandle.layoutParamsFlags = 0; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 72 | mWindowHandle.dispatchingTimeoutNanos = |
| 73 | WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 74 | mWindowHandle.visible = true; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 75 | mWindowHandle.canReceiveKeys = false; |
| 76 | mWindowHandle.hasFocus = false; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 77 | mWindowHandle.hasWallpaper = false; |
| 78 | mWindowHandle.paused = false; |
| 79 | mWindowHandle.ownerPid = Process.myPid(); |
| 80 | mWindowHandle.ownerUid = Process.myUid(); |
| 81 | mWindowHandle.inputFeatures = 0; |
| 82 | mWindowHandle.scaleFactor = 1.0f; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 85 | void linkToDeathRecipient() { |
| 86 | if (mToken == null) { |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | try { |
| 91 | mToken.linkToDeath(this, 0); |
| 92 | } catch (RemoteException e) { |
| 93 | // Client died, do nothing |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | void unlinkFromDeathRecipient() { |
| 98 | if (mToken == null) { |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | mToken.unlinkToDeath(this, 0); |
| 103 | } |
| 104 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 105 | void layout(int dw, int dh) { |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 106 | mWindowHandle.touchableRegion.set(0, 0, dw, dh); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 107 | mWindowHandle.frameLeft = 0; |
| 108 | mWindowHandle.frameTop = 0; |
| 109 | mWindowHandle.frameRight = dw; |
| 110 | mWindowHandle.frameBottom = dh; |
| 111 | } |
| 112 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 113 | private int getLayerLw(int windowType) { |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 114 | return mService.mPolicy.getWindowLayerFromTypeLw(windowType) |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 115 | * WindowManagerService.TYPE_LAYER_MULTIPLIER |
| 116 | + WindowManagerService.TYPE_LAYER_OFFSET; |
| 117 | } |
Vladislav Kaznacheev | 0d50d86 | 2016-03-29 15:43:28 -0700 | [diff] [blame] | 118 | |
| 119 | void disposeChannelsLw() { |
| 120 | mService.mInputManager.unregisterInputChannel(mServerChannel); |
| 121 | mClientChannel.dispose(); |
| 122 | mServerChannel.dispose(); |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 123 | unlinkFromDeathRecipient(); |
| 124 | } |
| 125 | |
| 126 | @Override |
| 127 | public void binderDied() { |
| 128 | synchronized (mService.getWindowManagerLock()) { |
| 129 | // Clean up the input consumer |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 130 | final InputMonitor inputMonitor = |
| 131 | mService.mRoot.getDisplayContent(mWindowHandle.displayId).getInputMonitor(); |
| 132 | inputMonitor.destroyInputConsumer(mName); |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 133 | unlinkFromDeathRecipient(); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | void dump(PrintWriter pw, String name, String prefix) { |
| 138 | pw.println(prefix + " name=" + name + " pid=" + mClientPid + " user=" + mClientUser); |
Vladislav Kaznacheev | 0d50d86 | 2016-03-29 15:43:28 -0700 | [diff] [blame] | 139 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 140 | } |