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