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