Home | History | Annotate | Download | only in android
      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 #include <vector>
     12 
     13 #include "base/base_export.h"
     14 #include "base/macros.h"
     15 #include "base/memory/singleton.h"
     16 
     17 namespace base {
     18 namespace android {
     19 
     20 // This enumeration maps to the values returned by BuildInfo::sdk_int(),
     21 // indicating the Android release associated with a given SDK version.
     22 enum SdkVersion {
     23   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,
     28   SDK_VERSION_LOLLIPOP = 21,
     29   SDK_VERSION_LOLLIPOP_MR1 = 22,
     30   SDK_VERSION_MARSHMALLOW = 23,
     31   SDK_VERSION_NOUGAT = 24,
     32   SDK_VERSION_NOUGAT_MR1 = 25,
     33   SDK_VERSION_OREO = 26,
     34 };
     35 
     36 // BuildInfo is a singleton class that stores android build and device
     37 // information. It will be called from Android specific code and gets used
     38 // primarily in crash reporting.
     39 class BASE_EXPORT BuildInfo {
     40  public:
     41 
     42   ~BuildInfo() {}
     43 
     44   // Static factory method for getting the singleton BuildInfo instance.
     45   // Note that ownership is not conferred on the caller and the BuildInfo in
     46   // question isn't actually freed until shutdown. This is ok because there
     47   // should only be one instance of BuildInfo ever created.
     48   static BuildInfo* GetInstance();
     49 
     50   // Const char* is used instead of std::strings because these values must be
     51   // available even if the process is in a crash state. Sadly
     52   // std::string.c_str() doesn't guarantee that memory won't be allocated when
     53   // it is called.
     54   const char* device() const {
     55     return device_;
     56   }
     57 
     58   const char* manufacturer() const {
     59     return manufacturer_;
     60   }
     61 
     62   const char* model() const {
     63     return model_;
     64   }
     65 
     66   const char* brand() const {
     67     return brand_;
     68   }
     69 
     70   const char* android_build_id() const {
     71     return android_build_id_;
     72   }
     73 
     74   const char* android_build_fp() const {
     75     return android_build_fp_;
     76   }
     77 
     78   const char* gms_version_code() const {
     79     return gms_version_code_;
     80   }
     81 
     82   const char* host_package_name() const { return host_package_name_; }
     83 
     84   const char* host_version_code() const { return host_version_code_; }
     85 
     86   const char* host_package_label() const { return host_package_label_; }
     87 
     88   const char* package_version_code() const {
     89     return package_version_code_;
     90   }
     91 
     92   const char* package_version_name() const {
     93     return package_version_name_;
     94   }
     95 
     96   const char* package_name() const {
     97     return package_name_;
     98   }
     99 
    100   // Will be empty string if no app id is assigned.
    101   const char* firebase_app_id() const { return firebase_app_id_; }
    102 
    103   const char* custom_themes() const { return custom_themes_; }
    104 
    105   const char* resources_version() const { return resources_version_; }
    106 
    107   const char* build_type() const {
    108     return build_type_;
    109   }
    110 
    111   const char* board() const { return board_; }
    112 
    113   const char* installer_package_name() const { return installer_package_name_; }
    114 
    115   const char* abi_name() const { return abi_name_; }
    116 
    117   std::string extracted_file_suffix() const { return extracted_file_suffix_; }
    118 
    119   int sdk_int() const {
    120     return sdk_int_;
    121   }
    122 
    123   bool is_at_least_p() const { return is_at_least_p_; }
    124 
    125  private:
    126   friend struct BuildInfoSingletonTraits;
    127 
    128   explicit BuildInfo(const std::vector<std::string>& params);
    129 
    130   // Const char* is used instead of std::strings because these values must be
    131   // available even if the process is in a crash state. Sadly
    132   // std::string.c_str() doesn't guarantee that memory won't be allocated when
    133   // it is called.
    134   const char* const brand_;
    135   const char* const device_;
    136   const char* const android_build_id_;
    137   const char* const manufacturer_;
    138   const char* const model_;
    139   const int sdk_int_;
    140   const char* const build_type_;
    141   const char* const board_;
    142   const char* const host_package_name_;
    143   const char* const host_version_code_;
    144   const char* const host_package_label_;
    145   const char* const package_name_;
    146   const char* const package_version_code_;
    147   const char* const package_version_name_;
    148   const char* const android_build_fp_;
    149   const char* const gms_version_code_;
    150   const char* const installer_package_name_;
    151   const char* const abi_name_;
    152   const char* const firebase_app_id_;
    153   const char* const custom_themes_;
    154   const char* const resources_version_;
    155   // Not needed by breakpad.
    156   const std::string extracted_file_suffix_;
    157   const int is_at_least_p_;
    158 
    159   DISALLOW_COPY_AND_ASSIGN(BuildInfo);
    160 };
    161 
    162 }  // namespace android
    163 }  // namespace base
    164 
    165 #endif  // BASE_ANDROID_BUILD_INFO_H_
    166