xref: /aosp_15_r20/system/chre/host/common/include/chre_host/time_syncer.h (revision 84e339476a462649f82315436d70fd732297a399)
1 /*
2  * Copyright (C) 2022 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 #ifndef CHRE_HOST_TIME_SYNCER_H_
18 #define CHRE_HOST_TIME_SYNCER_H_
19 
20 #include <cstdint>
21 #include <string>
22 
23 #include "chre_connection.h"
24 
25 namespace android::chre {
26 
27 using hardware::contexthub::common::implementation::ChreConnection;
28 
29 /** The functions synchronizing time between the Context hub and Android. */
30 class TimeSyncer final {
31  public:
32   /**
33    * Sends time sync message to Context hub and retries numRetries times until
34    * success.
35    *
36    * If the platform doesn't require the time sync the request will be ignored
37    * and true is returned.
38    *
39    * @return true if success, false otherwise.
40    */
41   static bool sendTimeSyncWithRetry(ChreConnection *connection,
42                                     size_t numOfRetries,
43                                     useconds_t retryDelayUs);
44 
45   /**
46    * Sends a time sync message to Context hub for once.
47    *
48    * If the platform doesn't require the time sync the request will be ignored
49    * and true is returned.
50    *
51    * @return true if success, false otherwise.
52    */
53   static bool sendTimeSync(ChreConnection *connection);
54 
55  private:
56   TimeSyncer() = default;
57 };
58 
59 }  // namespace android::chre
60 
61 #endif  // CHRE_HOST_TIME_SYNCER_H_