xref: /aosp_15_r20/external/cronet/base/system/sys_info.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1*6777b538SAndroid Build Coastguard Worker // Copyright 2012 The Chromium Authors
2*6777b538SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*6777b538SAndroid Build Coastguard Worker // found in the LICENSE file.
4*6777b538SAndroid Build Coastguard Worker 
5*6777b538SAndroid Build Coastguard Worker #ifndef BASE_SYSTEM_SYS_INFO_H_
6*6777b538SAndroid Build Coastguard Worker #define BASE_SYSTEM_SYS_INFO_H_
7*6777b538SAndroid Build Coastguard Worker 
8*6777b538SAndroid Build Coastguard Worker #include <stddef.h>
9*6777b538SAndroid Build Coastguard Worker #include <stdint.h>
10*6777b538SAndroid Build Coastguard Worker 
11*6777b538SAndroid Build Coastguard Worker #include <map>
12*6777b538SAndroid Build Coastguard Worker #include <optional>
13*6777b538SAndroid Build Coastguard Worker #include <string>
14*6777b538SAndroid Build Coastguard Worker #include <string_view>
15*6777b538SAndroid Build Coastguard Worker 
16*6777b538SAndroid Build Coastguard Worker #include "base/base_export.h"
17*6777b538SAndroid Build Coastguard Worker #include "base/functional/callback_forward.h"
18*6777b538SAndroid Build Coastguard Worker #include "base/gtest_prod_util.h"
19*6777b538SAndroid Build Coastguard Worker #include "base/metrics/field_trial_params.h"
20*6777b538SAndroid Build Coastguard Worker #include "base/time/time.h"
21*6777b538SAndroid Build Coastguard Worker #include "build/build_config.h"
22*6777b538SAndroid Build Coastguard Worker 
23*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_MAC)
24*6777b538SAndroid Build Coastguard Worker #include "base/feature_list.h"
25*6777b538SAndroid Build Coastguard Worker #endif
26*6777b538SAndroid Build Coastguard Worker 
27*6777b538SAndroid Build Coastguard Worker namespace base {
28*6777b538SAndroid Build Coastguard Worker 
29*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_MAC)
30*6777b538SAndroid Build Coastguard Worker // When enabled, NumberOfProcessors() returns the number of physical processors
31*6777b538SAndroid Build Coastguard Worker // instead of the number of logical processors if CPU security mitigations are
32*6777b538SAndroid Build Coastguard Worker // enabled for the current process.
33*6777b538SAndroid Build Coastguard Worker BASE_EXPORT BASE_DECLARE_FEATURE(kNumberOfCoresWithCpuSecurityMitigation);
34*6777b538SAndroid Build Coastguard Worker #endif
35*6777b538SAndroid Build Coastguard Worker 
36*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_CHROMEOS_ASH)
37*6777b538SAndroid Build Coastguard Worker // Strings for environment variables.
38*6777b538SAndroid Build Coastguard Worker BASE_EXPORT extern const char kLsbReleaseKey[];
39*6777b538SAndroid Build Coastguard Worker BASE_EXPORT extern const char kLsbReleaseTimeKey[];
40*6777b538SAndroid Build Coastguard Worker #endif
41*6777b538SAndroid Build Coastguard Worker 
42*6777b538SAndroid Build Coastguard Worker namespace debug {
43*6777b538SAndroid Build Coastguard Worker FORWARD_DECLARE_TEST(SystemMetricsTest, ParseMeminfo);
44*6777b538SAndroid Build Coastguard Worker }
45*6777b538SAndroid Build Coastguard Worker 
46*6777b538SAndroid Build Coastguard Worker namespace test {
47*6777b538SAndroid Build Coastguard Worker class ScopedAmountOfPhysicalMemoryOverride;
48*6777b538SAndroid Build Coastguard Worker }
49*6777b538SAndroid Build Coastguard Worker 
50*6777b538SAndroid Build Coastguard Worker class FilePath;
51*6777b538SAndroid Build Coastguard Worker struct SystemMemoryInfoKB;
52*6777b538SAndroid Build Coastguard Worker 
53*6777b538SAndroid Build Coastguard Worker class BASE_EXPORT SysInfo {
54*6777b538SAndroid Build Coastguard Worker  public:
55*6777b538SAndroid Build Coastguard Worker   // Returns the number of processors/cores available for the current
56*6777b538SAndroid Build Coastguard Worker   // application. This is typically the number of logical cores installed on the
57*6777b538SAndroid Build Coastguard Worker   // system, but could instead be the number of physical cores when
58*6777b538SAndroid Build Coastguard Worker   // SetCpuSecurityMitigationsEnabled() has been invoked to indicate that CPU
59*6777b538SAndroid Build Coastguard Worker   // security mitigations are enabled on Mac.
60*6777b538SAndroid Build Coastguard Worker   // On some platforms this may cache the resulting value in its implementation,
61*6777b538SAndroid Build Coastguard Worker   // e.g. on Linux/ChromeOS where this function cannot run in a sandbox and so
62*6777b538SAndroid Build Coastguard Worker   // a cached value must be returned.
63*6777b538SAndroid Build Coastguard Worker   static int NumberOfProcessors();
64*6777b538SAndroid Build Coastguard Worker 
65*6777b538SAndroid Build Coastguard Worker   // Returns the number of the most efficient logical processors for the current
66*6777b538SAndroid Build Coastguard Worker   // application. This is typically e-cores on Intel hybrid architecture, or
67*6777b538SAndroid Build Coastguard Worker   // LITTLE cores on ARM bit.LITTLE architecture.
68*6777b538SAndroid Build Coastguard Worker   // Returns 0 on symmetric architecture or when it failed to recognize.
69*6777b538SAndroid Build Coastguard Worker   // This function will cache the result value in its implementation.
70*6777b538SAndroid Build Coastguard Worker   static int NumberOfEfficientProcessors();
71*6777b538SAndroid Build Coastguard Worker 
72*6777b538SAndroid Build Coastguard Worker   // Return the number of bytes of physical memory on the current machine.
73*6777b538SAndroid Build Coastguard Worker   // If low-end device mode is manually enabled via command line flag, this
74*6777b538SAndroid Build Coastguard Worker   // will return the lesser of the actual physical memory, or 512MB.
75*6777b538SAndroid Build Coastguard Worker   static uint64_t AmountOfPhysicalMemory();
76*6777b538SAndroid Build Coastguard Worker 
77*6777b538SAndroid Build Coastguard Worker   // Return the number of bytes of current available physical memory on the
78*6777b538SAndroid Build Coastguard Worker   // machine.
79*6777b538SAndroid Build Coastguard Worker   // (The amount of memory that can be allocated without any significant
80*6777b538SAndroid Build Coastguard Worker   // impact on the system. It can lead to freeing inactive file-backed
81*6777b538SAndroid Build Coastguard Worker   // and/or speculative file-backed memory).
82*6777b538SAndroid Build Coastguard Worker   static uint64_t AmountOfAvailablePhysicalMemory();
83*6777b538SAndroid Build Coastguard Worker 
84*6777b538SAndroid Build Coastguard Worker   // Return the number of bytes of virtual memory of this process. A return
85*6777b538SAndroid Build Coastguard Worker   // value of zero means that there is no limit on the available virtual
86*6777b538SAndroid Build Coastguard Worker   // memory.
87*6777b538SAndroid Build Coastguard Worker   static uint64_t AmountOfVirtualMemory();
88*6777b538SAndroid Build Coastguard Worker 
89*6777b538SAndroid Build Coastguard Worker   // Return the number of megabytes of physical memory on the current machine.
AmountOfPhysicalMemoryMB()90*6777b538SAndroid Build Coastguard Worker   static int AmountOfPhysicalMemoryMB() {
91*6777b538SAndroid Build Coastguard Worker     return static_cast<int>(AmountOfPhysicalMemory() / 1024 / 1024);
92*6777b538SAndroid Build Coastguard Worker   }
93*6777b538SAndroid Build Coastguard Worker 
94*6777b538SAndroid Build Coastguard Worker   // Return the number of megabytes of available virtual memory, or zero if it
95*6777b538SAndroid Build Coastguard Worker   // is unlimited.
AmountOfVirtualMemoryMB()96*6777b538SAndroid Build Coastguard Worker   static int AmountOfVirtualMemoryMB() {
97*6777b538SAndroid Build Coastguard Worker     return static_cast<int>(AmountOfVirtualMemory() / 1024 / 1024);
98*6777b538SAndroid Build Coastguard Worker   }
99*6777b538SAndroid Build Coastguard Worker 
100*6777b538SAndroid Build Coastguard Worker   // Return the available disk space in bytes on the volume containing |path|,
101*6777b538SAndroid Build Coastguard Worker   // or -1 on failure.
102*6777b538SAndroid Build Coastguard Worker   static int64_t AmountOfFreeDiskSpace(const FilePath& path);
103*6777b538SAndroid Build Coastguard Worker 
104*6777b538SAndroid Build Coastguard Worker   // Return the total disk space in bytes on the volume containing |path|, or -1
105*6777b538SAndroid Build Coastguard Worker   // on failure.
106*6777b538SAndroid Build Coastguard Worker   static int64_t AmountOfTotalDiskSpace(const FilePath& path);
107*6777b538SAndroid Build Coastguard Worker 
108*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_FUCHSIA)
109*6777b538SAndroid Build Coastguard Worker   // Sets the total amount of disk space to report under the specified |path|.
110*6777b538SAndroid Build Coastguard Worker   // If |bytes| is -ve then any existing entry for |path| is removed.
111*6777b538SAndroid Build Coastguard Worker   static void SetAmountOfTotalDiskSpace(const FilePath& path, int64_t bytes);
112*6777b538SAndroid Build Coastguard Worker #endif
113*6777b538SAndroid Build Coastguard Worker 
114*6777b538SAndroid Build Coastguard Worker   // Returns system uptime.
115*6777b538SAndroid Build Coastguard Worker   static TimeDelta Uptime();
116*6777b538SAndroid Build Coastguard Worker 
117*6777b538SAndroid Build Coastguard Worker   // Returns a descriptive string for the current machine model or an empty
118*6777b538SAndroid Build Coastguard Worker   // string if the machine model is unknown or an error occurred.
119*6777b538SAndroid Build Coastguard Worker   // e.g. "MacPro1,1" on Mac, "iPhone9,3" on iOS or "Nexus 5" on Android. Only
120*6777b538SAndroid Build Coastguard Worker   // implemented on macOS, iOS, Android, Chrome OS and Windows. This returns an
121*6777b538SAndroid Build Coastguard Worker   // empty string on other platforms.
122*6777b538SAndroid Build Coastguard Worker   //
123*6777b538SAndroid Build Coastguard Worker   // For macOS, a useful reference of the resulting strings returned by this
124*6777b538SAndroid Build Coastguard Worker   // function and their corresponding hardware can be found at
125*6777b538SAndroid Build Coastguard Worker   // https://everymac.com/systems/by_capability/mac-specs-by-machine-model-machine-id.html
126*6777b538SAndroid Build Coastguard Worker   //
127*6777b538SAndroid Build Coastguard Worker   // For iOS, corresponding hardware can be found at
128*6777b538SAndroid Build Coastguard Worker   // https://deviceatlas.com/resources/clientside/ios-hardware-identification
129*6777b538SAndroid Build Coastguard Worker   static std::string HardwareModelName();
130*6777b538SAndroid Build Coastguard Worker 
131*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_MAC)
132*6777b538SAndroid Build Coastguard Worker   struct HardwareModelNameSplit {
133*6777b538SAndroid Build Coastguard Worker     std::string category;
134*6777b538SAndroid Build Coastguard Worker     int model = 0;
135*6777b538SAndroid Build Coastguard Worker     int variant = 0;
136*6777b538SAndroid Build Coastguard Worker   };
137*6777b538SAndroid Build Coastguard Worker   // Hardware model names on the Mac are of the shape "Mac��,��" where the
138*6777b538SAndroid Build Coastguard Worker   // prefix is the general category, the �� is the model, and the �� is the
139*6777b538SAndroid Build Coastguard Worker   // variant. This function takes the hardware model name as returned by
140*6777b538SAndroid Build Coastguard Worker   // HardwareModelName() above, and returns it split into its constituent parts.
141*6777b538SAndroid Build Coastguard Worker   // Returns nullopt if the value cannot be parsed.
142*6777b538SAndroid Build Coastguard Worker   //
143*6777b538SAndroid Build Coastguard Worker   // /!\ WARNING
144*6777b538SAndroid Build Coastguard Worker   //
145*6777b538SAndroid Build Coastguard Worker   // This is NOT A USEFUL FUNCTION and SHOULD NOT BE USED. While the `model`
146*6777b538SAndroid Build Coastguard Worker   // value does inform as to what generation of hardware it is within the
147*6777b538SAndroid Build Coastguard Worker   // `category`, this is not useful in determining the capabilities of the
148*6777b538SAndroid Build Coastguard Worker   // hardware. Instead of using the `model` value, check the actual capabilities
149*6777b538SAndroid Build Coastguard Worker   // of the hardware to verify what it can do rather than relying on a hardware
150*6777b538SAndroid Build Coastguard Worker   // model name. In addition, while the `category` value used to have meaning
151*6777b538SAndroid Build Coastguard Worker   // and could be used to determine the type of hardware (e.g. desktop vs
152*6777b538SAndroid Build Coastguard Worker   // laptop), in 2022 Apple started using the generic category of "Mac", thus
153*6777b538SAndroid Build Coastguard Worker   // removing its usefulness when used alone. While the entire model string as
154*6777b538SAndroid Build Coastguard Worker   // returned by HardwareModelName() above can be useful for identifying a
155*6777b538SAndroid Build Coastguard Worker   // specific piece of equipment, splitting apart it is not useful.
156*6777b538SAndroid Build Coastguard Worker   //
157*6777b538SAndroid Build Coastguard Worker   // Do not add any further callers! When the aforementioned 2022-era hardware
158*6777b538SAndroid Build Coastguard Worker   // is the minimum requirement for Chromium, remove this function and adjust
159*6777b538SAndroid Build Coastguard Worker   // all callers appropriately.
160*6777b538SAndroid Build Coastguard Worker   static std::optional<HardwareModelNameSplit> SplitHardwareModelNameDoNotUse(
161*6777b538SAndroid Build Coastguard Worker       std::string_view name);
162*6777b538SAndroid Build Coastguard Worker #endif
163*6777b538SAndroid Build Coastguard Worker 
164*6777b538SAndroid Build Coastguard Worker   struct HardwareInfo {
165*6777b538SAndroid Build Coastguard Worker     std::string manufacturer;
166*6777b538SAndroid Build Coastguard Worker     std::string model;
167*6777b538SAndroid Build Coastguard Worker   };
168*6777b538SAndroid Build Coastguard Worker   // Returns via |callback| a struct containing descriptive UTF-8 strings for
169*6777b538SAndroid Build Coastguard Worker   // the current machine manufacturer and model, or empty strings if the
170*6777b538SAndroid Build Coastguard Worker   // information is unknown or an error occurred. Implemented on Windows, macOS,
171*6777b538SAndroid Build Coastguard Worker   // iOS, Linux, Chrome OS and Android.
172*6777b538SAndroid Build Coastguard Worker   static void GetHardwareInfo(base::OnceCallback<void(HardwareInfo)> callback);
173*6777b538SAndroid Build Coastguard Worker 
174*6777b538SAndroid Build Coastguard Worker   // Returns the name of the host operating system.
175*6777b538SAndroid Build Coastguard Worker   static std::string OperatingSystemName();
176*6777b538SAndroid Build Coastguard Worker 
177*6777b538SAndroid Build Coastguard Worker   // Returns the version of the host operating system.
178*6777b538SAndroid Build Coastguard Worker   static std::string OperatingSystemVersion();
179*6777b538SAndroid Build Coastguard Worker 
180*6777b538SAndroid Build Coastguard Worker   // Retrieves detailed numeric values for the OS version.
181*6777b538SAndroid Build Coastguard Worker   // DON'T USE THIS ON THE MAC OR WINDOWS to determine the current OS release
182*6777b538SAndroid Build Coastguard Worker   // for OS version-specific feature checks and workarounds. If you must use an
183*6777b538SAndroid Build Coastguard Worker   // OS version check instead of a feature check, use
184*6777b538SAndroid Build Coastguard Worker   // base::mac::MacOSVersion()/MacOSMajorVersion() family from
185*6777b538SAndroid Build Coastguard Worker   // base/mac/mac_util.h, or base::win::GetVersion() from
186*6777b538SAndroid Build Coastguard Worker   // base/win/windows_version.h.
187*6777b538SAndroid Build Coastguard Worker   static void OperatingSystemVersionNumbers(int32_t* major_version,
188*6777b538SAndroid Build Coastguard Worker                                             int32_t* minor_version,
189*6777b538SAndroid Build Coastguard Worker                                             int32_t* bugfix_version);
190*6777b538SAndroid Build Coastguard Worker 
191*6777b538SAndroid Build Coastguard Worker   // Returns the architecture of the running operating system.
192*6777b538SAndroid Build Coastguard Worker   // Exact return value may differ across platforms.
193*6777b538SAndroid Build Coastguard Worker   // e.g. a 32-bit x86 kernel on a 64-bit capable CPU will return "x86",
194*6777b538SAndroid Build Coastguard Worker   //      whereas a x86-64 kernel on the same CPU will return "x86_64"
195*6777b538SAndroid Build Coastguard Worker   static std::string OperatingSystemArchitecture();
196*6777b538SAndroid Build Coastguard Worker 
197*6777b538SAndroid Build Coastguard Worker   // Returns the architecture of the running process, which might be different
198*6777b538SAndroid Build Coastguard Worker   // than the architecture returned by OperatingSystemArchitecture() (e.g.
199*6777b538SAndroid Build Coastguard Worker   // macOS Rosetta, a 32-bit binary on a 64-bit OS, etc).
200*6777b538SAndroid Build Coastguard Worker   // Will return one of: "x86", "x86_64", "ARM", "ARM_64", or an empty string if
201*6777b538SAndroid Build Coastguard Worker   // none of the above.
202*6777b538SAndroid Build Coastguard Worker   static std::string ProcessCPUArchitecture();
203*6777b538SAndroid Build Coastguard Worker 
204*6777b538SAndroid Build Coastguard Worker   // Returns the CPU model name of the system. If it can not be figured out,
205*6777b538SAndroid Build Coastguard Worker   // an empty string is returned.
206*6777b538SAndroid Build Coastguard Worker   // More detailed info can be obtained from base/cpu.h.
207*6777b538SAndroid Build Coastguard Worker   static std::string CPUModelName();
208*6777b538SAndroid Build Coastguard Worker 
209*6777b538SAndroid Build Coastguard Worker   // Return the smallest amount of memory (in bytes) which the VM system will
210*6777b538SAndroid Build Coastguard Worker   // allocate.
211*6777b538SAndroid Build Coastguard Worker   static size_t VMAllocationGranularity();
212*6777b538SAndroid Build Coastguard Worker 
213*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_CHROMEOS)
214*6777b538SAndroid Build Coastguard Worker   // Set |value| and return true if LsbRelease contains information about |key|.
215*6777b538SAndroid Build Coastguard Worker   static bool GetLsbReleaseValue(const std::string& key, std::string* value);
216*6777b538SAndroid Build Coastguard Worker 
217*6777b538SAndroid Build Coastguard Worker   // Convenience function for GetLsbReleaseValue("CHROMEOS_RELEASE_BOARD",...).
218*6777b538SAndroid Build Coastguard Worker   // Returns "unknown" if CHROMEOS_RELEASE_BOARD is not set. Otherwise, returns
219*6777b538SAndroid Build Coastguard Worker   // the full name of the board. Note that the returned value often differs
220*6777b538SAndroid Build Coastguard Worker   // between developers' systems and devices that use official builds. E.g. for
221*6777b538SAndroid Build Coastguard Worker   // a developer-built image, the function could return 'glimmer', while in an
222*6777b538SAndroid Build Coastguard Worker   // official build, it may be something like 'glimmer-signed-mp-v4keys'.
223*6777b538SAndroid Build Coastguard Worker   //
224*6777b538SAndroid Build Coastguard Worker   // NOTE: Strings returned by this function should be treated as opaque values
225*6777b538SAndroid Build Coastguard Worker   // within Chrome (e.g. for reporting metrics elsewhere). If you need to make
226*6777b538SAndroid Build Coastguard Worker   // Chrome behave differently for different Chrome OS devices, either directly
227*6777b538SAndroid Build Coastguard Worker   // check for the hardware feature that you care about (preferred) or add a
228*6777b538SAndroid Build Coastguard Worker   // command-line flag to Chrome and pass it from session_manager (based on
229*6777b538SAndroid Build Coastguard Worker   // whether a USE flag is set or not). See https://goo.gl/BbBkzg for more
230*6777b538SAndroid Build Coastguard Worker   // details.
231*6777b538SAndroid Build Coastguard Worker   static std::string GetLsbReleaseBoard();
232*6777b538SAndroid Build Coastguard Worker 
233*6777b538SAndroid Build Coastguard Worker   // Returns the creation time of /etc/lsb-release. (Used to get the date and
234*6777b538SAndroid Build Coastguard Worker   // time of the Chrome OS build).
235*6777b538SAndroid Build Coastguard Worker   static Time GetLsbReleaseTime();
236*6777b538SAndroid Build Coastguard Worker 
237*6777b538SAndroid Build Coastguard Worker   // Returns true when actually running in a Chrome OS environment.
238*6777b538SAndroid Build Coastguard Worker   static bool IsRunningOnChromeOS();
239*6777b538SAndroid Build Coastguard Worker 
240*6777b538SAndroid Build Coastguard Worker   // Overrides |lsb_release| and |lsb_release_time|. Overrides cannot be nested.
241*6777b538SAndroid Build Coastguard Worker   // Call ResetChromeOSVersionInfoForTest() to restore the previous values.
242*6777b538SAndroid Build Coastguard Worker   // Prefer base::test::ScopedChromeOSVersionInfo to calling this function.
243*6777b538SAndroid Build Coastguard Worker   static void SetChromeOSVersionInfoForTest(const std::string& lsb_release,
244*6777b538SAndroid Build Coastguard Worker                                             const Time& lsb_release_time);
245*6777b538SAndroid Build Coastguard Worker 
246*6777b538SAndroid Build Coastguard Worker   // Undoes the function above.
247*6777b538SAndroid Build Coastguard Worker   static void ResetChromeOSVersionInfoForTest();
248*6777b538SAndroid Build Coastguard Worker 
249*6777b538SAndroid Build Coastguard Worker   // Returns the kernel version of the host operating system.
250*6777b538SAndroid Build Coastguard Worker   static std::string KernelVersion();
251*6777b538SAndroid Build Coastguard Worker 
252*6777b538SAndroid Build Coastguard Worker   // Crashes if running on Chrome OS non-test image. Use only for really
253*6777b538SAndroid Build Coastguard Worker   // sensitive and risky use cases. Only works while running in verified mode,
254*6777b538SAndroid Build Coastguard Worker   // this check an easily be bypassed in dev mode.
255*6777b538SAndroid Build Coastguard Worker   static void CrashIfChromeOSNonTestImage();
256*6777b538SAndroid Build Coastguard Worker #endif  // BUILDFLAG(IS_CHROMEOS)
257*6777b538SAndroid Build Coastguard Worker 
258*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_ANDROID)
259*6777b538SAndroid Build Coastguard Worker   // Returns the Android build's codename.
260*6777b538SAndroid Build Coastguard Worker   static std::string GetAndroidBuildCodename();
261*6777b538SAndroid Build Coastguard Worker 
262*6777b538SAndroid Build Coastguard Worker   // Returns the Android build ID.
263*6777b538SAndroid Build Coastguard Worker   static std::string GetAndroidBuildID();
264*6777b538SAndroid Build Coastguard Worker 
265*6777b538SAndroid Build Coastguard Worker   // Returns the Android hardware EGL system property.
266*6777b538SAndroid Build Coastguard Worker   static std::string GetAndroidHardwareEGL();
267*6777b538SAndroid Build Coastguard Worker #endif  // BUILDFLAG(IS_ANDROID)
268*6777b538SAndroid Build Coastguard Worker 
269*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_IOS)
270*6777b538SAndroid Build Coastguard Worker   // Returns the iOS build number string which is normally an alphanumeric
271*6777b538SAndroid Build Coastguard Worker   // string like 12E456. This build number can differentiate between different
272*6777b538SAndroid Build Coastguard Worker   // versions of iOS that may have the same major/minor/bugfix version numbers.
273*6777b538SAndroid Build Coastguard Worker   // For example, iOS beta releases have the same version number but different
274*6777b538SAndroid Build Coastguard Worker   // build number strings.
275*6777b538SAndroid Build Coastguard Worker   static std::string GetIOSBuildNumber();
276*6777b538SAndroid Build Coastguard Worker 
277*6777b538SAndroid Build Coastguard Worker   // Overrides the hardware model name. The overridden value is used instead of
278*6777b538SAndroid Build Coastguard Worker   // `StringSysctl({CTL_HW, HW_MACHINE})`. `name` should not be empty.
279*6777b538SAndroid Build Coastguard Worker   static void OverrideHardwareModelName(std::string name);
280*6777b538SAndroid Build Coastguard Worker #endif  // BUILDFLAG(IS_IOS)
281*6777b538SAndroid Build Coastguard Worker 
282*6777b538SAndroid Build Coastguard Worker   // Returns true for low-end devices that may require extreme tradeoffs,
283*6777b538SAndroid Build Coastguard Worker   // including user-visible changes, for acceptable performance.
284*6777b538SAndroid Build Coastguard Worker   // For general memory optimizations, consider |AmountOfPhysicalMemoryMB|.
285*6777b538SAndroid Build Coastguard Worker   //
286*6777b538SAndroid Build Coastguard Worker   // On Android this returns:
287*6777b538SAndroid Build Coastguard Worker   //   true when memory <= 1GB on Android O and later.
288*6777b538SAndroid Build Coastguard Worker   //   true when memory <= 512MB on Android N and earlier.
289*6777b538SAndroid Build Coastguard Worker   // This is not the same as "low-memory" and will be false on a large number of
290*6777b538SAndroid Build Coastguard Worker   // <=1GB pre-O Android devices. See: |detectLowEndDevice| in SysUtils.java.
291*6777b538SAndroid Build Coastguard Worker   // On Desktop this returns true when memory <= 2GB.
292*6777b538SAndroid Build Coastguard Worker   static bool IsLowEndDevice();
293*6777b538SAndroid Build Coastguard Worker 
294*6777b538SAndroid Build Coastguard Worker   // The same as IsLowEndDevice() except on Android.
295*6777b538SAndroid Build Coastguard Worker   //
296*6777b538SAndroid Build Coastguard Worker   // On Android this returns:
297*6777b538SAndroid Build Coastguard Worker   //   true when IsLowEndDevice() returns true.
298*6777b538SAndroid Build Coastguard Worker   //   true when the physical memory of the device is 4gb or 6gb and
299*6777b538SAndroid Build Coastguard Worker   //             the feature: kPartialLowEndModeOnMidEndDevices() is enabled.
300*6777b538SAndroid Build Coastguard Worker   static bool IsLowEndDeviceOrPartialLowEndModeEnabled();
301*6777b538SAndroid Build Coastguard Worker   static bool IsLowEndDeviceOrPartialLowEndModeEnabled(
302*6777b538SAndroid Build Coastguard Worker       const FeatureParam<bool>& param_for_exclusion);
303*6777b538SAndroid Build Coastguard Worker 
304*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS)
305*6777b538SAndroid Build Coastguard Worker   // Returns true for Android devices whose memory is X GB, considering
306*6777b538SAndroid Build Coastguard Worker   // carveouts. The carveouts is memory reserved by the system, e.g.
307*6777b538SAndroid Build Coastguard Worker   // for drivers, MTE, etc. It's very common for querying app to see
308*6777b538SAndroid Build Coastguard Worker   // hundreds MBs less than actual physical memory installed on the system.
309*6777b538SAndroid Build Coastguard Worker   // Addendum: This logic should also work for ChromeOS.
310*6777b538SAndroid Build Coastguard Worker   static bool Is3GbDevice();
311*6777b538SAndroid Build Coastguard Worker   static bool Is4GbDevice();
312*6777b538SAndroid Build Coastguard Worker   static bool Is6GbDevice();
313*6777b538SAndroid Build Coastguard Worker   // Returns true for Android devices whose memory is 4GB or 6GB, considering
314*6777b538SAndroid Build Coastguard Worker   // carveouts.
315*6777b538SAndroid Build Coastguard Worker   static bool Is4GbOr6GbDevice();
316*6777b538SAndroid Build Coastguard Worker #endif  // BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS)
317*6777b538SAndroid Build Coastguard Worker 
318*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_MAC)
319*6777b538SAndroid Build Coastguard Worker   // Indicates that CPU security mitigations are enabled for the current
320*6777b538SAndroid Build Coastguard Worker   // process. This is used to control the behavior of NumberOfProcessors(), see
321*6777b538SAndroid Build Coastguard Worker   // comment on that method.
322*6777b538SAndroid Build Coastguard Worker   static void SetCpuSecurityMitigationsEnabled();
323*6777b538SAndroid Build Coastguard Worker 
324*6777b538SAndroid Build Coastguard Worker   // Resets all state associated with CPU security mitigations.
325*6777b538SAndroid Build Coastguard Worker   static void ResetCpuSecurityMitigationsEnabledForTesting();
326*6777b538SAndroid Build Coastguard Worker #endif
327*6777b538SAndroid Build Coastguard Worker 
328*6777b538SAndroid Build Coastguard Worker  private:
329*6777b538SAndroid Build Coastguard Worker   friend class test::ScopedAmountOfPhysicalMemoryOverride;
330*6777b538SAndroid Build Coastguard Worker   FRIEND_TEST_ALL_PREFIXES(SysInfoTest, AmountOfAvailablePhysicalMemory);
331*6777b538SAndroid Build Coastguard Worker   FRIEND_TEST_ALL_PREFIXES(debug::SystemMetricsTest, ParseMeminfo);
332*6777b538SAndroid Build Coastguard Worker 
333*6777b538SAndroid Build Coastguard Worker   static int NumberOfEfficientProcessorsImpl();
334*6777b538SAndroid Build Coastguard Worker   static uint64_t AmountOfPhysicalMemoryImpl();
335*6777b538SAndroid Build Coastguard Worker   static uint64_t AmountOfAvailablePhysicalMemoryImpl();
336*6777b538SAndroid Build Coastguard Worker   static bool IsLowEndDeviceImpl();
337*6777b538SAndroid Build Coastguard Worker   static HardwareInfo GetHardwareInfoSync();
338*6777b538SAndroid Build Coastguard Worker 
339*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || \
340*6777b538SAndroid Build Coastguard Worker     BUILDFLAG(IS_AIX)
341*6777b538SAndroid Build Coastguard Worker   static uint64_t AmountOfAvailablePhysicalMemory(
342*6777b538SAndroid Build Coastguard Worker       const SystemMemoryInfoKB& meminfo);
343*6777b538SAndroid Build Coastguard Worker #endif
344*6777b538SAndroid Build Coastguard Worker 
345*6777b538SAndroid Build Coastguard Worker   // Sets the amount of physical memory in MB for testing, thus allowing tests
346*6777b538SAndroid Build Coastguard Worker   // to run irrespective of the host machine's configuration.
347*6777b538SAndroid Build Coastguard Worker   static std::optional<uint64_t> SetAmountOfPhysicalMemoryMbForTesting(
348*6777b538SAndroid Build Coastguard Worker       uint64_t amount_of_memory_mb);
349*6777b538SAndroid Build Coastguard Worker   static void ClearAmountOfPhysicalMemoryMbForTesting();
350*6777b538SAndroid Build Coastguard Worker };
351*6777b538SAndroid Build Coastguard Worker 
352*6777b538SAndroid Build Coastguard Worker }  // namespace base
353*6777b538SAndroid Build Coastguard Worker 
354*6777b538SAndroid Build Coastguard Worker #endif  // BASE_SYSTEM_SYS_INFO_H_
355