blob: f3622efdaa7bd19ad3e1994c56a07412c8dcbfbb [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16package com.android.internal.policy.impl;
17
18import android.app.Activity;
Dianne Hackborna4972e92012-03-14 10:38:05 -070019import android.app.ActivityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080020import android.app.ActivityManagerNative;
Dianne Hackborn78968392010-03-04 20:47:56 -080021import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070022import android.app.ProgressDialog;
Dianne Hackborn78968392010-03-04 20:47:56 -080023import 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;
Daniel Sandler0601eb72011-04-13 01:01:32 -040026import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080027import android.content.ContentResolver;
28import android.content.Context;
29import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070030import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070031import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080032import android.content.pm.ActivityInfo;
33import android.content.pm.PackageManager;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070034import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080035import android.content.res.Configuration;
36import android.content.res.Resources;
37import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080038import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080039import android.graphics.Rect;
Dianne Hackbornd040edb2011-08-31 12:47:58 -070040import android.graphics.RectF;
Michael Jurka7a348952012-02-27 13:07:58 -080041import android.media.AudioManager;
42import android.media.IAudioService;
Daniel Sandler7e37df52011-11-16 22:08:23 -080043import android.os.BatteryManager;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070044import android.os.Bundle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080045import android.os.Handler;
46import android.os.IBinder;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070047import android.os.IRemoteCallback;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080048import android.os.LocalPowerManager;
Jeff Brown32cbc38552011-12-01 14:01:49 -080049import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070050import android.os.Message;
51import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080052import android.os.PowerManager;
53import android.os.RemoteException;
54import android.os.ServiceManager;
55import android.os.SystemClock;
56import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080057import android.os.UEventObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080058import android.os.Vibrator;
59import android.provider.Settings;
60
Jim Millere6ad1a82010-08-20 19:25:39 -070061import com.android.internal.R;
Joe Onoratod208e702010-10-08 16:22:43 -040062import com.android.internal.app.ShutdownThread;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080063import com.android.internal.policy.PolicyManager;
Joe Onorato0cbda992010-05-02 16:28:15 -070064import com.android.internal.statusbar.IStatusBarService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080065import com.android.internal.telephony.ITelephony;
Dianne Hackborn6019c9d2010-03-01 21:43:11 -080066import com.android.internal.widget.PointerLocationView;
67
Michael Jurka7a348952012-02-27 13:07:58 -080068import android.speech.RecognizerIntent;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070069import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080070import android.util.EventLog;
71import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070072import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080073import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070074import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080075import android.view.Gravity;
76import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080077import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080078import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070079import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070080import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080081import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080082import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080083import android.view.KeyCharacterMap;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080084import android.view.KeyEvent;
85import android.view.MotionEvent;
86import android.view.WindowOrientationListener;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080087import android.view.Surface;
88import android.view.View;
89import android.view.ViewConfiguration;
90import android.view.Window;
91import android.view.WindowManager;
92import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
93import static android.view.WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN;
94import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN;
95import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
96import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR;
97import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -070098import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070099import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Mike Lockwood28569302010-01-28 11:54:40 -0500100import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800101import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
102import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Dianne Hackborndea3ef72010-10-28 14:24:22 -0700103import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800104import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
105import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700106import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800107import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
108import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL;
109import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Christopher Tatea53146c2010-09-07 11:57:52 -0700110import static android.view.WindowManager.LayoutParams.TYPE_DRAG;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700111import static android.view.WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800112import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD;
113import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
114import static android.view.WindowManager.LayoutParams.TYPE_PHONE;
115import static android.view.WindowManager.LayoutParams.TYPE_PRIORITY_PHONE;
116import static android.view.WindowManager.LayoutParams.TYPE_SEARCH_BAR;
Jeff Brown3b2b3542010-10-15 00:54:27 -0700117import static android.view.WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800118import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
119import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL;
Joe Onorato29fc2c92010-11-24 10:26:50 -0800120import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL;
Dianne Hackborn6a294ce2009-12-03 11:37:44 -0800121import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800122import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
123import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
124import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
125import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
126import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
127import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Dianne Hackborne8ecde12011-08-03 18:55:19 -0700128import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY;
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -0700129import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Jeff Brown83c09682010-12-23 17:50:18 -0800130import static android.view.WindowManager.LayoutParams.TYPE_POINTER;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400131import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -0700132import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800133import android.view.WindowManagerImpl;
134import android.view.WindowManagerPolicy;
Jeff Brownac143512012-04-05 18:57:33 -0700135import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
136import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
137import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Jeff Brown6f2fba42011-02-19 01:08:02 -0800138import android.view.KeyCharacterMap.FallbackAction;
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700139import android.view.accessibility.AccessibilityEvent;
Dianne Hackborn01ad2f42009-09-24 19:24:56 -0700140import android.view.animation.Animation;
141import android.view.animation.AnimationUtils;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800142
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800143import java.io.File;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800144import java.io.FileDescriptor;
Joe Onoratodc100302011-01-11 17:07:41 -0800145import java.io.FileReader;
146import java.io.IOException;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800147import java.io.PrintWriter;
Dianne Hackborn08743722009-12-21 12:16:51 -0800148import java.util.ArrayList;
149
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800150/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700151 * WindowManagerPolicy implementation for the Android phone UI. This
152 * introduces a new method suffix, Lp, for an internal lock of the
153 * PhoneWindowManager. This is used to protect some internal state, and
154 * can be acquired with either thw Lw and Li lock held, so has the restrictions
155 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800156 */
157public class PhoneWindowManager implements WindowManagerPolicy {
158 static final String TAG = "WindowManager";
159 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700160 static final boolean localLOGV = false;
The Android Open Source Project11267662009-03-18 17:39:47 -0700161 static final boolean DEBUG_LAYOUT = false;
Jeff Brown49ed71d2010-12-06 17:13:33 -0800162 static final boolean DEBUG_FALLBACK = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800163 static final boolean SHOW_STARTING_ANIMATIONS = true;
164 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400165
Daniel Sandler11ddf532011-11-16 11:10:03 -0800166 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
167 // No longer recommended for desk docks; still useful in car docks.
168 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
169 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
170
Daniel Sandler7e37df52011-11-16 22:08:23 -0800171 // Should screen savers use their own timeout, or the SCREEN_OFF_TIMEOUT?
172 static final boolean SEPARATE_TIMEOUT_FOR_SCREEN_SAVER = false;
173
Joe Onoratod208e702010-10-08 16:22:43 -0400174 static final int LONG_PRESS_POWER_NOTHING = 0;
175 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
176 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700177
178 // These need to match the documentation/constant in
179 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800180 static final int LONG_PRESS_HOME_NOTHING = 0;
181 static final int LONG_PRESS_HOME_RECENT_DIALOG = 1;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700182 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 2;
Michael Jurka7a348952012-02-27 13:07:58 -0800183 static final int LONG_PRESS_HOME_VOICE_SEARCH = 3;
Joe Onorato46b0d682010-11-22 17:37:27 -0800184
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -0700185 // wallpaper is at the bottom, though the window manager may move it.
Dianne Hackborn3c3bd442009-08-19 17:09:46 -0700186 static final int WALLPAPER_LAYER = 2;
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -0700187 static final int APPLICATION_LAYER = 2;
188 static final int PHONE_LAYER = 3;
189 static final int SEARCH_BAR_LAYER = 4;
Dianne Hackborne8ecde12011-08-03 18:55:19 -0700190 static final int SYSTEM_DIALOG_LAYER = 5;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800191 // toasts and the plugged-in battery thing
Dianne Hackborne8ecde12011-08-03 18:55:19 -0700192 static final int TOAST_LAYER = 6;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800193 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne8ecde12011-08-03 18:55:19 -0700194 static final int PRIORITY_PHONE_LAYER = 7;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800195 // like the ANR / app crashed dialogs
Dianne Hackborne8ecde12011-08-03 18:55:19 -0700196 static final int SYSTEM_ALERT_LAYER = 8;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800197 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborn38cc8962011-10-13 11:33:55 -0700198 static final int INPUT_METHOD_LAYER = 9;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800199 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborn38cc8962011-10-13 11:33:55 -0700200 static final int INPUT_METHOD_DIALOG_LAYER = 10;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800201 // the keyguard; nothing on top of these can take focus, since they are
202 // responsible for power management when displayed.
Dianne Hackborn38cc8962011-10-13 11:33:55 -0700203 static final int KEYGUARD_LAYER = 11;
204 static final int KEYGUARD_DIALOG_LAYER = 12;
205 static final int STATUS_BAR_SUB_PANEL_LAYER = 13;
206 static final int STATUS_BAR_LAYER = 14;
207 static final int STATUS_BAR_PANEL_LAYER = 15;
Dianne Hackborne8ecde12011-08-03 18:55:19 -0700208 // the on-screen volume indicator and controller shown when the user
209 // changes the device volume
Dianne Hackborn38cc8962011-10-13 11:33:55 -0700210 static final int VOLUME_OVERLAY_LAYER = 16;
Jeff Brownbfcb60a2011-09-08 18:51:14 -0700211 // things in here CAN NOT take focus, but are shown on top of everything else.
Dianne Hackborn38cc8962011-10-13 11:33:55 -0700212 static final int SYSTEM_OVERLAY_LAYER = 17;
Jeff Brownbfcb60a2011-09-08 18:51:14 -0700213 // the navigation bar, if available, shows atop most things
Dianne Hackborn38cc8962011-10-13 11:33:55 -0700214 static final int NAVIGATION_BAR_LAYER = 18;
215 // system-level error dialogs
216 static final int SYSTEM_ERROR_LAYER = 19;
Christopher Tatea53146c2010-09-07 11:57:52 -0700217 // the drag layer: input for drag-and-drop is associated with this window,
218 // which sits above all other focusable windows
Jeff Brownbfcb60a2011-09-08 18:51:14 -0700219 static final int DRAG_LAYER = 20;
Dianne Hackborne8ecde12011-08-03 18:55:19 -0700220 static final int SECURE_SYSTEM_OVERLAY_LAYER = 21;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -0700221 static final int BOOT_PROGRESS_LAYER = 22;
Jeff Brown83c09682010-12-23 17:50:18 -0800222 // the (mouse) pointer layer
Dianne Hackborn29aae6f2011-08-18 18:30:09 -0700223 static final int POINTER_LAYER = 23;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700224 static final int HIDDEN_NAV_CONSUMER_LAYER = 24;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800225
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700226 static final int APPLICATION_MEDIA_SUBLAYER = -2;
227 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800228 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800229 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800230
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800231 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
232 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
233 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500234 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800235
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700236 /**
237 * These are the system UI flags that, when changing, can cause the layout
238 * of the screen to change.
239 */
240 static final int SYSTEM_UI_CHANGING_LAYOUT =
241 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
242
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700243 private static final int BTN_MOUSE = 0x110;
Jeff Brown6651a632011-11-28 12:59:11 -0800244
245 /* Table of Application Launch keys. Maps from key codes to intent categories.
246 *
247 * These are special keys that are used to launch particular kinds of applications,
248 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
249 * usage page. We don't support quite that many yet...
250 */
251 static SparseArray<String> sApplicationLaunchKeyCategories;
252 static {
253 sApplicationLaunchKeyCategories = new SparseArray<String>();
254 sApplicationLaunchKeyCategories.append(
255 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
256 sApplicationLaunchKeyCategories.append(
257 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
258 sApplicationLaunchKeyCategories.append(
259 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
260 sApplicationLaunchKeyCategories.append(
261 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
262 sApplicationLaunchKeyCategories.append(
263 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
264 sApplicationLaunchKeyCategories.append(
265 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
266 }
267
Dianne Hackborndf89e652011-10-06 22:35:11 -0700268 /**
269 * Lock protecting internal state. Must not call out into window
270 * manager with lock held. (This lock will be acquired in places
271 * where the window manager is calling in with its own lock held.)
272 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700273 final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700274
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800275 Context mContext;
276 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700277 WindowManagerFuncs mWindowManagerFuncs;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800278 LocalPowerManager mPowerManager;
Joe Onorato93056472010-09-10 10:30:46 -0400279 IStatusBarService mStatusBarService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800280 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
281
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700282 // Vibrator pattern for haptic feedback of a long press.
283 long[] mLongPressVibePattern;
284
285 // Vibrator pattern for haptic feedback of virtual key press.
286 long[] mVirtualKeyVibePattern;
287
Amith Yamasanic33cb712010-02-10 15:21:49 -0800288 // Vibrator pattern for a short vibration.
289 long[] mKeyboardTapVibePattern;
290
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700291 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
292 long[] mSafeModeDisabledVibePattern;
293
294 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
295 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700296
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800297 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
298 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400299
300 boolean mHeadless;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800301 boolean mSafeMode;
302 WindowState mStatusBar = null;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700303 boolean mHasSystemNavBar;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700304 int mStatusBarHeight;
Dianne Hackborn08743722009-12-21 12:16:51 -0800305 final ArrayList<WindowState> mStatusBarPanels = new ArrayList<WindowState>();
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400306 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400307 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700308 boolean mCanHideNavigationBar = false;
309 boolean mNavigationBarOnBottom = true;
Daniel Sandler36412a72011-08-04 09:35:13 -0400310 int mNavigationBarWidth = 0, mNavigationBarHeight = 0;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400311
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800312 WindowState mKeyguard = null;
313 KeyguardViewMediator mKeyguardMediator;
314 GlobalActions mGlobalActions;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700315 volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread
316 boolean mPendingPowerKeyUpCanceled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800317 Handler mHandler;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800318
Jeff Brown68b909d2011-12-07 16:36:01 -0800319 static final int RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS = 0;
320 static final int RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW = 1;
321 static final int RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH = 2;
322
323 RecentApplicationsDialog mRecentAppsDialog;
324 int mRecentAppsDialogHeldModifiers;
325
Jeff Brown4aed78b2011-01-14 17:36:55 -0800326 int mLidOpen = LID_ABSENT;
327
Dianne Hackbornc777e072010-02-12 13:07:59 -0800328 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700329 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800330 boolean mHdmiPlugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700331 int mExternalDisplayWidth;
332 int mExternalDisplayHeight;
Joe Onorato44fcb832011-12-14 20:59:30 -0800333 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700334 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700335 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400336 int mCarDockRotation;
337 int mDeskDockRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -0700338 int mHdmiRotation;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400339
340 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
341 int mUserRotation = Surface.ROTATION_0;
342
Jeff Brownd3187e32011-09-21 19:26:44 -0700343 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400344 boolean mCarDockEnablesAccelerometer;
345 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700346 int mLidKeyboardAccessibility;
347 int mLidNavigationAccessibility;
Joe Onoratod208e702010-10-08 16:22:43 -0400348 int mLongPressOnPowerBehavior = -1;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700349 boolean mScreenOnEarly = false;
350 boolean mScreenOnFully = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800351 boolean mOrientationSensorEnabled = false;
352 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
353 static final int DEFAULT_ACCELEROMETER_ROTATION = 0;
354 int mAccelerometerDefault = DEFAULT_ACCELEROMETER_ROTATION;
355 boolean mHasSoftInput = false;
356
Jeff Brown70825162012-03-28 17:27:48 -0700357 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800358
359 // The last window we were told about in focusChanged.
360 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800361 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800362
Jeff Brown70825162012-03-28 17:27:48 -0700363 private static final class PointerLocationInputEventReceiver extends InputEventReceiver {
364 private final PointerLocationView mView;
365
366 public PointerLocationInputEventReceiver(InputChannel inputChannel, Looper looper,
367 PointerLocationView view) {
Jeff Brown32cbc38552011-12-01 14:01:49 -0800368 super(inputChannel, looper);
Jeff Brown70825162012-03-28 17:27:48 -0700369 mView = view;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800370 }
371
Jeff Browna41ca772010-08-11 14:46:32 -0700372 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -0800373 public void onInputEvent(InputEvent event) {
Jeff Brown3915bb82010-11-05 15:02:16 -0700374 boolean handled = false;
375 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -0800376 if (event instanceof MotionEvent
377 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
378 final MotionEvent motionEvent = (MotionEvent)event;
Jeff Brown70825162012-03-28 17:27:48 -0700379 mView.addPointerEvent(motionEvent);
380 handled = true;
Jeff Brown93ed4e32010-09-23 13:51:48 -0700381 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700382 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -0800383 finishInputEvent(event, handled);
Jeff Browna41ca772010-08-11 14:46:32 -0700384 }
385 }
Jeff Brown32cbc38552011-12-01 14:01:49 -0800386 }
Jeff Brown70825162012-03-28 17:27:48 -0700387
388 // Pointer location view state, only modified on the mHandler Looper.
Jeff Brown32cbc38552011-12-01 14:01:49 -0800389 PointerLocationInputEventReceiver mPointerLocationInputEventReceiver;
Jeff Brown70825162012-03-28 17:27:48 -0700390 PointerLocationView mPointerLocationView;
391 InputChannel mPointerLocationInputChannel;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800392
Joe Onorato29fc2c92010-11-24 10:26:50 -0800393 // The current size of the screen; really; (ir)regardless of whether the status
394 // bar can be hidden or not
395 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
396 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700397 // The current size of the screen; these may be different than (0,0)-(dw,dh)
398 // if the status bar can't be hidden; in that case it effectively carves out
399 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800400 int mRestrictedScreenLeft, mRestrictedScreenTop;
401 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700402 // For applications requesting stable content insets, these are them.
403 int mStableLeft, mStableTop, mStableRight, mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800404 // During layout, the current screen borders with all outer decoration
405 // (status bar, input method dock) accounted for.
406 int mCurLeft, mCurTop, mCurRight, mCurBottom;
407 // During layout, the frame in which content should be displayed
408 // to the user, accounting for all screen decoration except for any
409 // space they deem as available for other content. This is usually
410 // the same as mCur*, but may be larger if the screen decor has supplied
411 // content insets.
412 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800413 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800414 // windows are placed.
415 int mDockLeft, mDockTop, mDockRight, mDockBottom;
416 // During layout, the layer at which the doc window is placed.
417 int mDockLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700418 int mLastSystemUiFlags;
419 // Bits that we are in the process of clearing, so we want to prevent
420 // them from being set by applications until everything has been updated
421 // to have them clear.
422 int mResettingSystemUiFlags = 0;
423 // Bits that we are currently always keeping cleared.
424 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800425 // What we last reported to system UI about whether the compatibility
426 // menu needs to be displayed.
427 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700428
429 FakeWindow mHideNavFakeWindow = null;
430
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800431 static final Rect mTmpParentFrame = new Rect();
432 static final Rect mTmpDisplayFrame = new Rect();
433 static final Rect mTmpContentFrame = new Rect();
434 static final Rect mTmpVisibleFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700435 static final Rect mTmpNavigationFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800436
437 WindowState mTopFullscreenOpaqueWindowState;
Joe Onorato93056472010-09-10 10:30:46 -0400438 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800439 boolean mForceStatusBar;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700440 boolean mHideLockScreen;
441 boolean mDismissKeyguard;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800442 boolean mHomePressed;
Michael Jurka7f2668c2012-03-27 07:49:52 -0700443 boolean mHomeLongPressed;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800444 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700445 Intent mCarDockIntent;
446 Intent mDeskDockIntent;
Jeff Brown49ed71d2010-12-06 17:13:33 -0800447 int mShortcutKeyPressed = -1;
448 boolean mConsumeShortcutKeyUp;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800449
Mike Lockwood28569302010-01-28 11:54:40 -0500450 // support for activating the lock screen while the screen is on
451 boolean mAllowLockscreenWhenOn;
452 int mLockScreenTimeout;
453 boolean mLockScreenTimerActive;
454
Daniel Sandler0601eb72011-04-13 01:01:32 -0400455 // visual screen saver support
Daniel Sandlere5f2cfe2011-11-02 23:30:58 -0400456 int mScreenSaverTimeout = 0;
Daniel Sandler2d545362011-11-17 10:38:37 -0800457 boolean mScreenSaverEnabledByUser = false;
458 boolean mScreenSaverMayRun = true; // false if a wakelock is held
Daniel Sandler7e37df52011-11-16 22:08:23 -0800459 boolean mPluggedIn;
Daniel Sandler0601eb72011-04-13 01:01:32 -0400460
David Brownbaf8d092010-03-08 21:52:59 -0800461 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800462 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800463
464 // Behavior of POWER button while in-call and screen on.
465 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
466 int mIncallPowerBehavior;
467
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700468 Display mDisplay;
469
Dianne Hackborn9d132642011-04-21 17:26:39 -0700470 int mLandscapeRotation = 0; // default landscape rotation
471 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
472 int mPortraitRotation = 0; // default portrait rotation
473 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700474
Joe Onorato46b0d682010-11-22 17:37:27 -0800475 // What we do when the user long presses on home
476 private int mLongPressOnHomeBehavior = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800477
Winson Chung9112ec32011-06-27 13:15:32 -0700478 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700479 // Time to volume and power must be pressed within this interval of each other.
480 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Christopher Tatee90585f2012-03-05 18:56:25 -0800481 private boolean mScreenshotChordEnabled;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700482 private boolean mVolumeDownKeyTriggered;
483 private long mVolumeDownKeyTime;
484 private boolean mVolumeDownKeyConsumedByScreenshotChord;
485 private boolean mVolumeUpKeyTriggered;
486 private boolean mPowerKeyTriggered;
487 private long mPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700488
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800489 ShortcutManager mShortcutManager;
490 PowerManager.WakeLock mBroadcastWakeLock;
491
Jeff Brown49ed71d2010-12-06 17:13:33 -0800492 final KeyCharacterMap.FallbackAction mFallbackAction = new KeyCharacterMap.FallbackAction();
493
Jeff Brown70825162012-03-28 17:27:48 -0700494 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
495 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
496
497 private class PolicyHandler extends Handler {
498 @Override
499 public void handleMessage(Message msg) {
500 switch (msg.what) {
501 case MSG_ENABLE_POINTER_LOCATION:
502 enablePointerLocation();
503 break;
504 case MSG_DISABLE_POINTER_LOCATION:
505 disablePointerLocation();
506 break;
507 }
508 }
509 }
510
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800511 private UEventObserver mHDMIObserver = new UEventObserver() {
512 @Override
513 public void onUEvent(UEventObserver.UEvent event) {
514 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
515 }
516 };
517
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800518 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800519 SettingsObserver(Handler handler) {
520 super(handler);
521 }
David Brownbaf8d092010-03-08 21:52:59 -0800522
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800523 void observe() {
524 ContentResolver resolver = mContext.getContentResolver();
525 resolver.registerContentObserver(Settings.System.getUriFor(
526 Settings.System.END_BUTTON_BEHAVIOR), false, this);
David Brownbaf8d092010-03-08 21:52:59 -0800527 resolver.registerContentObserver(Settings.Secure.getUriFor(
528 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800529 resolver.registerContentObserver(Settings.System.getUriFor(
530 Settings.System.ACCELEROMETER_ROTATION), false, this);
Mike Lockwood28569302010-01-28 11:54:40 -0500531 resolver.registerContentObserver(Settings.System.getUriFor(
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400532 Settings.System.USER_ROTATION), false, this);
533 resolver.registerContentObserver(Settings.System.getUriFor(
Mike Lockwood28569302010-01-28 11:54:40 -0500534 Settings.System.SCREEN_OFF_TIMEOUT), false, this);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800535 resolver.registerContentObserver(Settings.System.getUriFor(
Jeff Brown4519f072011-01-23 13:16:01 -0800536 Settings.System.WINDOW_ORIENTATION_LISTENER_LOG), false, this);
537 resolver.registerContentObserver(Settings.System.getUriFor(
Dianne Hackbornc777e072010-02-12 13:07:59 -0800538 Settings.System.POINTER_LOCATION), false, this);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800539 resolver.registerContentObserver(Settings.Secure.getUriFor(
540 Settings.Secure.DEFAULT_INPUT_METHOD), false, this);
Dianne Hackborn03759ed2009-03-27 16:04:08 -0700541 resolver.registerContentObserver(Settings.System.getUriFor(
542 "fancy_rotation_anim"), false, this);
Daniel Sandler2d545362011-11-17 10:38:37 -0800543 resolver.registerContentObserver(Settings.Secure.getUriFor(
544 Settings.Secure.SCREENSAVER_ENABLED), false, this);
Daniel Sandler7e37df52011-11-16 22:08:23 -0800545 if (SEPARATE_TIMEOUT_FOR_SCREEN_SAVER) {
546 resolver.registerContentObserver(Settings.Secure.getUriFor(
Daniel Sandler2d545362011-11-17 10:38:37 -0800547 "screensaver_timeout"), false, this);
Daniel Sandler7e37df52011-11-16 22:08:23 -0800548 } // otherwise SCREEN_OFF_TIMEOUT will do nicely
Dianne Hackbornc777e072010-02-12 13:07:59 -0800549 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800550 }
551
552 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800553 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700554 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800555 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800556 }
557
558 class MyOrientationListener extends WindowOrientationListener {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800559 MyOrientationListener(Context context) {
560 super(context);
561 }
562
563 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700564 public void onProposedRotationChanged(int rotation) {
565 if (localLOGV) Log.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700566 updateRotation(false);
567 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800568 }
569 MyOrientationListener mOrientationListener;
570
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700571 /*
572 * We always let the sensor be switched on by default except when
573 * the user has explicitly disabled sensor based rotation or when the
574 * screen is switched off.
575 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700576 boolean needSensorRunningLp() {
Dianne Hackborne5439f22010-10-02 16:53:50 -0700577 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
578 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
579 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
580 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800581 // If the application has explicitly requested to follow the
582 // orientation, then we need to turn the sensor or.
583 return true;
584 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700585 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800586 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
587 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
588 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400589 // enable accelerometer if we are docked in a dock that enables accelerometer
590 // orientation management,
591 return true;
592 }
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700593 if (mAccelerometerDefault == 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800594 // If the setting for using the sensor by default is enabled, then
595 // we will always leave it on. Note that the user could go to
596 // a window that forces an orientation that does not use the
597 // sensor and in theory we could turn it off... however, when next
598 // turning it on we won't have a good value for the current
599 // orientation for a little bit, which can cause orientation
600 // changes to lag, so we'd like to keep it always on. (It will
601 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700602 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800603 }
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700604 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800605 }
606
607 /*
608 * Various use cases for invoking this function
609 * screen turning off, should always disable listeners if already enabled
610 * screen turned on and current app has sensor based orientation, enable listeners
611 * if not already enabled
612 * screen turned on and current app does not have sensor orientation, disable listeners if
613 * already enabled
614 * screen turning on and current app has sensor based orientation, enable listeners if needed
615 * screen turning on and current app has nosensor based orientation, do nothing
616 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700617 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800618 if (!mOrientationListener.canDetectOrientation()) {
619 // If sensor is turned off or nonexistent for some reason
620 return;
621 }
622 //Could have been invoked due to screen turning on or off or
623 //change of the currently visible window's orientation
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700624 if (localLOGV) Log.v(TAG, "Screen status="+mScreenOnEarly+
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800625 ", current orientation="+mCurrentAppOrientation+
626 ", SensorEnabled="+mOrientationSensorEnabled);
627 boolean disable = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700628 if (mScreenOnEarly) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700629 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800630 disable = false;
631 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700632 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800633 mOrientationListener.enable();
Dianne Hackborn05726582009-09-22 17:28:24 -0700634 if(localLOGV) Log.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800635 mOrientationSensorEnabled = true;
636 }
637 }
638 }
639 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700640 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800641 mOrientationListener.disable();
Dianne Hackborn05726582009-09-22 17:28:24 -0700642 if(localLOGV) Log.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800643 mOrientationSensorEnabled = false;
644 }
645 }
646
Jeff Brown4d396052010-10-29 21:50:21 -0700647 private void interceptPowerKeyDown(boolean handled) {
648 mPowerKeyHandled = handled;
649 if (!handled) {
650 mHandler.postDelayed(mPowerLongPress, ViewConfiguration.getGlobalActionKeyTimeout());
651 }
652 }
653
654 private boolean interceptPowerKeyUp(boolean canceled) {
655 if (!mPowerKeyHandled) {
656 mHandler.removeCallbacks(mPowerLongPress);
657 return !canceled;
Jeff Brown4d396052010-10-29 21:50:21 -0700658 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700659 return false;
660 }
661
662 private void cancelPendingPowerKeyAction() {
663 if (!mPowerKeyHandled) {
664 mHandler.removeCallbacks(mPowerLongPress);
665 }
Jeff Brownff204712011-10-25 21:27:54 -0700666 if (mPowerKeyTriggered) {
667 mPendingPowerKeyUpCanceled = true;
668 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700669 }
670
671 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -0800672 if (mScreenshotChordEnabled
673 && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700674 final long now = SystemClock.uptimeMillis();
675 if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
676 && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
677 mVolumeDownKeyConsumedByScreenshotChord = true;
678 cancelPendingPowerKeyAction();
679
680 mHandler.postDelayed(mScreenshotChordLongPress,
681 ViewConfiguration.getGlobalActionKeyTimeout());
682 }
683 }
684 }
685
686 private void cancelPendingScreenshotChordAction() {
687 mHandler.removeCallbacks(mScreenshotChordLongPress);
Jeff Brown4d396052010-10-29 21:50:21 -0700688 }
689
690 private final Runnable mPowerLongPress = new Runnable() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800691 public void run() {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700692 // The context isn't read
693 if (mLongPressOnPowerBehavior < 0) {
694 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
695 com.android.internal.R.integer.config_longPressOnPowerBehavior);
Joe Onoratod208e702010-10-08 16:22:43 -0400696 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700697 switch (mLongPressOnPowerBehavior) {
698 case LONG_PRESS_POWER_NOTHING:
699 break;
700 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
701 mPowerKeyHandled = true;
702 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
703 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
704 showGlobalActionsDialog();
705 break;
706 case LONG_PRESS_POWER_SHUT_OFF:
707 mPowerKeyHandled = true;
708 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
709 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
710 ShutdownThread.shutdown(mContext, true);
711 break;
712 }
713 }
714 };
715
716 private final Runnable mScreenshotChordLongPress = new Runnable() {
717 public void run() {
718 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800719 }
720 };
721
722 void showGlobalActionsDialog() {
723 if (mGlobalActions == null) {
724 mGlobalActions = new GlobalActions(mContext);
725 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700726 final boolean keyguardShowing = keyguardIsShowingTq();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800727 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
728 if (keyguardShowing) {
729 // since it took two seconds of long press to bring this up,
730 // poke the wake lock so they have some time to see the dialog.
731 mKeyguardMediator.pokeWakelock();
732 }
733 }
734
735 boolean isDeviceProvisioned() {
736 return Settings.Secure.getInt(
737 mContext.getContentResolver(), Settings.Secure.DEVICE_PROVISIONED, 0) != 0;
738 }
739
Patrick Dubroyece94522011-02-23 18:35:01 -0800740 private void handleLongPressOnHome() {
Jim Milleree969aa2010-08-26 20:17:43 -0700741 // We can't initialize this in init() since the configuration hasn't been loaded yet.
Joe Onorato46b0d682010-11-22 17:37:27 -0800742 if (mLongPressOnHomeBehavior < 0) {
743 mLongPressOnHomeBehavior
Joe Onorato50262e52010-11-26 14:04:54 -0800744 = mContext.getResources().getInteger(R.integer.config_longPressOnHomeBehavior);
Joe Onorato46b0d682010-11-22 17:37:27 -0800745 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
Michael Jurka3b1fc472011-06-13 10:54:40 -0700746 mLongPressOnHomeBehavior > LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
Joe Onorato46b0d682010-11-22 17:37:27 -0800747 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
748 }
Michael Jurka7a348952012-02-27 13:07:58 -0800749 if (hasNavigationBar()) {
750 mLongPressOnHomeBehavior = LONG_PRESS_HOME_VOICE_SEARCH;
751 }
Joe Onorato46b0d682010-11-22 17:37:27 -0800752 }
753
754 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
755 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
756 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS);
Patrick Dubroyece94522011-02-23 18:35:01 -0800757
758 // Eat the longpress so it won't dismiss the recent apps dialog when
759 // the user lets go of the home key
Michael Jurka7f2668c2012-03-27 07:49:52 -0700760 mHomeLongPressed = true;
Jim Milleree969aa2010-08-26 20:17:43 -0700761 }
Patrick Dubroyece94522011-02-23 18:35:01 -0800762
Joe Onorato46b0d682010-11-22 17:37:27 -0800763 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_DIALOG) {
Jeff Brown68b909d2011-12-07 16:36:01 -0800764 showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS);
Michael Jurka3b1fc472011-06-13 10:54:40 -0700765 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
Jim Millere6ad1a82010-08-20 19:25:39 -0700766 try {
Michael Jurka3b1fc472011-06-13 10:54:40 -0700767 mStatusBarService.toggleRecentApps();
768 } catch (RemoteException e) {
769 Slog.e(TAG, "RemoteException when showing recent apps", e);
Jim Millere6ad1a82010-08-20 19:25:39 -0700770 }
Michael Jurka7a348952012-02-27 13:07:58 -0800771 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_VOICE_SEARCH) {
772 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
773 try {
774 intent.setFlags(
775 Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
776 mContext.startActivity(intent);
777 } catch (ActivityNotFoundException e) {
778 Log.e(TAG, "Unable to launch. tag=" + TAG + " intent=" + intent, e);
779 } catch (SecurityException e) {
780 Log.e(TAG, "PhoneWindowManager does not have the permission to launch " +
781 "tag=" + TAG + " intent=" + intent, e);
782 }
Jim Millere6ad1a82010-08-20 19:25:39 -0700783 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800784 }
Patrick Dubroyece94522011-02-23 18:35:01 -0800785
786 /**
Jeff Brown68b909d2011-12-07 16:36:01 -0800787 * Create (if necessary) and show or dismiss the recent apps dialog according
788 * according to the requested behavior.
Patrick Dubroyece94522011-02-23 18:35:01 -0800789 */
Jeff Brown68b909d2011-12-07 16:36:01 -0800790 void showOrHideRecentAppsDialog(final int behavior) {
Jeff Brownda3d5a92011-03-29 15:11:34 -0700791 mHandler.post(new Runnable() {
792 @Override
793 public void run() {
794 if (mRecentAppsDialog == null) {
Jeff Brown54875002011-04-06 15:33:01 -0700795 mRecentAppsDialog = new RecentApplicationsDialog(mContext);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700796 }
Jeff Brown54875002011-04-06 15:33:01 -0700797 if (mRecentAppsDialog.isShowing()) {
Jeff Brown68b909d2011-12-07 16:36:01 -0800798 switch (behavior) {
799 case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS:
800 mRecentAppsDialog.dismiss();
801 break;
802 case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH:
803 mRecentAppsDialog.dismissAndSwitch();
804 break;
805 case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW:
806 default:
807 break;
Jeff Brown54875002011-04-06 15:33:01 -0700808 }
809 } else {
Jeff Brown68b909d2011-12-07 16:36:01 -0800810 switch (behavior) {
811 case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS:
812 mRecentAppsDialog.show();
813 break;
814 case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW:
815 try {
816 mWindowManager.setInTouchMode(false);
817 } catch (RemoteException e) {
818 }
819 mRecentAppsDialog.show();
820 break;
821 case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH:
822 default:
823 break;
824 }
Jeff Brown54875002011-04-06 15:33:01 -0700825 }
Jeff Brownda3d5a92011-03-29 15:11:34 -0700826 }
827 });
Patrick Dubroyece94522011-02-23 18:35:01 -0800828 }
Jeff Brownda3d5a92011-03-29 15:11:34 -0700829
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800830 /** {@inheritDoc} */
831 public void init(Context context, IWindowManager windowManager,
Dianne Hackborndf89e652011-10-06 22:35:11 -0700832 WindowManagerFuncs windowManagerFuncs,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800833 LocalPowerManager powerManager) {
834 mContext = context;
835 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700836 mWindowManagerFuncs = windowManagerFuncs;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800837 mPowerManager = powerManager;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400838 mHeadless = "1".equals(SystemProperties.get("ro.config.headless", "0"));
839 if (!mHeadless) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700840 // don't create KeyguardViewMediator if headless
841 mKeyguardMediator = new KeyguardViewMediator(context, this, powerManager);
842 }
Jeff Brown70825162012-03-28 17:27:48 -0700843 mHandler = new PolicyHandler();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800844 mOrientationListener = new MyOrientationListener(mContext);
Jeff Brownc0347aa2011-09-23 17:26:09 -0700845 try {
846 mOrientationListener.setCurrentRotation(windowManager.getRotation());
847 } catch (RemoteException ex) { }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800848 SettingsObserver settingsObserver = new SettingsObserver(mHandler);
849 settingsObserver.observe();
850 mShortcutManager = new ShortcutManager(context, mHandler);
851 mShortcutManager.observe();
Joe Onorato44fcb832011-12-14 20:59:30 -0800852 mUiMode = context.getResources().getInteger(
853 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800854 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
855 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
856 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
857 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700858 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
859 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
860 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
861 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
862 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
863 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
864 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
865 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -0700866
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800867 PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
868 mBroadcastWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
869 "PhoneWindowManager.mBroadcastWakeLock");
870 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700871 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400872 com.android.internal.R.integer.config_lidOpenRotation);
873 mCarDockRotation = readRotation(
874 com.android.internal.R.integer.config_carDockRotation);
875 mDeskDockRotation = readRotation(
876 com.android.internal.R.integer.config_deskDockRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -0400877 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
878 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
879 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
880 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700881 mLidKeyboardAccessibility = mContext.getResources().getInteger(
882 com.android.internal.R.integer.config_lidKeyboardAccessibility);
883 mLidNavigationAccessibility = mContext.getResources().getInteger(
884 com.android.internal.R.integer.config_lidNavigationAccessibility);
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700885 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -0800886 IntentFilter filter = new IntentFilter();
887 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
888 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
889 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
890 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700891 filter.addAction(Intent.ACTION_DOCK_EVENT);
892 Intent intent = context.registerReceiver(mDockReceiver, filter);
893 if (intent != null) {
894 // Retrieve current sticky dock event broadcast.
895 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
896 Intent.EXTRA_DOCK_STATE_UNDOCKED);
897 }
Daniel Sandler7e37df52011-11-16 22:08:23 -0800898
899 // watch the plug to know whether to trigger the screen saver
900 filter = new IntentFilter();
901 filter.addAction(Intent.ACTION_BATTERY_CHANGED);
902 intent = context.registerReceiver(mPowerReceiver, filter);
903 if (intent != null) {
904 mPluggedIn = (0 != intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0));
905 }
906
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700907 mVibrator = new Vibrator();
908 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
909 com.android.internal.R.array.config_longPressVibePattern);
910 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
911 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -0800912 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
913 com.android.internal.R.array.config_keyboardTapVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700914 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
915 com.android.internal.R.array.config_safeModeDisabledVibePattern);
916 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
917 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -0400918
Christopher Tatee90585f2012-03-05 18:56:25 -0800919 mScreenshotChordEnabled = mContext.getResources().getBoolean(
920 com.android.internal.R.bool.config_enableScreenshotChord);
921
Joe Onoratoea495d42011-04-06 11:41:11 -0700922 // Controls rotation and the like.
923 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -0700924
925 // Match current screen state.
926 if (mPowerManager.isScreenOn()) {
927 screenTurningOn(null);
928 } else {
929 screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
930 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700931 }
932
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700933 public void setInitialDisplaySize(Display display, int width, int height) {
934 mDisplay = display;
935
936 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -0700937 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700938 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700939 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -0700940 mLandscapeRotation = Surface.ROTATION_0;
941 mSeascapeRotation = Surface.ROTATION_180;
942 if (mContext.getResources().getBoolean(
943 com.android.internal.R.bool.config_reverseDefaultRotation)) {
944 mPortraitRotation = Surface.ROTATION_90;
945 mUpsideDownRotation = Surface.ROTATION_270;
946 } else {
947 mPortraitRotation = Surface.ROTATION_270;
948 mUpsideDownRotation = Surface.ROTATION_90;
949 }
950 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700951 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700952 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -0700953 mPortraitRotation = Surface.ROTATION_0;
954 mUpsideDownRotation = Surface.ROTATION_180;
955 if (mContext.getResources().getBoolean(
956 com.android.internal.R.bool.config_reverseDefaultRotation)) {
957 mLandscapeRotation = Surface.ROTATION_270;
958 mSeascapeRotation = Surface.ROTATION_90;
959 } else {
960 mLandscapeRotation = Surface.ROTATION_90;
961 mSeascapeRotation = Surface.ROTATION_270;
962 }
963 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700964
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700965 mExternalDisplayWidth = mDisplay.getRawExternalWidth();
966 mExternalDisplayHeight = mDisplay.getRawExternalHeight();
967
968 mStatusBarHeight = mContext.getResources().getDimensionPixelSize(
969 com.android.internal.R.dimen.status_bar_height);
970 mNavigationBarHeight = mContext.getResources().getDimensionPixelSize(
971 com.android.internal.R.dimen.navigation_bar_height);
972 mNavigationBarWidth = mContext.getResources().getDimensionPixelSize(
973 com.android.internal.R.dimen.navigation_bar_width);
974
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700975 // Determine whether the status bar can hide based on the size
Daniel Sandlerc8cb3292012-04-05 23:56:05 -0400976 // of the screen. We assume sizes >= 600dp are tablets where we
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700977 // will use the system bar.
Daniel Sandlerc8cb3292012-04-05 23:56:05 -0400978 // XXX: This will change to 720dp soon.
Daniel Sandler631cb3d52011-06-03 01:25:43 -0400979 int shortSizeDp = shortSize
980 * DisplayMetrics.DENSITY_DEFAULT
981 / DisplayMetrics.DENSITY_DEVICE;
Daniel Sandlerc8cb3292012-04-05 23:56:05 -0400982 mHasSystemNavBar = shortSizeDp >= 600;
Daniel Sandler36412a72011-08-04 09:35:13 -0400983
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700984 if (!mHasSystemNavBar) {
985 mHasNavigationBar = mContext.getResources().getBoolean(
986 com.android.internal.R.bool.config_showNavigationBar);
987 // Allow a system property to override this. Used by the emulator.
988 // See also hasNavigationBar().
989 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
990 if (! "".equals(navBarOverride)) {
991 if (navBarOverride.equals("1")) mHasNavigationBar = false;
992 else if (navBarOverride.equals("0")) mHasNavigationBar = true;
993 }
994 } else {
995 mHasNavigationBar = false;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -0400996 }
997
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700998 if (mHasSystemNavBar) {
999 // The system bar is always at the bottom. If you are watching
1000 // a video in landscape, we don't need to hide it if we can still
1001 // show a 16:9 aspect ratio with it.
1002 int longSizeDp = longSize
1003 * DisplayMetrics.DENSITY_DEFAULT
1004 / DisplayMetrics.DENSITY_DEVICE;
1005 int barHeightDp = mNavigationBarHeight
1006 * DisplayMetrics.DENSITY_DEFAULT
1007 / DisplayMetrics.DENSITY_DEVICE;
1008 int aspect = ((shortSizeDp-barHeightDp) * 16) / longSizeDp;
1009 // We have computed the aspect ratio with the bar height taken
1010 // out to be 16:aspect. If this is less than 9, then hiding
1011 // the navigation bar will provide more useful space for wide
1012 // screen movies.
1013 mCanHideNavigationBar = aspect < 9;
1014 } else if (mHasNavigationBar) {
1015 // The navigation bar is at the right in landscape; it seems always
1016 // useful to hide it for showing a video.
1017 mCanHideNavigationBar = true;
1018 } else {
1019 mCanHideNavigationBar = false;
1020 }
Erik Gilling9a41ef82011-09-26 19:21:03 -07001021
1022 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
1023 mHdmiRotation = mPortraitRotation;
1024 } else {
1025 mHdmiRotation = mLandscapeRotation;
1026 }
Dianne Hackborn9d132642011-04-21 17:26:39 -07001027 }
1028
Dianne Hackbornc777e072010-02-12 13:07:59 -08001029 public void updateSettings() {
1030 ContentResolver resolver = mContext.getContentResolver();
1031 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001032 synchronized (mLock) {
1033 mEndcallBehavior = Settings.System.getInt(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001034 Settings.System.END_BUTTON_BEHAVIOR,
1035 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT);
1036 mIncallPowerBehavior = Settings.Secure.getInt(resolver,
1037 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
1038 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001039 int accelerometerDefault = Settings.System.getInt(resolver,
1040 Settings.System.ACCELEROMETER_ROTATION, DEFAULT_ACCELEROMETER_ROTATION);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001041
1042 // set up rotation lock state
Daniel Sandler1b815d62010-11-05 10:24:27 -04001043 mUserRotationMode = (accelerometerDefault == 0)
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001044 ? WindowManagerPolicy.USER_ROTATION_LOCKED
1045 : WindowManagerPolicy.USER_ROTATION_FREE;
1046 mUserRotation = Settings.System.getInt(resolver,
1047 Settings.System.USER_ROTATION,
1048 Surface.ROTATION_0);
1049
Dianne Hackbornc777e072010-02-12 13:07:59 -08001050 if (mAccelerometerDefault != accelerometerDefault) {
1051 mAccelerometerDefault = accelerometerDefault;
1052 updateOrientationListenerLp();
1053 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001054
Jeff Brown4519f072011-01-23 13:16:01 -08001055 mOrientationListener.setLogEnabled(
1056 Settings.System.getInt(resolver,
1057 Settings.System.WINDOW_ORIENTATION_LISTENER_LOG, 0) != 0);
1058
Dianne Hackbornc777e072010-02-12 13:07:59 -08001059 if (mSystemReady) {
1060 int pointerLocation = Settings.System.getInt(resolver,
1061 Settings.System.POINTER_LOCATION, 0);
1062 if (mPointerLocationMode != pointerLocation) {
1063 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001064 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1065 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001066 }
1067 }
1068 // use screen off timeout setting as the timeout for the lockscreen
1069 mLockScreenTimeout = Settings.System.getInt(resolver,
1070 Settings.System.SCREEN_OFF_TIMEOUT, 0);
1071 String imId = Settings.Secure.getString(resolver,
1072 Settings.Secure.DEFAULT_INPUT_METHOD);
1073 boolean hasSoftInput = imId != null && imId.length() > 0;
1074 if (mHasSoftInput != hasSoftInput) {
1075 mHasSoftInput = hasSoftInput;
1076 updateRotation = true;
1077 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04001078
Daniel Sandler2d545362011-11-17 10:38:37 -08001079 mScreenSaverEnabledByUser = 0 != Settings.Secure.getInt(resolver,
1080 Settings.Secure.SCREENSAVER_ENABLED, 1);
1081
Daniel Sandler7e37df52011-11-16 22:08:23 -08001082 if (SEPARATE_TIMEOUT_FOR_SCREEN_SAVER) {
1083 mScreenSaverTimeout = Settings.Secure.getInt(resolver,
Daniel Sandler2d545362011-11-17 10:38:37 -08001084 "screensaver_timeout", 0);
Daniel Sandler7e37df52011-11-16 22:08:23 -08001085 } else {
1086 mScreenSaverTimeout = Settings.System.getInt(resolver,
1087 Settings.System.SCREEN_OFF_TIMEOUT, 0);
1088 if (mScreenSaverTimeout > 0) {
1089 // We actually want to activate the screensaver just before the
1090 // power manager's screen timeout
1091 mScreenSaverTimeout -= 5000;
1092 }
1093 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04001094 updateScreenSaverTimeoutLocked();
Dianne Hackbornc777e072010-02-12 13:07:59 -08001095 }
1096 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001097 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001098 }
Jeff Brown70825162012-03-28 17:27:48 -07001099 }
1100
1101 private void enablePointerLocation() {
1102 if (mPointerLocationView == null) {
1103 mPointerLocationView = new PointerLocationView(mContext);
1104 mPointerLocationView.setPrintCoords(false);
1105
Dianne Hackbornc777e072010-02-12 13:07:59 -08001106 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1107 WindowManager.LayoutParams.MATCH_PARENT,
1108 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001109 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001110 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1111 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1112 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1113 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001114 lp.format = PixelFormat.TRANSLUCENT;
1115 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001116 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001117 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001118 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001119 wm.addView(mPointerLocationView, lp);
1120
Jeff Brownac143512012-04-05 18:57:33 -07001121 mPointerLocationInputChannel =
1122 mWindowManagerFuncs.monitorInput("PointerLocationView");
1123 mPointerLocationInputEventReceiver =
1124 new PointerLocationInputEventReceiver(mPointerLocationInputChannel,
1125 Looper.myLooper(), mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001126 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001127 }
Jeff Brown70825162012-03-28 17:27:48 -07001128
1129 private void disablePointerLocation() {
1130 if (mPointerLocationInputEventReceiver != null) {
1131 mPointerLocationInputEventReceiver.dispose();
1132 mPointerLocationInputEventReceiver = null;
1133 }
1134
1135 if (mPointerLocationInputChannel != null) {
1136 mPointerLocationInputChannel.dispose();
1137 mPointerLocationInputChannel = null;
1138 }
1139
1140 if (mPointerLocationView != null) {
1141 WindowManager wm = (WindowManager)
1142 mContext.getSystemService(Context.WINDOW_SERVICE);
1143 wm.removeView(mPointerLocationView);
1144 mPointerLocationView = null;
1145 }
1146 }
1147
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001148 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001149 try {
1150 int rotation = mContext.getResources().getInteger(resID);
1151 switch (rotation) {
1152 case 0:
1153 return Surface.ROTATION_0;
1154 case 90:
1155 return Surface.ROTATION_90;
1156 case 180:
1157 return Surface.ROTATION_180;
1158 case 270:
1159 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001160 }
1161 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001162 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001163 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001164 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001165 }
1166
1167 /** {@inheritDoc} */
1168 public int checkAddPermission(WindowManager.LayoutParams attrs) {
1169 int type = attrs.type;
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07001170
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001171 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1172 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
1173 return WindowManagerImpl.ADD_OKAY;
1174 }
1175 String permission = null;
1176 switch (type) {
1177 case TYPE_TOAST:
1178 // XXX right now the app process has complete control over
1179 // this... should introduce a token to let the system
1180 // monitor/control what they are doing.
1181 break;
1182 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001183 case TYPE_WALLPAPER:
1184 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001185 break;
1186 case TYPE_PHONE:
1187 case TYPE_PRIORITY_PHONE:
1188 case TYPE_SYSTEM_ALERT:
1189 case TYPE_SYSTEM_ERROR:
1190 case TYPE_SYSTEM_OVERLAY:
1191 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
1192 break;
1193 default:
1194 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1195 }
1196 if (permission != null) {
1197 if (mContext.checkCallingOrSelfPermission(permission)
1198 != PackageManager.PERMISSION_GRANTED) {
1199 return WindowManagerImpl.ADD_PERMISSION_DENIED;
1200 }
1201 }
1202 return WindowManagerImpl.ADD_OKAY;
1203 }
1204
1205 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1206 switch (attrs.type) {
1207 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001208 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001209 case TYPE_TOAST:
1210 // These types of windows can't receive input events.
1211 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1212 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001213 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001214 break;
1215 }
1216 }
1217
1218 void readLidState() {
Jeff Brownac143512012-04-05 18:57:33 -07001219 mLidOpen = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001220 }
1221
Jeff Brown4aed78b2011-01-14 17:36:55 -08001222 private int determineHiddenState(int mode, int hiddenValue, int visibleValue) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001223 if (mLidOpen != LID_ABSENT) {
1224 switch (mode) {
1225 case 1:
1226 return mLidOpen == LID_OPEN ? visibleValue : hiddenValue;
1227 case 2:
1228 return mLidOpen == LID_OPEN ? hiddenValue : visibleValue;
1229 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001230 }
1231 return visibleValue;
1232 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001233
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001234 /** {@inheritDoc} */
1235 public void adjustConfigurationLw(Configuration config) {
1236 readLidState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07001237 updateKeyboardVisibility();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001238
1239 if (config.keyboard == Configuration.KEYBOARD_NOKEYS) {
1240 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
1241 } else {
1242 config.hardKeyboardHidden = determineHiddenState(mLidKeyboardAccessibility,
1243 Configuration.HARDKEYBOARDHIDDEN_YES, Configuration.HARDKEYBOARDHIDDEN_NO);
1244 }
1245
1246 if (config.navigation == Configuration.NAVIGATION_NONAV) {
1247 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
1248 } else {
1249 config.navigationHidden = determineHiddenState(mLidNavigationAccessibility,
1250 Configuration.NAVIGATIONHIDDEN_YES, Configuration.NAVIGATIONHIDDEN_NO);
1251 }
1252
1253 if (mHasSoftInput || config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
1254 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
1255 } else {
1256 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1257 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001258 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001259
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001260 /** {@inheritDoc} */
1261 public int windowTypeToLayerLw(int type) {
1262 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
1263 return APPLICATION_LAYER;
1264 }
1265 switch (type) {
1266 case TYPE_STATUS_BAR:
1267 return STATUS_BAR_LAYER;
1268 case TYPE_STATUS_BAR_PANEL:
1269 return STATUS_BAR_PANEL_LAYER;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001270 case TYPE_STATUS_BAR_SUB_PANEL:
1271 return STATUS_BAR_SUB_PANEL_LAYER;
Dianne Hackborn6a294ce2009-12-03 11:37:44 -08001272 case TYPE_SYSTEM_DIALOG:
1273 return SYSTEM_DIALOG_LAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001274 case TYPE_SEARCH_BAR:
1275 return SEARCH_BAR_LAYER;
1276 case TYPE_PHONE:
1277 return PHONE_LAYER;
1278 case TYPE_KEYGUARD:
1279 return KEYGUARD_LAYER;
1280 case TYPE_KEYGUARD_DIALOG:
1281 return KEYGUARD_DIALOG_LAYER;
1282 case TYPE_SYSTEM_ALERT:
1283 return SYSTEM_ALERT_LAYER;
1284 case TYPE_SYSTEM_ERROR:
1285 return SYSTEM_ERROR_LAYER;
1286 case TYPE_INPUT_METHOD:
1287 return INPUT_METHOD_LAYER;
1288 case TYPE_INPUT_METHOD_DIALOG:
1289 return INPUT_METHOD_DIALOG_LAYER;
Dianne Hackborne8ecde12011-08-03 18:55:19 -07001290 case TYPE_VOLUME_OVERLAY:
1291 return VOLUME_OVERLAY_LAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001292 case TYPE_SYSTEM_OVERLAY:
1293 return SYSTEM_OVERLAY_LAYER;
Jeff Brown3b2b3542010-10-15 00:54:27 -07001294 case TYPE_SECURE_SYSTEM_OVERLAY:
1295 return SECURE_SYSTEM_OVERLAY_LAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001296 case TYPE_PRIORITY_PHONE:
1297 return PRIORITY_PHONE_LAYER;
1298 case TYPE_TOAST:
1299 return TOAST_LAYER;
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001300 case TYPE_WALLPAPER:
1301 return WALLPAPER_LAYER;
Christopher Tatea53146c2010-09-07 11:57:52 -07001302 case TYPE_DRAG:
1303 return DRAG_LAYER;
Jeff Brown83c09682010-12-23 17:50:18 -08001304 case TYPE_POINTER:
1305 return POINTER_LAYER;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001306 case TYPE_NAVIGATION_BAR:
1307 return NAVIGATION_BAR_LAYER;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001308 case TYPE_BOOT_PROGRESS:
1309 return BOOT_PROGRESS_LAYER;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001310 case TYPE_HIDDEN_NAV_CONSUMER:
1311 return HIDDEN_NAV_CONSUMER_LAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001312 }
1313 Log.e(TAG, "Unknown window type: " + type);
1314 return APPLICATION_LAYER;
1315 }
1316
1317 /** {@inheritDoc} */
1318 public int subWindowTypeToLayerLw(int type) {
1319 switch (type) {
1320 case TYPE_APPLICATION_PANEL:
1321 case TYPE_APPLICATION_ATTACHED_DIALOG:
1322 return APPLICATION_PANEL_SUBLAYER;
1323 case TYPE_APPLICATION_MEDIA:
1324 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001325 case TYPE_APPLICATION_MEDIA_OVERLAY:
1326 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001327 case TYPE_APPLICATION_SUB_PANEL:
1328 return APPLICATION_SUB_PANEL_SUBLAYER;
1329 }
1330 Log.e(TAG, "Unknown sub-window type: " + type);
1331 return 0;
1332 }
1333
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001334 public int getMaxWallpaperLayer() {
1335 return STATUS_BAR_LAYER;
1336 }
1337
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001338 public boolean hasSystemNavBar() {
1339 return mHasSystemNavBar;
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001340 }
1341
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001342 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001343 if (mHasNavigationBar) {
1344 // For a basic navigation bar, when we are in landscape mode we place
1345 // the navigation bar to the side.
1346 if (fullWidth > fullHeight) {
1347 return fullWidth - mNavigationBarWidth;
1348 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001349 }
1350 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001351 }
1352
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001353 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001354 if (mHasSystemNavBar) {
1355 // For the system navigation bar, we always place it at the bottom.
1356 return fullHeight - mNavigationBarHeight;
1357 }
1358 if (mHasNavigationBar) {
1359 // For a basic navigation bar, when we are in portrait mode we place
1360 // the navigation bar to the bottom.
1361 if (fullWidth < fullHeight) {
1362 return fullHeight - mNavigationBarHeight;
1363 }
1364 }
1365 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001366 }
1367
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001368 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1369 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001370 }
1371
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001372 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001373 // If we don't have a system nav bar, then there is a separate status
1374 // bar at the top of the display. We don't count that as part of the
1375 // fixed decor, since it can hide; however, for purposes of configurations,
1376 // we do want to exclude it since applications can't generally use that part
1377 // of the screen.
1378 if (!mHasSystemNavBar) {
1379 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
1380 }
1381 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001382 }
1383
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001384 public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs) {
1385 return attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD;
1386 }
1387
1388 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
1389 return attrs.type != WindowManager.LayoutParams.TYPE_STATUS_BAR
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001390 && attrs.type != WindowManager.LayoutParams.TYPE_NAVIGATION_BAR
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001391 && attrs.type != WindowManager.LayoutParams.TYPE_WALLPAPER;
1392 }
1393
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001394 /** {@inheritDoc} */
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001395 public View addStartingWindow(IBinder appToken, String packageName, int theme,
1396 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
1397 int icon, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001398 if (!SHOW_STARTING_ANIMATIONS) {
1399 return null;
1400 }
1401 if (packageName == null) {
1402 return null;
1403 }
1404
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001405 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001406 Context context = mContext;
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001407 //Log.i(TAG, "addStartingWindow " + packageName + ": nonLocalizedLabel="
1408 // + nonLocalizedLabel + " theme=" + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001409 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001410 try {
1411 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001412 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001413 } catch (PackageManager.NameNotFoundException e) {
1414 // Ignore
1415 }
1416 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001417
1418 Window win = PolicyManager.makeNewWindow(context);
1419 if (win.getWindowStyle().getBoolean(
1420 com.android.internal.R.styleable.Window_windowDisablePreview, false)) {
1421 return null;
1422 }
1423
1424 Resources r = context.getResources();
1425 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
1426
1427 win.setType(
1428 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
1429 // Force the window flags: this is a fake window, so it is not really
1430 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
1431 // flag because we do know that the next window will take input
1432 // focus, so we want to get the IME window up on top of us right away.
1433 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001434 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001435 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1436 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1437 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001438 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001439 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1440 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1441 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
1442
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001443 if (!compatInfo.supportsScreen()) {
1444 win.addFlags(WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW);
1445 }
1446
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001447 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001448 WindowManager.LayoutParams.MATCH_PARENT);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001449
1450 final WindowManager.LayoutParams params = win.getAttributes();
1451 params.token = appToken;
1452 params.packageName = packageName;
1453 params.windowAnimations = win.getWindowStyle().getResourceId(
1454 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
Dianne Hackborn5d927c22011-09-02 12:22:18 -07001455 params.privateFlags |=
1456 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001457 params.setTitle("Starting " + packageName);
1458
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001459 WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001460 View view = win.getDecorView();
1461
1462 if (win.isFloating()) {
1463 // Whoops, there is no way to display an animation/preview
1464 // of such a thing! After all that work... let's skip it.
1465 // (Note that we must do this here because it is in
1466 // getDecorView() where the theme is evaluated... maybe
1467 // we should peek the floating attribute from the theme
1468 // earlier.)
1469 return null;
1470 }
1471
1472 if (localLOGV) Log.v(
1473 TAG, "Adding starting window for " + packageName
1474 + " / " + appToken + ": "
1475 + (view.getParent() != null ? view : null));
1476
1477 wm.addView(view, params);
1478
1479 // Only return the view if it was successfully added to the
1480 // window manager... which we can tell by it having a parent.
1481 return view.getParent() != null ? view : null;
1482 } catch (WindowManagerImpl.BadTokenException e) {
1483 // ignore
1484 Log.w(TAG, appToken + " already running, starting window not displayed");
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001485 } catch (RuntimeException e) {
1486 // don't crash if something else bad happens, for example a
1487 // failure loading resources because we are loading from an app
1488 // on external storage that has been unmounted.
1489 Log.w(TAG, appToken + " failed creating starting window", e);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001490 }
1491
1492 return null;
1493 }
1494
1495 /** {@inheritDoc} */
1496 public void removeStartingWindow(IBinder appToken, View window) {
1497 // RuntimeException e = new RuntimeException();
1498 // Log.i(TAG, "remove " + appToken + " " + window, e);
1499
1500 if (localLOGV) Log.v(
1501 TAG, "Removing starting window for " + appToken + ": " + window);
1502
1503 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001504 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001505 wm.removeView(window);
1506 }
1507 }
1508
1509 /**
1510 * Preflight adding a window to the system.
1511 *
1512 * Currently enforces that three window types are singletons:
1513 * <ul>
1514 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001515 * <li>KEYGUARD_TYPE</li>
1516 * </ul>
1517 *
1518 * @param win The window to be added
1519 * @param attrs Information about the window to be added
1520 *
1521 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, WindowManagerImpl.ADD_MULTIPLE_SINGLETON
1522 */
1523 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
1524 switch (attrs.type) {
1525 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001526 mContext.enforceCallingOrSelfPermission(
1527 android.Manifest.permission.STATUS_BAR_SERVICE,
1528 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001529 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001530 if (mStatusBar.isAlive()) {
1531 return WindowManagerImpl.ADD_MULTIPLE_SINGLETON;
1532 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001533 }
1534 mStatusBar = win;
1535 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001536 case TYPE_NAVIGATION_BAR:
1537 mContext.enforceCallingOrSelfPermission(
1538 android.Manifest.permission.STATUS_BAR_SERVICE,
1539 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001540 if (mNavigationBar != null) {
1541 if (mNavigationBar.isAlive()) {
1542 return WindowManagerImpl.ADD_MULTIPLE_SINGLETON;
1543 }
1544 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001545 mNavigationBar = win;
1546 if (DEBUG_LAYOUT) Log.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
1547 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08001548 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001549 mContext.enforceCallingOrSelfPermission(
1550 android.Manifest.permission.STATUS_BAR_SERVICE,
1551 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08001552 mStatusBarPanels.add(win);
1553 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001554 case TYPE_STATUS_BAR_SUB_PANEL:
1555 mContext.enforceCallingOrSelfPermission(
1556 android.Manifest.permission.STATUS_BAR_SERVICE,
1557 "PhoneWindowManager");
1558 mStatusBarPanels.add(win);
1559 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001560 case TYPE_KEYGUARD:
1561 if (mKeyguard != null) {
1562 return WindowManagerImpl.ADD_MULTIPLE_SINGLETON;
1563 }
1564 mKeyguard = win;
1565 break;
1566 }
1567 return WindowManagerImpl.ADD_OKAY;
1568 }
1569
1570 /** {@inheritDoc} */
1571 public void removeWindowLw(WindowState win) {
1572 if (mStatusBar == win) {
1573 mStatusBar = null;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001574 } else if (mKeyguard == win) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001575 mKeyguard = null;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001576 } else if (mNavigationBar == win) {
1577 mNavigationBar = null;
Dianne Hackborn08743722009-12-21 12:16:51 -08001578 } else {
1579 mStatusBarPanels.remove(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001580 }
1581 }
1582
1583 static final boolean PRINT_ANIM = false;
1584
1585 /** {@inheritDoc} */
1586 public int selectAnimationLw(WindowState win, int transit) {
1587 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
1588 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001589 if (win == mStatusBar) {
1590 if (transit == TRANSIT_EXIT || transit == TRANSIT_HIDE) {
1591 return R.anim.dock_top_exit;
1592 } else if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) {
1593 return R.anim.dock_top_enter;
1594 }
1595 } else if (win == mNavigationBar) {
1596 // This can be on either the bottom or the right.
1597 if (mNavigationBarOnBottom) {
1598 if (transit == TRANSIT_EXIT || transit == TRANSIT_HIDE) {
1599 return R.anim.dock_bottom_exit;
1600 } else if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) {
1601 return R.anim.dock_bottom_enter;
1602 }
1603 } else {
1604 if (transit == TRANSIT_EXIT || transit == TRANSIT_HIDE) {
1605 return R.anim.dock_right_exit;
1606 } else if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) {
1607 return R.anim.dock_right_enter;
1608 }
1609 }
1610 } if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001611 if (win.hasAppShownWindows()) {
1612 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
1613 return com.android.internal.R.anim.app_starting_exit;
1614 }
1615 }
1616
1617 return 0;
1618 }
1619
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001620 public Animation createForceHideEnterAnimation() {
1621 return AnimationUtils.loadAnimation(mContext,
1622 com.android.internal.R.anim.lock_screen_behind_enter);
1623 }
1624
Jeff Brown4d396052010-10-29 21:50:21 -07001625 static ITelephony getTelephonyService() {
Mike Lockwoodf5f4ec92011-11-08 14:05:31 -08001626 return ITelephony.Stub.asInterface(
Jeff Brown4d396052010-10-29 21:50:21 -07001627 ServiceManager.checkService(Context.TELEPHONY_SERVICE));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001628 }
1629
Jeff Brown4d396052010-10-29 21:50:21 -07001630 static IAudioService getAudioService() {
1631 IAudioService audioService = IAudioService.Stub.asInterface(
1632 ServiceManager.checkService(Context.AUDIO_SERVICE));
1633 if (audioService == null) {
1634 Log.w(TAG, "Unable to find IAudioService interface.");
1635 }
1636 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001637 }
1638
1639 boolean keyguardOn() {
1640 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
1641 }
1642
1643 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
1644 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
1645 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
1646 };
1647
1648 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001649 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001650 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001651 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08001652 final int keyCode = event.getKeyCode();
1653 final int repeatCount = event.getRepeatCount();
1654 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001655 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08001656 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
1657 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001658
1659 if (false) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001660 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001661 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed);
1662 }
1663
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001664 // If we think we might have a volume down & power key chord on the way
1665 // but we're not sure, then tell the dispatcher to wait a little while and
1666 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08001667 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001668 if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
1669 final long now = SystemClock.uptimeMillis();
1670 final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
1671 if (now < timeoutTime) {
1672 return timeoutTime - now;
1673 }
1674 }
1675 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
1676 && mVolumeDownKeyConsumedByScreenshotChord) {
1677 if (!down) {
1678 mVolumeDownKeyConsumedByScreenshotChord = false;
1679 }
1680 return -1;
1681 }
1682 }
1683
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001684 // First we always handle the home key here, so applications
1685 // can never break it, although if keyguard is on, we do let
1686 // it handle it, because that gives us the correct 5 second
1687 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001688 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07001689
Jeff Brown49ed71d2010-12-06 17:13:33 -08001690 // If we have released the home key, and didn't do anything else
1691 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07001692 if (!down) {
1693 final boolean homeWasLongPressed = mHomeLongPressed;
Jeff Brown49ed71d2010-12-06 17:13:33 -08001694 mHomePressed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07001695 mHomeLongPressed = false;
1696 if (!homeWasLongPressed) {
Jeff Brown49ed71d2010-12-06 17:13:33 -08001697 try {
Michael Jurka7f2668c2012-03-27 07:49:52 -07001698 mStatusBarService.cancelPreloadRecentApps();
1699 } catch (RemoteException e) {
1700 Slog.e(TAG, "RemoteException when showing recent apps", e);
Jeff Brown49ed71d2010-12-06 17:13:33 -08001701 }
1702
Michael Jurka7f2668c2012-03-27 07:49:52 -07001703 mHomePressed = false;
1704 if (!canceled) {
1705 // If an incoming call is ringing, HOME is totally disabled.
1706 // (The user is already on the InCallScreen at this point,
1707 // and his ONLY options are to answer or reject the call.)
1708 boolean incomingRinging = false;
1709 try {
1710 ITelephony telephonyService = getTelephonyService();
1711 if (telephonyService != null) {
1712 incomingRinging = telephonyService.isRinging();
1713 }
1714 } catch (RemoteException ex) {
1715 Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
1716 }
1717
1718 if (incomingRinging) {
1719 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
1720 } else {
1721 launchHomeFromHotKey();
1722 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08001723 } else {
Michael Jurka7f2668c2012-03-27 07:49:52 -07001724 Log.i(TAG, "Ignoring HOME; event canceled.");
Jeff Brown49ed71d2010-12-06 17:13:33 -08001725 }
Michael Jurka7f2668c2012-03-27 07:49:52 -07001726 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08001727 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08001728 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001729
1730 // If a system window has focus, then it doesn't make sense
1731 // right now to interact with applications.
1732 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
1733 if (attrs != null) {
1734 final int type = attrs.type;
1735 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD
1736 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) {
1737 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001738 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001739 }
1740 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
1741 for (int i=0; i<typeCount; i++) {
1742 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
1743 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001744 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001745 }
1746 }
1747 }
Jeff Brown98392ef2011-09-12 18:24:59 -07001748 if (down) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07001749 if (!mHomePressed) {
1750 try {
1751 mStatusBarService.preloadRecentApps();
1752 } catch (RemoteException e) {
1753 Slog.e(TAG, "RemoteException when preloading recent apps", e);
1754 }
1755 }
Jeff Brown98392ef2011-09-12 18:24:59 -07001756 if (repeatCount == 0) {
1757 mHomePressed = true;
1758 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
1759 if (!keyguardOn) {
1760 handleLongPressOnHome();
1761 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001762 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001763 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001764 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001765 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001766 // Hijack modified menu keys for debugging features
1767 final int chordBug = KeyEvent.META_SHIFT_ON;
1768
1769 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001770 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001771 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
1772 mContext.sendOrderedBroadcast(intent, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001773 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001774 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001775 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001776 Intent service = new Intent();
1777 service.setClassName(mContext, "com.android.server.LoadAverageService");
1778 ContentResolver res = mContext.getContentResolver();
1779 boolean shown = Settings.System.getInt(
1780 res, Settings.System.SHOW_PROCESSES, 0) != 0;
1781 if (!shown) {
1782 mContext.startService(service);
1783 } else {
1784 mContext.stopService(service);
1785 }
1786 Settings.System.putInt(
1787 res, Settings.System.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001788 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001789 }
1790 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001791 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001792 if (down) {
1793 if (repeatCount == 0) {
Jeff Brown49ed71d2010-12-06 17:13:33 -08001794 mShortcutKeyPressed = keyCode;
1795 mConsumeShortcutKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001796 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08001797 } else if (keyCode == mShortcutKeyPressed) {
1798 mShortcutKeyPressed = -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08001799 if (mConsumeShortcutKeyUp) {
Jeff Brown49ed71d2010-12-06 17:13:33 -08001800 mConsumeShortcutKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001801 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001802 }
1803 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001804 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08001805 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Jeff Brownda3d5a92011-03-29 15:11:34 -07001806 if (down && repeatCount == 0) {
Jeff Brown68b909d2011-12-07 16:36:01 -08001807 showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS);
Jeff Brown49ed71d2010-12-06 17:13:33 -08001808 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001809 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001810 }
Jeff Browncaab4d02010-12-09 22:13:41 -08001811
Jeff Brownc1fb48d2010-12-08 16:52:09 -08001812 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08001813 // Any printing key that is chorded with Search should be consumed
1814 // even if no shortcut was invoked. This prevents text from being
1815 // inadvertently inserted when using a keyboard that has built-in macro
1816 // shortcut keys (that emit Search+x) and some of them are not registered.
1817 if (mShortcutKeyPressed != -1) {
1818 final KeyCharacterMap kcm = event.getKeyCharacterMap();
1819 if (kcm.isPrintingKey(keyCode)) {
1820 mConsumeShortcutKeyUp = true;
1821 if (down && repeatCount == 0 && !keyguardOn) {
1822 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
1823 if (shortcutIntent != null) {
1824 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08001825 try {
1826 mContext.startActivity(shortcutIntent);
1827 } catch (ActivityNotFoundException ex) {
1828 Slog.w(TAG, "Dropping shortcut key combination because "
1829 + "the activity to which it is registered was not found: "
1830 + KeyEvent.keyCodeToString(mShortcutKeyPressed)
1831 + "+" + KeyEvent.keyCodeToString(keyCode), ex);
1832 }
Jeff Browncaab4d02010-12-09 22:13:41 -08001833 } else {
1834 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
1835 + KeyEvent.keyCodeToString(mShortcutKeyPressed)
1836 + "+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08001837 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001838 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001839 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001840 }
1841 }
1842
Jeff Brown68b909d2011-12-07 16:36:01 -08001843 // Invoke shortcuts using Meta.
1844 if (down && repeatCount == 0
1845 && (metaState & KeyEvent.META_META_ON) != 0) {
1846 final KeyCharacterMap kcm = event.getKeyCharacterMap();
1847 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
1848 metaState & ~(KeyEvent.META_META_ON
1849 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
1850 if (shortcutIntent != null) {
1851 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1852 try {
1853 mContext.startActivity(shortcutIntent);
1854 } catch (ActivityNotFoundException ex) {
1855 Slog.w(TAG, "Dropping shortcut key combination because "
1856 + "the activity to which it is registered was not found: "
1857 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
1858 }
1859 return -1;
1860 }
1861 }
1862
Jeff Brown6651a632011-11-28 12:59:11 -08001863 // Handle application launch keys.
1864 if (down && repeatCount == 0) {
1865 String category = sApplicationLaunchKeyCategories.get(keyCode);
1866 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08001867 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08001868 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1869 try {
1870 mContext.startActivity(intent);
1871 } catch (ActivityNotFoundException ex) {
1872 Slog.w(TAG, "Dropping application launch key because "
1873 + "the activity to which it is registered was not found: "
1874 + "keyCode=" + keyCode + ", category=" + category, ex);
1875 }
Jeff Brown68b909d2011-12-07 16:36:01 -08001876 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08001877 }
1878 }
1879
Jeff Brown68b909d2011-12-07 16:36:01 -08001880 // Display task switcher for ALT-TAB or Meta-TAB.
1881 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
1882 if (mRecentAppsDialogHeldModifiers == 0) {
1883 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
1884 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)
1885 || KeyEvent.metaStateHasModifiers(
1886 shiftlessModifiers, KeyEvent.META_META_ON)) {
1887 mRecentAppsDialogHeldModifiers = shiftlessModifiers;
1888 showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW);
1889 return -1;
1890 }
1891 }
1892 } else if (!down && mRecentAppsDialogHeldModifiers != 0
1893 && (metaState & mRecentAppsDialogHeldModifiers) == 0) {
1894 mRecentAppsDialogHeldModifiers = 0;
1895 showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH);
1896 }
1897
1898 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001899 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001900 }
1901
Jeff Brown3915bb82010-11-05 15:02:16 -07001902 /** {@inheritDoc} */
1903 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08001904 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07001905 // Note: This method is only called if the initial down was unhandled.
Jeff Brown49ed71d2010-12-06 17:13:33 -08001906 if (DEBUG_FALLBACK) {
Jeff Brown1f245102010-11-18 20:53:46 -08001907 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
1908 + ", flags=" + event.getFlags()
1909 + ", keyCode=" + event.getKeyCode()
1910 + ", scanCode=" + event.getScanCode()
1911 + ", metaState=" + event.getMetaState()
1912 + ", repeatCount=" + event.getRepeatCount()
1913 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07001914 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08001915
1916 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
1917 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08001918 final int keyCode = event.getKeyCode();
1919 final int metaState = event.getMetaState();
Jeff Brown49ed71d2010-12-06 17:13:33 -08001920
Jeff Brown54875002011-04-06 15:33:01 -07001921 // Check for fallback actions specified by the key character map.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001922 if (getFallbackAction(kcm, keyCode, metaState, mFallbackAction)) {
Jeff Brown49ed71d2010-12-06 17:13:33 -08001923 if (DEBUG_FALLBACK) {
1924 Slog.d(TAG, "Fallback: keyCode=" + mFallbackAction.keyCode
1925 + " metaState=" + Integer.toHexString(mFallbackAction.metaState));
1926 }
1927
1928 int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
1929 KeyEvent fallbackEvent = KeyEvent.obtain(
1930 event.getDownTime(), event.getEventTime(),
1931 event.getAction(), mFallbackAction.keyCode,
1932 event.getRepeatCount(), mFallbackAction.metaState,
1933 event.getDeviceId(), event.getScanCode(),
1934 flags, event.getSource(), null);
1935 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags, true);
1936 if ((actions & ACTION_PASS_TO_USER) != 0) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001937 long delayMillis = interceptKeyBeforeDispatching(
1938 win, fallbackEvent, policyFlags);
1939 if (delayMillis == 0) {
Jeff Brown49ed71d2010-12-06 17:13:33 -08001940 if (DEBUG_FALLBACK) {
1941 Slog.d(TAG, "Performing fallback.");
1942 }
1943 return fallbackEvent;
1944 }
1945 }
1946 fallbackEvent.recycle();
1947 }
1948 }
1949
1950 if (DEBUG_FALLBACK) {
1951 Slog.d(TAG, "No fallback.");
1952 }
1953 return null;
Jeff Brown3915bb82010-11-05 15:02:16 -07001954 }
1955
Jeff Brown6f2fba42011-02-19 01:08:02 -08001956 private boolean getFallbackAction(KeyCharacterMap kcm, int keyCode, int metaState,
1957 FallbackAction outFallbackAction) {
1958 // Consult the key character map for specific fallback actions.
1959 // For example, map NUMPAD_1 to MOVE_HOME when NUMLOCK is not pressed.
Jeff Browncc0c1592011-02-19 05:07:28 -08001960 return kcm.getFallbackAction(keyCode, metaState, outFallbackAction);
Jeff Brown6f2fba42011-02-19 01:08:02 -08001961 }
1962
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001963 /**
1964 * A home key -> launch home action was detected. Take the appropriate action
1965 * given the situation with the keyguard.
1966 */
1967 void launchHomeFromHotKey() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07001968 if (mKeyguardMediator != null && mKeyguardMediator.isShowingAndNotHidden()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001969 // don't launch home if keyguard showing
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001970 } else if (!mHideLockScreen && mKeyguardMediator.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001971 // when in keyguard restricted mode, must first verify unlock
1972 // before launching home
1973 mKeyguardMediator.verifyUnlock(new OnKeyguardExitResult() {
1974 public void onKeyguardExitResult(boolean success) {
1975 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07001976 try {
1977 ActivityManagerNative.getDefault().stopAppSwitches();
1978 } catch (RemoteException e) {
1979 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05001980 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001981 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001982 }
1983 }
1984 });
1985 } else {
1986 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07001987 try {
1988 ActivityManagerNative.getDefault().stopAppSwitches();
1989 } catch (RemoteException e) {
1990 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05001991 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001992 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001993 }
1994 }
1995
Dianne Hackborne26ab702011-10-16 13:21:33 -07001996 /**
1997 * A delayed callback use to determine when it is okay to re-allow applications
1998 * to use certain system UI flags. This is used to prevent applications from
1999 * spamming system UI changes that prevent the navigation bar from being shown.
2000 */
2001 final Runnable mAllowSystemUiDelay = new Runnable() {
2002 @Override public void run() {
2003 }
2004 };
2005
2006 /**
2007 * Input handler used while nav bar is hidden. Captures any touch on the screen,
2008 * to determine when the nav bar should be shown and prevent applications from
2009 * receiving those touches.
2010 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08002011 final class HideNavInputEventReceiver extends InputEventReceiver {
2012 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
2013 super(inputChannel, looper);
2014 }
2015
Dianne Hackborndf89e652011-10-06 22:35:11 -07002016 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08002017 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002018 boolean handled = false;
2019 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08002020 if (event instanceof MotionEvent
2021 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
2022 final MotionEvent motionEvent = (MotionEvent)event;
2023 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002024 // When the user taps down, we re-show the nav bar.
2025 boolean changed = false;
2026 synchronized (mLock) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002027 // Any user activity always causes us to show the
2028 // navigation controls, if they had been hidden.
2029 // We also clear the low profile and only content
2030 // flags so that tapping on the screen will atomically
2031 // restore all currently hidden screen decorations.
2032 int newVal = mResettingSystemUiFlags |
2033 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
2034 View.SYSTEM_UI_FLAG_LOW_PROFILE |
2035 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002036 if (mResettingSystemUiFlags != newVal) {
2037 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002038 changed = true;
2039 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002040 // We don't allow the system's nav bar to be hidden
2041 // again for 1 second, to prevent applications from
2042 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002043 newVal = mForceClearedSystemUiFlags |
2044 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002045 if (mForceClearedSystemUiFlags != newVal) {
2046 mForceClearedSystemUiFlags = newVal;
2047 changed = true;
2048 mHandler.postDelayed(new Runnable() {
2049 @Override public void run() {
2050 synchronized (mLock) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002051 // Clear flags.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002052 mForceClearedSystemUiFlags &=
2053 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2054 }
2055 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2056 }
2057 }, 1000);
2058 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002059 }
2060 if (changed) {
2061 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2062 }
2063 }
2064 }
2065 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002066 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07002067 }
2068 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08002069 }
2070 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
2071 new InputEventReceiver.Factory() {
2072 @Override
2073 public InputEventReceiver createInputEventReceiver(
2074 InputChannel inputChannel, Looper looper) {
2075 return new HideNavInputEventReceiver(inputChannel, looper);
2076 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002077 };
2078
2079 @Override
2080 public int adjustSystemUiVisibilityLw(int visibility) {
2081 // Reset any bits in mForceClearingStatusBarVisibility that
2082 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002083 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002084 // Clear any bits in the new visibility that are currently being
2085 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002086 return visibility & ~mResettingSystemUiFlags
2087 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002088 }
2089
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002090 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
2091 final int fl = attrs.flags;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002092
Dianne Hackborn82de1ae2010-10-28 11:28:39 -07002093 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_FULLSCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002094 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002095 int availRight, availBottom;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002096 if (mCanHideNavigationBar &&
2097 (attrs.systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002098 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2099 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2100 } else {
2101 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
2102 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
2103 }
2104 if ((attrs.systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2105 contentInset.set(mStableLeft, mStableTop,
2106 availRight - mStableRight, availBottom - mStableBottom);
2107 } else if ((attrs.systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
2108 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
2109 contentInset.set(mCurLeft, mCurTop,
2110 availRight - mCurRight, availBottom - mCurBottom);
2111 } else {
2112 contentInset.set(mCurLeft, mCurTop,
2113 availRight - mCurRight, availBottom - mCurBottom);
2114 }
2115 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002116 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002117 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002118 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002119
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002120 /** {@inheritDoc} */
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002121 public void beginLayoutLw(int displayWidth, int displayHeight, int displayRotation) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08002122 mUnrestrictedScreenLeft = mUnrestrictedScreenTop = 0;
2123 mUnrestrictedScreenWidth = displayWidth;
2124 mUnrestrictedScreenHeight = displayHeight;
2125 mRestrictedScreenLeft = mRestrictedScreenTop = 0;
2126 mRestrictedScreenWidth = displayWidth;
2127 mRestrictedScreenHeight = displayHeight;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002128 mDockLeft = mContentLeft = mStableLeft = mCurLeft = 0;
2129 mDockTop = mContentTop = mStableTop = mCurTop = 0;
2130 mDockRight = mContentRight = mStableRight = mCurRight = displayWidth;
2131 mDockBottom = mContentBottom = mStableBottom = mCurBottom = displayHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002132 mDockLayer = 0x10000000;
2133
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002134 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
2135 final Rect pf = mTmpParentFrame;
2136 final Rect df = mTmpDisplayFrame;
2137 final Rect vf = mTmpVisibleFrame;
2138 pf.left = df.left = vf.left = mDockLeft;
2139 pf.top = df.top = vf.top = mDockTop;
2140 pf.right = df.right = vf.right = mDockRight;
2141 pf.bottom = df.bottom = vf.bottom = mDockBottom;
2142
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002143 // For purposes of putting out fake window up to steal focus, we will
2144 // drive nav being hidden only by whether it is requested.
2145 boolean navVisible = (mLastSystemUiFlags&View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002146
2147 // When the navigation bar isn't visible, we put up a fake
2148 // input window to catch all touch events. This way we can
2149 // detect when the user presses anywhere to bring back the nav
2150 // bar and ensure the application doesn't see the event.
2151 if (navVisible) {
2152 if (mHideNavFakeWindow != null) {
2153 mHideNavFakeWindow.dismiss();
2154 mHideNavFakeWindow = null;
2155 }
2156 } else if (mHideNavFakeWindow == null) {
2157 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
Jeff Brown32cbc38552011-12-01 14:01:49 -08002158 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Dianne Hackborne26ab702011-10-16 13:21:33 -07002159 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER,
2160 0, false, false, true);
2161 }
2162
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002163 // For purposes of positioning and showing the nav bar, if we have
2164 // decided that it can't be hidden (because of the screen aspect ratio),
2165 // then take that into account.
2166 navVisible |= !mCanHideNavigationBar;
2167
2168 if (mNavigationBar != null) {
2169 // Force the navigation bar to its appropriate place and
2170 // size. We need to do this directly, instead of relying on
2171 // it to bubble up from the nav bar, because this needs to
2172 // change atomically with screen rotations.
2173 mNavigationBarOnBottom = !mHasNavigationBar || displayWidth < displayHeight;
2174 if (mNavigationBarOnBottom) {
2175 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
2176 int top = displayHeight - mNavigationBarHeight;
2177 if (mHdmiPlugged) {
2178 if (top > mExternalDisplayHeight) {
2179 top = mExternalDisplayHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002180 }
2181 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002182 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight);
2183 mStableBottom = mTmpNavigationFrame.top;
2184 if (navVisible) {
2185 mNavigationBar.showLw(true);
2186 mDockBottom = mTmpNavigationFrame.top;
2187 mRestrictedScreenHeight = mDockBottom - mDockTop;
2188 } else {
2189 // We currently want to hide the navigation UI.
2190 mNavigationBar.hideLw(true);
2191 }
2192 } else {
2193 // Landscape screen; nav bar goes to the right.
2194 int left = displayWidth - mNavigationBarWidth;
2195 if (mHdmiPlugged) {
2196 if (left > mExternalDisplayWidth) {
2197 left = mExternalDisplayWidth;
2198 }
2199 }
2200 mTmpNavigationFrame.set(left, 0, displayWidth, displayHeight);
2201 mStableRight = mTmpNavigationFrame.left;
2202 if (navVisible) {
2203 mNavigationBar.showLw(true);
2204 mDockRight = mTmpNavigationFrame.left;
2205 mRestrictedScreenWidth = mDockRight - mDockLeft;
2206 } else {
2207 // We currently want to hide the navigation UI.
2208 mNavigationBar.hideLw(true);
2209 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002210 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002211 // Make sure the content and current rectangles are updated to
2212 // account for the restrictions from the navigation bar.
2213 mContentTop = mCurTop = mDockTop;
2214 mContentBottom = mCurBottom = mDockBottom;
2215 mContentLeft = mCurLeft = mDockLeft;
2216 mContentRight = mCurRight = mDockRight;
2217 // And compute the final frame.
2218 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
2219 mTmpNavigationFrame, mTmpNavigationFrame);
2220 if (DEBUG_LAYOUT) Log.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
2221 }
2222 if (DEBUG_LAYOUT) Log.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
2223 mDockLeft, mDockTop, mDockRight, mDockBottom));
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002224
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002225 // decide where the status bar goes ahead of time
2226 if (mStatusBar != null) {
2227 // apply any navigation bar insets
Dianne Hackborn98014352012-04-05 18:31:41 -07002228 pf.left = df.left = mUnrestrictedScreenLeft;
2229 pf.top = df.top = mUnrestrictedScreenTop;
2230 pf.right = df.right = mUnrestrictedScreenWidth - mUnrestrictedScreenLeft;
2231 pf.bottom = df.bottom = mUnrestrictedScreenHeight - mUnrestrictedScreenTop;
2232 vf.left = mStableLeft;
2233 vf.top = mStableTop;
2234 vf.right = mStableRight;
2235 vf.bottom = mStableBottom;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002236
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002237 mStatusBar.computeFrameLw(pf, df, vf, vf);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002238 final Rect r = mStatusBar.getFrameLw();
2239
2240 // Compute the stable dimensions whether or not the status bar is hidden.
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002241 if (mDockTop == r.top) mStableTop = r.bottom;
2242 else if (mDockBottom == r.bottom) mStableBottom = r.top;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002243
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002244 // If the status bar is hidden, we don't want to cause
2245 // windows behind it to scroll.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002246 if (mStatusBar.isVisibleLw()) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002247 // Status bar may go away, so the screen area it occupies
2248 // is available to apps but just covering them when the
2249 // status bar is visible.
2250 if (mDockTop == r.top) mDockTop = r.bottom;
2251 else if (mDockBottom == r.bottom) mDockBottom = r.top;
2252
2253 mContentTop = mCurTop = mDockTop;
2254 mContentBottom = mCurBottom = mDockBottom;
2255 mContentLeft = mCurLeft = mDockLeft;
2256 mContentRight = mCurRight = mDockRight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002257
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002258 if (DEBUG_LAYOUT) Log.v(TAG, "Status bar: " +
2259 String.format(
2260 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
2261 mDockLeft, mDockTop, mDockRight, mDockBottom,
2262 mContentLeft, mContentTop, mContentRight, mContentBottom,
2263 mCurLeft, mCurTop, mCurRight, mCurBottom));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002264 }
2265 }
2266 }
2267
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002268 void setAttachedWindowFrames(WindowState win, int fl, int adjust,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002269 WindowState attached, boolean insetDecors, Rect pf, Rect df, Rect cf, Rect vf) {
2270 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
2271 // Here's a special case: if this attached window is a panel that is
2272 // above the dock window, and the window it is attached to is below
2273 // the dock window, then the frames we computed for the window it is
2274 // attached to can not be used because the dock is effectively part
2275 // of the underlying window and the attached window is floating on top
2276 // of the whole thing. So, we ignore the attached window and explicitly
2277 // compute the frames that would be appropriate without the dock.
2278 df.left = cf.left = vf.left = mDockLeft;
2279 df.top = cf.top = vf.top = mDockTop;
2280 df.right = cf.right = vf.right = mDockRight;
2281 df.bottom = cf.bottom = vf.bottom = mDockBottom;
2282 } else {
2283 // The effective display frame of the attached window depends on
2284 // whether it is taking care of insetting its content. If not,
2285 // we need to use the parent's content frame so that the entire
2286 // window is positioned within that content. Otherwise we can use
2287 // the display frame and let the attached window take care of
2288 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002289 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002290 cf.set(attached.getDisplayFrameLw());
2291 } else {
2292 // If the window is resizing, then we want to base the content
2293 // frame on our attached content frame to resize... however,
2294 // things can be tricky if the attached window is NOT in resize
2295 // mode, in which case its content frame will be larger.
2296 // Ungh. So to deal with that, make sure the content frame
2297 // we end up using is not covering the IM dock.
2298 cf.set(attached.getContentFrameLw());
2299 if (attached.getSurfaceLayer() < mDockLayer) {
2300 if (cf.left < mContentLeft) cf.left = mContentLeft;
2301 if (cf.top < mContentTop) cf.top = mContentTop;
2302 if (cf.right > mContentRight) cf.right = mContentRight;
2303 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
2304 }
2305 }
2306 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
2307 vf.set(attached.getVisibleFrameLw());
2308 }
2309 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
2310 // window should be positioned relative to its parent or the entire
2311 // screen.
2312 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
2313 ? attached.getFrameLw() : df);
2314 }
2315
2316 /** {@inheritDoc} */
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07002317 public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,
2318 WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002319 // we've already done the status bar
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002320 if (win == mStatusBar || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002321 return;
2322 }
2323
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002324 final int fl = attrs.flags;
2325 final int sim = attrs.softInputMode;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002326 final int sysUiFl = win.getSystemUiVisibility();
2327
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002328 final Rect pf = mTmpParentFrame;
2329 final Rect df = mTmpDisplayFrame;
2330 final Rect cf = mTmpContentFrame;
2331 final Rect vf = mTmpVisibleFrame;
2332
Daniel Sandler36412a72011-08-04 09:35:13 -04002333 final boolean hasNavBar = (mHasNavigationBar
2334 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002335
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002336 if (attrs.type == TYPE_INPUT_METHOD) {
2337 pf.left = df.left = cf.left = vf.left = mDockLeft;
2338 pf.top = df.top = cf.top = vf.top = mDockTop;
2339 pf.right = df.right = cf.right = vf.right = mDockRight;
2340 pf.bottom = df.bottom = cf.bottom = vf.bottom = mDockBottom;
2341 // IM dock windows always go to the bottom of the screen.
2342 attrs.gravity = Gravity.BOTTOM;
2343 mDockLayer = win.getSurfaceLayer();
2344 } else {
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002345 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
2346
Dianne Hackborn82de1ae2010-10-28 11:28:39 -07002347 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_FULLSCREEN | FLAG_LAYOUT_INSET_DECOR))
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002348 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)
2349 && (sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002350 if (DEBUG_LAYOUT)
2351 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle()
2352 + "): IN_SCREEN, INSET_DECOR, !FULLSCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002353 // This is the case for a normal activity window: we want it
2354 // to cover all of the screen space, and it can take care of
2355 // moving its contents to account for screen decorations that
2356 // intrude into that space.
2357 if (attached != null) {
2358 // If this window is attached to another, our display
2359 // frame is the same as the one we are attached to.
2360 setAttachedWindowFrames(win, fl, sim, attached, true, pf, df, cf, vf);
2361 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002362 if (attrs.type == TYPE_STATUS_BAR_PANEL
2363 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08002364 // Status bar panels are the only windows who can go on top of
2365 // the status bar. They are protected by the STATUS_BAR_SERVICE
2366 // permission, so they have the same privileges as the status
2367 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002368 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002369 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002370
2371 pf.left = df.left = hasNavBar ? mDockLeft : mUnrestrictedScreenLeft;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002372 pf.top = df.top = mUnrestrictedScreenTop;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002373 pf.right = df.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002374 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002375 : mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2376 pf.bottom = df.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002377 ? mRestrictedScreenTop+mRestrictedScreenHeight
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002378 : mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
2379
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002380 if (DEBUG_LAYOUT) {
2381 Log.v(TAG, String.format(
2382 "Laying out status bar window: (%d,%d - %d,%d)",
2383 pf.left, pf.top, pf.right, pf.bottom));
2384 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002385 } else if (mCanHideNavigationBar
2386 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002387 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
2388 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
2389 // Asking for layout as if the nav bar is hidden, lets the
2390 // application extend into the unrestricted screen area. We
2391 // only do this for application windows to ensure no window that
2392 // can be above the nav bar can do this.
2393 pf.left = df.left = mUnrestrictedScreenLeft;
2394 pf.top = df.top = mUnrestrictedScreenTop;
2395 pf.right = df.right = mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2396 pf.bottom = df.bottom = mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002397 } else {
2398 pf.left = df.left = mRestrictedScreenLeft;
2399 pf.top = df.top = mRestrictedScreenTop;
2400 pf.right = df.right = mRestrictedScreenLeft+mRestrictedScreenWidth;
2401 pf.bottom = df.bottom = mRestrictedScreenTop+mRestrictedScreenHeight;
2402 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002403 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002404 cf.left = mDockLeft;
2405 cf.top = mDockTop;
2406 cf.right = mDockRight;
2407 cf.bottom = mDockBottom;
2408 } else {
2409 cf.left = mContentLeft;
2410 cf.top = mContentTop;
2411 cf.right = mContentRight;
2412 cf.bottom = mContentBottom;
2413 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002414 if ((sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2415 // If app is requesting a stable layout, don't let the
2416 // content insets go below the stable values.
2417 if (cf.left < mStableLeft) cf.left = mStableLeft;
2418 if (cf.top < mStableTop) cf.top = mStableTop;
2419 if (cf.right > mStableRight) cf.right = mStableRight;
2420 if (cf.bottom > mStableBottom) cf.bottom = mStableBottom;
2421 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002422 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
2423 vf.left = mCurLeft;
2424 vf.top = mCurTop;
2425 vf.right = mCurRight;
2426 vf.bottom = mCurBottom;
2427 } else {
2428 vf.set(cf);
2429 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002430 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002431 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
2432 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
2433 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002434 if (DEBUG_LAYOUT)
2435 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() + "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002436 // A window that has requested to fill the entire screen just
2437 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002438 if (attrs.type == TYPE_STATUS_BAR_PANEL
2439 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
2440 pf.left = df.left = cf.left = hasNavBar ? mDockLeft : mUnrestrictedScreenLeft;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002441 pf.top = df.top = cf.top = mUnrestrictedScreenTop;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002442 pf.right = df.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002443 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002444 : mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2445 pf.bottom = df.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002446 ? mRestrictedScreenTop+mRestrictedScreenHeight
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002447 : mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
Daniel Sandler36412a72011-08-04 09:35:13 -04002448 if (DEBUG_LAYOUT) {
2449 Log.v(TAG, String.format(
2450 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
2451 pf.left, pf.top, pf.right, pf.bottom));
2452 }
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002453 } else if (attrs.type == TYPE_NAVIGATION_BAR) {
2454 // The navigation bar has Real Ultimate Power.
2455 pf.left = df.left = mUnrestrictedScreenLeft;
2456 pf.top = df.top = mUnrestrictedScreenTop;
2457 pf.right = df.right = mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2458 pf.bottom = df.bottom = mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
2459 if (DEBUG_LAYOUT) {
2460 Log.v(TAG, String.format(
2461 "Laying out navigation bar window: (%d,%d - %d,%d)",
2462 pf.left, pf.top, pf.right, pf.bottom));
2463 }
Dianne Hackborn01011c32012-02-21 13:54:21 -08002464 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
2465 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002466 && ((fl & FLAG_FULLSCREEN) != 0)) {
2467 // Fullscreen secure system overlays get what they ask for.
2468 pf.left = df.left = mUnrestrictedScreenLeft;
2469 pf.top = df.top = mUnrestrictedScreenTop;
2470 pf.right = df.right = mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2471 pf.bottom = df.bottom = mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
Dianne Hackborn01011c32012-02-21 13:54:21 -08002472 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
2473 // Boot progress screen always covers entire display.
2474 pf.left = df.left = cf.left = mUnrestrictedScreenLeft;
2475 pf.top = df.top = cf.top = mUnrestrictedScreenTop;
2476 pf.right = df.right = cf.right = mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2477 pf.bottom = df.bottom = cf.bottom
2478 = mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002479 } else if (mCanHideNavigationBar
2480 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002481 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
2482 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
2483 // Asking for layout as if the nav bar is hidden, lets the
2484 // application extend into the unrestricted screen area. We
2485 // only do this for application windows to ensure no window that
2486 // can be above the nav bar can do this.
2487 // XXX This assumes that an app asking for this will also
2488 // ask for layout in only content. We can't currently figure out
2489 // what the screen would be if only laying out to hide the nav bar.
2490 pf.left = df.left = cf.left = mUnrestrictedScreenLeft;
2491 pf.top = df.top = cf.top = mUnrestrictedScreenTop;
2492 pf.right = df.right = cf.right = mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2493 pf.bottom = df.bottom = cf.bottom
2494 = mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002495 } else {
2496 pf.left = df.left = cf.left = mRestrictedScreenLeft;
2497 pf.top = df.top = cf.top = mRestrictedScreenTop;
2498 pf.right = df.right = cf.right = mRestrictedScreenLeft+mRestrictedScreenWidth;
2499 pf.bottom = df.bottom = cf.bottom
2500 = mRestrictedScreenTop+mRestrictedScreenHeight;
2501 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002502 if ((sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2503 // If app is requesting a stable layout, don't let the
2504 // content insets go below the stable values.
2505 if (cf.left < mStableLeft) cf.left = mStableLeft;
2506 if (cf.top < mStableTop) cf.top = mStableTop;
2507 if (cf.right > mStableRight) cf.right = mStableRight;
2508 if (cf.bottom > mStableBottom) cf.bottom = mStableBottom;
2509 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002510 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
2511 vf.left = mCurLeft;
2512 vf.top = mCurTop;
2513 vf.right = mCurRight;
2514 vf.bottom = mCurBottom;
2515 } else {
2516 vf.set(cf);
2517 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002518 } else if (attached != null) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002519 if (DEBUG_LAYOUT)
2520 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() + "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002521 // A child window should be placed inside of the same visible
2522 // frame that its parent had.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002523 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002524 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002525 if (DEBUG_LAYOUT)
2526 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() + "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002527 // Otherwise, a normal window must be placed inside the content
2528 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07002529 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
2530 // Status bar panels are the only windows who can go on top of
2531 // the status bar. They are protected by the STATUS_BAR_SERVICE
2532 // permission, so they have the same privileges as the status
2533 // bar itself.
Dianne Hackborn7d049322011-06-14 15:00:32 -07002534 pf.left = df.left = cf.left = mRestrictedScreenLeft;
2535 pf.top = df.top = cf.top = mRestrictedScreenTop;
2536 pf.right = df.right = cf.right = mRestrictedScreenLeft+mRestrictedScreenWidth;
2537 pf.bottom = df.bottom = cf.bottom
2538 = mRestrictedScreenTop+mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002539 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07002540 pf.left = mContentLeft;
2541 pf.top = mContentTop;
2542 pf.right = mContentRight;
2543 pf.bottom = mContentBottom;
2544 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
2545 df.left = cf.left = mDockLeft;
2546 df.top = cf.top = mDockTop;
2547 df.right = cf.right = mDockRight;
2548 df.bottom = cf.bottom = mDockBottom;
2549 } else {
2550 df.left = cf.left = mContentLeft;
2551 df.top = cf.top = mContentTop;
2552 df.right = cf.right = mContentRight;
2553 df.bottom = cf.bottom = mContentBottom;
2554 }
2555 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
2556 vf.left = mCurLeft;
2557 vf.top = mCurTop;
2558 vf.right = mCurRight;
2559 vf.bottom = mCurBottom;
2560 } else {
2561 vf.set(cf);
2562 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002563 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002564 }
2565 }
2566
2567 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0) {
2568 df.left = df.top = cf.left = cf.top = vf.left = vf.top = -10000;
2569 df.right = df.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
2570 }
2571
The Android Open Source Project11267662009-03-18 17:39:47 -07002572 if (DEBUG_LAYOUT) Log.v(TAG, "Compute frame " + attrs.getTitle()
2573 + ": sim=#" + Integer.toHexString(sim)
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002574 + " attach=" + attached + " type=" + attrs.type
2575 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07002576 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
2577 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString());
2578
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002579 win.computeFrameLw(pf, df, cf, vf);
2580
2581 // Dock windows carve out the bottom of the screen, so normal windows
2582 // can't appear underneath them.
2583 if (attrs.type == TYPE_INPUT_METHOD && !win.getGivenInsetsPendingLw()) {
2584 int top = win.getContentFrameLw().top;
2585 top += win.getGivenContentInsetsLw().top;
2586 if (mContentBottom > top) {
2587 mContentBottom = top;
2588 }
2589 top = win.getVisibleFrameLw().top;
2590 top += win.getGivenVisibleInsetsLw().top;
2591 if (mCurBottom > top) {
2592 mCurBottom = top;
2593 }
The Android Open Source Project11267662009-03-18 17:39:47 -07002594 if (DEBUG_LAYOUT) Log.v(TAG, "Input method: mDockBottom="
2595 + mDockBottom + " mContentBottom="
2596 + mContentBottom + " mCurBottom=" + mCurBottom);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002597 }
2598 }
2599
2600 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08002601 @Override
2602 public void finishLayoutLw() {
2603 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002604 }
2605
2606 /** {@inheritDoc} */
2607 public void beginAnimationLw(int displayWidth, int displayHeight) {
2608 mTopFullscreenOpaqueWindowState = null;
2609 mForceStatusBar = false;
2610
2611 mHideLockScreen = false;
2612 mAllowLockscreenWhenOn = false;
2613 mDismissKeyguard = false;
2614 }
2615
2616 /** {@inheritDoc} */
2617 public void animatingWindowLw(WindowState win,
2618 WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07002619 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
2620 + win.isVisibleOrBehindKeyguardLw());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002621 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08002622 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002623 if ((attrs.flags & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
2624 mForceStatusBar = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07002625 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002626 if (attrs.type >= FIRST_APPLICATION_WINDOW
2627 && attrs.type <= LAST_APPLICATION_WINDOW
Dianne Hackborn6493e642010-10-01 13:06:30 -07002628 && attrs.x == 0 && attrs.y == 0
2629 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
2630 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002631 if (DEBUG_LAYOUT) Log.v(TAG, "Fullscreen window: " + win);
2632 mTopFullscreenOpaqueWindowState = win;
2633 if ((attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
2634 if (localLOGV) Log.v(TAG, "Setting mHideLockScreen to true by win " + win);
2635 mHideLockScreen = true;
2636 }
2637 if ((attrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
2638 if (localLOGV) Log.v(TAG, "Setting mDismissKeyguard to true by win " + win);
2639 mDismissKeyguard = true;
2640 }
2641 if ((attrs.flags & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
2642 mAllowLockscreenWhenOn = true;
2643 }
2644 }
2645 }
2646 }
2647
2648 /** {@inheritDoc} */
2649 public int finishAnimationLw() {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002650 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04002651 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04002652
2653 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
2654 ? mTopFullscreenOpaqueWindowState.getAttrs()
2655 : null;
2656
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002657 if (mStatusBar != null) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07002658 if (DEBUG_LAYOUT) Log.i(TAG, "force=" + mForceStatusBar
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07002659 + " top=" + mTopFullscreenOpaqueWindowState);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002660 if (mForceStatusBar) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07002661 if (DEBUG_LAYOUT) Log.v(TAG, "Showing status bar: forced");
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002662 if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002663 } else if (mTopFullscreenOpaqueWindowState != null) {
Joe Onorato93056472010-09-10 10:30:46 -04002664 if (localLOGV) {
2665 Log.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
2666 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
2667 Log.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
2668 + " lp.flags=0x" + Integer.toHexString(lp.flags));
2669 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002670 topIsFullscreen = (lp.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
2671 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04002672 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
2673 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
2674 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
2675 // case though.
2676 if (topIsFullscreen) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002677 if (DEBUG_LAYOUT) Log.v(TAG, "** HIDING status bar");
2678 if (mStatusBar.hideLw(true)) {
2679 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Daniel Sandler9c00d5b2011-09-13 14:04:26 -04002680
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002681 mHandler.post(new Runnable() { public void run() {
2682 if (mStatusBarService != null) {
2683 try {
2684 mStatusBarService.collapse();
2685 } catch (RemoteException ex) {}
2686 }
2687 }});
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07002688 } else if (DEBUG_LAYOUT) {
Daniel Sandler40427442010-07-16 11:44:52 -04002689 Log.v(TAG, "Preventing status bar from hiding by policy");
2690 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002691 } else {
Dianne Hackborn01b02a72012-01-12 14:05:03 -08002692 if (DEBUG_LAYOUT) Log.v(TAG, "** SHOWING status bar: top is not fullscreen");
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002693 if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002694 }
2695 }
2696 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04002697
Joe Onorato644f9c32011-01-25 12:06:23 -08002698 mTopIsFullscreen = topIsFullscreen;
Daniel Sandlere02d8082010-10-08 15:13:22 -04002699
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07002700 // Hide the key guard if a visible window explicitly specifies that it wants to be displayed
2701 // when the screen is locked
2702 if (mKeyguard != null) {
Joe Onorato93056472010-09-10 10:30:46 -04002703 if (localLOGV) Log.v(TAG, "finishAnimationLw::mHideKeyguard="+mHideLockScreen);
Dianne Hackborn05726582009-09-22 17:28:24 -07002704 if (mDismissKeyguard && !mKeyguardMediator.isSecure()) {
Dianne Hackborn08743722009-12-21 12:16:51 -08002705 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002706 changes |= FINISH_LAYOUT_REDO_LAYOUT
2707 | FINISH_LAYOUT_REDO_CONFIG
2708 | FINISH_LAYOUT_REDO_WALLPAPER;
2709 }
Dianne Hackborn05726582009-09-22 17:28:24 -07002710 if (mKeyguardMediator.isShowing()) {
Dianne Hackbornb446e972009-09-20 15:23:25 -07002711 mHandler.post(new Runnable() {
2712 public void run() {
Dianne Hackborn05726582009-09-22 17:28:24 -07002713 mKeyguardMediator.keyguardDone(false, false);
Dianne Hackbornb446e972009-09-20 15:23:25 -07002714 }
2715 });
2716 }
Dianne Hackborn05726582009-09-22 17:28:24 -07002717 } else if (mHideLockScreen) {
Dianne Hackborn08743722009-12-21 12:16:51 -08002718 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002719 changes |= FINISH_LAYOUT_REDO_LAYOUT
2720 | FINISH_LAYOUT_REDO_CONFIG
2721 | FINISH_LAYOUT_REDO_WALLPAPER;
2722 }
Mike Lockwoodf3bfed52010-01-21 16:38:44 -05002723 mKeyguardMediator.setHidden(true);
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07002724 } else {
Dianne Hackborn08743722009-12-21 12:16:51 -08002725 if (mKeyguard.showLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002726 changes |= FINISH_LAYOUT_REDO_LAYOUT
2727 | FINISH_LAYOUT_REDO_CONFIG
2728 | FINISH_LAYOUT_REDO_WALLPAPER;
2729 }
Mike Lockwoodf3bfed52010-01-21 16:38:44 -05002730 mKeyguardMediator.setHidden(false);
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07002731 }
2732 }
Joe Onorato664644d2011-01-23 17:53:23 -08002733
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002734 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002735 // If the navigation bar has been hidden or shown, we need to do another
2736 // layout pass to update that window.
2737 changes |= FINISH_LAYOUT_REDO_LAYOUT;
2738 }
Joe Onorato664644d2011-01-23 17:53:23 -08002739
Mike Lockwood28569302010-01-28 11:54:40 -05002740 // update since mAllowLockscreenWhenOn might have changed
2741 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002742 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002743 }
2744
Dianne Hackborn08743722009-12-21 12:16:51 -08002745 public boolean allowAppAnimationsLw() {
2746 if (mKeyguard != null && mKeyguard.isVisibleLw()) {
2747 // If keyguard is currently visible, no reason to animate
2748 // behind it.
2749 return false;
2750 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002751 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
2752 RectF rect = new RectF(mStatusBar.getShownFrameLw());
2753 for (int i=mStatusBarPanels.size()-1; i>=0; i--) {
2754 WindowState w = mStatusBarPanels.get(i);
2755 if (w.isVisibleLw()) {
2756 rect.union(w.getShownFrameLw());
Dianne Hackborn08743722009-12-21 12:16:51 -08002757 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002758 }
2759 final int insetw = mRestrictedScreenWidth/10;
2760 final int inseth = mRestrictedScreenHeight/10;
2761 if (rect.contains(insetw, inseth, mRestrictedScreenWidth-insetw,
2762 mRestrictedScreenHeight-inseth)) {
2763 // All of the status bar windows put together cover the
2764 // screen, so the app can't be seen. (Note this test doesn't
2765 // work if the rects of these windows are at odd offsets or
2766 // sizes, causing gaps in the rect union we have computed.)
2767 return false;
Dianne Hackborn08743722009-12-21 12:16:51 -08002768 }
2769 }
2770 return true;
2771 }
2772
Dianne Hackborndf89e652011-10-06 22:35:11 -07002773 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08002774 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002775 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002776 // If the navigation bar has been hidden or shown, we need to do another
2777 // layout pass to update that window.
2778 return FINISH_LAYOUT_REDO_LAYOUT;
2779 }
2780 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08002781 }
2782
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07002783 /** {@inheritDoc} */
Jeff Brown46b9ac02010-04-22 18:58:52 -07002784 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07002785 // do nothing if headless
Mike Lockwoodd747dc82011-09-13 16:28:22 -04002786 if (mHeadless) return;
Mike Lockwood3a74bd32011-08-12 13:55:22 -07002787
Jeff Brown46b9ac02010-04-22 18:58:52 -07002788 // lid changed state
Jeff Brown4aed78b2011-01-14 17:36:55 -08002789 mLidOpen = lidOpen ? LID_OPEN : LID_CLOSED;
Jeff Brown01a98dd2011-09-20 15:08:29 -07002790 updateKeyboardVisibility();
2791
Jeff Brown4aed78b2011-01-14 17:36:55 -08002792 boolean awakeNow = mKeyguardMediator.doLidChangeTq(lidOpen);
Jeff Brown01a98dd2011-09-20 15:08:29 -07002793 updateRotation(true);
Jeff Brown46b9ac02010-04-22 18:58:52 -07002794 if (awakeNow) {
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08002795 // If the lid is opening and we don't have to keep the
Jeff Brown46b9ac02010-04-22 18:58:52 -07002796 // keyguard up, then we can turn on the screen
2797 // immediately.
2798 mKeyguardMediator.pokeWakelock();
2799 } else if (keyguardIsShowingTq()) {
Jeff Brown4aed78b2011-01-14 17:36:55 -08002800 if (lidOpen) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07002801 // If we are opening the lid and not hiding the
2802 // keyguard, then we need to have it turn on the
2803 // screen once it is shown.
2804 mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(
Jeff Brown43150bf2011-11-08 20:22:03 -08002805 KeyEvent.KEYCODE_POWER, mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED);
Jeff Brown46b9ac02010-04-22 18:58:52 -07002806 }
2807 } else {
2808 // Light up the keyboard if we are sliding up.
Jeff Brown4aed78b2011-01-14 17:36:55 -08002809 if (lidOpen) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07002810 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
2811 LocalPowerManager.BUTTON_EVENT);
2812 } else {
2813 mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
2814 LocalPowerManager.OTHER_EVENT);
2815 }
2816 }
2817 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002818
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08002819 void setHdmiPlugged(boolean plugged) {
2820 if (mHdmiPlugged != plugged) {
2821 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002822 if (plugged && mDisplay != null) {
2823 mExternalDisplayWidth = mDisplay.getRawExternalWidth();
2824 mExternalDisplayHeight = mDisplay.getRawExternalHeight();
2825 }
2826 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08002827 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08002828 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08002829 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
2830 mContext.sendStickyBroadcast(intent);
2831 }
2832 }
2833
Joe Onoratoea495d42011-04-06 11:41:11 -07002834 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07002835 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07002836 // watch for HDMI plug messages if the hdmi switch exists
2837 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
2838 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
2839
Joe Onoratoea495d42011-04-06 11:41:11 -07002840 final String filename = "/sys/class/switch/hdmi/state";
2841 FileReader reader = null;
2842 try {
2843 reader = new FileReader(filename);
2844 char[] buf = new char[15];
2845 int n = reader.read(buf);
2846 if (n > 1) {
2847 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
2848 }
2849 } catch (IOException ex) {
2850 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
2851 } catch (NumberFormatException ex) {
2852 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
2853 } finally {
2854 if (reader != null) {
2855 try {
2856 reader.close();
2857 } catch (IOException ex) {
2858 }
Joe Onoratodc100302011-01-11 17:07:41 -08002859 }
2860 }
2861 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07002862 // This dance forces the code in setHdmiPlugged to run.
2863 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
2864 mHdmiPlugged = !plugged;
2865 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08002866 }
2867
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002868 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002869 * @return Whether music is being played right now.
2870 */
2871 boolean isMusicActive() {
Eric Laurent413cb9d2009-07-17 11:52:43 -07002872 final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
2873 if (am == null) {
2874 Log.w(TAG, "isMusicActive: couldn't get AudioManager reference");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002875 return false;
2876 }
Eric Laurent413cb9d2009-07-17 11:52:43 -07002877 return am.isMusicActive();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002878 }
2879
2880 /**
2881 * Tell the audio service to adjust the volume appropriate to the event.
2882 * @param keycode
2883 */
Mike Lockwooda53e3812009-09-25 10:51:39 -04002884 void handleVolumeKey(int stream, int keycode) {
Jeff Brown4d396052010-10-29 21:50:21 -07002885 IAudioService audioService = getAudioService();
2886 if (audioService == null) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002887 return;
2888 }
2889 try {
2890 // since audio is playing, we shouldn't have to hold a wake lock
2891 // during the call, but we do it as a precaution for the rare possibility
2892 // that the music stops right before we call this
Jeff Brownb0418da2010-11-01 15:24:01 -07002893 // TODO: Actually handle MUTE.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002894 mBroadcastWakeLock.acquire();
Jeff Brown4d396052010-10-29 21:50:21 -07002895 audioService.adjustStreamVolume(stream,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002896 keycode == KeyEvent.KEYCODE_VOLUME_UP
2897 ? AudioManager.ADJUST_RAISE
2898 : AudioManager.ADJUST_LOWER,
2899 0);
2900 } catch (RemoteException e) {
2901 Log.w(TAG, "IAudioService.adjustStreamVolume() threw RemoteException " + e);
2902 } finally {
2903 mBroadcastWakeLock.release();
2904 }
2905 }
Jeff Brown4d396052010-10-29 21:50:21 -07002906
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07002907 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07002908 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07002909
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002910 final Runnable mScreenshotTimeout = new Runnable() {
2911 @Override public void run() {
2912 synchronized (mScreenshotLock) {
2913 if (mScreenshotConnection != null) {
2914 mContext.unbindService(mScreenshotConnection);
2915 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07002916 }
Winson Chung9112ec32011-06-27 13:15:32 -07002917 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002918 }
2919 };
2920
2921 // Assume this is called from the Handler thread.
2922 private void takeScreenshot() {
2923 synchronized (mScreenshotLock) {
2924 if (mScreenshotConnection != null) {
2925 return;
2926 }
2927 ComponentName cn = new ComponentName("com.android.systemui",
2928 "com.android.systemui.screenshot.TakeScreenshotService");
2929 Intent intent = new Intent();
2930 intent.setComponent(cn);
2931 ServiceConnection conn = new ServiceConnection() {
2932 @Override
2933 public void onServiceConnected(ComponentName name, IBinder service) {
2934 synchronized (mScreenshotLock) {
2935 if (mScreenshotConnection != this) {
2936 return;
2937 }
2938 Messenger messenger = new Messenger(service);
2939 Message msg = Message.obtain(null, 1);
2940 final ServiceConnection myConn = this;
2941 Handler h = new Handler(mHandler.getLooper()) {
2942 @Override
2943 public void handleMessage(Message msg) {
2944 synchronized (mScreenshotLock) {
2945 if (mScreenshotConnection == myConn) {
2946 mContext.unbindService(mScreenshotConnection);
2947 mScreenshotConnection = null;
2948 mHandler.removeCallbacks(mScreenshotTimeout);
2949 }
2950 }
2951 }
2952 };
2953 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07002954 msg.arg1 = msg.arg2 = 0;
2955 if (mStatusBar != null && mStatusBar.isVisibleLw())
2956 msg.arg1 = 1;
2957 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
2958 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002959 try {
2960 messenger.send(msg);
2961 } catch (RemoteException e) {
2962 }
2963 }
2964 }
2965 @Override
2966 public void onServiceDisconnected(ComponentName name) {}
2967 };
2968 if (mContext.bindService(intent, conn, Context.BIND_AUTO_CREATE)) {
2969 mScreenshotConnection = conn;
2970 mHandler.postDelayed(mScreenshotTimeout, 10000);
2971 }
2972 }
Winson Chung9112ec32011-06-27 13:15:32 -07002973 }
2974
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002975 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002976 @Override
Jeff Brown1f245102010-11-18 20:53:46 -08002977 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) {
2978 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2979 final boolean canceled = event.isCanceled();
2980 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07002981
Jeff Brown3122e442010-10-11 23:32:49 -07002982 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07002983
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05002984 // If screen is off then we treat the case where the keyguard is open but hidden
2985 // the same as if it were open and in front.
2986 // This will prevent any keys other than the power button from waking the screen
2987 // when the keyguard is hidden by another activity.
Mike Lockwood3a74bd32011-08-12 13:55:22 -07002988 final boolean keyguardActive = (mKeyguardMediator == null ? false :
2989 (isScreenOn ?
2990 mKeyguardMediator.isShowingAndNotHidden() :
2991 mKeyguardMediator.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002992
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07002993 if (!mSystemBooted) {
2994 // If we have not yet booted, don't let key events do anything.
2995 return 0;
2996 }
2997
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002998 if (false) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002999 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
3000 + " screenIsOn=" + isScreenOn + " keyguardActive=" + keyguardActive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003001 }
3002
Jeff Brown98392ef2011-09-12 18:24:59 -07003003 if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
3004 && event.getRepeatCount() == 0) {
Jeff Brown4d396052010-10-29 21:50:21 -07003005 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
3006 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003007
Jeff Brownbc072da2011-11-15 12:56:55 -08003008 if (keyCode == KeyEvent.KEYCODE_POWER) {
3009 policyFlags |= WindowManagerPolicy.FLAG_WAKE;
3010 }
3011 final boolean isWakeKey = (policyFlags & (WindowManagerPolicy.FLAG_WAKE
3012 | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
3013
Jeff Brown4d396052010-10-29 21:50:21 -07003014 // Basic policy based on screen state and keyguard.
3015 // FIXME: This policy isn't quite correct. We shouldn't care whether the screen
3016 // is on or off, really. We should care about whether the device is in an
3017 // interactive state or is in suspend pretending to be "off".
3018 // The primary screen might be turned off due to proximity sensor or
3019 // because we are presenting media on an auxiliary screen or remotely controlling
3020 // the device some other way (which is why we have an exemption here for injected
3021 // events).
3022 int result;
Mike Lockwoodd747dc82011-09-13 16:28:22 -04003023 if ((isScreenOn && !mHeadless) || (isInjected && !isWakeKey)) {
Jeff Brown4d396052010-10-29 21:50:21 -07003024 // When the screen is on or if the key is injected pass the key to the application.
3025 result = ACTION_PASS_TO_USER;
3026 } else {
3027 // When the screen is off and the key is not injected, determine whether
3028 // to wake the device but don't pass the key to the application.
3029 result = 0;
Jeff Brown4d396052010-10-29 21:50:21 -07003030 if (down && isWakeKey) {
3031 if (keyguardActive) {
3032 // If the keyguard is showing, let it decide what to do with the wake key.
Jeff Brown43150bf2011-11-08 20:22:03 -08003033 mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(keyCode,
3034 mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED);
Jeff Brown4d396052010-10-29 21:50:21 -07003035 } else {
3036 // Otherwise, wake the device ourselves.
3037 result |= ACTION_POKE_USER_ACTIVITY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003038 }
3039 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003040 }
3041
Jeff Brown4d396052010-10-29 21:50:21 -07003042 // Handle special keys.
3043 switch (keyCode) {
3044 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07003045 case KeyEvent.KEYCODE_VOLUME_UP:
3046 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003047 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
3048 if (down) {
3049 if (isScreenOn && !mVolumeDownKeyTriggered
3050 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3051 mVolumeDownKeyTriggered = true;
3052 mVolumeDownKeyTime = event.getDownTime();
3053 mVolumeDownKeyConsumedByScreenshotChord = false;
3054 cancelPendingPowerKeyAction();
3055 interceptScreenshotChord();
3056 }
3057 } else {
3058 mVolumeDownKeyTriggered = false;
3059 cancelPendingScreenshotChordAction();
3060 }
3061 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
3062 if (down) {
3063 if (isScreenOn && !mVolumeUpKeyTriggered
3064 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3065 mVolumeUpKeyTriggered = true;
3066 cancelPendingPowerKeyAction();
3067 cancelPendingScreenshotChordAction();
3068 }
3069 } else {
3070 mVolumeUpKeyTriggered = false;
3071 cancelPendingScreenshotChordAction();
3072 }
3073 }
Jeff Brown4d396052010-10-29 21:50:21 -07003074 if (down) {
3075 ITelephony telephonyService = getTelephonyService();
3076 if (telephonyService != null) {
3077 try {
3078 if (telephonyService.isRinging()) {
3079 // If an incoming call is ringing, either VOLUME key means
3080 // "silence ringer". We handle these keys here, rather than
3081 // in the InCallScreen, to make sure we'll respond to them
3082 // even if the InCallScreen hasn't come to the foreground yet.
3083 // Look for the DOWN event here, to agree with the "fallback"
3084 // behavior in the InCallScreen.
3085 Log.i(TAG, "interceptKeyBeforeQueueing:"
3086 + " VOLUME key-down while ringing: Silence ringer!");
3087
3088 // Silence the ringer. (It's safe to call this
3089 // even if the ringer has already been silenced.)
3090 telephonyService.silenceRinger();
3091
3092 // And *don't* pass this key thru to the current activity
3093 // (which is probably the InCallScreen.)
3094 result &= ~ACTION_PASS_TO_USER;
3095 break;
3096 }
3097 if (telephonyService.isOffhook()
3098 && (result & ACTION_PASS_TO_USER) == 0) {
3099 // If we are in call but we decided not to pass the key to
3100 // the application, handle the volume change here.
3101 handleVolumeKey(AudioManager.STREAM_VOICE_CALL, keyCode);
3102 break;
3103 }
3104 } catch (RemoteException ex) {
3105 Log.w(TAG, "ITelephony threw RemoteException", ex);
3106 }
3107 }
3108
3109 if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) {
3110 // If music is playing but we decided not to pass the key to the
3111 // application, handle the volume change here.
3112 handleVolumeKey(AudioManager.STREAM_MUSIC, keyCode);
3113 break;
3114 }
3115 }
3116 break;
3117 }
3118
3119 case KeyEvent.KEYCODE_ENDCALL: {
3120 result &= ~ACTION_PASS_TO_USER;
3121 if (down) {
3122 ITelephony telephonyService = getTelephonyService();
3123 boolean hungUp = false;
3124 if (telephonyService != null) {
3125 try {
3126 hungUp = telephonyService.endCall();
3127 } catch (RemoteException ex) {
3128 Log.w(TAG, "ITelephony threw RemoteException", ex);
3129 }
3130 }
3131 interceptPowerKeyDown(!isScreenOn || hungUp);
3132 } else {
3133 if (interceptPowerKeyUp(canceled)) {
3134 if ((mEndcallBehavior
3135 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
3136 if (goHome()) {
3137 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07003138 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003139 }
Jeff Brown4d396052010-10-29 21:50:21 -07003140 if ((mEndcallBehavior
3141 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
3142 result = (result & ~ACTION_POKE_USER_ACTIVITY) | ACTION_GO_TO_SLEEP;
3143 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003144 }
Jeff Brown4d396052010-10-29 21:50:21 -07003145 }
3146 break;
3147 }
3148
3149 case KeyEvent.KEYCODE_POWER: {
3150 result &= ~ACTION_PASS_TO_USER;
3151 if (down) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003152 if (isScreenOn && !mPowerKeyTriggered
3153 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3154 mPowerKeyTriggered = true;
3155 mPowerKeyTime = event.getDownTime();
3156 interceptScreenshotChord();
Winson Chung9112ec32011-06-27 13:15:32 -07003157 }
Winson Chung9112ec32011-06-27 13:15:32 -07003158
Jeff Brown4d396052010-10-29 21:50:21 -07003159 ITelephony telephonyService = getTelephonyService();
3160 boolean hungUp = false;
3161 if (telephonyService != null) {
3162 try {
3163 if (telephonyService.isRinging()) {
3164 // Pressing Power while there's a ringing incoming
3165 // call should silence the ringer.
3166 telephonyService.silenceRinger();
3167 } else if ((mIncallPowerBehavior
3168 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
3169 && telephonyService.isOffhook()) {
3170 // Otherwise, if "Power button ends call" is enabled,
3171 // the Power button will hang up any current active call.
3172 hungUp = telephonyService.endCall();
3173 }
3174 } catch (RemoteException ex) {
3175 Log.w(TAG, "ITelephony threw RemoteException", ex);
3176 }
3177 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003178 interceptPowerKeyDown(!isScreenOn || hungUp
3179 || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003180 } else {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003181 mPowerKeyTriggered = false;
3182 cancelPendingScreenshotChordAction();
3183 if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
Jeff Brown4d396052010-10-29 21:50:21 -07003184 result = (result & ~ACTION_POKE_USER_ACTIVITY) | ACTION_GO_TO_SLEEP;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003185 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003186 mPendingPowerKeyUpCanceled = false;
Jeff Brown4d396052010-10-29 21:50:21 -07003187 }
3188 break;
3189 }
3190
3191 case KeyEvent.KEYCODE_MEDIA_PLAY:
3192 case KeyEvent.KEYCODE_MEDIA_PAUSE:
3193 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
3194 if (down) {
3195 ITelephony telephonyService = getTelephonyService();
3196 if (telephonyService != null) {
3197 try {
3198 if (!telephonyService.isIdle()) {
3199 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
3200 // to avoid music playback.
3201 break;
3202 }
3203 } catch (RemoteException ex) {
3204 Log.w(TAG, "ITelephony threw RemoteException", ex);
Jeff Brown3122e442010-10-11 23:32:49 -07003205 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003206 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003207 }
Jeff Brown4d396052010-10-29 21:50:21 -07003208 case KeyEvent.KEYCODE_HEADSETHOOK:
3209 case KeyEvent.KEYCODE_MUTE:
3210 case KeyEvent.KEYCODE_MEDIA_STOP:
3211 case KeyEvent.KEYCODE_MEDIA_NEXT:
3212 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
3213 case KeyEvent.KEYCODE_MEDIA_REWIND:
3214 case KeyEvent.KEYCODE_MEDIA_RECORD:
3215 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: {
3216 if ((result & ACTION_PASS_TO_USER) == 0) {
3217 // Only do this if we would otherwise not pass it to the user. In that
3218 // case, the PhoneWindow class will do the same thing, except it will
3219 // only do it if the showing app doesn't process the key on its own.
Jeff Brown4d396052010-10-29 21:50:21 -07003220 mBroadcastWakeLock.acquire();
Jeff Brown1f245102010-11-18 20:53:46 -08003221 mHandler.post(new PassHeadsetKey(new KeyEvent(event)));
Jeff Brown4d396052010-10-29 21:50:21 -07003222 }
3223 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003224 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003225
Jeff Brown4d396052010-10-29 21:50:21 -07003226 case KeyEvent.KEYCODE_CALL: {
3227 if (down) {
3228 ITelephony telephonyService = getTelephonyService();
3229 if (telephonyService != null) {
3230 try {
3231 if (telephonyService.isRinging()) {
3232 Log.i(TAG, "interceptKeyBeforeQueueing:"
3233 + " CALL key-down while ringing: Answer the call!");
3234 telephonyService.answerRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003235
Jeff Brown4d396052010-10-29 21:50:21 -07003236 // And *don't* pass this key thru to the current activity
3237 // (which is presumably the InCallScreen.)
3238 result &= ~ACTION_PASS_TO_USER;
3239 }
3240 } catch (RemoteException ex) {
3241 Log.w(TAG, "ITelephony threw RemoteException", ex);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003242 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003243 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003244 }
Jeff Brown4d396052010-10-29 21:50:21 -07003245 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003246 }
3247 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003248 return result;
3249 }
3250
Jeff Brown56194eb2011-03-02 19:23:13 -08003251 /** {@inheritDoc} */
3252 @Override
3253 public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) {
3254 int result = 0;
3255
3256 final boolean isWakeMotion = (policyFlags
3257 & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
3258 if (isWakeMotion) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003259 if (mKeyguardMediator != null && mKeyguardMediator.isShowing()) {
Jeff Brown56194eb2011-03-02 19:23:13 -08003260 // If the keyguard is showing, let it decide what to do with the wake motion.
3261 mKeyguardMediator.onWakeMotionWhenKeyguardShowingTq();
3262 } else {
3263 // Otherwise, wake the device ourselves.
3264 result |= ACTION_POKE_USER_ACTIVITY;
3265 }
3266 }
3267 return result;
3268 }
3269
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003270 class PassHeadsetKey implements Runnable {
3271 KeyEvent mKeyEvent;
3272
3273 PassHeadsetKey(KeyEvent keyEvent) {
3274 mKeyEvent = keyEvent;
3275 }
3276
3277 public void run() {
3278 if (ActivityManagerNative.isSystemReady()) {
3279 Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
3280 intent.putExtra(Intent.EXTRA_KEY_EVENT, mKeyEvent);
3281 mContext.sendOrderedBroadcast(intent, null, mBroadcastDone,
3282 mHandler, Activity.RESULT_OK, null, null);
3283 }
3284 }
3285 }
3286
3287 BroadcastReceiver mBroadcastDone = new BroadcastReceiver() {
3288 public void onReceive(Context context, Intent intent) {
3289 mBroadcastWakeLock.release();
3290 }
3291 };
Mike Lockwood1753f7f2009-08-24 14:49:07 -07003292
3293 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
3294 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07003295 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
3296 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
3297 Intent.EXTRA_DOCK_STATE_UNDOCKED);
3298 } else {
3299 try {
3300 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
3301 ServiceManager.getService(Context.UI_MODE_SERVICE));
3302 mUiMode = uiModeService.getCurrentModeType();
3303 } catch (RemoteException e) {
3304 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07003305 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003306 updateRotation(true);
Mike Lockwoode9867d22009-09-20 01:59:02 -04003307 updateOrientationListenerLp();
Mike Lockwood1753f7f2009-08-24 14:49:07 -07003308 }
3309 };
3310
Daniel Sandler7e37df52011-11-16 22:08:23 -08003311 BroadcastReceiver mPowerReceiver = new BroadcastReceiver() {
3312 public void onReceive(Context context, Intent intent) {
3313 if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) {
3314 mPluggedIn = (0 != intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0));
3315 if (localLOGV) Log.v(TAG, "BATTERY_CHANGED: " + intent + " plugged=" + mPluggedIn);
3316 }
3317 }
3318 };
3319
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003320 /** {@inheritDoc} */
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003321 public void screenTurnedOff(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07003322 EventLog.writeEvent(70000, 0);
The Android Open Source Project0727d222009-03-11 12:11:58 -07003323 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003324 mScreenOnEarly = false;
3325 mScreenOnFully = false;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07003326 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003327 if (mKeyguardMediator != null) {
3328 mKeyguardMediator.onScreenTurnedOff(why);
3329 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07003330 synchronized (mLock) {
The Android Open Source Project0727d222009-03-11 12:11:58 -07003331 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05003332 updateLockScreenTimeout();
Daniel Sandler0601eb72011-04-13 01:01:32 -04003333 updateScreenSaverTimeoutLocked();
The Android Open Source Project0727d222009-03-11 12:11:58 -07003334 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003335 }
3336
3337 /** {@inheritDoc} */
Dianne Hackborn38e29a62011-09-18 14:43:08 -07003338 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Dianne Hackborn74489012009-03-24 20:50:09 -07003339 EventLog.writeEvent(70000, 1);
Dianne Hackborn40011092011-09-22 13:37:48 -07003340 if (false) {
3341 RuntimeException here = new RuntimeException("here");
3342 here.fillInStackTrace();
3343 Slog.i(TAG, "Screen turning on...", here);
3344 }
3345 if (screenOnListener != null) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003346 if (mKeyguardMediator != null) {
3347 mKeyguardMediator.onScreenTurnedOn(new KeyguardViewManager.ShowListener() {
3348 @Override public void onShown(IBinder windowToken) {
3349 if (windowToken != null) {
3350 try {
3351 mWindowManager.waitForWindowDrawn(windowToken,
3352 new IRemoteCallback.Stub() {
3353 @Override public void sendResult(Bundle data) {
3354 Slog.i(TAG, "Lock screen displayed!");
3355 screenOnListener.onScreenOn();
3356 synchronized (mLock) {
3357 mScreenOnFully = true;
3358 }
Dianne Hackborn40011092011-09-22 13:37:48 -07003359 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003360 });
3361 } catch (RemoteException e) {
3362 }
3363 } else {
3364 Slog.i(TAG, "No lock screen!");
3365 screenOnListener.onScreenOn();
3366 synchronized (mLock) {
3367 mScreenOnFully = true;
3368 }
Dianne Hackborn40011092011-09-22 13:37:48 -07003369 }
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003370 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003371 });
3372 }
Dianne Hackborn40011092011-09-22 13:37:48 -07003373 } else {
3374 synchronized (mLock) {
3375 mScreenOnFully = true;
Dianne Hackborn38e29a62011-09-18 14:43:08 -07003376 }
Dianne Hackborn40011092011-09-22 13:37:48 -07003377 }
The Android Open Source Project0727d222009-03-11 12:11:58 -07003378 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003379 mScreenOnEarly = true;
The Android Open Source Project0727d222009-03-11 12:11:58 -07003380 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05003381 updateLockScreenTimeout();
Daniel Sandler0601eb72011-04-13 01:01:32 -04003382 updateScreenSaverTimeoutLocked();
The Android Open Source Project0727d222009-03-11 12:11:58 -07003383 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003384 }
3385
3386 /** {@inheritDoc} */
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003387 public boolean isScreenOnEarly() {
3388 return mScreenOnEarly;
3389 }
3390
3391 /** {@inheritDoc} */
3392 public boolean isScreenOnFully() {
3393 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08003394 }
3395
3396 /** {@inheritDoc} */
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003397 public void enableKeyguard(boolean enabled) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003398 if (mKeyguardMediator != null) {
3399 mKeyguardMediator.setKeyguardEnabled(enabled);
3400 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003401 }
3402
3403 /** {@inheritDoc} */
3404 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003405 if (mKeyguardMediator != null) {
3406 mKeyguardMediator.verifyUnlock(callback);
3407 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003408 }
3409
Mike Lockwoodf7913302009-11-28 22:27:10 -05003410 private boolean keyguardIsShowingTq() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003411 if (mKeyguardMediator == null) return false;
Dianne Hackborn9dc06cc2009-11-17 18:19:23 -08003412 return mKeyguardMediator.isShowingAndNotHidden();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003413 }
3414
Mike Lockwood520d8bc2011-02-18 13:23:13 -05003415
3416 /** {@inheritDoc} */
3417 public boolean isKeyguardLocked() {
3418 return keyguardOn();
3419 }
3420
3421 /** {@inheritDoc} */
3422 public boolean isKeyguardSecure() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003423 if (mKeyguardMediator == null) return false;
Mike Lockwood520d8bc2011-02-18 13:23:13 -05003424 return mKeyguardMediator.isSecure();
3425 }
3426
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003427 /** {@inheritDoc} */
3428 public boolean inKeyguardRestrictedKeyInputMode() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003429 if (mKeyguardMediator == null) return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003430 return mKeyguardMediator.isInputRestricted();
3431 }
3432
Dianne Hackborn90c52de2011-09-23 12:57:44 -07003433 public void dismissKeyguardLw() {
3434 if (!mKeyguardMediator.isSecure()) {
3435 if (mKeyguardMediator.isShowing()) {
3436 mHandler.post(new Runnable() {
3437 public void run() {
3438 mKeyguardMediator.keyguardDone(false, true);
3439 }
3440 });
3441 }
3442 }
3443 }
3444
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003445 void sendCloseSystemWindows() {
3446 sendCloseSystemWindows(mContext, null);
3447 }
3448
3449 void sendCloseSystemWindows(String reason) {
3450 sendCloseSystemWindows(mContext, reason);
3451 }
3452
3453 static void sendCloseSystemWindows(Context context, String reason) {
3454 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07003455 try {
3456 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
3457 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003458 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003459 }
3460 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07003461
Jeff Brown01a98dd2011-09-20 15:08:29 -07003462 @Override
3463 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05003464 if (false) {
3465 Slog.v(TAG, "rotationForOrientationLw(orient="
3466 + orientation + ", last=" + lastRotation
3467 + "); user=" + mUserRotation + " "
3468 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
3469 ? "USER_ROTATION_LOCKED" : "")
3470 );
3471 }
3472
The Android Open Source Project0727d222009-03-11 12:11:58 -07003473 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07003474 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
3475 if (sensorRotation < 0) {
3476 sensorRotation = lastRotation;
3477 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003478
Jeff Browndec6cf42011-11-15 14:08:20 -08003479 final int preferredRotation;
Jeff Browneb3e4b92011-12-06 19:54:24 -08003480 if (mLidOpen == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07003481 // Ignore sensor when lid switch is open and rotation is forced.
3482 preferredRotation = mLidOpenRotation;
3483 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07003484 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07003485 // Ignore sensor when in car dock unless explicitly enabled.
3486 // This case can override the behavior of NOSENSOR, and can also
3487 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07003488 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07003489 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08003490 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
3491 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
3492 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07003493 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07003494 // Ignore sensor when in desk dock unless explicitly enabled.
3495 // This case can override the behavior of NOSENSOR, and can also
3496 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07003497 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07003498 ? sensorRotation : mDeskDockRotation;
Jeff Browneb3e4b92011-12-06 19:54:24 -08003499 } else if (mHdmiPlugged) {
3500 // Ignore sensor when plugged into HDMI.
3501 // Note that the dock orientation overrides the HDMI orientation.
3502 preferredRotation = mHdmiRotation;
Jeff Brown4dfce202011-10-05 12:00:10 -07003503 } else if ((mAccelerometerDefault != 0 /* implies not rotation locked */
Jeff Brown01a98dd2011-09-20 15:08:29 -07003504 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
3505 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED))
3506 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
3507 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
3508 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
3509 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
3510 // Otherwise, use sensor only if requested by the application or enabled
3511 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07003512 if (mAllowAllRotations < 0) {
3513 // Can't read this during init() because the context doesn't
3514 // have display metrics at that time so we cannot determine
3515 // tablet vs. phone then.
3516 mAllowAllRotations = mContext.getResources().getBoolean(
3517 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
3518 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003519 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07003520 || mAllowAllRotations == 1
Jeff Brown01a98dd2011-09-20 15:08:29 -07003521 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR) {
3522 preferredRotation = sensorRotation;
3523 } else {
3524 preferredRotation = lastRotation;
3525 }
Jeff Brown4dfce202011-10-05 12:00:10 -07003526 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
3527 // Apply rotation lock.
3528 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08003529 } else {
3530 // No overriding preference.
3531 // We will do exactly what the application asked us to do.
3532 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07003533 }
3534
Dianne Hackborne5439f22010-10-02 16:53:50 -07003535 switch (orientation) {
3536 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08003537 // Return portrait unless overridden.
3538 if (isAnyPortrait(preferredRotation)) {
3539 return preferredRotation;
3540 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07003541 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07003542
Jeff Brown01a98dd2011-09-20 15:08:29 -07003543 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08003544 // Return landscape unless overridden.
3545 if (isLandscapeOrSeascape(preferredRotation)) {
3546 return preferredRotation;
3547 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003548 return mLandscapeRotation;
3549
3550 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08003551 // Return reverse portrait unless overridden.
3552 if (isAnyPortrait(preferredRotation)) {
3553 return preferredRotation;
3554 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003555 return mUpsideDownRotation;
3556
3557 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08003558 // Return seascape unless overridden.
3559 if (isLandscapeOrSeascape(preferredRotation)) {
3560 return preferredRotation;
3561 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003562 return mSeascapeRotation;
3563
3564 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
3565 // Return either landscape rotation.
3566 if (isLandscapeOrSeascape(preferredRotation)) {
3567 return preferredRotation;
3568 }
3569 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08003570 return lastRotation;
3571 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003572 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003573
Jeff Brown01a98dd2011-09-20 15:08:29 -07003574 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
3575 // Return either portrait rotation.
3576 if (isAnyPortrait(preferredRotation)) {
3577 return preferredRotation;
3578 }
3579 if (isAnyPortrait(lastRotation)) {
3580 return lastRotation;
3581 }
3582 return mPortraitRotation;
3583
3584 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07003585 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
3586 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07003587 if (preferredRotation >= 0) {
3588 return preferredRotation;
3589 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07003590 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05003591 }
3592 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07003593 }
3594
Jeff Brown01a98dd2011-09-20 15:08:29 -07003595 @Override
3596 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
3597 switch (orientation) {
3598 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
3599 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
3600 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
3601 return isAnyPortrait(rotation);
3602
3603 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
3604 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
3605 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
3606 return isLandscapeOrSeascape(rotation);
3607
3608 default:
3609 return true;
3610 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07003611 }
3612
Jeff Brownc0347aa2011-09-23 17:26:09 -07003613 @Override
3614 public void setRotationLw(int rotation) {
3615 mOrientationListener.setCurrentRotation(rotation);
3616 }
3617
Jeff Brown01a98dd2011-09-20 15:08:29 -07003618 private boolean isLandscapeOrSeascape(int rotation) {
3619 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07003620 }
3621
Jeff Brown01a98dd2011-09-20 15:08:29 -07003622 private boolean isAnyPortrait(int rotation) {
3623 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07003624 }
3625
Daniel Sandlerb73617d2010-08-17 00:41:00 -04003626
3627 // User rotation: to be used when all else fails in assigning an orientation to the device
3628 public void setUserRotationMode(int mode, int rot) {
3629 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05003630
3631 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04003632 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Daniel Sandlerb73617d2010-08-17 00:41:00 -04003633 Settings.System.putInt(res,
3634 Settings.System.USER_ROTATION,
3635 rot);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05003636 Settings.System.putInt(res,
3637 Settings.System.ACCELEROMETER_ROTATION,
3638 0);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04003639 } else {
3640 Settings.System.putInt(res,
3641 Settings.System.ACCELEROMETER_ROTATION,
3642 1);
3643 }
3644 }
3645
Jeff Brownac143512012-04-05 18:57:33 -07003646 public void setSafeMode(boolean safeMode) {
3647 mSafeMode = safeMode;
3648 performHapticFeedbackLw(null, safeMode
3649 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
3650 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003651 }
3652
Dianne Hackborn181ceb52009-08-27 22:16:40 -07003653 static long[] getLongIntArray(Resources r, int resid) {
3654 int[] ar = r.getIntArray(resid);
3655 if (ar == null) {
3656 return null;
3657 }
3658 long[] out = new long[ar.length];
3659 for (int i=0; i<ar.length; i++) {
3660 out[i] = ar[i];
3661 }
3662 return out;
3663 }
3664
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003665 /** {@inheritDoc} */
3666 public void systemReady() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003667 if (mKeyguardMediator != null) {
3668 // tell the keyguard
3669 mKeyguardMediator.onSystemReady();
3670 }
Dianne Hackbornb1a79802009-09-29 15:18:31 -07003671 synchronized (mLock) {
3672 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08003673 mSystemReady = true;
3674 mHandler.post(new Runnable() {
3675 public void run() {
3676 updateSettings();
3677 }
3678 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003679 }
3680 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07003681
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07003682 /** {@inheritDoc} */
3683 public void systemBooted() {
3684 synchronized (mLock) {
3685 mSystemBooted = true;
3686 }
3687 }
3688
Dianne Hackborn661cd522011-08-22 00:26:20 -07003689 ProgressDialog mBootMsgDialog = null;
3690
3691 /** {@inheritDoc} */
3692 public void showBootMessage(final CharSequence msg, final boolean always) {
Mike Lockwoodaa5bf142011-09-21 13:03:40 -04003693 if (mHeadless) return;
Dianne Hackborn661cd522011-08-22 00:26:20 -07003694 mHandler.post(new Runnable() {
3695 @Override public void run() {
3696 if (mBootMsgDialog == null) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07003697 mBootMsgDialog = new ProgressDialog(mContext) {
3698 // This dialog will consume all events coming in to
3699 // it, to avoid it trying to do things too early in boot.
3700 @Override public boolean dispatchKeyEvent(KeyEvent event) {
3701 return true;
3702 }
3703 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
3704 return true;
3705 }
3706 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
3707 return true;
3708 }
3709 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
3710 return true;
3711 }
3712 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
3713 return true;
3714 }
3715 @Override public boolean dispatchPopulateAccessibilityEvent(
3716 AccessibilityEvent event) {
3717 return true;
3718 }
3719 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07003720 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
3721 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
3722 mBootMsgDialog.setIndeterminate(true);
3723 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07003724 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07003725 mBootMsgDialog.getWindow().addFlags(
3726 WindowManager.LayoutParams.FLAG_DIM_BEHIND
3727 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
3728 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08003729 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
3730 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
3731 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07003732 mBootMsgDialog.setCancelable(false);
3733 mBootMsgDialog.show();
3734 }
3735 mBootMsgDialog.setMessage(msg);
3736 }
3737 });
3738 }
3739
3740 /** {@inheritDoc} */
3741 public void hideBootMessages() {
3742 mHandler.post(new Runnable() {
3743 @Override public void run() {
3744 if (mBootMsgDialog != null) {
3745 mBootMsgDialog.dismiss();
3746 mBootMsgDialog = null;
3747 }
3748 }
3749 });
3750 }
3751
Mike Lockwood28569302010-01-28 11:54:40 -05003752 /** {@inheritDoc} */
3753 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003754 // ***************************************
3755 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
3756 // ***************************************
3757 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
3758 // WITH ITS LOCKS HELD.
3759 //
3760 // This code must be VERY careful about the locks
3761 // it acquires.
3762 // In fact, the current code acquires way too many,
3763 // and probably has lurking deadlocks.
3764
Mike Lockwood28569302010-01-28 11:54:40 -05003765 synchronized (mScreenLockTimeout) {
3766 if (mLockScreenTimerActive) {
3767 // reset the timer
3768 mHandler.removeCallbacks(mScreenLockTimeout);
3769 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
3770 }
3771 }
Daniel Sandler1d4d30a2011-04-28 12:35:29 -04003772
Daniel Sandlere5f2cfe2011-11-02 23:30:58 -04003773 synchronized (mLock) {
3774 // Only posts messages; holds no additional locks.
3775 updateScreenSaverTimeoutLocked();
Daniel Sandler0601eb72011-04-13 01:01:32 -04003776 }
3777 }
3778
Daniel Sandlere5f2cfe2011-11-02 23:30:58 -04003779 Runnable mScreenSaverActivator = new Runnable() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04003780 public void run() {
Daniel Sandler2d545362011-11-17 10:38:37 -08003781 if (!(mScreenSaverMayRun && mScreenOnEarly)) {
Daniel Sandlere5f2cfe2011-11-02 23:30:58 -04003782 Log.w(TAG, "mScreenSaverActivator ran, but the screensaver should not be showing. Who's driving this thing?");
3783 return;
3784 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08003785 if (!mPluggedIn) {
3786 if (localLOGV) Log.v(TAG, "mScreenSaverActivator: not running screen saver when not plugged in");
3787 return;
3788 }
Daniel Sandler7d46c612011-11-23 09:03:51 -05003789 // Quick fix for automation tests.
3790 // The correct fix is to move this triggering logic to PowerManager, where more complete
3791 // information about wakelocks (including StayOnWhilePluggedIn) is available.
3792 if (Settings.System.getInt(mContext.getContentResolver(),
3793 Settings.System.STAY_ON_WHILE_PLUGGED_IN,
3794 BatteryManager.BATTERY_PLUGGED_AC) != 0) {
3795 Log.v(TAG, "mScreenSaverActivator: not running screen saver when STAY_ON_WHILE_PLUGGED_IN");
3796 return;
3797 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04003798
Daniel Sandlere5f2cfe2011-11-02 23:30:58 -04003799 if (localLOGV) Log.v(TAG, "mScreenSaverActivator entering dreamland");
Daniel Sandler7e37df52011-11-16 22:08:23 -08003800
Daniel Sandlere5f2cfe2011-11-02 23:30:58 -04003801 try {
3802 String component = Settings.Secure.getString(
Daniel Sandler2d545362011-11-17 10:38:37 -08003803 mContext.getContentResolver(), Settings.Secure.SCREENSAVER_COMPONENT);
Daniel Sandlerc224f762011-11-15 22:55:03 -08003804 if (component == null) {
3805 component = mContext.getResources().getString(R.string.config_defaultDreamComponent);
3806 }
Daniel Sandlere5f2cfe2011-11-02 23:30:58 -04003807 if (component != null) {
Daniel Sandler5207d9c2011-11-18 09:30:08 -08003808 // dismiss the notification shade, recents, etc.
Dianne Hackborn672342c2011-11-29 11:29:02 -08003809 mContext.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)
3810 .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT));
Daniel Sandler5207d9c2011-11-18 09:30:08 -08003811
Daniel Sandlere5f2cfe2011-11-02 23:30:58 -04003812 ComponentName cn = ComponentName.unflattenFromString(component);
3813 Intent intent = new Intent(Intent.ACTION_MAIN)
3814 .setComponent(cn)
3815 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
3816 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
3817 | Intent.FLAG_ACTIVITY_NO_USER_ACTION
Daniel Sandler5207d9c2011-11-18 09:30:08 -08003818 | Intent.FLAG_FROM_BACKGROUND
3819 | Intent.FLAG_ACTIVITY_NO_HISTORY
Daniel Sandlere5f2cfe2011-11-02 23:30:58 -04003820 );
3821 mContext.startActivity(intent);
3822 } else {
3823 Log.e(TAG, "Couldn't start screen saver: none selected");
Daniel Sandler0601eb72011-04-13 01:01:32 -04003824 }
Daniel Sandlere5f2cfe2011-11-02 23:30:58 -04003825 } catch (android.content.ActivityNotFoundException exc) {
3826 // no screensaver? give up
3827 Log.e(TAG, "Couldn't start screen saver: none installed");
Daniel Sandler0601eb72011-04-13 01:01:32 -04003828 }
3829 }
3830 };
3831
3832 // Must call while holding mLock
3833 private void updateScreenSaverTimeoutLocked() {
Daniel Sandleree91d942011-08-03 14:13:36 -04003834 if (mScreenSaverActivator == null) return;
3835
Daniel Sandlere5f2cfe2011-11-02 23:30:58 -04003836 mHandler.removeCallbacks(mScreenSaverActivator);
Daniel Sandler2d545362011-11-17 10:38:37 -08003837 if (mScreenSaverEnabledByUser && mScreenSaverMayRun && mScreenOnEarly && mScreenSaverTimeout > 0) {
Daniel Sandlere5f2cfe2011-11-02 23:30:58 -04003838 if (localLOGV)
3839 Log.v(TAG, "scheduling screensaver for " + mScreenSaverTimeout + "ms from now");
3840 mHandler.postDelayed(mScreenSaverActivator, mScreenSaverTimeout);
3841 } else {
3842 if (localLOGV) {
Daniel Sandler2d545362011-11-17 10:38:37 -08003843 if (!mScreenSaverEnabledByUser || mScreenSaverTimeout == 0)
Daniel Sandlere5f2cfe2011-11-02 23:30:58 -04003844 Log.v(TAG, "screen saver disabled by user");
3845 else if (!mScreenOnEarly)
3846 Log.v(TAG, "screen saver disabled while screen off");
3847 else
3848 Log.v(TAG, "screen saver disabled by wakelock");
Daniel Sandler0601eb72011-04-13 01:01:32 -04003849 }
3850 }
Mike Lockwood28569302010-01-28 11:54:40 -05003851 }
3852
3853 Runnable mScreenLockTimeout = new Runnable() {
3854 public void run() {
3855 synchronized (this) {
3856 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003857 if (mKeyguardMediator != null) {
3858 mKeyguardMediator.doKeyguardTimeout();
3859 }
Mike Lockwood28569302010-01-28 11:54:40 -05003860 mLockScreenTimerActive = false;
3861 }
3862 }
3863 };
3864
Jim Miller93c518e2012-01-17 15:55:31 -08003865 public void lockNow() {
3866 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
3867 mHandler.removeCallbacks(mScreenLockTimeout);
3868 mHandler.post(mScreenLockTimeout);
3869 }
3870
Mike Lockwood28569302010-01-28 11:54:40 -05003871 private void updateLockScreenTimeout() {
3872 synchronized (mScreenLockTimeout) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003873 boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly &&
3874 mKeyguardMediator != null && mKeyguardMediator.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05003875 if (mLockScreenTimerActive != enable) {
3876 if (enable) {
3877 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
3878 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
3879 } else {
3880 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
3881 mHandler.removeCallbacks(mScreenLockTimeout);
3882 }
3883 mLockScreenTimerActive = enable;
3884 }
3885 }
3886 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003887
3888 /** {@inheritDoc} */
3889 public void enableScreenAfterBoot() {
3890 readLidState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07003891 updateKeyboardVisibility();
3892
3893 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003894 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07003895
Jeff Brown01a98dd2011-09-20 15:08:29 -07003896 private void updateKeyboardVisibility() {
Jeff Brown4aed78b2011-01-14 17:36:55 -08003897 mPowerManager.setKeyboardVisibility(mLidOpen == LID_OPEN);
Jeff Brown01a98dd2011-09-20 15:08:29 -07003898 }
3899
3900 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003901 try {
3902 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003903 mWindowManager.updateRotation(alwaysSendConfiguration, false);
3904 } catch (RemoteException e) {
3905 // Ignore
3906 }
3907 }
3908
3909 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
3910 try {
3911 //set orientation on WindowManager
3912 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003913 } catch (RemoteException e) {
3914 // Ignore
3915 }
3916 }
3917
3918 /**
Daniel Sandler11ddf532011-11-16 11:10:03 -08003919 * Return an Intent to launch the currently active dock app as home. Returns
3920 * null if the standard home should be launched, which is the case if any of the following is
3921 * true:
3922 * <ul>
3923 * <li>The device is not in either car mode or desk mode
3924 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
3925 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
3926 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
3927 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
3928 * </ul>
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003929 * @return
3930 */
3931 Intent createHomeDockIntent() {
Daniel Sandler11ddf532011-11-16 11:10:03 -08003932 Intent intent = null;
Dianne Hackborn867ab6472010-04-29 13:28:56 -07003933
3934 // What home does is based on the mode, not the dock state. That
3935 // is, when in car mode you should be taken to car home regardless
3936 // of whether we are actually in a car dock.
Dianne Hackborn78968392010-03-04 20:47:56 -08003937 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
Daniel Sandler11ddf532011-11-16 11:10:03 -08003938 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
3939 intent = mCarDockIntent;
3940 }
Dianne Hackborn78968392010-03-04 20:47:56 -08003941 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
Daniel Sandler11ddf532011-11-16 11:10:03 -08003942 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
3943 intent = mDeskDockIntent;
3944 }
3945 }
3946
3947 if (intent == null) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003948 return null;
3949 }
3950
3951 ActivityInfo ai = intent.resolveActivityInfo(
3952 mContext.getPackageManager(), PackageManager.GET_META_DATA);
3953 if (ai == null) {
3954 return null;
3955 }
3956
3957 if (ai.metaData != null && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
3958 intent = new Intent(intent);
3959 intent.setClassName(ai.packageName, ai.name);
3960 return intent;
3961 }
3962
3963 return null;
3964 }
3965
3966 void startDockOrHome() {
3967 Intent dock = createHomeDockIntent();
3968 if (dock != null) {
3969 try {
3970 mContext.startActivity(dock);
3971 return;
3972 } catch (ActivityNotFoundException e) {
3973 }
3974 }
3975 mContext.startActivity(mHomeIntent);
3976 }
3977
3978 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003979 * goes to the home screen
3980 * @return whether it did anything
3981 */
3982 boolean goHome() {
3983 if (false) {
3984 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003985 try {
3986 ActivityManagerNative.getDefault().stopAppSwitches();
3987 } catch (RemoteException e) {
3988 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07003989 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003990 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003991 } else {
3992 // This code brings home to the front or, if it is already
3993 // at the front, puts the device to sleep.
3994 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08003995 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
3996 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
3997 Log.d(TAG, "UTS-TEST-MODE");
3998 } else {
3999 ActivityManagerNative.getDefault().stopAppSwitches();
4000 sendCloseSystemWindows();
4001 Intent dock = createHomeDockIntent();
4002 if (dock != null) {
4003 int result = ActivityManagerNative.getDefault()
4004 .startActivity(null, dock,
4005 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07004006 null, null, 0,
4007 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
4008 null, null, null);
4009 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
Wink Savilled2e6a332010-02-12 12:12:06 -08004010 return false;
4011 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004012 }
4013 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004014 int result = ActivityManagerNative.getDefault()
4015 .startActivity(null, mHomeIntent,
4016 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07004017 null, null, 0,
4018 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
4019 null, null, null);
4020 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004021 return false;
4022 }
4023 } catch (RemoteException ex) {
4024 // bummer, the activity manager, which is in this process, is dead
4025 }
4026 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004027 return true;
4028 }
4029
The Android Open Source Project0727d222009-03-11 12:11:58 -07004030 public void setCurrentOrientationLw(int newOrientation) {
4031 synchronized (mLock) {
4032 if (newOrientation != mCurrentAppOrientation) {
4033 mCurrentAppOrientation = newOrientation;
4034 updateOrientationListenerLp();
4035 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004036 }
4037 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004038
The Android Open Source Project0727d222009-03-11 12:11:58 -07004039 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Jim Miller89b17222009-10-27 14:54:09 -07004040 final boolean hapticsDisabled = Settings.System.getInt(mContext.getContentResolver(),
4041 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0) == 0;
Dianne Hackborn9dc06cc2009-11-17 18:19:23 -08004042 if (!always && (hapticsDisabled || mKeyguardMediator.isShowingAndNotHidden())) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004043 return false;
4044 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004045 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004046 switch (effectId) {
4047 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004048 pattern = mLongPressVibePattern;
4049 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004050 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004051 pattern = mVirtualKeyVibePattern;
4052 break;
4053 case HapticFeedbackConstants.KEYBOARD_TAP:
4054 pattern = mKeyboardTapVibePattern;
4055 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004056 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004057 pattern = mSafeModeDisabledVibePattern;
4058 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004059 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004060 pattern = mSafeModeEnabledVibePattern;
4061 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08004062 default:
4063 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004064 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004065 if (pattern.length == 1) {
4066 // One-shot vibration
4067 mVibrator.vibrate(pattern[0]);
4068 } else {
4069 // Pattern vibration
4070 mVibrator.vibrate(pattern, -1);
4071 }
4072 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004073 }
4074
Daniel Sandler0601eb72011-04-13 01:01:32 -04004075 public void screenOnStartedLw() {
4076 // The window manager has just grabbed a wake lock. This is our cue to disable the screen
4077 // saver.
4078 synchronized (mLock) {
Daniel Sandler2d545362011-11-17 10:38:37 -08004079 mScreenSaverMayRun = false;
Daniel Sandler0601eb72011-04-13 01:01:32 -04004080 }
4081 }
4082
The Android Open Source Project0727d222009-03-11 12:11:58 -07004083 public void screenOnStoppedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04004084 if (mPowerManager.isScreenOn()) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004085 if (mKeyguardMediator != null && !mKeyguardMediator.isShowingAndNotHidden()) {
Daniel Sandler0601eb72011-04-13 01:01:32 -04004086 long curTime = SystemClock.uptimeMillis();
4087 mPowerManager.userActivity(curTime, false, LocalPowerManager.OTHER_EVENT);
4088 }
4089
4090 synchronized (mLock) {
4091 // even if the keyguard is up, now that all the wakelocks have been released, we
4092 // should re-enable the screen saver
Daniel Sandler2d545362011-11-17 10:38:37 -08004093 mScreenSaverMayRun = true;
Daniel Sandler0601eb72011-04-13 01:01:32 -04004094 updateScreenSaverTimeoutLocked();
4095 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004096 }
4097 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04004098
4099 public boolean allowKeyRepeat() {
4100 // disable key repeat when screen is off
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004101 return mScreenOnEarly;
Mike Lockwoodfcb39242009-10-21 23:01:07 -04004102 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004103
Dianne Hackborndf89e652011-10-06 22:35:11 -07004104 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08004105 // If there is no window focused, there will be nobody to handle the events
4106 // anyway, so just hang on in whatever state we're in until things settle down.
Dianne Hackborndf89e652011-10-06 22:35:11 -07004107 if (mFocusedWindow == null) {
4108 return 0;
4109 }
4110 final int visibility = mFocusedWindow.getSystemUiVisibility()
Dianne Hackborne26ab702011-10-16 13:21:33 -07004111 & ~mResettingSystemUiFlags
4112 & ~mForceClearedSystemUiFlags;
4113 int diff = visibility ^ mLastSystemUiFlags;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08004114 final boolean needsMenu = mFocusedWindow.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08004115 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
4116 && mFocusedApp == mFocusedWindow.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004117 return 0;
4118 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07004119 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08004120 mLastFocusNeedsMenu = needsMenu;
Dianne Hackborne0f085d2011-11-30 18:41:15 -08004121 mFocusedApp = mFocusedWindow.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07004122 mHandler.post(new Runnable() {
4123 public void run() {
4124 if (mStatusBarService == null) {
4125 mStatusBarService = IStatusBarService.Stub.asInterface(
4126 ServiceManager.getService("statusbar"));
4127 }
4128 if (mStatusBarService != null) {
4129 try {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004130 mStatusBarService.setSystemUiVisibility(visibility, 0xffffffff);
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08004131 mStatusBarService.topAppWindowChanged(needsMenu);
Dianne Hackborndf89e652011-10-06 22:35:11 -07004132 } catch (RemoteException e) {
4133 // not much to be done
4134 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08004135 }
4136 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07004137 }
4138 });
4139 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08004140 }
4141
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04004142 // Use this instead of checking config_showNavigationBar so that it can be consistently
4143 // overridden by qemu.hw.mainkeys in the emulator.
4144 public boolean hasNavigationBar() {
4145 return mHasNavigationBar;
4146 }
4147
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004148 public void dump(String prefix, FileDescriptor fd, PrintWriter pw, String[] args) {
4149 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004150 pw.print(" mSystemReady="); pw.print(mSystemReady);
4151 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004152 pw.print(prefix); pw.print("mLidOpen="); pw.print(mLidOpen);
4153 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
4154 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07004155 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
4156 || mForceClearedSystemUiFlags != 0) {
4157 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
4158 pw.print(Integer.toHexString(mLastSystemUiFlags));
4159 pw.print(" mResettingSystemUiFlags=0x");
4160 pw.print(Integer.toHexString(mResettingSystemUiFlags));
4161 pw.print(" mForceClearedSystemUiFlags=0x");
4162 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07004163 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08004164 if (mLastFocusNeedsMenu) {
4165 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
4166 pw.println(mLastFocusNeedsMenu);
4167 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004168 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
4169 pw.print(" mDockMode="); pw.print(mDockMode);
4170 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
4171 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
4172 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
4173 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004174 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004175 pw.print(prefix); pw.print("mAccelerometerDefault="); pw.print(mAccelerometerDefault);
4176 pw.print(" mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
4177 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
4178 pw.print(mCarDockEnablesAccelerometer);
4179 pw.print(" mDeskDockEnablesAccelerometer=");
4180 pw.println(mDeskDockEnablesAccelerometer);
4181 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
4182 pw.print(mLidKeyboardAccessibility);
4183 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
4184 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004185 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
4186 pw.print(" mScreenOnFully="); pw.print(mScreenOnFully);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004187 pw.print(" mOrientationSensorEnabled="); pw.print(mOrientationSensorEnabled);
4188 pw.print(" mHasSoftInput="); pw.println(mHasSoftInput);
4189 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
4190 pw.print(","); pw.print(mUnrestrictedScreenTop);
4191 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
4192 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
4193 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
4194 pw.print(","); pw.print(mRestrictedScreenTop);
4195 pw.print(") "); pw.print(mRestrictedScreenWidth);
4196 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004197 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
4198 pw.print(","); pw.print(mStableTop);
4199 pw.print(")-("); pw.print(mStableRight);
4200 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004201 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
4202 pw.print(","); pw.print(mCurTop);
4203 pw.print(")-("); pw.print(mCurRight);
4204 pw.print(","); pw.print(mCurBottom); pw.println(")");
4205 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
4206 pw.print(","); pw.print(mContentTop);
4207 pw.print(")-("); pw.print(mContentRight);
4208 pw.print(","); pw.print(mContentBottom); pw.println(")");
4209 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
4210 pw.print(","); pw.print(mDockTop);
4211 pw.print(")-("); pw.print(mDockRight);
4212 pw.print(","); pw.print(mDockBottom); pw.println(")");
4213 pw.print(prefix); pw.print("mDockLayer="); pw.println(mDockLayer);
4214 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
4215 pw.println(mTopFullscreenOpaqueWindowState);
4216 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
4217 pw.print(" mForceStatusBar="); pw.print(mForceStatusBar);
4218 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
4219 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
4220 pw.print(" mHomePressed="); pw.println(mHomePressed);
4221 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
4222 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
4223 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
4224 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
4225 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
4226 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
4227 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
4228 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
4229 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
4230 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
4231 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004232}