1df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn/* 2df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn * Copyright (C) 2011 The Android Open Source Project 3df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn * 4df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn * Licensed under the Apache License, Version 2.0 (the "License"); 5df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn * you may not use this file except in compliance with the License. 6df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn * You may obtain a copy of the License at 7df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn * 8df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn * http://www.apache.org/licenses/LICENSE-2.0 9df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn * 10df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn * Unless required by applicable law or agreed to in writing, software 11df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn * distributed under the License is distributed on an "AS IS" BASIS, 12df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn * See the License for the specific language governing permissions and 14df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn * limitations under the License. 15df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn */ 16df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn 17df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackbornpackage com.android.server.wm; 18df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn 194532e6158474a263d9d26c2b42240bcf7ce9b172Jeff Brownimport com.android.server.input.InputApplicationHandle; 204532e6158474a263d9d26c2b42240bcf7ce9b172Jeff Brownimport com.android.server.input.InputWindowHandle; 214532e6158474a263d9d26c2b42240bcf7ce9b172Jeff Brown 22df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackbornimport android.os.Looper; 23df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackbornimport android.os.Process; 24df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackbornimport android.util.Slog; 2559c009776dae5ccbdfb93d7151ff2065ca049dc3Craig Mautnerimport android.view.Display; 26df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackbornimport android.view.InputChannel; 2732cbc3855c2a971aa5a801fd339fb6a37db91a1aJeff Brownimport android.view.InputEventReceiver; 28df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackbornimport android.view.InputQueue; 29df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackbornimport android.view.WindowManagerPolicy; 30df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn 31df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackbornpublic final class FakeWindowImpl implements WindowManagerPolicy.FakeWindow { 32df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn final WindowManagerService mService; 33df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn final InputChannel mServerChannel, mClientChannel; 34df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn final InputApplicationHandle mApplicationHandle; 35df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn final InputWindowHandle mWindowHandle; 3632cbc3855c2a971aa5a801fd339fb6a37db91a1aJeff Brown final InputEventReceiver mInputEventReceiver; 37df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn final int mWindowLayer; 38df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn 39df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn boolean mTouchFullscreen; 40df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn 4132cbc3855c2a971aa5a801fd339fb6a37db91a1aJeff Brown public FakeWindowImpl(WindowManagerService service, 4232cbc3855c2a971aa5a801fd339fb6a37db91a1aJeff Brown Looper looper, InputEventReceiver.Factory inputEventReceiverFactory, 43df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn String name, int windowType, int layoutParamsFlags, boolean canReceiveKeys, 44df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn boolean hasFocus, boolean touchFullscreen) { 45df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mService = service; 46df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn 47df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn InputChannel[] channels = InputChannel.openInputChannelPair(name); 48df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mServerChannel = channels[0]; 49df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mClientChannel = channels[1]; 50df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mService.mInputManager.registerInputChannel(mServerChannel, null); 5132cbc3855c2a971aa5a801fd339fb6a37db91a1aJeff Brown 5232cbc3855c2a971aa5a801fd339fb6a37db91a1aJeff Brown mInputEventReceiver = inputEventReceiverFactory.createInputEventReceiver( 5332cbc3855c2a971aa5a801fd339fb6a37db91a1aJeff Brown mClientChannel, looper); 54df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn 55df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mApplicationHandle = new InputApplicationHandle(null); 56df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mApplicationHandle.name = name; 57df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mApplicationHandle.dispatchingTimeoutNanos = 58df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; 59df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn 6059c009776dae5ccbdfb93d7151ff2065ca049dc3Craig Mautner mWindowHandle = new InputWindowHandle(mApplicationHandle, null, Display.DEFAULT_DISPLAY); 61df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mWindowHandle.name = name; 62df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mWindowHandle.inputChannel = mServerChannel; 63df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mWindowLayer = getLayerLw(windowType); 64df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mWindowHandle.layer = mWindowLayer; 65df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mWindowHandle.layoutParamsFlags = layoutParamsFlags; 66df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mWindowHandle.layoutParamsType = windowType; 67df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mWindowHandle.dispatchingTimeoutNanos = 68df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; 69df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mWindowHandle.visible = true; 70df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mWindowHandle.canReceiveKeys = canReceiveKeys; 71df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mWindowHandle.hasFocus = hasFocus; 72df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mWindowHandle.hasWallpaper = false; 73df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mWindowHandle.paused = false; 74df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mWindowHandle.ownerPid = Process.myPid(); 75df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mWindowHandle.ownerUid = Process.myUid(); 76df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mWindowHandle.inputFeatures = 0; 77df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mWindowHandle.scaleFactor = 1.0f; 78df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn 79df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mTouchFullscreen = touchFullscreen; 80df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn } 81df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn 82df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn void layout(int dw, int dh) { 83df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn if (mTouchFullscreen) { 84df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mWindowHandle.touchableRegion.set(0, 0, dw, dh); 85df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn } else { 86df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mWindowHandle.touchableRegion.setEmpty(); 87df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn } 88df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mWindowHandle.frameLeft = 0; 89df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mWindowHandle.frameTop = 0; 90df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mWindowHandle.frameRight = dw; 91df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mWindowHandle.frameBottom = dh; 92df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn } 93df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn 94df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn @Override 95df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn public void dismiss() { 96df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn synchronized (mService.mWindowMap) { 97df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn if (mService.removeFakeWindowLocked(this)) { 9832cbc3855c2a971aa5a801fd339fb6a37db91a1aJeff Brown mInputEventReceiver.dispose(); 99df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mService.mInputManager.unregisterInputChannel(mServerChannel); 100df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mClientChannel.dispose(); 101df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn mServerChannel.dispose(); 102df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn } 103df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn } 104df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn } 105df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn 106df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn private int getLayerLw(int windowType) { 107df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn return mService.mPolicy.windowTypeToLayerLw(windowType) 108df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn * WindowManagerService.TYPE_LAYER_MULTIPLIER 109df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn + WindowManagerService.TYPE_LAYER_OFFSET; 110df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn } 111df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn} 112