blob: a6037aa131e96b6855c697180da20f634d0cdb0a [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.internal.policy.impl;
18
19import android.app.Activity;
20import android.app.ActivityManagerNative;
21import android.app.IActivityManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080022import android.app.IUiModeManager;
23import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070024import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080025import android.content.BroadcastReceiver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080026import android.content.ContentResolver;
27import android.content.Context;
28import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070029import android.content.IntentFilter;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080030import android.content.pm.ActivityInfo;
31import android.content.pm.PackageManager;
32import android.content.res.Configuration;
33import android.content.res.Resources;
34import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080035import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080036import android.graphics.Rect;
Dianne Hackborn247fe742011-01-08 17:25:57 -080037import android.os.Build;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080038import android.os.Handler;
39import android.os.IBinder;
40import android.os.LocalPowerManager;
41import android.os.PowerManager;
42import android.os.RemoteException;
43import android.os.ServiceManager;
44import android.os.SystemClock;
45import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080046import android.os.UEventObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080047import android.os.Vibrator;
48import android.provider.Settings;
49
Jim Millere6ad1a82010-08-20 19:25:39 -070050import com.android.internal.R;
Joe Onoratod208e702010-10-08 16:22:43 -040051import com.android.internal.app.ShutdownThread;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080052import com.android.internal.policy.PolicyManager;
Joe Onorato0cbda992010-05-02 16:28:15 -070053import com.android.internal.statusbar.IStatusBarService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080054import com.android.internal.telephony.ITelephony;
Jeff Browna41ca772010-08-11 14:46:32 -070055import com.android.internal.view.BaseInputHandler;
Dianne Hackborn6019c9d2010-03-01 21:43:11 -080056import com.android.internal.widget.PointerLocationView;
57
Jeff Brown4d396052010-10-29 21:50:21 -070058import android.telephony.TelephonyManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080059import android.util.Config;
60import android.util.EventLog;
61import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070062import android.util.Slog;
Mitsuru Oshima831d0d92009-06-16 18:27:18 -070063import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080064import android.view.Gravity;
65import android.view.HapticFeedbackConstants;
66import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070067import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070068import android.view.InputDevice;
Jeff Browna41ca772010-08-11 14:46:32 -070069import android.view.InputQueue;
70import android.view.InputHandler;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080071import android.view.KeyCharacterMap;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080072import android.view.KeyEvent;
73import android.view.MotionEvent;
74import android.view.WindowOrientationListener;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080075import android.view.Surface;
76import android.view.View;
77import android.view.ViewConfiguration;
78import android.view.Window;
79import android.view.WindowManager;
80import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
81import static android.view.WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN;
82import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN;
83import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
84import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR;
85import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -070086import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070087import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Mike Lockwood28569302010-01-28 11:54:40 -050088import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080089import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
90import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Dianne Hackborndea3ef72010-10-28 14:24:22 -070091import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080092import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
93import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -070094import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080095import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
96import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL;
97import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Christopher Tatea53146c2010-09-07 11:57:52 -070098import static android.view.WindowManager.LayoutParams.TYPE_DRAG;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080099import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD;
100import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
101import static android.view.WindowManager.LayoutParams.TYPE_PHONE;
102import static android.view.WindowManager.LayoutParams.TYPE_PRIORITY_PHONE;
103import static android.view.WindowManager.LayoutParams.TYPE_SEARCH_BAR;
Jeff Brown3b2b3542010-10-15 00:54:27 -0700104import static android.view.WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800105import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
106import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL;
Joe Onorato29fc2c92010-11-24 10:26:50 -0800107import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL;
Dianne Hackborn6a294ce2009-12-03 11:37:44 -0800108import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800109import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
110import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
111import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
112import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
113import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
114import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -0700115import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Jeff Brown83c09682010-12-23 17:50:18 -0800116import static android.view.WindowManager.LayoutParams.TYPE_POINTER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800117import android.view.WindowManagerImpl;
118import android.view.WindowManagerPolicy;
Dianne Hackborn01ad2f42009-09-24 19:24:56 -0700119import android.view.animation.Animation;
120import android.view.animation.AnimationUtils;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800121import android.media.IAudioService;
122import android.media.AudioManager;
123
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800124import java.io.File;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800125import java.io.FileDescriptor;
Joe Onoratodc100302011-01-11 17:07:41 -0800126import java.io.FileReader;
127import java.io.IOException;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800128import java.io.PrintWriter;
Dianne Hackborn08743722009-12-21 12:16:51 -0800129import java.util.ArrayList;
130
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800131/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700132 * WindowManagerPolicy implementation for the Android phone UI. This
133 * introduces a new method suffix, Lp, for an internal lock of the
134 * PhoneWindowManager. This is used to protect some internal state, and
135 * can be acquired with either thw Lw and Li lock held, so has the restrictions
136 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800137 */
138public class PhoneWindowManager implements WindowManagerPolicy {
139 static final String TAG = "WindowManager";
140 static final boolean DEBUG = false;
141 static final boolean localLOGV = DEBUG ? Config.LOGD : Config.LOGV;
The Android Open Source Project11267662009-03-18 17:39:47 -0700142 static final boolean DEBUG_LAYOUT = false;
Jeff Brown49ed71d2010-12-06 17:13:33 -0800143 static final boolean DEBUG_FALLBACK = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800144 static final boolean SHOW_STARTING_ANIMATIONS = true;
145 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400146
147 static final int LONG_PRESS_POWER_NOTHING = 0;
148 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
149 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800150
Joe Onorato46b0d682010-11-22 17:37:27 -0800151 static final int LONG_PRESS_HOME_NOTHING = 0;
152 static final int LONG_PRESS_HOME_RECENT_DIALOG = 1;
153 static final int LONG_PRESS_HOME_RECENT_ACTIVITY = 2;
154
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -0700155 // wallpaper is at the bottom, though the window manager may move it.
Dianne Hackborn3c3bd442009-08-19 17:09:46 -0700156 static final int WALLPAPER_LAYER = 2;
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -0700157 static final int APPLICATION_LAYER = 2;
158 static final int PHONE_LAYER = 3;
159 static final int SEARCH_BAR_LAYER = 4;
Joe Onorato29fc2c92010-11-24 10:26:50 -0800160 static final int STATUS_BAR_SUB_PANEL_LAYER = 5;
Dianne Hackborn6a294ce2009-12-03 11:37:44 -0800161 static final int SYSTEM_DIALOG_LAYER = 6;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800162 // toasts and the plugged-in battery thing
Dianne Hackborn6a294ce2009-12-03 11:37:44 -0800163 static final int TOAST_LAYER = 7;
164 static final int STATUS_BAR_LAYER = 8;
Joe Onorato29fc2c92010-11-24 10:26:50 -0800165 static final int STATUS_BAR_PANEL_LAYER = 9;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800166 // SIM errors and unlock. Not sure if this really should be in a high layer.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800167 static final int PRIORITY_PHONE_LAYER = 10;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800168 // like the ANR / app crashed dialogs
Joe Onorato29fc2c92010-11-24 10:26:50 -0800169 static final int SYSTEM_ALERT_LAYER = 11;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800170 // system-level error dialogs
Joe Onorato29fc2c92010-11-24 10:26:50 -0800171 static final int SYSTEM_ERROR_LAYER = 12;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800172 // on-screen keyboards and other such input method user interfaces go here.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800173 static final int INPUT_METHOD_LAYER = 13;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800174 // on-screen keyboards and other such input method user interfaces go here.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800175 static final int INPUT_METHOD_DIALOG_LAYER = 14;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800176 // the keyguard; nothing on top of these can take focus, since they are
177 // responsible for power management when displayed.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800178 static final int KEYGUARD_LAYER = 15;
179 static final int KEYGUARD_DIALOG_LAYER = 16;
Christopher Tatea53146c2010-09-07 11:57:52 -0700180 // the drag layer: input for drag-and-drop is associated with this window,
181 // which sits above all other focusable windows
Joe Onorato29fc2c92010-11-24 10:26:50 -0800182 static final int DRAG_LAYER = 17;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800183 // things in here CAN NOT take focus, but are shown on top of everything else.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800184 static final int SYSTEM_OVERLAY_LAYER = 18;
185 static final int SECURE_SYSTEM_OVERLAY_LAYER = 19;
Jeff Brown83c09682010-12-23 17:50:18 -0800186 // the (mouse) pointer layer
187 static final int POINTER_LAYER = 20;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800188
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700189 static final int APPLICATION_MEDIA_SUBLAYER = -2;
190 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800191 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800192 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800193
194 // Debugging: set this to have the system act like there is no hard keyboard.
195 static final boolean KEYBOARD_ALWAYS_HIDDEN = false;
196
197 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
198 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
199 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500200 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800201
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700202 // Useful scan codes.
203 private static final int SW_LID = 0x00;
204 private static final int BTN_MOUSE = 0x110;
205
The Android Open Source Project0727d222009-03-11 12:11:58 -0700206 final Object mLock = new Object();
207
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800208 Context mContext;
209 IWindowManager mWindowManager;
210 LocalPowerManager mPowerManager;
Joe Onorato93056472010-09-10 10:30:46 -0400211 IStatusBarService mStatusBarService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800212 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
213
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700214 // Vibrator pattern for haptic feedback of a long press.
215 long[] mLongPressVibePattern;
216
217 // Vibrator pattern for haptic feedback of virtual key press.
218 long[] mVirtualKeyVibePattern;
219
Amith Yamasanic33cb712010-02-10 15:21:49 -0800220 // Vibrator pattern for a short vibration.
221 long[] mKeyboardTapVibePattern;
222
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700223 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
224 long[] mSafeModeDisabledVibePattern;
225
226 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
227 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700228
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800229 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
230 boolean mEnableShiftMenuBugReports = false;
231
232 boolean mSafeMode;
233 WindowState mStatusBar = null;
Daniel Sandler40427442010-07-16 11:44:52 -0400234 boolean mStatusBarCanHide;
Dianne Hackborn08743722009-12-21 12:16:51 -0800235 final ArrayList<WindowState> mStatusBarPanels = new ArrayList<WindowState>();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800236 WindowState mKeyguard = null;
237 KeyguardViewMediator mKeyguardMediator;
238 GlobalActions mGlobalActions;
Jeff Brown4d396052010-10-29 21:50:21 -0700239 volatile boolean mPowerKeyHandled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800240 RecentApplicationsDialog mRecentAppsDialog;
241 Handler mHandler;
Dianne Hackborn05726582009-09-22 17:28:24 -0700242
Dianne Hackbornc777e072010-02-12 13:07:59 -0800243 boolean mSystemReady;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800244 boolean mLidOpen;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800245 boolean mHdmiPlugged;
Dianne Hackborn78968392010-03-04 20:47:56 -0800246 int mUiMode = Configuration.UI_MODE_TYPE_NORMAL;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700247 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700248 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400249 int mCarDockRotation;
250 int mDeskDockRotation;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400251
252 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
253 int mUserRotation = Surface.ROTATION_0;
254
Dianne Hackborna1111872010-11-23 20:55:11 -0800255 boolean mAllowAllRotations;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400256 boolean mCarDockEnablesAccelerometer;
257 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700258 int mLidKeyboardAccessibility;
259 int mLidNavigationAccessibility;
Joe Onoratod208e702010-10-08 16:22:43 -0400260 int mLongPressOnPowerBehavior = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800261 boolean mScreenOn = false;
262 boolean mOrientationSensorEnabled = false;
263 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
264 static final int DEFAULT_ACCELEROMETER_ROTATION = 0;
265 int mAccelerometerDefault = DEFAULT_ACCELEROMETER_ROTATION;
266 boolean mHasSoftInput = false;
267
Dianne Hackbornc777e072010-02-12 13:07:59 -0800268 int mPointerLocationMode = 0;
269 PointerLocationView mPointerLocationView = null;
Jeff Browna41ca772010-08-11 14:46:32 -0700270 InputChannel mPointerLocationInputChannel;
271
272 private final InputHandler mPointerLocationInputHandler = new BaseInputHandler() {
273 @Override
Jeff Brown3915bb82010-11-05 15:02:16 -0700274 public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) {
275 boolean handled = false;
276 try {
277 if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
278 synchronized (mLock) {
279 if (mPointerLocationView != null) {
280 mPointerLocationView.addTouchEvent(event);
281 handled = true;
282 }
283 }
Jeff Brown93ed4e32010-09-23 13:51:48 -0700284 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700285 } finally {
286 finishedCallback.finished(handled);
Jeff Browna41ca772010-08-11 14:46:32 -0700287 }
288 }
289 };
Dianne Hackbornc777e072010-02-12 13:07:59 -0800290
Joe Onorato29fc2c92010-11-24 10:26:50 -0800291 // The current size of the screen; really; (ir)regardless of whether the status
292 // bar can be hidden or not
293 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
294 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700295 // The current size of the screen; these may be different than (0,0)-(dw,dh)
296 // if the status bar can't be hidden; in that case it effectively carves out
297 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800298 int mRestrictedScreenLeft, mRestrictedScreenTop;
299 int mRestrictedScreenWidth, mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800300 // During layout, the current screen borders with all outer decoration
301 // (status bar, input method dock) accounted for.
302 int mCurLeft, mCurTop, mCurRight, mCurBottom;
303 // During layout, the frame in which content should be displayed
304 // to the user, accounting for all screen decoration except for any
305 // space they deem as available for other content. This is usually
306 // the same as mCur*, but may be larger if the screen decor has supplied
307 // content insets.
308 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800309 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800310 // windows are placed.
311 int mDockLeft, mDockTop, mDockRight, mDockBottom;
312 // During layout, the layer at which the doc window is placed.
313 int mDockLayer;
314
315 static final Rect mTmpParentFrame = new Rect();
316 static final Rect mTmpDisplayFrame = new Rect();
317 static final Rect mTmpContentFrame = new Rect();
318 static final Rect mTmpVisibleFrame = new Rect();
319
320 WindowState mTopFullscreenOpaqueWindowState;
Joe Onorato93056472010-09-10 10:30:46 -0400321 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800322 boolean mForceStatusBar;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700323 boolean mHideLockScreen;
324 boolean mDismissKeyguard;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800325 boolean mHomePressed;
326 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700327 Intent mCarDockIntent;
328 Intent mDeskDockIntent;
Jeff Brown49ed71d2010-12-06 17:13:33 -0800329 int mShortcutKeyPressed = -1;
330 boolean mConsumeShortcutKeyUp;
Daniel Sandlere02d8082010-10-08 15:13:22 -0400331 boolean mShowMenuKey = false; // track FLAG_NEEDS_MENU_KEY on frontmost window
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800332
Mike Lockwood28569302010-01-28 11:54:40 -0500333 // support for activating the lock screen while the screen is on
334 boolean mAllowLockscreenWhenOn;
335 int mLockScreenTimeout;
336 boolean mLockScreenTimerActive;
337
David Brownbaf8d092010-03-08 21:52:59 -0800338 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800339 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800340
341 // Behavior of POWER button while in-call and screen on.
342 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
343 int mIncallPowerBehavior;
344
Steve Howarda7bfe6a2010-09-23 16:47:49 -0700345 int mLandscapeRotation = -1; // default landscape rotation
346 int mSeascapeRotation = -1; // "other" landscape rotation, 180 degrees from mLandscapeRotation
Dianne Hackborne5439f22010-10-02 16:53:50 -0700347 int mPortraitRotation = -1; // default portrait rotation
348 int mUpsideDownRotation = -1; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700349
Dianne Hackborn03759ed2009-03-27 16:04:08 -0700350 // Nothing to see here, move along...
351 int mFancyRotationAnimation;
Jim Milleree969aa2010-08-26 20:17:43 -0700352
Joe Onorato46b0d682010-11-22 17:37:27 -0800353 // What we do when the user long presses on home
354 private int mLongPressOnHomeBehavior = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800355
356 ShortcutManager mShortcutManager;
357 PowerManager.WakeLock mBroadcastWakeLock;
358
Jeff Brown49ed71d2010-12-06 17:13:33 -0800359 final KeyCharacterMap.FallbackAction mFallbackAction = new KeyCharacterMap.FallbackAction();
360
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800361 private UEventObserver mHDMIObserver = new UEventObserver() {
362 @Override
363 public void onUEvent(UEventObserver.UEvent event) {
364 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
365 }
366 };
367
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800368 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800369 SettingsObserver(Handler handler) {
370 super(handler);
371 }
David Brownbaf8d092010-03-08 21:52:59 -0800372
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800373 void observe() {
374 ContentResolver resolver = mContext.getContentResolver();
375 resolver.registerContentObserver(Settings.System.getUriFor(
376 Settings.System.END_BUTTON_BEHAVIOR), false, this);
David Brownbaf8d092010-03-08 21:52:59 -0800377 resolver.registerContentObserver(Settings.Secure.getUriFor(
378 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800379 resolver.registerContentObserver(Settings.System.getUriFor(
380 Settings.System.ACCELEROMETER_ROTATION), false, this);
Mike Lockwood28569302010-01-28 11:54:40 -0500381 resolver.registerContentObserver(Settings.System.getUriFor(
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400382 Settings.System.USER_ROTATION), false, this);
383 resolver.registerContentObserver(Settings.System.getUriFor(
Mike Lockwood28569302010-01-28 11:54:40 -0500384 Settings.System.SCREEN_OFF_TIMEOUT), false, this);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800385 resolver.registerContentObserver(Settings.System.getUriFor(
386 Settings.System.POINTER_LOCATION), false, this);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800387 resolver.registerContentObserver(Settings.Secure.getUriFor(
388 Settings.Secure.DEFAULT_INPUT_METHOD), false, this);
Dianne Hackborn03759ed2009-03-27 16:04:08 -0700389 resolver.registerContentObserver(Settings.System.getUriFor(
390 "fancy_rotation_anim"), false, this);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800391 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800392 }
393
394 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800395 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800396 try {
Dianne Hackborn32bc91d2009-03-27 16:16:03 -0700397 mWindowManager.setRotation(USE_LAST_ROTATION, false,
398 mFancyRotationAnimation);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800399 } catch (RemoteException e) {
400 // Ignore
401 }
402 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800403 }
404
405 class MyOrientationListener extends WindowOrientationListener {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800406 MyOrientationListener(Context context) {
407 super(context);
408 }
409
410 @Override
The Android Open Source Projectd06b0972009-03-13 13:04:23 -0700411 public void onOrientationChanged(int rotation) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800412 // Send updates based on orientation value
Dianne Hackborn05726582009-09-22 17:28:24 -0700413 if (localLOGV) Log.v(TAG, "onOrientationChanged, rotation changed to " +rotation);
Dianne Hackborn03759ed2009-03-27 16:04:08 -0700414 try {
Dianne Hackborn32bc91d2009-03-27 16:16:03 -0700415 mWindowManager.setRotation(rotation, false,
416 mFancyRotationAnimation);
Dianne Hackborn03759ed2009-03-27 16:04:08 -0700417 } catch (RemoteException e) {
418 // Ignore
Wink Saville37c124c2009-04-02 01:37:02 -0700419
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800420 }
421 }
422 }
423 MyOrientationListener mOrientationListener;
424
Dianne Hackborn03759ed2009-03-27 16:04:08 -0700425 boolean useSensorForOrientationLp(int appOrientation) {
Joe Onorato1b58b3e2009-09-22 16:44:16 -0700426 // The app says use the sensor.
Dianne Hackborne5439f22010-10-02 16:53:50 -0700427 if (appOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
428 || appOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
429 || appOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
430 || appOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800431 return true;
432 }
Joe Onorato1b58b3e2009-09-22 16:44:16 -0700433 // The user preference says we can rotate, and the app is willing to rotate.
434 if (mAccelerometerDefault != 0 &&
435 (appOrientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackborne5439f22010-10-02 16:53:50 -0700436 || appOrientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800437 return true;
438 }
Dianne Hackborne5439f22010-10-02 16:53:50 -0700439 // We're in a dock that has a rotation affinity, and the app is willing to rotate.
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700440 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR)
441 || (mDeskDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_DESK)) {
Joe Onorato1b58b3e2009-09-22 16:44:16 -0700442 // Note we override the nosensor flag here.
443 if (appOrientation == ActivityInfo.SCREEN_ORIENTATION_USER
444 || appOrientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
Dianne Hackborne5439f22010-10-02 16:53:50 -0700445 || appOrientation == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
Joe Onorato1b58b3e2009-09-22 16:44:16 -0700446 return true;
447 }
448 }
449 // Else, don't use the sensor.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800450 return false;
451 }
452
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700453 /*
454 * We always let the sensor be switched on by default except when
455 * the user has explicitly disabled sensor based rotation or when the
456 * screen is switched off.
457 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700458 boolean needSensorRunningLp() {
Dianne Hackborne5439f22010-10-02 16:53:50 -0700459 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
460 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
461 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
462 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800463 // If the application has explicitly requested to follow the
464 // orientation, then we need to turn the sensor or.
465 return true;
466 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700467 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
468 (mDeskDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_DESK)) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400469 // enable accelerometer if we are docked in a dock that enables accelerometer
470 // orientation management,
471 return true;
472 }
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700473 if (mAccelerometerDefault == 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800474 // If the setting for using the sensor by default is enabled, then
475 // we will always leave it on. Note that the user could go to
476 // a window that forces an orientation that does not use the
477 // sensor and in theory we could turn it off... however, when next
478 // turning it on we won't have a good value for the current
479 // orientation for a little bit, which can cause orientation
480 // changes to lag, so we'd like to keep it always on. (It will
481 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700482 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800483 }
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700484 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800485 }
486
487 /*
488 * Various use cases for invoking this function
489 * screen turning off, should always disable listeners if already enabled
490 * screen turned on and current app has sensor based orientation, enable listeners
491 * if not already enabled
492 * screen turned on and current app does not have sensor orientation, disable listeners if
493 * already enabled
494 * screen turning on and current app has sensor based orientation, enable listeners if needed
495 * screen turning on and current app has nosensor based orientation, do nothing
496 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700497 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800498 if (!mOrientationListener.canDetectOrientation()) {
499 // If sensor is turned off or nonexistent for some reason
500 return;
501 }
502 //Could have been invoked due to screen turning on or off or
503 //change of the currently visible window's orientation
Dianne Hackborn05726582009-09-22 17:28:24 -0700504 if (localLOGV) Log.v(TAG, "Screen status="+mScreenOn+
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800505 ", current orientation="+mCurrentAppOrientation+
506 ", SensorEnabled="+mOrientationSensorEnabled);
507 boolean disable = true;
The Android Open Source Project0727d222009-03-11 12:11:58 -0700508 if (mScreenOn) {
509 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800510 disable = false;
511 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700512 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800513 mOrientationListener.enable();
Dianne Hackborn05726582009-09-22 17:28:24 -0700514 if(localLOGV) Log.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800515 mOrientationSensorEnabled = true;
516 }
517 }
518 }
519 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700520 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800521 mOrientationListener.disable();
Dianne Hackborn05726582009-09-22 17:28:24 -0700522 if(localLOGV) Log.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800523 mOrientationSensorEnabled = false;
524 }
525 }
526
Jeff Brown4d396052010-10-29 21:50:21 -0700527 private void interceptPowerKeyDown(boolean handled) {
528 mPowerKeyHandled = handled;
529 if (!handled) {
530 mHandler.postDelayed(mPowerLongPress, ViewConfiguration.getGlobalActionKeyTimeout());
531 }
532 }
533
534 private boolean interceptPowerKeyUp(boolean canceled) {
535 if (!mPowerKeyHandled) {
536 mHandler.removeCallbacks(mPowerLongPress);
537 return !canceled;
538 } else {
539 mPowerKeyHandled = true;
540 return false;
541 }
542 }
543
544 private final Runnable mPowerLongPress = new Runnable() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800545 public void run() {
Jeff Brown4d396052010-10-29 21:50:21 -0700546 if (!mPowerKeyHandled) {
547 // The context isn't read
548 if (mLongPressOnPowerBehavior < 0) {
549 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
550 com.android.internal.R.integer.config_longPressOnPowerBehavior);
551 }
552 switch (mLongPressOnPowerBehavior) {
553 case LONG_PRESS_POWER_NOTHING:
554 break;
555 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
556 mPowerKeyHandled = true;
557 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
558 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
559 showGlobalActionsDialog();
560 break;
561 case LONG_PRESS_POWER_SHUT_OFF:
562 mPowerKeyHandled = true;
563 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
564 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
565 ShutdownThread.shutdown(mContext, true);
566 break;
567 }
Joe Onoratod208e702010-10-08 16:22:43 -0400568 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800569 }
570 };
571
572 void showGlobalActionsDialog() {
573 if (mGlobalActions == null) {
574 mGlobalActions = new GlobalActions(mContext);
575 }
Dianne Hackborn9dc06cc2009-11-17 18:19:23 -0800576 final boolean keyguardShowing = mKeyguardMediator.isShowingAndNotHidden();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800577 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
578 if (keyguardShowing) {
579 // since it took two seconds of long press to bring this up,
580 // poke the wake lock so they have some time to see the dialog.
581 mKeyguardMediator.pokeWakelock();
582 }
583 }
584
585 boolean isDeviceProvisioned() {
586 return Settings.Secure.getInt(
587 mContext.getContentResolver(), Settings.Secure.DEVICE_PROVISIONED, 0) != 0;
588 }
589
590 /**
591 * When a home-key longpress expires, close other system windows and launch the recent apps
592 */
593 Runnable mHomeLongPress = new Runnable() {
594 public void run() {
595 /*
596 * Eat the longpress so it won't dismiss the recent apps dialog when
597 * the user lets go of the home key
598 */
599 mHomePressed = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800600 showRecentAppsDialog();
601 }
602 };
603
604 /**
605 * Create (if necessary) and launch the recent apps dialog
606 */
607 void showRecentAppsDialog() {
Jim Milleree969aa2010-08-26 20:17:43 -0700608 // We can't initialize this in init() since the configuration hasn't been loaded yet.
Joe Onorato46b0d682010-11-22 17:37:27 -0800609 if (mLongPressOnHomeBehavior < 0) {
610 mLongPressOnHomeBehavior
Joe Onorato50262e52010-11-26 14:04:54 -0800611 = mContext.getResources().getInteger(R.integer.config_longPressOnHomeBehavior);
Joe Onorato46b0d682010-11-22 17:37:27 -0800612 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
613 mLongPressOnHomeBehavior > LONG_PRESS_HOME_RECENT_ACTIVITY) {
614 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
615 }
616 }
617
618 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
619 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
620 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS);
Jim Milleree969aa2010-08-26 20:17:43 -0700621 }
622
Joe Onorato46b0d682010-11-22 17:37:27 -0800623 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_DIALOG) {
624 // Fallback to dialog if we fail to launch the above.
625 if (mRecentAppsDialog == null) {
626 mRecentAppsDialog = new RecentApplicationsDialog(mContext);
627 }
628 mRecentAppsDialog.show();
629 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_ACTIVITY) {
Jim Millere6ad1a82010-08-20 19:25:39 -0700630 try {
Jim Milleree969aa2010-08-26 20:17:43 -0700631 Intent intent = new Intent();
632 intent.setClassName("com.android.systemui",
Joe Onorato46b0d682010-11-22 17:37:27 -0800633 "com.android.systemui.recent.RecentApplicationsActivity");
Jim Milleree969aa2010-08-26 20:17:43 -0700634 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
635 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
636 mContext.startActivity(intent);
Jim Millere6ad1a82010-08-20 19:25:39 -0700637 return;
638 } catch (ActivityNotFoundException e) {
639 Log.e(TAG, "Failed to launch RecentAppsIntent", e);
640 }
641 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800642 }
643
644 /** {@inheritDoc} */
645 public void init(Context context, IWindowManager windowManager,
646 LocalPowerManager powerManager) {
647 mContext = context;
648 mWindowManager = windowManager;
649 mPowerManager = powerManager;
650 mKeyguardMediator = new KeyguardViewMediator(context, this, powerManager);
651 mHandler = new Handler();
652 mOrientationListener = new MyOrientationListener(mContext);
653 SettingsObserver settingsObserver = new SettingsObserver(mHandler);
654 settingsObserver.observe();
655 mShortcutManager = new ShortcutManager(context, mHandler);
656 mShortcutManager.observe();
657 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
658 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
659 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
660 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700661 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
662 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
663 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
664 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
665 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
666 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
667 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
668 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -0700669
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800670 PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
671 mBroadcastWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
672 "PhoneWindowManager.mBroadcastWakeLock");
673 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700674 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400675 com.android.internal.R.integer.config_lidOpenRotation);
676 mCarDockRotation = readRotation(
677 com.android.internal.R.integer.config_carDockRotation);
678 mDeskDockRotation = readRotation(
679 com.android.internal.R.integer.config_deskDockRotation);
Dianne Hackborna1111872010-11-23 20:55:11 -0800680 mAllowAllRotations = mContext.getResources().getBoolean(
681 com.android.internal.R.bool.config_allowAllRotations);
Mike Lockwoode9867d22009-09-20 01:59:02 -0400682 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
683 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
684 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
685 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700686 mLidKeyboardAccessibility = mContext.getResources().getInteger(
687 com.android.internal.R.integer.config_lidKeyboardAccessibility);
688 mLidNavigationAccessibility = mContext.getResources().getInteger(
689 com.android.internal.R.integer.config_lidNavigationAccessibility);
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700690 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -0800691 IntentFilter filter = new IntentFilter();
692 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
693 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
694 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
695 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700696 filter.addAction(Intent.ACTION_DOCK_EVENT);
697 Intent intent = context.registerReceiver(mDockReceiver, filter);
698 if (intent != null) {
699 // Retrieve current sticky dock event broadcast.
700 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
701 Intent.EXTRA_DOCK_STATE_UNDOCKED);
702 }
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700703 mVibrator = new Vibrator();
704 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
705 com.android.internal.R.array.config_longPressVibePattern);
706 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
707 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -0800708 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
709 com.android.internal.R.array.config_keyboardTapVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700710 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
711 com.android.internal.R.array.config_safeModeDisabledVibePattern);
712 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
713 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -0400714
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800715 // watch for HDMI plug messages if the hdmi switch exists
716 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
717 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
718 }
Joe Onoratodc100302011-01-11 17:07:41 -0800719 mHdmiPlugged = !readHdmiState();
720 setHdmiPlugged(!mHdmiPlugged);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800721
Daniel Sandler40427442010-07-16 11:44:52 -0400722 // Note: the Configuration is not stable here, so we cannot load mStatusBarCanHide from
723 // config_statusBarCanHide because the latter depends on the screen size
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700724 }
725
Dianne Hackbornc777e072010-02-12 13:07:59 -0800726 public void updateSettings() {
727 ContentResolver resolver = mContext.getContentResolver();
728 boolean updateRotation = false;
729 View addView = null;
730 View removeView = null;
731 synchronized (mLock) {
732 mEndcallBehavior = Settings.System.getInt(resolver,
David Brownbaf8d092010-03-08 21:52:59 -0800733 Settings.System.END_BUTTON_BEHAVIOR,
734 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT);
735 mIncallPowerBehavior = Settings.Secure.getInt(resolver,
736 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
737 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800738 mFancyRotationAnimation = Settings.System.getInt(resolver,
739 "fancy_rotation_anim", 0) != 0 ? 0x80 : 0;
740 int accelerometerDefault = Settings.System.getInt(resolver,
741 Settings.System.ACCELEROMETER_ROTATION, DEFAULT_ACCELEROMETER_ROTATION);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400742
743 // set up rotation lock state
Daniel Sandler1b815d62010-11-05 10:24:27 -0400744 mUserRotationMode = (accelerometerDefault == 0)
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400745 ? WindowManagerPolicy.USER_ROTATION_LOCKED
746 : WindowManagerPolicy.USER_ROTATION_FREE;
747 mUserRotation = Settings.System.getInt(resolver,
748 Settings.System.USER_ROTATION,
749 Surface.ROTATION_0);
750
Dianne Hackbornc777e072010-02-12 13:07:59 -0800751 if (mAccelerometerDefault != accelerometerDefault) {
752 mAccelerometerDefault = accelerometerDefault;
753 updateOrientationListenerLp();
754 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400755
Dianne Hackbornc777e072010-02-12 13:07:59 -0800756 if (mSystemReady) {
757 int pointerLocation = Settings.System.getInt(resolver,
758 Settings.System.POINTER_LOCATION, 0);
759 if (mPointerLocationMode != pointerLocation) {
760 mPointerLocationMode = pointerLocation;
761 if (pointerLocation != 0) {
762 if (mPointerLocationView == null) {
763 mPointerLocationView = new PointerLocationView(mContext);
764 mPointerLocationView.setPrintCoords(false);
765 addView = mPointerLocationView;
766 }
767 } else {
768 removeView = mPointerLocationView;
769 mPointerLocationView = null;
770 }
771 }
772 }
773 // use screen off timeout setting as the timeout for the lockscreen
774 mLockScreenTimeout = Settings.System.getInt(resolver,
775 Settings.System.SCREEN_OFF_TIMEOUT, 0);
776 String imId = Settings.Secure.getString(resolver,
777 Settings.Secure.DEFAULT_INPUT_METHOD);
778 boolean hasSoftInput = imId != null && imId.length() > 0;
779 if (mHasSoftInput != hasSoftInput) {
780 mHasSoftInput = hasSoftInput;
781 updateRotation = true;
782 }
783 }
784 if (updateRotation) {
785 updateRotation(0);
786 }
787 if (addView != null) {
788 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
789 WindowManager.LayoutParams.MATCH_PARENT,
790 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -0700791 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Dianne Hackbornc777e072010-02-12 13:07:59 -0800792 lp.flags =
793 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
794 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
795 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
796 lp.format = PixelFormat.TRANSLUCENT;
797 lp.setTitle("PointerLocation");
798 WindowManagerImpl wm = (WindowManagerImpl)
799 mContext.getSystemService(Context.WINDOW_SERVICE);
800 wm.addView(addView, lp);
Jeff Browna41ca772010-08-11 14:46:32 -0700801
802 if (mPointerLocationInputChannel == null) {
803 try {
804 mPointerLocationInputChannel =
805 mWindowManager.monitorInput("PointerLocationView");
806 InputQueue.registerInputChannel(mPointerLocationInputChannel,
807 mPointerLocationInputHandler, mHandler.getLooper().getQueue());
808 } catch (RemoteException ex) {
809 Slog.e(TAG, "Could not set up input monitoring channel for PointerLocation.",
810 ex);
811 }
812 }
Dianne Hackbornc777e072010-02-12 13:07:59 -0800813 }
814 if (removeView != null) {
Jeff Browna41ca772010-08-11 14:46:32 -0700815 if (mPointerLocationInputChannel != null) {
816 InputQueue.unregisterInputChannel(mPointerLocationInputChannel);
817 mPointerLocationInputChannel.dispose();
818 mPointerLocationInputChannel = null;
819 }
820
Dianne Hackbornc777e072010-02-12 13:07:59 -0800821 WindowManagerImpl wm = (WindowManagerImpl)
822 mContext.getSystemService(Context.WINDOW_SERVICE);
823 wm.removeView(removeView);
824 }
825 }
826
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400827 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700828 try {
829 int rotation = mContext.getResources().getInteger(resID);
830 switch (rotation) {
831 case 0:
832 return Surface.ROTATION_0;
833 case 90:
834 return Surface.ROTATION_90;
835 case 180:
836 return Surface.ROTATION_180;
837 case 270:
838 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700839 }
840 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400841 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700842 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400843 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800844 }
845
846 /** {@inheritDoc} */
847 public int checkAddPermission(WindowManager.LayoutParams attrs) {
848 int type = attrs.type;
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700849
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800850 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
851 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
852 return WindowManagerImpl.ADD_OKAY;
853 }
854 String permission = null;
855 switch (type) {
856 case TYPE_TOAST:
857 // XXX right now the app process has complete control over
858 // this... should introduce a token to let the system
859 // monitor/control what they are doing.
860 break;
861 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -0700862 case TYPE_WALLPAPER:
863 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800864 break;
865 case TYPE_PHONE:
866 case TYPE_PRIORITY_PHONE:
867 case TYPE_SYSTEM_ALERT:
868 case TYPE_SYSTEM_ERROR:
869 case TYPE_SYSTEM_OVERLAY:
870 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
871 break;
872 default:
873 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
874 }
875 if (permission != null) {
876 if (mContext.checkCallingOrSelfPermission(permission)
877 != PackageManager.PERMISSION_GRANTED) {
878 return WindowManagerImpl.ADD_PERMISSION_DENIED;
879 }
880 }
881 return WindowManagerImpl.ADD_OKAY;
882 }
883
884 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
885 switch (attrs.type) {
886 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -0700887 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800888 case TYPE_TOAST:
889 // These types of windows can't receive input events.
890 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
891 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
892 break;
893 }
894 }
895
896 void readLidState() {
897 try {
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700898 int sw = mWindowManager.getSwitchState(SW_LID);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800899 if (sw >= 0) {
900 mLidOpen = sw == 0;
901 }
902 } catch (RemoteException e) {
903 // Ignore
904 }
905 }
906
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700907 private int determineHiddenState(boolean lidOpen,
908 int mode, int hiddenValue, int visibleValue) {
909 switch (mode) {
910 case 1:
911 return lidOpen ? visibleValue : hiddenValue;
912 case 2:
913 return lidOpen ? hiddenValue : visibleValue;
914 }
915 return visibleValue;
916 }
917
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800918 /** {@inheritDoc} */
919 public void adjustConfigurationLw(Configuration config) {
920 readLidState();
921 final boolean lidOpen = !KEYBOARD_ALWAYS_HIDDEN && mLidOpen;
922 mPowerManager.setKeyboardVisibility(lidOpen);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700923 config.hardKeyboardHidden = determineHiddenState(lidOpen,
924 mLidKeyboardAccessibility, Configuration.HARDKEYBOARDHIDDEN_YES,
925 Configuration.HARDKEYBOARDHIDDEN_NO);
926 config.navigationHidden = determineHiddenState(lidOpen,
927 mLidNavigationAccessibility, Configuration.NAVIGATIONHIDDEN_YES,
928 Configuration.NAVIGATIONHIDDEN_NO);
929 config.keyboardHidden = (config.hardKeyboardHidden
930 == Configuration.HARDKEYBOARDHIDDEN_NO || mHasSoftInput)
931 ? Configuration.KEYBOARDHIDDEN_NO
932 : Configuration.KEYBOARDHIDDEN_YES;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800933 }
934
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800935 /** {@inheritDoc} */
936 public int windowTypeToLayerLw(int type) {
937 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
938 return APPLICATION_LAYER;
939 }
940 switch (type) {
941 case TYPE_STATUS_BAR:
942 return STATUS_BAR_LAYER;
943 case TYPE_STATUS_BAR_PANEL:
944 return STATUS_BAR_PANEL_LAYER;
Joe Onorato29fc2c92010-11-24 10:26:50 -0800945 case TYPE_STATUS_BAR_SUB_PANEL:
946 return STATUS_BAR_SUB_PANEL_LAYER;
Dianne Hackborn6a294ce2009-12-03 11:37:44 -0800947 case TYPE_SYSTEM_DIALOG:
948 return SYSTEM_DIALOG_LAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800949 case TYPE_SEARCH_BAR:
950 return SEARCH_BAR_LAYER;
951 case TYPE_PHONE:
952 return PHONE_LAYER;
953 case TYPE_KEYGUARD:
954 return KEYGUARD_LAYER;
955 case TYPE_KEYGUARD_DIALOG:
956 return KEYGUARD_DIALOG_LAYER;
957 case TYPE_SYSTEM_ALERT:
958 return SYSTEM_ALERT_LAYER;
959 case TYPE_SYSTEM_ERROR:
960 return SYSTEM_ERROR_LAYER;
961 case TYPE_INPUT_METHOD:
962 return INPUT_METHOD_LAYER;
963 case TYPE_INPUT_METHOD_DIALOG:
964 return INPUT_METHOD_DIALOG_LAYER;
965 case TYPE_SYSTEM_OVERLAY:
966 return SYSTEM_OVERLAY_LAYER;
Jeff Brown3b2b3542010-10-15 00:54:27 -0700967 case TYPE_SECURE_SYSTEM_OVERLAY:
968 return SECURE_SYSTEM_OVERLAY_LAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800969 case TYPE_PRIORITY_PHONE:
970 return PRIORITY_PHONE_LAYER;
971 case TYPE_TOAST:
972 return TOAST_LAYER;
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -0700973 case TYPE_WALLPAPER:
974 return WALLPAPER_LAYER;
Christopher Tatea53146c2010-09-07 11:57:52 -0700975 case TYPE_DRAG:
976 return DRAG_LAYER;
Jeff Brown83c09682010-12-23 17:50:18 -0800977 case TYPE_POINTER:
978 return POINTER_LAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800979 }
980 Log.e(TAG, "Unknown window type: " + type);
981 return APPLICATION_LAYER;
982 }
983
984 /** {@inheritDoc} */
985 public int subWindowTypeToLayerLw(int type) {
986 switch (type) {
987 case TYPE_APPLICATION_PANEL:
988 case TYPE_APPLICATION_ATTACHED_DIALOG:
989 return APPLICATION_PANEL_SUBLAYER;
990 case TYPE_APPLICATION_MEDIA:
991 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700992 case TYPE_APPLICATION_MEDIA_OVERLAY:
993 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800994 case TYPE_APPLICATION_SUB_PANEL:
995 return APPLICATION_SUB_PANEL_SUBLAYER;
996 }
997 Log.e(TAG, "Unknown sub-window type: " + type);
998 return 0;
999 }
1000
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001001 public int getMaxWallpaperLayer() {
1002 return STATUS_BAR_LAYER;
1003 }
1004
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001005 public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs) {
1006 return attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD;
1007 }
1008
1009 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
1010 return attrs.type != WindowManager.LayoutParams.TYPE_STATUS_BAR
1011 && attrs.type != WindowManager.LayoutParams.TYPE_WALLPAPER;
1012 }
1013
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001014 /** {@inheritDoc} */
1015 public View addStartingWindow(IBinder appToken, String packageName,
1016 int theme, CharSequence nonLocalizedLabel,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001017 int labelRes, int icon, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001018 if (!SHOW_STARTING_ANIMATIONS) {
1019 return null;
1020 }
1021 if (packageName == null) {
1022 return null;
1023 }
1024
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001025 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001026 Context context = mContext;
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001027 //Log.i(TAG, "addStartingWindow " + packageName + ": nonLocalizedLabel="
1028 // + nonLocalizedLabel + " theme=" + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001029 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001030 try {
1031 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001032 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001033 } catch (PackageManager.NameNotFoundException e) {
1034 // Ignore
1035 }
1036 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001037
1038 Window win = PolicyManager.makeNewWindow(context);
1039 if (win.getWindowStyle().getBoolean(
1040 com.android.internal.R.styleable.Window_windowDisablePreview, false)) {
1041 return null;
1042 }
1043
1044 Resources r = context.getResources();
1045 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
1046
1047 win.setType(
1048 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
1049 // Force the window flags: this is a fake window, so it is not really
1050 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
1051 // flag because we do know that the next window will take input
1052 // focus, so we want to get the IME window up on top of us right away.
1053 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001054 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001055 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1056 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1057 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001058 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001059 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1060 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1061 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
1062
1063 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
1064 WindowManager.LayoutParams.MATCH_PARENT);
1065
1066 final WindowManager.LayoutParams params = win.getAttributes();
1067 params.token = appToken;
1068 params.packageName = packageName;
1069 params.windowAnimations = win.getWindowStyle().getResourceId(
1070 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
1071 params.setTitle("Starting " + packageName);
1072
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001073 WindowManagerImpl wm = (WindowManagerImpl)
1074 context.getSystemService(Context.WINDOW_SERVICE);
1075 View view = win.getDecorView();
1076
1077 if (win.isFloating()) {
1078 // Whoops, there is no way to display an animation/preview
1079 // of such a thing! After all that work... let's skip it.
1080 // (Note that we must do this here because it is in
1081 // getDecorView() where the theme is evaluated... maybe
1082 // we should peek the floating attribute from the theme
1083 // earlier.)
1084 return null;
1085 }
1086
1087 if (localLOGV) Log.v(
1088 TAG, "Adding starting window for " + packageName
1089 + " / " + appToken + ": "
1090 + (view.getParent() != null ? view : null));
1091
1092 wm.addView(view, params);
1093
1094 // Only return the view if it was successfully added to the
1095 // window manager... which we can tell by it having a parent.
1096 return view.getParent() != null ? view : null;
1097 } catch (WindowManagerImpl.BadTokenException e) {
1098 // ignore
1099 Log.w(TAG, appToken + " already running, starting window not displayed");
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001100 } catch (RuntimeException e) {
1101 // don't crash if something else bad happens, for example a
1102 // failure loading resources because we are loading from an app
1103 // on external storage that has been unmounted.
1104 Log.w(TAG, appToken + " failed creating starting window", e);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001105 }
1106
1107 return null;
1108 }
1109
1110 /** {@inheritDoc} */
1111 public void removeStartingWindow(IBinder appToken, View window) {
1112 // RuntimeException e = new RuntimeException();
1113 // Log.i(TAG, "remove " + appToken + " " + window, e);
1114
1115 if (localLOGV) Log.v(
1116 TAG, "Removing starting window for " + appToken + ": " + window);
1117
1118 if (window != null) {
1119 WindowManagerImpl wm = (WindowManagerImpl) mContext.getSystemService(Context.WINDOW_SERVICE);
1120 wm.removeView(window);
1121 }
1122 }
1123
1124 /**
1125 * Preflight adding a window to the system.
1126 *
1127 * Currently enforces that three window types are singletons:
1128 * <ul>
1129 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001130 * <li>KEYGUARD_TYPE</li>
1131 * </ul>
1132 *
1133 * @param win The window to be added
1134 * @param attrs Information about the window to be added
1135 *
1136 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, WindowManagerImpl.ADD_MULTIPLE_SINGLETON
1137 */
1138 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
1139 switch (attrs.type) {
1140 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001141 mContext.enforceCallingOrSelfPermission(
1142 android.Manifest.permission.STATUS_BAR_SERVICE,
1143 "PhoneWindowManager");
1144 // TODO: Need to handle the race condition of the status bar proc
1145 // dying and coming back before the removeWindowLw cleanup has happened.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001146 if (mStatusBar != null) {
1147 return WindowManagerImpl.ADD_MULTIPLE_SINGLETON;
1148 }
1149 mStatusBar = win;
Daniel Sandler40427442010-07-16 11:44:52 -04001150
1151 // The Configuration will be stable by now, so we can load this
1152 mStatusBarCanHide = mContext.getResources().getBoolean(
1153 com.android.internal.R.bool.config_statusBarCanHide);
1154
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001155 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08001156 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001157 mContext.enforceCallingOrSelfPermission(
1158 android.Manifest.permission.STATUS_BAR_SERVICE,
1159 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08001160 mStatusBarPanels.add(win);
1161 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001162 case TYPE_STATUS_BAR_SUB_PANEL:
1163 mContext.enforceCallingOrSelfPermission(
1164 android.Manifest.permission.STATUS_BAR_SERVICE,
1165 "PhoneWindowManager");
1166 mStatusBarPanels.add(win);
1167 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001168 case TYPE_KEYGUARD:
1169 if (mKeyguard != null) {
1170 return WindowManagerImpl.ADD_MULTIPLE_SINGLETON;
1171 }
1172 mKeyguard = win;
1173 break;
1174 }
1175 return WindowManagerImpl.ADD_OKAY;
1176 }
1177
1178 /** {@inheritDoc} */
1179 public void removeWindowLw(WindowState win) {
1180 if (mStatusBar == win) {
1181 mStatusBar = null;
1182 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001183 else if (mKeyguard == win) {
1184 mKeyguard = null;
Dianne Hackborn08743722009-12-21 12:16:51 -08001185 } else {
1186 mStatusBarPanels.remove(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001187 }
1188 }
1189
1190 static final boolean PRINT_ANIM = false;
1191
1192 /** {@inheritDoc} */
1193 public int selectAnimationLw(WindowState win, int transit) {
1194 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
1195 + ": transit=" + transit);
1196 if (transit == TRANSIT_PREVIEW_DONE) {
1197 if (win.hasAppShownWindows()) {
1198 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
1199 return com.android.internal.R.anim.app_starting_exit;
1200 }
1201 }
1202
1203 return 0;
1204 }
1205
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001206 public Animation createForceHideEnterAnimation() {
1207 return AnimationUtils.loadAnimation(mContext,
1208 com.android.internal.R.anim.lock_screen_behind_enter);
1209 }
1210
Jeff Brown4d396052010-10-29 21:50:21 -07001211 static ITelephony getTelephonyService() {
1212 ITelephony telephonyService = ITelephony.Stub.asInterface(
1213 ServiceManager.checkService(Context.TELEPHONY_SERVICE));
1214 if (telephonyService == null) {
1215 Log.w(TAG, "Unable to find ITelephony interface.");
1216 }
1217 return telephonyService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001218 }
1219
Jeff Brown4d396052010-10-29 21:50:21 -07001220 static IAudioService getAudioService() {
1221 IAudioService audioService = IAudioService.Stub.asInterface(
1222 ServiceManager.checkService(Context.AUDIO_SERVICE));
1223 if (audioService == null) {
1224 Log.w(TAG, "Unable to find IAudioService interface.");
1225 }
1226 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001227 }
1228
1229 boolean keyguardOn() {
1230 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
1231 }
1232
1233 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
1234 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
1235 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
1236 };
1237
1238 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001239 @Override
Jeff Brown1f245102010-11-18 20:53:46 -08001240 public boolean interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001241 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08001242 final int keyCode = event.getKeyCode();
1243 final int repeatCount = event.getRepeatCount();
1244 final int metaState = event.getMetaState();
1245 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
1246 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001247
1248 if (false) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001249 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001250 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed);
1251 }
1252
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001253 // First we always handle the home key here, so applications
1254 // can never break it, although if keyguard is on, we do let
1255 // it handle it, because that gives us the correct 5 second
1256 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001257 if (keyCode == KeyEvent.KEYCODE_HOME) {
Jeff Brown49ed71d2010-12-06 17:13:33 -08001258 // Clear a pending HOME longpress if the user releases Home
1259 if (!down) {
1260 mHandler.removeCallbacks(mHomeLongPress);
1261 }
1262
1263 // If we have released the home key, and didn't do anything else
1264 // while it was pressed, then it is time to go home!
1265 if (mHomePressed && !down) {
1266 mHomePressed = false;
1267 if (!canceled) {
1268 // If an incoming call is ringing, HOME is totally disabled.
1269 // (The user is already on the InCallScreen at this point,
1270 // and his ONLY options are to answer or reject the call.)
1271 boolean incomingRinging = false;
1272 try {
1273 ITelephony telephonyService = getTelephonyService();
1274 if (telephonyService != null) {
1275 incomingRinging = telephonyService.isRinging();
1276 }
1277 } catch (RemoteException ex) {
1278 Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
1279 }
1280
1281 if (incomingRinging) {
1282 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
1283 } else {
1284 launchHomeFromHotKey();
1285 }
1286 } else {
1287 Log.i(TAG, "Ignoring HOME; event canceled.");
1288 }
1289 return true;
1290 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001291
1292 // If a system window has focus, then it doesn't make sense
1293 // right now to interact with applications.
1294 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
1295 if (attrs != null) {
1296 final int type = attrs.type;
1297 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD
1298 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) {
1299 // the "app" is keyguard, so give it the key
1300 return false;
1301 }
1302 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
1303 for (int i=0; i<typeCount; i++) {
1304 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
1305 // don't do anything, but also don't pass it to the app
1306 return true;
1307 }
1308 }
1309 }
1310
1311 if (down && repeatCount == 0) {
1312 if (!keyguardOn) {
1313 mHandler.postDelayed(mHomeLongPress, ViewConfiguration.getGlobalActionKeyTimeout());
1314 }
1315 mHomePressed = true;
1316 }
1317 return true;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001318 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001319 // Hijack modified menu keys for debugging features
1320 final int chordBug = KeyEvent.META_SHIFT_ON;
1321
1322 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001323 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001324 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
1325 mContext.sendOrderedBroadcast(intent, null);
1326 return true;
1327 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001328 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001329 Intent service = new Intent();
1330 service.setClassName(mContext, "com.android.server.LoadAverageService");
1331 ContentResolver res = mContext.getContentResolver();
1332 boolean shown = Settings.System.getInt(
1333 res, Settings.System.SHOW_PROCESSES, 0) != 0;
1334 if (!shown) {
1335 mContext.startService(service);
1336 } else {
1337 mContext.stopService(service);
1338 }
1339 Settings.System.putInt(
1340 res, Settings.System.SHOW_PROCESSES, shown ? 0 : 1);
1341 return true;
1342 }
1343 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001344 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001345 if (down) {
1346 if (repeatCount == 0) {
Jeff Brown49ed71d2010-12-06 17:13:33 -08001347 mShortcutKeyPressed = keyCode;
1348 mConsumeShortcutKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001349 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08001350 } else if (keyCode == mShortcutKeyPressed) {
1351 mShortcutKeyPressed = -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08001352 if (mConsumeShortcutKeyUp) {
Jeff Brown49ed71d2010-12-06 17:13:33 -08001353 mConsumeShortcutKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001354 return true;
1355 }
1356 }
Jeff Browncaab4d02010-12-09 22:13:41 -08001357 return false;
Jeff Brown49ed71d2010-12-06 17:13:33 -08001358 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
1359 if (!down) {
1360 showRecentAppsDialog();
1361 }
1362 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001363 }
Jeff Browncaab4d02010-12-09 22:13:41 -08001364
Jeff Brownc1fb48d2010-12-08 16:52:09 -08001365 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08001366 // Any printing key that is chorded with Search should be consumed
1367 // even if no shortcut was invoked. This prevents text from being
1368 // inadvertently inserted when using a keyboard that has built-in macro
1369 // shortcut keys (that emit Search+x) and some of them are not registered.
1370 if (mShortcutKeyPressed != -1) {
1371 final KeyCharacterMap kcm = event.getKeyCharacterMap();
1372 if (kcm.isPrintingKey(keyCode)) {
1373 mConsumeShortcutKeyUp = true;
1374 if (down && repeatCount == 0 && !keyguardOn) {
1375 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
1376 if (shortcutIntent != null) {
1377 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1378 mContext.startActivity(shortcutIntent);
1379 } else {
1380 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
1381 + KeyEvent.keyCodeToString(mShortcutKeyPressed)
1382 + "+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08001383 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001384 }
Jeff Browncaab4d02010-12-09 22:13:41 -08001385 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001386 }
1387 }
1388
1389 return false;
1390 }
1391
Jeff Brown3915bb82010-11-05 15:02:16 -07001392 /** {@inheritDoc} */
1393 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08001394 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
1395 if (DEBUG_FALLBACK) {
Jeff Brown1f245102010-11-18 20:53:46 -08001396 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
1397 + ", flags=" + event.getFlags()
1398 + ", keyCode=" + event.getKeyCode()
1399 + ", scanCode=" + event.getScanCode()
1400 + ", metaState=" + event.getMetaState()
1401 + ", repeatCount=" + event.getRepeatCount()
1402 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07001403 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08001404
1405 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brownc1fb48d2010-12-08 16:52:09 -08001406 // Invoke shortcuts using Meta as a fallback.
Jeff Brown49ed71d2010-12-06 17:13:33 -08001407 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08001408 final int keyCode = event.getKeyCode();
1409 final int metaState = event.getMetaState();
1410 if ((metaState & KeyEvent.META_META_ON) != 0) {
1411 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
1412 metaState & ~(KeyEvent.META_META_ON
1413 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
1414 if (shortcutIntent != null) {
1415 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1416 mContext.startActivity(shortcutIntent);
1417 return null;
1418 }
1419 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08001420
Jeff Brownc1fb48d2010-12-08 16:52:09 -08001421 // Check for fallback actions.
1422 if (kcm.getFallbackAction(keyCode, metaState, mFallbackAction)) {
Jeff Brown49ed71d2010-12-06 17:13:33 -08001423 if (DEBUG_FALLBACK) {
1424 Slog.d(TAG, "Fallback: keyCode=" + mFallbackAction.keyCode
1425 + " metaState=" + Integer.toHexString(mFallbackAction.metaState));
1426 }
1427
1428 int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
1429 KeyEvent fallbackEvent = KeyEvent.obtain(
1430 event.getDownTime(), event.getEventTime(),
1431 event.getAction(), mFallbackAction.keyCode,
1432 event.getRepeatCount(), mFallbackAction.metaState,
1433 event.getDeviceId(), event.getScanCode(),
1434 flags, event.getSource(), null);
1435 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags, true);
1436 if ((actions & ACTION_PASS_TO_USER) != 0) {
1437 if (!interceptKeyBeforeDispatching(win, fallbackEvent, policyFlags)) {
1438 if (DEBUG_FALLBACK) {
1439 Slog.d(TAG, "Performing fallback.");
1440 }
1441 return fallbackEvent;
1442 }
1443 }
1444 fallbackEvent.recycle();
1445 }
1446 }
1447
1448 if (DEBUG_FALLBACK) {
1449 Slog.d(TAG, "No fallback.");
1450 }
1451 return null;
Jeff Brown3915bb82010-11-05 15:02:16 -07001452 }
1453
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001454 /**
1455 * A home key -> launch home action was detected. Take the appropriate action
1456 * given the situation with the keyguard.
1457 */
1458 void launchHomeFromHotKey() {
Dianne Hackborn9dc06cc2009-11-17 18:19:23 -08001459 if (mKeyguardMediator.isShowingAndNotHidden()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001460 // don't launch home if keyguard showing
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001461 } else if (!mHideLockScreen && mKeyguardMediator.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001462 // when in keyguard restricted mode, must first verify unlock
1463 // before launching home
1464 mKeyguardMediator.verifyUnlock(new OnKeyguardExitResult() {
1465 public void onKeyguardExitResult(boolean success) {
1466 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07001467 try {
1468 ActivityManagerNative.getDefault().stopAppSwitches();
1469 } catch (RemoteException e) {
1470 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05001471 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001472 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001473 }
1474 }
1475 });
1476 } else {
1477 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07001478 try {
1479 ActivityManagerNative.getDefault().stopAppSwitches();
1480 } catch (RemoteException e) {
1481 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05001482 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001483 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001484 }
1485 }
1486
1487 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
1488 final int fl = attrs.flags;
1489
Dianne Hackborn82de1ae2010-10-28 11:28:39 -07001490 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_FULLSCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001491 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn82de1ae2010-10-28 11:28:39 -07001492 contentInset.set(mCurLeft, mCurTop,
Joe Onorato29fc2c92010-11-24 10:26:50 -08001493 (mRestrictedScreenLeft+mRestrictedScreenWidth) - mCurRight,
1494 (mRestrictedScreenTop+mRestrictedScreenHeight) - mCurBottom);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001495 } else {
1496 contentInset.setEmpty();
1497 }
1498 }
1499
1500 /** {@inheritDoc} */
1501 public void beginLayoutLw(int displayWidth, int displayHeight) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08001502 mUnrestrictedScreenLeft = mUnrestrictedScreenTop = 0;
1503 mUnrestrictedScreenWidth = displayWidth;
1504 mUnrestrictedScreenHeight = displayHeight;
1505 mRestrictedScreenLeft = mRestrictedScreenTop = 0;
1506 mRestrictedScreenWidth = displayWidth;
1507 mRestrictedScreenHeight = displayHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001508 mDockLeft = mContentLeft = mCurLeft = 0;
1509 mDockTop = mContentTop = mCurTop = 0;
1510 mDockRight = mContentRight = mCurRight = displayWidth;
1511 mDockBottom = mContentBottom = mCurBottom = displayHeight;
1512 mDockLayer = 0x10000000;
1513
1514 // decide where the status bar goes ahead of time
1515 if (mStatusBar != null) {
1516 final Rect pf = mTmpParentFrame;
1517 final Rect df = mTmpDisplayFrame;
1518 final Rect vf = mTmpVisibleFrame;
1519 pf.left = df.left = vf.left = 0;
1520 pf.top = df.top = vf.top = 0;
1521 pf.right = df.right = vf.right = displayWidth;
1522 pf.bottom = df.bottom = vf.bottom = displayHeight;
1523
1524 mStatusBar.computeFrameLw(pf, df, vf, vf);
1525 if (mStatusBar.isVisibleLw()) {
1526 // If the status bar is hidden, we don't want to cause
1527 // windows behind it to scroll.
Joe Onorato34bcebc2010-07-07 18:05:01 -04001528 final Rect r = mStatusBar.getFrameLw();
Dianne Hackborn82de1ae2010-10-28 11:28:39 -07001529 if (mStatusBarCanHide) {
1530 // Status bar may go away, so the screen area it occupies
1531 // is available to apps but just covering them when the
1532 // status bar is visible.
1533 if (mDockTop == r.top) mDockTop = r.bottom;
1534 else if (mDockBottom == r.bottom) mDockBottom = r.top;
1535 mContentTop = mCurTop = mDockTop;
1536 mContentBottom = mCurBottom = mDockBottom;
1537 if (DEBUG_LAYOUT) Log.v(TAG, "Status bar: mDockTop=" + mDockTop
1538 + " mContentTop=" + mContentTop
1539 + " mCurTop=" + mCurTop
1540 + " mDockBottom=" + mDockBottom
1541 + " mContentBottom=" + mContentBottom
1542 + " mCurBottom=" + mCurBottom);
1543 } else {
1544 // Status bar can't go away; the part of the screen it
1545 // covers does not exist for anything behind it.
Joe Onorato29fc2c92010-11-24 10:26:50 -08001546 if (mRestrictedScreenTop == r.top) {
1547 mRestrictedScreenTop = r.bottom;
1548 mRestrictedScreenHeight -= (r.bottom-r.top);
1549 } else if ((mRestrictedScreenHeight-mRestrictedScreenTop) == r.bottom) {
1550 mRestrictedScreenHeight -= (r.bottom-r.top);
Dianne Hackborn82de1ae2010-10-28 11:28:39 -07001551 }
Joe Onorato29fc2c92010-11-24 10:26:50 -08001552 mContentTop = mCurTop = mDockTop = mRestrictedScreenTop;
1553 mContentBottom = mCurBottom = mDockBottom
1554 = mRestrictedScreenTop + mRestrictedScreenHeight;
1555 if (DEBUG_LAYOUT) Log.v(TAG, "Status bar: mRestrictedScreenTop="
1556 + mRestrictedScreenTop
1557 + " mRestrictedScreenHeight=" + mRestrictedScreenHeight);
Dianne Hackborn82de1ae2010-10-28 11:28:39 -07001558 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001559 }
1560 }
1561 }
1562
Dianne Hackborndea3ef72010-10-28 14:24:22 -07001563 void setAttachedWindowFrames(WindowState win, int fl, int adjust,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001564 WindowState attached, boolean insetDecors, Rect pf, Rect df, Rect cf, Rect vf) {
1565 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
1566 // Here's a special case: if this attached window is a panel that is
1567 // above the dock window, and the window it is attached to is below
1568 // the dock window, then the frames we computed for the window it is
1569 // attached to can not be used because the dock is effectively part
1570 // of the underlying window and the attached window is floating on top
1571 // of the whole thing. So, we ignore the attached window and explicitly
1572 // compute the frames that would be appropriate without the dock.
1573 df.left = cf.left = vf.left = mDockLeft;
1574 df.top = cf.top = vf.top = mDockTop;
1575 df.right = cf.right = vf.right = mDockRight;
1576 df.bottom = cf.bottom = vf.bottom = mDockBottom;
1577 } else {
1578 // The effective display frame of the attached window depends on
1579 // whether it is taking care of insetting its content. If not,
1580 // we need to use the parent's content frame so that the entire
1581 // window is positioned within that content. Otherwise we can use
1582 // the display frame and let the attached window take care of
1583 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07001584 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001585 cf.set(attached.getDisplayFrameLw());
1586 } else {
1587 // If the window is resizing, then we want to base the content
1588 // frame on our attached content frame to resize... however,
1589 // things can be tricky if the attached window is NOT in resize
1590 // mode, in which case its content frame will be larger.
1591 // Ungh. So to deal with that, make sure the content frame
1592 // we end up using is not covering the IM dock.
1593 cf.set(attached.getContentFrameLw());
1594 if (attached.getSurfaceLayer() < mDockLayer) {
1595 if (cf.left < mContentLeft) cf.left = mContentLeft;
1596 if (cf.top < mContentTop) cf.top = mContentTop;
1597 if (cf.right > mContentRight) cf.right = mContentRight;
1598 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
1599 }
1600 }
1601 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
1602 vf.set(attached.getVisibleFrameLw());
1603 }
1604 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
1605 // window should be positioned relative to its parent or the entire
1606 // screen.
1607 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
1608 ? attached.getFrameLw() : df);
1609 }
1610
1611 /** {@inheritDoc} */
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07001612 public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,
1613 WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001614 // we've already done the status bar
1615 if (win == mStatusBar) {
1616 return;
1617 }
1618
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001619 final int fl = attrs.flags;
1620 final int sim = attrs.softInputMode;
1621
1622 final Rect pf = mTmpParentFrame;
1623 final Rect df = mTmpDisplayFrame;
1624 final Rect cf = mTmpContentFrame;
1625 final Rect vf = mTmpVisibleFrame;
1626
1627 if (attrs.type == TYPE_INPUT_METHOD) {
1628 pf.left = df.left = cf.left = vf.left = mDockLeft;
1629 pf.top = df.top = cf.top = vf.top = mDockTop;
1630 pf.right = df.right = cf.right = vf.right = mDockRight;
1631 pf.bottom = df.bottom = cf.bottom = vf.bottom = mDockBottom;
1632 // IM dock windows always go to the bottom of the screen.
1633 attrs.gravity = Gravity.BOTTOM;
1634 mDockLayer = win.getSurfaceLayer();
1635 } else {
Dianne Hackborndea3ef72010-10-28 14:24:22 -07001636 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
1637
Dianne Hackborn82de1ae2010-10-28 11:28:39 -07001638 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_FULLSCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001639 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
1640 // This is the case for a normal activity window: we want it
1641 // to cover all of the screen space, and it can take care of
1642 // moving its contents to account for screen decorations that
1643 // intrude into that space.
1644 if (attached != null) {
1645 // If this window is attached to another, our display
1646 // frame is the same as the one we are attached to.
1647 setAttachedWindowFrames(win, fl, sim, attached, true, pf, df, cf, vf);
1648 } else {
Joe Onorato29fc2c92010-11-24 10:26:50 -08001649 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
1650 // Status bar panels are the only windows who can go on top of
1651 // the status bar. They are protected by the STATUS_BAR_SERVICE
1652 // permission, so they have the same privileges as the status
1653 // bar itself.
1654 pf.left = df.left = mUnrestrictedScreenLeft;
1655 pf.top = df.top = mUnrestrictedScreenTop;
1656 pf.right = df.right = mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
1657 pf.bottom = df.bottom = mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
1658 } else {
1659 pf.left = df.left = mRestrictedScreenLeft;
1660 pf.top = df.top = mRestrictedScreenTop;
1661 pf.right = df.right = mRestrictedScreenLeft+mRestrictedScreenWidth;
1662 pf.bottom = df.bottom = mRestrictedScreenTop+mRestrictedScreenHeight;
1663 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07001664 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001665 cf.left = mDockLeft;
1666 cf.top = mDockTop;
1667 cf.right = mDockRight;
1668 cf.bottom = mDockBottom;
1669 } else {
1670 cf.left = mContentLeft;
1671 cf.top = mContentTop;
1672 cf.right = mContentRight;
1673 cf.bottom = mContentBottom;
1674 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07001675 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
1676 vf.left = mCurLeft;
1677 vf.top = mCurTop;
1678 vf.right = mCurRight;
1679 vf.bottom = mCurBottom;
1680 } else {
1681 vf.set(cf);
1682 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001683 }
Dianne Hackborn82de1ae2010-10-28 11:28:39 -07001684 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001685 // A window that has requested to fill the entire screen just
1686 // gets everything, period.
Joe Onorato29fc2c92010-11-24 10:26:50 -08001687 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
1688 pf.left = df.left = cf.left = mUnrestrictedScreenLeft;
1689 pf.top = df.top = cf.top = mUnrestrictedScreenTop;
1690 pf.right = df.right = cf.right
1691 = mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
1692 pf.bottom = df.bottom = cf.bottom
1693 = mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
1694 } else {
1695 pf.left = df.left = cf.left = mRestrictedScreenLeft;
1696 pf.top = df.top = cf.top = mRestrictedScreenTop;
1697 pf.right = df.right = cf.right = mRestrictedScreenLeft+mRestrictedScreenWidth;
1698 pf.bottom = df.bottom = cf.bottom
1699 = mRestrictedScreenTop+mRestrictedScreenHeight;
1700 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07001701 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
1702 vf.left = mCurLeft;
1703 vf.top = mCurTop;
1704 vf.right = mCurRight;
1705 vf.bottom = mCurBottom;
1706 } else {
1707 vf.set(cf);
1708 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001709 } else if (attached != null) {
1710 // A child window should be placed inside of the same visible
1711 // frame that its parent had.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07001712 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001713 } else {
1714 // Otherwise, a normal window must be placed inside the content
1715 // of all screen decorations.
1716 pf.left = mContentLeft;
1717 pf.top = mContentTop;
1718 pf.right = mContentRight;
1719 pf.bottom = mContentBottom;
Dianne Hackborndea3ef72010-10-28 14:24:22 -07001720 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001721 df.left = cf.left = mDockLeft;
1722 df.top = cf.top = mDockTop;
1723 df.right = cf.right = mDockRight;
1724 df.bottom = cf.bottom = mDockBottom;
1725 } else {
1726 df.left = cf.left = mContentLeft;
1727 df.top = cf.top = mContentTop;
1728 df.right = cf.right = mContentRight;
1729 df.bottom = cf.bottom = mContentBottom;
1730 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07001731 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
1732 vf.left = mCurLeft;
1733 vf.top = mCurTop;
1734 vf.right = mCurRight;
1735 vf.bottom = mCurBottom;
1736 } else {
1737 vf.set(cf);
1738 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001739 }
1740 }
1741
1742 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0) {
1743 df.left = df.top = cf.left = cf.top = vf.left = vf.top = -10000;
1744 df.right = df.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
1745 }
1746
The Android Open Source Project11267662009-03-18 17:39:47 -07001747 if (DEBUG_LAYOUT) Log.v(TAG, "Compute frame " + attrs.getTitle()
1748 + ": sim=#" + Integer.toHexString(sim)
1749 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
1750 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString());
1751
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001752 win.computeFrameLw(pf, df, cf, vf);
1753
1754 // Dock windows carve out the bottom of the screen, so normal windows
1755 // can't appear underneath them.
1756 if (attrs.type == TYPE_INPUT_METHOD && !win.getGivenInsetsPendingLw()) {
1757 int top = win.getContentFrameLw().top;
1758 top += win.getGivenContentInsetsLw().top;
1759 if (mContentBottom > top) {
1760 mContentBottom = top;
1761 }
1762 top = win.getVisibleFrameLw().top;
1763 top += win.getGivenVisibleInsetsLw().top;
1764 if (mCurBottom > top) {
1765 mCurBottom = top;
1766 }
The Android Open Source Project11267662009-03-18 17:39:47 -07001767 if (DEBUG_LAYOUT) Log.v(TAG, "Input method: mDockBottom="
1768 + mDockBottom + " mContentBottom="
1769 + mContentBottom + " mCurBottom=" + mCurBottom);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001770 }
1771 }
1772
1773 /** {@inheritDoc} */
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001774 public int finishLayoutLw() {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08001775 return 0;
1776 }
1777
1778 /** {@inheritDoc} */
1779 public void beginAnimationLw(int displayWidth, int displayHeight) {
1780 mTopFullscreenOpaqueWindowState = null;
1781 mForceStatusBar = false;
1782
1783 mHideLockScreen = false;
1784 mAllowLockscreenWhenOn = false;
1785 mDismissKeyguard = false;
1786 }
1787
1788 /** {@inheritDoc} */
1789 public void animatingWindowLw(WindowState win,
1790 WindowManager.LayoutParams attrs) {
1791 if (mTopFullscreenOpaqueWindowState == null &&
1792 win.isVisibleOrBehindKeyguardLw()) {
1793 if ((attrs.flags & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
1794 mForceStatusBar = true;
1795 }
1796 if (attrs.type >= FIRST_APPLICATION_WINDOW
1797 && attrs.type <= LAST_APPLICATION_WINDOW
Dianne Hackborn6493e642010-10-01 13:06:30 -07001798 && attrs.x == 0 && attrs.y == 0
1799 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
1800 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08001801 if (DEBUG_LAYOUT) Log.v(TAG, "Fullscreen window: " + win);
1802 mTopFullscreenOpaqueWindowState = win;
1803 if ((attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1804 if (localLOGV) Log.v(TAG, "Setting mHideLockScreen to true by win " + win);
1805 mHideLockScreen = true;
1806 }
1807 if ((attrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1808 if (localLOGV) Log.v(TAG, "Setting mDismissKeyguard to true by win " + win);
1809 mDismissKeyguard = true;
1810 }
1811 if ((attrs.flags & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
1812 mAllowLockscreenWhenOn = true;
1813 }
1814 }
1815 }
1816 }
1817
1818 /** {@inheritDoc} */
1819 public int finishAnimationLw() {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001820 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04001821 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04001822
1823 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
1824 ? mTopFullscreenOpaqueWindowState.getAttrs()
1825 : null;
1826
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001827 if (mStatusBar != null) {
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07001828 if (localLOGV) Log.i(TAG, "force=" + mForceStatusBar
1829 + " top=" + mTopFullscreenOpaqueWindowState);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001830 if (mForceStatusBar) {
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07001831 if (DEBUG_LAYOUT) Log.v(TAG, "Showing status bar");
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001832 if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001833 } else if (mTopFullscreenOpaqueWindowState != null) {
Joe Onorato93056472010-09-10 10:30:46 -04001834 if (localLOGV) {
1835 Log.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
1836 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
1837 Log.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
1838 + " lp.flags=0x" + Integer.toHexString(lp.flags));
1839 }
1840 topIsFullscreen = (lp.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
1841 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
1842 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
1843 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
1844 // case though.
1845 if (topIsFullscreen) {
Daniel Sandler40427442010-07-16 11:44:52 -04001846 if (mStatusBarCanHide) {
1847 if (DEBUG_LAYOUT) Log.v(TAG, "Hiding status bar");
1848 if (mStatusBar.hideLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT;
Daniel Sandler40427442010-07-16 11:44:52 -04001849 } else if (localLOGV) {
1850 Log.v(TAG, "Preventing status bar from hiding by policy");
1851 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001852 } else {
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07001853 if (DEBUG_LAYOUT) Log.v(TAG, "Showing status bar");
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001854 if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001855 }
1856 }
1857 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04001858
1859 boolean topNeedsMenu = mShowMenuKey;
1860 if (lp != null) {
1861 topNeedsMenu = (lp.flags & WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY) != 0;
1862 }
1863
1864 if (DEBUG_LAYOUT) Log.v(TAG, "Top window "
1865 + (topNeedsMenu ? "needs" : "does not need")
1866 + " the MENU key");
1867
1868 final boolean changedFullscreen = (mTopIsFullscreen != topIsFullscreen);
1869 final boolean changedMenu = (topNeedsMenu != mShowMenuKey);
1870
1871 if (changedFullscreen || changedMenu) {
Joe Onorato93056472010-09-10 10:30:46 -04001872 final boolean topIsFullscreenF = topIsFullscreen;
Daniel Sandlere02d8082010-10-08 15:13:22 -04001873 final boolean topNeedsMenuF = topNeedsMenu;
1874
Joe Onorato93056472010-09-10 10:30:46 -04001875 mTopIsFullscreen = topIsFullscreen;
Daniel Sandlere02d8082010-10-08 15:13:22 -04001876 mShowMenuKey = topNeedsMenu;
1877
Joe Onorato93056472010-09-10 10:30:46 -04001878 mHandler.post(new Runnable() {
1879 public void run() {
1880 if (mStatusBarService == null) {
1881 // This is the one that can not go away, but it doesn't come up
1882 // before the window manager does, so don't fail if it doesn't
1883 // exist. This works as long as no fullscreen windows come up
1884 // before the status bar service does.
1885 mStatusBarService = IStatusBarService.Stub.asInterface(
1886 ServiceManager.getService("statusbar"));
1887 }
1888 final IStatusBarService sbs = mStatusBarService;
1889 if (mStatusBarService != null) {
1890 try {
Daniel Sandlere02d8082010-10-08 15:13:22 -04001891 if (changedMenu) {
1892 sbs.setMenuKeyVisible(topNeedsMenuF);
1893 }
Daniel Sandler59485d742010-12-02 00:11:33 -05001894 if (changedFullscreen) {
1895 sbs.setActiveWindowIsFullscreen(topIsFullscreenF);
1896 }
Joe Onorato93056472010-09-10 10:30:46 -04001897 } catch (RemoteException e) {
1898 // This should be impossible because we're in the same process.
1899 mStatusBarService = null;
1900 }
1901 }
1902 }
1903 });
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08001904 }
1905
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07001906 // Hide the key guard if a visible window explicitly specifies that it wants to be displayed
1907 // when the screen is locked
1908 if (mKeyguard != null) {
Joe Onorato93056472010-09-10 10:30:46 -04001909 if (localLOGV) Log.v(TAG, "finishAnimationLw::mHideKeyguard="+mHideLockScreen);
Dianne Hackborn05726582009-09-22 17:28:24 -07001910 if (mDismissKeyguard && !mKeyguardMediator.isSecure()) {
Dianne Hackborn08743722009-12-21 12:16:51 -08001911 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001912 changes |= FINISH_LAYOUT_REDO_LAYOUT
1913 | FINISH_LAYOUT_REDO_CONFIG
1914 | FINISH_LAYOUT_REDO_WALLPAPER;
1915 }
Dianne Hackborn05726582009-09-22 17:28:24 -07001916 if (mKeyguardMediator.isShowing()) {
Dianne Hackbornb446e972009-09-20 15:23:25 -07001917 mHandler.post(new Runnable() {
1918 public void run() {
Dianne Hackborn05726582009-09-22 17:28:24 -07001919 mKeyguardMediator.keyguardDone(false, false);
Dianne Hackbornb446e972009-09-20 15:23:25 -07001920 }
1921 });
1922 }
Dianne Hackborn05726582009-09-22 17:28:24 -07001923 } else if (mHideLockScreen) {
Dianne Hackborn08743722009-12-21 12:16:51 -08001924 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001925 changes |= FINISH_LAYOUT_REDO_LAYOUT
1926 | FINISH_LAYOUT_REDO_CONFIG
1927 | FINISH_LAYOUT_REDO_WALLPAPER;
1928 }
Mike Lockwoodf3bfed52010-01-21 16:38:44 -05001929 mKeyguardMediator.setHidden(true);
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07001930 } else {
Dianne Hackborn08743722009-12-21 12:16:51 -08001931 if (mKeyguard.showLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001932 changes |= FINISH_LAYOUT_REDO_LAYOUT
1933 | FINISH_LAYOUT_REDO_CONFIG
1934 | FINISH_LAYOUT_REDO_WALLPAPER;
1935 }
Mike Lockwoodf3bfed52010-01-21 16:38:44 -05001936 mKeyguardMediator.setHidden(false);
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07001937 }
1938 }
The Android Open Source Projectc84bf282009-03-09 11:52:14 -07001939
Mike Lockwood28569302010-01-28 11:54:40 -05001940 // update since mAllowLockscreenWhenOn might have changed
1941 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001942 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001943 }
1944
Dianne Hackborn08743722009-12-21 12:16:51 -08001945 public boolean allowAppAnimationsLw() {
1946 if (mKeyguard != null && mKeyguard.isVisibleLw()) {
1947 // If keyguard is currently visible, no reason to animate
1948 // behind it.
1949 return false;
1950 }
1951 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
1952 Rect rect = new Rect(mStatusBar.getShownFrameLw());
1953 for (int i=mStatusBarPanels.size()-1; i>=0; i--) {
1954 WindowState w = mStatusBarPanels.get(i);
1955 if (w.isVisibleLw()) {
1956 rect.union(w.getShownFrameLw());
1957 }
1958 }
Joe Onorato29fc2c92010-11-24 10:26:50 -08001959 final int insetw = mRestrictedScreenWidth/10;
1960 final int inseth = mRestrictedScreenHeight/10;
1961 if (rect.contains(insetw, inseth, mRestrictedScreenWidth-insetw,
1962 mRestrictedScreenHeight-inseth)) {
Dianne Hackborn08743722009-12-21 12:16:51 -08001963 // All of the status bar windows put together cover the
1964 // screen, so the app can't be seen. (Note this test doesn't
1965 // work if the rects of these windows are at off offsets or
1966 // sizes, causing gaps in the rect union we have computed.)
1967 return false;
1968 }
1969 }
1970 return true;
1971 }
1972
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07001973 /** {@inheritDoc} */
Jeff Brown46b9ac02010-04-22 18:58:52 -07001974 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
1975 // lid changed state
1976 mLidOpen = lidOpen;
1977 boolean awakeNow = mKeyguardMediator.doLidChangeTq(mLidOpen);
1978 updateRotation(Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
1979 if (awakeNow) {
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08001980 // If the lid is opening and we don't have to keep the
Jeff Brown46b9ac02010-04-22 18:58:52 -07001981 // keyguard up, then we can turn on the screen
1982 // immediately.
1983 mKeyguardMediator.pokeWakelock();
1984 } else if (keyguardIsShowingTq()) {
1985 if (mLidOpen) {
1986 // If we are opening the lid and not hiding the
1987 // keyguard, then we need to have it turn on the
1988 // screen once it is shown.
1989 mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(
1990 KeyEvent.KEYCODE_POWER);
1991 }
1992 } else {
1993 // Light up the keyboard if we are sliding up.
1994 if (mLidOpen) {
1995 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
1996 LocalPowerManager.BUTTON_EVENT);
1997 } else {
1998 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
1999 LocalPowerManager.OTHER_EVENT);
2000 }
2001 }
2002 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002003
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08002004 void setHdmiPlugged(boolean plugged) {
2005 if (mHdmiPlugged != plugged) {
2006 mHdmiPlugged = plugged;
2007 updateRotation(Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
2008 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08002009 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08002010 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
2011 mContext.sendStickyBroadcast(intent);
2012 }
2013 }
2014
Joe Onoratodc100302011-01-11 17:07:41 -08002015 boolean readHdmiState() {
2016 final String filename = "/sys/class/switch/hdmi/state";
2017 FileReader reader = null;
2018 try {
2019 reader = new FileReader(filename);
2020 char[] buf = new char[15];
2021 int n = reader.read(buf);
2022 if (n > 1) {
2023 return 0 != Integer.parseInt(new String(buf, 0, n-1));
2024 } else {
2025 return false;
2026 }
2027 } catch (IOException ex) {
2028 Slog.d(TAG, "couldn't read hdmi state from " + filename + ": " + ex);
2029 return false;
2030 } catch (NumberFormatException ex) {
2031 Slog.d(TAG, "couldn't read hdmi state from " + filename + ": " + ex);
2032 return false;
2033 } finally {
2034 if (reader != null) {
2035 try {
2036 reader.close();
2037 } catch (IOException ex) {
2038 }
2039 }
2040 }
2041 }
2042
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002043 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002044 * @return Whether music is being played right now.
2045 */
2046 boolean isMusicActive() {
Eric Laurent413cb9d2009-07-17 11:52:43 -07002047 final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
2048 if (am == null) {
2049 Log.w(TAG, "isMusicActive: couldn't get AudioManager reference");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002050 return false;
2051 }
Eric Laurent413cb9d2009-07-17 11:52:43 -07002052 return am.isMusicActive();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002053 }
2054
2055 /**
2056 * Tell the audio service to adjust the volume appropriate to the event.
2057 * @param keycode
2058 */
Mike Lockwooda53e3812009-09-25 10:51:39 -04002059 void handleVolumeKey(int stream, int keycode) {
Jeff Brown4d396052010-10-29 21:50:21 -07002060 IAudioService audioService = getAudioService();
2061 if (audioService == null) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002062 return;
2063 }
2064 try {
2065 // since audio is playing, we shouldn't have to hold a wake lock
2066 // during the call, but we do it as a precaution for the rare possibility
2067 // that the music stops right before we call this
Jeff Brownb0418da2010-11-01 15:24:01 -07002068 // TODO: Actually handle MUTE.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002069 mBroadcastWakeLock.acquire();
Jeff Brown4d396052010-10-29 21:50:21 -07002070 audioService.adjustStreamVolume(stream,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002071 keycode == KeyEvent.KEYCODE_VOLUME_UP
2072 ? AudioManager.ADJUST_RAISE
2073 : AudioManager.ADJUST_LOWER,
2074 0);
2075 } catch (RemoteException e) {
2076 Log.w(TAG, "IAudioService.adjustStreamVolume() threw RemoteException " + e);
2077 } finally {
2078 mBroadcastWakeLock.release();
2079 }
2080 }
Jeff Brown4d396052010-10-29 21:50:21 -07002081
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002082 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002083 @Override
Jeff Brown1f245102010-11-18 20:53:46 -08002084 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) {
2085 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2086 final boolean canceled = event.isCanceled();
2087 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07002088
Jeff Brown3122e442010-10-11 23:32:49 -07002089 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07002090
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05002091 // If screen is off then we treat the case where the keyguard is open but hidden
2092 // the same as if it were open and in front.
2093 // This will prevent any keys other than the power button from waking the screen
2094 // when the keyguard is hidden by another activity.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002095 final boolean keyguardActive = (isScreenOn ?
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05002096 mKeyguardMediator.isShowingAndNotHidden() :
2097 mKeyguardMediator.isShowing());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002098
2099 if (false) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002100 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
2101 + " screenIsOn=" + isScreenOn + " keyguardActive=" + keyguardActive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002102 }
2103
Jeff Brown4d396052010-10-29 21:50:21 -07002104 if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0) {
2105 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
2106 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002107
Jeff Brown4d396052010-10-29 21:50:21 -07002108 // Basic policy based on screen state and keyguard.
2109 // FIXME: This policy isn't quite correct. We shouldn't care whether the screen
2110 // is on or off, really. We should care about whether the device is in an
2111 // interactive state or is in suspend pretending to be "off".
2112 // The primary screen might be turned off due to proximity sensor or
2113 // because we are presenting media on an auxiliary screen or remotely controlling
2114 // the device some other way (which is why we have an exemption here for injected
2115 // events).
2116 int result;
2117 if (isScreenOn || isInjected) {
2118 // When the screen is on or if the key is injected pass the key to the application.
2119 result = ACTION_PASS_TO_USER;
2120 } else {
2121 // When the screen is off and the key is not injected, determine whether
2122 // to wake the device but don't pass the key to the application.
2123 result = 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002124
Jeff Brown4d396052010-10-29 21:50:21 -07002125 final boolean isWakeKey = (policyFlags
2126 & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
2127 if (down && isWakeKey) {
2128 if (keyguardActive) {
2129 // If the keyguard is showing, let it decide what to do with the wake key.
2130 mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(keyCode);
2131 } else {
2132 // Otherwise, wake the device ourselves.
2133 result |= ACTION_POKE_USER_ACTIVITY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002134 }
2135 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002136 }
2137
Jeff Brown4d396052010-10-29 21:50:21 -07002138 // Handle special keys.
2139 switch (keyCode) {
2140 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07002141 case KeyEvent.KEYCODE_VOLUME_UP:
2142 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brown4d396052010-10-29 21:50:21 -07002143 if (down) {
2144 ITelephony telephonyService = getTelephonyService();
2145 if (telephonyService != null) {
2146 try {
2147 if (telephonyService.isRinging()) {
2148 // If an incoming call is ringing, either VOLUME key means
2149 // "silence ringer". We handle these keys here, rather than
2150 // in the InCallScreen, to make sure we'll respond to them
2151 // even if the InCallScreen hasn't come to the foreground yet.
2152 // Look for the DOWN event here, to agree with the "fallback"
2153 // behavior in the InCallScreen.
2154 Log.i(TAG, "interceptKeyBeforeQueueing:"
2155 + " VOLUME key-down while ringing: Silence ringer!");
2156
2157 // Silence the ringer. (It's safe to call this
2158 // even if the ringer has already been silenced.)
2159 telephonyService.silenceRinger();
2160
2161 // And *don't* pass this key thru to the current activity
2162 // (which is probably the InCallScreen.)
2163 result &= ~ACTION_PASS_TO_USER;
2164 break;
2165 }
2166 if (telephonyService.isOffhook()
2167 && (result & ACTION_PASS_TO_USER) == 0) {
2168 // If we are in call but we decided not to pass the key to
2169 // the application, handle the volume change here.
2170 handleVolumeKey(AudioManager.STREAM_VOICE_CALL, keyCode);
2171 break;
2172 }
2173 } catch (RemoteException ex) {
2174 Log.w(TAG, "ITelephony threw RemoteException", ex);
2175 }
2176 }
2177
2178 if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) {
2179 // If music is playing but we decided not to pass the key to the
2180 // application, handle the volume change here.
2181 handleVolumeKey(AudioManager.STREAM_MUSIC, keyCode);
2182 break;
2183 }
2184 }
2185 break;
2186 }
2187
2188 case KeyEvent.KEYCODE_ENDCALL: {
2189 result &= ~ACTION_PASS_TO_USER;
2190 if (down) {
2191 ITelephony telephonyService = getTelephonyService();
2192 boolean hungUp = false;
2193 if (telephonyService != null) {
2194 try {
2195 hungUp = telephonyService.endCall();
2196 } catch (RemoteException ex) {
2197 Log.w(TAG, "ITelephony threw RemoteException", ex);
2198 }
2199 }
2200 interceptPowerKeyDown(!isScreenOn || hungUp);
2201 } else {
2202 if (interceptPowerKeyUp(canceled)) {
2203 if ((mEndcallBehavior
2204 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
2205 if (goHome()) {
2206 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07002207 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002208 }
Jeff Brown4d396052010-10-29 21:50:21 -07002209 if ((mEndcallBehavior
2210 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
2211 result = (result & ~ACTION_POKE_USER_ACTIVITY) | ACTION_GO_TO_SLEEP;
2212 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002213 }
Jeff Brown4d396052010-10-29 21:50:21 -07002214 }
2215 break;
2216 }
2217
2218 case KeyEvent.KEYCODE_POWER: {
2219 result &= ~ACTION_PASS_TO_USER;
2220 if (down) {
2221 ITelephony telephonyService = getTelephonyService();
2222 boolean hungUp = false;
2223 if (telephonyService != null) {
2224 try {
2225 if (telephonyService.isRinging()) {
2226 // Pressing Power while there's a ringing incoming
2227 // call should silence the ringer.
2228 telephonyService.silenceRinger();
2229 } else if ((mIncallPowerBehavior
2230 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
2231 && telephonyService.isOffhook()) {
2232 // Otherwise, if "Power button ends call" is enabled,
2233 // the Power button will hang up any current active call.
2234 hungUp = telephonyService.endCall();
2235 }
2236 } catch (RemoteException ex) {
2237 Log.w(TAG, "ITelephony threw RemoteException", ex);
2238 }
2239 }
2240 interceptPowerKeyDown(!isScreenOn || hungUp);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002241 } else {
Jeff Brown4d396052010-10-29 21:50:21 -07002242 if (interceptPowerKeyUp(canceled)) {
2243 result = (result & ~ACTION_POKE_USER_ACTIVITY) | ACTION_GO_TO_SLEEP;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002244 }
Jeff Brown4d396052010-10-29 21:50:21 -07002245 }
2246 break;
2247 }
2248
2249 case KeyEvent.KEYCODE_MEDIA_PLAY:
2250 case KeyEvent.KEYCODE_MEDIA_PAUSE:
2251 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
2252 if (down) {
2253 ITelephony telephonyService = getTelephonyService();
2254 if (telephonyService != null) {
2255 try {
2256 if (!telephonyService.isIdle()) {
2257 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
2258 // to avoid music playback.
2259 break;
2260 }
2261 } catch (RemoteException ex) {
2262 Log.w(TAG, "ITelephony threw RemoteException", ex);
Jeff Brown3122e442010-10-11 23:32:49 -07002263 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002264 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002265 }
Jeff Brown4d396052010-10-29 21:50:21 -07002266 case KeyEvent.KEYCODE_HEADSETHOOK:
2267 case KeyEvent.KEYCODE_MUTE:
2268 case KeyEvent.KEYCODE_MEDIA_STOP:
2269 case KeyEvent.KEYCODE_MEDIA_NEXT:
2270 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
2271 case KeyEvent.KEYCODE_MEDIA_REWIND:
2272 case KeyEvent.KEYCODE_MEDIA_RECORD:
2273 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: {
2274 if ((result & ACTION_PASS_TO_USER) == 0) {
2275 // Only do this if we would otherwise not pass it to the user. In that
2276 // case, the PhoneWindow class will do the same thing, except it will
2277 // only do it if the showing app doesn't process the key on its own.
Jeff Brown4d396052010-10-29 21:50:21 -07002278 mBroadcastWakeLock.acquire();
Jeff Brown1f245102010-11-18 20:53:46 -08002279 mHandler.post(new PassHeadsetKey(new KeyEvent(event)));
Jeff Brown4d396052010-10-29 21:50:21 -07002280 }
2281 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002282 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002283
Jeff Brown4d396052010-10-29 21:50:21 -07002284 case KeyEvent.KEYCODE_CALL: {
2285 if (down) {
2286 ITelephony telephonyService = getTelephonyService();
2287 if (telephonyService != null) {
2288 try {
2289 if (telephonyService.isRinging()) {
2290 Log.i(TAG, "interceptKeyBeforeQueueing:"
2291 + " CALL key-down while ringing: Answer the call!");
2292 telephonyService.answerRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002293
Jeff Brown4d396052010-10-29 21:50:21 -07002294 // And *don't* pass this key thru to the current activity
2295 // (which is presumably the InCallScreen.)
2296 result &= ~ACTION_PASS_TO_USER;
2297 }
2298 } catch (RemoteException ex) {
2299 Log.w(TAG, "ITelephony threw RemoteException", ex);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002300 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002301 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002302 }
Jeff Brown4d396052010-10-29 21:50:21 -07002303 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002304 }
2305 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002306 return result;
2307 }
2308
2309 class PassHeadsetKey implements Runnable {
2310 KeyEvent mKeyEvent;
2311
2312 PassHeadsetKey(KeyEvent keyEvent) {
2313 mKeyEvent = keyEvent;
2314 }
2315
2316 public void run() {
2317 if (ActivityManagerNative.isSystemReady()) {
2318 Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
2319 intent.putExtra(Intent.EXTRA_KEY_EVENT, mKeyEvent);
2320 mContext.sendOrderedBroadcast(intent, null, mBroadcastDone,
2321 mHandler, Activity.RESULT_OK, null, null);
2322 }
2323 }
2324 }
2325
2326 BroadcastReceiver mBroadcastDone = new BroadcastReceiver() {
2327 public void onReceive(Context context, Intent intent) {
2328 mBroadcastWakeLock.release();
2329 }
2330 };
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002331
2332 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
2333 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002334 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
2335 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
2336 Intent.EXTRA_DOCK_STATE_UNDOCKED);
2337 } else {
2338 try {
2339 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
2340 ServiceManager.getService(Context.UI_MODE_SERVICE));
2341 mUiMode = uiModeService.getCurrentModeType();
2342 } catch (RemoteException e) {
2343 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07002344 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002345 updateRotation(Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
Mike Lockwoode9867d22009-09-20 01:59:02 -04002346 updateOrientationListenerLp();
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002347 }
2348 };
2349
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002350 /** {@inheritDoc} */
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002351 public void screenTurnedOff(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07002352 EventLog.writeEvent(70000, 0);
2353 mKeyguardMediator.onScreenTurnedOff(why);
The Android Open Source Project0727d222009-03-11 12:11:58 -07002354 synchronized (mLock) {
The Android Open Source Project0727d222009-03-11 12:11:58 -07002355 mScreenOn = false;
2356 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05002357 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07002358 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002359 }
2360
2361 /** {@inheritDoc} */
2362 public void screenTurnedOn() {
Dianne Hackborn74489012009-03-24 20:50:09 -07002363 EventLog.writeEvent(70000, 1);
2364 mKeyguardMediator.onScreenTurnedOn();
The Android Open Source Project0727d222009-03-11 12:11:58 -07002365 synchronized (mLock) {
The Android Open Source Project0727d222009-03-11 12:11:58 -07002366 mScreenOn = true;
2367 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05002368 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07002369 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002370 }
2371
2372 /** {@inheritDoc} */
Dianne Hackborn08743722009-12-21 12:16:51 -08002373 public boolean isScreenOn() {
2374 return mScreenOn;
2375 }
2376
2377 /** {@inheritDoc} */
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002378 public void enableKeyguard(boolean enabled) {
2379 mKeyguardMediator.setKeyguardEnabled(enabled);
2380 }
2381
2382 /** {@inheritDoc} */
2383 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
2384 mKeyguardMediator.verifyUnlock(callback);
2385 }
2386
Mike Lockwoodf7913302009-11-28 22:27:10 -05002387 private boolean keyguardIsShowingTq() {
Dianne Hackborn9dc06cc2009-11-17 18:19:23 -08002388 return mKeyguardMediator.isShowingAndNotHidden();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002389 }
2390
2391 /** {@inheritDoc} */
2392 public boolean inKeyguardRestrictedKeyInputMode() {
2393 return mKeyguardMediator.isInputRestricted();
2394 }
2395
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002396 void sendCloseSystemWindows() {
2397 sendCloseSystemWindows(mContext, null);
2398 }
2399
2400 void sendCloseSystemWindows(String reason) {
2401 sendCloseSystemWindows(mContext, reason);
2402 }
2403
2404 static void sendCloseSystemWindows(Context context, String reason) {
2405 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07002406 try {
2407 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
2408 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002409 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002410 }
2411 }
2412
The Android Open Source Project0727d222009-03-11 12:11:58 -07002413 public int rotationForOrientationLw(int orientation, int lastRotation,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002414 boolean displayEnabled) {
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07002415
2416 if (mPortraitRotation < 0) {
2417 // Initialize the rotation angles for each orientation once.
2418 Display d = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))
2419 .getDefaultDisplay();
2420 if (d.getWidth() > d.getHeight()) {
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07002421 mLandscapeRotation = Surface.ROTATION_0;
Steve Howarda7bfe6a2010-09-23 16:47:49 -07002422 mSeascapeRotation = Surface.ROTATION_180;
Dianne Hackborn07f3d662010-12-22 12:31:31 -08002423 if (mContext.getResources().getBoolean(
2424 com.android.internal.R.bool.config_reverseDefaultRotation)) {
2425 mPortraitRotation = Surface.ROTATION_90;
2426 mUpsideDownRotation = Surface.ROTATION_270;
2427 } else {
2428 mPortraitRotation = Surface.ROTATION_270;
2429 mUpsideDownRotation = Surface.ROTATION_90;
2430 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07002431 } else {
2432 mPortraitRotation = Surface.ROTATION_0;
Dianne Hackborne5439f22010-10-02 16:53:50 -07002433 mUpsideDownRotation = Surface.ROTATION_180;
Dianne Hackborn07f3d662010-12-22 12:31:31 -08002434 if (mContext.getResources().getBoolean(
2435 com.android.internal.R.bool.config_reverseDefaultRotation)) {
2436 mLandscapeRotation = Surface.ROTATION_270;
2437 mSeascapeRotation = Surface.ROTATION_90;
2438 } else {
2439 mLandscapeRotation = Surface.ROTATION_90;
2440 mSeascapeRotation = Surface.ROTATION_270;
2441 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07002442 }
2443 }
2444
The Android Open Source Project0727d222009-03-11 12:11:58 -07002445 synchronized (mLock) {
Dianne Hackborne5439f22010-10-02 16:53:50 -07002446 switch (orientation) {
2447 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
2448 //always return portrait if orientation set to portrait
2449 return mPortraitRotation;
2450 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
2451 //always return landscape if orientation set to landscape
2452 return mLandscapeRotation;
2453 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
2454 //always return portrait if orientation set to portrait
2455 return mUpsideDownRotation;
2456 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
2457 //always return seascape if orientation set to reverse landscape
2458 return mSeascapeRotation;
2459 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
2460 //return either landscape rotation based on the sensor
2461 mOrientationListener.setAllow180Rotation(false);
2462 return getCurrentLandscapeRotation(lastRotation);
2463 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
2464 mOrientationListener.setAllow180Rotation(true);
2465 return getCurrentPortraitRotation(lastRotation);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002466 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07002467
Dianne Hackborna1111872010-11-23 20:55:11 -08002468 mOrientationListener.setAllow180Rotation(mAllowAllRotations ||
Mathias Agopianf9ce8792010-11-13 22:01:50 -08002469 orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
Dianne Hackborne5439f22010-10-02 16:53:50 -07002470
The Android Open Source Project0727d222009-03-11 12:11:58 -07002471 // case for nosensor meaning ignore sensor and consider only lid
2472 // or orientation sensor disabled
2473 //or case.unspecified
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08002474 if (mHdmiPlugged) {
2475 return Surface.ROTATION_0;
2476 } else if (mLidOpen) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002477 return mLidOpenRotation;
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002478 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR && mCarDockRotation >= 0) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04002479 return mCarDockRotation;
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002480 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_DESK && mDeskDockRotation >= 0) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04002481 return mDeskDockRotation;
Daniel Sandlerb73617d2010-08-17 00:41:00 -04002482 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
2483 return mUserRotation;
The Android Open Source Project0727d222009-03-11 12:11:58 -07002484 } else {
Dianne Hackborn03759ed2009-03-27 16:04:08 -07002485 if (useSensorForOrientationLp(orientation)) {
Steve Howard5eb49582010-08-16 11:41:58 -07002486 return mOrientationListener.getCurrentRotation(lastRotation);
The Android Open Source Project0727d222009-03-11 12:11:58 -07002487 }
2488 return Surface.ROTATION_0;
2489 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002490 }
2491 }
2492
Steve Howarda7bfe6a2010-09-23 16:47:49 -07002493 private int getCurrentLandscapeRotation(int lastRotation) {
Dianne Hackborne5439f22010-10-02 16:53:50 -07002494 int sensorRotation = mOrientationListener.getCurrentRotation(lastRotation);
2495 if (isLandscapeOrSeascape(sensorRotation)) {
2496 return sensorRotation;
Steve Howarda7bfe6a2010-09-23 16:47:49 -07002497 }
2498 // try to preserve the old rotation if it was landscape
2499 if (isLandscapeOrSeascape(lastRotation)) {
2500 return lastRotation;
2501 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07002502 // default to one of the primary landscape rotation
Steve Howarda7bfe6a2010-09-23 16:47:49 -07002503 return mLandscapeRotation;
2504 }
2505
2506 private boolean isLandscapeOrSeascape(int sensorRotation) {
2507 return sensorRotation == mLandscapeRotation || sensorRotation == mSeascapeRotation;
2508 }
2509
Dianne Hackborne5439f22010-10-02 16:53:50 -07002510 private int getCurrentPortraitRotation(int lastRotation) {
2511 int sensorRotation = mOrientationListener.getCurrentRotation(lastRotation);
2512 if (isAnyPortrait(sensorRotation)) {
2513 return sensorRotation;
2514 }
2515 // try to preserve the old rotation if it was portrait
2516 if (isAnyPortrait(lastRotation)) {
2517 return lastRotation;
2518 }
2519 // default to one of the primary portrait rotations
2520 return mPortraitRotation;
2521 }
2522
2523 private boolean isAnyPortrait(int sensorRotation) {
2524 return sensorRotation == mPortraitRotation || sensorRotation == mUpsideDownRotation;
2525 }
2526
Daniel Sandlerb73617d2010-08-17 00:41:00 -04002527
2528 // User rotation: to be used when all else fails in assigning an orientation to the device
2529 public void setUserRotationMode(int mode, int rot) {
2530 ContentResolver res = mContext.getContentResolver();
2531 mUserRotationMode = mode;
2532 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
2533 mUserRotation = rot;
2534 Settings.System.putInt(res,
2535 Settings.System.ACCELEROMETER_ROTATION,
2536 0);
2537 Settings.System.putInt(res,
2538 Settings.System.USER_ROTATION,
2539 rot);
2540 } else {
2541 Settings.System.putInt(res,
2542 Settings.System.ACCELEROMETER_ROTATION,
2543 1);
2544 }
2545 }
2546
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002547 public boolean detectSafeMode() {
2548 try {
2549 int menuState = mWindowManager.getKeycodeState(KeyEvent.KEYCODE_MENU);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07002550 int sState = mWindowManager.getKeycodeState(KeyEvent.KEYCODE_S);
Dianne Hackborna8730f92009-11-17 15:53:36 -08002551 int dpadState = mWindowManager.getDPadKeycodeState(KeyEvent.KEYCODE_DPAD_CENTER);
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002552 int trackballState = mWindowManager.getTrackballScancodeState(BTN_MOUSE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07002553 mSafeMode = menuState > 0 || sState > 0 || dpadState > 0 || trackballState > 0;
2554 performHapticFeedbackLw(null, mSafeMode
2555 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
2556 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
Dianne Hackborn73b1ec82009-10-04 13:33:00 -07002557 if (mSafeMode) {
2558 Log.i(TAG, "SAFE MODE ENABLED (menu=" + menuState + " s=" + sState
2559 + " dpad=" + dpadState + " trackball=" + trackballState + ")");
2560 } else {
2561 Log.i(TAG, "SAFE MODE not enabled");
2562 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002563 return mSafeMode;
2564 } catch (RemoteException e) {
2565 // Doom! (it's also local)
2566 throw new RuntimeException("window manager dead");
2567 }
2568 }
2569
Dianne Hackborn181ceb52009-08-27 22:16:40 -07002570 static long[] getLongIntArray(Resources r, int resid) {
2571 int[] ar = r.getIntArray(resid);
2572 if (ar == null) {
2573 return null;
2574 }
2575 long[] out = new long[ar.length];
2576 for (int i=0; i<ar.length; i++) {
2577 out[i] = ar[i];
2578 }
2579 return out;
2580 }
2581
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002582 /** {@inheritDoc} */
2583 public void systemReady() {
Dianne Hackbornb1a79802009-09-29 15:18:31 -07002584 // tell the keyguard
2585 mKeyguardMediator.onSystemReady();
2586 android.os.SystemProperties.set("dev.bootcomplete", "1");
2587 synchronized (mLock) {
2588 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08002589 mSystemReady = true;
2590 mHandler.post(new Runnable() {
2591 public void run() {
2592 updateSettings();
2593 }
2594 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002595 }
2596 }
2597
Mike Lockwood28569302010-01-28 11:54:40 -05002598 /** {@inheritDoc} */
2599 public void userActivity() {
2600 synchronized (mScreenLockTimeout) {
2601 if (mLockScreenTimerActive) {
2602 // reset the timer
2603 mHandler.removeCallbacks(mScreenLockTimeout);
2604 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
2605 }
2606 }
2607 }
2608
2609 Runnable mScreenLockTimeout = new Runnable() {
2610 public void run() {
2611 synchronized (this) {
2612 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
2613 mKeyguardMediator.doKeyguardTimeout();
2614 mLockScreenTimerActive = false;
2615 }
2616 }
2617 };
2618
2619 private void updateLockScreenTimeout() {
2620 synchronized (mScreenLockTimeout) {
2621 boolean enable = (mAllowLockscreenWhenOn && mScreenOn && mKeyguardMediator.isSecure());
2622 if (mLockScreenTimerActive != enable) {
2623 if (enable) {
2624 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
2625 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
2626 } else {
2627 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
2628 mHandler.removeCallbacks(mScreenLockTimeout);
2629 }
2630 mLockScreenTimerActive = enable;
2631 }
2632 }
2633 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002634
2635 /** {@inheritDoc} */
2636 public void enableScreenAfterBoot() {
2637 readLidState();
Dianne Hackborn32bc91d2009-03-27 16:16:03 -07002638 updateRotation(Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002639 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07002640
Dianne Hackborn03759ed2009-03-27 16:04:08 -07002641 void updateRotation(int animFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002642 mPowerManager.setKeyboardVisibility(mLidOpen);
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002643 int rotation = Surface.ROTATION_0;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08002644 if (mHdmiPlugged) {
2645 rotation = Surface.ROTATION_0;
2646 } else if (mLidOpen) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07002647 rotation = mLidOpenRotation;
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002648 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR && mCarDockRotation >= 0) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04002649 rotation = mCarDockRotation;
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002650 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_DESK && mDeskDockRotation >= 0) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04002651 rotation = mDeskDockRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002652 }
2653 //if lid is closed orientation will be portrait
2654 try {
2655 //set orientation on WindowManager
Dianne Hackborn32bc91d2009-03-27 16:16:03 -07002656 mWindowManager.setRotation(rotation, true,
2657 mFancyRotationAnimation | animFlags);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002658 } catch (RemoteException e) {
2659 // Ignore
2660 }
2661 }
2662
2663 /**
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002664 * Return an Intent to launch the currently active dock as home. Returns
2665 * null if the standard home should be launched.
2666 * @return
2667 */
2668 Intent createHomeDockIntent() {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002669 Intent intent;
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002670
2671 // What home does is based on the mode, not the dock state. That
2672 // is, when in car mode you should be taken to car home regardless
2673 // of whether we are actually in a car dock.
Dianne Hackborn78968392010-03-04 20:47:56 -08002674 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002675 intent = mCarDockIntent;
Dianne Hackborn78968392010-03-04 20:47:56 -08002676 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002677 intent = mDeskDockIntent;
2678 } else {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002679 return null;
2680 }
2681
2682 ActivityInfo ai = intent.resolveActivityInfo(
2683 mContext.getPackageManager(), PackageManager.GET_META_DATA);
2684 if (ai == null) {
2685 return null;
2686 }
2687
2688 if (ai.metaData != null && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
2689 intent = new Intent(intent);
2690 intent.setClassName(ai.packageName, ai.name);
2691 return intent;
2692 }
2693
2694 return null;
2695 }
2696
2697 void startDockOrHome() {
2698 Intent dock = createHomeDockIntent();
2699 if (dock != null) {
2700 try {
2701 mContext.startActivity(dock);
2702 return;
2703 } catch (ActivityNotFoundException e) {
2704 }
2705 }
2706 mContext.startActivity(mHomeIntent);
2707 }
2708
2709 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002710 * goes to the home screen
2711 * @return whether it did anything
2712 */
2713 boolean goHome() {
2714 if (false) {
2715 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002716 try {
2717 ActivityManagerNative.getDefault().stopAppSwitches();
2718 } catch (RemoteException e) {
2719 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07002720 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002721 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002722 } else {
2723 // This code brings home to the front or, if it is already
2724 // at the front, puts the device to sleep.
2725 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08002726 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
2727 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
2728 Log.d(TAG, "UTS-TEST-MODE");
2729 } else {
2730 ActivityManagerNative.getDefault().stopAppSwitches();
2731 sendCloseSystemWindows();
2732 Intent dock = createHomeDockIntent();
2733 if (dock != null) {
2734 int result = ActivityManagerNative.getDefault()
2735 .startActivity(null, dock,
2736 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
2737 null, 0, null, null, 0, true /* onlyIfNeeded*/, false);
2738 if (result == IActivityManager.START_RETURN_INTENT_TO_CALLER) {
2739 return false;
2740 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002741 }
2742 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002743 int result = ActivityManagerNative.getDefault()
2744 .startActivity(null, mHomeIntent,
2745 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
2746 null, 0, null, null, 0, true /* onlyIfNeeded*/, false);
2747 if (result == IActivityManager.START_RETURN_INTENT_TO_CALLER) {
2748 return false;
2749 }
2750 } catch (RemoteException ex) {
2751 // bummer, the activity manager, which is in this process, is dead
2752 }
2753 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002754 return true;
2755 }
2756
The Android Open Source Project0727d222009-03-11 12:11:58 -07002757 public void setCurrentOrientationLw(int newOrientation) {
2758 synchronized (mLock) {
2759 if (newOrientation != mCurrentAppOrientation) {
2760 mCurrentAppOrientation = newOrientation;
2761 updateOrientationListenerLp();
2762 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002763 }
2764 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08002765
The Android Open Source Project0727d222009-03-11 12:11:58 -07002766 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Jim Miller89b17222009-10-27 14:54:09 -07002767 final boolean hapticsDisabled = Settings.System.getInt(mContext.getContentResolver(),
2768 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0) == 0;
Dianne Hackborn9dc06cc2009-11-17 18:19:23 -08002769 if (!always && (hapticsDisabled || mKeyguardMediator.isShowingAndNotHidden())) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002770 return false;
2771 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08002772 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002773 switch (effectId) {
2774 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08002775 pattern = mLongPressVibePattern;
2776 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07002777 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08002778 pattern = mVirtualKeyVibePattern;
2779 break;
2780 case HapticFeedbackConstants.KEYBOARD_TAP:
2781 pattern = mKeyboardTapVibePattern;
2782 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07002783 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08002784 pattern = mSafeModeDisabledVibePattern;
2785 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07002786 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08002787 pattern = mSafeModeEnabledVibePattern;
2788 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08002789 default:
2790 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002791 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08002792 if (pattern.length == 1) {
2793 // One-shot vibration
2794 mVibrator.vibrate(pattern[0]);
2795 } else {
2796 // Pattern vibration
2797 mVibrator.vibrate(pattern, -1);
2798 }
2799 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002800 }
2801
The Android Open Source Project0727d222009-03-11 12:11:58 -07002802 public void screenOnStoppedLw() {
Dianne Hackborn9dc06cc2009-11-17 18:19:23 -08002803 if (!mKeyguardMediator.isShowingAndNotHidden() && mPowerManager.isScreenOn()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002804 long curTime = SystemClock.uptimeMillis();
2805 mPowerManager.userActivity(curTime, false, LocalPowerManager.OTHER_EVENT);
2806 }
2807 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04002808
2809 public boolean allowKeyRepeat() {
2810 // disable key repeat when screen is off
2811 return mScreenOn;
2812 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08002813
2814 public void dump(String prefix, FileDescriptor fd, PrintWriter pw, String[] args) {
2815 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
2816 pw.print(" mSystemRead="); pw.println(mSystemReady);
2817 pw.print(prefix); pw.print("mLidOpen="); pw.print(mLidOpen);
2818 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
2819 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
2820 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
2821 pw.print(" mDockMode="); pw.print(mDockMode);
2822 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
2823 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
2824 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
2825 pw.print(" mUserRotation="); pw.print(mUserRotation);
2826 pw.print("mAllowAllRotations="); pw.println(mAllowAllRotations);
2827 pw.print(prefix); pw.print("mAccelerometerDefault="); pw.print(mAccelerometerDefault);
2828 pw.print(" mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
2829 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
2830 pw.print(mCarDockEnablesAccelerometer);
2831 pw.print(" mDeskDockEnablesAccelerometer=");
2832 pw.println(mDeskDockEnablesAccelerometer);
2833 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
2834 pw.print(mLidKeyboardAccessibility);
2835 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
2836 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
2837 pw.print(prefix); pw.print("mScreenOn="); pw.print(mScreenOn);
2838 pw.print(" mOrientationSensorEnabled="); pw.print(mOrientationSensorEnabled);
2839 pw.print(" mHasSoftInput="); pw.println(mHasSoftInput);
2840 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
2841 pw.print(","); pw.print(mUnrestrictedScreenTop);
2842 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
2843 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
2844 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
2845 pw.print(","); pw.print(mRestrictedScreenTop);
2846 pw.print(") "); pw.print(mRestrictedScreenWidth);
2847 pw.print("x"); pw.println(mRestrictedScreenHeight);
2848 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
2849 pw.print(","); pw.print(mCurTop);
2850 pw.print(")-("); pw.print(mCurRight);
2851 pw.print(","); pw.print(mCurBottom); pw.println(")");
2852 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
2853 pw.print(","); pw.print(mContentTop);
2854 pw.print(")-("); pw.print(mContentRight);
2855 pw.print(","); pw.print(mContentBottom); pw.println(")");
2856 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
2857 pw.print(","); pw.print(mDockTop);
2858 pw.print(")-("); pw.print(mDockRight);
2859 pw.print(","); pw.print(mDockBottom); pw.println(")");
2860 pw.print(prefix); pw.print("mDockLayer="); pw.println(mDockLayer);
2861 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
2862 pw.println(mTopFullscreenOpaqueWindowState);
2863 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
2864 pw.print(" mForceStatusBar="); pw.print(mForceStatusBar);
2865 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
2866 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
2867 pw.print(" mHomePressed="); pw.println(mHomePressed);
2868 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
2869 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
2870 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
2871 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
2872 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
2873 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
2874 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
2875 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
2876 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
2877 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
2878 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002879}