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