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

Commit f050150b authored by David van Tonder's avatar David van Tonder Committed by Gerrit Code Review
Browse files

Merge "Port "Framework Track Control : Switch from broadcast to audio service"" into cm-10.1

parents 7357ea8a f4263250
Loading
Loading
Loading
Loading
+12 −49
Original line number Diff line number Diff line
@@ -547,6 +547,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    private static final int MSG_DISABLE_POINTER_LOCATION = 2;
    private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
    private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
    private static final int MSG_DISPATCH_VOLKEY_WITH_WAKE_LOCK = 5;

    private class PolicyHandler extends Handler {
        @Override
@@ -564,6 +565,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
                    dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
                    break;
                case MSG_DISPATCH_VOLKEY_WITH_WAKE_LOCK:
                    dispatchMediaKeyWithWakeLockToAudioService((KeyEvent)msg.obj);
                    dispatchMediaKeyWithWakeLockToAudioService(KeyEvent.changeAction((KeyEvent)msg.obj, KeyEvent.ACTION_UP));
                    break;
            }
        }
    }
@@ -768,53 +773,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
    }

    /**
     * When a volumeup-key longpress expires, skip songs based on key press
     */
    Runnable mVolumeUpLongPress = new Runnable() {
        public void run() {
            // set the long press flag to true
            mIsLongPress = true;

            // Shamelessly copied from Kmobs LockScreen controls, works for Pandora, etc...
            sendMediaButtonEvent(KeyEvent.KEYCODE_MEDIA_NEXT);
        };
    };

    /**
     * When a volumedown-key longpress expires, skip songs based on key press
     */
    Runnable mVolumeDownLongPress = new Runnable() {
        public void run() {
            // set the long press flag to true
            mIsLongPress = true;

            // Shamelessly copied from Kmobs LockScreen controls, works for Pandora, etc...
            sendMediaButtonEvent(KeyEvent.KEYCODE_MEDIA_PREVIOUS);
        };
    };

    private void sendMediaButtonEvent(int code) {
        long eventtime = SystemClock.uptimeMillis();
        Intent keyIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
        KeyEvent keyEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, code, 0);
        keyIntent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent);
        mContext.sendOrderedBroadcast(keyIntent, null);
        keyEvent = KeyEvent.changeAction(keyEvent, KeyEvent.ACTION_UP);
        keyIntent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent);
        mContext.sendOrderedBroadcast(keyIntent, null);
    }

    void handleVolumeLongPress(int keycode) {
        mHandler.postDelayed(keycode == KeyEvent.KEYCODE_VOLUME_UP ? mVolumeUpLongPress :
            mVolumeDownLongPress, ViewConfiguration.getLongPressTimeout());
    }

    void handleVolumeLongPressAbort() {
        mHandler.removeCallbacks(mVolumeUpLongPress);
        mHandler.removeCallbacks(mVolumeDownLongPress);
    }

    private void interceptScreenshotChord() {
        if (mScreenshotChordEnabled
                && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
@@ -3942,11 +3900,16 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) {
                    if (mVolBtnMusicControls && down && (keyCode != KeyEvent.KEYCODE_VOLUME_MUTE)) {
                        mIsLongPress = false;
                        handleVolumeLongPress(keyCode);
                        int newKeyCode = event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP ?
                                KeyEvent.KEYCODE_MEDIA_NEXT : KeyEvent.KEYCODE_MEDIA_PREVIOUS;
                        Message msg = mHandler.obtainMessage(MSG_DISPATCH_VOLKEY_WITH_WAKE_LOCK,
                                new KeyEvent(event.getDownTime(), event.getEventTime(), event.getAction(), newKeyCode, 0));
                        msg.setAsynchronous(true);
                        mHandler.sendMessageDelayed(msg, ViewConfiguration.getLongPressTimeout());
                        break;
                    } else {
                        if (mVolBtnMusicControls && !down) {
                            handleVolumeLongPressAbort();
                            mHandler.removeMessages(MSG_DISPATCH_VOLKEY_WITH_WAKE_LOCK);
                            if (mIsLongPress) {
                                break;
                            }