blob: c18ea014c69ac2054acf03de627669a5235c6a06 [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;
Craig Mautner59c00972012-07-30 12:10:24 -070024import android.view.Display;
Dianne Hackborndf89e652011-10-06 22:35:11 -070025import android.view.InputChannel;
Jeff Brown32cbc38552011-12-01 14:01:49 -080026import android.view.InputEventReceiver;
Dianne Hackborndf89e652011-10-06 22:35:11 -070027import android.view.WindowManagerPolicy;
28
29public final class FakeWindowImpl implements WindowManagerPolicy.FakeWindow {
30 final WindowManagerService mService;
31 final InputChannel mServerChannel, mClientChannel;
32 final InputApplicationHandle mApplicationHandle;
33 final InputWindowHandle mWindowHandle;
Jeff Brown32cbc38552011-12-01 14:01:49 -080034 final InputEventReceiver mInputEventReceiver;
Dianne Hackborndf89e652011-10-06 22:35:11 -070035 final int mWindowLayer;
36
37 boolean mTouchFullscreen;
38
Jeff Brown32cbc38552011-12-01 14:01:49 -080039 public FakeWindowImpl(WindowManagerService service,
40 Looper looper, InputEventReceiver.Factory inputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -070041 String name, int windowType, int layoutParamsFlags, int layoutParamsPrivateFlags,
42 boolean canReceiveKeys, boolean hasFocus, boolean touchFullscreen) {
Dianne Hackborndf89e652011-10-06 22:35:11 -070043 mService = service;
44
45 InputChannel[] channels = InputChannel.openInputChannelPair(name);
46 mServerChannel = channels[0];
47 mClientChannel = channels[1];
48 mService.mInputManager.registerInputChannel(mServerChannel, null);
Jeff Brown32cbc38552011-12-01 14:01:49 -080049
50 mInputEventReceiver = inputEventReceiverFactory.createInputEventReceiver(
51 mClientChannel, looper);
Dianne Hackborndf89e652011-10-06 22:35:11 -070052
53 mApplicationHandle = new InputApplicationHandle(null);
54 mApplicationHandle.name = name;
55 mApplicationHandle.dispatchingTimeoutNanos =
56 WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
57
Craig Mautner59c00972012-07-30 12:10:24 -070058 mWindowHandle = new InputWindowHandle(mApplicationHandle, null, Display.DEFAULT_DISPLAY);
Dianne Hackborndf89e652011-10-06 22:35:11 -070059 mWindowHandle.name = name;
60 mWindowHandle.inputChannel = mServerChannel;
61 mWindowLayer = getLayerLw(windowType);
62 mWindowHandle.layer = mWindowLayer;
63 mWindowHandle.layoutParamsFlags = layoutParamsFlags;
Adam Lesinski95c42972013-10-02 10:13:27 -070064 mWindowHandle.layoutParamsPrivateFlags = layoutParamsPrivateFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -070065 mWindowHandle.layoutParamsType = windowType;
66 mWindowHandle.dispatchingTimeoutNanos =
67 WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
68 mWindowHandle.visible = true;
69 mWindowHandle.canReceiveKeys = canReceiveKeys;
70 mWindowHandle.hasFocus = hasFocus;
71 mWindowHandle.hasWallpaper = false;
72 mWindowHandle.paused = false;
73 mWindowHandle.ownerPid = Process.myPid();
74 mWindowHandle.ownerUid = Process.myUid();
75 mWindowHandle.inputFeatures = 0;
76 mWindowHandle.scaleFactor = 1.0f;
77
78 mTouchFullscreen = touchFullscreen;
79 }
80
81 void layout(int dw, int dh) {
82 if (mTouchFullscreen) {
83 mWindowHandle.touchableRegion.set(0, 0, dw, dh);
84 } else {
85 mWindowHandle.touchableRegion.setEmpty();
86 }
87 mWindowHandle.frameLeft = 0;
88 mWindowHandle.frameTop = 0;
89 mWindowHandle.frameRight = dw;
90 mWindowHandle.frameBottom = dh;
91 }
92
93 @Override
94 public void dismiss() {
95 synchronized (mService.mWindowMap) {
96 if (mService.removeFakeWindowLocked(this)) {
Jeff Brown32cbc38552011-12-01 14:01:49 -080097 mInputEventReceiver.dispose();
Dianne Hackborndf89e652011-10-06 22:35:11 -070098 mService.mInputManager.unregisterInputChannel(mServerChannel);
Dianne Hackborndf89e652011-10-06 22:35:11 -070099 mClientChannel.dispose();
100 mServerChannel.dispose();
101 }
102 }
103 }
104
105 private int getLayerLw(int windowType) {
106 return mService.mPolicy.windowTypeToLayerLw(windowType)
107 * WindowManagerService.TYPE_LAYER_MULTIPLIER
108 + WindowManagerService.TYPE_LAYER_OFFSET;
109 }
110}