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 19 import com.android.server.input.InputApplicationHandle; 20 import com.android.server.input.InputWindowHandle; 21 22 import android.os.Looper; 23 import android.os.Process; 24 import android.util.Slog; 25 import android.view.Display; 26 import android.view.InputChannel; 27 import android.view.InputEventReceiver; 28 import android.view.InputQueue; 29 import android.view.WindowManagerPolicy; 30 31 public final class FakeWindowImpl implements WindowManagerPolicy.FakeWindow { 32 final WindowManagerService mService; 33 final InputChannel mServerChannel, mClientChannel; 34 final InputApplicationHandle mApplicationHandle; 35 final InputWindowHandle mWindowHandle; 36 final InputEventReceiver mInputEventReceiver; 37 final int mWindowLayer; 38 39 boolean mTouchFullscreen; 40 FakeWindowImpl(WindowManagerService service, Looper looper, InputEventReceiver.Factory inputEventReceiverFactory, String name, int windowType, int layoutParamsFlags, int layoutParamsPrivateFlags, boolean canReceiveKeys, boolean hasFocus, boolean touchFullscreen)41 public FakeWindowImpl(WindowManagerService service, 42 Looper looper, InputEventReceiver.Factory inputEventReceiverFactory, 43 String name, int windowType, int layoutParamsFlags, int layoutParamsPrivateFlags, 44 boolean canReceiveKeys, boolean hasFocus, boolean touchFullscreen) { 45 mService = service; 46 47 InputChannel[] channels = InputChannel.openInputChannelPair(name); 48 mServerChannel = channels[0]; 49 mClientChannel = channels[1]; 50 mService.mInputManager.registerInputChannel(mServerChannel, null); 51 52 mInputEventReceiver = inputEventReceiverFactory.createInputEventReceiver( 53 mClientChannel, looper); 54 55 mApplicationHandle = new InputApplicationHandle(null); 56 mApplicationHandle.name = name; 57 mApplicationHandle.dispatchingTimeoutNanos = 58 WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; 59 60 mWindowHandle = new InputWindowHandle(mApplicationHandle, null, Display.DEFAULT_DISPLAY); 61 mWindowHandle.name = name; 62 mWindowHandle.inputChannel = mServerChannel; 63 mWindowLayer = getLayerLw(windowType); 64 mWindowHandle.layer = mWindowLayer; 65 mWindowHandle.layoutParamsFlags = layoutParamsFlags; 66 mWindowHandle.layoutParamsPrivateFlags = layoutParamsPrivateFlags; 67 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 layout(int dw, int dh)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 dismiss()96 public void dismiss() { 97 synchronized (mService.mWindowMap) { 98 if (mService.removeFakeWindowLocked(this)) { 99 mInputEventReceiver.dispose(); 100 mService.mInputManager.unregisterInputChannel(mServerChannel); 101 mClientChannel.dispose(); 102 mServerChannel.dispose(); 103 } 104 } 105 } 106 getLayerLw(int windowType)107 private int getLayerLw(int windowType) { 108 return mService.mPolicy.windowTypeToLayerLw(windowType) 109 * WindowManagerService.TYPE_LAYER_MULTIPLIER 110 + WindowManagerService.TYPE_LAYER_OFFSET; 111 } 112 } 113