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

Commit 21b90476 authored by William Escande's avatar William Escande Committed by Automerger Merge Worker
Browse files

Merge "GD: Init flags default in native" am: 06d70f1d

parents 16b94ec5 06d70f1d
Loading
Loading
Loading
Loading
+7 −97
Original line number Diff line number Diff line
@@ -5246,106 +5246,16 @@ public class AdapterService extends Service {
        }
    }

    // Boolean flags
    private static final String SDP_SERIALIZATION_FLAG = "INIT_sdp_serialization";
    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_SCANNING_FLAG = "INIT_gd_scanning";
    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";
    private static final String GD_L2CAP_FLAG = "INIT_gd_l2cap";
    private static final String GD_RUST_FLAG = "INIT_gd_rust";
    private static final String GD_LINK_POLICY_FLAG = "INIT_gd_link_policy";
    private static final String GATT_ROBUST_CACHING_CLIENT_FLAG = "INIT_gatt_robust_caching_client";
    private static final String GATT_ROBUST_CACHING_SERVER_FLAG = "INIT_gatt_robust_caching_server";
    private static final String IRK_ROTATION_FLAG = "INIT_irk_rotation";

    /**
     * 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 static final String BTAA_HCI_LOG_FLAG = "INIT_btaa_hci";

    @RequiresPermission(android.Manifest.permission.READ_DEVICE_CONFIG)
    private String[] getInitFlags() {
        final DeviceConfig.Properties properties =
                DeviceConfig.getProperties(DeviceConfig.NAMESPACE_BLUETOOTH);
        ArrayList<String> initFlags = new ArrayList<>();
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, GD_CORE_FLAG, false)) {
            initFlags.add(String.format("%s=%s", GD_CORE_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH,
                    SDP_SERIALIZATION_FLAG, true)) {
            initFlags.add(String.format("%s=%s", SDP_SERIALIZATION_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, GD_ADVERTISING_FLAG, false)) {
            initFlags.add(String.format("%s=%s", GD_ADVERTISING_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, GD_SCANNING_FLAG,
                Config.isGdEnabledUpToScanningLayer())) {
            initFlags.add(String.format("%s=%s", GD_SCANNING_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, GD_HCI_FLAG, false)) {
            initFlags.add(String.format("%s=%s", GD_HCI_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, GD_CONTROLLER_FLAG, false)) {
            initFlags.add(String.format("%s=%s", GD_CONTROLLER_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, GD_ACL_FLAG, false)) {
            initFlags.add(String.format("%s=%s", GD_ACL_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, GD_L2CAP_FLAG, false)) {
            initFlags.add(String.format("%s=%s", GD_L2CAP_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, GD_RUST_FLAG, false)) {
            initFlags.add(String.format("%s=%s", GD_RUST_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, GD_LINK_POLICY_FLAG, false)) {
            initFlags.add(String.format("%s=%s", GD_LINK_POLICY_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH,
                GATT_ROBUST_CACHING_CLIENT_FLAG, true)) {
            initFlags.add(String.format("%s=%s", GATT_ROBUST_CACHING_CLIENT_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH,
                GATT_ROBUST_CACHING_SERVER_FLAG, false)) {
            initFlags.add(String.format("%s=%s", GATT_ROBUST_CACHING_SERVER_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, IRK_ROTATION_FLAG, false)) {
            initFlags.add(String.format("%s=%s", IRK_ROTATION_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));
        for (String property: properties.getKeyset()) {
            if (property.startsWith("INIT_")) {
                initFlags.add(String.format("%s=%s", property,
                            properties.getString(property, null)));
            }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, BTAA_HCI_LOG_FLAG, true)) {
            initFlags.add(String.format("%s=%s", BTAA_HCI_LOG_FLAG, "true"));
        }
        return initFlags.toArray(new String[0]);
    }
+39 −14
Original line number Diff line number Diff line
use log::{error, info};
use log::{error, info, warn};
use paste::paste;
use std::sync::Mutex;

macro_rules! default_value {
    () => {
        false
    };
    ($default:tt) => {
        $default
    };
}

macro_rules! default_flag {
    ($flag:ident) => {
        let $flag = false;
    };
    ($flag:ident = $default:tt) => {
        let $flag = $default;
    };
}

macro_rules! init_flags {
    (flags: { $($flag:ident),* }, dependencies: { $($parent:ident => $child:ident),* }) => {
        #[derive(Default)]
    (flags: { $($flag:ident $(= $default:tt)?,)* }, dependencies: { $($parent:ident => $child:ident),* }) => {
        struct InitFlags {
            $($flag: bool,)*
        }

        impl Default for InitFlags {
            fn default() -> Self {
                $(default_flag!($flag $(= $default)?);)*
                Self { $($flag,)* }
            }
        }

        /// Sets all flags to true, for testing
        pub fn set_all_for_testing() {
            *FLAGS.lock().unwrap() = InitFlags { $($flag: true,)* };
@@ -16,7 +40,7 @@ macro_rules! init_flags {

        impl InitFlags {
            fn parse(flags: Vec<String>) -> Self {
                $(let mut $flag = false;)*
                let mut init_flags = Self::default();

                for flag in flags {
                    let values: Vec<&str> = flag.split("=").collect();
@@ -26,12 +50,13 @@ macro_rules! init_flags {
                    }

                    match values[0] {
                        $(concat!("INIT_", stringify!($flag)) => $flag = values[1].parse().unwrap_or(false),)*
                        _ => {}
                        $(concat!("INIT_", stringify!($flag)) =>
                            init_flags.$flag = values[1].parse().unwrap_or(default_value!($($default)?)),)*
                        _ => warn!("Unsaved flag: {} = {}", values[0], values[1])
                    }
                }

                Self { $($flag,)* }.reconcile()
                init_flags.reconcile()
            }

            fn reconcile(mut self) -> Self {
@@ -74,16 +99,16 @@ macro_rules! init_flags {

init_flags!(
    flags: {
        sdp_serialization,
        btaa_hci = true,
        gatt_robust_caching_client = true,
        gatt_robust_caching_server,
        gd_core,
        gd_security,
        gd_l2cap,
        gatt_robust_caching_client,
        gatt_robust_caching_server,
        btaa_hci,
        gd_rust,
        gd_link_policy,
        irk_rotation
        gd_rust,
        gd_security,
        irk_rotation,
        sdp_serialization = true,
    },
    dependencies: {
        gd_core => gd_security
+0 −2
Original line number Diff line number Diff line
@@ -110,8 +110,6 @@ tCONN_CB* find_ccb(uint16_t cid, uint8_t state) {
}

TEST_F(StackSdpMainTest, sdp_service_search_request_queuing) {
  bluetooth::common::InitFlags::SetAllForTesting();

  ASSERT_TRUE(SDP_ServiceSearchRequest(addr, sdp_db, nullptr));
  const int cid = L2CA_ConnectReq2_cid;
  tCONN_CB* p_ccb1 = find_ccb(cid, SDP_STATE_CONN_SETUP);