Do not force screen on when undocking from the desk dock.

The fact that the phone is losing power will do this anyway,
and this fixes (or works around) bug b/2250075
(Desk dock clock app sometimes doesn't exit when removing a sleeping droid from the dock)

Change-Id: I7b8b6cfb44ca16d2d9eb67589cb9d9a108a8de82
Signed-off-by: Mike Lockwood <lockwood@android.com>
diff --git a/services/java/com/android/server/DockObserver.java b/services/java/com/android/server/DockObserver.java
index f089de1..c2b1b96 100644
--- a/services/java/com/android/server/DockObserver.java
+++ b/services/java/com/android/server/DockObserver.java
@@ -111,8 +111,17 @@
             try {
                 int newState = Integer.parseInt(event.get("SWITCH_STATE"));
                 if (newState != mDockState) {
+                    int oldState = mDockState;
                     mDockState = newState;
                     if (mSystemReady) {
+                        // Don't force screen on when undocking from the desk dock.
+                        // The change in power state will do this anyway.
+                        // FIXME - we should be configurable.
+                        if (oldState != Intent.EXTRA_DOCK_STATE_DESK ||
+                                newState != Intent.EXTRA_DOCK_STATE_UNDOCKED) {
+                            mPowerManager.userActivityWithForce(SystemClock.uptimeMillis(),
+                                    false, true);
+                        }
                         update();
                     }
                 }
@@ -166,7 +175,6 @@
                     return;
                 }
                 // Pack up the values and broadcast them to everyone
-                mPowerManager.userActivityWithForce(SystemClock.uptimeMillis(), false, true);
                 Intent intent = new Intent(Intent.ACTION_DOCK_EVENT);
                 intent.putExtra(Intent.EXTRA_DOCK_STATE, mDockState);