Loading core/java/android/hardware/camera2/impl/CameraMetadataNative.java +71 −44 Original line number Diff line number Diff line Loading @@ -437,7 +437,7 @@ public class CameraMetadataNative implements Parcelable { } @Override public void writeToParcel(Parcel dest, int flags) { public synchronized void writeToParcel(Parcel dest, int flags) { nativeWriteToParcel(dest, mMetadataPtr); } Loading Loading @@ -479,7 +479,7 @@ public class CameraMetadataNative implements Parcelable { return getBase(key); } public void readFromParcel(Parcel in) { public synchronized void readFromParcel(Parcel in) { nativeReadFromParcel(in, mMetadataPtr); updateNativeAllocation(); } Loading Loading @@ -592,14 +592,16 @@ public class CameraMetadataNative implements Parcelable { } private <T> T getBase(Key<T> key) { int tag; int tag, nativeType; byte[] values = null; synchronized (this) { if (key.hasTag()) { tag = key.getTag(); } else { tag = nativeGetTagFromKeyLocal(mMetadataPtr, key.getName()); key.cacheTag(tag); } byte[] values = readValues(tag); values = readValues(tag); if (values == null) { // If the key returns null, use the fallback key if exists. // This is to support old key names for the newly published keys. Loading @@ -613,7 +615,10 @@ public class CameraMetadataNative implements Parcelable { } } int nativeType = nativeGetTypeFromTagLocal(mMetadataPtr, tag); nativeType = nativeGetTypeFromTagLocal(mMetadataPtr, tag); } // This block of code doesn't need to be synchronized since we aren't writing or reading // from the metadata buffer for this instance of CameraMetadataNative. Marshaler<T> marshaler = getMarshalerForKey(key, nativeType); ByteBuffer buffer = ByteBuffer.wrap(values).order(ByteOrder.nativeOrder()); return marshaler.unmarshal(buffer); Loading Loading @@ -1945,8 +1950,12 @@ public class CameraMetadataNative implements Parcelable { setBase(key.getNativeKey(), value); } private <T> void setBase(Key<T> key, T value) { int tag; // The whole method needs to be synchronized since we're making // multiple calls to the native layer. From one call to the other (within setBase) // we expect the metadata's properties such as vendor id etc to // stay the same and as a result the whole method should be synchronized for safety. private synchronized <T> void setBase(Key<T> key, T value) { int tag, nativeType; if (key.hasTag()) { tag = key.getTag(); } else { Loading @@ -1959,7 +1968,7 @@ public class CameraMetadataNative implements Parcelable { return; } // else update the entry to a new value int nativeType = nativeGetTypeFromTagLocal(mMetadataPtr, tag); nativeType = nativeGetTypeFromTagLocal(mMetadataPtr, tag); Marshaler<T> marshaler = getMarshalerForKey(key, nativeType); int size = marshaler.calculateMarshalSize(value); Loading Loading @@ -2162,7 +2171,7 @@ public class CameraMetadataNative implements Parcelable { return true; } private void updateNativeAllocation() { private synchronized void updateNativeAllocation() { long currentBufferSize = nativeGetBufferSize(mMetadataPtr); if (currentBufferSize != mBufferSize) { Loading Loading @@ -2245,6 +2254,11 @@ public class CameraMetadataNative implements Parcelable { @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) private long mMetadataPtr; // native std::shared_ptr<CameraMetadata>* // FastNative doesn't work with synchronized methods and we can do synchronization // wherever needed in the java layer (caller). At some places in java such as // setBase() / getBase(), we do need to synchronize the whole method, so leaving // synchronized out for these native methods. @FastNative private static native long nativeAllocate(); @FastNative Loading @@ -2254,28 +2268,41 @@ public class CameraMetadataNative implements Parcelable { @FastNative private static native void nativeUpdate(long dst, long src); private static synchronized native void nativeWriteToParcel(Parcel dest, long ptr); private static synchronized native void nativeReadFromParcel(Parcel source, long ptr); private static synchronized native void nativeSwap(long ptr, long otherPtr) @FastNative private static native void nativeWriteToParcel(Parcel dest, long ptr); @FastNative private static native void nativeReadFromParcel(Parcel source, long ptr); @FastNative private static native void nativeSwap(long ptr, long otherPtr) throws NullPointerException; @FastNative private static native void nativeSetVendorId(long ptr, long vendorId); private static synchronized native void nativeClose(long ptr); private static synchronized native boolean nativeIsEmpty(long ptr); private static synchronized native int nativeGetEntryCount(long ptr); private static synchronized native long nativeGetBufferSize(long ptr); @FastNative private static native void nativeClose(long ptr); @FastNative private static native boolean nativeIsEmpty(long ptr); @FastNative private static native int nativeGetEntryCount(long ptr); @FastNative private static native long nativeGetBufferSize(long ptr); @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) private static synchronized native byte[] nativeReadValues(int tag, long ptr); private static synchronized native void nativeWriteValues(int tag, byte[] src, long ptr); private static synchronized native void nativeDump(long ptr) throws IOException; // dump to LOGD @FastNative private static native byte[] nativeReadValues(int tag, long ptr); @FastNative private static native void nativeWriteValues(int tag, byte[] src, long ptr); @FastNative private static native void nativeDump(long ptr) throws IOException; // dump to LOGD private static synchronized native ArrayList nativeGetAllVendorKeys(long ptr, Class keyClass); @FastNative private static native ArrayList nativeGetAllVendorKeys(long ptr, Class keyClass); @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) private static synchronized native int nativeGetTagFromKeyLocal(long ptr, String keyName) @FastNative private static native int nativeGetTagFromKeyLocal(long ptr, String keyName) throws IllegalArgumentException; @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) private static synchronized native int nativeGetTypeFromTagLocal(long ptr, int tag) @FastNative private static native int nativeGetTypeFromTagLocal(long ptr, int tag) throws IllegalArgumentException; @FastNative private static native int nativeGetTagFromKey(String keyName, long vendorId) Loading @@ -2293,7 +2320,7 @@ public class CameraMetadataNative implements Parcelable { * @throws NullPointerException if other was null * @hide */ public void swap(CameraMetadataNative other) { public synchronized void swap(CameraMetadataNative other) { nativeSwap(mMetadataPtr, other.mMetadataPtr); mCameraId = other.mCameraId; mHasMandatoryConcurrentStreams = other.mHasMandatoryConcurrentStreams; Loading @@ -2308,14 +2335,14 @@ public class CameraMetadataNative implements Parcelable { * * @hide */ public void setVendorId(long vendorId) { public synchronized void setVendorId(long vendorId) { nativeSetVendorId(mMetadataPtr, vendorId); } /** * @hide */ public int getEntryCount() { public synchronized int getEntryCount() { return nativeGetEntryCount(mMetadataPtr); } Loading @@ -2324,7 +2351,7 @@ public class CameraMetadataNative implements Parcelable { * * @hide */ public boolean isEmpty() { public synchronized boolean isEmpty() { return nativeIsEmpty(mMetadataPtr); } Loading @@ -2343,7 +2370,7 @@ public class CameraMetadataNative implements Parcelable { * * @hide */ public <K> ArrayList<K> getAllVendorKeys(Class<K> keyClass) { public synchronized <K> ArrayList<K> getAllVendorKeys(Class<K> keyClass) { if (keyClass == null) { throw new NullPointerException(); } Loading Loading @@ -2398,7 +2425,7 @@ public class CameraMetadataNative implements Parcelable { * * @hide */ public void writeValues(int tag, byte[] src) { public synchronized void writeValues(int tag, byte[] src) { nativeWriteValues(tag, src, mMetadataPtr); } Loading @@ -2413,7 +2440,7 @@ public class CameraMetadataNative implements Parcelable { * @return {@code null} if there were 0 entries for this tag, a byte[] otherwise. * @hide */ public byte[] readValues(int tag) { public synchronized byte[] readValues(int tag) { // TODO: Optimization. Native code returns a ByteBuffer instead. return nativeReadValues(tag, mMetadataPtr); } Loading @@ -2426,7 +2453,7 @@ public class CameraMetadataNative implements Parcelable { * * @hide */ public void dumpToLog() { public synchronized void dumpToLog() { try { nativeDump(mMetadataPtr); } catch (IOException e) { Loading Loading
core/java/android/hardware/camera2/impl/CameraMetadataNative.java +71 −44 Original line number Diff line number Diff line Loading @@ -437,7 +437,7 @@ public class CameraMetadataNative implements Parcelable { } @Override public void writeToParcel(Parcel dest, int flags) { public synchronized void writeToParcel(Parcel dest, int flags) { nativeWriteToParcel(dest, mMetadataPtr); } Loading Loading @@ -479,7 +479,7 @@ public class CameraMetadataNative implements Parcelable { return getBase(key); } public void readFromParcel(Parcel in) { public synchronized void readFromParcel(Parcel in) { nativeReadFromParcel(in, mMetadataPtr); updateNativeAllocation(); } Loading Loading @@ -592,14 +592,16 @@ public class CameraMetadataNative implements Parcelable { } private <T> T getBase(Key<T> key) { int tag; int tag, nativeType; byte[] values = null; synchronized (this) { if (key.hasTag()) { tag = key.getTag(); } else { tag = nativeGetTagFromKeyLocal(mMetadataPtr, key.getName()); key.cacheTag(tag); } byte[] values = readValues(tag); values = readValues(tag); if (values == null) { // If the key returns null, use the fallback key if exists. // This is to support old key names for the newly published keys. Loading @@ -613,7 +615,10 @@ public class CameraMetadataNative implements Parcelable { } } int nativeType = nativeGetTypeFromTagLocal(mMetadataPtr, tag); nativeType = nativeGetTypeFromTagLocal(mMetadataPtr, tag); } // This block of code doesn't need to be synchronized since we aren't writing or reading // from the metadata buffer for this instance of CameraMetadataNative. Marshaler<T> marshaler = getMarshalerForKey(key, nativeType); ByteBuffer buffer = ByteBuffer.wrap(values).order(ByteOrder.nativeOrder()); return marshaler.unmarshal(buffer); Loading Loading @@ -1945,8 +1950,12 @@ public class CameraMetadataNative implements Parcelable { setBase(key.getNativeKey(), value); } private <T> void setBase(Key<T> key, T value) { int tag; // The whole method needs to be synchronized since we're making // multiple calls to the native layer. From one call to the other (within setBase) // we expect the metadata's properties such as vendor id etc to // stay the same and as a result the whole method should be synchronized for safety. private synchronized <T> void setBase(Key<T> key, T value) { int tag, nativeType; if (key.hasTag()) { tag = key.getTag(); } else { Loading @@ -1959,7 +1968,7 @@ public class CameraMetadataNative implements Parcelable { return; } // else update the entry to a new value int nativeType = nativeGetTypeFromTagLocal(mMetadataPtr, tag); nativeType = nativeGetTypeFromTagLocal(mMetadataPtr, tag); Marshaler<T> marshaler = getMarshalerForKey(key, nativeType); int size = marshaler.calculateMarshalSize(value); Loading Loading @@ -2162,7 +2171,7 @@ public class CameraMetadataNative implements Parcelable { return true; } private void updateNativeAllocation() { private synchronized void updateNativeAllocation() { long currentBufferSize = nativeGetBufferSize(mMetadataPtr); if (currentBufferSize != mBufferSize) { Loading Loading @@ -2245,6 +2254,11 @@ public class CameraMetadataNative implements Parcelable { @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) private long mMetadataPtr; // native std::shared_ptr<CameraMetadata>* // FastNative doesn't work with synchronized methods and we can do synchronization // wherever needed in the java layer (caller). At some places in java such as // setBase() / getBase(), we do need to synchronize the whole method, so leaving // synchronized out for these native methods. @FastNative private static native long nativeAllocate(); @FastNative Loading @@ -2254,28 +2268,41 @@ public class CameraMetadataNative implements Parcelable { @FastNative private static native void nativeUpdate(long dst, long src); private static synchronized native void nativeWriteToParcel(Parcel dest, long ptr); private static synchronized native void nativeReadFromParcel(Parcel source, long ptr); private static synchronized native void nativeSwap(long ptr, long otherPtr) @FastNative private static native void nativeWriteToParcel(Parcel dest, long ptr); @FastNative private static native void nativeReadFromParcel(Parcel source, long ptr); @FastNative private static native void nativeSwap(long ptr, long otherPtr) throws NullPointerException; @FastNative private static native void nativeSetVendorId(long ptr, long vendorId); private static synchronized native void nativeClose(long ptr); private static synchronized native boolean nativeIsEmpty(long ptr); private static synchronized native int nativeGetEntryCount(long ptr); private static synchronized native long nativeGetBufferSize(long ptr); @FastNative private static native void nativeClose(long ptr); @FastNative private static native boolean nativeIsEmpty(long ptr); @FastNative private static native int nativeGetEntryCount(long ptr); @FastNative private static native long nativeGetBufferSize(long ptr); @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) private static synchronized native byte[] nativeReadValues(int tag, long ptr); private static synchronized native void nativeWriteValues(int tag, byte[] src, long ptr); private static synchronized native void nativeDump(long ptr) throws IOException; // dump to LOGD @FastNative private static native byte[] nativeReadValues(int tag, long ptr); @FastNative private static native void nativeWriteValues(int tag, byte[] src, long ptr); @FastNative private static native void nativeDump(long ptr) throws IOException; // dump to LOGD private static synchronized native ArrayList nativeGetAllVendorKeys(long ptr, Class keyClass); @FastNative private static native ArrayList nativeGetAllVendorKeys(long ptr, Class keyClass); @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) private static synchronized native int nativeGetTagFromKeyLocal(long ptr, String keyName) @FastNative private static native int nativeGetTagFromKeyLocal(long ptr, String keyName) throws IllegalArgumentException; @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) private static synchronized native int nativeGetTypeFromTagLocal(long ptr, int tag) @FastNative private static native int nativeGetTypeFromTagLocal(long ptr, int tag) throws IllegalArgumentException; @FastNative private static native int nativeGetTagFromKey(String keyName, long vendorId) Loading @@ -2293,7 +2320,7 @@ public class CameraMetadataNative implements Parcelable { * @throws NullPointerException if other was null * @hide */ public void swap(CameraMetadataNative other) { public synchronized void swap(CameraMetadataNative other) { nativeSwap(mMetadataPtr, other.mMetadataPtr); mCameraId = other.mCameraId; mHasMandatoryConcurrentStreams = other.mHasMandatoryConcurrentStreams; Loading @@ -2308,14 +2335,14 @@ public class CameraMetadataNative implements Parcelable { * * @hide */ public void setVendorId(long vendorId) { public synchronized void setVendorId(long vendorId) { nativeSetVendorId(mMetadataPtr, vendorId); } /** * @hide */ public int getEntryCount() { public synchronized int getEntryCount() { return nativeGetEntryCount(mMetadataPtr); } Loading @@ -2324,7 +2351,7 @@ public class CameraMetadataNative implements Parcelable { * * @hide */ public boolean isEmpty() { public synchronized boolean isEmpty() { return nativeIsEmpty(mMetadataPtr); } Loading @@ -2343,7 +2370,7 @@ public class CameraMetadataNative implements Parcelable { * * @hide */ public <K> ArrayList<K> getAllVendorKeys(Class<K> keyClass) { public synchronized <K> ArrayList<K> getAllVendorKeys(Class<K> keyClass) { if (keyClass == null) { throw new NullPointerException(); } Loading Loading @@ -2398,7 +2425,7 @@ public class CameraMetadataNative implements Parcelable { * * @hide */ public void writeValues(int tag, byte[] src) { public synchronized void writeValues(int tag, byte[] src) { nativeWriteValues(tag, src, mMetadataPtr); } Loading @@ -2413,7 +2440,7 @@ public class CameraMetadataNative implements Parcelable { * @return {@code null} if there were 0 entries for this tag, a byte[] otherwise. * @hide */ public byte[] readValues(int tag) { public synchronized byte[] readValues(int tag) { // TODO: Optimization. Native code returns a ByteBuffer instead. return nativeReadValues(tag, mMetadataPtr); } Loading @@ -2426,7 +2453,7 @@ public class CameraMetadataNative implements Parcelable { * * @hide */ public void dumpToLog() { public synchronized void dumpToLog() { try { nativeDump(mMetadataPtr); } catch (IOException e) { Loading