John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | |
Jeff Brown | cef440f | 2012-09-25 18:58:48 -0700 | [diff] [blame] | 17 | package com.android.server.dreams; |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 18 | |
John Spurlock | eb8d1be | 2014-06-25 17:46:15 -0400 | [diff] [blame] | 19 | import static android.Manifest.permission.BIND_DREAM_SERVICE; |
| 20 | |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 21 | import com.android.internal.util.DumpUtils; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 22 | import com.android.server.FgThread; |
Jeff Brown | 567f7ca | 2014-01-30 23:38:03 -0800 | [diff] [blame] | 23 | import com.android.server.SystemService; |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 24 | |
Jeff Brown | 567f7ca | 2014-01-30 23:38:03 -0800 | [diff] [blame] | 25 | import android.Manifest; |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 26 | import android.app.ActivityManager; |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 27 | import android.content.BroadcastReceiver; |
| 28 | import android.content.ComponentName; |
| 29 | import android.content.Context; |
| 30 | import android.content.Intent; |
| 31 | import android.content.IntentFilter; |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 32 | import android.content.pm.PackageManager; |
John Spurlock | bbdb062 | 2012-12-10 18:15:07 -0500 | [diff] [blame] | 33 | import android.content.pm.PackageManager.NameNotFoundException; |
John Spurlock | eb8d1be | 2014-06-25 17:46:15 -0400 | [diff] [blame] | 34 | import android.content.pm.ServiceInfo; |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 35 | import android.os.Binder; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 36 | import android.os.Build; |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 37 | import android.os.Handler; |
| 38 | import android.os.IBinder; |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 39 | import android.os.Looper; |
| 40 | import android.os.PowerManager; |
Jeff Brown | 970d413 | 2014-07-19 11:33:47 -0700 | [diff] [blame] | 41 | import android.os.PowerManagerInternal; |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 42 | import android.os.SystemClock; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 43 | import android.os.SystemProperties; |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 44 | import android.os.UserHandle; |
| 45 | import android.provider.Settings; |
Jeff Brown | 567f7ca | 2014-01-30 23:38:03 -0800 | [diff] [blame] | 46 | import android.service.dreams.DreamManagerInternal; |
| 47 | import android.service.dreams.DreamService; |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 48 | import android.service.dreams.IDreamManager; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 49 | import android.text.TextUtils; |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 50 | import android.util.Slog; |
Jeff Brown | 970d413 | 2014-07-19 11:33:47 -0700 | [diff] [blame] | 51 | import android.view.Display; |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 52 | |
| 53 | import java.io.FileDescriptor; |
| 54 | import java.io.PrintWriter; |
John Spurlock | bbdb062 | 2012-12-10 18:15:07 -0500 | [diff] [blame] | 55 | import java.util.ArrayList; |
| 56 | import java.util.List; |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 57 | |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 58 | import libcore.util.Objects; |
| 59 | |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 60 | /** |
| 61 | * Service api for managing dreams. |
| 62 | * |
| 63 | * @hide |
| 64 | */ |
Jeff Brown | 567f7ca | 2014-01-30 23:38:03 -0800 | [diff] [blame] | 65 | public final class DreamManagerService extends SystemService { |
Dianne Hackborn | 40e9f29 | 2012-11-27 19:12:23 -0800 | [diff] [blame] | 66 | private static final boolean DEBUG = false; |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 67 | private static final String TAG = "DreamManagerService"; |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 68 | |
| 69 | private final Object mLock = new Object(); |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 70 | |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 71 | private final Context mContext; |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 72 | private final DreamHandler mHandler; |
| 73 | private final DreamController mController; |
| 74 | private final PowerManager mPowerManager; |
Jeff Brown | 970d413 | 2014-07-19 11:33:47 -0700 | [diff] [blame] | 75 | private final PowerManagerInternal mPowerManagerInternal; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 76 | private final PowerManager.WakeLock mDozeWakeLock; |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 77 | |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 78 | private Binder mCurrentDreamToken; |
| 79 | private ComponentName mCurrentDreamName; |
| 80 | private int mCurrentDreamUserId; |
| 81 | private boolean mCurrentDreamIsTest; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 82 | private boolean mCurrentDreamCanDoze; |
| 83 | private boolean mCurrentDreamIsDozing; |
Jeff Brown | f6d4668 | 2014-07-17 22:44:20 -0700 | [diff] [blame] | 84 | private boolean mCurrentDreamIsWaking; |
Jeff Brown | 970d413 | 2014-07-19 11:33:47 -0700 | [diff] [blame] | 85 | private int mCurrentDreamDozeScreenState = Display.STATE_UNKNOWN; |
| 86 | private int mCurrentDreamDozeScreenBrightness = PowerManager.BRIGHTNESS_DEFAULT; |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 87 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 88 | public DreamManagerService(Context context) { |
Jeff Brown | 567f7ca | 2014-01-30 23:38:03 -0800 | [diff] [blame] | 89 | super(context); |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 90 | mContext = context; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 91 | mHandler = new DreamHandler(FgThread.get().getLooper()); |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 92 | mController = new DreamController(context, mHandler, mControllerListener); |
| 93 | |
| 94 | mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
Jeff Brown | 970d413 | 2014-07-19 11:33:47 -0700 | [diff] [blame] | 95 | mPowerManagerInternal = getLocalService(PowerManagerInternal.class); |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 96 | mDozeWakeLock = mPowerManager.newWakeLock(PowerManager.DOZE_WAKE_LOCK, TAG); |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 97 | } |
| 98 | |
Jeff Brown | 567f7ca | 2014-01-30 23:38:03 -0800 | [diff] [blame] | 99 | @Override |
| 100 | public void onStart() { |
| 101 | publishBinderService(DreamService.DREAM_SERVICE, new BinderService()); |
| 102 | publishLocalService(DreamManagerInternal.class, new LocalService()); |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | @Override |
Jeff Brown | 567f7ca | 2014-01-30 23:38:03 -0800 | [diff] [blame] | 106 | public void onBootPhase(int phase) { |
| 107 | if (phase == SystemService.PHASE_THIRD_PARTY_APPS_CAN_START) { |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 108 | if (Build.IS_DEBUGGABLE) { |
| 109 | SystemProperties.addChangeCallback(mSystemPropertiesChanged); |
| 110 | } |
Jeff Brown | 567f7ca | 2014-01-30 23:38:03 -0800 | [diff] [blame] | 111 | mContext.registerReceiver(new BroadcastReceiver() { |
| 112 | @Override |
| 113 | public void onReceive(Context context, Intent intent) { |
| 114 | synchronized (mLock) { |
Jeff Brown | f6d4668 | 2014-07-17 22:44:20 -0700 | [diff] [blame] | 115 | stopDreamLocked(false /*immediate*/); |
Jeff Brown | 567f7ca | 2014-01-30 23:38:03 -0800 | [diff] [blame] | 116 | } |
| 117 | } |
| 118 | }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler); |
John Spurlock | da5b6f2 | 2013-08-14 09:46:52 -0400 | [diff] [blame] | 119 | } |
Jeff Brown | 567f7ca | 2014-01-30 23:38:03 -0800 | [diff] [blame] | 120 | } |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 121 | |
Jeff Brown | 567f7ca | 2014-01-30 23:38:03 -0800 | [diff] [blame] | 122 | private void dumpInternal(PrintWriter pw) { |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 123 | pw.println("DREAM MANAGER (dumpsys dreams)"); |
| 124 | pw.println(); |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 125 | pw.println("mCurrentDreamToken=" + mCurrentDreamToken); |
| 126 | pw.println("mCurrentDreamName=" + mCurrentDreamName); |
| 127 | pw.println("mCurrentDreamUserId=" + mCurrentDreamUserId); |
| 128 | pw.println("mCurrentDreamIsTest=" + mCurrentDreamIsTest); |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 129 | pw.println("mCurrentDreamCanDoze=" + mCurrentDreamCanDoze); |
| 130 | pw.println("mCurrentDreamIsDozing=" + mCurrentDreamIsDozing); |
Jeff Brown | f6d4668 | 2014-07-17 22:44:20 -0700 | [diff] [blame] | 131 | pw.println("mCurrentDreamIsWaking=" + mCurrentDreamIsWaking); |
Jeff Brown | 970d413 | 2014-07-19 11:33:47 -0700 | [diff] [blame] | 132 | pw.println("mCurrentDreamDozeScreenState=" |
| 133 | + Display.stateToString(mCurrentDreamDozeScreenState)); |
| 134 | pw.println("mCurrentDreamDozeScreenBrightness=" + mCurrentDreamDozeScreenBrightness); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 135 | pw.println("getDozeComponent()=" + getDozeComponent()); |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 136 | pw.println(); |
| 137 | |
| 138 | DumpUtils.dumpAsync(mHandler, new DumpUtils.Dump() { |
| 139 | @Override |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 140 | public void dump(PrintWriter pw, String prefix) { |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 141 | mController.dump(pw); |
| 142 | } |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 143 | }, pw, "", 200); |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 144 | } |
| 145 | |
Jeff Brown | 567f7ca | 2014-01-30 23:38:03 -0800 | [diff] [blame] | 146 | private boolean isDreamingInternal() { |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 147 | synchronized (mLock) { |
Jeff Brown | f6d4668 | 2014-07-17 22:44:20 -0700 | [diff] [blame] | 148 | return mCurrentDreamToken != null && !mCurrentDreamIsTest |
| 149 | && !mCurrentDreamIsWaking; |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 150 | } |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 151 | } |
| 152 | |
Jeff Brown | 567f7ca | 2014-01-30 23:38:03 -0800 | [diff] [blame] | 153 | private void requestDreamInternal() { |
| 154 | // Ask the power manager to nap. It will eventually call back into |
| 155 | // startDream() if/when it is appropriate to start dreaming. |
| 156 | // Because napping could cause the screen to turn off immediately if the dream |
| 157 | // cannot be started, we keep one eye open and gently poke user activity. |
| 158 | long time = SystemClock.uptimeMillis(); |
| 159 | mPowerManager.userActivity(time, true /*noChangeLights*/); |
| 160 | mPowerManager.nap(time); |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 161 | } |
| 162 | |
Jeff Brown | 567f7ca | 2014-01-30 23:38:03 -0800 | [diff] [blame] | 163 | private void requestAwakenInternal() { |
| 164 | // Treat an explicit request to awaken as user activity so that the |
| 165 | // device doesn't immediately go to sleep if the timeout expired, |
| 166 | // for example when being undocked. |
| 167 | long time = SystemClock.uptimeMillis(); |
| 168 | mPowerManager.userActivity(time, false /*noChangeLights*/); |
Jeff Brown | f6d4668 | 2014-07-17 22:44:20 -0700 | [diff] [blame] | 169 | stopDreamInternal(false /*immediate*/); |
Jeff Brown | 567f7ca | 2014-01-30 23:38:03 -0800 | [diff] [blame] | 170 | } |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 171 | |
Jeff Brown | f6d4668 | 2014-07-17 22:44:20 -0700 | [diff] [blame] | 172 | private void finishSelfInternal(IBinder token, boolean immediate) { |
Jeff Brown | 567f7ca | 2014-01-30 23:38:03 -0800 | [diff] [blame] | 173 | if (DEBUG) { |
Jeff Brown | f6d4668 | 2014-07-17 22:44:20 -0700 | [diff] [blame] | 174 | Slog.d(TAG, "Dream finished: " + token + ", immediate=" + immediate); |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Jeff Brown | 567f7ca | 2014-01-30 23:38:03 -0800 | [diff] [blame] | 177 | // Note that a dream finishing and self-terminating is not |
| 178 | // itself considered user activity. If the dream is ending because |
| 179 | // the user interacted with the device then user activity will already |
| 180 | // have been poked so the device will stay awake a bit longer. |
| 181 | // If the dream is ending on its own for other reasons and no wake |
| 182 | // locks are held and the user activity timeout has expired then the |
| 183 | // device may simply go to sleep. |
| 184 | synchronized (mLock) { |
| 185 | if (mCurrentDreamToken == token) { |
Jeff Brown | f6d4668 | 2014-07-17 22:44:20 -0700 | [diff] [blame] | 186 | stopDreamLocked(immediate); |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 187 | } |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 188 | } |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 189 | } |
| 190 | |
Jeff Brown | 567f7ca | 2014-01-30 23:38:03 -0800 | [diff] [blame] | 191 | private void testDreamInternal(ComponentName dream, int userId) { |
| 192 | synchronized (mLock) { |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 193 | startDreamLocked(dream, true /*isTest*/, false /*canDoze*/, userId); |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 197 | private void startDreamInternal(boolean doze) { |
| 198 | final int userId = ActivityManager.getCurrentUser(); |
John Spurlock | eb8d1be | 2014-06-25 17:46:15 -0400 | [diff] [blame] | 199 | final ComponentName dream = chooseDreamForUser(doze, userId); |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 200 | if (dream != null) { |
| 201 | synchronized (mLock) { |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 202 | startDreamLocked(dream, false /*isTest*/, doze, userId); |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 203 | } |
| 204 | } |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Jeff Brown | f6d4668 | 2014-07-17 22:44:20 -0700 | [diff] [blame] | 207 | private void stopDreamInternal(boolean immediate) { |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 208 | synchronized (mLock) { |
Jeff Brown | f6d4668 | 2014-07-17 22:44:20 -0700 | [diff] [blame] | 209 | stopDreamLocked(immediate); |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 210 | } |
| 211 | } |
| 212 | |
Jeff Brown | 970d413 | 2014-07-19 11:33:47 -0700 | [diff] [blame] | 213 | private void startDozingInternal(IBinder token, int screenState, |
| 214 | int screenBrightness) { |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 215 | if (DEBUG) { |
Jeff Brown | 970d413 | 2014-07-19 11:33:47 -0700 | [diff] [blame] | 216 | Slog.d(TAG, "Dream requested to start dozing: " + token |
| 217 | + ", screenState=" + screenState |
| 218 | + ", screenBrightness=" + screenBrightness); |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | synchronized (mLock) { |
Jeff Brown | 970d413 | 2014-07-19 11:33:47 -0700 | [diff] [blame] | 222 | if (mCurrentDreamToken == token && mCurrentDreamCanDoze) { |
| 223 | mCurrentDreamDozeScreenState = screenState; |
| 224 | mCurrentDreamDozeScreenBrightness = screenBrightness; |
| 225 | mPowerManagerInternal.setDozeOverrideFromDreamManager( |
| 226 | screenState, screenBrightness); |
| 227 | if (!mCurrentDreamIsDozing) { |
| 228 | mCurrentDreamIsDozing = true; |
| 229 | mDozeWakeLock.acquire(); |
| 230 | } |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | private void stopDozingInternal(IBinder token) { |
| 236 | if (DEBUG) { |
| 237 | Slog.d(TAG, "Dream requested to stop dozing: " + token); |
| 238 | } |
| 239 | |
| 240 | synchronized (mLock) { |
| 241 | if (mCurrentDreamToken == token && mCurrentDreamIsDozing) { |
| 242 | mCurrentDreamIsDozing = false; |
| 243 | mDozeWakeLock.release(); |
Jeff Brown | 970d413 | 2014-07-19 11:33:47 -0700 | [diff] [blame] | 244 | mPowerManagerInternal.setDozeOverrideFromDreamManager( |
| 245 | Display.STATE_UNKNOWN, PowerManager.BRIGHTNESS_DEFAULT); |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | } |
| 249 | |
John Spurlock | eb8d1be | 2014-06-25 17:46:15 -0400 | [diff] [blame] | 250 | private ComponentName chooseDreamForUser(boolean doze, int userId) { |
| 251 | if (doze) { |
John Spurlock | a4215ce | 2014-08-04 14:50:38 -0400 | [diff] [blame] | 252 | ComponentName dozeComponent = getDozeComponent(userId); |
John Spurlock | eb8d1be | 2014-06-25 17:46:15 -0400 | [diff] [blame] | 253 | return validateDream(dozeComponent) ? dozeComponent : null; |
| 254 | } |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 255 | ComponentName[] dreams = getDreamComponentsForUser(userId); |
| 256 | return dreams != null && dreams.length != 0 ? dreams[0] : null; |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 257 | } |
| 258 | |
John Spurlock | eb8d1be | 2014-06-25 17:46:15 -0400 | [diff] [blame] | 259 | private boolean validateDream(ComponentName component) { |
| 260 | if (component == null) return false; |
| 261 | final ServiceInfo serviceInfo = getServiceInfo(component); |
| 262 | if (serviceInfo == null) { |
| 263 | Slog.w(TAG, "Dream " + component + " does not exist"); |
| 264 | return false; |
Dianne Hackborn | 955d8d6 | 2014-10-07 20:17:19 -0700 | [diff] [blame] | 265 | } else if (serviceInfo.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.LOLLIPOP |
John Spurlock | eb8d1be | 2014-06-25 17:46:15 -0400 | [diff] [blame] | 266 | && !BIND_DREAM_SERVICE.equals(serviceInfo.permission)) { |
| 267 | Slog.w(TAG, "Dream " + component |
| 268 | + " is not available because its manifest is missing the " + BIND_DREAM_SERVICE |
| 269 | + " permission on the dream service declaration."); |
| 270 | return false; |
| 271 | } |
| 272 | return true; |
| 273 | } |
| 274 | |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 275 | private ComponentName[] getDreamComponentsForUser(int userId) { |
| 276 | String names = Settings.Secure.getStringForUser(mContext.getContentResolver(), |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 277 | Settings.Secure.SCREENSAVER_COMPONENTS, |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 278 | userId); |
John Spurlock | bbdb062 | 2012-12-10 18:15:07 -0500 | [diff] [blame] | 279 | ComponentName[] components = componentsFromString(names); |
| 280 | |
| 281 | // first, ensure components point to valid services |
| 282 | List<ComponentName> validComponents = new ArrayList<ComponentName>(); |
| 283 | if (components != null) { |
| 284 | for (ComponentName component : components) { |
John Spurlock | eb8d1be | 2014-06-25 17:46:15 -0400 | [diff] [blame] | 285 | if (validateDream(component)) { |
John Spurlock | bbdb062 | 2012-12-10 18:15:07 -0500 | [diff] [blame] | 286 | validComponents.add(component); |
John Spurlock | bbdb062 | 2012-12-10 18:15:07 -0500 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | // fallback to the default dream component if necessary |
| 292 | if (validComponents.isEmpty()) { |
Jeff Brown | 567f7ca | 2014-01-30 23:38:03 -0800 | [diff] [blame] | 293 | ComponentName defaultDream = getDefaultDreamComponentForUser(userId); |
John Spurlock | bbdb062 | 2012-12-10 18:15:07 -0500 | [diff] [blame] | 294 | if (defaultDream != null) { |
| 295 | Slog.w(TAG, "Falling back to default dream " + defaultDream); |
| 296 | validComponents.add(defaultDream); |
| 297 | } |
| 298 | } |
| 299 | return validComponents.toArray(new ComponentName[validComponents.size()]); |
| 300 | } |
| 301 | |
Jeff Brown | 567f7ca | 2014-01-30 23:38:03 -0800 | [diff] [blame] | 302 | private void setDreamComponentsForUser(int userId, ComponentName[] componentNames) { |
| 303 | Settings.Secure.putStringForUser(mContext.getContentResolver(), |
| 304 | Settings.Secure.SCREENSAVER_COMPONENTS, |
| 305 | componentsToString(componentNames), |
| 306 | userId); |
| 307 | } |
| 308 | |
| 309 | private ComponentName getDefaultDreamComponentForUser(int userId) { |
| 310 | String name = Settings.Secure.getStringForUser(mContext.getContentResolver(), |
| 311 | Settings.Secure.SCREENSAVER_DEFAULT_COMPONENT, |
| 312 | userId); |
| 313 | return name == null ? null : ComponentName.unflattenFromString(name); |
| 314 | } |
| 315 | |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 316 | private ComponentName getDozeComponent() { |
John Spurlock | a4215ce | 2014-08-04 14:50:38 -0400 | [diff] [blame] | 317 | return getDozeComponent(ActivityManager.getCurrentUser()); |
| 318 | } |
| 319 | |
| 320 | private ComponentName getDozeComponent(int userId) { |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 321 | // Read the component from a system property to facilitate debugging. |
| 322 | // Note that for production devices, the dream should actually be declared in |
| 323 | // a config.xml resource. |
| 324 | String name = Build.IS_DEBUGGABLE ? SystemProperties.get("debug.doze.component") : null; |
| 325 | if (TextUtils.isEmpty(name)) { |
| 326 | // Read the component from a config.xml resource. |
| 327 | // The value should be specified in a resource overlay for the product. |
| 328 | name = mContext.getResources().getString( |
| 329 | com.android.internal.R.string.config_dozeComponent); |
| 330 | } |
John Spurlock | a4215ce | 2014-08-04 14:50:38 -0400 | [diff] [blame] | 331 | boolean enabled = Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 332 | Settings.Secure.DOZE_ENABLED, 1, userId) != 0; |
| 333 | return TextUtils.isEmpty(name) || !enabled ? null : ComponentName.unflattenFromString(name); |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 334 | } |
| 335 | |
John Spurlock | eb8d1be | 2014-06-25 17:46:15 -0400 | [diff] [blame] | 336 | private ServiceInfo getServiceInfo(ComponentName name) { |
John Spurlock | bbdb062 | 2012-12-10 18:15:07 -0500 | [diff] [blame] | 337 | try { |
John Spurlock | eb8d1be | 2014-06-25 17:46:15 -0400 | [diff] [blame] | 338 | return name != null ? mContext.getPackageManager().getServiceInfo(name, 0) : null; |
John Spurlock | bbdb062 | 2012-12-10 18:15:07 -0500 | [diff] [blame] | 339 | } catch (NameNotFoundException e) { |
John Spurlock | eb8d1be | 2014-06-25 17:46:15 -0400 | [diff] [blame] | 340 | return null; |
John Spurlock | bbdb062 | 2012-12-10 18:15:07 -0500 | [diff] [blame] | 341 | } |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 342 | } |
| 343 | |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 344 | private void startDreamLocked(final ComponentName name, |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 345 | final boolean isTest, final boolean canDoze, final int userId) { |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 346 | if (Objects.equal(mCurrentDreamName, name) |
| 347 | && mCurrentDreamIsTest == isTest |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 348 | && mCurrentDreamCanDoze == canDoze |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 349 | && mCurrentDreamUserId == userId) { |
| 350 | return; |
| 351 | } |
| 352 | |
Jeff Brown | f6d4668 | 2014-07-17 22:44:20 -0700 | [diff] [blame] | 353 | stopDreamLocked(true /*immediate*/); |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 354 | |
Jeff Brown | f6d4668 | 2014-07-17 22:44:20 -0700 | [diff] [blame] | 355 | Slog.i(TAG, "Entering dreamland."); |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 356 | |
| 357 | final Binder newToken = new Binder(); |
| 358 | mCurrentDreamToken = newToken; |
| 359 | mCurrentDreamName = name; |
| 360 | mCurrentDreamIsTest = isTest; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 361 | mCurrentDreamCanDoze = canDoze; |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 362 | mCurrentDreamUserId = userId; |
| 363 | |
| 364 | mHandler.post(new Runnable() { |
| 365 | @Override |
| 366 | public void run() { |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 367 | mController.startDream(newToken, name, isTest, canDoze, userId); |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 368 | } |
| 369 | }); |
| 370 | } |
| 371 | |
Jeff Brown | f6d4668 | 2014-07-17 22:44:20 -0700 | [diff] [blame] | 372 | private void stopDreamLocked(final boolean immediate) { |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 373 | if (mCurrentDreamToken != null) { |
Jeff Brown | f6d4668 | 2014-07-17 22:44:20 -0700 | [diff] [blame] | 374 | if (immediate) { |
| 375 | Slog.i(TAG, "Leaving dreamland."); |
| 376 | cleanupDreamLocked(); |
| 377 | } else if (mCurrentDreamIsWaking) { |
| 378 | return; // already waking |
| 379 | } else { |
| 380 | Slog.i(TAG, "Gently waking up from dream."); |
| 381 | mCurrentDreamIsWaking = true; |
| 382 | } |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 383 | |
| 384 | mHandler.post(new Runnable() { |
| 385 | @Override |
| 386 | public void run() { |
Jeff Brown | f6d4668 | 2014-07-17 22:44:20 -0700 | [diff] [blame] | 387 | mController.stopDream(immediate); |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 388 | } |
| 389 | }); |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | private void cleanupDreamLocked() { |
| 394 | mCurrentDreamToken = null; |
| 395 | mCurrentDreamName = null; |
| 396 | mCurrentDreamIsTest = false; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 397 | mCurrentDreamCanDoze = false; |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 398 | mCurrentDreamUserId = 0; |
Jeff Brown | f6d4668 | 2014-07-17 22:44:20 -0700 | [diff] [blame] | 399 | mCurrentDreamIsWaking = false; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 400 | if (mCurrentDreamIsDozing) { |
| 401 | mCurrentDreamIsDozing = false; |
| 402 | mDozeWakeLock.release(); |
| 403 | } |
Jeff Brown | 970d413 | 2014-07-19 11:33:47 -0700 | [diff] [blame] | 404 | mCurrentDreamDozeScreenState = Display.STATE_UNKNOWN; |
| 405 | mCurrentDreamDozeScreenBrightness = PowerManager.BRIGHTNESS_DEFAULT; |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | private void checkPermission(String permission) { |
| 409 | if (mContext.checkCallingOrSelfPermission(permission) |
| 410 | != PackageManager.PERMISSION_GRANTED) { |
| 411 | throw new SecurityException("Access denied to process: " + Binder.getCallingPid() |
| 412 | + ", must have permission " + permission); |
| 413 | } |
| 414 | } |
| 415 | |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 416 | private static String componentsToString(ComponentName[] componentNames) { |
| 417 | StringBuilder names = new StringBuilder(); |
| 418 | if (componentNames != null) { |
| 419 | for (ComponentName componentName : componentNames) { |
| 420 | if (names.length() > 0) { |
| 421 | names.append(','); |
| 422 | } |
| 423 | names.append(componentName.flattenToString()); |
| 424 | } |
| 425 | } |
| 426 | return names.toString(); |
| 427 | } |
| 428 | |
| 429 | private static ComponentName[] componentsFromString(String names) { |
John Spurlock | f5df689 | 2012-12-14 13:12:43 -0500 | [diff] [blame] | 430 | if (names == null) { |
| 431 | return null; |
| 432 | } |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 433 | String[] namesArray = names.split(","); |
| 434 | ComponentName[] componentNames = new ComponentName[namesArray.length]; |
| 435 | for (int i = 0; i < namesArray.length; i++) { |
| 436 | componentNames[i] = ComponentName.unflattenFromString(namesArray[i]); |
| 437 | } |
| 438 | return componentNames; |
| 439 | } |
| 440 | |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 441 | private final DreamController.Listener mControllerListener = new DreamController.Listener() { |
| 442 | @Override |
| 443 | public void onDreamStopped(Binder token) { |
| 444 | synchronized (mLock) { |
| 445 | if (mCurrentDreamToken == token) { |
| 446 | cleanupDreamLocked(); |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 447 | } |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 448 | } |
| 449 | } |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 450 | }; |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 451 | |
| 452 | /** |
| 453 | * Handler for asynchronous operations performed by the dream manager. |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 454 | * Ensures operations to {@link DreamController} are single-threaded. |
| 455 | */ |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 456 | private final class DreamHandler extends Handler { |
| 457 | public DreamHandler(Looper looper) { |
| 458 | super(looper, null, true /*async*/); |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 459 | } |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 460 | } |
Jeff Brown | 567f7ca | 2014-01-30 23:38:03 -0800 | [diff] [blame] | 461 | |
| 462 | private final class BinderService extends IDreamManager.Stub { |
| 463 | @Override // Binder call |
| 464 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 465 | if (mContext.checkCallingOrSelfPermission(Manifest.permission.DUMP) |
| 466 | != PackageManager.PERMISSION_GRANTED) { |
| 467 | pw.println("Permission Denial: can't dump DreamManager from from pid=" |
| 468 | + Binder.getCallingPid() |
| 469 | + ", uid=" + Binder.getCallingUid()); |
| 470 | return; |
| 471 | } |
| 472 | |
| 473 | final long ident = Binder.clearCallingIdentity(); |
| 474 | try { |
| 475 | dumpInternal(pw); |
| 476 | } finally { |
| 477 | Binder.restoreCallingIdentity(ident); |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | @Override // Binder call |
| 482 | public ComponentName[] getDreamComponents() { |
| 483 | checkPermission(android.Manifest.permission.READ_DREAM_STATE); |
| 484 | |
| 485 | final int userId = UserHandle.getCallingUserId(); |
| 486 | final long ident = Binder.clearCallingIdentity(); |
| 487 | try { |
| 488 | return getDreamComponentsForUser(userId); |
| 489 | } finally { |
| 490 | Binder.restoreCallingIdentity(ident); |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | @Override // Binder call |
| 495 | public void setDreamComponents(ComponentName[] componentNames) { |
| 496 | checkPermission(android.Manifest.permission.WRITE_DREAM_STATE); |
| 497 | |
| 498 | final int userId = UserHandle.getCallingUserId(); |
| 499 | final long ident = Binder.clearCallingIdentity(); |
| 500 | try { |
| 501 | setDreamComponentsForUser(userId, componentNames); |
| 502 | } finally { |
| 503 | Binder.restoreCallingIdentity(ident); |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | @Override // Binder call |
| 508 | public ComponentName getDefaultDreamComponent() { |
| 509 | checkPermission(android.Manifest.permission.READ_DREAM_STATE); |
| 510 | |
| 511 | final int userId = UserHandle.getCallingUserId(); |
| 512 | final long ident = Binder.clearCallingIdentity(); |
| 513 | try { |
| 514 | return getDefaultDreamComponentForUser(userId); |
| 515 | } finally { |
| 516 | Binder.restoreCallingIdentity(ident); |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | @Override // Binder call |
| 521 | public boolean isDreaming() { |
| 522 | checkPermission(android.Manifest.permission.READ_DREAM_STATE); |
| 523 | |
| 524 | final long ident = Binder.clearCallingIdentity(); |
| 525 | try { |
| 526 | return isDreamingInternal(); |
| 527 | } finally { |
| 528 | Binder.restoreCallingIdentity(ident); |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | @Override // Binder call |
| 533 | public void dream() { |
| 534 | checkPermission(android.Manifest.permission.WRITE_DREAM_STATE); |
| 535 | |
| 536 | final long ident = Binder.clearCallingIdentity(); |
| 537 | try { |
| 538 | requestDreamInternal(); |
| 539 | } finally { |
| 540 | Binder.restoreCallingIdentity(ident); |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | @Override // Binder call |
| 545 | public void testDream(ComponentName dream) { |
| 546 | if (dream == null) { |
| 547 | throw new IllegalArgumentException("dream must not be null"); |
| 548 | } |
| 549 | checkPermission(android.Manifest.permission.WRITE_DREAM_STATE); |
| 550 | |
| 551 | final int callingUserId = UserHandle.getCallingUserId(); |
| 552 | final int currentUserId = ActivityManager.getCurrentUser(); |
| 553 | if (callingUserId != currentUserId) { |
| 554 | // This check is inherently prone to races but at least it's something. |
| 555 | Slog.w(TAG, "Aborted attempt to start a test dream while a different " |
| 556 | + " user is active: callingUserId=" + callingUserId |
| 557 | + ", currentUserId=" + currentUserId); |
| 558 | return; |
| 559 | } |
| 560 | final long ident = Binder.clearCallingIdentity(); |
| 561 | try { |
| 562 | testDreamInternal(dream, callingUserId); |
| 563 | } finally { |
| 564 | Binder.restoreCallingIdentity(ident); |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | @Override // Binder call |
| 569 | public void awaken() { |
| 570 | checkPermission(android.Manifest.permission.WRITE_DREAM_STATE); |
| 571 | |
| 572 | final long ident = Binder.clearCallingIdentity(); |
| 573 | try { |
| 574 | requestAwakenInternal(); |
| 575 | } finally { |
| 576 | Binder.restoreCallingIdentity(ident); |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | @Override // Binder call |
Jeff Brown | f6d4668 | 2014-07-17 22:44:20 -0700 | [diff] [blame] | 581 | public void finishSelf(IBinder token, boolean immediate) { |
Jeff Brown | 567f7ca | 2014-01-30 23:38:03 -0800 | [diff] [blame] | 582 | // Requires no permission, called by Dream from an arbitrary process. |
| 583 | if (token == null) { |
| 584 | throw new IllegalArgumentException("token must not be null"); |
| 585 | } |
| 586 | |
| 587 | final long ident = Binder.clearCallingIdentity(); |
| 588 | try { |
Jeff Brown | f6d4668 | 2014-07-17 22:44:20 -0700 | [diff] [blame] | 589 | finishSelfInternal(token, immediate); |
Jeff Brown | 567f7ca | 2014-01-30 23:38:03 -0800 | [diff] [blame] | 590 | } finally { |
| 591 | Binder.restoreCallingIdentity(ident); |
| 592 | } |
| 593 | } |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 594 | |
| 595 | @Override // Binder call |
Jeff Brown | 970d413 | 2014-07-19 11:33:47 -0700 | [diff] [blame] | 596 | public void startDozing(IBinder token, int screenState, int screenBrightness) { |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 597 | // Requires no permission, called by Dream from an arbitrary process. |
| 598 | if (token == null) { |
| 599 | throw new IllegalArgumentException("token must not be null"); |
| 600 | } |
| 601 | |
| 602 | final long ident = Binder.clearCallingIdentity(); |
| 603 | try { |
Jeff Brown | 970d413 | 2014-07-19 11:33:47 -0700 | [diff] [blame] | 604 | startDozingInternal(token, screenState, screenBrightness); |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 605 | } finally { |
| 606 | Binder.restoreCallingIdentity(ident); |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | @Override // Binder call |
| 611 | public void stopDozing(IBinder token) { |
| 612 | // Requires no permission, called by Dream from an arbitrary process. |
| 613 | if (token == null) { |
| 614 | throw new IllegalArgumentException("token must not be null"); |
| 615 | } |
| 616 | |
| 617 | final long ident = Binder.clearCallingIdentity(); |
| 618 | try { |
| 619 | stopDozingInternal(token); |
| 620 | } finally { |
| 621 | Binder.restoreCallingIdentity(ident); |
| 622 | } |
| 623 | } |
Jeff Brown | 567f7ca | 2014-01-30 23:38:03 -0800 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | private final class LocalService extends DreamManagerInternal { |
| 627 | @Override |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 628 | public void startDream(boolean doze) { |
| 629 | startDreamInternal(doze); |
Jeff Brown | 567f7ca | 2014-01-30 23:38:03 -0800 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | @Override |
Jeff Brown | f6d4668 | 2014-07-17 22:44:20 -0700 | [diff] [blame] | 633 | public void stopDream(boolean immediate) { |
| 634 | stopDreamInternal(immediate); |
Jeff Brown | 567f7ca | 2014-01-30 23:38:03 -0800 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | @Override |
| 638 | public boolean isDreaming() { |
| 639 | return isDreamingInternal(); |
| 640 | } |
| 641 | } |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 642 | |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 643 | private final Runnable mSystemPropertiesChanged = new Runnable() { |
| 644 | @Override |
| 645 | public void run() { |
| 646 | if (DEBUG) Slog.d(TAG, "System properties changed"); |
Jeff Brown | f6d4668 | 2014-07-17 22:44:20 -0700 | [diff] [blame] | 647 | synchronized (mLock) { |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 648 | if (mCurrentDreamName != null && mCurrentDreamCanDoze |
| 649 | && !mCurrentDreamName.equals(getDozeComponent())) { |
Jeff Brown | f6d4668 | 2014-07-17 22:44:20 -0700 | [diff] [blame] | 650 | // May have updated the doze component, wake up |
| 651 | mPowerManager.wakeUp(SystemClock.uptimeMillis()); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 652 | } |
| 653 | } |
| 654 | } |
| 655 | }; |
John Spurlock | f4f6b4c | 2012-08-25 12:08:03 -0400 | [diff] [blame] | 656 | } |