diff options
3 files changed, 44 insertions, 6 deletions
diff --git a/core/java/android/hardware/CameraSessionStats.java b/core/java/android/hardware/CameraSessionStats.java index 698cc76f6325..9ef63065c057 100644 --- a/core/java/android/hardware/CameraSessionStats.java +++ b/core/java/android/hardware/CameraSessionStats.java @@ -61,6 +61,7 @@ public class CameraSessionStats implements Parcelable { private boolean mDeviceError; private float mMaxPreviewFps; private ArrayList<CameraStreamStats> mStreamStats; + private String mUserTag; public CameraSessionStats() { mFacing = -1; @@ -131,6 +132,7 @@ public class CameraSessionStats implements Parcelable { dest.writeLong(mResultErrorCount); dest.writeBoolean(mDeviceError); dest.writeTypedList(mStreamStats); + dest.writeString(mUserTag); } public void readFromParcel(Parcel in) { @@ -151,6 +153,8 @@ public class CameraSessionStats implements Parcelable { ArrayList<CameraStreamStats> streamStats = new ArrayList<CameraStreamStats>(); in.readTypedList(streamStats, CameraStreamStats.CREATOR); mStreamStats = streamStats; + + mUserTag = in.readString(); } public String getCameraId() { @@ -208,4 +212,8 @@ public class CameraSessionStats implements Parcelable { public List<CameraStreamStats> getStreamStats() { return mStreamStats; } + + public String getUserTag() { + return mUserTag; + } } diff --git a/core/java/android/hardware/camera2/CaptureRequest.java b/core/java/android/hardware/camera2/CaptureRequest.java index d94ad3aa1732..ff9a7cf40b0b 100644 --- a/core/java/android/hardware/camera2/CaptureRequest.java +++ b/core/java/android/hardware/camera2/CaptureRequest.java @@ -266,6 +266,8 @@ public final class CaptureRequest extends CameraMetadata<CaptureRequest.Key<?>> private int mRequestType = -1; + private static final String SET_TAG_STRING_PREFIX = + "android.hardware.camera2.CaptureRequest.setTag."; /** * Get the type of the capture request * @@ -614,6 +616,11 @@ public final class CaptureRequest extends CameraMetadata<CaptureRequest.Key<?>> throw new RuntimeException("Reading cached CaptureRequest is not supported"); } } + + boolean hasUserTagStr = (in.readInt() == 1) ? true : false; + if (hasUserTagStr) { + mUserTag = in.readString(); + } } @Override @@ -656,6 +663,19 @@ public final class CaptureRequest extends CameraMetadata<CaptureRequest.Key<?>> dest.writeInt(0); } } + + // Write string for user tag if set to something in the same namespace + if (mUserTag != null) { + String userTagStr = mUserTag.toString(); + if (userTagStr != null && userTagStr.startsWith(SET_TAG_STRING_PREFIX)) { + dest.writeInt(1); + dest.writeString(userTagStr.substring(SET_TAG_STRING_PREFIX.length())); + } else { + dest.writeInt(0); + } + } else { + dest.writeInt(0); + } } /** @@ -938,7 +958,10 @@ public final class CaptureRequest extends CameraMetadata<CaptureRequest.Key<?>> * <p>This tag is not used for anything by the camera device, but can be * used by an application to easily identify a CaptureRequest when it is * returned by - * {@link CameraCaptureSession.CaptureCallback#onCaptureCompleted CaptureCallback.onCaptureCompleted} + * {@link CameraCaptureSession.CaptureCallback#onCaptureCompleted CaptureCallback.onCaptureCompleted}.</p> + * + * <p>If the application overrides the tag object's {@link Object#toString} function, the + * returned string must not contain personal identifiable information.</p> * * @param tag an arbitrary Object to store with this request * @see CaptureRequest#getTag diff --git a/services/core/java/com/android/server/camera/CameraServiceProxy.java b/services/core/java/com/android/server/camera/CameraServiceProxy.java index 7db99f1da130..be112537274a 100644 --- a/services/core/java/com/android/server/camera/CameraServiceProxy.java +++ b/services/core/java/com/android/server/camera/CameraServiceProxy.java @@ -239,6 +239,8 @@ public class CameraServiceProxy extends SystemService public long mResultErrorCount; public boolean mDeviceError; public List<CameraStreamStats> mStreamStats; + public String mUserTag; + private long mDurationOrStartTimeMs; // Either start time, or duration once completed CameraUsageEvent(String cameraId, int facing, String clientName, int apiLevel, @@ -257,7 +259,7 @@ public class CameraServiceProxy extends SystemService public void markCompleted(int internalReconfigure, long requestCount, long resultErrorCount, boolean deviceError, - List<CameraStreamStats> streamStats) { + List<CameraStreamStats> streamStats, String userTag) { if (mCompleted) { return; } @@ -268,6 +270,7 @@ public class CameraServiceProxy extends SystemService mResultErrorCount = resultErrorCount; mDeviceError = deviceError; mStreamStats = streamStats; + mUserTag = userTag; if (CameraServiceProxy.DEBUG) { Slog.v(TAG, "A camera facing " + cameraFacingToString(mCameraFacing) + " was in use by " + mClientName + " for " + @@ -794,7 +797,8 @@ public class CameraServiceProxy extends SystemService + ", requestCount " + e.mRequestCount + ", resultErrorCount " + e.mResultErrorCount + ", deviceError " + e.mDeviceError - + ", streamCount is " + streamCount); + + ", streamCount is " + streamCount + + ", userTag is " + e.mUserTag); } // Convert from CameraStreamStats to CameraStreamProto CameraStreamProto[] streamProtos = new CameraStreamProto[MAX_STREAM_STATISTICS]; @@ -851,7 +855,8 @@ public class CameraServiceProxy extends SystemService MessageNano.toByteArray(streamProtos[1]), MessageNano.toByteArray(streamProtos[2]), MessageNano.toByteArray(streamProtos[3]), - MessageNano.toByteArray(streamProtos[4])); + MessageNano.toByteArray(streamProtos[4]), + e.mUserTag); } } @@ -1038,6 +1043,7 @@ public class CameraServiceProxy extends SystemService long resultErrorCount = cameraState.getResultErrorCount(); boolean deviceError = cameraState.getDeviceErrorFlag(); List<CameraStreamStats> streamStats = cameraState.getStreamStats(); + String userTag = cameraState.getUserTag(); synchronized(mLock) { // Update active camera list and notify NFC if necessary boolean wasEmpty = mActiveCameraUsage.isEmpty(); @@ -1091,7 +1097,8 @@ public class CameraServiceProxy extends SystemService if (oldEvent != null) { Slog.w(TAG, "Camera " + cameraId + " was already marked as active"); oldEvent.markCompleted(/*internalReconfigure*/0, /*requestCount*/0, - /*resultErrorCount*/0, /*deviceError*/false, streamStats); + /*resultErrorCount*/0, /*deviceError*/false, streamStats, + /*userTag*/""); mCameraUsageHistory.add(oldEvent); } break; @@ -1101,7 +1108,7 @@ public class CameraServiceProxy extends SystemService if (doneEvent != null) { doneEvent.markCompleted(internalReconfigureCount, requestCount, - resultErrorCount, deviceError, streamStats); + resultErrorCount, deviceError, streamStats, userTag); mCameraUsageHistory.add(doneEvent); // Check current active camera IDs to see if this package is still |