1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <aidl/android/media/audio/common/AudioUuid.h>
20 #include <android-base/stringprintf.h>
21 
22 namespace android::audio::utils {
23 
24 /**
25  * This method returns a string representation of the AudioUuid object in hexadecimal format which
26  * aligns with the UUID canonical textual representation.
27  *
28  * There is also an AIDL generated ::aidl::android::media::audio::common::AudioUuid::toString()
29  * method that returns a decimal format string of the AudioUuid object.
30  *
31  * If this header is included, then android::internal::ToString(AudioUuid) is expected to use this
32  * toString() override implementation instead of the generated one.
33  */
toString(const::aidl::android::media::audio::common::AudioUuid & uuid)34 static inline std::string toString(const ::aidl::android::media::audio::common::AudioUuid& uuid) {
35   return android::base::StringPrintf(
36       "%08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x", uuid.timeLow,
37       uuid.timeMid, uuid.timeHiAndVersion, uuid.clockSeq, uuid.node[0],
38       uuid.node[1], uuid.node[2], uuid.node[3], uuid.node[4], uuid.node[5]);
39 }
40 
41 } // namespace android::audio::utils