blob: 828728f0ae9e7da4acf519b5a8589678905bf370 [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
John Spurlockbf370992014-06-17 13:58:31 -040019import android.service.dreams.DreamService;
20import android.util.Log;
John Spurlockbf370992014-06-17 13:58:31 -040021
Jason Monk59d86ed2017-01-04 15:13:11 -050022import com.android.systemui.plugins.Plugin;
23import com.android.systemui.plugins.PluginManager;
24import com.android.systemui.plugins.doze.DozeProvider;
25
John Spurlock66127272014-06-28 11:27:17 -040026import java.io.FileDescriptor;
27import java.io.PrintWriter;
28
Adrian Roosff2c4562016-11-03 12:13:36 -070029public class DozeService extends DreamService implements DozeMachine.Service {
John Spurlocked69bd62014-07-23 11:09:02 -040030 private static final String TAG = "DozeService";
Adrian Roosea8d6ae2016-10-26 10:40:12 -070031 static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
John Spurlockbf370992014-06-17 13:58:31 -040032
Adrian Roosff2c4562016-11-03 12:13:36 -070033 private DozeMachine mDozeMachine;
Adrian Roosb7e4e102016-10-14 13:03:45 -070034
John Spurlockbf370992014-06-17 13:58:31 -040035 public DozeService() {
John Spurlockbf370992014-06-17 13:58:31 -040036 setDebug(DEBUG);
37 }
38
39 @Override
40 public void onCreate() {
John Spurlockbf370992014-06-17 13:58:31 -040041 super.onCreate();
42
John Spurlockbf370992014-06-17 13:58:31 -040043 setWindowless(true);
44
Adrian Roos0b2e23a2017-01-03 12:13:49 -080045 if (DozeFactory.getHost(this) == null) {
46 finish();
47 return;
48 }
49
Jason Monk59d86ed2017-01-04 15:13:11 -050050 DozeProvider provider = PluginManager.getInstance(this)
51 .getOneShotPlugin(DozeProvider.ACTION, DozeProvider.VERSION);
52 mDozeMachine = new DozeFactory(provider).assembleMachine(this);
John Spurlockbf370992014-06-17 13:58:31 -040053 }
54
55 @Override
56 public void onDreamingStarted() {
57 super.onDreamingStarted();
Adrian Roosff2c4562016-11-03 12:13:36 -070058 mDozeMachine.requestState(DozeMachine.State.INITIALIZED);
59 startDozing();
John Spurlocked69bd62014-07-23 11:09:02 -040060 }
61
John Spurlockbf370992014-06-17 13:58:31 -040062 @Override
63 public void onDreamingStopped() {
John Spurlockbf370992014-06-17 13:58:31 -040064 super.onDreamingStopped();
Adrian Roosff2c4562016-11-03 12:13:36 -070065 mDozeMachine.requestState(DozeMachine.State.FINISH);
John Spurlockcb566aa2014-08-03 22:58:28 -040066 }
67
Adrian Roosea8d6ae2016-10-26 10:40:12 -070068 @Override
Adrian Roosff2c4562016-11-03 12:13:36 -070069 protected void dumpOnHandler(FileDescriptor fd, PrintWriter pw, String[] args) {
Adrian Roos0b2e23a2017-01-03 12:13:49 -080070 if (mDozeMachine != null) {
71 mDozeMachine.dump(pw);
72 }
John Spurlock92b8d412014-10-03 17:12:40 -040073 }
John Spurlockbf370992014-06-17 13:58:31 -040074}