Loading services/core/java/com/android/server/policy/PhoneWindowManager.java +4 −4 Original line number Diff line number Diff line Loading @@ -2242,7 +2242,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { */ private final class PowerKeyRule extends SingleKeyGestureDetector.SingleKeyRule { PowerKeyRule(int gestures) { super(mContext, KEYCODE_POWER, gestures); super(KEYCODE_POWER, gestures); } @Override Loading Loading @@ -2293,7 +2293,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { */ private final class BackKeyRule extends SingleKeyGestureDetector.SingleKeyRule { BackKeyRule(int gestures) { super(mContext, KEYCODE_BACK, gestures); super(KEYCODE_BACK, gestures); } @Override Loading @@ -2317,7 +2317,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { */ private final class StemPrimaryKeyRule extends SingleKeyGestureDetector.SingleKeyRule { StemPrimaryKeyRule(int gestures) { super(mContext, KeyEvent.KEYCODE_STEM_PRIMARY, gestures); super(KeyEvent.KEYCODE_STEM_PRIMARY, gestures); } @Override Loading @@ -2342,7 +2342,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { } private void initSingleKeyGestureRules() { mSingleKeyGestureDetector = new SingleKeyGestureDetector(); mSingleKeyGestureDetector = SingleKeyGestureDetector.get(mContext); int powerKeyGestures = 0; if (hasVeryLongPressOnPowerBehavior()) { Loading services/core/java/com/android/server/policy/SingleKeyGestureDetector.java +17 −11 Original line number Diff line number Diff line Loading @@ -55,12 +55,15 @@ public final class SingleKeyGestureDetector { private volatile boolean mHandledByLongPress = false; private final Handler mHandler; private long mLastDownTime = 0; private static final long MULTI_PRESS_TIMEOUT = ViewConfiguration.getMultiPressTimeout(); /** Supported gesture flags */ public static final int KEY_LONGPRESS = 1 << 1; public static final int KEY_VERYLONGPRESS = 1 << 2; static final long MULTI_PRESS_TIMEOUT = ViewConfiguration.getMultiPressTimeout(); static long sDefaultLongPressTimeout; static long sDefaultVeryLongPressTimeout; /** @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef(prefix = { "KEY_" }, value = { Loading @@ -86,16 +89,10 @@ public final class SingleKeyGestureDetector { abstract static class SingleKeyRule { private final int mKeyCode; private final int mSupportedGestures; private final long mDefaultLongPressTimeout; private final long mDefaultVeryLongPressTimeout; SingleKeyRule(Context context, int keyCode, @KeyGestureFlag int supportedGestures) { SingleKeyRule(int keyCode, @KeyGestureFlag int supportedGestures) { mKeyCode = keyCode; mSupportedGestures = supportedGestures; mDefaultLongPressTimeout = ViewConfiguration.get(context).getDeviceGlobalActionKeyTimeout(); mDefaultVeryLongPressTimeout = context.getResources().getInteger( com.android.internal.R.integer.config_veryLongPressTimeout); } /** Loading Loading @@ -145,7 +142,7 @@ public final class SingleKeyGestureDetector { * press timeout. */ long getLongPressTimeoutMs() { return mDefaultLongPressTimeout; return sDefaultLongPressTimeout; } /** * Callback when long press has been detected. Loading @@ -157,7 +154,7 @@ public final class SingleKeyGestureDetector { * If long press is supported, this should always be longer than the long press timeout. */ long getVeryLongPressTimeoutMs() { return mDefaultVeryLongPressTimeout; return sDefaultVeryLongPressTimeout; } /** * Callback when very long press has been detected. Loading @@ -173,7 +170,16 @@ public final class SingleKeyGestureDetector { } } public SingleKeyGestureDetector() { static SingleKeyGestureDetector get(Context context) { SingleKeyGestureDetector detector = new SingleKeyGestureDetector(); sDefaultLongPressTimeout = context.getResources().getInteger( com.android.internal.R.integer.config_globalActionsKeyTimeout); sDefaultVeryLongPressTimeout = context.getResources().getInteger( com.android.internal.R.integer.config_veryLongPressTimeout); return detector; } private SingleKeyGestureDetector() { mHandler = new KeyHandler(); } Loading services/tests/wmtests/src/com/android/server/policy/SingleKeyGestureTests.java +6 −8 Original line number Diff line number Diff line Loading @@ -37,7 +37,6 @@ import android.os.HandlerThread; import android.os.Process; import android.os.SystemClock; import android.view.KeyEvent; import android.view.ViewConfiguration; import org.junit.Before; import org.junit.Test; Loading Loading @@ -75,18 +74,17 @@ public class SingleKeyGestureTests { @Before public void setUp() { mInstrumentation.runOnMainSync(() -> { mDetector = new SingleKeyGestureDetector(); mDetector = SingleKeyGestureDetector.get(mContext); initSingleKeyGestureRules(); }); mWaitTimeout = ViewConfiguration.getMultiPressTimeout() + 50; mLongPressTime = ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout() + 50; mVeryLongPressTime = mContext.getResources().getInteger( com.android.internal.R.integer.config_veryLongPressTimeout) + 50; mWaitTimeout = SingleKeyGestureDetector.MULTI_PRESS_TIMEOUT + 50; mLongPressTime = SingleKeyGestureDetector.sDefaultLongPressTimeout + 50; mVeryLongPressTime = SingleKeyGestureDetector.sDefaultVeryLongPressTimeout + 50; } private void initSingleKeyGestureRules() { mDetector.addRule(new SingleKeyGestureDetector.SingleKeyRule(mContext, KEYCODE_POWER, mDetector.addRule(new SingleKeyGestureDetector.SingleKeyRule(KEYCODE_POWER, KEY_LONGPRESS | KEY_VERYLONGPRESS) { @Override int getMaxMultiPressCount() { Loading Loading @@ -124,7 +122,7 @@ public class SingleKeyGestureTests { } }); mDetector.addRule(new SingleKeyGestureDetector.SingleKeyRule(mContext, KEYCODE_BACK, 0) { mDetector.addRule(new SingleKeyGestureDetector.SingleKeyRule(KEYCODE_BACK, 0) { @Override int getMaxMultiPressCount() { return mMaxMultiPressCount; Loading Loading
services/core/java/com/android/server/policy/PhoneWindowManager.java +4 −4 Original line number Diff line number Diff line Loading @@ -2242,7 +2242,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { */ private final class PowerKeyRule extends SingleKeyGestureDetector.SingleKeyRule { PowerKeyRule(int gestures) { super(mContext, KEYCODE_POWER, gestures); super(KEYCODE_POWER, gestures); } @Override Loading Loading @@ -2293,7 +2293,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { */ private final class BackKeyRule extends SingleKeyGestureDetector.SingleKeyRule { BackKeyRule(int gestures) { super(mContext, KEYCODE_BACK, gestures); super(KEYCODE_BACK, gestures); } @Override Loading @@ -2317,7 +2317,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { */ private final class StemPrimaryKeyRule extends SingleKeyGestureDetector.SingleKeyRule { StemPrimaryKeyRule(int gestures) { super(mContext, KeyEvent.KEYCODE_STEM_PRIMARY, gestures); super(KeyEvent.KEYCODE_STEM_PRIMARY, gestures); } @Override Loading @@ -2342,7 +2342,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { } private void initSingleKeyGestureRules() { mSingleKeyGestureDetector = new SingleKeyGestureDetector(); mSingleKeyGestureDetector = SingleKeyGestureDetector.get(mContext); int powerKeyGestures = 0; if (hasVeryLongPressOnPowerBehavior()) { Loading
services/core/java/com/android/server/policy/SingleKeyGestureDetector.java +17 −11 Original line number Diff line number Diff line Loading @@ -55,12 +55,15 @@ public final class SingleKeyGestureDetector { private volatile boolean mHandledByLongPress = false; private final Handler mHandler; private long mLastDownTime = 0; private static final long MULTI_PRESS_TIMEOUT = ViewConfiguration.getMultiPressTimeout(); /** Supported gesture flags */ public static final int KEY_LONGPRESS = 1 << 1; public static final int KEY_VERYLONGPRESS = 1 << 2; static final long MULTI_PRESS_TIMEOUT = ViewConfiguration.getMultiPressTimeout(); static long sDefaultLongPressTimeout; static long sDefaultVeryLongPressTimeout; /** @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef(prefix = { "KEY_" }, value = { Loading @@ -86,16 +89,10 @@ public final class SingleKeyGestureDetector { abstract static class SingleKeyRule { private final int mKeyCode; private final int mSupportedGestures; private final long mDefaultLongPressTimeout; private final long mDefaultVeryLongPressTimeout; SingleKeyRule(Context context, int keyCode, @KeyGestureFlag int supportedGestures) { SingleKeyRule(int keyCode, @KeyGestureFlag int supportedGestures) { mKeyCode = keyCode; mSupportedGestures = supportedGestures; mDefaultLongPressTimeout = ViewConfiguration.get(context).getDeviceGlobalActionKeyTimeout(); mDefaultVeryLongPressTimeout = context.getResources().getInteger( com.android.internal.R.integer.config_veryLongPressTimeout); } /** Loading Loading @@ -145,7 +142,7 @@ public final class SingleKeyGestureDetector { * press timeout. */ long getLongPressTimeoutMs() { return mDefaultLongPressTimeout; return sDefaultLongPressTimeout; } /** * Callback when long press has been detected. Loading @@ -157,7 +154,7 @@ public final class SingleKeyGestureDetector { * If long press is supported, this should always be longer than the long press timeout. */ long getVeryLongPressTimeoutMs() { return mDefaultVeryLongPressTimeout; return sDefaultVeryLongPressTimeout; } /** * Callback when very long press has been detected. Loading @@ -173,7 +170,16 @@ public final class SingleKeyGestureDetector { } } public SingleKeyGestureDetector() { static SingleKeyGestureDetector get(Context context) { SingleKeyGestureDetector detector = new SingleKeyGestureDetector(); sDefaultLongPressTimeout = context.getResources().getInteger( com.android.internal.R.integer.config_globalActionsKeyTimeout); sDefaultVeryLongPressTimeout = context.getResources().getInteger( com.android.internal.R.integer.config_veryLongPressTimeout); return detector; } private SingleKeyGestureDetector() { mHandler = new KeyHandler(); } Loading
services/tests/wmtests/src/com/android/server/policy/SingleKeyGestureTests.java +6 −8 Original line number Diff line number Diff line Loading @@ -37,7 +37,6 @@ import android.os.HandlerThread; import android.os.Process; import android.os.SystemClock; import android.view.KeyEvent; import android.view.ViewConfiguration; import org.junit.Before; import org.junit.Test; Loading Loading @@ -75,18 +74,17 @@ public class SingleKeyGestureTests { @Before public void setUp() { mInstrumentation.runOnMainSync(() -> { mDetector = new SingleKeyGestureDetector(); mDetector = SingleKeyGestureDetector.get(mContext); initSingleKeyGestureRules(); }); mWaitTimeout = ViewConfiguration.getMultiPressTimeout() + 50; mLongPressTime = ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout() + 50; mVeryLongPressTime = mContext.getResources().getInteger( com.android.internal.R.integer.config_veryLongPressTimeout) + 50; mWaitTimeout = SingleKeyGestureDetector.MULTI_PRESS_TIMEOUT + 50; mLongPressTime = SingleKeyGestureDetector.sDefaultLongPressTimeout + 50; mVeryLongPressTime = SingleKeyGestureDetector.sDefaultVeryLongPressTimeout + 50; } private void initSingleKeyGestureRules() { mDetector.addRule(new SingleKeyGestureDetector.SingleKeyRule(mContext, KEYCODE_POWER, mDetector.addRule(new SingleKeyGestureDetector.SingleKeyRule(KEYCODE_POWER, KEY_LONGPRESS | KEY_VERYLONGPRESS) { @Override int getMaxMultiPressCount() { Loading Loading @@ -124,7 +122,7 @@ public class SingleKeyGestureTests { } }); mDetector.addRule(new SingleKeyGestureDetector.SingleKeyRule(mContext, KEYCODE_BACK, 0) { mDetector.addRule(new SingleKeyGestureDetector.SingleKeyRule(KEYCODE_BACK, 0) { @Override int getMaxMultiPressCount() { return mMaxMultiPressCount; Loading