blob: 52aec78fee424669c15220a31e0c9736ef6b9f44 [file] [log] [blame]
[email protected]6653c192012-04-10 22:52:441// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef BASE_ANDROID_BUILD_INFO_H_
6#define BASE_ANDROID_BUILD_INFO_H_
7
8#include <jni.h>
9
10#include <string>
agrieve8e74adc2017-06-16 15:57:2411#include <vector>
[email protected]6653c192012-04-10 22:52:4412
[email protected]4f2b94f2013-02-22 21:06:3713#include "base/base_export.h"
avib30f2402015-12-24 03:43:2814#include "base/macros.h"
[email protected]6653c192012-04-10 22:52:4415#include "base/memory/singleton.h"
16
17namespace base {
18namespace android {
19
peterd948e022015-02-17 17:49:4620// This enumeration maps to the values returned by BuildInfo::sdk_int(),
21// indicating the Android release associated with a given SDK version.
22enum SdkVersion {
peterd948e022015-02-17 17:49:4623 SDK_VERSION_JELLY_BEAN = 16,
24 SDK_VERSION_JELLY_BEAN_MR1 = 17,
25 SDK_VERSION_JELLY_BEAN_MR2 = 18,
26 SDK_VERSION_KITKAT = 19,
27 SDK_VERSION_KITKAT_WEAR = 20,
jdduke05bb97f2015-06-10 00:27:5628 SDK_VERSION_LOLLIPOP = 21,
andrewhayden752b1fb2015-08-27 21:05:5729 SDK_VERSION_LOLLIPOP_MR1 = 22,
tobiasjs2c944c92016-11-08 21:10:0930 SDK_VERSION_MARSHMALLOW = 23,
Simeon Anfinrudd9644fc2017-06-02 17:26:5531 SDK_VERSION_NOUGAT = 24,
Klaus Weidner3824a8882017-11-03 06:24:5732 SDK_VERSION_NOUGAT_MR1 = 25,
33 SDK_VERSION_OREO = 26,
peterd948e022015-02-17 17:49:4634};
35
[email protected]6653c192012-04-10 22:52:4436// BuildInfo is a singleton class that stores android build and device
[email protected]9be878f2012-09-18 01:51:2737// information. It will be called from Android specific code and gets used
[email protected]6653c192012-04-10 22:52:4438// primarily in crash reporting.
[email protected]1b46a532012-05-23 05:59:4939
40// It is also used to store the last java exception seen during JNI.
41// TODO(nileshagrawal): Find a better place to store this info.
[email protected]4f2b94f2013-02-22 21:06:3742class BASE_EXPORT BuildInfo {
[email protected]6653c192012-04-10 22:52:4443 public:
44
45 ~BuildInfo() {}
46
47 // Static factory method for getting the singleton BuildInfo instance.
48 // Note that ownership is not conferred on the caller and the BuildInfo in
49 // question isn't actually freed until shutdown. This is ok because there
50 // should only be one instance of BuildInfo ever created.
51 static BuildInfo* GetInstance();
52
53 // Const char* is used instead of std::strings because these values must be
54 // available even if the process is in a crash state. Sadly
55 // std::string.c_str() doesn't guarantee that memory won't be allocated when
56 // it is called.
57 const char* device() const {
58 return device_;
59 }
60
gunsche2dcec52014-09-23 21:39:1961 const char* manufacturer() const {
62 return manufacturer_;
63 }
64
[email protected]6653c192012-04-10 22:52:4465 const char* model() const {
66 return model_;
67 }
68
69 const char* brand() const {
70 return brand_;
71 }
72
73 const char* android_build_id() const {
74 return android_build_id_;
75 }
76
77 const char* android_build_fp() const {
78 return android_build_fp_;
79 }
80
hzle36a1302016-06-10 17:50:1781 const char* gms_version_code() const {
82 return gms_version_code_;
83 }
84
[email protected]6653c192012-04-10 22:52:4485 const char* package_version_code() const {
86 return package_version_code_;
87 }
88
89 const char* package_version_name() const {
90 return package_version_name_;
91 }
92
[email protected]9be878f2012-09-18 01:51:2793 const char* package_label() const {
94 return package_label_;
95 }
96
[email protected]281288d2012-11-09 03:03:2397 const char* package_name() const {
98 return package_name_;
99 }
100
[email protected]a588c092014-02-13 23:26:54101 const char* build_type() const {
102 return build_type_;
103 }
104
ranjf2c67e42017-06-29 19:43:30105 const char* installer_package_name() const { return installer_package_name_; }
106
107 const char* abi_name() const { return abi_name_; }
108
agrievea9cdba42017-04-20 18:03:29109 std::string extracted_file_suffix() const { return extracted_file_suffix_; }
110
[email protected]197284842012-11-20 03:39:01111 int sdk_int() const {
112 return sdk_int_;
113 }
114
[email protected]1b46a532012-05-23 05:59:49115 const char* java_exception_info() const {
116 return java_exception_info_;
117 }
118
cjhopman060e0072015-05-06 21:37:48119 void SetJavaExceptionInfo(const std::string& info);
120
121 void ClearJavaExceptionInfo();
[email protected]1b46a532012-05-23 05:59:49122
[email protected]6653c192012-04-10 22:52:44123 private:
[email protected]57bf1832012-06-20 16:42:39124 friend struct BuildInfoSingletonTraits;
[email protected]6653c192012-04-10 22:52:44125
agrieve8e74adc2017-06-16 15:57:24126 explicit BuildInfo(const std::vector<std::string>& params);
[email protected]6653c192012-04-10 22:52:44127
128 // Const char* is used instead of std::strings because these values must be
129 // available even if the process is in a crash state. Sadly
130 // std::string.c_str() doesn't guarantee that memory won't be allocated when
131 // it is called.
agrieve8e74adc2017-06-16 15:57:24132 const char* const brand_;
[email protected]57bf1832012-06-20 16:42:39133 const char* const device_;
agrieve8e74adc2017-06-16 15:57:24134 const char* const android_build_id_;
gunsche2dcec52014-09-23 21:39:19135 const char* const manufacturer_;
[email protected]57bf1832012-06-20 16:42:39136 const char* const model_;
agrieve8e74adc2017-06-16 15:57:24137 const int sdk_int_;
138 const char* const build_type_;
agrieve91522d02017-04-24 15:44:29139 const char* const package_label_;
140 const char* const package_name_;
agrieve8e74adc2017-06-16 15:57:24141 const char* const package_version_code_;
142 const char* const package_version_name_;
143 const char* const android_build_fp_;
144 const char* const gms_version_code_;
ranjf2c67e42017-06-29 19:43:30145 const char* const installer_package_name_;
146 const char* const abi_name_;
agrievea9cdba42017-04-20 18:03:29147 // Not needed by breakpad.
148 const std::string extracted_file_suffix_;
[email protected]57bf1832012-06-20 16:42:39149 // This is set via set_java_exception_info, not at constructor time.
150 const char* java_exception_info_;
[email protected]6653c192012-04-10 22:52:44151
152 DISALLOW_COPY_AND_ASSIGN(BuildInfo);
153};
154
[email protected]6653c192012-04-10 22:52:44155} // namespace android
156} // namespace base
157
158#endif // BASE_ANDROID_BUILD_INFO_H_