Search in sources :

Example 11 with IStatusBarService

use of com.android.internal.statusbar.IStatusBarService in project android_frameworks_base by ParanoidAndroid.

the class PhoneWindowManager method preloadRecentApps.

private void preloadRecentApps() {
    try {
        IStatusBarService statusbar = getStatusBarService();
        if (statusbar != null) {
            statusbar.preloadRecentApps();
            mRecentAppsPreloaded = true;
        }
    } catch (RemoteException e) {
        Slog.e(TAG, "RemoteException when preloading recent apps", e);
        // re-acquire status bar service next time it is needed.
        mStatusBarService = null;
    }
}
Also used : IStatusBarService(com.android.internal.statusbar.IStatusBarService) RemoteException(android.os.RemoteException)

Example 12 with IStatusBarService

use of com.android.internal.statusbar.IStatusBarService in project android_frameworks_base by ParanoidAndroid.

the class PhoneWindowManager method finishPostLayoutPolicyLw.

/** {@inheritDoc} */
@Override
public int finishPostLayoutPolicyLw() {
    int changes = 0;
    boolean topIsFullscreen = false;
    final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null) ? mTopFullscreenOpaqueWindowState.getAttrs() : null;
    // while the dream is showing.
    if (!mShowingDream) {
        mDreamingLockscreen = mShowingLockscreen;
    }
    if (mStatusBar != null) {
        if (DEBUG_LAYOUT)
            Log.i(TAG, "force=" + mForceStatusBar + " forcefkg=" + mForceStatusBarFromKeyguard + " top=" + mTopFullscreenOpaqueWindowState);
        if ((mForceStatusBar || mForceStatusBarFromKeyguard) && Settings.System.getInt(mContext.getContentResolver(), Settings.System.EXPANDED_DESKTOP_STATE, 0) == 0) {
            if (DEBUG_LAYOUT)
                Log.v(TAG, "Showing status bar: forced");
            if (mStatusBar.showLw(true))
                changes |= FINISH_LAYOUT_REDO_LAYOUT;
        } else if (mTopFullscreenOpaqueWindowState != null) {
            if (localLOGV) {
                Log.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw() + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
                Log.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs() + " lp.flags=0x" + Integer.toHexString(lp.flags));
            }
            topIsFullscreen = (lp.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
            // case though.
            if (topIsFullscreen || Settings.System.getInt(mContext.getContentResolver(), Settings.System.EXPANDED_DESKTOP_STATE, 0) == 1) {
                if (DEBUG_LAYOUT)
                    Log.v(TAG, "** HIDING status bar");
                if (mStatusBar.hideLw(true)) {
                    changes |= FINISH_LAYOUT_REDO_LAYOUT;
                    mHandler.post(new Runnable() {

                        @Override
                        public void run() {
                            try {
                                IStatusBarService statusbar = getStatusBarService();
                                if (statusbar != null) {
                                    statusbar.collapsePanels();
                                }
                            } catch (RemoteException ex) {
                                // re-acquire status bar service next time it is needed.
                                mStatusBarService = null;
                            }
                        }
                    });
                } else if (DEBUG_LAYOUT) {
                    Log.v(TAG, "Preventing status bar from hiding by policy");
                }
            } else {
                if (DEBUG_LAYOUT)
                    Log.v(TAG, "** SHOWING status bar: top is not fullscreen");
                if (mStatusBar.showLw(true))
                    changes |= FINISH_LAYOUT_REDO_LAYOUT;
            }
        }
    }
    mTopIsFullscreen = topIsFullscreen;
    // displayed when the screen is locked.
    if (mKeyguard != null) {
        if (localLOGV)
            Log.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard=" + mHideLockScreen);
        if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardMediator.isSecure()) {
            if (mKeyguard.hideLw(true)) {
                changes |= FINISH_LAYOUT_REDO_LAYOUT | FINISH_LAYOUT_REDO_CONFIG | FINISH_LAYOUT_REDO_WALLPAPER;
            }
            if (mKeyguardMediator.isShowing()) {
                mHandler.post(new Runnable() {

                    @Override
                    public void run() {
                        mKeyguardMediator.keyguardDone(false, false);
                    }
                });
            }
        } else if (mHideLockScreen) {
            if (mKeyguard.hideLw(true)) {
                changes |= FINISH_LAYOUT_REDO_LAYOUT | FINISH_LAYOUT_REDO_CONFIG | FINISH_LAYOUT_REDO_WALLPAPER;
            }
            mKeyguardMediator.setHidden(true);
        } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
            // This is the case of keyguard isSecure() and not mHideLockScreen.
            if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
                // Only launch the next keyguard unlock window once per window.
                if (mKeyguard.showLw(true)) {
                    changes |= FINISH_LAYOUT_REDO_LAYOUT | FINISH_LAYOUT_REDO_CONFIG | FINISH_LAYOUT_REDO_WALLPAPER;
                }
                mKeyguardMediator.setHidden(false);
                mHandler.post(new Runnable() {

                    @Override
                    public void run() {
                        mKeyguardMediator.dismiss();
                    }
                });
            }
        } else {
            mWinDismissingKeyguard = null;
            if (mKeyguard.showLw(true)) {
                changes |= FINISH_LAYOUT_REDO_LAYOUT | FINISH_LAYOUT_REDO_CONFIG | FINISH_LAYOUT_REDO_WALLPAPER;
            }
            mKeyguardMediator.setHidden(false);
        }
    }
    if ((updateSystemUiVisibilityLw() & SYSTEM_UI_CHANGING_LAYOUT) != 0) {
        // If the navigation bar has been hidden or shown, we need to do another
        // layout pass to update that window.
        changes |= FINISH_LAYOUT_REDO_LAYOUT;
    }
    // update since mAllowLockscreenWhenOn might have changed
    updateLockScreenTimeout();
    return changes;
}
Also used : IStatusBarService(com.android.internal.statusbar.IStatusBarService) LayoutParams(android.view.WindowManager.LayoutParams) RemoteException(android.os.RemoteException) IWindowManager(android.view.IWindowManager) WindowManager(android.view.WindowManager)

Example 13 with IStatusBarService

use of com.android.internal.statusbar.IStatusBarService in project cornerstone by Onskreen.

the class PhoneWindowManager method finishAnimationLw.

/** {@inheritDoc} */
public int finishAnimationLw() {
    int changes = 0;
    boolean topIsFullscreen = false;
    final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null) ? mTopFullscreenOpaqueWindowState.getAttrs() : null;
    if (mStatusBar != null) {
        if (DEBUG_LAYOUT)
            Log.i(TAG, "force=" + mForceStatusBar + " top=" + mTopFullscreenOpaqueWindowState);
        if (mForceStatusBar) {
            if (DEBUG_LAYOUT)
                Log.v(TAG, "Showing status bar: forced");
            if (mStatusBar.showLw(true))
                changes |= FINISH_LAYOUT_REDO_LAYOUT;
        } else if (mTopFullscreenOpaqueWindowState != null) {
            if (localLOGV) {
                Log.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw() + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
                Log.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs() + " lp.flags=0x" + Integer.toHexString(lp.flags));
            }
            topIsFullscreen = (lp.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
            /**
                 * Author: Onskreen
                 * Date: 24/02/2011
                 *
                 * Never hide the status bar to ensure that app always renders within
                 * the CS panel.
                 */
            topIsFullscreen = false;
            // case though.
            if (topIsFullscreen) {
                if (DEBUG_LAYOUT)
                    Log.v(TAG, "** HIDING status bar");
                if (mStatusBar.hideLw(true)) {
                    changes |= FINISH_LAYOUT_REDO_LAYOUT;
                    mHandler.post(new Runnable() {

                        public void run() {
                            try {
                                IStatusBarService statusbar = getStatusBarService();
                                if (statusbar != null) {
                                    statusbar.collapse();
                                }
                            } catch (RemoteException ex) {
                                // re-acquire status bar service next time it is needed.
                                mStatusBarService = null;
                            }
                        }
                    });
                } else if (DEBUG_LAYOUT) {
                    Log.v(TAG, "Preventing status bar from hiding by policy");
                }
            } else {
                if (DEBUG_LAYOUT)
                    Log.v(TAG, "** SHOWING status bar: top is not fullscreen");
                if (mStatusBar.showLw(true))
                    changes |= FINISH_LAYOUT_REDO_LAYOUT;
            }
        }
    }
    mTopIsFullscreen = topIsFullscreen;
    // when the screen is locked
    if (mKeyguard != null) {
        if (localLOGV)
            Log.v(TAG, "finishAnimationLw::mHideKeyguard=" + mHideLockScreen);
        if (mDismissKeyguard && !mKeyguardMediator.isSecure()) {
            if (mKeyguard.hideLw(true)) {
                changes |= FINISH_LAYOUT_REDO_LAYOUT | FINISH_LAYOUT_REDO_CONFIG | FINISH_LAYOUT_REDO_WALLPAPER;
            }
            if (mKeyguardMediator.isShowing()) {
                mHandler.post(new Runnable() {

                    public void run() {
                        mKeyguardMediator.keyguardDone(false, false);
                    }
                });
            }
        } else if (mHideLockScreen) {
            if (mKeyguard.hideLw(true)) {
                changes |= FINISH_LAYOUT_REDO_LAYOUT | FINISH_LAYOUT_REDO_CONFIG | FINISH_LAYOUT_REDO_WALLPAPER;
            }
            mKeyguardMediator.setHidden(true);
        } else {
            if (mKeyguard.showLw(true)) {
                changes |= FINISH_LAYOUT_REDO_LAYOUT | FINISH_LAYOUT_REDO_CONFIG | FINISH_LAYOUT_REDO_WALLPAPER;
            }
            mKeyguardMediator.setHidden(false);
        }
    }
    if ((updateSystemUiVisibilityLw() & SYSTEM_UI_CHANGING_LAYOUT) != 0) {
        // If the navigation bar has been hidden or shown, we need to do another
        // layout pass to update that window.
        changes |= FINISH_LAYOUT_REDO_LAYOUT;
    }
    // update since mAllowLockscreenWhenOn might have changed
    updateLockScreenTimeout();
    return changes;
}
Also used : IStatusBarService(com.android.internal.statusbar.IStatusBarService) RemoteException(android.os.RemoteException) IWindowManager(android.view.IWindowManager) WindowManager(android.view.WindowManager)

Example 14 with IStatusBarService

use of com.android.internal.statusbar.IStatusBarService in project cornerstone by Onskreen.

the class PhoneWindowManager method interceptKeyBeforeDispatching.

/** {@inheritDoc} */
@Override
public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
    final boolean keyguardOn = keyguardOn();
    final int keyCode = event.getKeyCode();
    final int repeatCount = event.getRepeatCount();
    final int metaState = event.getMetaState();
    final int flags = event.getFlags();
    final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
    final boolean canceled = event.isCanceled();
    if (DEBUG_INPUT) {
        Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed + " canceled=" + canceled);
    }
    // try again later before dispatching.
    if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
        if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
            final long now = SystemClock.uptimeMillis();
            final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
            if (now < timeoutTime) {
                return timeoutTime - now;
            }
        }
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN && mVolumeDownKeyConsumedByScreenshotChord) {
            if (!down) {
                mVolumeDownKeyConsumedByScreenshotChord = false;
            }
            return -1;
        }
    }
    // timeout.
    if (keyCode == KeyEvent.KEYCODE_HOME) {
        // while it was pressed, then it is time to go home!
        if (!down) {
            final boolean homeWasLongPressed = mHomeLongPressed;
            mHomePressed = false;
            mHomeLongPressed = false;
            if (!homeWasLongPressed) {
                try {
                    IStatusBarService statusbar = getStatusBarService();
                    if (statusbar != null) {
                        statusbar.cancelPreloadRecentApps();
                    }
                } catch (RemoteException e) {
                    Slog.e(TAG, "RemoteException when showing recent apps", e);
                    // re-acquire status bar service next time it is needed.
                    mStatusBarService = null;
                }
                mHomePressed = false;
                if (!canceled) {
                    // If an incoming call is ringing, HOME is totally disabled.
                    // (The user is already on the InCallScreen at this point,
                    // and his ONLY options are to answer or reject the call.)
                    boolean incomingRinging = false;
                    try {
                        ITelephony telephonyService = getTelephonyService();
                        if (telephonyService != null) {
                            incomingRinging = telephonyService.isRinging();
                        }
                    } catch (RemoteException ex) {
                        Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
                    }
                    if (incomingRinging) {
                        Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
                    } else {
                        launchHomeFromHotKey();
                    }
                } else {
                    Log.i(TAG, "Ignoring HOME; event canceled.");
                }
                return -1;
            }
        }
        // If a system window has focus, then it doesn't make sense
        // right now to interact with applications.
        WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
        if (attrs != null) {
            final int type = attrs.type;
            if (type == WindowManager.LayoutParams.TYPE_KEYGUARD || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) {
                // the "app" is keyguard, so give it the key
                return 0;
            }
            final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
            for (int i = 0; i < typeCount; i++) {
                if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
                    // don't do anything, but also don't pass it to the app
                    return -1;
                }
            }
        }
        if (down) {
            if (!mHomePressed && mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
                try {
                    IStatusBarService statusbar = getStatusBarService();
                    if (statusbar != null) {
                        statusbar.preloadRecentApps();
                    }
                } catch (RemoteException e) {
                    Slog.e(TAG, "RemoteException when preloading recent apps", e);
                    // re-acquire status bar service next time it is needed.
                    mStatusBarService = null;
                }
            }
            if (repeatCount == 0) {
                /**
                     * Author: Onskreen
                     * Date: 31/05/2011
                     *
                     * If the dialog is present, first kill/dismiss the dialog
                     * and then launch the HOME app or recent app dialog.
                     */
                if (win.isDialog()) {
                    win.removeWindowState();
                }
                mHomePressed = true;
            } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
                if (!keyguardOn) {
                    handleLongPressOnHome();
                }
            }
        }
        return -1;
    } else if (keyCode == KeyEvent.KEYCODE_MENU) {
        // Hijack modified menu keys for debugging features
        final int chordBug = KeyEvent.META_SHIFT_ON;
        if (down && repeatCount == 0) {
            if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
                Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
                mContext.sendOrderedBroadcast(intent, null);
                return -1;
            } else if (SHOW_PROCESSES_ON_ALT_MENU && (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
                Intent service = new Intent();
                service.setClassName(mContext, "com.android.server.LoadAverageService");
                ContentResolver res = mContext.getContentResolver();
                boolean shown = Settings.System.getInt(res, Settings.System.SHOW_PROCESSES, 0) != 0;
                if (!shown) {
                    mContext.startService(service);
                } else {
                    mContext.stopService(service);
                }
                Settings.System.putInt(res, Settings.System.SHOW_PROCESSES, shown ? 0 : 1);
                return -1;
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
        if (down) {
            if (repeatCount == 0) {
                mSearchKeyShortcutPending = true;
                mConsumeSearchKeyUp = false;
            }
        } else {
            mSearchKeyShortcutPending = false;
            if (mConsumeSearchKeyUp) {
                mConsumeSearchKeyUp = false;
                return -1;
            }
        }
        return 0;
    } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
        if (down && repeatCount == 0 && !keyguardOn) {
            showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS);
        }
        return -1;
    } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
        if (down) {
            if (repeatCount == 0) {
                mAssistKeyLongPressed = false;
            } else if (repeatCount == 1) {
                mAssistKeyLongPressed = true;
                if (!keyguardOn) {
                    launchAssistLongPressAction();
                }
            }
        } else {
            if (mAssistKeyLongPressed) {
                mAssistKeyLongPressed = false;
            } else {
                if (!keyguardOn) {
                    launchAssistAction();
                }
            }
        }
        return -1;
    }
    // shortcut keys (that emit Search+x) and some of them are not registered.
    if (mSearchKeyShortcutPending) {
        final KeyCharacterMap kcm = event.getKeyCharacterMap();
        if (kcm.isPrintingKey(keyCode)) {
            mConsumeSearchKeyUp = true;
            mSearchKeyShortcutPending = false;
            if (down && repeatCount == 0 && !keyguardOn) {
                Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
                if (shortcutIntent != null) {
                    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    try {
                        mContext.startActivity(shortcutIntent);
                    } catch (ActivityNotFoundException ex) {
                        Slog.w(TAG, "Dropping shortcut key combination because " + "the activity to which it is registered was not found: " + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
                    }
                } else {
                    Slog.i(TAG, "Dropping unregistered shortcut key combination: " + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
                }
            }
            return -1;
        }
    }
    // Invoke shortcuts using Meta.
    if (down && repeatCount == 0 && !keyguardOn && (metaState & KeyEvent.META_META_ON) != 0) {
        final KeyCharacterMap kcm = event.getKeyCharacterMap();
        if (kcm.isPrintingKey(keyCode)) {
            Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState & ~(KeyEvent.META_META_ON | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
            if (shortcutIntent != null) {
                shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                try {
                    mContext.startActivity(shortcutIntent);
                } catch (ActivityNotFoundException ex) {
                    Slog.w(TAG, "Dropping shortcut key combination because " + "the activity to which it is registered was not found: " + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
                }
                return -1;
            }
        }
    }
    // Handle application launch keys.
    if (down && repeatCount == 0 && !keyguardOn) {
        String category = sApplicationLaunchKeyCategories.get(keyCode);
        if (category != null) {
            Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            try {
                mContext.startActivity(intent);
            } catch (ActivityNotFoundException ex) {
                Slog.w(TAG, "Dropping application launch key because " + "the activity to which it is registered was not found: " + "keyCode=" + keyCode + ", category=" + category, ex);
            }
            return -1;
        }
    }
    // Display task switcher for ALT-TAB or Meta-TAB.
    if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
        if (mRecentAppsDialogHeldModifiers == 0 && !keyguardOn) {
            final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
            if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON) || KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_META_ON)) {
                mRecentAppsDialogHeldModifiers = shiftlessModifiers;
                showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW);
                return -1;
            }
        }
    } else if (!down && mRecentAppsDialogHeldModifiers != 0 && (metaState & mRecentAppsDialogHeldModifiers) == 0) {
        mRecentAppsDialogHeldModifiers = 0;
        showOrHideRecentAppsDialog(keyguardOn ? RECENT_APPS_BEHAVIOR_DISMISS : RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH);
    }
    // Handle keyboard language switching.
    if (down && repeatCount == 0 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH || (keyCode == KeyEvent.KEYCODE_SPACE && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
        int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
        mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
        return -1;
    }
    if (mLanguageSwitchKeyPressed && !down && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH || keyCode == KeyEvent.KEYCODE_SPACE)) {
        mLanguageSwitchKeyPressed = false;
        return -1;
    }
    // Let the application handle the key.
    return 0;
}
Also used : IStatusBarService(com.android.internal.statusbar.IStatusBarService) Intent(android.content.Intent) KeyCharacterMap(android.view.KeyCharacterMap) IWindowManager(android.view.IWindowManager) WindowManager(android.view.WindowManager) ContentResolver(android.content.ContentResolver) ActivityNotFoundException(android.content.ActivityNotFoundException) RemoteException(android.os.RemoteException) ITelephony(com.android.internal.telephony.ITelephony)

Example 15 with IStatusBarService

use of com.android.internal.statusbar.IStatusBarService in project android_frameworks_base by DirtyUnicorns.

the class PhoneWindowManager method interceptKeyBeforeDispatching.

/** {@inheritDoc} */
@Override
public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
    final boolean keyguardOn = keyguardOn();
    final int repeatCount = event.getRepeatCount();
    final int metaState = event.getMetaState();
    final int flags = event.getFlags();
    final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
    final boolean canceled = event.isCanceled();
    final int keyCode = event.getKeyCode();
    final boolean longPress = (flags & KeyEvent.FLAG_LONG_PRESS) != 0;
    final boolean virtualKey = event.getDeviceId() == KeyCharacterMap.VIRTUAL_KEYBOARD;
    if (DEBUG_INPUT) {
        Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed + " canceled=" + canceled);
    }
    // implementation handle event
    if (mKeyHandler != null && !keyguardOn && !virtualKey) {
        boolean handled = mKeyHandler.handleKeyEvent(win, keyCode, repeatCount, down, canceled, longPress, keyguardOn);
        if (handled)
            return -1;
    }
    // try again later before dispatching.
    if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
        if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
            final long now = SystemClock.uptimeMillis();
            final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
            if (now < timeoutTime) {
                return timeoutTime - now;
            }
        }
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN && mScreenshotChordVolumeDownKeyConsumed) {
            if (!down) {
                mScreenshotChordVolumeDownKeyConsumed = false;
            }
            return -1;
        }
    }
    // try again later before dispatching.
    if (mScreenrecordChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
        if (mVolumeUpKeyTriggered && !mPowerKeyTriggered) {
            final long now = SystemClock.uptimeMillis();
            final long timeoutTime = mVolumeUpKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
            if (now < timeoutTime) {
                return timeoutTime - now;
            }
        }
        if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && mScreenrecordChordVolumeUpKeyConsumed) {
            if (!down) {
                mScreenrecordChordVolumeUpKeyConsumed = false;
            }
            return -1;
        }
    }
    // of the meta key and its corresponding up.
    if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
        mPendingMetaAction = false;
    }
    // Any key that is not Alt or Meta cancels Caps Lock combo tracking.
    if (mPendingCapsLockToggle && !KeyEvent.isMetaKey(keyCode) && !KeyEvent.isAltKey(keyCode)) {
        mPendingCapsLockToggle = false;
    }
    // timeout.
    if (keyCode == KeyEvent.KEYCODE_HOME) {
        // while it was pressed, then it is time to go home!
        if (!down) {
            cancelPreloadRecentApps();
            mHomePressed = false;
            if (mHomeConsumed) {
                mHomeConsumed = false;
                return -1;
            }
            if (canceled) {
                Log.i(TAG, "Ignoring HOME; event canceled.");
                return -1;
            }
            // Delay handling home if a double-tap is possible.
            if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
                // just in case
                mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
                mHomeDoubleTapPending = true;
                mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable, ViewConfiguration.getDoubleTapTimeout());
                return -1;
            }
            handleShortPressOnHome();
            return -1;
        }
        // If a system window has focus, then it doesn't make sense
        // right now to interact with applications.
        WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
        if (attrs != null) {
            final int type = attrs.type;
            if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
                // the "app" is keyguard, so give it the key
                return 0;
            }
            final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
            for (int i = 0; i < typeCount; i++) {
                if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
                    // don't do anything, but also don't pass it to the app
                    return -1;
                }
            }
        }
        // Remember that home is pressed and handle special actions.
        if (repeatCount == 0) {
            mHomePressed = true;
            if (mHomeDoubleTapPending) {
                mHomeDoubleTapPending = false;
                mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
                handleDoubleTapOnHome();
            } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
                preloadRecentApps();
            }
        } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
            if (!keyguardOn) {
                handleLongPressOnHome(event.getDeviceId());
            }
        }
        return -1;
    } else if (keyCode == KeyEvent.KEYCODE_MENU) {
        // Hijack modified menu keys for debugging features
        final int chordBug = KeyEvent.META_SHIFT_ON;
        if (down && repeatCount == 0) {
            if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
                Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
                mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, null, null, null, 0, null, null);
                return -1;
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
        if (down) {
            if (repeatCount == 0) {
                mSearchKeyShortcutPending = true;
                mConsumeSearchKeyUp = false;
            }
        } else {
            mSearchKeyShortcutPending = false;
            if (mConsumeSearchKeyUp) {
                mConsumeSearchKeyUp = false;
                return -1;
            }
        }
        return 0;
    } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
        if (!keyguardOn) {
            if (down && repeatCount == 0) {
                preloadRecentApps();
            } else if (!down) {
                toggleRecentApps();
            }
        }
        return -1;
    } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
        if (down) {
            IStatusBarService service = getStatusBarService();
            if (service != null) {
                try {
                    service.expandNotificationsPanel();
                } catch (RemoteException e) {
                // do nothing.
                }
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_S && event.isMetaPressed() && event.isCtrlPressed()) {
        if (down && repeatCount == 0) {
            int type = (event.isShiftPressed() || Settings.System.getInt(mContext.getContentResolver(), Settings.System.SCREENSHOT_TYPE, 0) == 1) ? TAKE_SCREENSHOT_SELECTED_REGION : TAKE_SCREENSHOT_FULLSCREEN;
            mScreenshotRunnable.setScreenshotType(type);
            mHandler.post(mScreenshotRunnable);
            return -1;
        }
    } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) {
        if (down && repeatCount == 0 && !isKeyguardLocked()) {
            toggleKeyboardShortcutsMenu(event.getDeviceId());
        }
    } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
        if (down) {
            if (repeatCount == 0) {
                mAssistKeyLongPressed = false;
            } else if (repeatCount == 1) {
                mAssistKeyLongPressed = true;
                if (!keyguardOn) {
                    launchAssistLongPressAction();
                }
            }
        } else {
            if (mAssistKeyLongPressed) {
                mAssistKeyLongPressed = false;
            } else {
                if (!keyguardOn) {
                    launchAssistAction(null, event.getDeviceId());
                }
            }
        }
        return -1;
    } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
        if (!down) {
            Intent voiceIntent;
            if (!keyguardOn) {
                voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
            } else {
                IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
                if (dic != null) {
                    try {
                        dic.exitIdle("voice-search");
                    } catch (RemoteException e) {
                    }
                }
                voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
                voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
            }
            startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
        }
    } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
        if (down && repeatCount == 0) {
            if (Settings.System.getInt(mContext.getContentResolver(), Settings.System.SCREENSHOT_TYPE, 0) == 1) {
                mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_SELECTED_REGION);
            } else {
                mScreenshotRunnable.setScreenshotType(TAKE_SCREENSHOT_FULLSCREEN);
            }
            mHandler.post(mScreenshotRunnable);
        }
        return -1;
    } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
        if (down) {
            int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
            // Disable autobrightness if it's on
            int auto = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, UserHandle.USER_CURRENT_OR_SELF);
            if (auto != 0) {
                Settings.System.putIntForUser(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, UserHandle.USER_CURRENT_OR_SELF);
            }
            int min = mPowerManager.getMinimumScreenBrightnessSetting();
            int max = mPowerManager.getMaximumScreenBrightnessSetting();
            int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
            int brightness = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, mPowerManager.getDefaultScreenBrightnessSetting(), UserHandle.USER_CURRENT_OR_SELF);
            brightness += step;
            // Make sure we don't go beyond the limits.
            brightness = Math.min(max, brightness);
            brightness = Math.max(min, brightness);
            Settings.System.putIntForUser(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, brightness, UserHandle.USER_CURRENT_OR_SELF);
            startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG), UserHandle.CURRENT_OR_SELF);
        }
        return -1;
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
        if (mUseTvRouting) {
            // On TVs volume keys never go to the foreground app.
            dispatchDirectAudioEvent(event);
            return -1;
        }
    }
    // Toggle Caps Lock on META-ALT.
    boolean actionTriggered = false;
    if (KeyEvent.isModifierKey(keyCode)) {
        if (!mPendingCapsLockToggle) {
            // Start tracking meta state for combo.
            mInitialMetaState = mMetaState;
            mPendingCapsLockToggle = true;
        } else if (event.getAction() == KeyEvent.ACTION_UP) {
            int altOnMask = mMetaState & KeyEvent.META_ALT_MASK;
            int metaOnMask = mMetaState & KeyEvent.META_META_MASK;
            // Check for Caps Lock toggle
            if ((metaOnMask != 0) && (altOnMask != 0)) {
                // Check if nothing else is pressed
                if (mInitialMetaState == (mMetaState ^ (altOnMask | metaOnMask))) {
                    // Handle Caps Lock Toggle
                    mInputManagerInternal.toggleCapsLock(event.getDeviceId());
                    actionTriggered = true;
                }
            }
            // Always stop tracking when key goes up.
            mPendingCapsLockToggle = false;
        }
    }
    // Store current meta state to be able to evaluate it later.
    mMetaState = metaState;
    if (actionTriggered) {
        return -1;
    }
    if (KeyEvent.isMetaKey(keyCode)) {
        if (down) {
            mPendingMetaAction = true;
        } else if (mPendingMetaAction) {
            launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
        }
        return -1;
    }
    // shortcut keys (that emit Search+x) and some of them are not registered.
    if (mSearchKeyShortcutPending) {
        final KeyCharacterMap kcm = event.getKeyCharacterMap();
        if (kcm.isPrintingKey(keyCode)) {
            mConsumeSearchKeyUp = true;
            mSearchKeyShortcutPending = false;
            if (down && repeatCount == 0 && !keyguardOn) {
                Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
                if (shortcutIntent != null) {
                    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    try {
                        startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
                        dismissKeyboardShortcutsMenu();
                    } catch (ActivityNotFoundException ex) {
                        Slog.w(TAG, "Dropping shortcut key combination because " + "the activity to which it is registered was not found: " + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
                    }
                } else {
                    Slog.i(TAG, "Dropping unregistered shortcut key combination: " + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
                }
            }
            return -1;
        }
    }
    // Invoke shortcuts using Meta.
    if (down && repeatCount == 0 && !keyguardOn && (metaState & KeyEvent.META_META_ON) != 0) {
        final KeyCharacterMap kcm = event.getKeyCharacterMap();
        if (kcm.isPrintingKey(keyCode)) {
            Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState & ~(KeyEvent.META_META_ON | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
            if (shortcutIntent != null) {
                shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                try {
                    startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
                    dismissKeyboardShortcutsMenu();
                } catch (ActivityNotFoundException ex) {
                    Slog.w(TAG, "Dropping shortcut key combination because " + "the activity to which it is registered was not found: " + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
                }
                return -1;
            }
        }
    }
    // Handle application launch keys.
    if (down && repeatCount == 0 && !keyguardOn) {
        String category = sApplicationLaunchKeyCategories.get(keyCode);
        if (category != null) {
            Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            try {
                startActivityAsUser(intent, UserHandle.CURRENT);
                dismissKeyboardShortcutsMenu();
            } catch (ActivityNotFoundException ex) {
                Slog.w(TAG, "Dropping application launch key because " + "the activity to which it is registered was not found: " + "keyCode=" + keyCode + ", category=" + category, ex);
            }
            return -1;
        }
    }
    // Display task switcher for ALT-TAB.
    if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
        if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) {
            final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
            if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
                mRecentAppsHeldModifiers = shiftlessModifiers;
                showRecentApps(true, false);
                return -1;
            }
        }
    } else if (!down && mRecentAppsHeldModifiers != 0 && (metaState & mRecentAppsHeldModifiers) == 0) {
        mRecentAppsHeldModifiers = 0;
        hideRecentApps(true, false);
    }
    // Handle input method switching.
    if (down && repeatCount == 0 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH || (keyCode == KeyEvent.KEYCODE_SPACE && (metaState & KeyEvent.META_META_MASK) != 0))) {
        final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0;
        mWindowManagerFuncs.switchInputMethod(forwardDirection);
        return -1;
    }
    if (mLanguageSwitchKeyPressed && !down && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH || keyCode == KeyEvent.KEYCODE_SPACE)) {
        mLanguageSwitchKeyPressed = false;
        return -1;
    }
    if (isValidGlobalKey(keyCode) && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
        return -1;
    }
    // Specific device key handling
    if (mDeviceKeyHandler != null) {
        try {
            // The device only should consume known keys.
            if (mDeviceKeyHandler.handleKeyEvent(event)) {
                return -1;
            }
        } catch (Exception e) {
            Slog.w(TAG, "Could not dispatch event to device key handler", e);
        }
    }
    if (down) {
        long shortcutCode = keyCode;
        if (event.isCtrlPressed()) {
            shortcutCode |= ((long) KeyEvent.META_CTRL_ON) << Integer.SIZE;
        }
        if (event.isAltPressed()) {
            shortcutCode |= ((long) KeyEvent.META_ALT_ON) << Integer.SIZE;
        }
        if (event.isShiftPressed()) {
            shortcutCode |= ((long) KeyEvent.META_SHIFT_ON) << Integer.SIZE;
        }
        if (event.isMetaPressed()) {
            shortcutCode |= ((long) KeyEvent.META_META_ON) << Integer.SIZE;
        }
        IShortcutService shortcutService = mShortcutKeyServices.get(shortcutCode);
        if (shortcutService != null) {
            try {
                if (isUserSetupComplete()) {
                    shortcutService.notifyShortcutKeyPressed(shortcutCode);
                }
            } catch (RemoteException e) {
                mShortcutKeyServices.delete(shortcutCode);
            }
            return -1;
        }
    }
    // Reserve all the META modifier combos for system behavior
    if ((metaState & KeyEvent.META_META_ON) != 0) {
        return -1;
    }
    // Let the application handle the key.
    return 0;
}
Also used : IStatusBarService(com.android.internal.statusbar.IStatusBarService) Intent(android.content.Intent) RecognizerIntent(android.speech.RecognizerIntent) IDeviceIdleController(android.os.IDeviceIdleController) KeyCharacterMap(android.view.KeyCharacterMap) RemoteException(android.os.RemoteException) IOException(java.io.IOException) ActivityNotFoundException(android.content.ActivityNotFoundException) CameraAccessException(android.hardware.camera2.CameraAccessException) IWindowManager(android.view.IWindowManager) WindowManager(android.view.WindowManager) IShortcutService(com.android.internal.policy.IShortcutService) ActivityNotFoundException(android.content.ActivityNotFoundException) LayoutParams(android.view.WindowManager.LayoutParams) RemoteException(android.os.RemoteException)

Aggregations

RemoteException (android.os.RemoteException)17 IStatusBarService (com.android.internal.statusbar.IStatusBarService)17 IWindowManager (android.view.IWindowManager)8 Intent (android.content.Intent)7 WindowManager (android.view.WindowManager)6 ActivityNotFoundException (android.content.ActivityNotFoundException)5 KeyCharacterMap (android.view.KeyCharacterMap)4 LayoutParams (android.view.WindowManager.LayoutParams)4 IDeviceIdleController (android.os.IDeviceIdleController)3 RecognizerIntent (android.speech.RecognizerIntent)3 IShortcutService (com.android.internal.policy.IShortcutService)3 URISyntaxException (java.net.URISyntaxException)3 SearchManager (android.app.SearchManager)1 ContentResolver (android.content.ContentResolver)1 CameraAccessException (android.hardware.camera2.CameraAccessException)1 AudioManager (android.media.AudioManager)1 ToneGenerator (android.media.ToneGenerator)1 PowerManager (android.os.PowerManager)1 UserHandle (android.os.UserHandle)1 Vibrator (android.os.Vibrator)1