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