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 android.os.Process;
20 import android.view.Display;
21 import android.view.InputChannel;
22 import android.view.WindowManager;
23 import com.android.server.input.InputApplicationHandle;
24 import com.android.server.input.InputWindowHandle;
25 
26 class InputConsumerImpl {
27     final WindowManagerService mService;
28     final InputChannel mServerChannel, mClientChannel;
29     final InputApplicationHandle mApplicationHandle;
30     final InputWindowHandle mWindowHandle;
31 
InputConsumerImpl(WindowManagerService service, String name, InputChannel inputChannel)32     InputConsumerImpl(WindowManagerService service, String name, InputChannel inputChannel) {
33         mService = service;
34 
35         InputChannel[] channels = InputChannel.openInputChannelPair(name);
36         mServerChannel = channels[0];
37         if (inputChannel != null) {
38             channels[1].transferTo(inputChannel);
39             channels[1].dispose();
40             mClientChannel = inputChannel;
41         } else {
42             mClientChannel = channels[1];
43         }
44         mService.mInputManager.registerInputChannel(mServerChannel, null);
45 
46         mApplicationHandle = new InputApplicationHandle(null);
47         mApplicationHandle.name = name;
48         mApplicationHandle.dispatchingTimeoutNanos =
49                 WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
50 
51         mWindowHandle = new InputWindowHandle(mApplicationHandle, null, Display.DEFAULT_DISPLAY);
52         mWindowHandle.name = name;
53         mWindowHandle.inputChannel = mServerChannel;
54         mWindowHandle.layoutParamsType = WindowManager.LayoutParams.TYPE_INPUT_CONSUMER;
55         mWindowHandle.layer = getLayerLw(mWindowHandle.layoutParamsType);
56         mWindowHandle.layoutParamsFlags = 0;
57         mWindowHandle.dispatchingTimeoutNanos =
58                 WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
59         mWindowHandle.visible = true;
60         mWindowHandle.canReceiveKeys = false;
61         mWindowHandle.hasFocus = false;
62         mWindowHandle.hasWallpaper = false;
63         mWindowHandle.paused = false;
64         mWindowHandle.ownerPid = Process.myPid();
65         mWindowHandle.ownerUid = Process.myUid();
66         mWindowHandle.inputFeatures = 0;
67         mWindowHandle.scaleFactor = 1.0f;
68     }
69 
layout(int dw, int dh)70     void layout(int dw, int dh) {
71         mWindowHandle.touchableRegion.set(0, 0, dw, dh);
72         mWindowHandle.frameLeft = 0;
73         mWindowHandle.frameTop = 0;
74         mWindowHandle.frameRight = dw;
75         mWindowHandle.frameBottom = dh;
76     }
77 
getLayerLw(int windowType)78     private int getLayerLw(int windowType) {
79         return mService.mPolicy.windowTypeToLayerLw(windowType)
80                 * WindowManagerService.TYPE_LAYER_MULTIPLIER
81                 + WindowManagerService.TYPE_LAYER_OFFSET;
82     }
83 
disposeChannelsLw()84     void disposeChannelsLw() {
85         mService.mInputManager.unregisterInputChannel(mServerChannel);
86         mClientChannel.dispose();
87         mServerChannel.dispose();
88     }
89 }
90