Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.wm; |
| 18 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 19 | import com.android.server.input.InputApplicationHandle; |
| 20 | import com.android.server.input.InputWindowHandle; |
| 21 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 22 | import android.os.Looper; |
| 23 | import android.os.Process; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 24 | import android.view.Display; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 25 | import android.view.InputChannel; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 26 | import android.view.InputEventReceiver; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 27 | import android.view.WindowManagerPolicy; |
| 28 | |
| 29 | public final class FakeWindowImpl implements WindowManagerPolicy.FakeWindow { |
| 30 | final WindowManagerService mService; |
| 31 | final InputChannel mServerChannel, mClientChannel; |
| 32 | final InputApplicationHandle mApplicationHandle; |
| 33 | final InputWindowHandle mWindowHandle; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 34 | final InputEventReceiver mInputEventReceiver; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 35 | final int mWindowLayer; |
| 36 | |
| 37 | boolean mTouchFullscreen; |
| 38 | |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 39 | public FakeWindowImpl(WindowManagerService service, |
| 40 | Looper looper, InputEventReceiver.Factory inputEventReceiverFactory, |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 41 | String name, int windowType, int layoutParamsFlags, int layoutParamsPrivateFlags, |
| 42 | boolean canReceiveKeys, boolean hasFocus, boolean touchFullscreen) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 43 | mService = service; |
| 44 | |
| 45 | InputChannel[] channels = InputChannel.openInputChannelPair(name); |
| 46 | mServerChannel = channels[0]; |
| 47 | mClientChannel = channels[1]; |
| 48 | mService.mInputManager.registerInputChannel(mServerChannel, null); |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 49 | |
| 50 | mInputEventReceiver = inputEventReceiverFactory.createInputEventReceiver( |
| 51 | mClientChannel, looper); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 52 | |
| 53 | mApplicationHandle = new InputApplicationHandle(null); |
| 54 | mApplicationHandle.name = name; |
| 55 | mApplicationHandle.dispatchingTimeoutNanos = |
| 56 | WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 57 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 58 | mWindowHandle = new InputWindowHandle(mApplicationHandle, null, Display.DEFAULT_DISPLAY); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 59 | mWindowHandle.name = name; |
| 60 | mWindowHandle.inputChannel = mServerChannel; |
| 61 | mWindowLayer = getLayerLw(windowType); |
| 62 | mWindowHandle.layer = mWindowLayer; |
| 63 | mWindowHandle.layoutParamsFlags = layoutParamsFlags; |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 64 | mWindowHandle.layoutParamsPrivateFlags = layoutParamsPrivateFlags; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 65 | 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 Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 97 | mInputEventReceiver.dispose(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 98 | mService.mInputManager.unregisterInputChannel(mServerChannel); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 99 | 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 | } |