blob: e55a597223853cc42c0e61f67446e582a0fa247c [file] [log] [blame]
John Spurlockbf370992014-06-17 13:58:31 -04001/*
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
17package com.android.systemui.doze;
18
Adrian Roos4fb1f512017-02-14 14:01:32 +010019import android.os.PowerManager;
20import android.os.SystemClock;
John Spurlockbf370992014-06-17 13:58:31 -040021import android.service.dreams.DreamService;
22import android.util.Log;
John Spurlockbf370992014-06-17 13:58:31 -040023
Jason Monkde850bb2017-02-01 19:26:30 -050024import com.android.systemui.Dependency;
Jason Monk59d86ed2017-01-04 15:13:11 -050025import com.android.systemui.plugins.Plugin;
26import com.android.systemui.plugins.PluginManager;
27import com.android.systemui.plugins.doze.DozeProvider;
28
John Spurlock66127272014-06-28 11:27:17 -040029import java.io.FileDescriptor;
30import java.io.PrintWriter;
31
Adrian Roosff2c4562016-11-03 12:13:36 -070032public class DozeService extends DreamService implements DozeMachine.Service {
John Spurlocked69bd62014-07-23 11:09:02 -040033 private static final String TAG = "DozeService";
Adrian Roosea8d6ae2016-10-26 10:40:12 -070034 static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
John Spurlockbf370992014-06-17 13:58:31 -040035
Adrian Roosff2c4562016-11-03 12:13:36 -070036 private DozeMachine mDozeMachine;
Adrian Roosb7e4e102016-10-14 13:03:45 -070037
John Spurlockbf370992014-06-17 13:58:31 -040038 public DozeService() {
John Spurlockbf370992014-06-17 13:58:31 -040039 setDebug(DEBUG);
40 }
41
42 @Override
43 public void onCreate() {
John Spurlockbf370992014-06-17 13:58:31 -040044 super.onCreate();
45
John Spurlockbf370992014-06-17 13:58:31 -040046 setWindowless(true);
47
Adrian Roos0b2e23a2017-01-03 12:13:49 -080048 if (DozeFactory.getHost(this) == null) {
49 finish();
50 return;
51 }
52
Jason Monkde850bb2017-02-01 19:26:30 -050053 DozeProvider provider = Dependency.get(PluginManager.class)
Jason Monk5bec68f2017-02-08 20:45:10 -080054 .getOneShotPlugin(DozeProvider.class);
Jason Monk59d86ed2017-01-04 15:13:11 -050055 mDozeMachine = new DozeFactory(provider).assembleMachine(this);
John Spurlockbf370992014-06-17 13:58:31 -040056 }
57
58 @Override
59 public void onDreamingStarted() {
60 super.onDreamingStarted();
Adrian Roosff2c4562016-11-03 12:13:36 -070061 mDozeMachine.requestState(DozeMachine.State.INITIALIZED);
62 startDozing();
John Spurlocked69bd62014-07-23 11:09:02 -040063 }
64
John Spurlockbf370992014-06-17 13:58:31 -040065 @Override
66 public void onDreamingStopped() {
John Spurlockbf370992014-06-17 13:58:31 -040067 super.onDreamingStopped();
Adrian Roosff2c4562016-11-03 12:13:36 -070068 mDozeMachine.requestState(DozeMachine.State.FINISH);
John Spurlockcb566aa2014-08-03 22:58:28 -040069 }
70
Adrian Roosea8d6ae2016-10-26 10:40:12 -070071 @Override
Adrian Roosff2c4562016-11-03 12:13:36 -070072 protected void dumpOnHandler(FileDescriptor fd, PrintWriter pw, String[] args) {
Adrian Roos0b2e23a2017-01-03 12:13:49 -080073 if (mDozeMachine != null) {
74 mDozeMachine.dump(pw);
75 }
John Spurlock92b8d412014-10-03 17:12:40 -040076 }
Adrian Roos4fb1f512017-02-14 14:01:32 +010077
78 @Override
79 public void requestWakeUp() {
80 PowerManager pm = getSystemService(PowerManager.class);
81 pm.wakeUp(SystemClock.uptimeMillis(), "com.android.systemui:NODOZE");
82 }
John Spurlockbf370992014-06-17 13:58:31 -040083}