Adds usage of RTC_LOG macros in code for Android

Bug: webrtc:8710
Change-Id: Ifeedc51ef7d4998278b9583d9530f8f2bdc8f3a2
Reviewed-on: https://webrtc-review.googlesource.com/39266
Commit-Queue: Henrik Andreassson <henrika@webrtc.org>
Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21678}
diff --git a/modules/audio_device/android/audio_manager.cc b/modules/audio_device/android/audio_manager.cc
index fae4ecc..16995d0 100644
--- a/modules/audio_device/android/audio_manager.cc
+++ b/modules/audio_device/android/audio_manager.cc
@@ -12,21 +12,13 @@
 
 #include <utility>
 
-#include <android/log.h>
-
 #include "modules/audio_device/android/audio_common.h"
 #include "modules/utility/include/helpers_android.h"
 #include "rtc_base/arraysize.h"
 #include "rtc_base/checks.h"
+#include "rtc_base/logging.h"
 #include "rtc_base/platform_thread.h"
 
-#define TAG "AudioManager"
-#define ALOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, TAG, __VA_ARGS__)
-#define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
-#define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
-#define ALOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG, __VA_ARGS__)
-#define ALOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
-
 namespace webrtc {
 
 // AudioManager::JavaAudioManager implementation
@@ -41,11 +33,11 @@
       is_device_blacklisted_for_open_sles_usage_(
           native_reg->GetMethodId("isDeviceBlacklistedForOpenSLESUsage",
                                   "()Z")) {
-  ALOGD("JavaAudioManager::ctor @[tid=%d]", rtc::CurrentThreadId());
+  RTC_LOG(INFO) << "JavaAudioManager::ctor";
 }
 
 AudioManager::JavaAudioManager::~JavaAudioManager() {
-  ALOGD("JavaAudioManager::dtor[tid=%d]", rtc::CurrentThreadId());
+  RTC_LOG(INFO) << "JavaAudioManager::~dtor";
 }
 
 bool AudioManager::JavaAudioManager::Init() {
@@ -76,7 +68,7 @@
       low_latency_playout_(false),
       low_latency_record_(false),
       delay_estimate_in_milliseconds_(0) {
-  ALOGD("ctor[tid=%d]", rtc::CurrentThreadId());
+  RTC_LOG(INFO) << "ctor";
   RTC_CHECK(j_environment_);
   JNINativeMethod native_methods[] = {
       {"nativeCacheAudioParameters", "(IIIZZZZZZIIJ)V",
@@ -91,14 +83,14 @@
 }
 
 AudioManager::~AudioManager() {
-  ALOGD("~dtor[tid=%d]", rtc::CurrentThreadId());
+  RTC_LOG(INFO) << "dtor";
   RTC_DCHECK(thread_checker_.CalledOnValidThread());
   Close();
 }
 
 void AudioManager::SetActiveAudioLayer(
     AudioDeviceModule::AudioLayer audio_layer) {
-  ALOGD("SetActiveAudioLayer(%d)[tid=%d]", audio_layer, rtc::CurrentThreadId());
+  RTC_LOG(INFO) << "SetActiveAudioLayer: " << audio_layer;
   RTC_DCHECK(thread_checker_.CalledOnValidThread());
   RTC_DCHECK(!initialized_);
   // Store the currently utilized audio layer.
@@ -111,25 +103,27 @@
       (audio_layer == AudioDeviceModule::kAndroidJavaAudio)
           ? kHighLatencyModeDelayEstimateInMilliseconds
           : kLowLatencyModeDelayEstimateInMilliseconds;
-  ALOGD("delay_estimate_in_milliseconds: %d", delay_estimate_in_milliseconds_);
+  RTC_LOG(INFO) << "delay_estimate_in_milliseconds: "
+                << delay_estimate_in_milliseconds_;
 }
 
 SLObjectItf AudioManager::GetOpenSLEngine() {
-  ALOGD("GetOpenSLEngine[tid=%d]", rtc::CurrentThreadId());
+  RTC_LOG(INFO) << "GetOpenSLEngine";
   RTC_DCHECK(thread_checker_.CalledOnValidThread());
   // Only allow usage of OpenSL ES if such an audio layer has been specified.
   if (audio_layer_ != AudioDeviceModule::kAndroidOpenSLESAudio &&
       audio_layer_ !=
           AudioDeviceModule::kAndroidJavaInputAndOpenSLESOutputAudio) {
-    ALOGI("Unable to create OpenSL engine for the current audio layer: %d",
-          audio_layer_);
+    RTC_LOG(INFO)
+        << "Unable to create OpenSL engine for the current audio layer: "
+        << audio_layer_;
     return nullptr;
   }
   // OpenSL ES for Android only supports a single engine per application.
   // If one already has been created, return existing object instead of
   // creating a new.
   if (engine_object_.Get() != nullptr) {
-    ALOGI("The OpenSL ES engine object has already been created");
+    RTC_LOG(WARNING) << "The OpenSL ES engine object has already been created";
     return engine_object_.Get();
   }
   // Create the engine object in thread safe mode.
@@ -138,14 +132,15 @@
   SLresult result =
       slCreateEngine(engine_object_.Receive(), 1, option, 0, NULL, NULL);
   if (result != SL_RESULT_SUCCESS) {
-    ALOGE("slCreateEngine() failed: %s", GetSLErrorString(result));
+    RTC_LOG(LS_ERROR) << "slCreateEngine() failed: "
+                      << GetSLErrorString(result);
     engine_object_.Reset();
     return nullptr;
   }
   // Realize the SL Engine in synchronous mode.
   result = engine_object_->Realize(engine_object_.Get(), SL_BOOLEAN_FALSE);
   if (result != SL_RESULT_SUCCESS) {
-    ALOGE("Realize() failed: %s", GetSLErrorString(result));
+    RTC_LOG(LS_ERROR) << "Realize() failed: " << GetSLErrorString(result);
     engine_object_.Reset();
     return nullptr;
   }
@@ -154,12 +149,12 @@
 }
 
 bool AudioManager::Init() {
-  ALOGD("Init[tid=%d]", rtc::CurrentThreadId());
+  RTC_LOG(INFO) << "Init";
   RTC_DCHECK(thread_checker_.CalledOnValidThread());
   RTC_DCHECK(!initialized_);
   RTC_DCHECK_NE(audio_layer_, AudioDeviceModule::kPlatformDefaultAudio);
   if (!j_audio_manager_->Init()) {
-    ALOGE("init failed!");
+    RTC_LOG(LS_ERROR) << "Init() failed";
     return false;
   }
   initialized_ = true;
@@ -167,7 +162,7 @@
 }
 
 bool AudioManager::Close() {
-  ALOGD("Close[tid=%d]", rtc::CurrentThreadId());
+  RTC_LOG(INFO) << "Close";
   RTC_DCHECK(thread_checker_.CalledOnValidThread());
   if (!initialized_)
     return true;
@@ -177,7 +172,6 @@
 }
 
 bool AudioManager::IsCommunicationModeEnabled() const {
-  ALOGD("IsCommunicationModeEnabled()");
   RTC_DCHECK(thread_checker_.CalledOnValidThread());
   return j_audio_manager_->IsCommunicationModeEnabled();
 }
@@ -199,7 +193,6 @@
 
 bool AudioManager::IsLowLatencyPlayoutSupported() const {
   RTC_DCHECK(thread_checker_.CalledOnValidThread());
-  ALOGD("IsLowLatencyPlayoutSupported()");
   // Some devices are blacklisted for usage of OpenSL ES even if they report
   // that low-latency playout is supported. See b/21485703 for details.
   return j_audio_manager_->IsDeviceBlacklistedForOpenSLESUsage()
@@ -209,13 +202,11 @@
 
 bool AudioManager::IsLowLatencyRecordSupported() const {
   RTC_DCHECK(thread_checker_.CalledOnValidThread());
-  ALOGD("IsLowLatencyRecordSupported()");
   return low_latency_record_;
 }
 
 bool AudioManager::IsProAudioSupported() const {
   RTC_DCHECK(thread_checker_.CalledOnValidThread());
-  ALOGD("IsProAudioSupported()");
   // TODO(henrika): return the state independently of if OpenSL ES is
   // blacklisted or not for now. We could use the same approach as in
   // IsLowLatencyPlayoutSupported() but I can't see the need for it yet.
@@ -224,13 +215,11 @@
 
 bool AudioManager::IsStereoPlayoutSupported() const {
   RTC_DCHECK(thread_checker_.CalledOnValidThread());
-  ALOGD("IsStereoPlayoutSupported()");
   return (playout_parameters_.channels() == 2);
 }
 
 bool AudioManager::IsStereoRecordSupported() const {
   RTC_DCHECK(thread_checker_.CalledOnValidThread());
-  ALOGD("IsStereoRecordSupported()");
   return (record_parameters_.channels() == 2);
 }
 
@@ -272,18 +261,19 @@
                                           jboolean pro_audio,
                                           jint output_buffer_size,
                                           jint input_buffer_size) {
-  ALOGD("OnCacheAudioParameters[tid=%d]", rtc::CurrentThreadId());
-  ALOGD("hardware_aec: %d", hardware_aec);
-  ALOGD("hardware_agc: %d", hardware_agc);
-  ALOGD("hardware_ns: %d", hardware_ns);
-  ALOGD("low_latency_output: %d", low_latency_output);
-  ALOGD("low_latency_input: %d", low_latency_input);
-  ALOGD("pro_audio: %d", pro_audio);
-  ALOGD("sample_rate: %d", sample_rate);
-  ALOGD("output_channels: %d", output_channels);
-  ALOGD("input_channels: %d", input_channels);
-  ALOGD("output_buffer_size: %d", output_buffer_size);
-  ALOGD("input_buffer_size: %d", input_buffer_size);
+  RTC_LOG(INFO)
+      << "OnCacheAudioParameters: "
+      << "hardware_aec: " << static_cast<bool>(hardware_aec)
+      << ", hardware_agc: " << static_cast<bool>(hardware_agc)
+      << ", hardware_ns: " << static_cast<bool>(hardware_ns)
+      << ", low_latency_output: " << static_cast<bool>(low_latency_output)
+      << ", low_latency_input: " << static_cast<bool>(low_latency_input)
+      << ", pro_audio: " << static_cast<bool>(pro_audio)
+      << ", sample_rate: " << static_cast<int>(sample_rate)
+      << ", output_channels: " << static_cast<int>(output_channels)
+      << ", input_channels: " << static_cast<int>(input_channels)
+      << ", output_buffer_size: " << static_cast<int>(output_buffer_size)
+      << ", input_buffer_size: " << static_cast<int>(input_buffer_size);
   RTC_DCHECK(thread_checker_.CalledOnValidThread());
   hardware_aec_ = hardware_aec;
   hardware_agc_ = hardware_agc;
diff --git a/modules/utility/source/jvm_android.cc b/modules/utility/source/jvm_android.cc
index fc0739c..d43ec65 100644
--- a/modules/utility/source/jvm_android.cc
+++ b/modules/utility/source/jvm_android.cc
@@ -15,12 +15,9 @@
 #include "modules/utility/include/jvm_android.h"
 
 #include "rtc_base/checks.h"
+#include "rtc_base/logging.h"
 #include "rtc_base/platform_thread.h"
 
-#define TAG "JVM"
-#define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
-#define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
-
 namespace webrtc {
 
 JVM* g_jvm;
@@ -41,10 +38,10 @@
 // stack.  Consequently, we only look up all classes once in native WebRTC.
 // http://developer.android.com/training/articles/perf-jni.html#faq_FindClass
 void LoadClasses(JNIEnv* jni) {
-  ALOGD("LoadClasses");
+  RTC_LOG(INFO) << "LoadClasses:";
   for (auto& c : loaded_classes) {
     jclass localRef = FindClass(jni, c.name);
-    ALOGD("name: %s", c.name);
+    RTC_LOG(INFO) << "name: " << c.name;
     CHECK_EXCEPTION(jni) << "Error during FindClass: " << c.name;
     RTC_CHECK(localRef) << c.name;
     jclass globalRef = reinterpret_cast<jclass>(jni->NewGlobalRef(localRef));
@@ -73,12 +70,12 @@
 // AttachCurrentThreadIfNeeded implementation.
 AttachCurrentThreadIfNeeded::AttachCurrentThreadIfNeeded()
     : attached_(false) {
-  ALOGD("AttachCurrentThreadIfNeeded::ctor[tid=%d]", rtc::CurrentThreadId());
+  RTC_LOG(INFO) << "AttachCurrentThreadIfNeeded::ctor";
   JavaVM* jvm = JVM::GetInstance()->jvm();
   RTC_CHECK(jvm);
   JNIEnv* jni = GetEnv(jvm);
   if (!jni) {
-    ALOGD("Attaching thread to JVM");
+    RTC_LOG(INFO) << "Attaching thread to JVM";
     JNIEnv* env = nullptr;
     jint ret = jvm->AttachCurrentThread(&env, nullptr);
     attached_ = (ret == JNI_OK);
@@ -86,10 +83,10 @@
 }
 
 AttachCurrentThreadIfNeeded::~AttachCurrentThreadIfNeeded() {
-  ALOGD("AttachCurrentThreadIfNeeded::dtor[tid=%d]", rtc::CurrentThreadId());
+  RTC_LOG(INFO) << "AttachCurrentThreadIfNeeded::dtor";
   RTC_DCHECK(thread_checker_.CalledOnValidThread());
   if (attached_) {
-    ALOGD("Detaching thread from JVM");
+    RTC_LOG(INFO) << "Detaching thread from JVM";
     jint res = JVM::GetInstance()->jvm()->DetachCurrentThread();
     RTC_CHECK(res == JNI_OK) << "DetachCurrentThread failed: " << res;
   }
@@ -98,11 +95,11 @@
 // GlobalRef implementation.
 GlobalRef::GlobalRef(JNIEnv* jni, jobject object)
     : jni_(jni), j_object_(NewGlobalRef(jni, object)) {
-  ALOGD("GlobalRef::ctor[tid=%d]", rtc::CurrentThreadId());
+  RTC_LOG(INFO) << "GlobalRef::ctor";
 }
 
 GlobalRef::~GlobalRef() {
-  ALOGD("GlobalRef::dtor[tid=%d]", rtc::CurrentThreadId());
+  RTC_LOG(INFO) << "GlobalRef::dtor";
   DeleteGlobalRef(jni_, j_object_);
 }
 
@@ -135,18 +132,18 @@
 // NativeRegistration implementation.
 NativeRegistration::NativeRegistration(JNIEnv* jni, jclass clazz)
     : JavaClass(jni, clazz), jni_(jni) {
-  ALOGD("NativeRegistration::ctor[tid=%d]", rtc::CurrentThreadId());
+  RTC_LOG(INFO) << "NativeRegistration::ctor";
 }
 
 NativeRegistration::~NativeRegistration() {
-  ALOGD("NativeRegistration::dtor[tid=%d]", rtc::CurrentThreadId());
+  RTC_LOG(INFO) << "NativeRegistration::dtor";
   jni_->UnregisterNatives(j_class_);
   CHECK_EXCEPTION(jni_) << "Error during UnregisterNatives";
 }
 
 std::unique_ptr<GlobalRef> NativeRegistration::NewObject(
     const char* name, const char* signature, ...) {
-  ALOGD("NativeRegistration::NewObject[tid=%d]", rtc::CurrentThreadId());
+  RTC_LOG(INFO) << "NativeRegistration::NewObject";
   va_list args;
   va_start(args, signature);
   jobject obj = jni_->NewObjectV(j_class_,
@@ -186,17 +183,17 @@
 
 // JNIEnvironment implementation.
 JNIEnvironment::JNIEnvironment(JNIEnv* jni) : jni_(jni) {
-  ALOGD("JNIEnvironment::ctor[tid=%d]", rtc::CurrentThreadId());
+  RTC_LOG(INFO) << "JNIEnvironment::ctor";
 }
 
 JNIEnvironment::~JNIEnvironment() {
-  ALOGD("JNIEnvironment::dtor[tid=%d]", rtc::CurrentThreadId());
+  RTC_LOG(INFO) << "JNIEnvironment::dtor";
   RTC_DCHECK(thread_checker_.CalledOnValidThread());
 }
 
 std::unique_ptr<NativeRegistration> JNIEnvironment::RegisterNatives(
     const char* name, const JNINativeMethod *methods, int num_methods) {
-  ALOGD("JNIEnvironment::RegisterNatives(%s)", name);
+  RTC_LOG(INFO) << "JNIEnvironment::RegisterNatives: " << name;
   RTC_DCHECK(thread_checker_.CalledOnValidThread());
   jclass clazz = LookUpClass(name);
   jni_->RegisterNatives(clazz, methods, num_methods);
@@ -219,7 +216,7 @@
 
 // static
 void JVM::Initialize(JavaVM* jvm) {
-  ALOGD("JVM::Initialize[tid=%d]", rtc::CurrentThreadId());
+  RTC_LOG(INFO) << "JVM::Initialize";
   RTC_CHECK(!g_jvm);
   g_jvm = new JVM(jvm);
 }
@@ -237,7 +234,7 @@
 
 // static
 void JVM::Uninitialize() {
-  ALOGD("JVM::Uninitialize[tid=%d]", rtc::CurrentThreadId());
+  RTC_LOG(INFO) << "JVM::Uninitialize";
   RTC_DCHECK(g_jvm);
   delete g_jvm;
   g_jvm = nullptr;
@@ -250,19 +247,20 @@
 }
 
 JVM::JVM(JavaVM* jvm) : jvm_(jvm) {
-  ALOGD("JVM::JVM[tid=%d]", rtc::CurrentThreadId());
+  RTC_LOG(INFO) << "JVM::JVM";
   RTC_CHECK(jni()) << "AttachCurrentThread() must be called on this thread.";
   LoadClasses(jni());
 }
 
 JVM::~JVM() {
-  ALOGD("JVM::~JVM[tid=%d]", rtc::CurrentThreadId());
+  RTC_LOG(INFO) << "JVM::~JVM";
   RTC_DCHECK(thread_checker_.CalledOnValidThread());
   FreeClassReferences(jni());
 }
 
 std::unique_ptr<JNIEnvironment> JVM::environment() {
-  ALOGD("JVM::environment[tid=%d]", rtc::CurrentThreadId());
+  RTC_LOG(INFO) << "JVM::environment";
+  ;
   // The JNIEnv is used for thread-local storage. For this reason, we cannot
   // share a JNIEnv between threads. If a piece of code has no other way to get
   // its JNIEnv, we should share the JavaVM, and use GetEnv to discover the
@@ -270,14 +268,15 @@
   // See // http://developer.android.com/training/articles/perf-jni.html.
   JNIEnv* jni = GetEnv(jvm_);
   if (!jni) {
-    ALOGE("AttachCurrentThread() has not been called on this thread.");
+    RTC_LOG(LS_ERROR)
+        << "AttachCurrentThread() has not been called on this thread";
     return std::unique_ptr<JNIEnvironment>();
   }
   return std::unique_ptr<JNIEnvironment>(new JNIEnvironment(jni));
 }
 
 JavaClass JVM::GetClass(const char* name) {
-  ALOGD("JVM::GetClass(%s)[tid=%d]", name, rtc::CurrentThreadId());
+  RTC_LOG(INFO) << "JVM::GetClass: " << name;
   RTC_DCHECK(thread_checker_.CalledOnValidThread());
   return JavaClass(jni(), LookUpClass(name));
 }