1df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn/*
2df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn * Copyright (C) 2011 The Android Open Source Project
3df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn *
4df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn * Licensed under the Apache License, Version 2.0 (the "License");
5df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn * you may not use this file except in compliance with the License.
6df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn * You may obtain a copy of the License at
7df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn *
8df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn *      http://www.apache.org/licenses/LICENSE-2.0
9df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn *
10df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn * Unless required by applicable law or agreed to in writing, software
11df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn * distributed under the License is distributed on an "AS IS" BASIS,
12df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn * See the License for the specific language governing permissions and
14df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn * limitations under the License.
15df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn */
16df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn
17df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackbornpackage com.android.server.wm;
18df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn
19df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackbornimport android.os.Process;
2059c009776dae5ccbdfb93d7151ff2065ca049dc3Craig Mautnerimport android.view.Display;
21df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackbornimport android.view.InputChannel;
22f83e824216435e45f36a3587e269888f791b2a01Selim Cinekimport android.view.WindowManager;
23f83e824216435e45f36a3587e269888f791b2a01Selim Cinekimport com.android.server.input.InputApplicationHandle;
24f83e824216435e45f36a3587e269888f791b2a01Selim Cinekimport com.android.server.input.InputWindowHandle;
25f83e824216435e45f36a3587e269888f791b2a01Selim Cinek
260d50d8660dac35f7eceb5d74756de0417095b427Vladislav Kaznacheevclass InputConsumerImpl {
27df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn    final WindowManagerService mService;
28df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn    final InputChannel mServerChannel, mClientChannel;
29df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn    final InputApplicationHandle mApplicationHandle;
30df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn    final InputWindowHandle mWindowHandle;
31df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn
320d50d8660dac35f7eceb5d74756de0417095b427Vladislav Kaznacheev    InputConsumerImpl(WindowManagerService service, String name, InputChannel inputChannel) {
33df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn        mService = service;
34df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn
35df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn        InputChannel[] channels = InputChannel.openInputChannelPair(name);
36df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn        mServerChannel = channels[0];
370d50d8660dac35f7eceb5d74756de0417095b427Vladislav Kaznacheev        if (inputChannel != null) {
380d50d8660dac35f7eceb5d74756de0417095b427Vladislav Kaznacheev            channels[1].transferTo(inputChannel);
390d50d8660dac35f7eceb5d74756de0417095b427Vladislav Kaznacheev            channels[1].dispose();
400d50d8660dac35f7eceb5d74756de0417095b427Vladislav Kaznacheev            mClientChannel = inputChannel;
410d50d8660dac35f7eceb5d74756de0417095b427Vladislav Kaznacheev        } else {
420d50d8660dac35f7eceb5d74756de0417095b427Vladislav Kaznacheev            mClientChannel = channels[1];
430d50d8660dac35f7eceb5d74756de0417095b427Vladislav Kaznacheev        }
44df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn        mService.mInputManager.registerInputChannel(mServerChannel, null);
4532cbc3855c2a971aa5a801fd339fb6a37db91a1aJeff Brown
46df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn        mApplicationHandle = new InputApplicationHandle(null);
47df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn        mApplicationHandle.name = name;
48df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn        mApplicationHandle.dispatchingTimeoutNanos =
49df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn                WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
50df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn
513787de16d24001eeb452e1c711d4290a396e67c9Vladislav Kaznacheev        mWindowHandle = new InputWindowHandle(mApplicationHandle, null, null,
523787de16d24001eeb452e1c711d4290a396e67c9Vladislav Kaznacheev                Display.DEFAULT_DISPLAY);
53df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn        mWindowHandle.name = name;
54df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn        mWindowHandle.inputChannel = mServerChannel;
55f83e824216435e45f36a3587e269888f791b2a01Selim Cinek        mWindowHandle.layoutParamsType = WindowManager.LayoutParams.TYPE_INPUT_CONSUMER;
560d50d8660dac35f7eceb5d74756de0417095b427Vladislav Kaznacheev        mWindowHandle.layer = getLayerLw(mWindowHandle.layoutParamsType);
57f83e824216435e45f36a3587e269888f791b2a01Selim Cinek        mWindowHandle.layoutParamsFlags = 0;
58df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn        mWindowHandle.dispatchingTimeoutNanos =
59df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn                WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
60df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn        mWindowHandle.visible = true;
61f83e824216435e45f36a3587e269888f791b2a01Selim Cinek        mWindowHandle.canReceiveKeys = false;
62f83e824216435e45f36a3587e269888f791b2a01Selim Cinek        mWindowHandle.hasFocus = false;
63df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn        mWindowHandle.hasWallpaper = false;
64df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn        mWindowHandle.paused = false;
65df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn        mWindowHandle.ownerPid = Process.myPid();
66df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn        mWindowHandle.ownerUid = Process.myUid();
67df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn        mWindowHandle.inputFeatures = 0;
68df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn        mWindowHandle.scaleFactor = 1.0f;
69df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn    }
70df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn
71df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn    void layout(int dw, int dh) {
72f83e824216435e45f36a3587e269888f791b2a01Selim Cinek        mWindowHandle.touchableRegion.set(0, 0, dw, dh);
73df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn        mWindowHandle.frameLeft = 0;
74df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn        mWindowHandle.frameTop = 0;
75df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn        mWindowHandle.frameRight = dw;
76df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn        mWindowHandle.frameBottom = dh;
77df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn    }
78df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn
79df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn    private int getLayerLw(int windowType) {
805cd907d3d6ceebf8731ef1f69347cce6f76109e9Wale Ogunwale        return mService.mPolicy.getWindowLayerFromTypeLw(windowType)
81df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn                * WindowManagerService.TYPE_LAYER_MULTIPLIER
82df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn                + WindowManagerService.TYPE_LAYER_OFFSET;
83df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn    }
840d50d8660dac35f7eceb5d74756de0417095b427Vladislav Kaznacheev
850d50d8660dac35f7eceb5d74756de0417095b427Vladislav Kaznacheev    void disposeChannelsLw() {
860d50d8660dac35f7eceb5d74756de0417095b427Vladislav Kaznacheev        mService.mInputManager.unregisterInputChannel(mServerChannel);
870d50d8660dac35f7eceb5d74756de0417095b427Vladislav Kaznacheev        mClientChannel.dispose();
880d50d8660dac35f7eceb5d74756de0417095b427Vladislav Kaznacheev        mServerChannel.dispose();
890d50d8660dac35f7eceb5d74756de0417095b427Vladislav Kaznacheev    }
90df89e65bf0fcc651d20b208c8d8d0b848fb43418Dianne Hackborn}
91