1 /* 2 * Copyright (C) 2014 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 package android.car.media; 18 19 import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.BOILERPLATE_CODE; 20 21 import android.annotation.NonNull; 22 import android.annotation.SystemApi; 23 import android.os.Parcel; 24 import android.os.Parcelable; 25 26 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport; 27 import com.android.internal.util.Preconditions; 28 29 /** 30 * A class to encapsulate the handle for a system level audio patch. This is used 31 * to provide a "safe" way for permitted applications to route automotive audio sources 32 * outside of android. 33 * @hide 34 */ 35 @SystemApi 36 public final class CarAudioPatchHandle implements Parcelable { 37 38 // This is enough information to uniquely identify a patch to the system 39 private final int mHandleId; 40 private final String mSourceAddress; 41 private final String mSinkAddress; 42 43 /** 44 * Construct a audio patch handle container given the system level handle 45 * NOTE: Assumes (as it true today), that there is exactly one device port in the source 46 * and sink arrays. 47 * 48 * @hide 49 */ CarAudioPatchHandle(int patchId, @NonNull String sourceAddress, @NonNull String sinkAddress)50 public CarAudioPatchHandle(int patchId, 51 @NonNull String sourceAddress, 52 @NonNull String sinkAddress) { 53 mSourceAddress = Preconditions.checkNotNull(sourceAddress, 54 "Patch id %d Source's Address device can not be null", patchId); 55 mSinkAddress = Preconditions.checkNotNull(sinkAddress, 56 "Patch id %d Sink's Address device can not be null", patchId); 57 mHandleId = patchId; 58 } 59 60 @Override toString()61 public String toString() { 62 return "Patch (mHandleId=" + mHandleId + "): " 63 + mSourceAddress + " => " + mSinkAddress; 64 } 65 66 /** 67 * Given a parcel, populate our data members 68 */ CarAudioPatchHandle(Parcel in)69 private CarAudioPatchHandle(Parcel in) { 70 mHandleId = in.readInt(); 71 mSourceAddress = in.readString(); 72 mSinkAddress = in.readString(); 73 } 74 75 /** 76 * Serialize our internal data to a parcel 77 */ 78 @Override writeToParcel(Parcel out, int flags)79 public void writeToParcel(Parcel out, int flags) { 80 out.writeInt(mHandleId); 81 out.writeString(mSourceAddress); 82 out.writeString(mSinkAddress); 83 } 84 85 public static final Parcelable.Creator<CarAudioPatchHandle> CREATOR = 86 new Parcelable.Creator<CarAudioPatchHandle>() { 87 public CarAudioPatchHandle createFromParcel(Parcel in) { 88 return new CarAudioPatchHandle(in); 89 } 90 91 public CarAudioPatchHandle[] newArray(int size) { 92 return new CarAudioPatchHandle[size]; 93 } 94 }; 95 96 @Override 97 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE) describeContents()98 public int describeContents() { 99 return 0; 100 } 101 102 /** 103 * returns the source address 104 * 105 * @hide 106 */ getSourceAddress()107 public String getSourceAddress() { 108 return mSourceAddress; 109 } 110 111 /** 112 * returns the sink address 113 * 114 * @hide 115 */ getSinkAddress()116 public String getSinkAddress() { 117 return mSinkAddress; 118 } 119 120 /** 121 * returns the patch handle 122 * 123 * @hide 124 */ getHandleId()125 public int getHandleId() { 126 return mHandleId; 127 } 128 } 129