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 android.service.dreams;
18 
19 
20 /**
21  * Dream manager local system service interface.
22  *
23  * @hide Only for use within the system server.
24  */
25 public abstract class DreamManagerInternal {
26     /**
27      * Called by the power manager to start a dream.
28      *
29      * @param doze If true, starts the doze dream component if one has been configured,
30      * otherwise starts the user-specified dream.
31      * @param reason The reason to start dreaming, which is logged to help debugging.
32      */
startDream(boolean doze, String reason)33     public abstract void startDream(boolean doze, String reason);
34 
35     /**
36      * Called by the power manager to stop a dream.
37      *
38      * @param immediate If true, ends the dream summarily, otherwise gives it some time
39      * to perform a proper exit transition.
40      * @param reason The reason to stop dreaming, which is logged to help debugging.
41      */
stopDream(boolean immediate, String reason)42     public abstract void stopDream(boolean immediate, String reason);
43 
44     /**
45      * Called by the power manager to determine whether a dream is running.
46      */
isDreaming()47     public abstract boolean isDreaming();
48 
49     /**
50      * Ask the power manager to nap.  It will eventually call back into startDream() if/when it is
51      * appropriate to start dreaming.
52      */
requestDream()53     public abstract void requestDream();
54 
55     /**
56      * Whether dreaming can start given user settings and the current dock/charge state.
57      *
58      * @param isScreenOn True if the screen is currently on.
59      */
canStartDreaming(boolean isScreenOn)60     public abstract boolean canStartDreaming(boolean isScreenOn);
61 
62     /**
63      * Register a {@link DreamManagerStateListener}, which will be called when there are changes to
64      * dream state.
65      *
66      * @param listener The listener to register.
67      */
registerDreamManagerStateListener(DreamManagerStateListener listener)68     public abstract void registerDreamManagerStateListener(DreamManagerStateListener listener);
69 
70     /**
71      * Unregister a {@link DreamManagerStateListener}, which will be called when there are changes
72      * to dream state.
73      *
74      * @param listener The listener to unregister.
75      */
unregisterDreamManagerStateListener(DreamManagerStateListener listener)76     public abstract void unregisterDreamManagerStateListener(DreamManagerStateListener listener);
77 
78     /**
79      * Called when there are changes to dream state.
80      */
81     public interface DreamManagerStateListener {
82         /**
83          * Called when keep dreaming when plug has changed.
84          *
85          * @param keepDreaming True if the current dream should continue when undocking.
86          */
onKeepDreamingWhenUnpluggingChanged(boolean keepDreaming)87         default void onKeepDreamingWhenUnpluggingChanged(boolean keepDreaming) {
88         }
89 
90         /**
91          * Called when dreaming has started.
92          */
onDreamingStarted()93         default void onDreamingStarted() {
94         }
95 
96         /**
97          * Called when dreaming has stopped.
98          */
onDreamingStopped()99         default void onDreamingStopped() {
100         }
101     }
102 }
103