blob: 36753b7d5e0469830bfeeab10ad1bb168e764493 [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
Dianne Hackborndf89e652011-10-06 22:35:11 -070019import android.os.Process;
Craig Mautner59c00972012-07-30 12:10:24 -070020import android.view.Display;
Dianne Hackborndf89e652011-10-06 22:35:11 -070021import android.view.InputChannel;
Selim Cinekf83e8242015-05-19 18:08:14 -070022import android.view.WindowManager;
Selim Cinekf83e8242015-05-19 18:08:14 -070023import com.android.server.input.InputApplicationHandle;
24import com.android.server.input.InputWindowHandle;
25
Vladislav Kaznacheev0d50d862016-03-29 15:43:28 -070026class InputConsumerImpl {
Dianne Hackborndf89e652011-10-06 22:35:11 -070027 final WindowManagerService mService;
28 final InputChannel mServerChannel, mClientChannel;
29 final InputApplicationHandle mApplicationHandle;
30 final InputWindowHandle mWindowHandle;
Dianne Hackborndf89e652011-10-06 22:35:11 -070031
Vladislav Kaznacheev0d50d862016-03-29 15:43:28 -070032 InputConsumerImpl(WindowManagerService service, String name, InputChannel inputChannel) {
Dianne Hackborndf89e652011-10-06 22:35:11 -070033 mService = service;
34
35 InputChannel[] channels = InputChannel.openInputChannelPair(name);
36 mServerChannel = channels[0];
Vladislav Kaznacheev0d50d862016-03-29 15:43:28 -070037 if (inputChannel != null) {
38 channels[1].transferTo(inputChannel);
39 channels[1].dispose();
40 mClientChannel = inputChannel;
41 } else {
42 mClientChannel = channels[1];
43 }
Dianne Hackborndf89e652011-10-06 22:35:11 -070044 mService.mInputManager.registerInputChannel(mServerChannel, null);
Jeff Brown32cbc38552011-12-01 14:01:49 -080045
Dianne Hackborndf89e652011-10-06 22:35:11 -070046 mApplicationHandle = new InputApplicationHandle(null);
47 mApplicationHandle.name = name;
48 mApplicationHandle.dispatchingTimeoutNanos =
49 WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
50
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -080051 mWindowHandle = new InputWindowHandle(mApplicationHandle, null, null,
52 Display.DEFAULT_DISPLAY);
Dianne Hackborndf89e652011-10-06 22:35:11 -070053 mWindowHandle.name = name;
54 mWindowHandle.inputChannel = mServerChannel;
Selim Cinekf83e8242015-05-19 18:08:14 -070055 mWindowHandle.layoutParamsType = WindowManager.LayoutParams.TYPE_INPUT_CONSUMER;
Vladislav Kaznacheev0d50d862016-03-29 15:43:28 -070056 mWindowHandle.layer = getLayerLw(mWindowHandle.layoutParamsType);
Selim Cinekf83e8242015-05-19 18:08:14 -070057 mWindowHandle.layoutParamsFlags = 0;
Dianne Hackborndf89e652011-10-06 22:35:11 -070058 mWindowHandle.dispatchingTimeoutNanos =
59 WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
60 mWindowHandle.visible = true;
Selim Cinekf83e8242015-05-19 18:08:14 -070061 mWindowHandle.canReceiveKeys = false;
62 mWindowHandle.hasFocus = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -070063 mWindowHandle.hasWallpaper = false;
64 mWindowHandle.paused = false;
65 mWindowHandle.ownerPid = Process.myPid();
66 mWindowHandle.ownerUid = Process.myUid();
67 mWindowHandle.inputFeatures = 0;
68 mWindowHandle.scaleFactor = 1.0f;
Dianne Hackborndf89e652011-10-06 22:35:11 -070069 }
70
71 void layout(int dw, int dh) {
Selim Cinekf83e8242015-05-19 18:08:14 -070072 mWindowHandle.touchableRegion.set(0, 0, dw, dh);
Dianne Hackborndf89e652011-10-06 22:35:11 -070073 mWindowHandle.frameLeft = 0;
74 mWindowHandle.frameTop = 0;
75 mWindowHandle.frameRight = dw;
76 mWindowHandle.frameBottom = dh;
77 }
78
Dianne Hackborndf89e652011-10-06 22:35:11 -070079 private int getLayerLw(int windowType) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -080080 return mService.mPolicy.getWindowLayerFromTypeLw(windowType)
Dianne Hackborndf89e652011-10-06 22:35:11 -070081 * WindowManagerService.TYPE_LAYER_MULTIPLIER
82 + WindowManagerService.TYPE_LAYER_OFFSET;
83 }
Vladislav Kaznacheev0d50d862016-03-29 15:43:28 -070084
85 void disposeChannelsLw() {
86 mService.mInputManager.unregisterInputChannel(mServerChannel);
87 mClientChannel.dispose();
88 mServerChannel.dispose();
89 }
Dianne Hackborndf89e652011-10-06 22:35:11 -070090}