Search in sources :

Example 21 with InputChannel

use of android.view.InputChannel in project android_frameworks_base by AOSPA.

the class TvInputService method onBind.

@Override
public final IBinder onBind(Intent intent) {
    return new ITvInputService.Stub() {

        @Override
        public void registerCallback(ITvInputServiceCallback cb) {
            if (cb != null) {
                mCallbacks.register(cb);
            }
        }

        @Override
        public void unregisterCallback(ITvInputServiceCallback cb) {
            if (cb != null) {
                mCallbacks.unregister(cb);
            }
        }

        @Override
        public void createSession(InputChannel channel, ITvInputSessionCallback cb, String inputId) {
            if (channel == null) {
                Log.w(TAG, "Creating session without input channel");
            }
            if (cb == null) {
                return;
            }
            SomeArgs args = SomeArgs.obtain();
            args.arg1 = channel;
            args.arg2 = cb;
            args.arg3 = inputId;
            mServiceHandler.obtainMessage(ServiceHandler.DO_CREATE_SESSION, args).sendToTarget();
        }

        @Override
        public void createRecordingSession(ITvInputSessionCallback cb, String inputId) {
            if (cb == null) {
                return;
            }
            SomeArgs args = SomeArgs.obtain();
            args.arg1 = cb;
            args.arg2 = inputId;
            mServiceHandler.obtainMessage(ServiceHandler.DO_CREATE_RECORDING_SESSION, args).sendToTarget();
        }

        @Override
        public void notifyHardwareAdded(TvInputHardwareInfo hardwareInfo) {
            mServiceHandler.obtainMessage(ServiceHandler.DO_ADD_HARDWARE_INPUT, hardwareInfo).sendToTarget();
        }

        @Override
        public void notifyHardwareRemoved(TvInputHardwareInfo hardwareInfo) {
            mServiceHandler.obtainMessage(ServiceHandler.DO_REMOVE_HARDWARE_INPUT, hardwareInfo).sendToTarget();
        }

        @Override
        public void notifyHdmiDeviceAdded(HdmiDeviceInfo deviceInfo) {
            mServiceHandler.obtainMessage(ServiceHandler.DO_ADD_HDMI_INPUT, deviceInfo).sendToTarget();
        }

        @Override
        public void notifyHdmiDeviceRemoved(HdmiDeviceInfo deviceInfo) {
            mServiceHandler.obtainMessage(ServiceHandler.DO_REMOVE_HDMI_INPUT, deviceInfo).sendToTarget();
        }
    };
}
Also used : HdmiDeviceInfo(android.hardware.hdmi.HdmiDeviceInfo) SomeArgs(com.android.internal.os.SomeArgs) InputChannel(android.view.InputChannel)

Example 22 with InputChannel

use of android.view.InputChannel in project cornerstone by Onskreen.

the class InputMonitor method updateInputWindowsLw.

/* Updates the cached window information provided to the input dispatcher. */
public void updateInputWindowsLw(boolean force) {
    if (!force && !mUpdateInputWindowsNeeded) {
        return;
    }
    mUpdateInputWindowsNeeded = false;
    if (false)
        Slog.d(WindowManagerService.TAG, ">>>>>> ENTERED updateInputWindowsLw");
    // Populate the input window list with information about all of the windows that
    // could potentially receive input.
    // As an optimization, we could try to prune the list of windows but this turns
    // out to be difficult because only the native code knows for sure which window
    // currently has touch focus.
    final ArrayList<WindowState> windows = mService.mWindows;
    // If there's a drag in flight, provide a pseudowindow to catch drag input
    final boolean inDrag = (mService.mDragState != null);
    if (inDrag) {
        if (WindowManagerService.DEBUG_DRAG) {
            Log.d(WindowManagerService.TAG, "Inserting drag window");
        }
        final InputWindowHandle dragWindowHandle = mService.mDragState.mDragWindowHandle;
        if (dragWindowHandle != null) {
            addInputWindowHandleLw(dragWindowHandle);
        } else {
            Slog.w(WindowManagerService.TAG, "Drag is in progress but there is no " + "drag window handle.");
        }
    }
    final int NFW = mService.mFakeWindows.size();
    for (int i = 0; i < NFW; i++) {
        addInputWindowHandleLw(mService.mFakeWindows.get(i).mWindowHandle);
    }
    final int N = windows.size();
    for (int i = N - 1; i >= 0; i--) {
        final WindowState child = windows.get(i);
        final InputChannel inputChannel = child.mInputChannel;
        final InputWindowHandle inputWindowHandle = child.mInputWindowHandle;
        if (inputChannel == null || inputWindowHandle == null || child.mRemoved) {
            // Skip this window because it cannot possibly receive input.
            continue;
        }
        final int flags = child.mAttrs.flags;
        final int type = child.mAttrs.type;
        final boolean hasFocus = (child == mInputFocus);
        final boolean isVisible = child.isVisibleLw();
        final boolean hasWallpaper = (child == mService.mWallpaperTarget) && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
        // make sure it's been told about the drag
        if (inDrag && isVisible) {
            mService.mDragState.sendDragStartedIfNeededLw(child);
        }
        // Add a window to our list of input windows.
        inputWindowHandle.name = child.toString();
        inputWindowHandle.layoutParamsFlags = flags;
        inputWindowHandle.layoutParamsType = type;
        inputWindowHandle.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
        inputWindowHandle.visible = isVisible;
        inputWindowHandle.canReceiveKeys = child.canReceiveKeys();
        inputWindowHandle.hasFocus = hasFocus;
        inputWindowHandle.hasWallpaper = hasWallpaper;
        inputWindowHandle.paused = child.mAppToken != null ? child.mAppToken.paused : false;
        inputWindowHandle.layer = child.mLayer;
        inputWindowHandle.ownerPid = child.mSession.mPid;
        inputWindowHandle.ownerUid = child.mSession.mUid;
        inputWindowHandle.inputFeatures = child.mAttrs.inputFeatures;
        final Rect frame = child.mFrame;
        inputWindowHandle.frameLeft = frame.left;
        inputWindowHandle.frameTop = frame.top;
        inputWindowHandle.frameRight = frame.right;
        inputWindowHandle.frameBottom = frame.bottom;
        if (child.mGlobalScale != 1) {
            // If we are scaling the window, input coordinates need
            // to be inversely scaled to map from what is on screen
            // to what is actually being touched in the UI.
            inputWindowHandle.scaleFactor = 1.0f / child.mGlobalScale;
        } else {
            inputWindowHandle.scaleFactor = 1;
        }
        child.getTouchableRegion(inputWindowHandle.touchableRegion);
        addInputWindowHandleLw(inputWindowHandle);
    }
    // Send windows to native code.
    mService.mInputManager.setInputWindows(mInputWindowHandles);
    // Clear the list in preparation for the next round.
    clearInputWindowHandlesLw();
    if (false)
        Slog.d(WindowManagerService.TAG, "<<<<<<< EXITED updateInputWindowsLw");
}
Also used : Rect(android.graphics.Rect) InputChannel(android.view.InputChannel) InputWindowHandle(com.android.server.input.InputWindowHandle)

Example 23 with InputChannel

use of android.view.InputChannel in project cornerstone by Onskreen.

the class WindowManagerService method addWindow.

public int addWindow(Session session, IWindow client, int seq, WindowManager.LayoutParams attrs, int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
    int res = mPolicy.checkAddPermission(attrs);
    if (res != WindowManagerImpl.ADD_OKAY) {
        return res;
    }
    boolean reportNewConfig = false;
    WindowState attachedWindow = null;
    WindowState win = null;
    long origId;
    synchronized (mWindowMap) {
        if (mDisplay == null) {
            throw new IllegalStateException("Display has not been initialialized");
        }
        if (mWindowMap.containsKey(client.asBinder())) {
            Slog.w(TAG, "Window " + client + " is already added");
            return WindowManagerImpl.ADD_DUPLICATE_ADD;
        }
        if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
            attachedWindow = windowForClientLocked(null, attrs.token, false);
            if (attachedWindow == null) {
                Slog.w(TAG, "Attempted to add window with token that is not a window: " + attrs.token + ".  Aborting.");
                return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
            }
            if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
                Slog.w(TAG, "Attempted to add window with token that is a sub-window: " + attrs.token + ".  Aborting.");
                return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
            }
        }
        boolean addToken = false;
        WindowToken token = mTokenMap.get(attrs.token);
        if (token == null) {
            if (attrs.type >= FIRST_APPLICATION_WINDOW && attrs.type <= LAST_APPLICATION_WINDOW) {
                Slog.w(TAG, "Attempted to add application window with unknown token " + attrs.token + ".  Aborting.");
                return WindowManagerImpl.ADD_BAD_APP_TOKEN;
            }
            if (attrs.type == TYPE_INPUT_METHOD) {
                Slog.w(TAG, "Attempted to add input method window with unknown token " + attrs.token + ".  Aborting.");
                return WindowManagerImpl.ADD_BAD_APP_TOKEN;
            }
            if (attrs.type == TYPE_WALLPAPER) {
                Slog.w(TAG, "Attempted to add wallpaper window with unknown token " + attrs.token + ".  Aborting.");
                return WindowManagerImpl.ADD_BAD_APP_TOKEN;
            }
            if (attrs.type == TYPE_DREAM) {
                Slog.w(TAG, "Attempted to add Dream window with unknown token " + attrs.token + ".  Aborting.");
                return WindowManagerImpl.ADD_BAD_APP_TOKEN;
            }
            token = new WindowToken(this, attrs.token, -1, false);
            addToken = true;
        } else if (attrs.type >= FIRST_APPLICATION_WINDOW && attrs.type <= LAST_APPLICATION_WINDOW) {
            AppWindowToken atoken = token.appWindowToken;
            if (atoken == null) {
                Slog.w(TAG, "Attempted to add window with non-application token " + token + ".  Aborting.");
                return WindowManagerImpl.ADD_NOT_APP_TOKEN;
            } else if (atoken.removed) {
                Slog.w(TAG, "Attempted to add window with exiting application token " + token + ".  Aborting.");
                return WindowManagerImpl.ADD_APP_EXITING;
            }
            if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
                // No need for this guy!
                if (localLOGV)
                    Slog.v(TAG, "**** NO NEED TO START: " + attrs.getTitle());
                return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
            }
        } else if (attrs.type == TYPE_INPUT_METHOD) {
            if (token.windowType != TYPE_INPUT_METHOD) {
                Slog.w(TAG, "Attempted to add input method window with bad token " + attrs.token + ".  Aborting.");
                return WindowManagerImpl.ADD_BAD_APP_TOKEN;
            }
        } else if (attrs.type == TYPE_WALLPAPER) {
            if (token.windowType != TYPE_WALLPAPER) {
                Slog.w(TAG, "Attempted to add wallpaper window with bad token " + attrs.token + ".  Aborting.");
                return WindowManagerImpl.ADD_BAD_APP_TOKEN;
            }
        } else if (attrs.type == TYPE_DREAM) {
            if (token.windowType != TYPE_DREAM) {
                Slog.w(TAG, "Attempted to add Dream window with bad token " + attrs.token + ".  Aborting.");
                return WindowManagerImpl.ADD_BAD_APP_TOKEN;
            }
        }
        win = new WindowState(this, session, client, token, attachedWindow, seq, attrs, viewVisibility);
        /**
             * Author: Onskreen
             * Date: 12/01/2011
             *
             * Sets the WindowPanel rect for apptokens.
             */
        if (token.appWindowToken != null) {
            setWindowPanel(token.appWindowToken.groupId);
            //Since the windowstate has not yet been added to mWindows, it
            //must be manually updated here.
            WindowPanel wp = findWindowPanel(token.appWindowToken.groupId);
            if (wp != null) {
                win.mFrame.set(wp.getPos());
            }
        }
        if (win.mDeathRecipient == null) {
            // Client has apparently died, so there is no reason to
            // continue.
            Slog.w(TAG, "Adding window client " + client.asBinder() + " that is dead, aborting.");
            return WindowManagerImpl.ADD_APP_EXITING;
        }
        mPolicy.adjustWindowParamsLw(win.mAttrs);
        res = mPolicy.prepareAddWindowLw(win, attrs);
        if (res != WindowManagerImpl.ADD_OKAY) {
            return res;
        }
        if (outInputChannel != null && (attrs.inputFeatures & WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL) == 0) {
            String name = win.makeInputChannelName();
            InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
            win.setInputChannel(inputChannels[0]);
            inputChannels[1].transferTo(outInputChannel);
            mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle);
        }
        // From now on, no exceptions or errors allowed!
        res = WindowManagerImpl.ADD_OKAY;
        origId = Binder.clearCallingIdentity();
        if (addToken) {
            mTokenMap.put(attrs.token, token);
        }
        win.attach();
        mWindowMap.put(client.asBinder(), win);
        if (attrs.type == TYPE_APPLICATION_STARTING && token.appWindowToken != null) {
            token.appWindowToken.startingWindow = win;
            if (DEBUG_STARTING_WINDOW)
                Slog.v(TAG, "addWindow: " + token.appWindowToken + " startingWindow=" + win);
        }
        boolean imMayMove = true;
        if (attrs.type == TYPE_INPUT_METHOD) {
            win.mGivenInsetsPending = true;
            mInputMethodWindow = win;
            addInputMethodWindowToListLocked(win);
            imMayMove = false;
        } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
            mInputMethodDialogs.add(win);
            addWindowToListInOrderLocked(win, true);
            adjustInputMethodDialogsLocked();
            imMayMove = false;
        } else {
            addWindowToListInOrderLocked(win, true);
            if (attrs.type == TYPE_WALLPAPER) {
                mLastWallpaperTimeoutTime = 0;
                adjustWallpaperWindowsLocked();
            } else if ((attrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
                adjustWallpaperWindowsLocked();
            }
        }
        win.mWinAnimator.mEnterAnimationPending = true;
        mPolicy.getContentInsetHintLw(attrs, outContentInsets);
        if (mInTouchMode) {
            res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
        }
        if (win.mAppToken == null || !win.mAppToken.clientHidden) {
            res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
        }
        mInputMonitor.setUpdateInputWindowsNeededLw();
        boolean focusChanged = false;
        if (win.canReceiveKeys()) {
            focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS, false);
            if (focusChanged) {
                imMayMove = false;
            }
        }
        if (imMayMove) {
            moveInputMethodWindowsIfNeededLocked(false);
        }
        assignLayersLocked();
        if (focusChanged) {
            finishUpdateFocusedWindowAfterAssignLayersLocked(false);
        }
        mInputMonitor.updateInputWindowsLw(false);
        if (localLOGV)
            Slog.v(TAG, "New client " + client.asBinder() + ": window=" + win);
        if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) {
            reportNewConfig = true;
        }
    }
    if (reportNewConfig) {
        sendNewConfiguration();
    }
    Binder.restoreCallingIdentity(origId);
    return res;
}
Also used : InputChannel(android.view.InputChannel) Point(android.graphics.Point)

Example 24 with InputChannel

use of android.view.InputChannel in project android_frameworks_base by ResurrectionRemix.

the class TvInputManagerService method createSessionInternalLocked.

private void createSessionInternalLocked(ITvInputService service, IBinder sessionToken, int userId) {
    UserState userState = getOrCreateUserStateLocked(userId);
    SessionState sessionState = userState.sessionStateMap.get(sessionToken);
    if (DEBUG) {
        Slog.d(TAG, "createSessionInternalLocked(inputId=" + sessionState.inputId + ")");
    }
    InputChannel[] channels = InputChannel.openInputChannelPair(sessionToken.toString());
    // Set up a callback to send the session token.
    ITvInputSessionCallback callback = new SessionCallback(sessionState, channels);
    // Create a session. When failed, send a null token immediately.
    try {
        if (sessionState.isRecordingSession) {
            service.createRecordingSession(callback, sessionState.inputId);
        } else {
            service.createSession(channels[1], callback, sessionState.inputId);
        }
    } catch (RemoteException e) {
        Slog.e(TAG, "error in createSession", e);
        removeSessionStateLocked(sessionToken, userId);
        sendSessionTokenToClientLocked(sessionState.client, sessionState.inputId, null, null, sessionState.seq);
    }
    channels[1].dispose();
}
Also used : InputChannel(android.view.InputChannel) ITvInputSessionCallback(android.media.tv.ITvInputSessionCallback) RemoteException(android.os.RemoteException) ITvInputSessionCallback(android.media.tv.ITvInputSessionCallback)

Example 25 with InputChannel

use of android.view.InputChannel in project android_frameworks_base by ResurrectionRemix.

the class InputMonitor method updateInputWindowsLw.

/* Updates the cached window information provided to the input dispatcher. */
public void updateInputWindowsLw(boolean force) {
    if (!force && !mUpdateInputWindowsNeeded) {
        return;
    }
    mUpdateInputWindowsNeeded = false;
    if (false)
        Slog.d(TAG_WM, ">>>>>> ENTERED updateInputWindowsLw");
    // Populate the input window list with information about all of the windows that
    // could potentially receive input.
    // As an optimization, we could try to prune the list of windows but this turns
    // out to be difficult because only the native code knows for sure which window
    // currently has touch focus.
    boolean disableWallpaperTouchEvents = false;
    // If there's a drag in flight, provide a pseudowindow to catch drag input
    final boolean inDrag = (mService.mDragState != null);
    if (inDrag) {
        if (DEBUG_DRAG) {
            Log.d(TAG_WM, "Inserting drag window");
        }
        final InputWindowHandle dragWindowHandle = mService.mDragState.mDragWindowHandle;
        if (dragWindowHandle != null) {
            addInputWindowHandleLw(dragWindowHandle);
        } else {
            Slog.w(TAG_WM, "Drag is in progress but there is no " + "drag window handle.");
        }
    }
    final boolean inPositioning = (mService.mTaskPositioner != null);
    if (inPositioning) {
        if (DEBUG_TASK_POSITIONING) {
            Log.d(TAG_WM, "Inserting window handle for repositioning");
        }
        final InputWindowHandle dragWindowHandle = mService.mTaskPositioner.mDragWindowHandle;
        if (dragWindowHandle != null) {
            addInputWindowHandleLw(dragWindowHandle);
        } else {
            Slog.e(TAG_WM, "Repositioning is in progress but there is no drag window handle.");
        }
    }
    boolean addInputConsumerHandle = mService.mInputConsumer != null;
    boolean addWallpaperInputConsumerHandle = mService.mWallpaperInputConsumer != null;
    // Add all windows on the default display.
    final int numDisplays = mService.mDisplayContents.size();
    final WallpaperController wallpaperController = mService.mWallpaperControllerLocked;
    for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
        final DisplayContent displayContent = mService.mDisplayContents.valueAt(displayNdx);
        final WindowList windows = displayContent.getWindowList();
        for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) {
            final WindowState child = windows.get(winNdx);
            final InputChannel inputChannel = child.mInputChannel;
            final InputWindowHandle inputWindowHandle = child.mInputWindowHandle;
            if (inputChannel == null || inputWindowHandle == null || child.mRemoved || child.isAdjustedForMinimizedDock()) {
                // Skip this window because it cannot possibly receive input.
                continue;
            }
            if (addInputConsumerHandle && inputWindowHandle.layer <= mService.mInputConsumer.mWindowHandle.layer) {
                addInputWindowHandleLw(mService.mInputConsumer.mWindowHandle);
                addInputConsumerHandle = false;
            }
            if (addWallpaperInputConsumerHandle) {
                if (child.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER) {
                    // Add the wallpaper input consumer above the first wallpaper window.
                    addInputWindowHandleLw(mService.mWallpaperInputConsumer.mWindowHandle);
                    addWallpaperInputConsumerHandle = false;
                }
            }
            final int flags = child.mAttrs.flags;
            final int privateFlags = child.mAttrs.privateFlags;
            final int type = child.mAttrs.type;
            final boolean hasFocus = (child == mInputFocus);
            final boolean isVisible = child.isVisibleLw();
            if ((privateFlags & WindowManager.LayoutParams.PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS) != 0) {
                disableWallpaperTouchEvents = true;
            }
            final boolean hasWallpaper = wallpaperController.isWallpaperTarget(child) && (privateFlags & WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD) == 0 && !disableWallpaperTouchEvents;
            final boolean onDefaultDisplay = (child.getDisplayId() == Display.DEFAULT_DISPLAY);
            // make sure it's been told about the drag
            if (inDrag && isVisible && onDefaultDisplay) {
                mService.mDragState.sendDragStartedIfNeededLw(child);
            }
            addInputWindowHandleLw(inputWindowHandle, child, flags, type, isVisible, hasFocus, hasWallpaper);
        }
    }
    if (addWallpaperInputConsumerHandle) {
        // No wallpaper found, add the wallpaper input consumer at the end.
        addInputWindowHandleLw(mService.mWallpaperInputConsumer.mWindowHandle);
    }
    // Send windows to native code.
    mService.mInputManager.setInputWindows(mInputWindowHandles);
    // Clear the list in preparation for the next round.
    clearInputWindowHandlesLw();
    if (false)
        Slog.d(TAG_WM, "<<<<<<< EXITED updateInputWindowsLw");
}
Also used : InputChannel(android.view.InputChannel) InputWindowHandle(com.android.server.input.InputWindowHandle)

Aggregations

InputChannel (android.view.InputChannel)32 InputWindowHandle (com.android.server.input.InputWindowHandle)15 Point (android.graphics.Point)11 SomeArgs (com.android.internal.os.SomeArgs)11 RemoteException (android.os.RemoteException)10 InputApplicationHandle (com.android.server.input.InputApplicationHandle)9 IInputMethod (com.android.internal.view.IInputMethod)6 IInputMethodClient (com.android.internal.view.IInputMethodClient)6 IInputSessionCallback (com.android.internal.view.IInputSessionCallback)6 InputBindResult (com.android.internal.view.InputBindResult)6 HdmiDeviceInfo (android.hardware.hdmi.HdmiDeviceInfo)5 EditorInfo (android.view.inputmethod.EditorInfo)5 IInputContext (com.android.internal.view.IInputContext)5 DragInputEventReceiver (com.android.server.wm.WindowManagerService.DragInputEventReceiver)5 ITvInputSessionCallback (android.media.tv.ITvInputSessionCallback)4 Rect (android.graphics.Rect)1