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 | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 19 | import android.service.dreams.DreamService; |
| 20 | import android.util.Log; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 21 | |
Jason Monk | 59d86ed | 2017-01-04 15:13:11 -0500 | [diff] [blame] | 22 | import com.android.systemui.plugins.Plugin; |
| 23 | import com.android.systemui.plugins.PluginManager; |
| 24 | import com.android.systemui.plugins.doze.DozeProvider; |
| 25 | |
John Spurlock | 6612727 | 2014-06-28 11:27:17 -0400 | [diff] [blame] | 26 | import java.io.FileDescriptor; |
| 27 | import java.io.PrintWriter; |
| 28 | |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 29 | public class DozeService extends DreamService implements DozeMachine.Service { |
John Spurlock | ed69bd6 | 2014-07-23 11:09:02 -0400 | [diff] [blame] | 30 | private static final String TAG = "DozeService"; |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 31 | static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 32 | |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 33 | private DozeMachine mDozeMachine; |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 34 | |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 35 | public DozeService() { |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 36 | setDebug(DEBUG); |
| 37 | } |
| 38 | |
| 39 | @Override |
| 40 | public void onCreate() { |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 41 | super.onCreate(); |
| 42 | |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 43 | setWindowless(true); |
| 44 | |
Adrian Roos | 0b2e23a | 2017-01-03 12:13:49 -0800 | [diff] [blame^] | 45 | if (DozeFactory.getHost(this) == null) { |
| 46 | finish(); |
| 47 | return; |
| 48 | } |
| 49 | |
Jason Monk | 59d86ed | 2017-01-04 15:13:11 -0500 | [diff] [blame] | 50 | DozeProvider provider = PluginManager.getInstance(this) |
| 51 | .getOneShotPlugin(DozeProvider.ACTION, DozeProvider.VERSION); |
| 52 | mDozeMachine = new DozeFactory(provider).assembleMachine(this); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public void onDreamingStarted() { |
| 57 | super.onDreamingStarted(); |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 58 | mDozeMachine.requestState(DozeMachine.State.INITIALIZED); |
| 59 | startDozing(); |
John Spurlock | ed69bd6 | 2014-07-23 11:09:02 -0400 | [diff] [blame] | 60 | } |
| 61 | |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 62 | @Override |
| 63 | public void onDreamingStopped() { |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 64 | super.onDreamingStopped(); |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 65 | mDozeMachine.requestState(DozeMachine.State.FINISH); |
John Spurlock | cb566aa | 2014-08-03 22:58:28 -0400 | [diff] [blame] | 66 | } |
| 67 | |
Adrian Roos | ea8d6ae | 2016-10-26 10:40:12 -0700 | [diff] [blame] | 68 | @Override |
Adrian Roos | ff2c456 | 2016-11-03 12:13:36 -0700 | [diff] [blame] | 69 | protected void dumpOnHandler(FileDescriptor fd, PrintWriter pw, String[] args) { |
Adrian Roos | 0b2e23a | 2017-01-03 12:13:49 -0800 | [diff] [blame^] | 70 | if (mDozeMachine != null) { |
| 71 | mDozeMachine.dump(pw); |
| 72 | } |
John Spurlock | 92b8d41 | 2014-10-03 17:12:40 -0400 | [diff] [blame] | 73 | } |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 74 | } |