• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 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 #include "trusty_time_stamper.h"
18 
19 #include <limits>
20 
21 #include <inttypes.h>
22 #include <stdio.h>
23 #include <trusty/time.h>
24 
25 #include <trusty_log.h>
26 
27 #define TLOG_TAG "confirmationui"
28 
29 namespace monotonic_time_stamper {
30 
now()31 TimeStamp now() {
32     int rv;
33     int64_t secure_time_ns = 0;
34     rv = trusty_gettime(0, &secure_time_ns);
35     if (rv || secure_time_ns < 0) {
36         TLOGE("Error getting time. Error: %d, time: %" PRIu64, rv,
37               secure_time_ns);
38         return 0;  // 0 is considered invalid. see TimeStamp::isOk()
39     }
40     return static_cast<uint64_t>(secure_time_ns) / 1000000;
41 }
42 
43 }  // namespace monotonic_time_stamper
44