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 package android.hardware;
17 import android.os.Parcel;
18 import android.os.Parcelable;
19 import android.util.Range;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 
24 /**
25  * The camera action state used for passing camera usage information from
26  * camera service to camera service proxy .
27  *
28  * Include camera id, facing, state, client apk name, apiLevel, isNdk,
29  * and session/stream statistics.
30  *
31  * @hide
32  */
33 public class CameraSessionStats implements Parcelable {
34     public static final int CAMERA_STATE_OPEN = 0;
35     public static final int CAMERA_STATE_ACTIVE = 1;
36     public static final int CAMERA_STATE_IDLE = 2;
37     public static final int CAMERA_STATE_CLOSED = 3;
38 
39     /**
40      * Values for notifyCameraState facing
41      */
42     public static final int CAMERA_FACING_BACK = 0;
43     public static final int CAMERA_FACING_FRONT = 1;
44     public static final int CAMERA_FACING_EXTERNAL = 2;
45 
46     /**
47      * Values for notifyCameraState api level
48      */
49     public static final int CAMERA_API_LEVEL_1 = 1;
50     public static final int CAMERA_API_LEVEL_2 = 2;
51 
52     private String mCameraId;
53     private int mFacing;
54     private int mNewCameraState;
55     private String mClientName;
56     private int mApiLevel;
57     private boolean mIsNdk;
58     private int mLatencyMs;
59     private long mLogId;
60     private int mSessionType;
61     private int mInternalReconfigure;
62     private long mRequestCount;
63     private long mResultErrorCount;
64     private boolean mDeviceError;
65     private float mMaxPreviewFps;
66     private ArrayList<CameraStreamStats> mStreamStats;
67     private String mUserTag;
68     private int mVideoStabilizationMode;
69     private boolean mUsedUltraWide;
70     private boolean mUsedZoomOverride;
71     private Range<Integer> mMostRequestedFpsRange;
72     private int mSessionIndex;
73     private CameraExtensionSessionStats mCameraExtensionSessionStats;
74 
CameraSessionStats()75     public CameraSessionStats() {
76         mFacing = -1;
77         mNewCameraState = -1;
78         mApiLevel = -1;
79         mIsNdk = false;
80         mLatencyMs = -1;
81         mLogId = 0;
82         mMaxPreviewFps = 0;
83         mSessionType = -1;
84         mInternalReconfigure = -1;
85         mRequestCount = 0;
86         mResultErrorCount = 0;
87         mDeviceError = false;
88         mStreamStats = new ArrayList<CameraStreamStats>();
89         mVideoStabilizationMode = -1;
90         mUsedUltraWide = false;
91         mUsedZoomOverride = false;
92         mMostRequestedFpsRange = new Range<Integer>(0, 0);
93         mSessionIndex = 0;
94         mCameraExtensionSessionStats = new CameraExtensionSessionStats();
95     }
96 
CameraSessionStats(String cameraId, int facing, int newCameraState, String clientName, int apiLevel, boolean isNdk, int creationDuration, float maxPreviewFps, int sessionType, int internalReconfigure, long logId, int sessionIdx)97     public CameraSessionStats(String cameraId, int facing, int newCameraState,
98             String clientName, int apiLevel, boolean isNdk, int creationDuration,
99             float maxPreviewFps, int sessionType, int internalReconfigure, long logId,
100             int sessionIdx) {
101         mCameraId = cameraId;
102         mFacing = facing;
103         mNewCameraState = newCameraState;
104         mClientName = clientName;
105         mApiLevel = apiLevel;
106         mIsNdk = isNdk;
107         mLatencyMs = creationDuration;
108         mLogId = logId;
109         mMaxPreviewFps = maxPreviewFps;
110         mSessionType = sessionType;
111         mInternalReconfigure = internalReconfigure;
112         mStreamStats = new ArrayList<CameraStreamStats>();
113         mVideoStabilizationMode = -1;
114         mUsedUltraWide = false;
115         mUsedZoomOverride = false;
116         mMostRequestedFpsRange = new Range<Integer>(0, 0);
117         mSessionIndex = sessionIdx;
118         mCameraExtensionSessionStats = new CameraExtensionSessionStats();
119     }
120 
121     public static final @android.annotation.NonNull Parcelable.Creator<CameraSessionStats> CREATOR =
122             new Parcelable.Creator<CameraSessionStats>() {
123         @Override
124         public CameraSessionStats createFromParcel(Parcel in) {
125             return new CameraSessionStats(in);
126         }
127 
128         @Override
129         public CameraSessionStats[] newArray(int size) {
130             return new CameraSessionStats[size];
131         }
132     };
133 
CameraSessionStats(Parcel in)134     private CameraSessionStats(Parcel in) {
135         readFromParcel(in);
136     }
137 
138     @Override
describeContents()139     public int describeContents() {
140         return 0;
141     }
142 
143     @Override
writeToParcel(Parcel dest, int flags)144     public void writeToParcel(Parcel dest, int flags) {
145         dest.writeString(mCameraId);
146         dest.writeInt(mFacing);
147         dest.writeInt(mNewCameraState);
148         dest.writeString(mClientName);
149         dest.writeInt(mApiLevel);
150         dest.writeBoolean(mIsNdk);
151         dest.writeInt(mLatencyMs);
152         dest.writeLong(mLogId);
153         dest.writeFloat(mMaxPreviewFps);
154         dest.writeInt(mSessionType);
155         dest.writeInt(mInternalReconfigure);
156         dest.writeLong(mRequestCount);
157         dest.writeLong(mResultErrorCount);
158         dest.writeBoolean(mDeviceError);
159         dest.writeTypedList(mStreamStats);
160         dest.writeString(mUserTag);
161         dest.writeInt(mVideoStabilizationMode);
162         dest.writeBoolean(mUsedUltraWide);
163         dest.writeBoolean(mUsedZoomOverride);
164         dest.writeInt(mSessionIndex);
165         mCameraExtensionSessionStats.writeToParcel(dest, 0);
166         dest.writeInt(mMostRequestedFpsRange.getLower());
167         dest.writeInt(mMostRequestedFpsRange.getUpper());
168     }
169 
readFromParcel(Parcel in)170     public void readFromParcel(Parcel in) {
171         mCameraId = in.readString();
172         mFacing = in.readInt();
173         mNewCameraState = in.readInt();
174         mClientName = in.readString();
175         mApiLevel = in.readInt();
176         mIsNdk = in.readBoolean();
177         mLatencyMs = in.readInt();
178         mLogId = in.readLong();
179         mMaxPreviewFps = in.readFloat();
180         mSessionType = in.readInt();
181         mInternalReconfigure = in.readInt();
182         mRequestCount = in.readLong();
183         mResultErrorCount = in.readLong();
184         mDeviceError = in.readBoolean();
185 
186         ArrayList<CameraStreamStats> streamStats = new ArrayList<CameraStreamStats>();
187         in.readTypedList(streamStats, CameraStreamStats.CREATOR);
188         mStreamStats = streamStats;
189 
190         mUserTag = in.readString();
191         mVideoStabilizationMode = in.readInt();
192 
193         mUsedUltraWide = in.readBoolean();
194         mUsedZoomOverride = in.readBoolean();
195 
196         mSessionIndex = in.readInt();
197         mCameraExtensionSessionStats = CameraExtensionSessionStats.CREATOR.createFromParcel(in);
198         int minFps = in.readInt();
199         int maxFps = in.readInt();
200         mMostRequestedFpsRange = new Range<Integer>(minFps, maxFps);
201     }
202 
getCameraId()203     public String getCameraId() {
204         return mCameraId;
205     }
206 
getFacing()207     public int getFacing() {
208         return mFacing;
209     }
210 
getNewCameraState()211     public int getNewCameraState() {
212         return mNewCameraState;
213     }
214 
getClientName()215     public String getClientName() {
216         return mClientName;
217     }
218 
getApiLevel()219     public int getApiLevel() {
220         return mApiLevel;
221     }
222 
isNdk()223     public boolean isNdk() {
224         return mIsNdk;
225     }
226 
getLatencyMs()227     public int getLatencyMs() {
228         return mLatencyMs;
229     }
230 
getLogId()231     public long getLogId() {
232         return mLogId;
233     }
234 
getMaxPreviewFps()235     public float getMaxPreviewFps() {
236         return mMaxPreviewFps;
237     }
238 
getSessionType()239     public int getSessionType() {
240         return mSessionType;
241     }
242 
getInternalReconfigureCount()243     public int getInternalReconfigureCount() {
244         return mInternalReconfigure;
245     }
246 
getRequestCount()247     public long getRequestCount() {
248         return mRequestCount;
249     }
250 
getResultErrorCount()251     public long getResultErrorCount() {
252         return mResultErrorCount;
253     }
254 
getDeviceErrorFlag()255     public boolean getDeviceErrorFlag() {
256         return mDeviceError;
257     }
258 
getStreamStats()259     public List<CameraStreamStats> getStreamStats() {
260         return mStreamStats;
261     }
262 
getUserTag()263     public String getUserTag() {
264         return mUserTag;
265     }
266 
getVideoStabilizationMode()267     public int getVideoStabilizationMode() {
268         return mVideoStabilizationMode;
269     }
270 
getUsedUltraWide()271     public boolean getUsedUltraWide() {
272         return mUsedUltraWide;
273     }
274 
getUsedZoomOverride()275     public boolean getUsedZoomOverride() {
276         return mUsedZoomOverride;
277     }
278 
getSessionIndex()279     public int getSessionIndex() {
280         return mSessionIndex;
281     }
282 
getExtensionSessionStats()283     public CameraExtensionSessionStats getExtensionSessionStats() {
284         return mCameraExtensionSessionStats;
285     }
286 
getMostRequestedFpsRange()287     public Range<Integer> getMostRequestedFpsRange() {
288         return mMostRequestedFpsRange;
289     }
290 }
291