Loading policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +76 −11 Original line number Diff line number Diff line /* * Copyright (C) 2006 The Android Open Source Project * Copyright (C) 2012 The CyanogenMod Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading Loading @@ -60,6 +61,7 @@ import android.provider.Settings; import com.android.internal.R; import com.android.internal.app.ShutdownThread; import com.android.internal.app.ThemeUtils; import com.android.internal.os.DeviceKeyHandler; import com.android.internal.policy.PolicyManager; import com.android.internal.statusbar.IStatusBarService; Loading Loading @@ -138,8 +140,11 @@ import android.view.KeyCharacterMap.FallbackAction; import android.view.accessibility.AccessibilityEvent; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.view.VolumePanel; import android.widget.Toast; import android.media.IAudioService; import android.media.AudioService; import android.media.AudioManager; import java.io.File; Loading Loading @@ -463,10 +468,12 @@ 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 ACTION_CHORD_DEBOUNCE_DELAY_MILLIS = 150; private boolean mVolumeDownKeyTriggered; private long mVolumeDownKeyTime; private boolean mVolumeDownKeyConsumedByScreenshotChord; private long mVolumeUpKeyTime; private boolean mVolumeDownKeyConsumedByChord; private boolean mVolumeUpKeyConsumedByChord; private boolean mVolumeUpKeyTriggered; private boolean mPowerKeyTriggered; private long mPowerKeyTime; Loading Loading @@ -686,9 +693,9 @@ public class PhoneWindowManager implements WindowManagerPolicy { private void interceptScreenshotChord() { if (mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) { final long now = SystemClock.uptimeMillis(); if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { mVolumeDownKeyConsumedByScreenshotChord = true; if (now <= mVolumeDownKeyTime + ACTION_CHORD_DEBOUNCE_DELAY_MILLIS && now <= mPowerKeyTime + ACTION_CHORD_DEBOUNCE_DELAY_MILLIS) { mVolumeDownKeyConsumedByChord = true; cancelPendingPowerKeyAction(); mHandler.postDelayed(mScreenshotChordLongPress, Loading @@ -701,6 +708,24 @@ public class PhoneWindowManager implements WindowManagerPolicy { mHandler.removeCallbacks(mScreenshotChordLongPress); } private void interceptRingerChord() { if (mVolumeDownKeyTriggered && !mPowerKeyTriggered && mVolumeUpKeyTriggered) { final long now = SystemClock.uptimeMillis(); if (now <= mVolumeDownKeyTime + ACTION_CHORD_DEBOUNCE_DELAY_MILLIS && now <= mVolumeUpKeyTime + ACTION_CHORD_DEBOUNCE_DELAY_MILLIS) { mVolumeDownKeyConsumedByChord = true; mVolumeUpKeyConsumedByChord = true; mHandler.postDelayed(mRingerChordLongPress, ViewConfiguration.getGlobalActionKeyTimeout()); } } } private void cancelPendingRingerChordAction() { mHandler.removeCallbacks(mRingerChordLongPress); } private final Runnable mPowerLongPress = new Runnable() { public void run() { // The context isn't read Loading Loading @@ -733,6 +758,26 @@ public class PhoneWindowManager implements WindowManagerPolicy { } }; private final Runnable mRingerChordLongPress = new Runnable() { public void run() { // Do the switch final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE); final int ringerMode = am.getRingerMode(); final VolumePanel volumePanel = new VolumePanel(ThemeUtils.createUiContext(mContext), (AudioService) getAudioService()); if (ringerMode == AudioManager.RINGER_MODE_NORMAL) { boolean vibrateSetting = am.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER) == AudioManager.VIBRATE_SETTING_ON; am.setRingerMode(vibrateSetting ? AudioManager.RINGER_MODE_VIBRATE : AudioManager.RINGER_MODE_SILENT); } else { am.setRingerMode(AudioManager.RINGER_MODE_NORMAL); } volumePanel.postVolumeChanged(AudioManager.STREAM_RING,AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_VIBRATE); } }; Runnable mBackLongPress = new Runnable() { public void run() { try { Loading Loading @@ -1633,21 +1678,34 @@ public class PhoneWindowManager implements WindowManagerPolicy { + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed); } // If we think we might have a volume down & power key chord on the way // If we think we might have a volume down & power/volume-up key chord on the way // but we're not sure, then tell the dispatcher to wait a little while and // try again later before dispatching. if ((flags & KeyEvent.FLAG_FALLBACK) == 0) { if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) { if (mVolumeDownKeyTriggered && !mPowerKeyTriggered && !mVolumeUpKeyTriggered) { final long now = SystemClock.uptimeMillis(); final long timeoutTime = mVolumeDownKeyTime + ACTION_CHORD_DEBOUNCE_DELAY_MILLIS; if (now < timeoutTime) { return timeoutTime - now; } } else if (mVolumeUpKeyTriggered && !mVolumeDownKeyTriggered) { final long now = SystemClock.uptimeMillis(); final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; final long timeoutTime = mVolumeUpKeyTime + ACTION_CHORD_DEBOUNCE_DELAY_MILLIS; if (now < timeoutTime) { return timeoutTime - now; } } if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN && mVolumeDownKeyConsumedByScreenshotChord) { && mVolumeDownKeyConsumedByChord) { if (!down) { mVolumeDownKeyConsumedByChord = false; } return -1; } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && mVolumeUpKeyConsumedByChord) { if (!down) { mVolumeDownKeyConsumedByScreenshotChord = false; mVolumeUpKeyConsumedByChord = false; } return -1; } Loading Loading @@ -2989,25 +3047,31 @@ public class PhoneWindowManager implements WindowManagerPolicy { && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { mVolumeDownKeyTriggered = true; mVolumeDownKeyTime = event.getDownTime(); mVolumeDownKeyConsumedByScreenshotChord = false; mVolumeDownKeyConsumedByChord = false; cancelPendingPowerKeyAction(); interceptScreenshotChord(); interceptRingerChord(); } } else { mVolumeDownKeyTriggered = false; cancelPendingScreenshotChordAction(); cancelPendingRingerChordAction(); } } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { if (down) { if (isScreenOn && !mVolumeUpKeyTriggered && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { mVolumeUpKeyTriggered = true; mVolumeUpKeyTime = event.getDownTime(); mVolumeUpKeyConsumedByChord = false; cancelPendingPowerKeyAction(); cancelPendingScreenshotChordAction(); interceptRingerChord(); } } else { mVolumeUpKeyTriggered = false; cancelPendingScreenshotChordAction(); cancelPendingRingerChordAction(); } } if (down) { Loading Loading @@ -3084,6 +3148,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { mPowerKeyTriggered = true; mPowerKeyTime = event.getDownTime(); cancelPendingRingerChordAction(); interceptScreenshotChord(); } Loading Loading
policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +76 −11 Original line number Diff line number Diff line /* * Copyright (C) 2006 The Android Open Source Project * Copyright (C) 2012 The CyanogenMod Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading Loading @@ -60,6 +61,7 @@ import android.provider.Settings; import com.android.internal.R; import com.android.internal.app.ShutdownThread; import com.android.internal.app.ThemeUtils; import com.android.internal.os.DeviceKeyHandler; import com.android.internal.policy.PolicyManager; import com.android.internal.statusbar.IStatusBarService; Loading Loading @@ -138,8 +140,11 @@ import android.view.KeyCharacterMap.FallbackAction; import android.view.accessibility.AccessibilityEvent; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.view.VolumePanel; import android.widget.Toast; import android.media.IAudioService; import android.media.AudioService; import android.media.AudioManager; import java.io.File; Loading Loading @@ -463,10 +468,12 @@ 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 ACTION_CHORD_DEBOUNCE_DELAY_MILLIS = 150; private boolean mVolumeDownKeyTriggered; private long mVolumeDownKeyTime; private boolean mVolumeDownKeyConsumedByScreenshotChord; private long mVolumeUpKeyTime; private boolean mVolumeDownKeyConsumedByChord; private boolean mVolumeUpKeyConsumedByChord; private boolean mVolumeUpKeyTriggered; private boolean mPowerKeyTriggered; private long mPowerKeyTime; Loading Loading @@ -686,9 +693,9 @@ public class PhoneWindowManager implements WindowManagerPolicy { private void interceptScreenshotChord() { if (mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) { final long now = SystemClock.uptimeMillis(); if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { mVolumeDownKeyConsumedByScreenshotChord = true; if (now <= mVolumeDownKeyTime + ACTION_CHORD_DEBOUNCE_DELAY_MILLIS && now <= mPowerKeyTime + ACTION_CHORD_DEBOUNCE_DELAY_MILLIS) { mVolumeDownKeyConsumedByChord = true; cancelPendingPowerKeyAction(); mHandler.postDelayed(mScreenshotChordLongPress, Loading @@ -701,6 +708,24 @@ public class PhoneWindowManager implements WindowManagerPolicy { mHandler.removeCallbacks(mScreenshotChordLongPress); } private void interceptRingerChord() { if (mVolumeDownKeyTriggered && !mPowerKeyTriggered && mVolumeUpKeyTriggered) { final long now = SystemClock.uptimeMillis(); if (now <= mVolumeDownKeyTime + ACTION_CHORD_DEBOUNCE_DELAY_MILLIS && now <= mVolumeUpKeyTime + ACTION_CHORD_DEBOUNCE_DELAY_MILLIS) { mVolumeDownKeyConsumedByChord = true; mVolumeUpKeyConsumedByChord = true; mHandler.postDelayed(mRingerChordLongPress, ViewConfiguration.getGlobalActionKeyTimeout()); } } } private void cancelPendingRingerChordAction() { mHandler.removeCallbacks(mRingerChordLongPress); } private final Runnable mPowerLongPress = new Runnable() { public void run() { // The context isn't read Loading Loading @@ -733,6 +758,26 @@ public class PhoneWindowManager implements WindowManagerPolicy { } }; private final Runnable mRingerChordLongPress = new Runnable() { public void run() { // Do the switch final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE); final int ringerMode = am.getRingerMode(); final VolumePanel volumePanel = new VolumePanel(ThemeUtils.createUiContext(mContext), (AudioService) getAudioService()); if (ringerMode == AudioManager.RINGER_MODE_NORMAL) { boolean vibrateSetting = am.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER) == AudioManager.VIBRATE_SETTING_ON; am.setRingerMode(vibrateSetting ? AudioManager.RINGER_MODE_VIBRATE : AudioManager.RINGER_MODE_SILENT); } else { am.setRingerMode(AudioManager.RINGER_MODE_NORMAL); } volumePanel.postVolumeChanged(AudioManager.STREAM_RING,AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_VIBRATE); } }; Runnable mBackLongPress = new Runnable() { public void run() { try { Loading Loading @@ -1633,21 +1678,34 @@ public class PhoneWindowManager implements WindowManagerPolicy { + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed); } // If we think we might have a volume down & power key chord on the way // If we think we might have a volume down & power/volume-up key chord on the way // but we're not sure, then tell the dispatcher to wait a little while and // try again later before dispatching. if ((flags & KeyEvent.FLAG_FALLBACK) == 0) { if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) { if (mVolumeDownKeyTriggered && !mPowerKeyTriggered && !mVolumeUpKeyTriggered) { final long now = SystemClock.uptimeMillis(); final long timeoutTime = mVolumeDownKeyTime + ACTION_CHORD_DEBOUNCE_DELAY_MILLIS; if (now < timeoutTime) { return timeoutTime - now; } } else if (mVolumeUpKeyTriggered && !mVolumeDownKeyTriggered) { final long now = SystemClock.uptimeMillis(); final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; final long timeoutTime = mVolumeUpKeyTime + ACTION_CHORD_DEBOUNCE_DELAY_MILLIS; if (now < timeoutTime) { return timeoutTime - now; } } if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN && mVolumeDownKeyConsumedByScreenshotChord) { && mVolumeDownKeyConsumedByChord) { if (!down) { mVolumeDownKeyConsumedByChord = false; } return -1; } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && mVolumeUpKeyConsumedByChord) { if (!down) { mVolumeDownKeyConsumedByScreenshotChord = false; mVolumeUpKeyConsumedByChord = false; } return -1; } Loading Loading @@ -2989,25 +3047,31 @@ public class PhoneWindowManager implements WindowManagerPolicy { && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { mVolumeDownKeyTriggered = true; mVolumeDownKeyTime = event.getDownTime(); mVolumeDownKeyConsumedByScreenshotChord = false; mVolumeDownKeyConsumedByChord = false; cancelPendingPowerKeyAction(); interceptScreenshotChord(); interceptRingerChord(); } } else { mVolumeDownKeyTriggered = false; cancelPendingScreenshotChordAction(); cancelPendingRingerChordAction(); } } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { if (down) { if (isScreenOn && !mVolumeUpKeyTriggered && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { mVolumeUpKeyTriggered = true; mVolumeUpKeyTime = event.getDownTime(); mVolumeUpKeyConsumedByChord = false; cancelPendingPowerKeyAction(); cancelPendingScreenshotChordAction(); interceptRingerChord(); } } else { mVolumeUpKeyTriggered = false; cancelPendingScreenshotChordAction(); cancelPendingRingerChordAction(); } } if (down) { Loading Loading @@ -3084,6 +3148,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { mPowerKeyTriggered = true; mPowerKeyTime = event.getDownTime(); cancelPendingRingerChordAction(); interceptScreenshotChord(); } Loading