build_info.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #ifndef MODULES_AUDIO_DEVICE_ANDROID_BUILD_INFO_H_
  11. #define MODULES_AUDIO_DEVICE_ANDROID_BUILD_INFO_H_
  12. #include <jni.h>
  13. #include <memory>
  14. #include <string>
  15. #include "modules/utility/include/jvm_android.h"
  16. namespace webrtc {
  17. // This enumeration maps to the values returned by BuildInfo::GetSdkVersion(),
  18. // indicating the Android release associated with a given SDK version.
  19. // See https://developer.android.com/guide/topics/manifest/uses-sdk-element.html
  20. // for details.
  21. enum SdkCode {
  22. SDK_CODE_JELLY_BEAN = 16, // Android 4.1
  23. SDK_CODE_JELLY_BEAN_MR1 = 17, // Android 4.2
  24. SDK_CODE_JELLY_BEAN_MR2 = 18, // Android 4.3
  25. SDK_CODE_KITKAT = 19, // Android 4.4
  26. SDK_CODE_WATCH = 20, // Android 4.4W
  27. SDK_CODE_LOLLIPOP = 21, // Android 5.0
  28. SDK_CODE_LOLLIPOP_MR1 = 22, // Android 5.1
  29. SDK_CODE_MARSHMALLOW = 23, // Android 6.0
  30. SDK_CODE_N = 24,
  31. };
  32. // Utility class used to query the Java class (org/webrtc/voiceengine/BuildInfo)
  33. // for device and Android build information.
  34. // The calling thread is attached to the JVM at construction if needed and a
  35. // valid Java environment object is also created.
  36. // All Get methods must be called on the creating thread. If not, the code will
  37. // hit RTC_DCHECKs when calling JNIEnvironment::JavaToStdString().
  38. class BuildInfo {
  39. public:
  40. BuildInfo();
  41. ~BuildInfo() {}
  42. // End-user-visible name for the end product (e.g. "Nexus 6").
  43. std::string GetDeviceModel();
  44. // Consumer-visible brand (e.g. "google").
  45. std::string GetBrand();
  46. // Manufacturer of the product/hardware (e.g. "motorola").
  47. std::string GetDeviceManufacturer();
  48. // Android build ID (e.g. LMY47D).
  49. std::string GetAndroidBuildId();
  50. // The type of build (e.g. "user" or "eng").
  51. std::string GetBuildType();
  52. // The user-visible version string (e.g. "5.1").
  53. std::string GetBuildRelease();
  54. // The user-visible SDK version of the framework (e.g. 21). See SdkCode enum
  55. // for translation.
  56. SdkCode GetSdkVersion();
  57. private:
  58. // Helper method which calls a static getter method with |name| and returns
  59. // a string from Java.
  60. std::string GetStringFromJava(const char* name);
  61. // Ensures that this class can access a valid JNI interface pointer even
  62. // if the creating thread was not attached to the JVM.
  63. JvmThreadConnector attach_thread_if_needed_;
  64. // Provides access to the JNIEnv interface pointer and the JavaToStdString()
  65. // method which is used to translate Java strings to std strings.
  66. std::unique_ptr<JNIEnvironment> j_environment_;
  67. // Holds the jclass object and provides access to CallStaticObjectMethod().
  68. // Used by GetStringFromJava() during construction only.
  69. JavaClass j_build_info_;
  70. };
  71. } // namespace webrtc
  72. #endif // MODULES_AUDIO_DEVICE_ANDROID_BUILD_INFO_H_