Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ad75c435 authored by yifan.bai's avatar yifan.bai Committed by android-build-merger
Browse files

Fix headset media button long press cannot reject call. am: fbafd903 am: 6de5288f

am: 14da17ff

Change-Id: I33b2cfbeb35ff0f932b46df33a1fb3f97434a92d
parents e18e90d8 14da17ff
Loading
Loading
Loading
Loading
+18 −10
Original line number Diff line number Diff line
@@ -1511,24 +1511,32 @@ public class CallsManager extends Call.ListenerBase

    boolean onMediaButton(int type) {
        if (hasAnyCalls()) {
            if (HeadsetMediaButton.SHORT_PRESS == type) {
            Call ringingCall = getFirstCallWithState(CallState.RINGING);
            if (HeadsetMediaButton.SHORT_PRESS == type) {
                if (ringingCall == null) {
                    mCallAudioManager.toggleMute();
                    Call callToHangup = getFirstCallWithState(CallState.RINGING, CallState.DIALING,
                            CallState.PULLING, CallState.ACTIVE, CallState.ON_HOLD);
                    Log.addEvent(callToHangup, LogUtils.Events.INFO,
                            "media btn short press - end call.");
                    if (callToHangup != null) {
                        callToHangup.disconnect();
                        return true;
                    }
                } else {
                    ringingCall.answer(VideoProfile.STATE_AUDIO_ONLY);
                    return true;
                }
            } else if (HeadsetMediaButton.LONG_PRESS == type) {
                Log.d(this, "handleHeadsetHook: longpress -> hangup");
                Call callToHangup = getFirstCallWithState(
                        CallState.RINGING, CallState.DIALING, CallState.PULLING, CallState.ACTIVE,
                        CallState.ON_HOLD);
                if (callToHangup != null) {
                    callToHangup.disconnect();
                    return true;
                if (ringingCall != null) {
                    Log.addEvent( getForegroundCall(), LogUtils.Events.INFO,
                            "media btn long press - reject");
                    ringingCall.reject(false, null);
                } else {
                    Log.addEvent(getForegroundCall(), LogUtils.Events.INFO,
                            "media btn long press - mute");
                    mCallAudioManager.toggleMute();
                }
                return true;
            }
        }
        return false;
+17 −2
Original line number Diff line number Diff line
@@ -93,6 +93,7 @@ public class HeadsetMediaButton extends CallsManagerListenerBase {
    private final CallsManager mCallsManager;
    private final TelecomSystem.SyncRoot mLock;
    private MediaSession mSession;
    private KeyEvent mLastHookEvent;

    public HeadsetMediaButton(
            Context context,
@@ -115,11 +116,25 @@ public class HeadsetMediaButton extends CallsManagerListenerBase {
    private boolean handleHeadsetHook(KeyEvent event) {
        Log.d(this, "handleHeadsetHook()...%s %s", event.getAction(), event.getRepeatCount());

        // Save ACTION_DOWN Event temporarily.
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            mLastHookEvent = event;
        }

        if (event.isLongPress()) {
            return mCallsManager.onMediaButton(LONG_PRESS);
        } else if (event.getAction() == KeyEvent.ACTION_UP && event.getRepeatCount() == 0) {
        } else if (event.getAction() == KeyEvent.ACTION_UP) {
            // We should not judge SHORT_PRESS by ACTION_UP event repeatCount, because it always
            // return 0.
            // Actually ACTION_DOWN event repeatCount only increases when LONG_PRESS performed.
            if (mLastHookEvent != null && mLastHookEvent.getRepeatCount() == 0) {
                return mCallsManager.onMediaButton(SHORT_PRESS);
            }
        }

        if (event.getAction() != KeyEvent.ACTION_DOWN) {
            mLastHookEvent = null;
        }

        return true;
    }