blob: 5a3471b06215ec06c72e7f67b8cd1c7c90bb4ff1 [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
Jeff Brown4532e612012-04-05 14:27:12 -070019import com.android.server.input.InputApplicationHandle;
20import com.android.server.input.InputWindowHandle;
21
Dianne Hackborndf89e652011-10-06 22:35:11 -070022import android.os.Looper;
23import android.os.Process;
24import android.util.Slog;
Craig Mautner59c00972012-07-30 12:10:24 -070025import android.view.Display;
Dianne Hackborndf89e652011-10-06 22:35:11 -070026import android.view.InputChannel;
Jeff Brown32cbc38552011-12-01 14:01:49 -080027import android.view.InputEventReceiver;
Dianne Hackborndf89e652011-10-06 22:35:11 -070028import android.view.InputQueue;
29import android.view.WindowManagerPolicy;
30
31public final class FakeWindowImpl implements WindowManagerPolicy.FakeWindow {
32 final WindowManagerService mService;
33 final InputChannel mServerChannel, mClientChannel;
34 final InputApplicationHandle mApplicationHandle;
35 final InputWindowHandle mWindowHandle;
Jeff Brown32cbc38552011-12-01 14:01:49 -080036 final InputEventReceiver mInputEventReceiver;
Dianne Hackborndf89e652011-10-06 22:35:11 -070037 final int mWindowLayer;
38
39 boolean mTouchFullscreen;
40
Jeff Brown32cbc38552011-12-01 14:01:49 -080041 public FakeWindowImpl(WindowManagerService service,
42 Looper looper, InputEventReceiver.Factory inputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -070043 String name, int windowType, int layoutParamsFlags, int layoutParamsPrivateFlags,
44 boolean canReceiveKeys, boolean hasFocus, boolean touchFullscreen) {
Dianne Hackborndf89e652011-10-06 22:35:11 -070045 mService = service;
46
47 InputChannel[] channels = InputChannel.openInputChannelPair(name);
48 mServerChannel = channels[0];
49 mClientChannel = channels[1];
50 mService.mInputManager.registerInputChannel(mServerChannel, null);
Jeff Brown32cbc38552011-12-01 14:01:49 -080051
52 mInputEventReceiver = inputEventReceiverFactory.createInputEventReceiver(
53 mClientChannel, looper);
Dianne Hackborndf89e652011-10-06 22:35:11 -070054
55 mApplicationHandle = new InputApplicationHandle(null);
56 mApplicationHandle.name = name;
57 mApplicationHandle.dispatchingTimeoutNanos =
58 WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
59
Craig Mautner59c00972012-07-30 12:10:24 -070060 mWindowHandle = new InputWindowHandle(mApplicationHandle, null, Display.DEFAULT_DISPLAY);
Dianne Hackborndf89e652011-10-06 22:35:11 -070061 mWindowHandle.name = name;
62 mWindowHandle.inputChannel = mServerChannel;
63 mWindowLayer = getLayerLw(windowType);
64 mWindowHandle.layer = mWindowLayer;
65 mWindowHandle.layoutParamsFlags = layoutParamsFlags;
Adam Lesinski95c42972013-10-02 10:13:27 -070066 mWindowHandle.layoutParamsPrivateFlags = layoutParamsPrivateFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -070067 mWindowHandle.layoutParamsType = windowType;
68 mWindowHandle.dispatchingTimeoutNanos =
69 WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
70 mWindowHandle.visible = true;
71 mWindowHandle.canReceiveKeys = canReceiveKeys;
72 mWindowHandle.hasFocus = hasFocus;
73 mWindowHandle.hasWallpaper = false;
74 mWindowHandle.paused = false;
75 mWindowHandle.ownerPid = Process.myPid();
76 mWindowHandle.ownerUid = Process.myUid();
77 mWindowHandle.inputFeatures = 0;
78 mWindowHandle.scaleFactor = 1.0f;
79
80 mTouchFullscreen = touchFullscreen;
81 }
82
83 void layout(int dw, int dh) {
84 if (mTouchFullscreen) {
85 mWindowHandle.touchableRegion.set(0, 0, dw, dh);
86 } else {
87 mWindowHandle.touchableRegion.setEmpty();
88 }
89 mWindowHandle.frameLeft = 0;
90 mWindowHandle.frameTop = 0;
91 mWindowHandle.frameRight = dw;
92 mWindowHandle.frameBottom = dh;
93 }
94
95 @Override
96 public void dismiss() {
97 synchronized (mService.mWindowMap) {
98 if (mService.removeFakeWindowLocked(this)) {
Jeff Brown32cbc38552011-12-01 14:01:49 -080099 mInputEventReceiver.dispose();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700100 mService.mInputManager.unregisterInputChannel(mServerChannel);
Dianne Hackborndf89e652011-10-06 22:35:11 -0700101 mClientChannel.dispose();
102 mServerChannel.dispose();
103 }
104 }
105 }
106
107 private int getLayerLw(int windowType) {
108 return mService.mPolicy.windowTypeToLayerLw(windowType)
109 * WindowManagerService.TYPE_LAYER_MULTIPLIER
110 + WindowManagerService.TYPE_LAYER_OFFSET;
111 }
112}