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
This commit is contained in:
Justin Yun
2018-05-18 20:39:45 +09:00
parent 2b3c858296
commit f01e40c5e1
3 changed files with 48 additions and 1 deletions

View File

@@ -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.
*

View File

@@ -87,6 +87,15 @@ public class CaptureResult extends CameraMetadata<CaptureResult.Key<?>> {
*
* @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.
*
* @hide
*/
public Key(String name, Class<T> type) {
mKey = new CameraMetadataNative.Key<T>(name, type);
}

View File

@@ -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,7 +514,16 @@ public class CameraMetadataNative implements Parcelable {
int tag = nativeGetTagFromKeyLocal(key.getName());
byte[] values = readValues(tag);
if (values == null) {
return 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);