Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f01e40c5 authored by Justin Yun's avatar Justin Yun
Browse files

Camera: Use fallback key if the requested key returns null

If the key returns null, try with the fallback key to get the values.
This is to support old key names for old camera hals.

Bug: 79183654
Test: Launch GCA in P and P+OMR1 walleye devices.

Change-Id: I1d55cc53b159401d4cd47da9a02f174cb6cb9e5e
parent 2b3c8582
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -76,6 +76,15 @@ public final class CameraCharacteristics extends CameraMetadata<CameraCharacteri
            mKey = new CameraMetadataNative.Key<T>(name,  type, vendorId);
        }

        /**
         * Visible for testing and vendor extensions only.
         *
         * @hide
         */
        public Key(String name, String fallbackName, Class<T> type) {
            mKey = new CameraMetadataNative.Key<T>(name,  fallbackName, type);
        }

        /**
         * Visible for testing and vendor extensions only.
         *
+9 −0
Original line number Diff line number Diff line
@@ -82,6 +82,15 @@ public class CaptureResult extends CameraMetadata<CaptureResult.Key<?>> {
            mKey = new CameraMetadataNative.Key<T>(name, type, vendorId);
        }

        /**
         * Visible for testing and vendor extensions only.
         *
         * @hide
         */
        public Key(String name, String fallbackName, Class<T> type) {
            mKey = new CameraMetadataNative.Key<T>(name, fallbackName, type);
        }

       /**
         * Visible for testing and vendor extensions only.
         *
+30 −1
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ public class CameraMetadataNative implements Parcelable {
        private final Class<T> mType;
        private final TypeReference<T> mTypeReference;
        private final String mName;
        private final String mFallbackName;
        private final int mHash;

        /**
@@ -96,12 +97,29 @@ public class CameraMetadataNative implements Parcelable {
                throw new NullPointerException("Type needs to be non-null");
            }
            mName = name;
            mFallbackName = null;
            mType = type;
            mVendorId = vendorId;
            mTypeReference = TypeReference.createSpecializedTypeReference(type);
            mHash = mName.hashCode() ^ mTypeReference.hashCode();
        }

        /**
         * @hide
         */
        public Key(String name, String fallbackName, Class<T> type) {
            if (name == null) {
                throw new NullPointerException("Key needs a valid name");
            } else if (type == null) {
                throw new NullPointerException("Type needs to be non-null");
            }
            mName = name;
            mFallbackName = fallbackName;
            mType = type;
            mTypeReference = TypeReference.createSpecializedTypeReference(type);
            mHash = mName.hashCode() ^ mTypeReference.hashCode();
        }

        /**
         * Visible for testing only.
         *
@@ -115,6 +133,7 @@ public class CameraMetadataNative implements Parcelable {
                throw new NullPointerException("Type needs to be non-null");
            }
            mName = name;
            mFallbackName = null;
            mType = type;
            mTypeReference = TypeReference.createSpecializedTypeReference(type);
            mHash = mName.hashCode() ^ mTypeReference.hashCode();
@@ -134,6 +153,7 @@ public class CameraMetadataNative implements Parcelable {
                throw new NullPointerException("TypeReference needs to be non-null");
            }
            mName = name;
            mFallbackName = null;
            mType = (Class<T>)typeReference.getRawType();
            mTypeReference = typeReference;
            mHash = mName.hashCode() ^ mTypeReference.hashCode();
@@ -494,8 +514,17 @@ public class CameraMetadataNative implements Parcelable {
        int tag = nativeGetTagFromKeyLocal(key.getName());
        byte[] 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.
            if (key.mFallbackName == null) {
                return null;
            }
            tag = nativeGetTagFromKeyLocal(key.mFallbackName);
            values = readValues(tag);
            if (values == null) {
                return null;
            }
        }

        int nativeType = nativeGetTypeFromTagLocal(tag);
        Marshaler<T> marshaler = getMarshalerForKey(key, nativeType);