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