1 // Copyright 2023 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.
5 #ifndef COMPONENTS_METRICS_ANDROID_METRICS_HELPER_H_
6 #define COMPONENTS_METRICS_ANDROID_METRICS_HELPER_H_
10 #include "components/prefs/pref_registry_simple.h"
11 #include "components/prefs/pref_service.h"
16 constexpr char kVersionCodePref[] = "android_system_info.last_version_code";
19 // Whether 64-bit and/or 32-bit apps can be installed on this device/OS.
21 // These values are persisted to logs. Entries should not be renumbered and
22 // numeric values should never be reused. See CpuAbiBitnessSupport in enums.xml.
23 enum class CpuAbiBitnessSupport {
28 kMaxValue = k32And64bit,
31 // AndroidMetricsHelper is responsible for helping to log information related to
32 // system-level information about the Android device as well as the process.
33 class AndroidMetricsHelper {
35 AndroidMetricsHelper(const AndroidMetricsHelper&) = delete;
36 AndroidMetricsHelper& operator=(const AndroidMetricsHelper&) = delete;
37 ~AndroidMetricsHelper() = default;
39 static AndroidMetricsHelper* GetInstance();
40 static AndroidMetricsHelper* CreateInstanceForTest(
41 const std::string& version_code,
44 return new AndroidMetricsHelper(version_code, has_abilist32, has_abilist64);
47 int version_code_int() const { return version_code_int_; }
48 CpuAbiBitnessSupport cpu_abi_bitness_support() const {
49 return cpu_abi_bitness_support_;
52 // |on_did_create_metrics_log| denotes whether data is emitted in
53 // OnDidCreateMetricsLog, as opposed to in ProvidePreviousSessionData.
54 void EmitHistograms(PrefService* local_state, bool on_did_create_metrics_log);
56 static void RegisterPrefs(PrefRegistrySimple* registry);
58 // Made public for testing.
59 static void SaveLocalState(PrefService* local_state, int version_code_int);
61 static void ResetGlobalStateForTesting() { local_state_saved_ = false; }
64 friend struct AndroidMetricsHelperSingletonTraits;
66 AndroidMetricsHelper(const std::string& version_code,
70 int version_code_int_ = 0;
71 CpuAbiBitnessSupport cpu_abi_bitness_support_ =
72 CpuAbiBitnessSupport::kNeither;
74 static inline bool local_state_saved_ = false;
77 } // namespace metrics
79 #endif // COMPONENTS_METRICS_ANDROID_METRICS_HELPER_H_