use of android.telecom.TelecomManager in project android_frameworks_base by ResurrectionRemix.
the class KeyguardBottomAreaView method launchPhone.
private void launchPhone() {
final TelecomManager tm = TelecomManager.from(mContext);
if (tm.isInCall()) {
AsyncTask.execute(new Runnable() {
@Override
public void run() {
tm.showInCallScreen(false);
}
});
} else {
mActivityStarter.startActivity(PHONE_INTENT, false);
updateCameraIconColor();
updatePhoneIconColor();
updateLockIconColor();
updateIndicationTextColor();
}
}
use of android.telecom.TelecomManager in project android_frameworks_base by ResurrectionRemix.
the class AudioService method isInCommunication.
private boolean isInCommunication() {
boolean IsInCall = false;
TelecomManager telecomManager = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
final long ident = Binder.clearCallingIdentity();
IsInCall = telecomManager.isInCall();
Binder.restoreCallingIdentity(ident);
return (IsInCall || getMode() == AudioManager.MODE_IN_COMMUNICATION);
}
use of android.telecom.TelecomManager in project android_frameworks_base by ResurrectionRemix.
the class HardkeyActionHandler method handleKeyEvent.
public boolean handleKeyEvent(WindowState win, int keyCode, int repeatCount, boolean down, boolean canceled, boolean longPress, boolean keyguardOn) {
if (filterDisabledKey(keyCode)) {
return true;
}
if (keyCode == KeyEvent.KEYCODE_HOME) {
if (!down && mHomeButton.isPressed()) {
mHomeButton.setPressed(false);
if (mHomeButton.wasConsumed()) {
mHomeButton.setWasConsumed(false);
return true;
}
if (!mHomeButton.keyHasDoubleTapRecents()) {
ActionHandler.cancelPreloadRecentApps();
}
if (canceled) {
return true;
}
/*
// If an incoming call is ringing, HOME is totally disabled.
// (The user is already on the InCallUI at this point,
// and his ONLY options are to answer or reject the call.)
TelecomManager telecomManager = getTelecommService();
if (telecomManager != null && telecomManager.isRinging()) {
if ((mRingHomeBehavior
& Settings.Secure.RING_HOME_BUTTON_BEHAVIOR_ANSWER) != 0) {
Log.i(TAG, "Answering with HOME button.");
telecomManager.acceptRingingCall();
return true;
} else {
Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
return true;
}
}
*/
// If an incoming call is ringing, HOME is totally disabled.
// (The user is already on the InCallUI at this point,
// and his ONLY options are to answer or reject the call.)
TelecomManager telecomManager = getTelecommService();
if (telecomManager != null && telecomManager.isRinging()) {
Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
return true;
}
if (mHomeButton.isDoubleTapEnabled()) {
mHomeButton.cancelDTTimeout();
mHomeButton.setDoubleTapPending(true);
mHomeButton.postDTTimeout();
return true;
}
mHomeButton.fireSingleTap();
return true;
}
// If a system window has focus, then it doesn't make sense
// right now to interact with applications.
//
// NOTE: I don't think this code block is reachable here anyways because
// we don't intercept any key events if keyguard is showing
// However, "WINDOW_TYPES_WHERE_HOME_DOESNT_WORK" is reachable
//
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) {
// thing we just did.
return false;
}
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 true;
}
}
}
if (!down) {
return true;
}
if (repeatCount == 0) {
mHomeButton.setPressed(true);
fireBooster(mHomeButton);
if (mHomeButton.isDoubleTapPending()) {
mHomeButton.setDoubleTapPending(false);
mHomeButton.cancelDTTimeout();
mHomeButton.fireDoubleTap();
mHomeButton.setWasConsumed(true);
} else if (mHomeButton.keyHasLongPressRecents() || mHomeButton.keyHasDoubleTapRecents()) {
ActionHandler.preloadRecentApps();
}
} else if (longPress) {
if (!keyguardOn && !mHomeButton.wasConsumed() && mHomeButton.isLongTapEnabled()) {
mHomeButton.setPressed(true);
if (!mHomeButton.keyHasLongPressRecents()) {
ActionHandler.cancelPreloadRecentApps();
}
mHandler.sendEmptyMessage(MSG_DO_HAPTIC_FB);
mHomeButton.fireLongPress();
mHomeButton.setWasConsumed(true);
}
}
return true;
} else if (keyCode == KeyEvent.KEYCODE_MENU) {
if (!down && mMenuButton.isPressed()) {
mMenuButton.setPressed(false);
if (mMenuButton.wasConsumed()) {
mMenuButton.setWasConsumed(false);
return true;
}
if (!mMenuButton.keyHasDoubleTapRecents()) {
ActionHandler.cancelPreloadRecentApps();
}
if (canceled || keyguardOn) {
return true;
}
if (mMenuButton.isDoubleTapEnabled()) {
mMenuButton.setDoubleTapPending(true);
mMenuButton.cancelDTTimeout();
mMenuButton.postDTTimeout();
return true;
}
if (!mMenuButton.keyHasSingleTapRecent()) {
ActionHandler.cancelPreloadRecentApps();
}
mMenuButton.fireSingleTap();
return true;
}
if (!down) {
return true;
}
if (repeatCount == 0) {
mMenuButton.setPressed(true);
fireBooster(mMenuButton);
if (mMenuButton.isDoubleTapPending()) {
mMenuButton.setDoubleTapPending(false);
mMenuButton.cancelDTTimeout();
mMenuButton.fireDoubleTap();
mMenuButton.setWasConsumed(true);
} else if (mMenuButton.keyHasLongPressRecents() || mMenuButton.keyHasDoubleTapRecents() || mMenuButton.keyHasSingleTapRecent()) {
ActionHandler.preloadRecentApps();
}
} else if (longPress) {
if (!keyguardOn && !mMenuButton.wasConsumed() && mMenuButton.isLongTapEnabled()) {
mMenuButton.setPressed(true);
if (!mMenuButton.keyHasLongPressRecents()) {
ActionHandler.cancelPreloadRecentApps();
}
mHandler.sendEmptyMessage(MSG_DO_HAPTIC_FB);
mMenuButton.fireLongPress();
mMenuButton.setWasConsumed(true);
}
}
return true;
} else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
if (!down && mRecentButton.isPressed()) {
mRecentButton.setPressed(false);
if (mRecentButton.wasConsumed()) {
mRecentButton.setWasConsumed(false);
return true;
}
if (!mRecentButton.keyHasDoubleTapRecents()) {
ActionHandler.cancelPreloadRecentApps();
}
if (canceled || keyguardOn) {
return true;
}
if (mRecentButton.isDoubleTapEnabled()) {
mRecentButton.setDoubleTapPending(true);
mRecentButton.cancelDTTimeout();
mRecentButton.postDTTimeout();
return true;
}
if (!mRecentButton.keyHasSingleTapRecent()) {
ActionHandler.cancelPreloadRecentApps();
}
mRecentButton.fireSingleTap();
return true;
}
if (!down) {
return true;
}
if (repeatCount == 0) {
mRecentButton.setPressed(true);
fireBooster(mRecentButton);
if (mRecentButton.isDoubleTapPending()) {
mRecentButton.setDoubleTapPending(false);
mRecentButton.cancelDTTimeout();
mRecentButton.fireDoubleTap();
mRecentButton.setWasConsumed(true);
} else if (mRecentButton.keyHasLongPressRecents() || mRecentButton.keyHasDoubleTapRecents() || mRecentButton.keyHasSingleTapRecent()) {
ActionHandler.preloadRecentApps();
}
} else if (longPress) {
if (!keyguardOn && !mRecentButton.wasConsumed() && mRecentButton.isLongTapEnabled()) {
mRecentButton.setPressed(true);
if (!mRecentButton.keyHasLongPressRecents()) {
ActionHandler.cancelPreloadRecentApps();
}
mHandler.sendEmptyMessage(MSG_DO_HAPTIC_FB);
mRecentButton.fireLongPress();
mRecentButton.setWasConsumed(true);
}
}
return true;
} else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
if (!down && mAssistButton.isPressed()) {
mAssistButton.setPressed(false);
if (mAssistButton.wasConsumed()) {
mAssistButton.setWasConsumed(false);
return true;
}
if (!mAssistButton.keyHasDoubleTapRecents()) {
ActionHandler.cancelPreloadRecentApps();
}
if (canceled || keyguardOn) {
return true;
}
if (mAssistButton.isDoubleTapEnabled()) {
mAssistButton.setDoubleTapPending(true);
mAssistButton.cancelDTTimeout();
mAssistButton.postDTTimeout();
return true;
}
if (!mAssistButton.keyHasSingleTapRecent()) {
ActionHandler.cancelPreloadRecentApps();
}
mAssistButton.fireSingleTap();
return true;
}
if (!down) {
return true;
}
if (repeatCount == 0) {
mAssistButton.setPressed(true);
fireBooster(mAssistButton);
if (mAssistButton.isDoubleTapPending()) {
mAssistButton.setDoubleTapPending(false);
mAssistButton.cancelDTTimeout();
mAssistButton.fireDoubleTap();
mAssistButton.setWasConsumed(true);
} else if (mAssistButton.keyHasLongPressRecents() || mAssistButton.keyHasDoubleTapRecents() || mAssistButton.keyHasSingleTapRecent()) {
ActionHandler.preloadRecentApps();
}
} else if (longPress) {
if (!keyguardOn && !mAssistButton.wasConsumed() && mAssistButton.isLongTapEnabled()) {
mAssistButton.setPressed(true);
if (!mAssistButton.keyHasLongPressRecents()) {
ActionHandler.cancelPreloadRecentApps();
}
mHandler.sendEmptyMessage(MSG_DO_HAPTIC_FB);
mAssistButton.fireLongPress();
mAssistButton.setWasConsumed(true);
}
}
return true;
} else if (keyCode == KeyEvent.KEYCODE_BACK) {
if (!down && mBackButton.isPressed()) {
mBackButton.setPressed(false);
if (mBackButton.wasConsumed()) {
mBackButton.setWasConsumed(false);
return true;
}
if (!mBackButton.keyHasDoubleTapRecents()) {
ActionHandler.cancelPreloadRecentApps();
}
if (canceled || keyguardOn) {
return true;
}
if (mBackButton.isDoubleTapEnabled()) {
mBackButton.setDoubleTapPending(true);
mBackButton.cancelDTTimeout();
mBackButton.postDTTimeout();
return true;
}
mBackButton.fireSingleTap();
return true;
}
if (!down) {
return true;
}
if (repeatCount == 0) {
mBackButton.setPressed(true);
fireBooster(mBackButton);
if (mBackButton.isDoubleTapPending()) {
mBackButton.setDoubleTapPending(false);
mBackButton.cancelDTTimeout();
mBackButton.fireDoubleTap();
mBackButton.setWasConsumed(true);
} else if (mBackButton.keyHasLongPressRecents() || mBackButton.keyHasDoubleTapRecents()) {
ActionHandler.preloadRecentApps();
}
} else if (longPress) {
if (!keyguardOn && !mBackButton.wasConsumed()) {
mBackButton.setPressed(true);
if (ActionHandler.isLockTaskOn()) {
ActionHandler.turnOffLockTask();
mHandler.sendEmptyMessage(MSG_DO_HAPTIC_FB);
mBackButton.setWasConsumed(true);
} else {
if (mBackButton.isLongTapEnabled()) {
if (!mBackButton.keyHasLongPressRecents()) {
ActionHandler.cancelPreloadRecentApps();
}
mBackButton.fireLongPress();
mHandler.sendEmptyMessage(MSG_DO_HAPTIC_FB);
mBackButton.setWasConsumed(true);
}
}
}
}
return true;
}
return false;
}
use of android.telecom.TelecomManager in project android_frameworks_base by ResurrectionRemix.
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;
final int scanCode = event.getScanCode();
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;
}
if (keyCode == KeyEvent.KEYCODE_BACK && !down) {
mHandler.removeCallbacks(mBackLongPress);
}
// timeout.
if (keyCode == KeyEvent.KEYCODE_HOME) {
// while it was pressed, then it is time to go home!
if (!down) {
if (mDoubleTapOnHomeBehavior != KEY_ACTION_APP_SWITCH) {
cancelPreloadRecentApps();
}
mHomePressed = false;
if (mHomeConsumed) {
mHomeConsumed = false;
return -1;
}
if (canceled) {
Log.i(TAG, "Ignoring HOME; event canceled.");
return -1;
}
if ((mRingHomeBehavior & CMSettings.Secure.RING_HOME_BUTTON_BEHAVIOR_ANSWER) != 0) {
final TelecomManager telecomManager = getTelecommService();
if (telecomManager != null && telecomManager.isRinging()) {
telecomManager.acceptRingingCall();
return -1;
}
}
// Delay handling home if a double-tap is possible.
if (mDoubleTapOnHomeBehavior != KEY_ACTION_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);
performKeyAction(mDoubleTapOnHomeBehavior, event);
if (mDoubleTapOnHomeBehavior != KEY_ACTION_SLEEP) {
mHomeConsumed = true;
}
} else if (mLongPressOnHomeBehavior == KEY_ACTION_APP_SWITCH || mDoubleTapOnHomeBehavior == KEY_ACTION_APP_SWITCH) {
preloadRecentApps();
}
} else if (longPress) {
if (!keyguardOn && !mHomeConsumed && mLongPressOnHomeBehavior != KEY_ACTION_NOTHING) {
if (mLongPressOnHomeBehavior != KEY_ACTION_APP_SWITCH) {
cancelPreloadRecentApps();
}
mHomePressed = true;
performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
performKeyAction(mLongPressOnHomeBehavior, event);
if (mLongPressOnHomeBehavior != KEY_ACTION_SLEEP) {
mHomeConsumed = true;
}
}
}
return -1;
} else if (keyCode == KeyEvent.KEYCODE_MENU) {
// Hijack modified menu keys for debugging features
final int chordBug = KeyEvent.META_SHIFT_ON;
if (virtualKey || keyguardOn) {
// Let the app handle the key
return 0;
}
if (down) {
if (mPressOnMenuBehavior == KEY_ACTION_APP_SWITCH || mLongPressOnMenuBehavior == KEY_ACTION_APP_SWITCH) {
preloadRecentApps();
}
if (repeatCount == 0) {
mMenuPressed = true;
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 (longPress) {
if (!keyguardOn && mLongPressOnMenuBehavior != KEY_ACTION_NOTHING) {
if (mLongPressOnMenuBehavior != KEY_ACTION_APP_SWITCH) {
cancelPreloadRecentApps();
}
performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
performKeyAction(mLongPressOnMenuBehavior, event);
mMenuPressed = false;
return -1;
}
}
}
if (!down && mMenuPressed) {
if (mPressOnMenuBehavior != KEY_ACTION_APP_SWITCH) {
cancelPreloadRecentApps();
}
mMenuPressed = false;
if (!canceled) {
performKeyAction(mPressOnMenuBehavior, event);
}
}
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) {
if (mPressOnAppSwitchBehavior == KEY_ACTION_APP_SWITCH || mLongPressOnAppSwitchBehavior == KEY_ACTION_APP_SWITCH) {
preloadRecentApps();
}
if (repeatCount == 0) {
mAppSwitchLongPressed = false;
} else if (longPress) {
if (!keyguardOn && mLongPressOnAppSwitchBehavior != KEY_ACTION_NOTHING) {
if (mLongPressOnAppSwitchBehavior != KEY_ACTION_APP_SWITCH) {
cancelPreloadRecentApps();
}
performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
performKeyAction(mLongPressOnAppSwitchBehavior, event);
mAppSwitchLongPressed = true;
}
}
} else {
if (mAppSwitchLongPressed) {
mAppSwitchLongPressed = false;
} else {
if (mPressOnAppSwitchBehavior != KEY_ACTION_APP_SWITCH) {
cancelPreloadRecentApps();
}
if (!canceled) {
performKeyAction(mPressOnAppSwitchBehavior, event);
}
}
}
}
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 (mPressOnAssistBehavior == KEY_ACTION_APP_SWITCH || mLongPressOnAssistBehavior == KEY_ACTION_APP_SWITCH) {
preloadRecentApps();
}
if (repeatCount == 0) {
mAssistKeyLongPressed = false;
} else if (longPress) {
if (!keyguardOn && mLongPressOnAssistBehavior != KEY_ACTION_NOTHING) {
if (mLongPressOnAssistBehavior != KEY_ACTION_APP_SWITCH) {
cancelPreloadRecentApps();
}
performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
performKeyAction(mLongPressOnAssistBehavior, event);
mAssistKeyLongPressed = true;
}
}
} else {
if (mAssistKeyLongPressed) {
mAssistKeyLongPressed = false;
} else {
if (mPressOnAssistBehavior != KEY_ACTION_APP_SWITCH) {
cancelPreloadRecentApps();
}
if (!canceled) {
performKeyAction(mPressOnAssistBehavior, event);
}
}
}
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_BACK) {
// Disable back key if navbar hw keys is set to off
if (scanCode != 0 && isHwKeysDisabled() && !mContext.getResources().getBoolean(com.android.internal.R.bool.config_hwKeysBackAlwaysOn)) {
Log.i(TAG, "Ignoring Back Key: we have hw keys disabled");
return 0;
}
if (Settings.Secure.getIntForUser(mContext.getContentResolver(), Settings.Secure.KILL_APP_LONGPRESS_BACK, 0, UserHandle.USER_CURRENT) == 1) {
if (down && repeatCount == 0) {
mHandler.postDelayed(mBackLongPress, mBackKillTimeout);
}
}
} 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;
} else if (keyCode == KeyEvent.KEYCODE_BACK) {
if (unpinActivity(true) || CMSettings.Secure.getInt(mContext.getContentResolver(), CMSettings.Secure.KILL_APP_LONGPRESS_BACK, 0) == 1) {
if (down && repeatCount == 0) {
mHandler.postDelayed(mBackLongPress, mBackKillTimeout);
}
}
}
// 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 (dispatchKeyToKeyHandlers(event)) {
return -1;
}
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;
}
use of android.telecom.TelecomManager in project android_frameworks_base by ResurrectionRemix.
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);
}
}
Aggregations