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