blob: 0581a165a3743dac63ac0ba271595667912627ad [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
19import android.os.Looper;
20import android.os.Process;
Craig Mautner59c00972012-07-30 12:10:24 -070021import android.view.Display;
Dianne Hackborndf89e652011-10-06 22:35:11 -070022import android.view.InputChannel;
Jeff Brown32cbc38552011-12-01 14:01:49 -080023import android.view.InputEventReceiver;
Selim Cinekf83e8242015-05-19 18:08:14 -070024import android.view.WindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -070025import android.view.WindowManagerPolicy;
26
Selim Cinekf83e8242015-05-19 18:08:14 -070027import com.android.server.input.InputApplicationHandle;
28import com.android.server.input.InputWindowHandle;
29
30public final class InputConsumerImpl implements WindowManagerPolicy.InputConsumer {
Dianne Hackborndf89e652011-10-06 22:35:11 -070031 final WindowManagerService mService;
32 final InputChannel mServerChannel, mClientChannel;
33 final InputApplicationHandle mApplicationHandle;
34 final InputWindowHandle mWindowHandle;
Jeff Brown32cbc38552011-12-01 14:01:49 -080035 final InputEventReceiver mInputEventReceiver;
Dianne Hackborndf89e652011-10-06 22:35:11 -070036 final int mWindowLayer;
37
Selim Cinekf83e8242015-05-19 18:08:14 -070038 public InputConsumerImpl(WindowManagerService service, Looper looper,
39 InputEventReceiver.Factory inputEventReceiverFactory) {
40 String name = "input consumer";
Dianne Hackborndf89e652011-10-06 22:35:11 -070041 mService = service;
42
43 InputChannel[] channels = InputChannel.openInputChannelPair(name);
44 mServerChannel = channels[0];
45 mClientChannel = channels[1];
46 mService.mInputManager.registerInputChannel(mServerChannel, null);
Jeff Brown32cbc38552011-12-01 14:01:49 -080047
48 mInputEventReceiver = inputEventReceiverFactory.createInputEventReceiver(
49 mClientChannel, looper);
Dianne Hackborndf89e652011-10-06 22:35:11 -070050
51 mApplicationHandle = new InputApplicationHandle(null);
52 mApplicationHandle.name = name;
53 mApplicationHandle.dispatchingTimeoutNanos =
54 WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
55
Craig Mautner59c00972012-07-30 12:10:24 -070056 mWindowHandle = new InputWindowHandle(mApplicationHandle, null, Display.DEFAULT_DISPLAY);
Dianne Hackborndf89e652011-10-06 22:35:11 -070057 mWindowHandle.name = name;
58 mWindowHandle.inputChannel = mServerChannel;
Selim Cinekf83e8242015-05-19 18:08:14 -070059 mWindowHandle.layoutParamsType = WindowManager.LayoutParams.TYPE_INPUT_CONSUMER;
60 mWindowLayer = getLayerLw(mWindowHandle.layoutParamsType);
Dianne Hackborndf89e652011-10-06 22:35:11 -070061 mWindowHandle.layer = mWindowLayer;
Selim Cinekf83e8242015-05-19 18:08:14 -070062 mWindowHandle.layoutParamsFlags = 0;
Dianne Hackborndf89e652011-10-06 22:35:11 -070063 mWindowHandle.dispatchingTimeoutNanos =
64 WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
65 mWindowHandle.visible = true;
Selim Cinekf83e8242015-05-19 18:08:14 -070066 mWindowHandle.canReceiveKeys = false;
67 mWindowHandle.hasFocus = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -070068 mWindowHandle.hasWallpaper = false;
69 mWindowHandle.paused = false;
70 mWindowHandle.ownerPid = Process.myPid();
71 mWindowHandle.ownerUid = Process.myUid();
72 mWindowHandle.inputFeatures = 0;
73 mWindowHandle.scaleFactor = 1.0f;
Dianne Hackborndf89e652011-10-06 22:35:11 -070074 }
75
76 void layout(int dw, int dh) {
Selim Cinekf83e8242015-05-19 18:08:14 -070077 mWindowHandle.touchableRegion.set(0, 0, dw, dh);
Dianne Hackborndf89e652011-10-06 22:35:11 -070078 mWindowHandle.frameLeft = 0;
79 mWindowHandle.frameTop = 0;
80 mWindowHandle.frameRight = dw;
81 mWindowHandle.frameBottom = dh;
82 }
83
84 @Override
85 public void dismiss() {
86 synchronized (mService.mWindowMap) {
Selim Cinekf83e8242015-05-19 18:08:14 -070087 if (mService.removeInputConsumer()) {
Jeff Brown32cbc38552011-12-01 14:01:49 -080088 mInputEventReceiver.dispose();
Dianne Hackborndf89e652011-10-06 22:35:11 -070089 mService.mInputManager.unregisterInputChannel(mServerChannel);
Dianne Hackborndf89e652011-10-06 22:35:11 -070090 mClientChannel.dispose();
91 mServerChannel.dispose();
92 }
93 }
94 }
95
96 private int getLayerLw(int windowType) {
97 return mService.mPolicy.windowTypeToLayerLw(windowType)
98 * WindowManagerService.TYPE_LAYER_MULTIPLIER
99 + WindowManagerService.TYPE_LAYER_OFFSET;
100 }
101}