Search in sources :

Example 56 with TelecomManager

use of android.telecom.TelecomManager in project android_frameworks_base by AOSPA.

the class SimSwitchController method subscriptionIdToPhoneAccountHandle.

private PhoneAccountHandle subscriptionIdToPhoneAccountHandle(final int subId) {
    final TelecomManager telecomManager = TelecomManager.from(mContext);
    final TelephonyManager telephonyManager = TelephonyManager.from(mContext);
    final Iterator<PhoneAccountHandle> phoneAccounts = telecomManager.getCallCapablePhoneAccounts().listIterator();
    while (phoneAccounts.hasNext()) {
        final PhoneAccountHandle phoneAccountHandle = phoneAccounts.next();
        final PhoneAccount phoneAccount = telecomManager.getPhoneAccount(phoneAccountHandle);
        if (subId == telephonyManager.getSubIdForPhoneAccount(phoneAccount)) {
            return phoneAccountHandle;
        }
    }
    return null;
}
Also used : PhoneAccount(android.telecom.PhoneAccount) PhoneAccountHandle(android.telecom.PhoneAccountHandle) TelephonyManager(android.telephony.TelephonyManager) TelecomManager(android.telecom.TelecomManager)

Example 57 with TelecomManager

use of android.telecom.TelecomManager in project android_frameworks_base by ResurrectionRemix.

the class TelecomLoaderService method registerDefaultAppProviders.

private void registerDefaultAppProviders() {
    final PackageManagerInternal packageManagerInternal = LocalServices.getService(PackageManagerInternal.class);
    // Set a callback for the package manager to query the default sms app.
    packageManagerInternal.setSmsAppPackagesProvider(new PackageManagerInternal.PackagesProvider() {

        @Override
        public String[] getPackages(int userId) {
            synchronized (mLock) {
                if (mServiceConnection == null) {
                    if (mDefaultSmsAppRequests == null) {
                        mDefaultSmsAppRequests = new IntArray();
                    }
                    mDefaultSmsAppRequests.add(userId);
                    return null;
                }
            }
            ComponentName smsComponent = SmsApplication.getDefaultSmsApplication(mContext, true);
            if (smsComponent != null) {
                return new String[] { smsComponent.getPackageName() };
            }
            return null;
        }
    });
    // Set a callback for the package manager to query the default dialer app.
    packageManagerInternal.setDialerAppPackagesProvider(new PackageManagerInternal.PackagesProvider() {

        @Override
        public String[] getPackages(int userId) {
            synchronized (mLock) {
                if (mServiceConnection == null) {
                    if (mDefaultDialerAppRequests == null) {
                        mDefaultDialerAppRequests = new IntArray();
                    }
                    mDefaultDialerAppRequests.add(userId);
                    return null;
                }
            }
            String packageName = DefaultDialerManager.getDefaultDialerApplication(mContext);
            if (packageName != null) {
                return new String[] { packageName };
            }
            return null;
        }
    });
    // Set a callback for the package manager to query the default sim call manager.
    packageManagerInternal.setSimCallManagerPackagesProvider(new PackageManagerInternal.PackagesProvider() {

        @Override
        public String[] getPackages(int userId) {
            synchronized (mLock) {
                if (mServiceConnection == null) {
                    if (mDefaultSimCallManagerRequests == null) {
                        mDefaultSimCallManagerRequests = new IntArray();
                    }
                    mDefaultSimCallManagerRequests.add(userId);
                    return null;
                }
            }
            TelecomManager telecomManager = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
            PhoneAccountHandle phoneAccount = telecomManager.getSimCallManager(userId);
            if (phoneAccount != null) {
                return new String[] { phoneAccount.getComponentName().getPackageName() };
            }
            return null;
        }
    });
}
Also used : IntArray(android.util.IntArray) PhoneAccountHandle(android.telecom.PhoneAccountHandle) PackageManagerInternal(android.content.pm.PackageManagerInternal) ComponentName(android.content.ComponentName) TelecomManager(android.telecom.TelecomManager)

Example 58 with TelecomManager

use of android.telecom.TelecomManager in project android_frameworks_base by ResurrectionRemix.

the class PhoneWindowManager method interceptBackKeyUp.

// returns true if the key was handled and should not be passed to the user
private boolean interceptBackKeyUp(KeyEvent event) {
    // Cache handled state
    boolean handled = mBackKeyHandled;
    if (hasPanicPressOnBackBehavior()) {
        // Check for back key panic press
        ++mBackKeyPressCounter;
        final long eventTime = event.getDownTime();
        if (mBackKeyPressCounter <= PANIC_PRESS_BACK_COUNT) {
            // This could be a multi-press.  Wait a little bit longer to confirm.
            Message msg = mHandler.obtainMessage(MSG_BACK_DELAYED_PRESS, mBackKeyPressCounter, 0, eventTime);
            msg.setAsynchronous(true);
            mHandler.sendMessageDelayed(msg, ViewConfiguration.getMultiPressTimeout());
        }
    }
    // Reset back long press state
    cancelPendingBackKeyAction();
    if (mHasFeatureWatch) {
        TelecomManager telecomManager = getTelecommService();
        if (telecomManager != null) {
            if (telecomManager.isRinging()) {
                // Pressing back while there's a ringing incoming
                // call should silence the ringer.
                telecomManager.silenceRinger();
                // It should not prevent navigating away
                return false;
            } else if ((mIncallBackBehavior & Settings.Secure.INCALL_BACK_BUTTON_BEHAVIOR_HANGUP) != 0 && telecomManager.isInCall()) {
                // the Back button will hang up any current active call.
                return telecomManager.endCall();
            }
        }
    }
    return handled;
}
Also used : Message(android.os.Message) TelecomManager(android.telecom.TelecomManager)

Example 59 with TelecomManager

use of android.telecom.TelecomManager in project android_frameworks_base by ResurrectionRemix.

the class PhoneWindowManager method interceptKeyBeforeQueueing.

/** {@inheritDoc} */
@Override
public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
    if (!mSystemBooted) {
        // If we have not yet booted, don't let key events do anything.
        return 0;
    }
    final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
    final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
    final boolean canceled = event.isCanceled();
    final int keyCode = event.getKeyCode();
    final int scanCode = event.getScanCode();
    final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
    // If screen is off then we treat the case where the keyguard is open but hidden
    // the same as if it were open and in front.
    // This will prevent any keys other than the power button from waking the screen
    // when the keyguard is hidden by another activity.
    final boolean keyguardActive = (mKeyguardDelegate == null ? false : (interactive ? isKeyguardShowingAndNotOccluded() : mKeyguardDelegate.isShowing()));
    // Disable all hw keys actions but let home key wake on if it's enabled
    if (isHwKeysDisabled()) {
        if (scanCode != 0 && keyCode == KeyEvent.KEYCODE_BACK && !mContext.getResources().getBoolean(com.android.internal.R.bool.config_hwKeysBackAlwaysOn)) {
            Log.i(TAG, "Ignoring Back Key: we have hw keys disabled");
            return 0;
        }
    }
    if (DEBUG_INPUT) {
        Log.d(TAG, "interceptKeyTq keycode=" + keyCode + " interactive=" + interactive + " keyguardActive=" + keyguardActive + " policyFlags=" + Integer.toHexString(policyFlags));
    }
    // Basic policy based on interactive state.
    int result;
    boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0 || event.isWakeKey();
    if (interactive || (isInjected && !isWakeKey)) {
        // When the device is interactive or the key is injected pass the
        // key to the application.
        result = ACTION_PASS_TO_USER;
        isWakeKey = false;
        if (interactive) {
            // then don't pass it to the application
            if (keyCode == mPendingWakeKey && !down) {
                result = 0;
            }
            // Reset the pending key
            mPendingWakeKey = PENDING_KEY_NULL;
        }
    } else if (!interactive && shouldDispatchInputWhenNonInteractive(event)) {
        // If we're currently dozing with the screen on and the keyguard showing, pass the key
        // to the application but preserve its wake key status to make sure we still move
        // from dozing to fully interactive if we would normally go from off to fully
        // interactive, unless the user has explicitly disabled this wake key.
        result = ACTION_PASS_TO_USER;
        isWakeKey = isWakeKey && isWakeKeyEnabled(keyCode);
        // Since we're dispatching the input, reset the pending key
        mPendingWakeKey = PENDING_KEY_NULL;
    } else {
        // When the screen is off and the key is not injected, determine whether
        // to wake the device but don't pass the key to the application.
        result = 0;
        if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
            isWakeKey = false;
        }
        // Cache the wake key on down event so we can also avoid sending the up event to the app
        if (isWakeKey && down) {
            mPendingWakeKey = keyCode;
        }
    }
    // key processing.
    if (isValidGlobalKey(keyCode) && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
        if (isWakeKey) {
            wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY", true);
        }
        return result;
    }
    boolean useHapticFeedback = down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0 && event.getRepeatCount() == 0 && !isHwKeysDisabled();
    // Specific device key handling
    if (dispatchKeyToKeyHandlers(event)) {
        return 0;
    }
    // Handle special keys.
    switch(keyCode) {
        case KeyEvent.KEYCODE_BACK:
            {
                if (down) {
                    interceptBackKeyDown();
                } else {
                    boolean handled = interceptBackKeyUp(event);
                    // Don't pass back press to app if we've already handled it via long press
                    if (handled) {
                        result &= ~ACTION_PASS_TO_USER;
                    }
                }
                break;
            }
        case KeyEvent.KEYCODE_VOLUME_DOWN:
        case KeyEvent.KEYCODE_VOLUME_UP:
        case KeyEvent.KEYCODE_VOLUME_MUTE:
            {
                // This disables volume control, music control, and "beep" on key up.
                if (isWakeKey && mVolumeWakeScreen) {
                    setVolumeWakeTriggered(keyCode, true);
                    break;
                } else if (getVolumeWakeTriggered(keyCode) && !down) {
                    result &= ~ACTION_PASS_TO_USER;
                    setVolumeWakeTriggered(keyCode, false);
                    break;
                }
                if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
                    if (down) {
                        if (interactive && !mVolumeDownKeyTriggered && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
                            mVolumeDownKeyTriggered = true;
                            mVolumeDownKeyTime = event.getDownTime();
                            mScreenshotChordVolumeDownKeyConsumed = false;
                            cancelPendingPowerKeyAction();
                            cancelPendingScreenrecordChordAction();
                            checkSettings();
                            interceptScreenshotChord();
                        }
                    } else {
                        mVolumeDownKeyTriggered = false;
                        cancelPendingScreenshotChordAction();
                        cancelPendingScreenrecordChordAction();
                    }
                } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
                    if (down) {
                        if (interactive && !mVolumeUpKeyTriggered && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
                            mVolumeUpKeyTriggered = true;
                            mVolumeUpKeyTime = event.getDownTime();
                            mScreenrecordChordVolumeUpKeyConsumed = false;
                            cancelPendingPowerKeyAction();
                            cancelPendingScreenshotChordAction();
                            interceptScreenrecordChord();
                        }
                    } else {
                        mVolumeUpKeyTriggered = false;
                        cancelPendingScreenshotChordAction();
                        cancelPendingScreenrecordChordAction();
                    }
                }
                if (down) {
                    TelecomManager telecomManager = getTelecommService();
                    if (telecomManager != null) {
                        if (telecomManager.isRinging()) {
                            if (mVolumeAnswerCall) {
                                telecomManager.acceptRingingCall();
                            }
                            // If an incoming call is ringing, either VOLUME key means
                            // "silence ringer".  We handle these keys here, rather than
                            // in the InCallScreen, to make sure we'll respond to them
                            // even if the InCallScreen hasn't come to the foreground yet.
                            // Look for the DOWN event here, to agree with the "fallback"
                            // behavior in the InCallScreen.
                            Log.i(TAG, "interceptKeyBeforeQueueing:" + " VOLUME key-down while ringing: Silence ringer!");
                            // Silence the ringer.  (It's safe to call this
                            // even if the ringer has already been silenced.)
                            telecomManager.silenceRinger();
                            // And *don't* pass this key thru to the current activity
                            // (which is probably the InCallScreen.)
                            result &= ~ACTION_PASS_TO_USER;
                            break;
                        }
                        if (telecomManager.isInCall() && (result & ACTION_PASS_TO_USER) == 0) {
                            // If we are in call but we decided not to pass the key to
                            // the application, just pass it to the session service.
                            MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent(event, false);
                            break;
                        }
                    }
                }
                // Disable music and volume control when used as wake key
                if ((result & ACTION_PASS_TO_USER) == 0 && !mVolumeWakeScreen) {
                    boolean mayChangeVolume = false;
                    if (isMusicActive()) {
                        if (mVolBtnMusicControls && (keyCode != KeyEvent.KEYCODE_VOLUME_MUTE)) {
                            // Detect long key presses.
                            if (down) {
                                mIsLongPress = false;
                                // TODO: Long press of MUTE could be mapped to KEYCODE_MEDIA_PLAY_PAUSE
                                int newKeyCode = event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP ? KeyEvent.KEYCODE_MEDIA_NEXT : KeyEvent.KEYCODE_MEDIA_PREVIOUS;
                                scheduleLongPressKeyEvent(event, newKeyCode);
                                // Consume key down events of all presses.
                                break;
                            } else {
                                mHandler.removeMessages(MSG_DISPATCH_VOLKEY_WITH_WAKE_LOCK);
                                // Consume key up events of long presses only.
                                if (mIsLongPress) {
                                    break;
                                }
                                // Change volume only on key up events of short presses.
                                mayChangeVolume = true;
                            }
                        } else {
                            // Long key press detection not applicable, change volume only
                            // on key down events
                            mayChangeVolume = down;
                        }
                    }
                    if (mayChangeVolume) {
                        if (mUseTvRouting) {
                            dispatchDirectAudioEvent(event);
                        } else {
                            // If we aren't passing to the user and no one else
                            // handled it send it to the session manager to figure
                            // out.
                            // Rewrite the event to use key-down as sendVolumeKeyEvent will
                            // only change the volume on key down.
                            KeyEvent newEvent = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
                            MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent(newEvent, true);
                        }
                    }
                    break;
                }
                break;
            }
        case KeyEvent.KEYCODE_HOME:
            if (down && !interactive && mHomeWakeScreen) {
                isWakeKey = true;
            }
            break;
        case KeyEvent.KEYCODE_FOCUS:
            if (down && !interactive && mCameraSleepOnRelease) {
                mIsFocusPressed = true;
            } else if ((event.getAction() == KeyEvent.ACTION_UP) && mScreenOnFully && mIsFocusPressed) {
                // Check if screen is fully on before letting the device go to sleep
                mPowerManager.goToSleep(SystemClock.uptimeMillis());
                mIsFocusPressed = false;
            }
            break;
        case KeyEvent.KEYCODE_CAMERA:
            if (down && mIsFocusPressed) {
                mIsFocusPressed = false;
            }
            if (down) {
                mIsLongPress = false;
                scheduleLongPressKeyEvent(event, KeyEvent.KEYCODE_CAMERA);
                // Consume key down events of all presses.
                break;
            } else {
                mHandler.removeMessages(MSG_CAMERA_LONG_PRESS);
                // Consume key up events of long presses only.
                if (mIsLongPress && mCameraLaunch) {
                    Intent intent;
                    if (keyguardActive) {
                        intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
                    } else {
                        intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
                    }
                    isWakeKey = true;
                    startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
                }
            }
            break;
        case KeyEvent.KEYCODE_ENDCALL:
            {
                result &= ~ACTION_PASS_TO_USER;
                if (down) {
                    TelecomManager telecomManager = getTelecommService();
                    boolean hungUp = false;
                    if (telecomManager != null) {
                        hungUp = telecomManager.endCall();
                    }
                    if (interactive && !hungUp) {
                        mEndCallKeyHandled = false;
                        mHandler.postDelayed(mEndCallLongPress, ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
                    } else {
                        mEndCallKeyHandled = true;
                    }
                } else {
                    if (!mEndCallKeyHandled) {
                        mHandler.removeCallbacks(mEndCallLongPress);
                        if (!canceled) {
                            if ((mEndcallBehavior & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
                                if (goHome()) {
                                    break;
                                }
                            }
                            if ((mEndcallBehavior & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
                                mPowerManager.goToSleep(event.getEventTime(), PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
                                isWakeKey = false;
                            }
                        }
                    }
                }
                break;
            }
        case KeyEvent.KEYCODE_POWER:
            {
                if (mTopFullscreenOpaqueWindowState != null && (mTopFullscreenOpaqueWindowState.getAttrs().privateFlags & WindowManager.LayoutParams.PRIVATE_FLAG_PREVENT_POWER_KEY) != 0 && mScreenOnFully) {
                    return result;
                }
                result &= ~ACTION_PASS_TO_USER;
                // wake-up will be handled separately
                isWakeKey = false;
                if (down) {
                    interceptPowerKeyDown(event, interactive);
                } else {
                    interceptPowerKeyUp(event, interactive, canceled);
                }
                break;
            }
        case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_DOWN:
        // fall through
        case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_UP:
        // fall through
        case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_LEFT:
        // fall through
        case KeyEvent.KEYCODE_SYSTEM_NAVIGATION_RIGHT:
            {
                result &= ~ACTION_PASS_TO_USER;
                interceptSystemNavigationKey(event);
                break;
            }
        case KeyEvent.KEYCODE_SLEEP:
            {
                result &= ~ACTION_PASS_TO_USER;
                isWakeKey = false;
                if (!mPowerManager.isInteractive()) {
                    // suppress feedback if already non-interactive
                    useHapticFeedback = false;
                }
                if (down) {
                    sleepPress(event.getEventTime());
                } else {
                    sleepRelease(event.getEventTime());
                }
                break;
            }
        case KeyEvent.KEYCODE_SOFT_SLEEP:
            {
                result &= ~ACTION_PASS_TO_USER;
                isWakeKey = false;
                if (!down) {
                    mPowerManagerInternal.setUserInactiveOverrideFromWindowManager();
                }
                break;
            }
        case KeyEvent.KEYCODE_WAKEUP:
            {
                result &= ~ACTION_PASS_TO_USER;
                isWakeKey = true;
                break;
            }
        case KeyEvent.KEYCODE_MEDIA_PLAY:
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
        case KeyEvent.KEYCODE_HEADSETHOOK:
        case KeyEvent.KEYCODE_MUTE:
        case KeyEvent.KEYCODE_MEDIA_STOP:
        case KeyEvent.KEYCODE_MEDIA_NEXT:
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
        case KeyEvent.KEYCODE_MEDIA_REWIND:
        case KeyEvent.KEYCODE_MEDIA_RECORD:
        case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
        case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
            {
                if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
                    // If the global session is active pass all media keys to it
                    // instead of the active window.
                    result &= ~ACTION_PASS_TO_USER;
                }
                if ((result & ACTION_PASS_TO_USER) == 0) {
                    // Only do this if we would otherwise not pass it to the user. In that
                    // case, the PhoneWindow class will do the same thing, except it will
                    // only do it if the showing app doesn't process the key on its own.
                    // Note that we need to make a copy of the key event here because the
                    // original key event will be recycled when we return.
                    mBroadcastWakeLock.acquire();
                    Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK, new KeyEvent(event));
                    msg.setAsynchronous(true);
                    msg.sendToTarget();
                }
                break;
            }
        case KeyEvent.KEYCODE_CALL:
            {
                if (down) {
                    TelecomManager telecomManager = getTelecommService();
                    if (telecomManager != null) {
                        if (telecomManager.isRinging()) {
                            Log.i(TAG, "interceptKeyBeforeQueueing:" + " CALL key-down while ringing: Answer the call!");
                            telecomManager.acceptRingingCall();
                            // And *don't* pass this key thru to the current activity
                            // (which is presumably the InCallScreen.)
                            result &= ~ACTION_PASS_TO_USER;
                        }
                    }
                }
                break;
            }
        case KeyEvent.KEYCODE_VOICE_ASSIST:
            {
                // key event here because the original key event will be recycled when we return.
                if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
                    mBroadcastWakeLock.acquire();
                    Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK, keyguardActive ? 1 : 0, 0);
                    msg.setAsynchronous(true);
                    msg.sendToTarget();
                }
                break;
            }
        case KeyEvent.KEYCODE_WINDOW:
            {
                if (mShortPressWindowBehavior == SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE) {
                    if (mTvPictureInPictureVisible) {
                        // to customize PIP key behavior.
                        if (!down) {
                            showTvPictureInPictureMenu(event);
                        }
                        result &= ~ACTION_PASS_TO_USER;
                    }
                }
                break;
            }
    }
    if (useHapticFeedback) {
        performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
    }
    if (isWakeKey) {
        wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY", // Check prox only on wake key
        event.getKeyCode() == KeyEvent.KEYCODE_WAKEUP);
    }
    return result;
}
Also used : KeyEvent(android.view.KeyEvent) Message(android.os.Message) Intent(android.content.Intent) RecognizerIntent(android.speech.RecognizerIntent) TelecomManager(android.telecom.TelecomManager)

Example 60 with TelecomManager

use of android.telecom.TelecomManager in project android_frameworks_base by ResurrectionRemix.

the class PhoneWindowManager method interceptPowerKeyDown.

private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
    // Hold a wake lock until the power key is released.
    if (!mPowerKeyWakeLock.isHeld()) {
        mPowerKeyWakeLock.acquire();
    }
    // Cancel multi-press detection timeout.
    if (mPowerKeyPressCounter != 0) {
        mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
    }
    // Detect user pressing the power button in panic when an application has
    // taken over the whole screen.
    boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive, SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags), isNavBarEmpty(mLastSystemUiFlags));
    if (panic) {
        mHandler.post(mHiddenNavPanic);
    }
    // Latch power key state to detect screenshot chord.
    if (interactive && !mPowerKeyTriggered && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
        mPowerKeyTriggered = true;
        mPowerKeyTime = event.getDownTime();
        checkSettings();
        interceptScreenshotChord();
        interceptScreenrecordChord();
    }
    // Stop ringing or end call if configured to do so when power is pressed.
    TelecomManager telecomManager = getTelecommService();
    boolean hungUp = false;
    if (telecomManager != null) {
        if (telecomManager.isRinging()) {
            // Pressing Power while there's a ringing incoming
            // call should silence the ringer.
            telecomManager.silenceRinger();
        } else if ((mIncallPowerBehavior & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 && telecomManager.isInCall() && interactive) {
            // Otherwise, if "Power button ends call" is enabled,
            // the Power button will hang up any current active call.
            hungUp = telecomManager.endCall();
        }
    }
    GestureLauncherService gestureService = LocalServices.getService(GestureLauncherService.class);
    boolean gesturedServiceIntercepted = false;
    if (gestureService != null) {
        gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive, mTmpBoolean);
        if (mTmpBoolean.value && mGoingToSleep) {
            mCameraGestureTriggeredDuringGoingToSleep = true;
        }
    }
    // If the power key has still not yet been handled, then detect short
    // press, long press, or multi press and decide what to do.
    mPowerKeyHandled = hungUp || mVolumeDownKeyTriggered || gesturedServiceIntercepted || mVolumeUpKeyTriggered;
    if (!mPowerKeyHandled) {
        if (interactive) {
            // Wait for a long press or for the button to be released to decide what to do.
            if (hasLongPressOnPowerBehavior()) {
                Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
                msg.setAsynchronous(true);
                mHandler.sendMessageDelayed(msg, ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
            }
        } else {
            if (!mTorchEnabled) {
                wakeUpFromPowerKey(event.getDownTime());
            }
            if (mTorchEnabled && mIsTorchActive) {
                try {
                    mCameraManager.setTorchMode(getCameraId(), false);
                } catch (Exception e) {
                    mWasTorchActive = false;
                }
                mIsTorchActive = false;
                mWasTorchActive = true;
            } else if (mTorchEnabled || (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior())) {
                Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
                msg.setAsynchronous(true);
                mHandler.sendMessageDelayed(msg, ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
                mBeganFromNonInteractive = true;
            } else {
                final int maxCount = getMaxMultiPressPowerCount();
                if (maxCount <= 1) {
                    mPowerKeyHandled = true;
                } else {
                    mBeganFromNonInteractive = true;
                }
            }
        }
    }
}
Also used : Message(android.os.Message) TelecomManager(android.telecom.TelecomManager) GestureLauncherService(com.android.server.GestureLauncherService) RemoteException(android.os.RemoteException) IOException(java.io.IOException) ActivityNotFoundException(android.content.ActivityNotFoundException) CameraAccessException(android.hardware.camera2.CameraAccessException)

Aggregations

TelecomManager (android.telecom.TelecomManager)86 PhoneAccountHandle (android.telecom.PhoneAccountHandle)45 PhoneAccount (android.telecom.PhoneAccount)30 TelephonyManager (android.telephony.TelephonyManager)17 SubscriptionInfo (android.telephony.SubscriptionInfo)11 KeyEvent (android.view.KeyEvent)9 ArrayList (java.util.ArrayList)9 AlertDialog (android.app.AlertDialog)8 ActivityNotFoundException (android.content.ActivityNotFoundException)8 DialogInterface (android.content.DialogInterface)8 Message (android.os.Message)8 SubscriptionManager (android.telephony.SubscriptionManager)8 Dialog (android.app.Dialog)7 ListAdapter (android.widget.ListAdapter)7 Intent (android.content.Intent)6 Preference (android.support.v7.preference.Preference)6 ComponentName (android.content.ComponentName)4 PackageManagerInternal (android.content.pm.PackageManagerInternal)4 RemoteException (android.os.RemoteException)4 IntArray (android.util.IntArray)4