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

Commit f83640d6 authored by Tom Cherry's avatar Tom Cherry
Browse files

liblog: don't use a cache for __android_log_is_debuggable()

ro.debuggable is set by init before other processes would possibly
call __android_log_is_debuggable(), so this property can be checked
once and stored without liblog's property caching mechanisms.

Test: this function returns accurately
Change-Id: Idb1e5e10e53ca809b7f9a75164a4982f39827d4e
parent 3b8b444f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
extern "C" {
#endif

/* Returns `1` if the device is debuggable or `0` if not. */
int __android_log_is_debuggable();

#ifdef __cplusplus
+5 −26
Original line number Diff line number Diff line
@@ -294,33 +294,12 @@ int __android_log_is_loggable(int prio, const char* tag, int default_prio) {
}

int __android_log_is_debuggable() {
  static uint32_t serial;
  static struct cache_char tag_cache;
  static const char key[] = "ro.debuggable";
  int ret;

  if (tag_cache.c) { /* ro property does not change after set */
    ret = tag_cache.c == '1';
  } else if (lock()) {
    struct cache_char temp_cache = {{NULL, 0xFFFFFFFF}, '\0'};
    refresh_cache(&temp_cache, key);
    ret = temp_cache.c == '1';
  } else {
    int change_detected = check_cache(&tag_cache.cache);
    uint32_t current_serial = __system_property_area_serial();
    if (current_serial != serial) {
      change_detected = 1;
    }
    if (change_detected) {
      refresh_cache(&tag_cache, key);
      serial = current_serial;
    }
    ret = tag_cache.c == '1';

    unlock();
  }
  static int is_debuggable = [] {
    char value[PROP_VALUE_MAX] = {};
    return __system_property_get("ro.debuggable", value) > 0 && !strcmp(value, "1");
  }();

  return ret;
  return is_debuggable;
}

/*