xref: /aosp_15_r20/external/libchrome/base/time/time_android.cc (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard Worker // Copyright 2018 The Chromium Authors. All rights reserved.
2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file.
4*635a8641SAndroid Build Coastguard Worker 
5*635a8641SAndroid Build Coastguard Worker #include "base/time/time.h"
6*635a8641SAndroid Build Coastguard Worker 
7*635a8641SAndroid Build Coastguard Worker namespace base {
8*635a8641SAndroid Build Coastguard Worker 
9*635a8641SAndroid Build Coastguard Worker // static
FromUptimeMillis(jlong uptime_millis_value)10*635a8641SAndroid Build Coastguard Worker TimeTicks TimeTicks::FromUptimeMillis(jlong uptime_millis_value) {
11*635a8641SAndroid Build Coastguard Worker   // The implementation of the SystemClock.uptimeMillis() in AOSP uses the same
12*635a8641SAndroid Build Coastguard Worker   // clock as base::TimeTicks::Now(): clock_gettime(CLOCK_MONOTONIC), see in
13*635a8641SAndroid Build Coastguard Worker   // platform/system/code:
14*635a8641SAndroid Build Coastguard Worker   // 1. libutils/SystemClock.cpp
15*635a8641SAndroid Build Coastguard Worker   // 2. libutils/Timers.cpp
16*635a8641SAndroid Build Coastguard Worker   //
17*635a8641SAndroid Build Coastguard Worker   // We are not aware of any motivations for Android OEMs to modify the AOSP
18*635a8641SAndroid Build Coastguard Worker   // implementation of either uptimeMillis() or clock_gettime(CLOCK_MONOTONIC),
19*635a8641SAndroid Build Coastguard Worker   // so we assume that there are no such customizations.
20*635a8641SAndroid Build Coastguard Worker   //
21*635a8641SAndroid Build Coastguard Worker   // Under these assumptions the conversion is as safe as copying the value of
22*635a8641SAndroid Build Coastguard Worker   // base::TimeTicks::Now() with a loss of sub-millisecond precision.
23*635a8641SAndroid Build Coastguard Worker   return TimeTicks(uptime_millis_value * Time::kMicrosecondsPerMillisecond);
24*635a8641SAndroid Build Coastguard Worker }
25*635a8641SAndroid Build Coastguard Worker 
26*635a8641SAndroid Build Coastguard Worker }  // namespace base
27