From ffe2ab43f8ba77418bc3f5facbce6411de3208f9 Mon Sep 17 00:00:00 2001 From: The Android Open Source Project Date: Thu, 19 Feb 2009 10:57:35 -0800 Subject: [PATCH] auto import from //branches/cupcake/...@132276 --- .../policy/impl/AccountUnlockScreen.java | 7 +- .../policy/impl/PhoneWindowManager.java | 122 ++++++++++++++---- .../internal/policy/impl/UnlockScreen.java | 7 +- 3 files changed, 107 insertions(+), 29 deletions(-) diff --git a/policy/com/android/internal/policy/impl/AccountUnlockScreen.java b/policy/com/android/internal/policy/impl/AccountUnlockScreen.java index 573622f32ee9b..b5a144ec604dd 100644 --- a/policy/com/android/internal/policy/impl/AccountUnlockScreen.java +++ b/policy/com/android/internal/policy/impl/AccountUnlockScreen.java @@ -56,6 +56,11 @@ public class AccountUnlockScreen extends RelativeLayout implements KeyguardScree private static final String LOCK_PATTERN_CLASS = "com.android.settings.ChooseLockPattern"; + /** + * The amount of millis to stay awake once this screen detects activity + */ + private static final int AWAKE_POKE_MILLIS = 30000; + private final KeyguardScreenCallback mCallback; private final LockPatternUtils mLockPatternUtils; private IAccountsService mAccountsService; @@ -116,7 +121,7 @@ public class AccountUnlockScreen extends RelativeLayout implements KeyguardScree } public void onTextChanged(CharSequence s, int start, int before, int count) { - mCallback.pokeWakelock(); + mCallback.pokeWakelock(AWAKE_POKE_MILLIS); } @Override diff --git a/policy/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/com/android/internal/policy/impl/PhoneWindowManager.java index e76ce548113f0..7b1819df3d73f 100644 --- a/policy/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/policy/com/android/internal/policy/impl/PhoneWindowManager.java @@ -52,7 +52,7 @@ import android.view.HapticFeedbackConstants; import android.view.IWindowManager; import android.view.KeyEvent; import android.view.MotionEvent; -import android.view.OrientationListener; +import android.view.WindowOrientationListener; import android.view.RawInputEvent; import android.view.Surface; import android.view.View; @@ -141,7 +141,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { // Vibrator pattern for haptic feedback of a long press. private static final long[] LONG_PRESS_VIBE_PATTERN = {0, 1, 40, 41}; // Vibrator pattern for haptic feedback of a zoom ring tick - private static final long[] ZOOM_RING_TICK_VIBE_PATTERN = {0, 1, 40, 41}; + private static final long[] ZOOM_RING_TICK_VIBE_PATTERN = {0, 10}; Context mContext; IWindowManager mWindowManager; @@ -254,33 +254,47 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } - class MyOrientationListener extends OrientationListener { - + class MyOrientationListener extends WindowOrientationListener { + private static final int _LOWER_THRESHOLD = 30; + private static final int _UPPER_THRESHOLD = 60; + MyOrientationListener(Context context) { super(context); } @Override public void onOrientationChanged(int orientation) { - // ignore orientation changes unless the value is in a range that - // matches portrait or landscape - // portrait range is 270+45 to 359 and 0 to 45 - // landscape range is 270-45 to 270+45 - if ((orientation >= 0 && orientation <= 45) || (orientation >= 270 - 45)) { - int rotation = (orientation >= 270 - 45 - && orientation <= 270 + 45) + // ignore orientation changes unless the value is in a range + // When switching from portrait to landscape try to use a lower threshold limit + // Use upper threshold limit when switching from landscape to portrait + // this is to delay the switch as much as we can + int rotation; + int threshold = (mSensorRotation == Surface.ROTATION_90) ? _UPPER_THRESHOLD : + _LOWER_THRESHOLD; + + if ((orientation >= 0 && orientation <= _UPPER_THRESHOLD) || + (orientation >= 270 - _LOWER_THRESHOLD)) { + rotation = (orientation >= 270 - _LOWER_THRESHOLD + && orientation <= 270 + threshold) ? Surface.ROTATION_90 : Surface.ROTATION_0; - if (rotation != mSensorRotation) { - if(localLOGV) Log.i(TAG, "onOrientationChanged, rotation changed from "+rotation+" to "+mSensorRotation); - // Update window manager. The lid rotation hasn't changed, - // but we want it to re-evaluate the final rotation in case - // it needs to call back and get the sensor orientation. - mSensorRotation = rotation; - try { - mWindowManager.setRotation(rotation, false); - } catch (RemoteException e) { - // Ignore - } + } else if (orientation == WindowOrientationListener.ORIENTATION_FLAT) { + // return portrait + rotation = Surface.ROTATION_0; + } else { + // ignore orientation value + return; + } + // Send updates based on orientation value + if (rotation != mSensorRotation) { + if(localLOGV) Log.i(TAG, "onOrientationChanged, rotation changed from "+rotation+" to "+mSensorRotation); + // Update window manager. The lid rotation hasn't changed, + // but we want it to re-evaluate the final rotation in case + // it needs to call back and get the sensor orientation. + mSensorRotation = rotation; + try { + mWindowManager.setRotation(rotation, false); + } catch (RemoteException e) { + // Ignore } } } @@ -1355,6 +1369,11 @@ public class PhoneWindowManager implements WindowManagerPolicy { final boolean isWakeKey = isWakeKeyTq(event); final boolean keyguardShowing = keyguardIsShowingTq(); + if (false) { + Log.d(TAG, "interceptKeyTq event=" + event + " keycode=" + event.keycode + + " screenIsOn=" + screenIsOn + " keyguardShowing=" + keyguardShowing); + } + if (keyguardShowing) { if (screenIsOn) { // when the screen is on, always give the event to the keyguard @@ -1458,6 +1477,65 @@ public class PhoneWindowManager implements WindowManagerPolicy { mBroadcastWakeLock.acquire(); mHandler.post(new PassHeadsetKey(keyEvent)); } + } else if (code == KeyEvent.KEYCODE_CALL) { + // If an incoming call is ringing, answer it! + // (We handle this key here, rather than in the InCallScreen, to make + // sure we'll respond to the key even if the InCallScreen hasn't come to + // the foreground yet.) + + // We answer the call on the DOWN event, to agree with + // the "fallback" behavior in the InCallScreen. + if (down) { + try { + ITelephony phoneServ = getPhoneInterface(); + if (phoneServ != null) { + if (phoneServ.isRinging()) { + Log.i(TAG, "interceptKeyTq:" + + " CALL key-down while ringing: Answer the call!"); + phoneServ.answerRingingCall(); + + // And *don't* pass this key thru to the current activity + // (which is presumably the InCallScreen.) + result &= ~ACTION_PASS_TO_USER; + } + } else { + Log.w(TAG, "CALL button: Unable to find ITelephony interface"); + } + } catch (RemoteException ex) { + Log.w(TAG, "CALL button: RemoteException from getPhoneInterface()", ex); + } + } + } else if ((code == KeyEvent.KEYCODE_VOLUME_UP) + || (code == KeyEvent.KEYCODE_VOLUME_DOWN)) { + // If an incoming call is ringing, either VOLUME key means + // "silence ringer". We handle these keys here, rather than + // in the InCallScreen, to make sure we'll respond to them + // even if the InCallScreen hasn't come to the foreground yet. + + // Look for the DOWN event here, to agree with the "fallback" + // behavior in the InCallScreen. + if (down) { + try { + ITelephony phoneServ = getPhoneInterface(); + if (phoneServ != null) { + if (phoneServ.isRinging()) { + Log.i(TAG, "interceptKeyTq:" + + " VOLUME key-down while ringing: Silence ringer!"); + // Silence the ringer. (It's safe to call this + // even if the ringer has already been silenced.) + phoneServ.silenceRinger(); + + // And *don't* pass this key thru to the current activity + // (which is probably the InCallScreen.) + result &= ~ACTION_PASS_TO_USER; + } + } else { + Log.w(TAG, "VOLUME button: Unable to find ITelephony interface"); + } + } catch (RemoteException ex) { + Log.w(TAG, "VOLUME button: RemoteException from getPhoneInterface()", ex); + } + } } } diff --git a/policy/com/android/internal/policy/impl/UnlockScreen.java b/policy/com/android/internal/policy/impl/UnlockScreen.java index 16208d9c4d27d..51e3621f368a7 100644 --- a/policy/com/android/internal/policy/impl/UnlockScreen.java +++ b/policy/com/android/internal/policy/impl/UnlockScreen.java @@ -16,14 +16,10 @@ package com.android.internal.policy.impl; -import android.content.ComponentName; import android.content.Context; import android.content.ServiceConnection; import android.os.CountDownTimer; -import android.os.IBinder; -import android.os.RemoteException; import android.os.SystemClock; -import android.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; @@ -304,8 +300,7 @@ class UnlockScreen extends LinearLayoutWithDefaultTouchRecepient mCallback.reportFailedPatternAttempt(); } if (mFailedPatternAttemptsSinceLastTimeout >= LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT) { - long deadline = SystemClock.elapsedRealtime() + LockPatternUtils.FAILED_ATTEMPT_TIMEOUT_MS; - mLockPatternUtils.setLockoutAttemptDeadline(deadline); + long deadline = mLockPatternUtils.setLockoutAttemptDeadline(); handleAttemptLockout(deadline); return; }