xref: /aosp_15_r20/external/cronet/base/process/process_android.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2021 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "base/process/process.h"
6 
7 #include "base/notimplemented.h"
8 #include "base/process/internal_linux.h"
9 
10 namespace base {
11 
12 // static
CanSetPriority()13 bool Process::CanSetPriority() {
14   return false;
15 }
16 
GetPriority() const17 Process::Priority Process::GetPriority() const {
18   // See SetPriority().
19   DCHECK(IsValid());
20   return Priority::kUserBlocking;
21 }
22 
SetPriority(Priority priority)23 bool Process::SetPriority(Priority priority) {
24   // Not implemented for POSIX systems other than Linux and Mac. With POSIX, if
25   // we were to lower the process priority we wouldn't be able to raise it back
26   // to its initial priority.
27   NOTIMPLEMENTED();
28   return false;
29 }
30 
CreationTime() const31 Time Process::CreationTime() const {
32   // On Android, /proc is mounted (on recent-enough versions) with hidepid=2,
33   // which hides other PIDs in /proc. This means that only /proc/self is
34   // accessible. Instead of trying (and failing) to read the file, don't attempt
35   // to read it. This also provides consistency across releases.
36   int64_t start_ticks = is_current()
37                             ? internal::ReadProcSelfStatsAndGetFieldAsInt64(
38                                   internal::VM_STARTTIME)
39                             : 0;
40 
41   if (!start_ticks)
42     return Time();
43 
44   TimeDelta start_offset = internal::ClockTicksToTimeDelta(start_ticks);
45   Time boot_time = internal::GetBootTime();
46   if (boot_time.is_null())
47     return Time();
48   return Time(boot_time + start_offset);
49 }
50 
51 }  // namespace base
52