1 // 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> 11 12 #include "base/base_export.h" 13 #include "base/memory/singleton.h" 14 15 namespace base { 16 namespace android { 17 18 // BuildInfo is a singleton class that stores android build and device 19 // information. It will be called from Android specific code and gets used 20 // primarily in crash reporting. 21 22 // It is also used to store the last java exception seen during JNI. 23 // TODO(nileshagrawal): Find a better place to store this info. 24 class BASE_EXPORT BuildInfo { 25 public: 26 ~BuildInfo()27 ~BuildInfo() {} 28 29 // Static factory method for getting the singleton BuildInfo instance. 30 // Note that ownership is not conferred on the caller and the BuildInfo in 31 // question isn't actually freed until shutdown. This is ok because there 32 // should only be one instance of BuildInfo ever created. 33 static BuildInfo* GetInstance(); 34 35 // Const char* is used instead of std::strings because these values must be 36 // available even if the process is in a crash state. Sadly 37 // std::string.c_str() doesn't guarantee that memory won't be allocated when 38 // it is called. device()39 const char* device() const { 40 return device_; 41 } 42 model()43 const char* model() const { 44 return model_; 45 } 46 brand()47 const char* brand() const { 48 return brand_; 49 } 50 android_build_id()51 const char* android_build_id() const { 52 return android_build_id_; 53 } 54 android_build_fp()55 const char* android_build_fp() const { 56 return android_build_fp_; 57 } 58 package_version_code()59 const char* package_version_code() const { 60 return package_version_code_; 61 } 62 package_version_name()63 const char* package_version_name() const { 64 return package_version_name_; 65 } 66 package_label()67 const char* package_label() const { 68 return package_label_; 69 } 70 package_name()71 const char* package_name() const { 72 return package_name_; 73 } 74 build_type()75 const char* build_type() const { 76 return build_type_; 77 } 78 sdk_int()79 int sdk_int() const { 80 return sdk_int_; 81 } 82 java_exception_info()83 const char* java_exception_info() const { 84 return java_exception_info_; 85 } 86 87 void set_java_exception_info(const std::string& info); 88 89 static bool RegisterBindings(JNIEnv* env); 90 91 private: 92 friend struct BuildInfoSingletonTraits; 93 94 explicit BuildInfo(JNIEnv* env); 95 96 // Const char* is used instead of std::strings because these values must be 97 // available even if the process is in a crash state. Sadly 98 // std::string.c_str() doesn't guarantee that memory won't be allocated when 99 // it is called. 100 const char* const device_; 101 const char* const model_; 102 const char* const brand_; 103 const char* const android_build_id_; 104 const char* const android_build_fp_; 105 const char* const package_version_code_; 106 const char* const package_version_name_; 107 const char* const package_label_; 108 const char* const package_name_; 109 const char* const build_type_; 110 const int sdk_int_; 111 // This is set via set_java_exception_info, not at constructor time. 112 const char* java_exception_info_; 113 114 DISALLOW_COPY_AND_ASSIGN(BuildInfo); 115 }; 116 117 } // namespace android 118 } // namespace base 119 120 #endif // BASE_ANDROID_BUILD_INFO_H_ 121