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