Skip to content

Commit d42a5fd

Browse files
committed
camera2: (legacy) Fix the comparison for fixed-focus cameras
* Use #equals instead of == for string comparison * Also make sure lens.info.minimumFocusDistance shows up in CameraCharacteristics#getKeys() for fixed-focus cameras Bug: 16900875 Change-Id: I3b9248c5cb62ddcfb13587c6349525e145e353ac
1 parent 7336f47 commit d42a5fd

1 file changed

Lines changed: 36 additions & 6 deletions

File tree

core/java/android/hardware/camera2/legacy/LegacyMetadataMapper.java

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,6 @@ private static void mapCharacteristicsFromParameters(CameraMetadataNative m,
188188
*/
189189
mapFlash(m, p);
190190

191-
/*
192-
* request.*
193-
*/
194-
mapRequest(m, p);
195191
// TODO: map other fields
196192

197193
/*
@@ -224,6 +220,13 @@ private static void mapCharacteristicsFromParameters(CameraMetadataNative m,
224220
*/
225221
mapScalerStreamConfigs(m, p);
226222

223+
// Order matters below: Put this last so that we can read the metadata set previously
224+
225+
/*
226+
* request.*
227+
*/
228+
mapRequest(m, p);
229+
227230
}
228231

229232
private static void mapScalerStreamConfigs(CameraMetadataNative m, Camera.Parameters p) {
@@ -553,11 +556,23 @@ private static void mapLens(CameraMetadataNative m, Camera.Parameters p) {
553556
* We can tell if the lens is fixed focus;
554557
* but if it's not, we can't tell the minimum focus distance, so leave it null then.
555558
*/
556-
if (p.getFocusMode() == Camera.Parameters.FOCUS_MODE_FIXED) {
559+
if (VERBOSE) {
560+
Log.v(TAG, "mapLens - focus-mode='" + p.getFocusMode() + "'");
561+
}
562+
563+
if (Camera.Parameters.FOCUS_MODE_FIXED.equals(p.getFocusMode())) {
557564
/*
558565
* lens.info.minimumFocusDistance
559566
*/
560567
m.set(LENS_INFO_MINIMUM_FOCUS_DISTANCE, LENS_INFO_MINIMUM_FOCUS_DISTANCE_FIXED_FOCUS);
568+
569+
if (VERBOSE) {
570+
Log.v(TAG, "mapLens - lens.info.minimumFocusDistance = 0");
571+
}
572+
} else {
573+
if (VERBOSE) {
574+
Log.v(TAG, "mapLens - lens.info.minimumFocusDistance is unknown");
575+
}
561576
}
562577

563578
float[] focalLengths = new float[] { p.getFocalLength() };
@@ -628,7 +643,17 @@ private static void mapRequest(CameraMetadataNative m, Parameters p) {
628643
CameraCharacteristics.STATISTICS_INFO_MAX_FACE_COUNT ,
629644
CameraCharacteristics.SYNC_MAX_LATENCY ,
630645
};
631-
m.set(REQUEST_AVAILABLE_CHARACTERISTICS_KEYS, getTagsForKeys(availableKeys));
646+
List<Key<?>> characteristicsKeys = new ArrayList<>(Arrays.asList(availableKeys));
647+
648+
/*
649+
* Add the conditional keys
650+
*/
651+
if (m.get(LENS_INFO_MINIMUM_FOCUS_DISTANCE) != null) {
652+
characteristicsKeys.add(LENS_INFO_MINIMUM_FOCUS_DISTANCE);
653+
}
654+
655+
m.set(REQUEST_AVAILABLE_CHARACTERISTICS_KEYS,
656+
getTagsForKeys(characteristicsKeys.toArray(new Key<?>[0])));
632657
}
633658

634659
/*
@@ -1141,6 +1166,11 @@ public static CameraMetadataNative createRequestTemplate(
11411166
}
11421167
}
11431168

1169+
if (VERBOSE) {
1170+
Log.v(TAG, "createRequestTemplate (templateId=" + templateId + ")," +
1171+
" afMode=" + afMode + ", minimumFocusDistance=" + minimumFocusDistance);
1172+
}
1173+
11441174
m.set(CaptureRequest.CONTROL_AF_MODE, afMode);
11451175
}
11461176

0 commit comments

Comments
 (0)