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/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 36 AudioDeviceTypeAddr(audio_devices_t type, const std::string& address); 37 38 const char* getAddress() const; 39 40 const std::string& address() const; 41 42 void setAddress(const std::string& address); 43 44 bool isAddressSensitive(); 45 46 bool equals(const AudioDeviceTypeAddr& other) const; 47 48 AudioDeviceTypeAddr& operator= (const AudioDeviceTypeAddr&) = default; 49 50 bool operator<(const AudioDeviceTypeAddr& other) const; 51 52 bool operator==(const AudioDeviceTypeAddr& rhs) const; 53 54 bool operator!=(const AudioDeviceTypeAddr& rhs) const; 55 56 void reset(); 57 58 std::string toString(bool includeSensitiveInfo=false) const; 59 60 status_t readFromParcel(const Parcel *parcel) override; 61 62 status_t writeToParcel(Parcel *parcel) const override; 63 64 audio_devices_t mType = AUDIO_DEVICE_NONE; 65 66 private: 67 std::string mAddress; 68 bool mIsAddressSensitive; 69 }; 70 71 using AudioDeviceTypeAddrVector = std::vector<AudioDeviceTypeAddr>; 72 73 /** 74 * Return a collection of audio device types from a collection of AudioDeviceTypeAddr 75 */ 76 DeviceTypeSet getAudioDeviceTypes(const AudioDeviceTypeAddrVector& deviceTypeAddrs); 77 78 /** 79 * Return a collection of AudioDeviceTypeAddrs that are shown in `devices` but not 80 * in `devicesToExclude` 81 */ 82 AudioDeviceTypeAddrVector excludeDeviceTypeAddrsFrom( 83 const AudioDeviceTypeAddrVector& devices, 84 const AudioDeviceTypeAddrVector& devicesToExclude); 85 86 std::string dumpAudioDeviceTypeAddrVector(const AudioDeviceTypeAddrVector& deviceTypeAddrs, 87 bool includeSensitiveInfo=false); 88 89 // Conversion routines, according to AidlConversion.h conventions. 90 ConversionResult<AudioDeviceTypeAddr> 91 aidl2legacy_AudioDeviceTypeAddress(const media::AudioDevice& aidl); 92 ConversionResult<media::AudioDevice> 93 legacy2aidl_AudioDeviceTypeAddress(const AudioDeviceTypeAddr& legacy); 94 95 } // namespace android 96