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

Commit 0f19a45d authored by Austin T. Conn's avatar Austin T. Conn Committed by Steve Kondik
Browse files

Settings: Forward Port Volume Long Press Skip Tracks (1/2)

Bring Forward Volume Rocker Track Change

Requires Settings Change
http://review.cyanogenmod.org/#/c/82222/

Change-Id: I70b00e08fe48707110725dd1daa56b1e48d15a03
parent 0755450e
Loading
Loading
Loading
Loading
+64 −2
Original line number Diff line number Diff line
@@ -508,6 +508,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    WindowState mFocusedWindow;
    IApplicationToken mFocusedApp;

    // Behavior of volbtn music controls
    boolean mVolBtnMusicControls;
    boolean mIsLongPress;

    PointerLocationView mPointerLocationView;

    // The current size of the screen; really; extends into the overscan area of
@@ -758,6 +762,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    private static final int MSG_SHOW_TV_PICTURE_IN_PICTURE_MENU = 17;
    private static final int MSG_BACK_LONG_PRESS = 18;
    private static final int MSG_DISPOSE_INPUT_CONSUMER = 19;
    private static final int MSG_DISPATCH_VOLKEY_WITH_WAKE_LOCK = 20;

    private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
    private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
@@ -828,6 +833,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                case MSG_DISPOSE_INPUT_CONSUMER:
                    disposeInputConsumer((InputConsumer) msg.obj);
                    break;
                case MSG_DISPATCH_VOLKEY_WITH_WAKE_LOCK:
                    dispatchMediaKeyWithWakeLockToAudioService((KeyEvent)msg.obj);
                    dispatchMediaKeyWithWakeLockToAudioService(KeyEvent.changeAction((KeyEvent)msg.obj, KeyEvent.ACTION_UP));
                    break;
            }
        }
    }
@@ -901,6 +910,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            resolver.registerContentObserver(Settings.Global.getUriFor(
                    Settings.Global.POLICY_CONTROL), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.VOLBTN_MUSIC_CONTROLS), false, this,
                    UserHandle.USER_ALL);

            updateSettings();
        }

@@ -2083,6 +2096,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
                    Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
                    UserHandle.USER_CURRENT);
            mVolBtnMusicControls = (Settings.System.getIntForUser(resolver,
                    Settings.System.VOLBTN_MUSIC_CONTROLS, 1, UserHandle.USER_CURRENT) == 1);

            // Configure wake gesture.
            boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
@@ -3133,7 +3148,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    @Override
    public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
        final boolean keyguardOn = keyguardOn();
        final int keyCode = event.getKeyCode();
        final int repeatCount = event.getRepeatCount();
        final int metaState = event.getMetaState();
        final int flags = event.getFlags();
@@ -3141,6 +3155,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        final boolean canceled = event.isCanceled();
        final boolean longPress = (flags & KeyEvent.FLAG_LONG_PRESS) != 0;
        final boolean virtualKey = event.getDeviceId() == KeyCharacterMap.VIRTUAL_KEYBOARD;
        final int keyCode = event.getKeyCode();

        if (DEBUG_INPUT) {
            Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
@@ -5617,6 +5632,20 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        setHdmiPlugged(!mHdmiPlugged);
    }

    /**
     * @return Whether music is being played right now "locally" (e.g. on the device's speakers
     *    or wired headphones) or "remotely" (e.g. on a device using the Cast protocol and
     *    controlled by this device, or through remote submix).
     */
    private boolean isMusicActive() {
        final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
        if (am == null) {
            Log.w(TAG, "isMusicActive: couldn't get AudioManager reference");
            return false;
        }
        return am.isMusicActive();
    }

    final Object mScreenshotLock = new Object();
    ServiceConnection mScreenshotConnection = null;

@@ -5872,8 +5901,41 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    MediaSessionLegacyHelper.getHelper(mContext)
                            .sendVolumeKeyEvent(event, true);
                }

                if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) {
                    if (mVolBtnMusicControls && down && (keyCode != KeyEvent.KEYCODE_VOLUME_MUTE)) {
                        mIsLongPress = false;
                        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) {
                            mHandler.removeMessages(MSG_DISPATCH_VOLKEY_WITH_WAKE_LOCK);
                            if (mIsLongPress) {
                                break;
                            }
                        }
                    }
                }

                if ((result & ACTION_PASS_TO_USER) == 0) {
                    if (mUseTvRouting) {
                        dispatchDirectAudioEvent(event);
                    } else {
                        // If we aren't passing to the user and no one else
                        // handled it send it to the session manager to
                        // figure out.
                        MediaSessionLegacyHelper.getHelper(mContext)
                                .sendVolumeKeyEvent(event, true);
                    }
                    break;
                }
                }
                break;

            case KeyEvent.KEYCODE_ENDCALL: {
                result &= ~ACTION_PASS_TO_USER;