Home | History | Annotate | Download | only in android
      1 /*
      2  *  Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 #ifndef WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_BUILD_INFO_H_
     12 #define WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_BUILD_INFO_H_
     13 
     14 #include <jni.h>
     15 #include <string>
     16 
     17 #include "webrtc/modules/utility/include/jvm_android.h"
     18 
     19 namespace webrtc {
     20 
     21 // Utility class used to query the Java class (org/webrtc/voiceengine/BuildInfo)
     22 // for device and Android build information.
     23 // The calling thread is attached to the JVM at construction if needed and a
     24 // valid Java environment object is also created.
     25 // All Get methods must be called on the creating thread. If not, the code will
     26 // hit RTC_DCHECKs when calling JNIEnvironment::JavaToStdString().
     27 class BuildInfo {
     28  public:
     29   BuildInfo();
     30   ~BuildInfo() {}
     31 
     32   // End-user-visible name for the end product (e.g. "Nexus 6").
     33   std::string GetDeviceModel();
     34   // Consumer-visible brand (e.g. "google").
     35   std::string GetBrand();
     36   // Manufacturer of the product/hardware (e.g. "motorola").
     37   std::string GetDeviceManufacturer();
     38   // Android build ID (e.g. LMY47D).
     39   std::string GetAndroidBuildId();
     40   // The type of build (e.g. "user" or "eng").
     41   std::string GetBuildType();
     42   // The user-visible version string (e.g. "5.1").
     43   std::string GetBuildRelease();
     44   // The user-visible SDK version of the framework (e.g. 21).
     45   std::string GetSdkVersion();
     46 
     47  private:
     48   // Helper method which calls a static getter method with |name| and returns
     49   // a string from Java.
     50   std::string GetStringFromJava(const char* name);
     51 
     52   // Ensures that this class can access a valid JNI interface pointer even
     53   // if the creating thread was not attached to the JVM.
     54   AttachCurrentThreadIfNeeded attach_thread_if_needed_;
     55 
     56   // Provides access to the JNIEnv interface pointer and the JavaToStdString()
     57   // method which is used to translate Java strings to std strings.
     58   rtc::scoped_ptr<JNIEnvironment> j_environment_;
     59 
     60   // Holds the jclass object and provides access to CallStaticObjectMethod().
     61   // Used by GetStringFromJava() during construction only.
     62   JavaClass j_build_info_;
     63 };
     64 
     65 }  // namespace webrtc
     66 
     67 #endif  // WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_BUILD_INFO_H_
     68