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

Commit 716ba600 authored by Abhishek Pandit-Subedi's avatar Abhishek Pandit-Subedi
Browse files

floss: Improve uuid printing in btclient

If a uuid is a known service, we should print out what service it is.

Example
  0000110a-0000-1000-8000-00805F9B34FB: A2dpSource
  0000111f-0000-1000-8000-00805F9B34FB: HfpAg
  00001112-0000-1000-8000-00805F9B34FB: HspAg

Bug: 242772604
Test: Run adapter show in btclient
Tag: #floss
Change-Id: I375cf663aee18d2cca7c82f97f92c3ee5390593f
parent 677b704f
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -321,7 +321,7 @@ impl CommandHandler {
                        DisplayList(
                            uuids
                                .iter()
                                .map(|&x| UuidHelper::to_string(&x))
                                .map(|&x| uuid_helper.known_uuid_to_string(&x))
                                .collect::<Vec<String>>()
                        )
                    );
@@ -529,6 +529,7 @@ impl CommandHandler {
                        (name, alias, device_type, class, bonded, connected, uuids)
                    };

                    let uuid_helper = UuidHelper::new();
                    print_info!("Address: {}", &device.address);
                    print_info!("Name: {}", name);
                    print_info!("Alias: {}", alias);
@@ -541,7 +542,7 @@ impl CommandHandler {
                        DisplayList(
                            uuids
                                .iter()
                                .map(|&x| UuidHelper::to_string(&x))
                                .map(|&x| uuid_helper.known_uuid_to_string(&x))
                                .collect::<Vec<String>>()
                        )
                    );
+19 −0
Original line number Diff line number Diff line
@@ -81,6 +81,15 @@ impl<'a> Display for UuidWrapper<'a> {
    }
}

pub struct KnownUuidWrapper<'a>(pub &'a Uuid128Bit, pub &'a Profile);

impl<'a> Display for KnownUuidWrapper<'a> {
    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
        let _ = Uuid::format(&self.0, f);
        write!(f, ": {:?}", self.1)
    }
}

pub struct UuidHelper {
    /// A list of enabled profiles on the system. These may be modified by policy.
    pub enabled_profiles: HashSet<Profile>,
@@ -165,6 +174,16 @@ impl UuidHelper {
        UuidWrapper(&uuid).to_string()
    }

    /// If a uuid is known to be a certain service, convert it into a formatted
    /// string that shows the service name. Else just format the uuid.
    pub fn known_uuid_to_string(&self, uuid: &Uuid128Bit) -> String {
        if let Some(p) = self.is_known_profile(uuid) {
            return KnownUuidWrapper(&uuid, &p).to_string();
        }

        UuidHelper::to_string(uuid)
    }

    /// Converts a well-formatted UUID string to a UUID byte array.
    /// The UUID string should be in the format:
    /// 12345678-1234-1234-1234-1234567890