Search in sources :

Example 6 with TelecomManager

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

the class SimDialogActivity method setUserSelectedOutgoingPhoneAccount.

private void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle phoneAccount) {
    final TelecomManager telecomManager = TelecomManager.from(this);
    telecomManager.setUserSelectedOutgoingPhoneAccount(phoneAccount);
}
Also used : TelecomManager(android.telecom.TelecomManager)

Example 7 with TelecomManager

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

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;
}
Also used : TelecomManager(android.telecom.TelecomManager) WindowManager(android.view.WindowManager)

Example 8 with TelecomManager

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

the class AudioService method startMusicPlayer.

private void startMusicPlayer() {
    TelecomManager tm = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
    if (!tm.isInCall()) {
        try {
            Intent playerIntent = new Intent(Intent.ACTION_MAIN);
            playerIntent.addCategory(Intent.CATEGORY_APP_MUSIC);
            playerIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mContext.startActivity(playerIntent);
        } catch (ActivityNotFoundException | IllegalArgumentException e) {
            Log.w(TAG, "No music player Activity could be found");
        }
    }
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) Intent(android.content.Intent) TelecomManager(android.telecom.TelecomManager)

Example 9 with TelecomManager

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

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);
}
Also used : TelecomManager(android.telecom.TelecomManager)

Example 10 with TelecomManager

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

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)

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