Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server; |
| 18 | |
| 19 | import android.app.Activity; |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame^] | 20 | import android.app.ActivityManager; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 21 | import android.app.ActivityManagerNative; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 22 | import android.app.IUiModeManager; |
| 23 | import android.app.Notification; |
| 24 | import android.app.NotificationManager; |
| 25 | import android.app.PendingIntent; |
| 26 | import android.app.StatusBarManager; |
| 27 | import android.app.UiModeManager; |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 28 | import android.content.ActivityNotFoundException; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 29 | import android.content.BroadcastReceiver; |
| 30 | import android.content.Context; |
| 31 | import android.content.Intent; |
| 32 | import android.content.IntentFilter; |
| 33 | import android.content.pm.PackageManager; |
| 34 | import android.content.res.Configuration; |
Mike Lockwood | e29db6a | 2010-03-05 13:45:51 -0500 | [diff] [blame] | 35 | import android.os.BatteryManager; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 36 | import android.os.Binder; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 37 | import android.os.Handler; |
Mike Lockwood | e29db6a | 2010-03-05 13:45:51 -0500 | [diff] [blame] | 38 | import android.os.PowerManager; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 39 | import android.os.RemoteException; |
| 40 | import android.os.ServiceManager; |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 41 | import android.os.UserHandle; |
Dianne Hackborn | 2ccda4d | 2010-03-22 21:49:15 -0700 | [diff] [blame] | 42 | import android.provider.Settings; |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame^] | 43 | import android.service.dreams.Dream; |
| 44 | import android.service.dreams.IDreamManager; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 45 | import android.util.Slog; |
| 46 | |
| 47 | import java.io.FileDescriptor; |
| 48 | import java.io.PrintWriter; |
| 49 | |
| 50 | import com.android.internal.R; |
| 51 | import com.android.internal.app.DisableCarModeActivity; |
Jeff Brown | 2416e09 | 2012-08-21 22:12:20 -0700 | [diff] [blame] | 52 | import com.android.server.TwilightService.TwilightState; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 53 | |
| 54 | class UiModeManagerService extends IUiModeManager.Stub { |
| 55 | private static final String TAG = UiModeManager.class.getSimpleName(); |
| 56 | private static final boolean LOG = false; |
| 57 | |
Daniel Sandler | 11ddf53 | 2011-11-16 11:10:03 -0800 | [diff] [blame] | 58 | // Enable launching of applications when entering the dock. |
| 59 | private static final boolean ENABLE_LAUNCH_CAR_DOCK_APP = true; |
John Spurlock | 960779d | 2012-05-29 14:37:05 -0400 | [diff] [blame] | 60 | private static final boolean ENABLE_LAUNCH_DESK_DOCK_APP = true; |
Daniel Sandler | 11ddf53 | 2011-11-16 11:10:03 -0800 | [diff] [blame] | 61 | |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame^] | 62 | private static final int DEFAULT_SCREENSAVER_ENABLED = 1; |
| 63 | private static final int DEFAULT_SCREENSAVER_ACTIVATED_ON_DOCK = 1; |
| 64 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 65 | private final Context mContext; |
Jeff Brown | 2416e09 | 2012-08-21 22:12:20 -0700 | [diff] [blame] | 66 | private final TwilightService mTwilightService; |
| 67 | private final Handler mHandler = new Handler(); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 68 | |
| 69 | final Object mLock = new Object(); |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 70 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 71 | private int mDockState = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 72 | private int mLastBroadcastState = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 73 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 74 | private int mNightMode = UiModeManager.MODE_NIGHT_NO; |
| 75 | private boolean mCarModeEnabled = false; |
Mike Lockwood | e29db6a | 2010-03-05 13:45:51 -0500 | [diff] [blame] | 76 | private boolean mCharging = false; |
Joe Onorato | 44fcb83 | 2011-12-14 20:59:30 -0800 | [diff] [blame] | 77 | private final int mDefaultUiModeType; |
Mike Lockwood | e29db6a | 2010-03-05 13:45:51 -0500 | [diff] [blame] | 78 | private final boolean mCarModeKeepsScreenOn; |
| 79 | private final boolean mDeskModeKeepsScreenOn; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 80 | private final boolean mTelevision; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 81 | |
| 82 | private boolean mComputedNightMode; |
| 83 | private int mCurUiMode = 0; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 84 | private int mSetUiMode = 0; |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 85 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 86 | private boolean mHoldingConfiguration = false; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 87 | private Configuration mConfiguration = new Configuration(); |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 88 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 89 | private boolean mSystemReady; |
| 90 | |
| 91 | private NotificationManager mNotificationManager; |
| 92 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 93 | private StatusBarManager mStatusBarManager; |
Mike Lockwood | e29db6a | 2010-03-05 13:45:51 -0500 | [diff] [blame] | 94 | private final PowerManager.WakeLock mWakeLock; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 95 | |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 96 | static Intent buildHomeIntent(String category) { |
| 97 | Intent intent = new Intent(Intent.ACTION_MAIN); |
| 98 | intent.addCategory(category); |
| 99 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 100 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 101 | return intent; |
| 102 | } |
John Spurlock | 960779d | 2012-05-29 14:37:05 -0400 | [diff] [blame] | 103 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 104 | // The broadcast receiver which receives the result of the ordered broadcast sent when |
| 105 | // the dock state changes. The original ordered broadcast is sent with an initial result |
| 106 | // code of RESULT_OK. If any of the registered broadcast receivers changes this value, e.g., |
| 107 | // to RESULT_CANCELED, then the intent to start a dock app will not be sent. |
| 108 | private final BroadcastReceiver mResultReceiver = new BroadcastReceiver() { |
| 109 | @Override |
| 110 | public void onReceive(Context context, Intent intent) { |
| 111 | if (getResultCode() != Activity.RESULT_OK) { |
Daniel Sandler | 69a1da4 | 2011-11-04 15:08:30 -0400 | [diff] [blame] | 112 | if (LOG) { |
John Spurlock | 960779d | 2012-05-29 14:37:05 -0400 | [diff] [blame] | 113 | Slog.v(TAG, "Handling broadcast result for action " + intent.getAction() |
Daniel Sandler | 69a1da4 | 2011-11-04 15:08:30 -0400 | [diff] [blame] | 114 | + ": canceled: " + getResultCode()); |
| 115 | } |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 116 | return; |
| 117 | } |
| 118 | |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame^] | 119 | final int enableFlags = intent.getIntExtra("enableFlags", 0); |
| 120 | final int disableFlags = intent.getIntExtra("disableFlags", 0); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 121 | synchronized (mLock) { |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame^] | 122 | updateAfterBroadcastLocked(intent.getAction(), enableFlags, disableFlags); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | }; |
| 126 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 127 | private final BroadcastReceiver mDockModeReceiver = new BroadcastReceiver() { |
| 128 | @Override |
| 129 | public void onReceive(Context context, Intent intent) { |
| 130 | int state = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 131 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 132 | updateDockState(state); |
| 133 | } |
| 134 | }; |
| 135 | |
Mike Lockwood | e29db6a | 2010-03-05 13:45:51 -0500 | [diff] [blame] | 136 | private final BroadcastReceiver mBatteryReceiver = new BroadcastReceiver() { |
| 137 | @Override |
| 138 | public void onReceive(Context context, Intent intent) { |
| 139 | mCharging = (intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0); |
| 140 | synchronized (mLock) { |
| 141 | if (mSystemReady) { |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 142 | updateLocked(0, 0); |
Mike Lockwood | e29db6a | 2010-03-05 13:45:51 -0500 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | } |
| 146 | }; |
| 147 | |
Jeff Brown | 2416e09 | 2012-08-21 22:12:20 -0700 | [diff] [blame] | 148 | private final TwilightService.TwilightListener mTwilightListener = |
| 149 | new TwilightService.TwilightListener() { |
Dianne Hackborn | 57f4503 | 2010-06-17 15:49:33 -0700 | [diff] [blame] | 150 | @Override |
Jeff Brown | 2416e09 | 2012-08-21 22:12:20 -0700 | [diff] [blame] | 151 | public void onTwilightStateChanged() { |
| 152 | updateTwilight(); |
Dianne Hackborn | 57f4503 | 2010-06-17 15:49:33 -0700 | [diff] [blame] | 153 | } |
| 154 | }; |
| 155 | |
Jeff Brown | 2416e09 | 2012-08-21 22:12:20 -0700 | [diff] [blame] | 156 | public UiModeManagerService(Context context, TwilightService twilight) { |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 157 | mContext = context; |
Jeff Brown | 2416e09 | 2012-08-21 22:12:20 -0700 | [diff] [blame] | 158 | mTwilightService = twilight; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 159 | |
| 160 | ServiceManager.addService(Context.UI_MODE_SERVICE, this); |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 161 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 162 | mContext.registerReceiver(mDockModeReceiver, |
| 163 | new IntentFilter(Intent.ACTION_DOCK_EVENT)); |
Mike Lockwood | e29db6a | 2010-03-05 13:45:51 -0500 | [diff] [blame] | 164 | mContext.registerReceiver(mBatteryReceiver, |
| 165 | new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); |
| 166 | |
| 167 | PowerManager powerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 168 | mWakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, TAG); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 169 | |
| 170 | mConfiguration.setToDefaults(); |
Mike Lockwood | e29db6a | 2010-03-05 13:45:51 -0500 | [diff] [blame] | 171 | |
Joe Onorato | 44fcb83 | 2011-12-14 20:59:30 -0800 | [diff] [blame] | 172 | mDefaultUiModeType = context.getResources().getInteger( |
| 173 | com.android.internal.R.integer.config_defaultUiModeType); |
Mike Lockwood | e29db6a | 2010-03-05 13:45:51 -0500 | [diff] [blame] | 174 | mCarModeKeepsScreenOn = (context.getResources().getInteger( |
| 175 | com.android.internal.R.integer.config_carDockKeepsScreenOn) == 1); |
| 176 | mDeskModeKeepsScreenOn = (context.getResources().getInteger( |
| 177 | com.android.internal.R.integer.config_deskDockKeepsScreenOn) == 1); |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 178 | mTelevision = context.getPackageManager().hasSystemFeature( |
| 179 | PackageManager.FEATURE_TELEVISION); |
| 180 | |
Dianne Hackborn | 2ccda4d | 2010-03-22 21:49:15 -0700 | [diff] [blame] | 181 | mNightMode = Settings.Secure.getInt(mContext.getContentResolver(), |
| 182 | Settings.Secure.UI_NIGHT_MODE, UiModeManager.MODE_NIGHT_AUTO); |
Jeff Brown | 2416e09 | 2012-08-21 22:12:20 -0700 | [diff] [blame] | 183 | |
| 184 | mTwilightService.registerListener(mTwilightListener, mHandler); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 185 | } |
| 186 | |
Dianne Hackborn | d49258f | 2010-03-26 00:44:29 -0700 | [diff] [blame] | 187 | public void disableCarMode(int flags) { |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 188 | synchronized (mLock) { |
| 189 | setCarModeLocked(false); |
Mike Lockwood | 924e164 | 2010-03-05 11:56:53 -0500 | [diff] [blame] | 190 | if (mSystemReady) { |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 191 | updateLocked(0, flags); |
Mike Lockwood | 924e164 | 2010-03-05 11:56:53 -0500 | [diff] [blame] | 192 | } |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 196 | public void enableCarMode(int flags) { |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 197 | synchronized (mLock) { |
| 198 | setCarModeLocked(true); |
Mike Lockwood | 924e164 | 2010-03-05 11:56:53 -0500 | [diff] [blame] | 199 | if (mSystemReady) { |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 200 | updateLocked(flags, 0); |
Mike Lockwood | 924e164 | 2010-03-05 11:56:53 -0500 | [diff] [blame] | 201 | } |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | |
| 205 | public int getCurrentModeType() { |
| 206 | synchronized (mLock) { |
| 207 | return mCurUiMode & Configuration.UI_MODE_TYPE_MASK; |
| 208 | } |
| 209 | } |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 210 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 211 | public void setNightMode(int mode) throws RemoteException { |
| 212 | synchronized (mLock) { |
| 213 | switch (mode) { |
| 214 | case UiModeManager.MODE_NIGHT_NO: |
| 215 | case UiModeManager.MODE_NIGHT_YES: |
| 216 | case UiModeManager.MODE_NIGHT_AUTO: |
| 217 | break; |
| 218 | default: |
| 219 | throw new IllegalArgumentException("Unknown mode: " + mode); |
| 220 | } |
| 221 | if (!isDoingNightMode()) { |
| 222 | return; |
| 223 | } |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 224 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 225 | if (mNightMode != mode) { |
Dianne Hackborn | 2ccda4d | 2010-03-22 21:49:15 -0700 | [diff] [blame] | 226 | long ident = Binder.clearCallingIdentity(); |
| 227 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 228 | Settings.Secure.UI_NIGHT_MODE, mode); |
| 229 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 230 | mNightMode = mode; |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 231 | updateLocked(0, 0); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | } |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 235 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 236 | public int getNightMode() throws RemoteException { |
| 237 | return mNightMode; |
| 238 | } |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 239 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 240 | void systemReady() { |
| 241 | synchronized (mLock) { |
| 242 | mSystemReady = true; |
| 243 | mCarModeEnabled = mDockState == Intent.EXTRA_DOCK_STATE_CAR; |
Jeff Brown | 2416e09 | 2012-08-21 22:12:20 -0700 | [diff] [blame] | 244 | updateComputedNightModeLocked(); |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 245 | updateLocked(0, 0); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | |
| 249 | boolean isDoingNightMode() { |
| 250 | return mCarModeEnabled || mDockState != Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 251 | } |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 252 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 253 | void setCarModeLocked(boolean enabled) { |
| 254 | if (mCarModeEnabled != enabled) { |
| 255 | mCarModeEnabled = enabled; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 256 | } |
| 257 | } |
| 258 | |
| 259 | void updateDockState(int newState) { |
| 260 | synchronized (mLock) { |
| 261 | if (newState != mDockState) { |
| 262 | mDockState = newState; |
Mike Lockwood | 924e164 | 2010-03-05 11:56:53 -0500 | [diff] [blame] | 263 | setCarModeLocked(mDockState == Intent.EXTRA_DOCK_STATE_CAR); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 264 | if (mSystemReady) { |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 265 | updateLocked(UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME, 0); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 266 | } |
| 267 | } |
| 268 | } |
| 269 | } |
Mike Lockwood | e29db6a | 2010-03-05 13:45:51 -0500 | [diff] [blame] | 270 | |
Daniel Sandler | 69a1da4 | 2011-11-04 15:08:30 -0400 | [diff] [blame] | 271 | final static boolean isDeskDockState(int state) { |
| 272 | switch (state) { |
| 273 | case Intent.EXTRA_DOCK_STATE_DESK: |
| 274 | case Intent.EXTRA_DOCK_STATE_LE_DESK: |
| 275 | case Intent.EXTRA_DOCK_STATE_HE_DESK: |
| 276 | return true; |
| 277 | default: |
| 278 | return false; |
| 279 | } |
| 280 | } |
| 281 | |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame^] | 282 | final void updateConfigurationLocked() { |
| 283 | int uiMode = mTelevision ? Configuration.UI_MODE_TYPE_TELEVISION : mDefaultUiModeType; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 284 | if (mCarModeEnabled) { |
| 285 | uiMode = Configuration.UI_MODE_TYPE_CAR; |
Daniel Sandler | 69a1da4 | 2011-11-04 15:08:30 -0400 | [diff] [blame] | 286 | } else if (isDeskDockState(mDockState)) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 287 | uiMode = Configuration.UI_MODE_TYPE_DESK; |
| 288 | } |
Dianne Hackborn | 9c9c532 | 2010-03-30 23:12:22 -0700 | [diff] [blame] | 289 | if (mCarModeEnabled) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 290 | if (mNightMode == UiModeManager.MODE_NIGHT_AUTO) { |
Jeff Brown | 2416e09 | 2012-08-21 22:12:20 -0700 | [diff] [blame] | 291 | updateComputedNightModeLocked(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 292 | uiMode |= mComputedNightMode ? Configuration.UI_MODE_NIGHT_YES |
| 293 | : Configuration.UI_MODE_NIGHT_NO; |
| 294 | } else { |
| 295 | uiMode |= mNightMode << 4; |
| 296 | } |
| 297 | } else { |
| 298 | // Disabling the car mode clears the night mode. |
Daniel Sandler | 8daf2a4 | 2010-04-02 10:15:09 -0400 | [diff] [blame] | 299 | uiMode = (uiMode & ~Configuration.UI_MODE_NIGHT_MASK) | Configuration.UI_MODE_NIGHT_NO; |
| 300 | } |
| 301 | |
| 302 | if (LOG) { |
John Spurlock | 960779d | 2012-05-29 14:37:05 -0400 | [diff] [blame] | 303 | Slog.d(TAG, |
| 304 | "updateConfigurationLocked: mDockState=" + mDockState |
Daniel Sandler | 8daf2a4 | 2010-04-02 10:15:09 -0400 | [diff] [blame] | 305 | + "; mCarMode=" + mCarModeEnabled |
| 306 | + "; mNightMode=" + mNightMode |
| 307 | + "; uiMode=" + uiMode); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 308 | } |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 309 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 310 | mCurUiMode = uiMode; |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame^] | 311 | if (!mHoldingConfiguration) { |
Dianne Hackborn | 2ccda4d | 2010-03-22 21:49:15 -0700 | [diff] [blame] | 312 | mConfiguration.uiMode = uiMode; |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame^] | 313 | } |
| 314 | } |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 315 | |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame^] | 316 | final void sendConfigurationLocked() { |
| 317 | if (mSetUiMode != mConfiguration.uiMode) { |
| 318 | mSetUiMode = mConfiguration.uiMode; |
| 319 | |
| 320 | try { |
| 321 | ActivityManagerNative.getDefault().updateConfiguration(mConfiguration); |
| 322 | } catch (RemoteException e) { |
| 323 | Slog.w(TAG, "Failure communicating with activity manager", e); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | } |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 327 | |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 328 | final void updateLocked(int enableFlags, int disableFlags) { |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 329 | long ident = Binder.clearCallingIdentity(); |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 330 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 331 | try { |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 332 | String action = null; |
| 333 | String oldAction = null; |
| 334 | if (mLastBroadcastState == Intent.EXTRA_DOCK_STATE_CAR) { |
Tobias Haamel | 780b260 | 2010-03-15 12:54:45 +0100 | [diff] [blame] | 335 | adjustStatusBarCarModeLocked(); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 336 | oldAction = UiModeManager.ACTION_EXIT_CAR_MODE; |
Daniel Sandler | 69a1da4 | 2011-11-04 15:08:30 -0400 | [diff] [blame] | 337 | } else if (isDeskDockState(mLastBroadcastState)) { |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 338 | oldAction = UiModeManager.ACTION_EXIT_DESK_MODE; |
| 339 | } |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 340 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 341 | if (mCarModeEnabled) { |
| 342 | if (mLastBroadcastState != Intent.EXTRA_DOCK_STATE_CAR) { |
| 343 | adjustStatusBarCarModeLocked(); |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 344 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 345 | if (oldAction != null) { |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 346 | mContext.sendBroadcastAsUser(new Intent(oldAction), UserHandle.ALL); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 347 | } |
| 348 | mLastBroadcastState = Intent.EXTRA_DOCK_STATE_CAR; |
| 349 | action = UiModeManager.ACTION_ENTER_CAR_MODE; |
| 350 | } |
Daniel Sandler | 69a1da4 | 2011-11-04 15:08:30 -0400 | [diff] [blame] | 351 | } else if (isDeskDockState(mDockState)) { |
| 352 | if (!isDeskDockState(mLastBroadcastState)) { |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 353 | if (oldAction != null) { |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 354 | mContext.sendBroadcastAsUser(new Intent(oldAction), UserHandle.ALL); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 355 | } |
Daniel Sandler | 69a1da4 | 2011-11-04 15:08:30 -0400 | [diff] [blame] | 356 | mLastBroadcastState = mDockState; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 357 | action = UiModeManager.ACTION_ENTER_DESK_MODE; |
| 358 | } |
| 359 | } else { |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 360 | mLastBroadcastState = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 361 | action = oldAction; |
| 362 | } |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 363 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 364 | if (action != null) { |
Daniel Sandler | 69a1da4 | 2011-11-04 15:08:30 -0400 | [diff] [blame] | 365 | if (LOG) { |
| 366 | Slog.v(TAG, String.format( |
| 367 | "updateLocked: preparing broadcast: action=%s enable=0x%08x disable=0x%08x", |
| 368 | action, enableFlags, disableFlags)); |
| 369 | } |
| 370 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 371 | // Send the ordered broadcast; the result receiver will receive after all |
| 372 | // broadcasts have been sent. If any broadcast receiver changes the result |
| 373 | // code from the initial value of RESULT_OK, then the result receiver will |
| 374 | // not launch the corresponding dock application. This gives apps a chance |
| 375 | // to override the behavior and stay in their app even when the device is |
| 376 | // placed into a dock. |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 377 | Intent intent = new Intent(action); |
| 378 | intent.putExtra("enableFlags", enableFlags); |
| 379 | intent.putExtra("disableFlags", disableFlags); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 380 | mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, null, |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 381 | mResultReceiver, null, Activity.RESULT_OK, null, null); |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame^] | 382 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 383 | // Attempting to make this transition a little more clean, we are going |
| 384 | // to hold off on doing a configuration change until we have finished |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 385 | // the broadcast and started the home activity. |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 386 | mHoldingConfiguration = true; |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame^] | 387 | updateConfigurationLocked(); |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 388 | } else { |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame^] | 389 | String category = null; |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 390 | if (mCarModeEnabled) { |
Daniel Sandler | 11ddf53 | 2011-11-16 11:10:03 -0800 | [diff] [blame] | 391 | if (ENABLE_LAUNCH_CAR_DOCK_APP |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame^] | 392 | && (enableFlags & UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) { |
| 393 | category = Intent.CATEGORY_CAR_DOCK; |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 394 | } |
Daniel Sandler | 69a1da4 | 2011-11-04 15:08:30 -0400 | [diff] [blame] | 395 | } else if (isDeskDockState(mDockState)) { |
Daniel Sandler | 11ddf53 | 2011-11-16 11:10:03 -0800 | [diff] [blame] | 396 | if (ENABLE_LAUNCH_DESK_DOCK_APP |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame^] | 397 | && (enableFlags & UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) { |
| 398 | category = Intent.CATEGORY_DESK_DOCK; |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 399 | } |
| 400 | } else { |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame^] | 401 | if ((disableFlags & UiModeManager.DISABLE_CAR_MODE_GO_HOME) != 0) { |
| 402 | category = Intent.CATEGORY_HOME; |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 403 | } |
| 404 | } |
Daniel Sandler | 69a1da4 | 2011-11-04 15:08:30 -0400 | [diff] [blame] | 405 | |
| 406 | if (LOG) { |
| 407 | Slog.v(TAG, "updateLocked: null action, mDockState=" |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame^] | 408 | + mDockState +", category=" + category); |
Daniel Sandler | 69a1da4 | 2011-11-04 15:08:30 -0400 | [diff] [blame] | 409 | } |
| 410 | |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame^] | 411 | sendConfigurationAndStartDreamOrDockAppLocked(category); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 412 | } |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 413 | |
Mike Lockwood | e29db6a | 2010-03-05 13:45:51 -0500 | [diff] [blame] | 414 | // keep screen on when charging and in car mode |
| 415 | boolean keepScreenOn = mCharging && |
| 416 | ((mCarModeEnabled && mCarModeKeepsScreenOn) || |
| 417 | (mCurUiMode == Configuration.UI_MODE_TYPE_DESK && mDeskModeKeepsScreenOn)); |
| 418 | if (keepScreenOn != mWakeLock.isHeld()) { |
| 419 | if (keepScreenOn) { |
| 420 | mWakeLock.acquire(); |
| 421 | } else { |
| 422 | mWakeLock.release(); |
| 423 | } |
| 424 | } |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 425 | } finally { |
| 426 | Binder.restoreCallingIdentity(ident); |
| 427 | } |
| 428 | } |
| 429 | |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame^] | 430 | private void updateAfterBroadcastLocked(String action, int enableFlags, int disableFlags) { |
| 431 | // Launch a dock activity |
| 432 | String category = null; |
| 433 | if (UiModeManager.ACTION_ENTER_CAR_MODE.equals(action)) { |
| 434 | // Only launch car home when car mode is enabled and the caller |
| 435 | // has asked us to switch to it. |
| 436 | if (ENABLE_LAUNCH_CAR_DOCK_APP |
| 437 | && (enableFlags & UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) { |
| 438 | category = Intent.CATEGORY_CAR_DOCK; |
| 439 | } |
| 440 | } else if (UiModeManager.ACTION_ENTER_DESK_MODE.equals(action)) { |
| 441 | // Only launch car home when desk mode is enabled and the caller |
| 442 | // has asked us to switch to it. Currently re-using the car |
| 443 | // mode flag since we don't have a formal API for "desk mode". |
| 444 | if (ENABLE_LAUNCH_DESK_DOCK_APP |
| 445 | && (enableFlags & UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) { |
| 446 | category = Intent.CATEGORY_DESK_DOCK; |
| 447 | } |
| 448 | } else { |
| 449 | // Launch the standard home app if requested. |
| 450 | if ((disableFlags & UiModeManager.DISABLE_CAR_MODE_GO_HOME) != 0) { |
| 451 | category = Intent.CATEGORY_HOME; |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | if (LOG) { |
| 456 | Slog.v(TAG, String.format( |
| 457 | "Handling broadcast result for action %s: enable=0x%08x, disable=0x%08x, " |
| 458 | + "category=%s", |
| 459 | action, enableFlags, disableFlags, category)); |
| 460 | } |
| 461 | |
| 462 | sendConfigurationAndStartDreamOrDockAppLocked(category); |
| 463 | } |
| 464 | |
| 465 | private void sendConfigurationAndStartDreamOrDockAppLocked(String category) { |
| 466 | // Update the configuration but don't send it yet. |
| 467 | mHoldingConfiguration = false; |
| 468 | updateConfigurationLocked(); |
| 469 | |
| 470 | // Start the dock app, if there is one. |
| 471 | boolean dockAppStarted = false; |
| 472 | if (category != null) { |
| 473 | // Now we are going to be careful about switching the |
| 474 | // configuration and starting the activity -- we need to |
| 475 | // do this in a specific order under control of the |
| 476 | // activity manager, to do it cleanly. So compute the |
| 477 | // new config, but don't set it yet, and let the |
| 478 | // activity manager take care of both the start and config |
| 479 | // change. |
| 480 | Intent homeIntent = buildHomeIntent(category); |
| 481 | try { |
| 482 | int result = ActivityManagerNative.getDefault().startActivityWithConfig( |
| 483 | null, homeIntent, null, null, null, 0, 0, |
| 484 | mConfiguration, null, UserHandle.USER_CURRENT); |
| 485 | if (result >= ActivityManager.START_SUCCESS) { |
| 486 | dockAppStarted = true; |
| 487 | } else if (result != ActivityManager.START_INTENT_NOT_RESOLVED) { |
| 488 | Slog.e(TAG, "Could not start dock app: " + homeIntent |
| 489 | + ", startActivityWithConfig result " + result); |
| 490 | } |
| 491 | } catch (RemoteException ex) { |
| 492 | Slog.e(TAG, "Could not start dock app: " + homeIntent, ex); |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | // Send the new configuration. |
| 497 | sendConfigurationLocked(); |
| 498 | |
| 499 | // If we did not start a dock app, then start dreaming if supported. |
| 500 | if (!dockAppStarted && isScreenSaverEnabled() && isScreenSaverActivatedOnDock()) { |
| 501 | Slog.i(TAG, "Activating dream while docked."); |
| 502 | try { |
| 503 | IDreamManager dreamManagerService = IDreamManager.Stub.asInterface( |
| 504 | ServiceManager.getService(Dream.DREAM_SERVICE)); |
| 505 | dreamManagerService.dream(); |
| 506 | } catch (RemoteException ex) { |
| 507 | Slog.e(TAG, "Could not start dream when docked.", ex); |
| 508 | } |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | private boolean isScreenSaverEnabled() { |
| 513 | return Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 514 | Settings.Secure.SCREENSAVER_ENABLED, DEFAULT_SCREENSAVER_ENABLED, |
| 515 | UserHandle.USER_CURRENT) != 0; |
| 516 | } |
| 517 | |
| 518 | private boolean isScreenSaverActivatedOnDock() { |
| 519 | return Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 520 | Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK, |
| 521 | DEFAULT_SCREENSAVER_ACTIVATED_ON_DOCK, UserHandle.USER_CURRENT) != 0; |
| 522 | } |
| 523 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 524 | private void adjustStatusBarCarModeLocked() { |
| 525 | if (mStatusBarManager == null) { |
| 526 | mStatusBarManager = (StatusBarManager) mContext.getSystemService(Context.STATUS_BAR_SERVICE); |
| 527 | } |
| 528 | |
Joe Onorato | 089de88 | 2010-04-12 08:18:45 -0700 | [diff] [blame] | 529 | // Fear not: StatusBarManagerService manages a list of requests to disable |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 530 | // features of the status bar; these are ORed together to form the |
| 531 | // active disabled list. So if (for example) the device is locked and |
| 532 | // the status bar should be totally disabled, the calls below will |
| 533 | // have no effect until the device is unlocked. |
| 534 | if (mStatusBarManager != null) { |
| 535 | mStatusBarManager.disable(mCarModeEnabled |
| 536 | ? StatusBarManager.DISABLE_NOTIFICATION_TICKER |
| 537 | : StatusBarManager.DISABLE_NONE); |
| 538 | } |
| 539 | |
| 540 | if (mNotificationManager == null) { |
| 541 | mNotificationManager = (NotificationManager) |
| 542 | mContext.getSystemService(Context.NOTIFICATION_SERVICE); |
| 543 | } |
| 544 | |
| 545 | if (mNotificationManager != null) { |
| 546 | if (mCarModeEnabled) { |
| 547 | Intent carModeOffIntent = new Intent(mContext, DisableCarModeActivity.class); |
| 548 | |
| 549 | Notification n = new Notification(); |
| 550 | n.icon = R.drawable.stat_notify_car_mode; |
| 551 | n.defaults = Notification.DEFAULT_LIGHTS; |
| 552 | n.flags = Notification.FLAG_ONGOING_EVENT; |
| 553 | n.when = 0; |
| 554 | n.setLatestEventInfo( |
| 555 | mContext, |
| 556 | mContext.getString(R.string.car_mode_disable_notification_title), |
| 557 | mContext.getString(R.string.car_mode_disable_notification_message), |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 558 | PendingIntent.getActivityAsUser(mContext, 0, carModeOffIntent, 0, |
| 559 | null, UserHandle.CURRENT)); |
| 560 | mNotificationManager.notifyAsUser(null, |
| 561 | R.string.car_mode_disable_notification_title, n, UserHandle.ALL); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 562 | } else { |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 563 | mNotificationManager.cancelAsUser(null, |
| 564 | R.string.car_mode_disable_notification_title, UserHandle.ALL); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 565 | } |
| 566 | } |
| 567 | } |
| 568 | |
Jeff Brown | 2416e09 | 2012-08-21 22:12:20 -0700 | [diff] [blame] | 569 | private void updateTwilight() { |
| 570 | synchronized (mLock) { |
| 571 | if (isDoingNightMode() && mNightMode == UiModeManager.MODE_NIGHT_AUTO) { |
| 572 | updateComputedNightModeLocked(); |
| 573 | updateLocked(0, 0); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 574 | } |
| 575 | } |
Jeff Brown | 2416e09 | 2012-08-21 22:12:20 -0700 | [diff] [blame] | 576 | } |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 577 | |
Jeff Brown | 2416e09 | 2012-08-21 22:12:20 -0700 | [diff] [blame] | 578 | private void updateComputedNightModeLocked() { |
| 579 | TwilightState state = mTwilightService.getCurrentState(); |
| 580 | if (state != null) { |
| 581 | mComputedNightMode = state.isNight(); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 582 | } |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 583 | } |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 584 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 585 | @Override |
| 586 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 587 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 588 | != PackageManager.PERMISSION_GRANTED) { |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 589 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 590 | pw.println("Permission Denial: can't dump uimode service from from pid=" |
| 591 | + Binder.getCallingPid() |
| 592 | + ", uid=" + Binder.getCallingUid()); |
| 593 | return; |
| 594 | } |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 595 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 596 | synchronized (mLock) { |
| 597 | pw.println("Current UI Mode Service state:"); |
| 598 | pw.print(" mDockState="); pw.print(mDockState); |
| 599 | pw.print(" mLastBroadcastState="); pw.println(mLastBroadcastState); |
| 600 | pw.print(" mNightMode="); pw.print(mNightMode); |
| 601 | pw.print(" mCarModeEnabled="); pw.print(mCarModeEnabled); |
| 602 | pw.print(" mComputedNightMode="); pw.println(mComputedNightMode); |
| 603 | pw.print(" mCurUiMode=0x"); pw.print(Integer.toHexString(mCurUiMode)); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 604 | pw.print(" mSetUiMode=0x"); pw.println(Integer.toHexString(mSetUiMode)); |
| 605 | pw.print(" mHoldingConfiguration="); pw.print(mHoldingConfiguration); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 606 | pw.print(" mSystemReady="); pw.println(mSystemReady); |
Jeff Brown | 2416e09 | 2012-08-21 22:12:20 -0700 | [diff] [blame] | 607 | pw.print(" mTwilightService.getCurrentState()="); |
| 608 | pw.println(mTwilightService.getCurrentState()); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 609 | } |
| 610 | } |
| 611 | } |