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