Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 036e3ffc authored by Sal Savage's avatar Sal Savage
Browse files

Set the stack's default logging level to match "log.tag.bluetooth"

Normally, the android logging framework uses the system wide default log
level (info) when deciding what to return when calling Log.isLoggable or
the other various APIs in different languages. This patch uses the
__android_log_set_minimum_priority() function to override that value to
a special bluetooth log tag so we can control our own default.

Once set, this impacts whats returned for isLoggable calls when nothing
is set. It also updates how log lines are enforced by the framework.
Now, Log.d(TAG) and other calls will be checked against the process
minimum level instead of verbose (which is effectively "no enforcement"
otherwise)

Tag: #refactor
Bug: 315046089
Flag: EXEMPT, logging only change
Test: m com.android.btservices
Change-Id: I3b65b38e6ab9c51881e767fc0e6e6d14d12b7ed4
parent 30a80b24
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -2269,6 +2269,34 @@ int register_com_android_bluetooth_btservice_AdapterService(JNIEnv* env) {
 * JNI Initialization
 */
jint JNI_OnLoad(JavaVM* jvm, void* /* reserved */) {
  /* Set the default logging level for the process using the tag
   *  "log.tag.bluetooth" and/or "persist.log.tag.bluetooth" via the android
   * logging framework.
   */
  const char* stack_default_log_tag = "bluetooth";
  int default_prio = ANDROID_LOG_INFO;
  if (__android_log_is_loggable(ANDROID_LOG_VERBOSE, stack_default_log_tag,
                                default_prio)) {
    __android_log_set_minimum_priority(ANDROID_LOG_VERBOSE);
    log::info("Set stack default log level to 'VERBOSE'");
  } else if (__android_log_is_loggable(ANDROID_LOG_DEBUG, stack_default_log_tag,
                                       default_prio)) {
    __android_log_set_minimum_priority(ANDROID_LOG_DEBUG);
    log::info("Set stack default log level to 'DEBUG'");
  } else if (__android_log_is_loggable(ANDROID_LOG_INFO, stack_default_log_tag,
                                       default_prio)) {
    __android_log_set_minimum_priority(ANDROID_LOG_INFO);
    log::info("Set stack default log level to 'INFO'");
  } else if (__android_log_is_loggable(ANDROID_LOG_WARN, stack_default_log_tag,
                                       default_prio)) {
    __android_log_set_minimum_priority(ANDROID_LOG_WARN);
    log::info("Set stack default log level to 'WARN'");
  } else if (__android_log_is_loggable(ANDROID_LOG_ERROR, stack_default_log_tag,
                                       default_prio)) {
    __android_log_set_minimum_priority(ANDROID_LOG_ERROR);
    log::info("Set stack default log level to 'ERROR'");
  }

  JNIEnv* e;
  int status;