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     /** Internal interface for attention callback. */
50     public abstract static class AttentionCallbackInternal {
51         /**
52          * Provides the result of the attention check, if the check was successful.
53          *
54          * @param result      an int with the result of the check
55          * @param timestamp   a {@code SystemClock.uptimeMillis()} timestamp associated with the
56          *                    attention check
57          */
onSuccess(int result, long timestamp)58         public abstract void onSuccess(int result, long timestamp);
59 
60         /**
61          * Provides the explanation for why the attention check had failed.
62          *
63          * @param error       an int with the reason for failure
64          */
onFailure(int error)65         public abstract void onFailure(int error);
66     }
67 }
68