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 | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 28 | import android.content.BroadcastReceiver; |
| 29 | import android.content.Context; |
| 30 | import android.content.Intent; |
| 31 | import android.content.IntentFilter; |
| 32 | import android.content.pm.PackageManager; |
| 33 | import android.content.res.Configuration; |
Mike Lockwood | e29db6a | 2010-03-05 13:45:51 -0500 | [diff] [blame] | 34 | import android.os.BatteryManager; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 35 | import android.os.Binder; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 36 | import android.os.Handler; |
Mike Lockwood | e29db6a | 2010-03-05 13:45:51 -0500 | [diff] [blame] | 37 | import android.os.PowerManager; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 38 | import android.os.RemoteException; |
| 39 | import android.os.ServiceManager; |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 40 | import android.os.UserHandle; |
Dianne Hackborn | 2ccda4d | 2010-03-22 21:49:15 -0700 | [diff] [blame] | 41 | import android.provider.Settings; |
Dianne Hackborn | be87e2f | 2012-09-28 16:31:34 -0700 | [diff] [blame] | 42 | import android.service.dreams.DreamService; |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 43 | import android.service.dreams.IDreamManager; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 44 | import android.util.Slog; |
| 45 | |
| 46 | import java.io.FileDescriptor; |
| 47 | import java.io.PrintWriter; |
| 48 | |
| 49 | import com.android.internal.R; |
| 50 | import com.android.internal.app.DisableCarModeActivity; |
Jeff Brown | 2416e09 | 2012-08-21 22:12:20 -0700 | [diff] [blame] | 51 | import com.android.server.TwilightService.TwilightState; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 52 | |
| 53 | class UiModeManagerService extends IUiModeManager.Stub { |
| 54 | private static final String TAG = UiModeManager.class.getSimpleName(); |
| 55 | private static final boolean LOG = false; |
| 56 | |
Daniel Sandler | 11ddf53 | 2011-11-16 11:10:03 -0800 | [diff] [blame] | 57 | // Enable launching of applications when entering the dock. |
| 58 | private static final boolean ENABLE_LAUNCH_CAR_DOCK_APP = true; |
John Spurlock | 960779d | 2012-05-29 14:37:05 -0400 | [diff] [blame] | 59 | private static final boolean ENABLE_LAUNCH_DESK_DOCK_APP = true; |
Daniel Sandler | 11ddf53 | 2011-11-16 11:10:03 -0800 | [diff] [blame] | 60 | |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 61 | private static final int DEFAULT_SCREENSAVER_ENABLED = 1; |
| 62 | private static final int DEFAULT_SCREENSAVER_ACTIVATED_ON_DOCK = 1; |
| 63 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 64 | private final Context mContext; |
Jeff Brown | 2416e09 | 2012-08-21 22:12:20 -0700 | [diff] [blame] | 65 | private final TwilightService mTwilightService; |
| 66 | private final Handler mHandler = new Handler(); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 67 | |
| 68 | final Object mLock = new Object(); |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 69 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 70 | private int mDockState = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 71 | private int mLastBroadcastState = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 72 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 73 | private int mNightMode = UiModeManager.MODE_NIGHT_NO; |
| 74 | private boolean mCarModeEnabled = false; |
Mike Lockwood | e29db6a | 2010-03-05 13:45:51 -0500 | [diff] [blame] | 75 | private boolean mCharging = false; |
Joe Onorato | 44fcb83 | 2011-12-14 20:59:30 -0800 | [diff] [blame] | 76 | private final int mDefaultUiModeType; |
Mike Lockwood | e29db6a | 2010-03-05 13:45:51 -0500 | [diff] [blame] | 77 | private final boolean mCarModeKeepsScreenOn; |
| 78 | private final boolean mDeskModeKeepsScreenOn; |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 79 | private final boolean mTelevision; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 80 | |
| 81 | private boolean mComputedNightMode; |
| 82 | private int mCurUiMode = 0; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 83 | private int mSetUiMode = 0; |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 84 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 85 | private boolean mHoldingConfiguration = false; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 86 | private Configuration mConfiguration = new Configuration(); |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 87 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 88 | private boolean mSystemReady; |
| 89 | |
| 90 | private NotificationManager mNotificationManager; |
| 91 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 92 | private StatusBarManager mStatusBarManager; |
Mike Lockwood | e29db6a | 2010-03-05 13:45:51 -0500 | [diff] [blame] | 93 | private final PowerManager.WakeLock mWakeLock; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 94 | |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 95 | static Intent buildHomeIntent(String category) { |
| 96 | Intent intent = new Intent(Intent.ACTION_MAIN); |
| 97 | intent.addCategory(category); |
| 98 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 99 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 100 | return intent; |
| 101 | } |
John Spurlock | 960779d | 2012-05-29 14:37:05 -0400 | [diff] [blame] | 102 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 103 | // The broadcast receiver which receives the result of the ordered broadcast sent when |
| 104 | // the dock state changes. The original ordered broadcast is sent with an initial result |
| 105 | // code of RESULT_OK. If any of the registered broadcast receivers changes this value, e.g., |
| 106 | // to RESULT_CANCELED, then the intent to start a dock app will not be sent. |
| 107 | private final BroadcastReceiver mResultReceiver = new BroadcastReceiver() { |
| 108 | @Override |
| 109 | public void onReceive(Context context, Intent intent) { |
| 110 | if (getResultCode() != Activity.RESULT_OK) { |
Daniel Sandler | 69a1da4 | 2011-11-04 15:08:30 -0400 | [diff] [blame] | 111 | if (LOG) { |
John Spurlock | 960779d | 2012-05-29 14:37:05 -0400 | [diff] [blame] | 112 | Slog.v(TAG, "Handling broadcast result for action " + intent.getAction() |
Daniel Sandler | 69a1da4 | 2011-11-04 15:08:30 -0400 | [diff] [blame] | 113 | + ": canceled: " + getResultCode()); |
| 114 | } |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 115 | return; |
| 116 | } |
| 117 | |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 118 | final int enableFlags = intent.getIntExtra("enableFlags", 0); |
| 119 | final int disableFlags = intent.getIntExtra("disableFlags", 0); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 120 | synchronized (mLock) { |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 121 | updateAfterBroadcastLocked(intent.getAction(), enableFlags, disableFlags); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | }; |
| 125 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 126 | private final BroadcastReceiver mDockModeReceiver = new BroadcastReceiver() { |
| 127 | @Override |
| 128 | public void onReceive(Context context, Intent intent) { |
| 129 | int state = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 130 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 131 | updateDockState(state); |
| 132 | } |
| 133 | }; |
| 134 | |
Mike Lockwood | e29db6a | 2010-03-05 13:45:51 -0500 | [diff] [blame] | 135 | private final BroadcastReceiver mBatteryReceiver = new BroadcastReceiver() { |
| 136 | @Override |
| 137 | public void onReceive(Context context, Intent intent) { |
| 138 | mCharging = (intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0); |
| 139 | synchronized (mLock) { |
| 140 | if (mSystemReady) { |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 141 | updateLocked(0, 0); |
Mike Lockwood | e29db6a | 2010-03-05 13:45:51 -0500 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | } |
| 145 | }; |
| 146 | |
Jeff Brown | 2416e09 | 2012-08-21 22:12:20 -0700 | [diff] [blame] | 147 | private final TwilightService.TwilightListener mTwilightListener = |
| 148 | new TwilightService.TwilightListener() { |
Dianne Hackborn | 57f4503 | 2010-06-17 15:49:33 -0700 | [diff] [blame] | 149 | @Override |
Jeff Brown | 2416e09 | 2012-08-21 22:12:20 -0700 | [diff] [blame] | 150 | public void onTwilightStateChanged() { |
| 151 | updateTwilight(); |
Dianne Hackborn | 57f4503 | 2010-06-17 15:49:33 -0700 | [diff] [blame] | 152 | } |
| 153 | }; |
| 154 | |
Jeff Brown | 2416e09 | 2012-08-21 22:12:20 -0700 | [diff] [blame] | 155 | public UiModeManagerService(Context context, TwilightService twilight) { |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 156 | mContext = context; |
Jeff Brown | 2416e09 | 2012-08-21 22:12:20 -0700 | [diff] [blame] | 157 | mTwilightService = twilight; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 158 | |
| 159 | ServiceManager.addService(Context.UI_MODE_SERVICE, this); |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 160 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 161 | mContext.registerReceiver(mDockModeReceiver, |
| 162 | new IntentFilter(Intent.ACTION_DOCK_EVENT)); |
Mike Lockwood | e29db6a | 2010-03-05 13:45:51 -0500 | [diff] [blame] | 163 | mContext.registerReceiver(mBatteryReceiver, |
| 164 | new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); |
| 165 | |
| 166 | PowerManager powerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 167 | mWakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, TAG); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 168 | |
| 169 | mConfiguration.setToDefaults(); |
Mike Lockwood | e29db6a | 2010-03-05 13:45:51 -0500 | [diff] [blame] | 170 | |
Joe Onorato | 44fcb83 | 2011-12-14 20:59:30 -0800 | [diff] [blame] | 171 | mDefaultUiModeType = context.getResources().getInteger( |
| 172 | com.android.internal.R.integer.config_defaultUiModeType); |
Mike Lockwood | e29db6a | 2010-03-05 13:45:51 -0500 | [diff] [blame] | 173 | mCarModeKeepsScreenOn = (context.getResources().getInteger( |
| 174 | com.android.internal.R.integer.config_carDockKeepsScreenOn) == 1); |
| 175 | mDeskModeKeepsScreenOn = (context.getResources().getInteger( |
| 176 | com.android.internal.R.integer.config_deskDockKeepsScreenOn) == 1); |
Dianne Hackborn | 0cf2c8a | 2012-05-17 17:29:49 -0700 | [diff] [blame] | 177 | mTelevision = context.getPackageManager().hasSystemFeature( |
| 178 | PackageManager.FEATURE_TELEVISION); |
| 179 | |
Dianne Hackborn | 2ccda4d | 2010-03-22 21:49:15 -0700 | [diff] [blame] | 180 | mNightMode = Settings.Secure.getInt(mContext.getContentResolver(), |
| 181 | Settings.Secure.UI_NIGHT_MODE, UiModeManager.MODE_NIGHT_AUTO); |
Jeff Brown | 2416e09 | 2012-08-21 22:12:20 -0700 | [diff] [blame] | 182 | |
| 183 | mTwilightService.registerListener(mTwilightListener, mHandler); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 184 | } |
| 185 | |
Dianne Hackborn | d49258f | 2010-03-26 00:44:29 -0700 | [diff] [blame] | 186 | public void disableCarMode(int flags) { |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 187 | synchronized (mLock) { |
| 188 | setCarModeLocked(false); |
Mike Lockwood | 924e164 | 2010-03-05 11:56:53 -0500 | [diff] [blame] | 189 | if (mSystemReady) { |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 190 | updateLocked(0, flags); |
Mike Lockwood | 924e164 | 2010-03-05 11:56:53 -0500 | [diff] [blame] | 191 | } |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 192 | } |
| 193 | } |
| 194 | |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 195 | public void enableCarMode(int flags) { |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 196 | synchronized (mLock) { |
| 197 | setCarModeLocked(true); |
Mike Lockwood | 924e164 | 2010-03-05 11:56:53 -0500 | [diff] [blame] | 198 | if (mSystemReady) { |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 199 | updateLocked(flags, 0); |
Mike Lockwood | 924e164 | 2010-03-05 11:56:53 -0500 | [diff] [blame] | 200 | } |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | |
| 204 | public int getCurrentModeType() { |
| 205 | synchronized (mLock) { |
| 206 | return mCurUiMode & Configuration.UI_MODE_TYPE_MASK; |
| 207 | } |
| 208 | } |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 209 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 210 | public void setNightMode(int mode) throws RemoteException { |
| 211 | synchronized (mLock) { |
| 212 | switch (mode) { |
| 213 | case UiModeManager.MODE_NIGHT_NO: |
| 214 | case UiModeManager.MODE_NIGHT_YES: |
| 215 | case UiModeManager.MODE_NIGHT_AUTO: |
| 216 | break; |
| 217 | default: |
| 218 | throw new IllegalArgumentException("Unknown mode: " + mode); |
| 219 | } |
| 220 | if (!isDoingNightMode()) { |
| 221 | return; |
| 222 | } |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 223 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 224 | if (mNightMode != mode) { |
Dianne Hackborn | 2ccda4d | 2010-03-22 21:49:15 -0700 | [diff] [blame] | 225 | long ident = Binder.clearCallingIdentity(); |
| 226 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 227 | Settings.Secure.UI_NIGHT_MODE, mode); |
| 228 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 229 | mNightMode = mode; |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 230 | updateLocked(0, 0); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | } |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 234 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 235 | public int getNightMode() throws RemoteException { |
| 236 | return mNightMode; |
| 237 | } |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 238 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 239 | void systemReady() { |
| 240 | synchronized (mLock) { |
| 241 | mSystemReady = true; |
| 242 | mCarModeEnabled = mDockState == Intent.EXTRA_DOCK_STATE_CAR; |
Jeff Brown | 2416e09 | 2012-08-21 22:12:20 -0700 | [diff] [blame] | 243 | updateComputedNightModeLocked(); |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 244 | updateLocked(0, 0); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 245 | } |
| 246 | } |
| 247 | |
| 248 | boolean isDoingNightMode() { |
| 249 | return mCarModeEnabled || mDockState != Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 250 | } |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 251 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 252 | void setCarModeLocked(boolean enabled) { |
| 253 | if (mCarModeEnabled != enabled) { |
| 254 | mCarModeEnabled = enabled; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | |
| 258 | void updateDockState(int newState) { |
| 259 | synchronized (mLock) { |
| 260 | if (newState != mDockState) { |
| 261 | mDockState = newState; |
Mike Lockwood | 924e164 | 2010-03-05 11:56:53 -0500 | [diff] [blame] | 262 | setCarModeLocked(mDockState == Intent.EXTRA_DOCK_STATE_CAR); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 263 | if (mSystemReady) { |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 264 | updateLocked(UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME, 0); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | } |
| 268 | } |
Mike Lockwood | e29db6a | 2010-03-05 13:45:51 -0500 | [diff] [blame] | 269 | |
Daniel Sandler | 69a1da4 | 2011-11-04 15:08:30 -0400 | [diff] [blame] | 270 | final static boolean isDeskDockState(int state) { |
| 271 | switch (state) { |
| 272 | case Intent.EXTRA_DOCK_STATE_DESK: |
| 273 | case Intent.EXTRA_DOCK_STATE_LE_DESK: |
| 274 | case Intent.EXTRA_DOCK_STATE_HE_DESK: |
| 275 | return true; |
| 276 | default: |
| 277 | return false; |
| 278 | } |
| 279 | } |
| 280 | |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 281 | final void updateConfigurationLocked() { |
| 282 | int uiMode = mTelevision ? Configuration.UI_MODE_TYPE_TELEVISION : mDefaultUiModeType; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 283 | if (mCarModeEnabled) { |
| 284 | uiMode = Configuration.UI_MODE_TYPE_CAR; |
Daniel Sandler | 69a1da4 | 2011-11-04 15:08:30 -0400 | [diff] [blame] | 285 | } else if (isDeskDockState(mDockState)) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 286 | uiMode = Configuration.UI_MODE_TYPE_DESK; |
| 287 | } |
Dianne Hackborn | 9c9c532 | 2010-03-30 23:12:22 -0700 | [diff] [blame] | 288 | if (mCarModeEnabled) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 289 | if (mNightMode == UiModeManager.MODE_NIGHT_AUTO) { |
Jeff Brown | 2416e09 | 2012-08-21 22:12:20 -0700 | [diff] [blame] | 290 | updateComputedNightModeLocked(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 291 | uiMode |= mComputedNightMode ? Configuration.UI_MODE_NIGHT_YES |
| 292 | : Configuration.UI_MODE_NIGHT_NO; |
| 293 | } else { |
| 294 | uiMode |= mNightMode << 4; |
| 295 | } |
| 296 | } else { |
| 297 | // Disabling the car mode clears the night mode. |
Daniel Sandler | 8daf2a4 | 2010-04-02 10:15:09 -0400 | [diff] [blame] | 298 | uiMode = (uiMode & ~Configuration.UI_MODE_NIGHT_MASK) | Configuration.UI_MODE_NIGHT_NO; |
| 299 | } |
| 300 | |
| 301 | if (LOG) { |
John Spurlock | 960779d | 2012-05-29 14:37:05 -0400 | [diff] [blame] | 302 | Slog.d(TAG, |
| 303 | "updateConfigurationLocked: mDockState=" + mDockState |
Daniel Sandler | 8daf2a4 | 2010-04-02 10:15:09 -0400 | [diff] [blame] | 304 | + "; mCarMode=" + mCarModeEnabled |
| 305 | + "; mNightMode=" + mNightMode |
| 306 | + "; uiMode=" + uiMode); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 307 | } |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 308 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 309 | mCurUiMode = uiMode; |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 310 | if (!mHoldingConfiguration) { |
Dianne Hackborn | 2ccda4d | 2010-03-22 21:49:15 -0700 | [diff] [blame] | 311 | mConfiguration.uiMode = uiMode; |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 312 | } |
| 313 | } |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 314 | |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 315 | final void sendConfigurationLocked() { |
| 316 | if (mSetUiMode != mConfiguration.uiMode) { |
| 317 | mSetUiMode = mConfiguration.uiMode; |
| 318 | |
| 319 | try { |
| 320 | ActivityManagerNative.getDefault().updateConfiguration(mConfiguration); |
| 321 | } catch (RemoteException e) { |
| 322 | Slog.w(TAG, "Failure communicating with activity manager", e); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | } |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 326 | |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 327 | final void updateLocked(int enableFlags, int disableFlags) { |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 328 | long ident = Binder.clearCallingIdentity(); |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 329 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 330 | try { |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 331 | String action = null; |
| 332 | String oldAction = null; |
| 333 | if (mLastBroadcastState == Intent.EXTRA_DOCK_STATE_CAR) { |
Tobias Haamel | 780b260 | 2010-03-15 12:54:45 +0100 | [diff] [blame] | 334 | adjustStatusBarCarModeLocked(); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 335 | oldAction = UiModeManager.ACTION_EXIT_CAR_MODE; |
Daniel Sandler | 69a1da4 | 2011-11-04 15:08:30 -0400 | [diff] [blame] | 336 | } else if (isDeskDockState(mLastBroadcastState)) { |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 337 | oldAction = UiModeManager.ACTION_EXIT_DESK_MODE; |
| 338 | } |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 339 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 340 | if (mCarModeEnabled) { |
| 341 | if (mLastBroadcastState != Intent.EXTRA_DOCK_STATE_CAR) { |
| 342 | adjustStatusBarCarModeLocked(); |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 343 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 344 | if (oldAction != null) { |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 345 | mContext.sendBroadcastAsUser(new Intent(oldAction), UserHandle.ALL); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 346 | } |
| 347 | mLastBroadcastState = Intent.EXTRA_DOCK_STATE_CAR; |
| 348 | action = UiModeManager.ACTION_ENTER_CAR_MODE; |
| 349 | } |
Daniel Sandler | 69a1da4 | 2011-11-04 15:08:30 -0400 | [diff] [blame] | 350 | } else if (isDeskDockState(mDockState)) { |
| 351 | if (!isDeskDockState(mLastBroadcastState)) { |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 352 | if (oldAction != null) { |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 353 | mContext.sendBroadcastAsUser(new Intent(oldAction), UserHandle.ALL); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 354 | } |
Daniel Sandler | 69a1da4 | 2011-11-04 15:08:30 -0400 | [diff] [blame] | 355 | mLastBroadcastState = mDockState; |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 356 | action = UiModeManager.ACTION_ENTER_DESK_MODE; |
| 357 | } |
| 358 | } else { |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 359 | mLastBroadcastState = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 360 | action = oldAction; |
| 361 | } |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 362 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 363 | if (action != null) { |
Daniel Sandler | 69a1da4 | 2011-11-04 15:08:30 -0400 | [diff] [blame] | 364 | if (LOG) { |
| 365 | Slog.v(TAG, String.format( |
| 366 | "updateLocked: preparing broadcast: action=%s enable=0x%08x disable=0x%08x", |
| 367 | action, enableFlags, disableFlags)); |
| 368 | } |
| 369 | |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 370 | // Send the ordered broadcast; the result receiver will receive after all |
| 371 | // broadcasts have been sent. If any broadcast receiver changes the result |
| 372 | // code from the initial value of RESULT_OK, then the result receiver will |
| 373 | // not launch the corresponding dock application. This gives apps a chance |
| 374 | // to override the behavior and stay in their app even when the device is |
| 375 | // placed into a dock. |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 376 | Intent intent = new Intent(action); |
| 377 | intent.putExtra("enableFlags", enableFlags); |
| 378 | intent.putExtra("disableFlags", disableFlags); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 379 | mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, null, |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 380 | mResultReceiver, null, Activity.RESULT_OK, null, null); |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 381 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 382 | // Attempting to make this transition a little more clean, we are going |
| 383 | // to hold off on doing a configuration change until we have finished |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 384 | // the broadcast and started the home activity. |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 385 | mHoldingConfiguration = true; |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 386 | updateConfigurationLocked(); |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 387 | } else { |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 388 | String category = null; |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 389 | if (mCarModeEnabled) { |
Daniel Sandler | 11ddf53 | 2011-11-16 11:10:03 -0800 | [diff] [blame] | 390 | if (ENABLE_LAUNCH_CAR_DOCK_APP |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 391 | && (enableFlags & UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) { |
| 392 | category = Intent.CATEGORY_CAR_DOCK; |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 393 | } |
Daniel Sandler | 69a1da4 | 2011-11-04 15:08:30 -0400 | [diff] [blame] | 394 | } else if (isDeskDockState(mDockState)) { |
Daniel Sandler | 11ddf53 | 2011-11-16 11:10:03 -0800 | [diff] [blame] | 395 | if (ENABLE_LAUNCH_DESK_DOCK_APP |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 396 | && (enableFlags & UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) { |
| 397 | category = Intent.CATEGORY_DESK_DOCK; |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 398 | } |
| 399 | } else { |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 400 | if ((disableFlags & UiModeManager.DISABLE_CAR_MODE_GO_HOME) != 0) { |
| 401 | category = Intent.CATEGORY_HOME; |
Dianne Hackborn | f5c5d22 | 2010-04-09 13:14:48 -0700 | [diff] [blame] | 402 | } |
| 403 | } |
Daniel Sandler | 69a1da4 | 2011-11-04 15:08:30 -0400 | [diff] [blame] | 404 | |
| 405 | if (LOG) { |
| 406 | Slog.v(TAG, "updateLocked: null action, mDockState=" |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 407 | + mDockState +", category=" + category); |
Daniel Sandler | 69a1da4 | 2011-11-04 15:08:30 -0400 | [diff] [blame] | 408 | } |
| 409 | |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 410 | sendConfigurationAndStartDreamOrDockAppLocked(category); |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 411 | } |
Bernd Holzhey | ba9ab18 | 2010-03-12 09:30:29 +0100 | [diff] [blame] | 412 | |
Mike Lockwood | e29db6a | 2010-03-05 13:45:51 -0500 | [diff] [blame] | 413 | // keep screen on when charging and in car mode |
| 414 | boolean keepScreenOn = mCharging && |
| 415 | ((mCarModeEnabled && mCarModeKeepsScreenOn) || |
| 416 | (mCurUiMode == Configuration.UI_MODE_TYPE_DESK && mDeskModeKeepsScreenOn)); |
| 417 | if (keepScreenOn != mWakeLock.isHeld()) { |
| 418 | if (keepScreenOn) { |
| 419 | mWakeLock.acquire(); |
| 420 | } else { |
| 421 | mWakeLock.release(); |
| 422 | } |
| 423 | } |
Dianne Hackborn | 7299c41 | 2010-03-04 18:41:49 -0800 | [diff] [blame] | 424 | } finally { |
| 425 | Binder.restoreCallingIdentity(ident); |
| 426 | } |
| 427 | } |
| 428 | |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 429 | private void updateAfterBroadcastLocked(String action, int enableFlags, int disableFlags) { |
| 430 | // Launch a dock activity |
| 431 | String category = null; |
| 432 | if (UiModeManager.ACTION_ENTER_CAR_MODE.equals(action)) { |
| 433 | // Only launch car home when car mode is enabled and the caller |
| 434 | // has asked us to switch to it. |
| 435 | if (ENABLE_LAUNCH_CAR_DOCK_APP |
| 436 | && (enableFlags & UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) { |
| 437 | category = Intent.CATEGORY_CAR_DOCK; |
| 438 | } |
| 439 | } else if (UiModeManager.ACTION_ENTER_DESK_MODE.equals(action)) { |
| 440 | // Only launch car home when desk mode is enabled and the caller |
| 441 | // has asked us to switch to it. Currently re-using the car |
| 442 | // mode flag since we don't have a formal API for "desk mode". |
| 443 | if (ENABLE_LAUNCH_DESK_DOCK_APP |
| 444 | && (enableFlags & UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) { |
| 445 | category = Intent.CATEGORY_DESK_DOCK; |
| 446 | } |
| 447 | } else { |
| 448 | // Launch the standard home app if requested. |
| 449 | if ((disableFlags & UiModeManager.DISABLE_CAR_MODE_GO_HOME) != 0) { |
| 450 | category = Intent.CATEGORY_HOME; |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | if (LOG) { |
| 455 | Slog.v(TAG, String.format( |
| 456 | "Handling broadcast result for action %s: enable=0x%08x, disable=0x%08x, " |
| 457 | + "category=%s", |
| 458 | action, enableFlags, disableFlags, category)); |
| 459 | } |
| 460 | |
| 461 | sendConfigurationAndStartDreamOrDockAppLocked(category); |
| 462 | } |
| 463 | |
| 464 | private void sendConfigurationAndStartDreamOrDockAppLocked(String category) { |
| 465 | // Update the configuration but don't send it yet. |
| 466 | mHoldingConfiguration = false; |
| 467 | updateConfigurationLocked(); |
| 468 | |
| 469 | // Start the dock app, if there is one. |
| 470 | boolean dockAppStarted = false; |
| 471 | if (category != null) { |
| 472 | // Now we are going to be careful about switching the |
| 473 | // configuration and starting the activity -- we need to |
| 474 | // do this in a specific order under control of the |
| 475 | // activity manager, to do it cleanly. So compute the |
| 476 | // new config, but don't set it yet, and let the |
| 477 | // activity manager take care of both the start and config |
| 478 | // change. |
| 479 | Intent homeIntent = buildHomeIntent(category); |
| 480 | try { |
| 481 | int result = ActivityManagerNative.getDefault().startActivityWithConfig( |
| 482 | null, homeIntent, null, null, null, 0, 0, |
| 483 | mConfiguration, null, UserHandle.USER_CURRENT); |
| 484 | if (result >= ActivityManager.START_SUCCESS) { |
| 485 | dockAppStarted = true; |
| 486 | } else if (result != ActivityManager.START_INTENT_NOT_RESOLVED) { |
| 487 | Slog.e(TAG, "Could not start dock app: " + homeIntent |
| 488 | + ", startActivityWithConfig result " + result); |
| 489 | } |
| 490 | } catch (RemoteException ex) { |
| 491 | Slog.e(TAG, "Could not start dock app: " + homeIntent, ex); |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | // Send the new configuration. |
| 496 | sendConfigurationLocked(); |
| 497 | |
| 498 | // If we did not start a dock app, then start dreaming if supported. |
Jeff Brown | f9d40f4 | 2012-09-26 18:57:48 -0700 | [diff] [blame] | 499 | if (category != null && !dockAppStarted |
| 500 | && isScreenSaverEnabled() && isScreenSaverActivatedOnDock()) { |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 501 | Slog.i(TAG, "Activating dream while docked."); |
| 502 | try { |
| 503 | IDreamManager dreamManagerService = IDreamManager.Stub.asInterface( |
Dianne Hackborn | be87e2f | 2012-09-28 16:31:34 -0700 | [diff] [blame] | 504 | ServiceManager.getService(DreamService.DREAM_SERVICE)); |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 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 | } |