John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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.systemui.doze; |
| 18 | |
John Spurlock | ed69bd6 | 2014-07-23 11:09:02 -0400 | [diff] [blame] | 19 | import static android.os.PowerManager.BRIGHTNESS_OFF; |
| 20 | import static android.os.PowerManager.BRIGHTNESS_ON; |
| 21 | |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 22 | import android.app.AlarmManager; |
| 23 | import android.app.PendingIntent; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 24 | import android.content.BroadcastReceiver; |
| 25 | import android.content.Context; |
| 26 | import android.content.Intent; |
| 27 | import android.content.IntentFilter; |
John Spurlock | ed69bd6 | 2014-07-23 11:09:02 -0400 | [diff] [blame] | 28 | import android.content.res.Resources; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 29 | import android.hardware.Sensor; |
| 30 | import android.hardware.SensorManager; |
| 31 | import android.hardware.TriggerEvent; |
| 32 | import android.hardware.TriggerEventListener; |
John Spurlock | ed69bd6 | 2014-07-23 11:09:02 -0400 | [diff] [blame] | 33 | import android.os.Handler; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 34 | import android.os.PowerManager; |
John Spurlock | 6612727 | 2014-06-28 11:27:17 -0400 | [diff] [blame] | 35 | import android.os.SystemProperties; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 36 | import android.os.Vibrator; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 37 | import android.service.dreams.DreamService; |
| 38 | import android.util.Log; |
John Spurlock | ed69bd6 | 2014-07-23 11:09:02 -0400 | [diff] [blame] | 39 | import android.util.MathUtils; |
| 40 | import android.view.Display; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 41 | |
John Spurlock | 6612727 | 2014-06-28 11:27:17 -0400 | [diff] [blame] | 42 | import com.android.systemui.R; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 43 | import com.android.systemui.SystemUIApplication; |
| 44 | |
John Spurlock | 6612727 | 2014-06-28 11:27:17 -0400 | [diff] [blame] | 45 | import java.io.FileDescriptor; |
| 46 | import java.io.PrintWriter; |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 47 | import java.util.Date; |
John Spurlock | 6612727 | 2014-06-28 11:27:17 -0400 | [diff] [blame] | 48 | |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 49 | public class DozeService extends DreamService { |
John Spurlock | ed69bd6 | 2014-07-23 11:09:02 -0400 | [diff] [blame] | 50 | private static final String TAG = "DozeService"; |
| 51 | private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 52 | |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 53 | private static final String ACTION_BASE = "com.android.systemui.doze"; |
| 54 | private static final String PULSE_ACTION = ACTION_BASE + ".pulse"; |
| 55 | private static final String NOTIFICATION_PULSE_ACTION = ACTION_BASE + ".notification_pulse"; |
| 56 | private static final String EXTRA_PULSES = "pulses"; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 57 | |
John Spurlock | ed69bd6 | 2014-07-23 11:09:02 -0400 | [diff] [blame] | 58 | private final String mTag = String.format(TAG + ".%08x", hashCode()); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 59 | private final Context mContext = this; |
John Spurlock | ed69bd6 | 2014-07-23 11:09:02 -0400 | [diff] [blame] | 60 | private final Handler mHandler = new Handler(); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 61 | |
| 62 | private Host mHost; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 63 | private SensorManager mSensors; |
| 64 | private Sensor mSigMotionSensor; |
| 65 | private PowerManager mPowerManager; |
| 66 | private PowerManager.WakeLock mWakeLock; |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 67 | private AlarmManager mAlarmManager; |
John Spurlock | ed69bd6 | 2014-07-23 11:09:02 -0400 | [diff] [blame] | 68 | private int mMaxBrightness; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 69 | private boolean mDreaming; |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 70 | private boolean mBroadcastReceiverRegistered; |
John Spurlock | 6612727 | 2014-06-28 11:27:17 -0400 | [diff] [blame] | 71 | private boolean mSigMotionConfigured; |
| 72 | private boolean mSigMotionEnabled; |
John Spurlock | ed69bd6 | 2014-07-23 11:09:02 -0400 | [diff] [blame] | 73 | private boolean mDisplayStateSupported; |
| 74 | private int mDisplayStateWhenOn; |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 75 | private boolean mNotificationLightOn; |
| 76 | private PendingIntent mNotificationPulseIntent; |
| 77 | private int mMultipulseCount; |
| 78 | private int mNotificationPulseInterval; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 79 | |
| 80 | public DozeService() { |
| 81 | if (DEBUG) Log.d(mTag, "new DozeService()"); |
| 82 | setDebug(DEBUG); |
| 83 | } |
| 84 | |
| 85 | @Override |
John Spurlock | 6612727 | 2014-06-28 11:27:17 -0400 | [diff] [blame] | 86 | protected void dumpOnHandler(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 87 | super.dumpOnHandler(fd, pw, args); |
| 88 | pw.print(" mDreaming: "); pw.println(mDreaming); |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 89 | pw.print(" mBroadcastReceiverRegistered: "); pw.println(mBroadcastReceiverRegistered); |
John Spurlock | 6612727 | 2014-06-28 11:27:17 -0400 | [diff] [blame] | 90 | pw.print(" mSigMotionSensor: "); pw.println(mSigMotionSensor); |
| 91 | pw.print(" mSigMotionConfigured: "); pw.println(mSigMotionConfigured); |
| 92 | pw.print(" mSigMotionEnabled: "); pw.println(mSigMotionEnabled); |
John Spurlock | ed69bd6 | 2014-07-23 11:09:02 -0400 | [diff] [blame] | 93 | pw.print(" mMaxBrightness: "); pw.println(mMaxBrightness); |
| 94 | pw.print(" mDisplayStateSupported: "); pw.println(mDisplayStateSupported); |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 95 | pw.print(" mNotificationLightOn: "); pw.println(mNotificationLightOn); |
| 96 | pw.print(" mMultipulseCount: "); pw.println(mMultipulseCount); |
| 97 | pw.print(" mNotificationPulseInterval: "); pw.println(mNotificationPulseInterval); |
John Spurlock | 6612727 | 2014-06-28 11:27:17 -0400 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | @Override |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 101 | public void onCreate() { |
| 102 | if (DEBUG) Log.d(mTag, "onCreate"); |
| 103 | super.onCreate(); |
| 104 | |
| 105 | if (getApplication() instanceof SystemUIApplication) { |
| 106 | final SystemUIApplication app = (SystemUIApplication) getApplication(); |
| 107 | mHost = app.getComponent(Host.class); |
| 108 | } |
| 109 | |
| 110 | setWindowless(true); |
| 111 | |
| 112 | mSensors = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); |
| 113 | mSigMotionSensor = mSensors.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION); |
| 114 | mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); |
| 115 | mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, mTag); |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 116 | mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); |
John Spurlock | ed69bd6 | 2014-07-23 11:09:02 -0400 | [diff] [blame] | 117 | final Resources res = mContext.getResources(); |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 118 | mSigMotionConfigured = SystemProperties.getBoolean("doze.pulse.sigmotion", |
| 119 | res.getBoolean(R.bool.doze_pulse_on_significant_motion)); |
John Spurlock | ed69bd6 | 2014-07-23 11:09:02 -0400 | [diff] [blame] | 120 | mDisplayStateSupported = SystemProperties.getBoolean("doze.display.supported", |
| 121 | res.getBoolean(R.bool.doze_display_state_supported)); |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 122 | mMaxBrightness = MathUtils.constrain(res.getInteger(R.integer.doze_pulse_brightness), |
John Spurlock | ed69bd6 | 2014-07-23 11:09:02 -0400 | [diff] [blame] | 123 | BRIGHTNESS_OFF, BRIGHTNESS_ON); |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 124 | mNotificationPulseIntent = PendingIntent.getBroadcast(mContext, 0, |
| 125 | new Intent(NOTIFICATION_PULSE_ACTION).setPackage(getPackageName()), |
| 126 | PendingIntent.FLAG_CANCEL_CURRENT); |
| 127 | mMultipulseCount = SystemProperties.getInt("doze.multipulses", |
| 128 | res.getInteger(R.integer.doze_multipulse_count)); |
| 129 | mNotificationPulseInterval = SystemProperties.getInt("doze.notification.pulse", |
| 130 | res.getInteger(R.integer.doze_notification_pulse_interval)); |
John Spurlock | ed69bd6 | 2014-07-23 11:09:02 -0400 | [diff] [blame] | 131 | mDisplayStateWhenOn = mDisplayStateSupported ? Display.STATE_DOZE : Display.STATE_ON; |
| 132 | setDozeScreenState(mDisplayStateWhenOn); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public void onAttachedToWindow() { |
| 137 | if (DEBUG) Log.d(mTag, "onAttachedToWindow"); |
| 138 | super.onAttachedToWindow(); |
| 139 | } |
| 140 | |
| 141 | @Override |
| 142 | public void onDreamingStarted() { |
| 143 | super.onDreamingStarted(); |
Jeff Brown | 0f208eb | 2014-07-26 15:14:21 -0700 | [diff] [blame] | 144 | if (DEBUG) Log.d(mTag, "onDreamingStarted canDoze=" + canDoze()); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 145 | mDreaming = true; |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 146 | listenForPulseSignals(true); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 147 | requestDoze(); |
| 148 | } |
| 149 | |
| 150 | public void stayAwake(long millis) { |
| 151 | if (mDreaming && millis > 0) { |
| 152 | mWakeLock.acquire(millis); |
John Spurlock | ed69bd6 | 2014-07-23 11:09:02 -0400 | [diff] [blame] | 153 | setDozeScreenState(mDisplayStateWhenOn); |
| 154 | setDozeScreenBrightness(mMaxBrightness); |
| 155 | rescheduleOff(millis); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 156 | } |
| 157 | } |
| 158 | |
John Spurlock | ed69bd6 | 2014-07-23 11:09:02 -0400 | [diff] [blame] | 159 | private void rescheduleOff(long millis) { |
| 160 | if (DEBUG) Log.d(TAG, "rescheduleOff millis=" + millis); |
| 161 | mHandler.removeCallbacks(mDisplayOff); |
| 162 | mHandler.postDelayed(mDisplayOff, millis); |
| 163 | } |
| 164 | |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 165 | public void startDozing() { |
| 166 | if (DEBUG) Log.d(mTag, "startDozing mDreaming=" + mDreaming); |
| 167 | if (!mDreaming) { |
| 168 | Log.w(mTag, "Not dozing, no longer dreaming"); |
| 169 | return; |
| 170 | } |
| 171 | |
| 172 | super.startDozing(); |
| 173 | } |
| 174 | |
| 175 | @Override |
| 176 | public void onDreamingStopped() { |
| 177 | if (DEBUG) Log.d(mTag, "onDreamingStopped isDozing=" + isDozing()); |
| 178 | super.onDreamingStopped(); |
| 179 | |
| 180 | mDreaming = false; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 181 | if (mWakeLock.isHeld()) { |
| 182 | mWakeLock.release(); |
| 183 | } |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 184 | listenForPulseSignals(false); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 185 | stopDozing(); |
| 186 | dozingStopped(); |
| 187 | } |
| 188 | |
| 189 | @Override |
| 190 | public void onDetachedFromWindow() { |
| 191 | if (DEBUG) Log.d(mTag, "onDetachedFromWindow"); |
| 192 | super.onDetachedFromWindow(); |
| 193 | |
| 194 | dozingStopped(); |
| 195 | } |
| 196 | |
| 197 | @Override |
| 198 | public void onDestroy() { |
| 199 | if (DEBUG) Log.d(mTag, "onDestroy"); |
| 200 | super.onDestroy(); |
| 201 | |
| 202 | dozingStopped(); |
| 203 | } |
| 204 | |
| 205 | private void requestDoze() { |
| 206 | if (mHost != null) { |
| 207 | mHost.requestDoze(this); |
| 208 | } |
| 209 | } |
| 210 | |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 211 | private void requestMultipulse() { |
| 212 | requestPulse(mMultipulseCount); |
| 213 | } |
| 214 | |
| 215 | private void requestPulse() { |
| 216 | requestPulse(1); |
| 217 | } |
| 218 | |
| 219 | private void requestPulse(int pulses) { |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 220 | if (mHost != null) { |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 221 | mHost.requestPulse(pulses, this); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | |
| 225 | private void dozingStopped() { |
| 226 | if (mHost != null) { |
| 227 | mHost.dozingStopped(this); |
| 228 | } |
| 229 | } |
| 230 | |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 231 | private void listenForPulseSignals(boolean listen) { |
| 232 | if (DEBUG) Log.d(mTag, "listenForPulseSignals: " + listen); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 233 | listenForSignificantMotion(listen); |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 234 | listenForBroadcasts(listen); |
John Spurlock | 6612727 | 2014-06-28 11:27:17 -0400 | [diff] [blame] | 235 | listenForNotifications(listen); |
| 236 | } |
| 237 | |
| 238 | private void listenForSignificantMotion(boolean listen) { |
| 239 | if (!mSigMotionConfigured || mSigMotionSensor == null) return; |
| 240 | if (listen) { |
| 241 | mSigMotionEnabled = |
| 242 | mSensors.requestTriggerSensor(mSigMotionListener, mSigMotionSensor); |
| 243 | } else if (mSigMotionEnabled) { |
| 244 | mSensors.cancelTriggerSensor(mSigMotionListener, mSigMotionSensor); |
| 245 | } |
| 246 | } |
| 247 | |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 248 | private void listenForBroadcasts(boolean listen) { |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 249 | if (listen) { |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 250 | final IntentFilter filter = new IntentFilter(PULSE_ACTION); |
| 251 | filter.addAction(NOTIFICATION_PULSE_ACTION); |
| 252 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 253 | mBroadcastReceiverRegistered = true; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 254 | } else { |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 255 | if (mBroadcastReceiverRegistered) { |
| 256 | mContext.unregisterReceiver(mBroadcastReceiver); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 257 | } |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 258 | mBroadcastReceiverRegistered = false; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | |
John Spurlock | 6612727 | 2014-06-28 11:27:17 -0400 | [diff] [blame] | 262 | private void listenForNotifications(boolean listen) { |
| 263 | if (mHost == null) return; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 264 | if (listen) { |
John Spurlock | 6612727 | 2014-06-28 11:27:17 -0400 | [diff] [blame] | 265 | mHost.addCallback(mHostCallback); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 266 | } else { |
John Spurlock | 6612727 | 2014-06-28 11:27:17 -0400 | [diff] [blame] | 267 | mHost.removeCallback(mHostCallback); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 271 | private void rescheduleNotificationPulse() { |
| 272 | mAlarmManager.cancel(mNotificationPulseIntent); |
| 273 | if (mNotificationLightOn) { |
| 274 | final long time = System.currentTimeMillis() + mNotificationPulseInterval; |
| 275 | if (DEBUG) Log.d(TAG, "Scheduling pulse for " + new Date(time)); |
| 276 | mAlarmManager.setExact(AlarmManager.RTC_WAKEUP, time, mNotificationPulseIntent); |
| 277 | } |
| 278 | } |
| 279 | |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 280 | private static String triggerEventToString(TriggerEvent event) { |
| 281 | if (event == null) return null; |
| 282 | final StringBuilder sb = new StringBuilder("TriggerEvent[") |
| 283 | .append(event.timestamp).append(',') |
| 284 | .append(event.sensor.getName()); |
| 285 | if (event.values != null) { |
| 286 | for (int i = 0; i < event.values.length; i++) { |
| 287 | sb.append(',').append(event.values[i]); |
| 288 | } |
| 289 | } |
| 290 | return sb.append(']').toString(); |
| 291 | } |
| 292 | |
John Spurlock | ed69bd6 | 2014-07-23 11:09:02 -0400 | [diff] [blame] | 293 | private final Runnable mDisplayOff = new Runnable() { |
| 294 | @Override |
| 295 | public void run() { |
| 296 | if (DEBUG) Log.d(TAG, "Display off"); |
| 297 | setDozeScreenState(Display.STATE_OFF); |
| 298 | setDozeScreenBrightness(PowerManager.BRIGHTNESS_DEFAULT); |
| 299 | } |
| 300 | }; |
| 301 | |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 302 | private final TriggerEventListener mSigMotionListener = new TriggerEventListener() { |
| 303 | @Override |
| 304 | public void onTrigger(TriggerEvent event) { |
| 305 | if (DEBUG) Log.d(mTag, "sigMotion.onTrigger: " + triggerEventToString(event)); |
| 306 | if (DEBUG) { |
| 307 | final Vibrator v = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE); |
| 308 | if (v != null) { |
| 309 | v.vibrate(1000); |
| 310 | } |
| 311 | } |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 312 | requestPulse(); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 313 | listenForSignificantMotion(true); // reregister, this sensor only fires once |
| 314 | } |
| 315 | }; |
| 316 | |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 317 | private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 318 | @Override |
| 319 | public void onReceive(Context context, Intent intent) { |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 320 | if (PULSE_ACTION.equals(intent.getAction())) { |
| 321 | if (DEBUG) Log.d(mTag, "Received pulse intent"); |
| 322 | requestPulse(intent.getIntExtra(EXTRA_PULSES, mMultipulseCount)); |
| 323 | } |
| 324 | if (NOTIFICATION_PULSE_ACTION.equals(intent.getAction())) { |
| 325 | if (DEBUG) Log.d(mTag, "Received notification pulse intent"); |
| 326 | requestPulse(); |
| 327 | rescheduleNotificationPulse(); |
| 328 | } |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 329 | } |
| 330 | }; |
| 331 | |
| 332 | private final Host.Callback mHostCallback = new Host.Callback() { |
| 333 | @Override |
| 334 | public void onNewNotifications() { |
| 335 | if (DEBUG) Log.d(mTag, "onNewNotifications"); |
John Spurlock | cad5768 | 2014-07-26 17:09:56 -0400 | [diff] [blame] | 336 | // noop for now |
| 337 | } |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 338 | |
John Spurlock | cad5768 | 2014-07-26 17:09:56 -0400 | [diff] [blame] | 339 | @Override |
| 340 | public void onBuzzBeepBlinked() { |
| 341 | if (DEBUG) Log.d(mTag, "onBuzzBeepBlinked"); |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 342 | requestMultipulse(); |
| 343 | } |
| 344 | |
| 345 | @Override |
| 346 | public void onNotificationLight(boolean on) { |
| 347 | if (DEBUG) Log.d(mTag, "onNotificationLight on=" + on); |
| 348 | if (mNotificationLightOn == on) return; |
| 349 | mNotificationLightOn = on; |
| 350 | rescheduleNotificationPulse(); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 351 | } |
| 352 | }; |
| 353 | |
| 354 | public interface Host { |
| 355 | void addCallback(Callback callback); |
| 356 | void removeCallback(Callback callback); |
| 357 | void requestDoze(DozeService dozeService); |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 358 | void requestPulse(int pulses, DozeService dozeService); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 359 | void dozingStopped(DozeService dozeService); |
| 360 | |
| 361 | public interface Callback { |
| 362 | void onNewNotifications(); |
John Spurlock | cad5768 | 2014-07-26 17:09:56 -0400 | [diff] [blame] | 363 | void onBuzzBeepBlinked(); |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame^] | 364 | void onNotificationLight(boolean on); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | } |