1 /*
2  * Copyright (C) 2020 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.hardware.camera2.utils;
18 
19 import android.annotation.NonNull;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 import android.util.ArraySet;
23 import android.util.Pair;
24 
25 import java.util.Set;
26 
27 /**
28  * ConcurrentCameraIdCombination
29  *
30  * Includes a list of camera ids that may have sessions configured concurrently.
31  * @hide
32  */
33 public class ConcurrentCameraIdCombination implements Parcelable {
34 
35     private final Set<Pair<String, Integer>> mConcurrentCameraIdDeviceIdPairs = new ArraySet<>();
36 
37     public static final @NonNull
38             Parcelable.Creator<ConcurrentCameraIdCombination> CREATOR =
39             new Parcelable.Creator<>() {
40                 @Override
41                 public ConcurrentCameraIdCombination createFromParcel(Parcel in) {
42                     return new ConcurrentCameraIdCombination(in);
43                 }
44 
45                 @Override
46                 public ConcurrentCameraIdCombination[] newArray(int size) {
47                     return new ConcurrentCameraIdCombination[size];
48                 }
49             };
50 
ConcurrentCameraIdCombination(Parcel in)51     private ConcurrentCameraIdCombination(Parcel in) {
52         readFromParcel(in);
53     }
54 
55     @Override
describeContents()56     public int describeContents() {
57         return 0;
58     }
59 
60     @Override
writeToParcel(Parcel dest, int flags)61     public void writeToParcel(Parcel dest, int flags) {
62         dest.writeInt(mConcurrentCameraIdDeviceIdPairs.size());
63         for (Pair<String, Integer> cameraIdDeviceIdPair : mConcurrentCameraIdDeviceIdPairs) {
64             dest.writeString(cameraIdDeviceIdPair.first);
65             dest.writeInt(cameraIdDeviceIdPair.second);
66         }
67     }
68 
69     /**
70      * helper for CREATOR
71      */
readFromParcel(Parcel in)72     public void readFromParcel(Parcel in) {
73         mConcurrentCameraIdDeviceIdPairs.clear();
74         int cameraCombinationSize = in.readInt();
75         if (cameraCombinationSize < 0) {
76             throw new RuntimeException("cameraCombinationSize " + cameraCombinationSize
77                     + " should not be negative");
78         }
79         for (int i = 0; i < cameraCombinationSize; i++) {
80             String cameraId = in.readString();
81             if (cameraId == null) {
82                 throw new RuntimeException("Failed to read camera id from Parcel");
83             }
84             int deviceId = in.readInt();
85             mConcurrentCameraIdDeviceIdPairs.add(new Pair<>(cameraId, deviceId));
86         }
87     }
88 
89     /**
90      * Get this concurrent camera id combination.
91      */
getConcurrentCameraIdCombination()92     public Set<Pair<String, Integer>> getConcurrentCameraIdCombination() {
93         return mConcurrentCameraIdDeviceIdPairs;
94     }
95 }
96