Home | History | Annotate | Download | only in wm
      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.InputChannel;
     26 import android.view.InputEventReceiver;
     27 import android.view.InputQueue;
     28 import android.view.WindowManagerPolicy;
     29 
     30 public final class FakeWindowImpl implements WindowManagerPolicy.FakeWindow {
     31     final WindowManagerService mService;
     32     final InputChannel mServerChannel, mClientChannel;
     33     final InputApplicationHandle mApplicationHandle;
     34     final InputWindowHandle mWindowHandle;
     35     final InputEventReceiver mInputEventReceiver;
     36     final int mWindowLayer;
     37 
     38     boolean mTouchFullscreen;
     39 
     40     public FakeWindowImpl(WindowManagerService service,
     41             Looper looper, InputEventReceiver.Factory inputEventReceiverFactory,
     42             String name, int windowType, int layoutParamsFlags, boolean canReceiveKeys,
     43             boolean hasFocus, boolean touchFullscreen) {
     44         mService = service;
     45 
     46         InputChannel[] channels = InputChannel.openInputChannelPair(name);
     47         mServerChannel = channels[0];
     48         mClientChannel = channels[1];
     49         mService.mInputManager.registerInputChannel(mServerChannel, null);
     50 
     51         mInputEventReceiver = inputEventReceiverFactory.createInputEventReceiver(
     52                 mClientChannel, looper);
     53 
     54         mApplicationHandle = new InputApplicationHandle(null);
     55         mApplicationHandle.name = name;
     56         mApplicationHandle.dispatchingTimeoutNanos =
     57                 WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
     58 
     59         mWindowHandle = new InputWindowHandle(mApplicationHandle, null);
     60         mWindowHandle.name = name;
     61         mWindowHandle.inputChannel = mServerChannel;
     62         mWindowLayer = getLayerLw(windowType);
     63         mWindowHandle.layer = mWindowLayer;
     64         mWindowHandle.layoutParamsFlags = layoutParamsFlags;
     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)) {
     97                 mInputEventReceiver.dispose();
     98                 mService.mInputManager.unregisterInputChannel(mServerChannel);
     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 }
    111