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 19 import android.os.PowerManager; 20 import android.os.SystemClock; 21 import android.service.dreams.DreamService; 22 import android.util.Log; 23 24 import com.android.systemui.Dependency; 25 import com.android.systemui.plugins.Plugin; 26 import com.android.systemui.plugins.PluginManager; 27 28 import java.io.FileDescriptor; 29 import java.io.PrintWriter; 30 31 public class DozeService extends DreamService implements DozeMachine.Service { 32 private static final String TAG = "DozeService"; 33 static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); 34 35 private DozeMachine mDozeMachine; 36 DozeService()37 public DozeService() { 38 setDebug(DEBUG); 39 } 40 41 @Override onCreate()42 public void onCreate() { 43 super.onCreate(); 44 45 setWindowless(true); 46 47 if (DozeFactory.getHost(this) == null) { 48 finish(); 49 return; 50 } 51 52 mDozeMachine = new DozeFactory().assembleMachine(this); 53 } 54 55 @Override onDreamingStarted()56 public void onDreamingStarted() { 57 super.onDreamingStarted(); 58 mDozeMachine.requestState(DozeMachine.State.INITIALIZED); 59 startDozing(); 60 } 61 62 @Override onDreamingStopped()63 public void onDreamingStopped() { 64 super.onDreamingStopped(); 65 mDozeMachine.requestState(DozeMachine.State.FINISH); 66 } 67 68 @Override dumpOnHandler(FileDescriptor fd, PrintWriter pw, String[] args)69 protected void dumpOnHandler(FileDescriptor fd, PrintWriter pw, String[] args) { 70 if (mDozeMachine != null) { 71 mDozeMachine.dump(pw); 72 } 73 } 74 75 @Override requestWakeUp()76 public void requestWakeUp() { 77 PowerManager pm = getSystemService(PowerManager.class); 78 pm.wakeUp(SystemClock.uptimeMillis(), "com.android.systemui:NODOZE"); 79 } 80 } 81