Search in sources :

Example 46 with TelecomManager

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

the class SimDialogActivity method setDefaultCallsSubId.

private void setDefaultCallsSubId(final int subId) {
    final PhoneAccountHandle phoneAccount = subscriptionIdToPhoneAccountHandle(subId);
    final TelecomManager telecomManager = getSystemService(TelecomManager.class);
    telecomManager.setUserSelectedOutgoingPhoneAccount(phoneAccount);
}
Also used : PhoneAccountHandle(android.telecom.PhoneAccountHandle) TelecomManager(android.telecom.TelecomManager)

Example 47 with TelecomManager

use of android.telecom.TelecomManager in project platform_frameworks_base by android.

the class ActivityManagerService method stopLockTaskMode.

@Override
public void stopLockTaskMode() {
    final TaskRecord lockTask = mStackSupervisor.getLockedTaskLocked();
    if (lockTask == null) {
        // Our work here is done.
        return;
    }
    final int callingUid = Binder.getCallingUid();
    final int lockTaskUid = lockTask.mLockTaskUid;
    final int lockTaskModeState = mStackSupervisor.getLockTaskModeState();
    if (lockTaskModeState == ActivityManager.LOCK_TASK_MODE_NONE) {
        // Done.
        return;
    } else {
        // {@link MANAGE_ACTIVITY_STACKS} can stop any lock task.
        if (checkCallingPermission(MANAGE_ACTIVITY_STACKS) != PERMISSION_GRANTED && callingUid != lockTaskUid && (lockTaskUid != 0 || callingUid != lockTask.effectiveUid)) {
            throw new SecurityException("Invalid uid, expected " + lockTaskUid + " callingUid=" + callingUid + " effectiveUid=" + lockTask.effectiveUid);
        }
    }
    long ident = Binder.clearCallingIdentity();
    try {
        Log.d(TAG, "stopLockTaskMode");
        // Stop lock task
        synchronized (this) {
            mStackSupervisor.setLockTaskModeLocked(null, ActivityManager.LOCK_TASK_MODE_NONE, "stopLockTask", true);
        }
        TelecomManager tm = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
        if (tm != null) {
            tm.showInCallScreen(false);
        }
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
Also used : Point(android.graphics.Point) TelecomManager(android.telecom.TelecomManager)

Example 48 with TelecomManager

use of android.telecom.TelecomManager in project platform_frameworks_base by android.

the class TelecomLoaderService method updateSimCallManagerPermissions.

private void updateSimCallManagerPermissions(PackageManagerInternal packageManagerInternal, int userId) {
    TelecomManager telecomManager = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
    PhoneAccountHandle phoneAccount = telecomManager.getSimCallManager(userId);
    if (phoneAccount != null) {
        Slog.i(TAG, "updating sim call manager permissions for userId:" + userId);
        String packageName = phoneAccount.getComponentName().getPackageName();
        packageManagerInternal.grantDefaultPermissionsToDefaultSimCallManager(packageName, userId);
    }
}
Also used : PhoneAccountHandle(android.telecom.PhoneAccountHandle) TelecomManager(android.telecom.TelecomManager)

Example 49 with TelecomManager

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

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)

Example 50 with TelecomManager

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

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 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()));
    if (DEBUG_INPUT) {
        Log.d(TAG, "interceptKeyTq keycode=" + keyCode + " interactive=" + interactive + " keyguardActive=" + keyguardActive + " policyFlags=" + Integer.toHexString(policyFlags));
    }
    // Basic policy based on interactive state.
    final boolean isVolumeRockerWake = !isScreenOn() && mVolumeRockerWake && (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN);
    int result;
    boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0 || event.isWakeKey() || isVolumeRockerWake;
    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.
        result = ACTION_PASS_TO_USER;
        // 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 (mDeviceKeyHandler != null) {
        try {
            // The device only should consume known keys.
            if (mDeviceKeyHandler.handleKeyEvent(event)) {
                return 0;
            }
        } catch (Exception e) {
            Slog.w(TAG, "Could not dispatch event to device key handler", e);
        }
    }
    // 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:
            {
                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 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 && !mVolumeRockerWake) {
                    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 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_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:
            {
                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) RemoteException(android.os.RemoteException) IOException(java.io.IOException) ActivityNotFoundException(android.content.ActivityNotFoundException) CameraAccessException(android.hardware.camera2.CameraAccessException) TelecomManager(android.telecom.TelecomManager)

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