blob: 24783bccf3d5b9d92df35914a90c304d21fc0b0b [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
Craig Mautner59c00972012-07-30 12:10:24 -070051 mWindowHandle = new InputWindowHandle(mApplicationHandle, null, Display.DEFAULT_DISPLAY);
Dianne Hackborndf89e652011-10-06 22:35:11 -070052 mWindowHandle.name = name;
53 mWindowHandle.inputChannel = mServerChannel;
Selim Cinekf83e8242015-05-19 18:08:14 -070054 mWindowHandle.layoutParamsType = WindowManager.LayoutParams.TYPE_INPUT_CONSUMER;
Vladislav Kaznacheev0d50d862016-03-29 15:43:28 -070055 mWindowHandle.layer = getLayerLw(mWindowHandle.layoutParamsType);
Selim Cinekf83e8242015-05-19 18:08:14 -070056 mWindowHandle.layoutParamsFlags = 0;
Dianne Hackborndf89e652011-10-06 22:35:11 -070057 mWindowHandle.dispatchingTimeoutNanos =
58 WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
59 mWindowHandle.visible = true;
Selim Cinekf83e8242015-05-19 18:08:14 -070060 mWindowHandle.canReceiveKeys = false;
61 mWindowHandle.hasFocus = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -070062 mWindowHandle.hasWallpaper = false;
63 mWindowHandle.paused = false;
64 mWindowHandle.ownerPid = Process.myPid();
65 mWindowHandle.ownerUid = Process.myUid();
66 mWindowHandle.inputFeatures = 0;
67 mWindowHandle.scaleFactor = 1.0f;
Dianne Hackborndf89e652011-10-06 22:35:11 -070068 }
69
70 void layout(int dw, int dh) {
Selim Cinekf83e8242015-05-19 18:08:14 -070071 mWindowHandle.touchableRegion.set(0, 0, dw, dh);
Dianne Hackborndf89e652011-10-06 22:35:11 -070072 mWindowHandle.frameLeft = 0;
73 mWindowHandle.frameTop = 0;
74 mWindowHandle.frameRight = dw;
75 mWindowHandle.frameBottom = dh;
76 }
77
Dianne Hackborndf89e652011-10-06 22:35:11 -070078 private int getLayerLw(int windowType) {
79 return mService.mPolicy.windowTypeToLayerLw(windowType)
80 * WindowManagerService.TYPE_LAYER_MULTIPLIER
81 + WindowManagerService.TYPE_LAYER_OFFSET;
82 }
Vladislav Kaznacheev0d50d862016-03-29 15:43:28 -070083
84 void disposeChannelsLw() {
85 mService.mInputManager.unregisterInputChannel(mServerChannel);
86 mClientChannel.dispose();
87 mServerChannel.dispose();
88 }
Dianne Hackborndf89e652011-10-06 22:35:11 -070089}