• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 <string>
20 #include <vector>
21 
22 #include <android/media/audio/common/AudioDevice.h>
23 #include <binder/Parcelable.h>
24 #include <binder/Parcel.h>
25 #include <media/AudioContainers.h>
26 #include <media/AidlConversionUtil.h>
27 #include <system/audio.h>
28 #include <utils/Errors.h>
29 
30 namespace android {
31 
32 class AudioDeviceTypeAddr : public Parcelable {
33 public:
34     AudioDeviceTypeAddr() = default;
35     AudioDeviceTypeAddr(const AudioDeviceTypeAddr&) = default;
36 
37     AudioDeviceTypeAddr(audio_devices_t type, const std::string& address);
38 
39     const char* getAddress() const;
40 
41     const std::string& address() const;
42 
43     void setAddress(const std::string& address);
44 
45     bool isAddressSensitive();
46 
47     bool equals(const AudioDeviceTypeAddr& other) const;
48 
49     AudioDeviceTypeAddr& operator= (const AudioDeviceTypeAddr&) = default;
50 
51     bool operator<(const AudioDeviceTypeAddr& other) const;
52 
53     bool operator==(const AudioDeviceTypeAddr& rhs) const;
54 
55     bool operator!=(const AudioDeviceTypeAddr& rhs) const;
56 
57     void reset();
58 
59     std::string toString(bool includeSensitiveInfo=false) const;
60 
61     status_t readFromParcel(const Parcel *parcel) override;
62 
63     status_t writeToParcel(Parcel *parcel) const override;
64 
65     audio_devices_t mType = AUDIO_DEVICE_NONE;
66 
67 private:
68     std::string mAddress;
69     bool mIsAddressSensitive;
70 };
71 
72 using AudioDeviceTypeAddrVector = std::vector<AudioDeviceTypeAddr>;
73 
74 /**
75  * Return a collection of audio device types from a collection of AudioDeviceTypeAddr
76  */
77 DeviceTypeSet getAudioDeviceTypes(const AudioDeviceTypeAddrVector& deviceTypeAddrs);
78 
79 /**
80  * Return a collection of AudioDeviceTypeAddrs that are shown in `devices` but not
81  * in `devicesToExclude`
82  */
83 AudioDeviceTypeAddrVector excludeDeviceTypeAddrsFrom(
84         const AudioDeviceTypeAddrVector& devices,
85         const AudioDeviceTypeAddrVector& devicesToExclude);
86 
87 /**
88  * Return a collection of AudioDeviceTypeAddrs that is the union of `devices` and
89  * `devicesToJoin`
90  */
91 AudioDeviceTypeAddrVector joinDeviceTypeAddrs(
92         const AudioDeviceTypeAddrVector& devices,
93         const AudioDeviceTypeAddrVector& devicesToJoin);
94 
95 std::string dumpAudioDeviceTypeAddrVector(const AudioDeviceTypeAddrVector& deviceTypeAddrs,
96                                           bool includeSensitiveInfo=false);
97 
98 // Conversion routines, according to AidlConversion.h conventions.
99 ConversionResult<AudioDeviceTypeAddr>
100 aidl2legacy_AudioDeviceTypeAddress(const media::audio::common::AudioDevice& aidl);
101 ConversionResult<media::audio::common::AudioDevice>
102 legacy2aidl_AudioDeviceTypeAddress(const AudioDeviceTypeAddr& legacy);
103 
104 } // namespace android
105