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

Commit ecd9b8a7 authored by Jack He's avatar Jack He
Browse files

GD-Logging: Add INIT flags to configure debug logging

* Three flags:
 - INIT_logging_debug_enabled_for_all
 - INIT_logging_debug_enabled_for_tags
 - INIT_logging_debug_disabled_for_tags
* If a tag is explicitly disabled or enabled, we will follow that
  setting. Otherwise, we check the global enable flag
* This setup allows us to enable/disable individual tags as well as
  enable or disable debug logging for all tags
* This affects only DEBUG and VERBOSE level logs in native

Bug: 170163727
Test: bluetooth_test_gd
Tag: #gd-refactor
Change-Id: Ic42ed521c6953e268a4ba7a40aa83370e2efa4e0
parent 9c2cb262
Loading
Loading
Loading
Loading
+42 −5
Original line number Diff line number Diff line
@@ -3052,27 +3052,64 @@ public class AdapterService extends Service {
                .isCommonCriteriaModeEnabled(null);
    }

    // Boolean flags
    private static final String GD_CORE_FLAG = "INIT_gd_core";
    private static final String GD_ADVERTISING_FLAG = "INIT_gd_advertising";
    private static final String GD_HCI_FLAG = "INIT_gd_hci";
    private static final String GD_CONTROLLER_FLAG = "INIT_gd_controller";
    private static final String GD_ACL_FLAG = "INIT_gd_acl";
    /**
     * Logging flags logic (only applies to DEBUG and VERBOSE levels):
     * if LOG_TAG in LOGGING_DEBUG_DISABLED_FOR_TAGS_FLAG:
     *   DO NOT LOG
     * else if LOG_TAG in LOGGING_DEBUG_ENABLED_FOR_TAGS_FLAG:
     *   DO LOG
     * else if LOGGING_DEBUG_ENABLED_FOR_ALL_FLAG:
     *   DO LOG
     * else:
     *   DO NOT LOG
     */
    private static final String LOGGING_DEBUG_ENABLED_FOR_ALL_FLAG =
            "INIT_logging_debug_enabled_for_all";
    // String flags
    // Comma separated tags
    private static final String LOGGING_DEBUG_ENABLED_FOR_TAGS_FLAG =
            "INIT_logging_debug_enabled_for_tags";
    private static final String LOGGING_DEBUG_DISABLED_FOR_TAGS_FLAG =
            "INIT_logging_debug_disabled_for_tags";

    private String[] getInitFlags() {
        ArrayList<String> initFlags = new ArrayList<>();
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, GD_CORE_FLAG, false)) {
            initFlags.add(GD_CORE_FLAG);
            initFlags.add(String.format("%s=%s", GD_CORE_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, GD_ADVERTISING_FLAG, false)) {
            initFlags.add(GD_ADVERTISING_FLAG);
            initFlags.add(String.format("%s=%s", GD_ADVERTISING_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, GD_HCI_FLAG, false)) {
            initFlags.add(GD_HCI_FLAG);
            initFlags.add(String.format("%s=%s", GD_HCI_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, GD_CONTROLLER_FLAG, false)) {
            initFlags.add(GD_CONTROLLER_FLAG);
            initFlags.add(String.format("%s=%s", GD_CONTROLLER_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, GD_ACL_FLAG, false)) {
            initFlags.add(GD_ACL_FLAG);
            initFlags.add(String.format("%s=%s", GD_ACL_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH,
                LOGGING_DEBUG_ENABLED_FOR_ALL_FLAG, false)) {
            initFlags.add(String.format("%s=%s", LOGGING_DEBUG_ENABLED_FOR_ALL_FLAG, "true"));
        }
        String debugLoggingEnabledTags = DeviceConfig.getString(DeviceConfig.NAMESPACE_BLUETOOTH,
                LOGGING_DEBUG_ENABLED_FOR_TAGS_FLAG, "");
        if (!debugLoggingEnabledTags.isEmpty()) {
            initFlags.add(String.format("%s=%s", LOGGING_DEBUG_ENABLED_FOR_TAGS_FLAG,
                    debugLoggingEnabledTags));
        }
        String debugLoggingDisabledTags = DeviceConfig.getString(DeviceConfig.NAMESPACE_BLUETOOTH,
                LOGGING_DEBUG_DISABLED_FOR_TAGS_FLAG, "");
        if (!debugLoggingDisabledTags.isEmpty()) {
            initFlags.add(String.format("%s=%s", LOGGING_DEBUG_DISABLED_FOR_TAGS_FLAG,
                    debugLoggingDisabledTags));
        }
        return initFlags.toArray(new String[0]);
    }