修改framework/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -679,6 +680,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
// Screenshot trigger states
// Time to volume and power must be pressed within this interval of each other.
private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
+ private static final long CUSTOM_CHORD_DEBOUNCE_DELAY_MILLIS = 5000;
// Increase the chord delay when taking a screenshot from the keyguard
private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
private boolean mScreenshotChordEnabled;
@@ -686,8 +688,20 @@ public class PhoneWindowManager implements WindowManagerPolicy {
private long mScreenshotChordVolumeDownKeyTime;
private boolean mScreenshotChordVolumeDownKeyConsumed;
private boolean mScreenshotChordVolumeUpKeyTriggered;
private boolean mScreenshotChordPowerKeyTriggered;
private long mScreenshotChordPowerKeyTime;
+
+ private boolean mCustomChordEnabled;
+ private boolean mCustomChordVolumeDownKeyTriggered;
+ private long mCustomChordVolumeDownKeyTime;
+ private boolean mCustomChordVolumeDownKeyConsumed;
+ private boolean mCustomChordVolumeUpKeyTriggered;
+ private long mCustomChordVolumeUpKeyTime;
+ private boolean mCustomChordVolumeUpKeyConsumed;
private static final int BRIGHTNESS_STEPS = 10;
@@ -736,7 +750,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
boolean mWifiDisplayConnected = false;
int mWifiDisplayCustomRotation = -1;
private class PolicyHandler extends Handler {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
@@ -1332,6 +1346,32 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
}
}
+
+ private void CustomChord() {
+ Log.d(TAG,"CustomChord CustomChordstart");
+ if (mCustomChordEnabled
+ && mCustomChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered
+ && mCustomChordVolumeUpKeyTriggered) {
+ final long now = SystemClock.uptimeMillis();
+ Log.d(TAG,"CustomChord if");
+ if (now >= mCustomChordVolumeDownKeyTime + CUSTOM_CHORD_DEBOUNCE_DELAY_MILLIS
+ && now >= mCustomChordVolumeUpKeyTime
+ + CUSTOM_CHORD_DEBOUNCE_DELAY_MILLIS) {
+ Log.d(TAG,"CustomChord log");
+ Intent intent = new Intent();
+ intent.setAction("com.upanddown.broadcast");
+ mContext.sendBroadcast(intent);
+ Log.d(TAG,"CustomChord Action end");
+ }
+ }
+ }
private long getScreenshotChordLongPressDelay() {
if (mKeyguardDelegate.isShowing()) {
@@ -1774,6 +1814,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mScreenshotChordEnabled = mContext.getResources().getBoolean(
com.android.internal.R.bool.config_enableScreenshotChord);
+ mCustomChordEnabled = mContext.getResources().getBoolean(
+ com.android.internal.R.bool.config_enableCustomChord);
mGlobalKeyManager = new GlobalKeyManager(mContext);
@@ -3029,6 +3072,39 @@ public class PhoneWindowManager implements WindowManagerPolicy {
return -1;
}
}
+
+ if (mCustomChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
+ if (mCustomChordVolumeDownKeyTriggered && !mCustomChordVolumeUpKeyTriggered) {
+ final long now = SystemClock.uptimeMillis();
+ final long timeoutTime = mCustomChordVolumeDownKeyTime
+ + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
+ if (now < timeoutTime) {
+ return timeoutTime - now;
+ }
+ }
+ if (!mCustomChordVolumeDownKeyTriggered && mCustomChordVolumeUpKeyTriggered) {
+ final long now = SystemClock.uptimeMillis();
+ final long timeoutTime = mCustomChordVolumeUpKeyTime
+ + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
+ if (now < timeoutTime) {
+ return timeoutTime - now;
+ }
+ }
+ if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
+ && mCustomChordVolumeDownKeyConsumed) {
+ if (!down) {
+ mCustomChordVolumeDownKeyConsumed = false;
+ }
+ return -1;
+ }
+ if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
+ && mCustomChordVolumeUpKeyConsumed) {
+ if (!down) {
+ mCustomChordVolumeUpKeyConsumed = false;
+ }
+ return -1;
+ }
+ }
// Cancel any pending meta actions if we see any other keys being pressed between the down
// of the meta key and its corresponding up.
@@ -5478,6 +5554,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
+ final boolean up = event.getAction() == KeyEvent.ACTION_UP;
final boolean canceled = event.isCanceled();
final int keyCode = event.getKeyCode();
@@ -5487,7 +5564,14 @@ public class PhoneWindowManager implements WindowManagerPolicy {
// the same as if it were open and in front.
// This will prevent any keys other than the power button from waking the screen
// when the keyguard is hidden by another activity.
+ final Runnable customRunnable = new Runnable() {
+ @Override public void run() {
+ if (!up) {
+ CustomChord();
+ }
+ }
+ };
final boolean keyguardActive = (mKeyguardDelegate == null ? false :
(interactive ?
isKeyguardShowingAndNotOccluded() :
mKeyguardDelegate.isShowing()));
@@ -5566,28 +5667,42 @@ public class PhoneWindowManager implements WindowManagerPolicy {
case KeyEvent.KEYCODE_VOLUME_MUTE: {
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
if (down) {
- if (interactive && !mScreenshotChordVolumeDownKeyTriggered
+ if (interactive && !(mScreenshotChordVolumeDownKeyTriggered || mCustomChordVolumeDownKeyTriggered)
&& (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
mScreenshotChordVolumeDownKeyTriggered = true;
mScreenshotChordVolumeDownKeyTime = event.getDownTime();
mScreenshotChordVolumeDownKeyConsumed = false;
+ mCustomChordVolumeDownKeyTriggered = true;
+ mCustomChordVolumeDownKeyTime = event.getDownTime();
+ mCustomChordVolumeDownKeyConsumed = false;
cancelPendingPowerKeyAction();
interceptScreenshotChord();
- }
+ Log.d(TAG,"down CustomChord");
+ mHandler.postDelayed(customRunnable, 5000);
+ }
} else {
mScreenshotChordVolumeDownKeyTriggered = false;
+ mCustomChordVolumeDownKeyTriggered = false;
cancelPendingScreenshotChordAction();
}
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
if (down) {
- if (interactive && !mScreenshotChordVolumeUpKeyTriggered
+ if (interactive && !(mScreenshotChordVolumeUpKeyTriggered || mCustomChordVolumeUpKeyTriggered)
&& (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
- mScreenshotChordVolumeUpKeyTriggered = true;
+ mScreenshotChordVolumeUpKeyTriggered = true;
+ mScreenshotChordVolumeUpKeyTime = event.getDownTime();
+ mScreenshotChordVolumeUpKeyConsumed = false;
+ mCustomChordVolumeUpKeyTriggered = true;
+ mCustomChordVolumeUpKeyTime = event.getDownTime();
+ mCustomChordVolumeUpKeyConsumed = false;
cancelPendingPowerKeyAction();
cancelPendingScreenshotChordAction();
- }
+ Log.d(TAG,"up CustomChord");
+ mHandler.postDelayed(customRunnable, 5000);
+ }
} else {
mScreenshotChordVolumeUpKeyTriggered = false;
+ mCustomChordVolumeUpKeyTriggered = false;
cancelPendingScreenshotChordAction();
}
}
修改framework/base//core/res/res/values/config.xml
@@ -565,7 +565,8 @@
<!-- If this is true, key chords can be used to take a screenshot on the device. -->
<bool name="config_enableScreenshotChord">true</bool>
-
+ <!-- If this is true, key chords can be used to custom on the device. -->
+ <bool name="config_enableCustomChord">true</bool>
<!-- If this is true, allow wake from theater mode when plugged in or unplugged. -->
<bool name="config_allowTheaterModeWakeFromUnplug">false</bool>
<!-- If this is true, allow wake from theater mode from gesture. -->
修改framework/base/core/res/res/values/symbols.xml
@@ -278,6 +278,7 @@
<java-symbol type="bool" name="config_enableWallpaperService" />
<java-symbol type="bool" name="config_sendAudioBecomingNoisy" />
<java-symbol type="bool" name="config_enableScreenshotChord" />
+ <java-symbol type="bool" name="config_enableCustomChord" />
<java-symbol type="bool" name="config_bluetooth_default_profiles" />
<java-symbol type="bool" name="config_enableWifiDisplay" />
<java-symbol type="bool" name="config_allowAnimationsInLowPowerMode" />
以上内容基于android原生的power鍵加音量-鍵截屏功能修改,如果想實作其他功能,可以将廣播發送的地方換成需要的功能。