1 /*
2  * Copyright (C) 2019 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.attention;
18 
19 /**
20  * Attention manager local system server interface.
21  *
22  * @hide Only for use within the system server.
23  */
24 public abstract class AttentionManagerInternal {
25     /**
26      * Returns {@code true} if attention service is supported on this device.
27      */
isAttentionServiceSupported()28     public abstract boolean isAttentionServiceSupported();
29 
30     /**
31      * Checks whether user attention is at the screen and calls in the provided callback.
32      *
33      * @param timeoutMillis a budget for the attention check; if it takes longer - {@link
34      *                      AttentionCallbackInternal#onFailure} would be called with the {@link
35      *                      android.service.attention.AttentionService#ATTENTION_FAILURE_TIMED_OUT}
36      *                      code
37      * @param callback      a callback for when the attention check has completed
38      * @return {@code true} if the attention check should succeed.
39      */
checkAttention(long timeoutMillis, AttentionCallbackInternal callback)40     public abstract boolean checkAttention(long timeoutMillis, AttentionCallbackInternal callback);
41 
42     /**
43      * Cancels the specified attention check in case it's no longer needed.
44      *
45      * @param callback a callback that was used in {@link #checkAttention}
46      */
cancelAttentionCheck(AttentionCallbackInternal callback)47     public abstract void cancelAttentionCheck(AttentionCallbackInternal callback);
48 
49     /**
50      * Requests the continuous updates of proximity signal via the provided callback,
51      * until the given callback is unregistered. Currently, AttentionManagerService only
52      * anticipates one client and updates one client at a time.
53      *
54      * @param callback      a callback that receives the proximity updates
55      * @return {@code true} if the registration should succeed.
56      */
onStartProximityUpdates(ProximityUpdateCallbackInternal callback)57     public abstract boolean onStartProximityUpdates(ProximityUpdateCallbackInternal callback);
58 
59     /**
60      * Requests to stop providing continuous updates until the callback is registered.
61      *
62      * @param callback a callback that was used in {@link #onStartProximityUpdates}
63      */
onStopProximityUpdates(ProximityUpdateCallbackInternal callback)64     public abstract void onStopProximityUpdates(ProximityUpdateCallbackInternal callback);
65 
66     /** Internal interface for attention callback. */
67     public abstract static class AttentionCallbackInternal {
68         /**
69          * Provides the result of the attention check, if the check was successful.
70          *
71          * @param result      an int with the result of the check
72          * @param timestamp   a {@code SystemClock.uptimeMillis()} timestamp associated with the
73          *                    attention check
74          */
onSuccess(int result, long timestamp)75         public abstract void onSuccess(int result, long timestamp);
76 
77         /**
78          * Provides the explanation for why the attention check had failed.
79          *
80          * @param error       an int with the reason for failure
81          */
onFailure(int error)82         public abstract void onFailure(int error);
83     }
84 
85     /** Internal interface for proximity callback. */
86     public interface ProximityUpdateCallbackInternal {
87         /**
88          * @param distance the estimated distance of the user (in meter)
89          * The distance will be PROXIMITY_UNKNOWN if the proximity sensing was inconclusive.
90          */
onProximityUpdate(double distance)91         void onProximityUpdate(double distance);
92     }
93 }
94