FakeWindowImpl.java revision df89e65bf0fcc651d20b208c8d8d0b848fb43418
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 17package com.android.server.wm; 18 19import android.os.Looper; 20import android.os.Process; 21import android.util.Slog; 22import android.view.InputChannel; 23import android.view.InputHandler; 24import android.view.InputQueue; 25import android.view.WindowManagerPolicy; 26 27public final class FakeWindowImpl implements WindowManagerPolicy.FakeWindow { 28 final WindowManagerService mService; 29 final InputChannel mServerChannel, mClientChannel; 30 final InputApplicationHandle mApplicationHandle; 31 final InputWindowHandle mWindowHandle; 32 final int mWindowLayer; 33 34 boolean mTouchFullscreen; 35 36 public FakeWindowImpl(WindowManagerService service, Looper looper, InputHandler inputHandler, 37 String name, int windowType, int layoutParamsFlags, boolean canReceiveKeys, 38 boolean hasFocus, boolean touchFullscreen) { 39 mService = service; 40 41 InputChannel[] channels = InputChannel.openInputChannelPair(name); 42 mServerChannel = channels[0]; 43 mClientChannel = channels[1]; 44 mService.mInputManager.registerInputChannel(mServerChannel, null); 45 InputQueue.registerInputChannel(mClientChannel, inputHandler, looper.getQueue()); 46 47 mApplicationHandle = new InputApplicationHandle(null); 48 mApplicationHandle.name = name; 49 mApplicationHandle.dispatchingTimeoutNanos = 50 WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; 51 52 mWindowHandle = new InputWindowHandle(mApplicationHandle, null); 53 mWindowHandle.name = name; 54 mWindowHandle.inputChannel = mServerChannel; 55 mWindowLayer = getLayerLw(windowType); 56 mWindowHandle.layer = mWindowLayer; 57 mWindowHandle.layoutParamsFlags = layoutParamsFlags; 58 mWindowHandle.layoutParamsType = windowType; 59 mWindowHandle.dispatchingTimeoutNanos = 60 WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; 61 mWindowHandle.visible = true; 62 mWindowHandle.canReceiveKeys = canReceiveKeys; 63 mWindowHandle.hasFocus = hasFocus; 64 mWindowHandle.hasWallpaper = false; 65 mWindowHandle.paused = false; 66 mWindowHandle.ownerPid = Process.myPid(); 67 mWindowHandle.ownerUid = Process.myUid(); 68 mWindowHandle.inputFeatures = 0; 69 mWindowHandle.scaleFactor = 1.0f; 70 71 mTouchFullscreen = touchFullscreen; 72 } 73 74 void layout(int dw, int dh) { 75 if (mTouchFullscreen) { 76 mWindowHandle.touchableRegion.set(0, 0, dw, dh); 77 } else { 78 mWindowHandle.touchableRegion.setEmpty(); 79 } 80 mWindowHandle.frameLeft = 0; 81 mWindowHandle.frameTop = 0; 82 mWindowHandle.frameRight = dw; 83 mWindowHandle.frameBottom = dh; 84 } 85 86 @Override 87 public void dismiss() { 88 synchronized (mService.mWindowMap) { 89 if (mService.removeFakeWindowLocked(this)) { 90 mService.mInputManager.unregisterInputChannel(mServerChannel); 91 InputQueue.unregisterInputChannel(mClientChannel); 92 mClientChannel.dispose(); 93 mServerChannel.dispose(); 94 } 95 } 96 } 97 98 private int getLayerLw(int windowType) { 99 return mService.mPolicy.windowTypeToLayerLw(windowType) 100 * WindowManagerService.TYPE_LAYER_MULTIPLIER 101 + WindowManagerService.TYPE_LAYER_OFFSET; 102 } 103} 104