1 /*
2  * Copyright 2017 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 package android.hardware.location;
17 
18 import android.annotation.SystemApi;
19 
20 import java.util.concurrent.Executor;
21 
22 /**
23  * A class for {@link android.hardware.location.ContextHubClient ContextHubClient} to
24  * receive messages and life-cycle events from nanoapps in the Context Hub at which the client is
25  * attached to.
26  *
27  * This callback is registered through the {@link
28  * android.hardware.location.ContextHubManager#createClient(
29  * ContextHubInfo, ContextHubClientCallback, Executor) creation} of
30  * {@link android.hardware.location.ContextHubClient ContextHubClient}. Callbacks are invoked in
31  * the following ways:
32  * 1) Messages from nanoapps delivered through onMessageFromNanoApp may either be broadcasted
33  *    or targeted to a specific client.
34  * 2) Nanoapp or Context Hub events (the remaining callbacks) are broadcasted to all clients, and
35  *    the client can choose to ignore the event by filtering through the parameters.
36  *
37  * @hide
38  */
39 @SystemApi
40 public class ContextHubClientCallback {
41     /**
42      * Callback invoked when receiving a message from a nanoapp.
43      *
44      * The message contents of this callback may either be broadcasted or targeted to the
45      * client receiving the invocation.
46      *
47      * @param client the client that is associated with this callback
48      * @param message the message sent by the nanoapp
49      */
onMessageFromNanoApp(ContextHubClient client, NanoAppMessage message)50     public void onMessageFromNanoApp(ContextHubClient client, NanoAppMessage message) {}
51 
52     /**
53      * Callback invoked when the attached Context Hub has reset.
54      *
55      * @param client the client that is associated with this callback
56      */
onHubReset(ContextHubClient client)57     public void onHubReset(ContextHubClient client) {}
58 
59     /**
60      * Callback invoked when a nanoapp aborts at the attached Context Hub.
61      *
62      * @param client the client that is associated with this callback
63      * @param nanoAppId the ID of the nanoapp that had aborted
64      * @param abortCode the reason for nanoapp's abort, specific to each nanoapp
65      */
onNanoAppAborted(ContextHubClient client, long nanoAppId, int abortCode)66     public void onNanoAppAborted(ContextHubClient client, long nanoAppId, int abortCode) {}
67 
68     /**
69      * Callback invoked when a nanoapp is dynamically loaded at the attached Context Hub through
70      * the {@link android.hardware.location.ContextHubManager}. This callback is not invoked for a
71      * nanoapp that is loaded internally by CHRE (e.g. nanoapps that are preloaded by the system).
72      *
73      * @param client the client that is associated with this callback
74      * @param nanoAppId the ID of the nanoapp that had been loaded
75      */
onNanoAppLoaded(ContextHubClient client, long nanoAppId)76     public void onNanoAppLoaded(ContextHubClient client, long nanoAppId) {}
77 
78     /**
79      * Callback invoked when a nanoapp is dynamically unloaded from the attached Context Hub through
80      * the {@link android.hardware.location.ContextHubManager}.
81      *
82      * @param client the client that is associated with this callback
83      * @param nanoAppId the ID of the nanoapp that had been unloaded
84      */
onNanoAppUnloaded(ContextHubClient client, long nanoAppId)85     public void onNanoAppUnloaded(ContextHubClient client, long nanoAppId) {}
86 
87     /**
88      * Callback invoked when a nanoapp is dynamically enabled at the attached Context Hub through
89      * the {@link android.hardware.location.ContextHubManager}.
90      *
91      * @param client the client that is associated with this callback
92      * @param nanoAppId the ID of the nanoapp that had been enabled
93      */
onNanoAppEnabled(ContextHubClient client, long nanoAppId)94     public void onNanoAppEnabled(ContextHubClient client, long nanoAppId) {}
95 
96     /**
97      * Callback invoked when a nanoapp is dynamically disabled at the attached Context Hub through
98      * the {@link android.hardware.location.ContextHubManager}.
99      *
100      * @param client the client that is associated with this callback
101      * @param nanoAppId the ID of the nanoapp that had been disabled
102      */
onNanoAppDisabled(ContextHubClient client, long nanoAppId)103     public void onNanoAppDisabled(ContextHubClient client, long nanoAppId) {}
104 }
105