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

Commit dd3cf356 authored by Vladislav Koldobskiy's avatar Vladislav Koldobskiy Committed by Gerrit Code Review
Browse files

Camera button support: useful features & bugfixes (1/2)

Screw the remapping, let's make something more useful!
Replaced the code to actually launch Camera app, not just fire the shutter.
I won't remove it: it's cool to have an option to double-click Home for Camera.
Added:
  * Camera wake (with button half-press) and unlock options
  * "Peek": releasing the half-pressed Camera button will
    turn the screen back off
  * Camera playback control

Change-Id: Id49e09e20d81cd80d9800ab8ab0f200d44485a09
parent c8900d18
Loading
Loading
Loading
Loading
+42 −33
Original line number Diff line number Diff line
@@ -2941,6 +2941,24 @@ public final class Settings {
         */
        public static final String VOLBTN_MUSIC_CONTROLS = "volbtn_music_controls";

        /**
         * Whether to wake the screen with the camera key half-press.
         * @hide
         */
        public static final String CAMERA_WAKE_SCREEN = "camera_wake_screen";

        /**
         * Whether or not to send device back to sleep if Camera button is released ("Peek")
         * @hide
         */
        public static final String CAMERA_SLEEP_ON_RELEASE = "camera_sleep_on_release";

        /**
         * Whether or not camera button music controls should be enabled to play/pause media tracks
         * @hide
         */
        public static final String CAMERA_MUSIC_CONTROLS = "camera_music_controls";

        /**
         * Whether or not to launch default music player when headset is connected
         * @hide
@@ -3137,6 +3155,12 @@ public final class Settings {
         */
        public static final String HOME_UNLOCK_SCREEN = "home_unlock_screen";

        /**
         * Whether to unlock the screen with the camera key.  The value is boolean (1 or 0).
         * @hide
         */
        public static final String CAMERA_UNLOCK_SCREEN = "camera_unlock_screen";

        /**
         * Whether the lockscreen vibrate should be enabled.
         * @hide
@@ -3229,21 +3253,6 @@ public final class Settings {
         */
        public static final String KEY_APP_SWITCH_LONG_PRESS_ACTION = "key_app_switch_long_press_action";

         /**
          * Action to perform when the Camera key is pressed. (Default is 0)
          * (See KEY_HOME_LONG_PRESS_ACTION for valid values)
          * @hide
          */
         public static final String KEY_CAMERA_ACTION = "key_camera_action";

         /**
          * Action to perform when the Camera key is long-pressed. (Default is 6)
          * (See KEY_HOME_LONG_PRESS_ACTION for valid values)
          * @hide
          */
         public static final String KEY_CAMERA_LONG_PRESS_ACTION = "key_camera_long_press_action";


        /**
         * Control the display of the action overflow button within app UI.
         * 0 = use system default
+4 −0
Original line number Diff line number Diff line
@@ -1249,6 +1249,10 @@
         config to 7. -->
    <integer name="config_deviceHardwareKeys">15</integer>

    <!-- Indicates that the device has Single-stage Camera key
         (without "Focus" state) instead of Dual-stage. -->
    <bool name="config_singleStageCameraKey">false</bool>

    <!-- Maximum wallpaper width for devices with very high-res screen (1920x1200)
         the wallpaper width suggestion by the launcher may be too large for
         the GPU to handle. -->
+1 −0
Original line number Diff line number Diff line
@@ -1918,6 +1918,7 @@

  <!-- Hardware Key ReMapping -->
  <java-symbol type="integer" name="config_deviceHardwareKeys" />
  <java-symbol type="bool" name="config_singleStageCameraKey" />

  <!-- Notification and battery light -->
  <java-symbol type="bool" name="config_intrusiveBatteryLed" />
+92 −5
Original line number Diff line number Diff line
@@ -324,6 +324,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    int mBackKillTimeout;
    int mPointerLocationMode = 0; // guarded by mLock
    int mDeviceHardwareKeys;
    boolean mSingleStageCameraKey;
    boolean mHasMenuKeyEnabled;

    int mCurrentUser = 0;
@@ -338,9 +339,17 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    // Behavior of volume wake
    boolean mVolumeWakeScreen;

    // Behavior of volbtn music controls
    // Behavior of camera wake
    boolean mCameraWakeScreen;
    boolean mCameraSleepOnRelease;
    boolean mIsFocusPressed;

    // Behavior of volbtn/camera music controls
    boolean mCameraMusicControls;
    boolean mVolBtnMusicControls;
    boolean mIsLongPress;
    boolean mCameraKeyPressable = false;

    private boolean mAnimatingWindows;
    private boolean mNeedUpdateSettings;

@@ -599,9 +608,18 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.VOLUME_WAKE_SCREEN), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.CAMERA_WAKE_SCREEN), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.CAMERA_SLEEP_ON_RELEASE), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.VOLBTN_MUSIC_CONTROLS), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.CAMERA_MUSIC_CONTROLS), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.ACCELEROMETER_ROTATION), false, this,
                    UserHandle.USER_ALL);
@@ -999,7 +1017,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                triggerVirtualKeypress(KeyEvent.KEYCODE_SEARCH);
                break;
            case KEY_ACTION_LAUNCH_CAMERA:
                triggerVirtualKeypress(KeyEvent.KEYCODE_CAMERA);
                launchCameraAction();
                break;
            default:
                break;
@@ -1127,6 +1145,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                com.android.internal.R.integer.config_backKillTimeout);
        mDeviceHardwareKeys = mContext.getResources().getInteger(
                com.android.internal.R.integer.config_deviceHardwareKeys);
        mSingleStageCameraKey = mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_singleStageCameraKey);

        updateKeyAssignments();

@@ -1418,8 +1438,16 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    Settings.System.HOME_WAKE_SCREEN, 1, UserHandle.USER_CURRENT) == 1);
            mVolumeWakeScreen = (Settings.System.getIntForUser(resolver,
                    Settings.System.VOLUME_WAKE_SCREEN, 0, UserHandle.USER_CURRENT) == 1);
            mCameraWakeScreen = (Settings.System.getIntForUser(resolver,
                    Settings.System.CAMERA_WAKE_SCREEN, 0, UserHandle.USER_CURRENT) == 1);
            mCameraSleepOnRelease = ((Settings.System.getIntForUser(resolver,
                    Settings.System.CAMERA_SLEEP_ON_RELEASE, 0, UserHandle.USER_CURRENT) == 1)
                    && mCameraWakeScreen);
            mVolBtnMusicControls = (Settings.System.getIntForUser(resolver,
                    Settings.System.VOLBTN_MUSIC_CONTROLS, 1, UserHandle.USER_CURRENT) == 1);
            mCameraMusicControls = ((Settings.System.getIntForUser(resolver,
                    Settings.System.CAMERA_MUSIC_CONTROLS, 1, UserHandle.USER_CURRENT) == 1)
                    && !mCameraWakeScreen);

            updateKeyAssignments();

@@ -2792,6 +2820,13 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
    }

    private void launchCameraAction() {
        sendCloseSystemWindows();
        Intent intent = new Intent(Intent.ACTION_CAMERA_BUTTON, null);
        mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF,
                null, null, null, 0, null, null);
    }

    private SearchManager getSearchManager() {
        if (mSearchManager == null) {
            mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
@@ -4256,6 +4291,52 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    }
                }
                break;
            case KeyEvent.KEYCODE_FOCUS:
                if (down && !isScreenOn && mCameraWakeScreen) {
                    if (keyguardActive) {
                        mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(keyCode);
                    } else {
                        result |= ACTION_WAKE_UP;
                    }
                    if (mCameraSleepOnRelease) {
                        mIsFocusPressed = true;
                    }
                } else if (!down && isScreenOn && mIsFocusPressed) {
                     result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP;
                     mIsFocusPressed = false;
                }
                break;
            case KeyEvent.KEYCODE_CAMERA:
                if (down && mIsFocusPressed) {
                    mIsFocusPressed = false;
                }
                if (down && !isScreenOn && mCameraWakeScreen && mSingleStageCameraKey) {
                    if (keyguardActive) {
                        mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(keyCode);
                    } else {
                        result |= ACTION_WAKE_UP;
                    }
                }
                if (mCameraMusicControls) {
                    // if the camera key is not pressable, see if music is active
                    if (!mCameraKeyPressable) {
                        mCameraKeyPressable = isMusicActive();
                    }

                    if (mCameraKeyPressable) {
                        if (down) {
                            Message msg = mHandler.obtainMessage(MSG_DISPATCH_VOLKEY_WITH_WAKE_LOCK,
                                    new KeyEvent(event.getDownTime(), event.getEventTime(),
                                    event.getAction(), KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, 0));
                            msg.setAsynchronous(true);
                            mHandler.sendMessageDelayed(msg, ViewConfiguration.getLongPressTimeout());
                            break;
                        } else {
                            mHandler.removeMessages(MSG_DISPATCH_VOLKEY_WITH_WAKE_LOCK);
                        }
                    }
                }
                break;
            case KeyEvent.KEYCODE_VOLUME_DOWN:
            case KeyEvent.KEYCODE_VOLUME_UP:
            case KeyEvent.KEYCODE_VOLUME_MUTE: {
@@ -4491,7 +4572,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            case KeyEvent.KEYCODE_VOLUME_MUTE:
                return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;

            // ignore media and camera keys
            // ignore media keys
            case KeyEvent.KEYCODE_MUTE:
            case KeyEvent.KEYCODE_HEADSETHOOK:
            case KeyEvent.KEYCODE_MEDIA_PLAY:
@@ -4503,10 +4584,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            case KeyEvent.KEYCODE_MEDIA_REWIND:
            case KeyEvent.KEYCODE_MEDIA_RECORD:
            case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
            case KeyEvent.KEYCODE_CAMERA:
                return false;

            // home wake can be configurable so default to no here
            // home & camera wake can be configurable so default to no here
            case KeyEvent.KEYCODE_FOCUS:
            case KeyEvent.KEYCODE_CAMERA:
            case KeyEvent.KEYCODE_HOME:
                return false;
        }
@@ -4692,6 +4774,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }

        synchronized (mLock) {
            // since the screen turned on, assume we don't enable play-pause again
            // unless they turn it off and music is still playing.  this is done to
            // prevent the camera button from starting playback if playback wasn't
            // originally running
            mCameraKeyPressable = false;
            mScreenOnEarly = true;
            updateOrientationListenerLp();
            updateLockScreenTimeout();
+15 −0
Original line number Diff line number Diff line
@@ -1742,6 +1742,11 @@ public class KeyguardHostView extends KeyguardViewBase {
        return homeOverride;
    }

    private boolean shouldEnableCameraKey() {
        final boolean cameraOverride = Settings.System.getInt(getContext().getContentResolver(), Settings.System.CAMERA_UNLOCK_SCREEN, 0) == 1;
        return cameraOverride;
    }

    public void goToUserSwitcher() {
        mAppWidgetContainer.setCurrentPage(getWidgetPosition(R.id.keyguard_multi_user_selector));
    }
@@ -1760,6 +1765,16 @@ public class KeyguardHostView extends KeyguardViewBase {
        return false;
    }


    public boolean handleCameraKey() {
        // The following enables the CAMERA key to work for testing automation
        if (shouldEnableCameraKey()) {
            showNextSecurityScreenOrFinish(false);
            return true;
        }
        return false;
    }

    public boolean handleHomeKey() {
        // The following enables the HOME key to work for testing automation
        if (shouldEnableHomeKey()) {
Loading