InputConsumerImpl.java revision 5cd907d3d6ceebf8731ef1f69347cce6f76109e9
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.Process;
20import android.view.Display;
21import android.view.InputChannel;
22import android.view.WindowManager;
23import com.android.server.input.InputApplicationHandle;
24import com.android.server.input.InputWindowHandle;
25
26class InputConsumerImpl {
27    final WindowManagerService mService;
28    final InputChannel mServerChannel, mClientChannel;
29    final InputApplicationHandle mApplicationHandle;
30    final InputWindowHandle mWindowHandle;
31
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, null,
52                Display.DEFAULT_DISPLAY);
53        mWindowHandle.name = name;
54        mWindowHandle.inputChannel = mServerChannel;
55        mWindowHandle.layoutParamsType = WindowManager.LayoutParams.TYPE_INPUT_CONSUMER;
56        mWindowHandle.layer = getLayerLw(mWindowHandle.layoutParamsType);
57        mWindowHandle.layoutParamsFlags = 0;
58        mWindowHandle.dispatchingTimeoutNanos =
59                WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
60        mWindowHandle.visible = true;
61        mWindowHandle.canReceiveKeys = false;
62        mWindowHandle.hasFocus = false;
63        mWindowHandle.hasWallpaper = false;
64        mWindowHandle.paused = false;
65        mWindowHandle.ownerPid = Process.myPid();
66        mWindowHandle.ownerUid = Process.myUid();
67        mWindowHandle.inputFeatures = 0;
68        mWindowHandle.scaleFactor = 1.0f;
69    }
70
71    void layout(int dw, int dh) {
72        mWindowHandle.touchableRegion.set(0, 0, dw, dh);
73        mWindowHandle.frameLeft = 0;
74        mWindowHandle.frameTop = 0;
75        mWindowHandle.frameRight = dw;
76        mWindowHandle.frameBottom = dh;
77    }
78
79    private int getLayerLw(int windowType) {
80        return mService.mPolicy.getWindowLayerFromTypeLw(windowType)
81                * WindowManagerService.TYPE_LAYER_MULTIPLIER
82                + WindowManagerService.TYPE_LAYER_OFFSET;
83    }
84
85    void disposeChannelsLw() {
86        mService.mInputManager.unregisterInputChannel(mServerChannel);
87        mClientChannel.dispose();
88        mServerChannel.dispose();
89    }
90}
91