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

Commit 18e7428e authored by Avichal Rakesh's avatar Avichal Rakesh Committed by Android (Google) Code Review
Browse files

Merge changes from topic "session_chars_cp" into main

* changes:
  camera2: Ensure SessionCharacteristics and CameraCharactersitics can be used interchangeably
  Camera2: Add Session Characteristic keys by query version.
parents 7f04bec5 22d63688
Loading
Loading
Loading
Loading
+33 −12
Original line number Original line Diff line number Diff line
@@ -41,7 +41,9 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
import java.util.Collections;
import java.util.Collections;
import java.util.List;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Set;
import java.util.stream.Collectors;


/**
/**
 * <p>The properties describing a
 * <p>The properties describing a
@@ -569,10 +571,23 @@ public final class CameraCharacteristics extends CameraMetadata<CameraCharacteri
    @NonNull
    @NonNull
    @FlaggedApi(Flags.FLAG_FEATURE_COMBINATION_QUERY)
    @FlaggedApi(Flags.FLAG_FEATURE_COMBINATION_QUERY)
    public List<CameraCharacteristics.Key<?>> getAvailableSessionCharacteristicsKeys() {
    public List<CameraCharacteristics.Key<?>> getAvailableSessionCharacteristicsKeys() {
        if (mAvailableSessionCharacteristicsKeys == null) {
        if (mAvailableSessionCharacteristicsKeys != null) {
            mAvailableSessionCharacteristicsKeys =
            return mAvailableSessionCharacteristicsKeys;
                    Arrays.asList(CONTROL_ZOOM_RATIO_RANGE, SCALER_AVAILABLE_MAX_DIGITAL_ZOOM);
        }
        }

        Integer queryVersion = get(INFO_SESSION_CONFIGURATION_QUERY_VERSION);
        if (queryVersion == null) {
            mAvailableSessionCharacteristicsKeys = List.of();
            return mAvailableSessionCharacteristicsKeys;
        }

        mAvailableSessionCharacteristicsKeys =
                AVAILABLE_SESSION_CHARACTERISTICS_KEYS_MAP.entrySet().stream()
                        .filter(e -> e.getKey() <= queryVersion)
                        .map(Map.Entry::getValue)
                        .flatMap(Arrays::stream)
                        .collect(Collectors.toUnmodifiableList());

        return mAvailableSessionCharacteristicsKeys;
        return mAvailableSessionCharacteristicsKeys;
    }
    }


@@ -6117,16 +6132,22 @@ public final class CameraCharacteristics extends CameraMetadata<CameraCharacteri
    public static final Key<android.util.Range<Float>> EFV_PADDING_ZOOM_FACTOR_RANGE =
    public static final Key<android.util.Range<Float>> EFV_PADDING_ZOOM_FACTOR_RANGE =
            new Key<android.util.Range<Float>>("android.efv.paddingZoomFactorRange", new TypeReference<android.util.Range<Float>>() {{ }});
            new Key<android.util.Range<Float>>("android.efv.paddingZoomFactorRange", new TypeReference<android.util.Range<Float>>() {{ }});



    /**
     * Mapping from INFO_SESSION_CONFIGURATION_QUERY_VERSION to session characteristics key.
     */
    private static final Map<Integer, Key<?>[]> AVAILABLE_SESSION_CHARACTERISTICS_KEYS_MAP =
            Map.ofEntries(
                Map.entry(
                    35,
                    new Key<?>[] {
                        CONTROL_ZOOM_RATIO_RANGE,
                        SCALER_AVAILABLE_MAX_DIGITAL_ZOOM,
                    }
                )
            );

    /*~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~
    /*~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~
     * End generated code
     * End generated code
     *~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~O@*/
     *~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~O@*/









}
}
+78 −22
Original line number Original line Diff line number Diff line
@@ -112,6 +112,34 @@ public final class CameraManager {
    private static final int CAMERA_TYPE_BACKWARD_COMPATIBLE = 0;
    private static final int CAMERA_TYPE_BACKWARD_COMPATIBLE = 0;
    private static final int CAMERA_TYPE_ALL = 1;
    private static final int CAMERA_TYPE_ALL = 1;


    /**
     * Caches the mapping between a logical camera ID and 'MultiResolutionStreamConfigurationMap'
     * that is calculated by {@link #getPhysicalCameraMultiResolutionConfigs} as the calculation
     * might take many binder calls.
     * <p>
     * Note, this is a map of maps. The structure is:
     * <pre>
     * {
     *     logicalCameraId_1 -> {
     *         physicalCameraId_1 -> [
     *             streamConfiguration_1,
     *             streamConfiguration_2,
     *             ...
     *         ],
     *         physicalCameraId_2 -> [...],
     *         ...
     *     },
     *     logicalCameraId_2 -> {
     *         ...
     *     },
     *     ...
     * }
     * </pre>
     * </p>
     */
    private final Map<String, Map<String, StreamConfiguration[]>>
            mCameraIdToMultiResolutionStreamConfigurationMap = new HashMap<>();

    private final Context mContext;
    private final Context mContext;
    private final Object mLock = new Object();
    private final Object mLock = new Object();


@@ -566,8 +594,14 @@ public final class CameraManager {
    private Map<String, StreamConfiguration[]> getPhysicalCameraMultiResolutionConfigs(
    private Map<String, StreamConfiguration[]> getPhysicalCameraMultiResolutionConfigs(
            String cameraId, CameraMetadataNative info, ICameraService cameraService)
            String cameraId, CameraMetadataNative info, ICameraService cameraService)
            throws CameraAccessException {
            throws CameraAccessException {
        if (mCameraIdToMultiResolutionStreamConfigurationMap.containsKey(cameraId)) {
            return mCameraIdToMultiResolutionStreamConfigurationMap.get(cameraId);
        }

        HashMap<String, StreamConfiguration[]> multiResolutionStreamConfigurations =
        HashMap<String, StreamConfiguration[]> multiResolutionStreamConfigurations =
                new HashMap<String, StreamConfiguration[]>();
                new HashMap<>();
        mCameraIdToMultiResolutionStreamConfigurationMap.put(cameraId,
                multiResolutionStreamConfigurations);


        Boolean multiResolutionStreamSupported = info.get(
        Boolean multiResolutionStreamSupported = info.get(
                CameraCharacteristics.SCALER_MULTI_RESOLUTION_STREAM_SUPPORTED);
                CameraCharacteristics.SCALER_MULTI_RESOLUTION_STREAM_SUPPORTED);
@@ -676,13 +710,42 @@ public final class CameraManager {
                        "Camera service is currently unavailable");
                        "Camera service is currently unavailable");
            }
            }
            try {
            try {
                Size displaySize = getDisplaySize();

                CameraMetadataNative info = cameraService.getCameraCharacteristics(cameraId,
                CameraMetadataNative info = cameraService.getCameraCharacteristics(cameraId,
                        mContext.getApplicationInfo().targetSdkVersion, overrideToPortrait,
                        mContext.getApplicationInfo().targetSdkVersion, overrideToPortrait,
                        mContext.getDeviceId(), getDevicePolicyFromContext(mContext));
                        mContext.getDeviceId(), getDevicePolicyFromContext(mContext));
                characteristics = prepareCameraCharacteristics(cameraId, info, cameraService);
            } catch (ServiceSpecificException e) {
                throw ExceptionUtils.throwAsPublicException(e);
            } catch (RemoteException e) {
                // Camera service died - act as if the camera was disconnected
                throw new CameraAccessException(CameraAccessException.CAMERA_DISCONNECTED,
                        "Camera service is currently unavailable", e);
            }
        }
        registerDeviceStateListener(characteristics);
        return characteristics;
    }


    /**
     * Utility method to take a {@link CameraMetadataNative} object and wrap it into a
     * {@link CameraCharacteristics} object that has all required fields and keys set and is fit
     * for apps to consume.
     *
     * @param cameraId      camera Id that the CameraMetadataNative was fetched for.
     * @param metadata      base CameraMetadataNative to be wrapped
     * @param cameraService remote cameraservice instance to be used if binder calls need
     *                      to be made.
     * @return A CameraCharacteristics object that can be used by the apps.
     * @hide
     */
    @NonNull
    public CameraCharacteristics prepareCameraCharacteristics(
            @NonNull String cameraId, CameraMetadataNative metadata, ICameraService cameraService)
            throws CameraAccessException {
        synchronized (mLock) {
            try {
            try {
                    info.setCameraId(Integer.parseInt(cameraId));
                metadata.setCameraId(Integer.parseInt(cameraId));
            } catch (NumberFormatException e) {
            } catch (NumberFormatException e) {
                Log.v(TAG, "Failed to parse camera Id " + cameraId + " to integer");
                Log.v(TAG, "Failed to parse camera Id " + cameraId + " to integer");
            }
            }
@@ -690,26 +753,19 @@ public final class CameraManager {
            boolean hasConcurrentStreams =
            boolean hasConcurrentStreams =
                    CameraManagerGlobal.get().cameraIdHasConcurrentStreamsLocked(cameraId,
                    CameraManagerGlobal.get().cameraIdHasConcurrentStreamsLocked(cameraId,
                            mContext.getDeviceId());
                            mContext.getDeviceId());
                info.setHasMandatoryConcurrentStreams(hasConcurrentStreams);
            metadata.setHasMandatoryConcurrentStreams(hasConcurrentStreams);
                info.setDisplaySize(displaySize);

            Size displaySize = getDisplaySize();
            metadata.setDisplaySize(displaySize);


            Map<String, StreamConfiguration[]> multiResolutionSizeMap =
            Map<String, StreamConfiguration[]> multiResolutionSizeMap =
                        getPhysicalCameraMultiResolutionConfigs(cameraId, info, cameraService);
                    getPhysicalCameraMultiResolutionConfigs(cameraId, metadata, cameraService);
                if (multiResolutionSizeMap.size() > 0) {
            if (!multiResolutionSizeMap.isEmpty()) {
                    info.setMultiResolutionStreamConfigurationMap(multiResolutionSizeMap);
                metadata.setMultiResolutionStreamConfigurationMap(multiResolutionSizeMap);
            }
            }


                characteristics = new CameraCharacteristics(info);
            return new CameraCharacteristics(metadata);
            } catch (ServiceSpecificException e) {
                throw ExceptionUtils.throwAsPublicException(e);
            } catch (RemoteException e) {
                // Camera service died - act as if the camera was disconnected
                throw new CameraAccessException(CameraAccessException.CAMERA_DISCONNECTED,
                        "Camera service is currently unavailable", e);
            }
        }
        }
        registerDeviceStateListener(characteristics);
        return characteristics;
    }
    }


    /**
    /**
+0 −9
Original line number Original line Diff line number Diff line
@@ -4454,13 +4454,4 @@ public final class CaptureRequest extends CameraMetadata<CaptureRequest.Key<?>>
    /*~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~
    /*~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~
     * End generated code
     * End generated code
     *~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~O@*/
     *~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~O@*/









}
}
+0 −10
Original line number Original line Diff line number Diff line
@@ -6133,14 +6133,4 @@ public class CaptureResult extends CameraMetadata<CaptureResult.Key<?>> {
    /*~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~
    /*~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~
     * End generated code
     * End generated code
     *~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~O@*/
     *~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~O@*/










}
}
+3 −2
Original line number Original line Diff line number Diff line
@@ -132,13 +132,14 @@ public class CameraDeviceSetupImpl extends CameraDevice.CameraDeviceSetup {
            }
            }


            try {
            try {
                CameraMetadataNative metadataNative = cameraService.getSessionCharacteristics(
                CameraMetadataNative metadata = cameraService.getSessionCharacteristics(
                        mCameraId, mTargetSdkVersion,
                        mCameraId, mTargetSdkVersion,
                        CameraManager.shouldOverrideToPortrait(mContext), sessionConfig,
                        CameraManager.shouldOverrideToPortrait(mContext), sessionConfig,
                        mContext.getDeviceId(),
                        mContext.getDeviceId(),
                        mCameraManager.getDevicePolicyFromContext(mContext));
                        mCameraManager.getDevicePolicyFromContext(mContext));


                return new CameraCharacteristics(metadataNative);
                return mCameraManager.prepareCameraCharacteristics(mCameraId, metadata,
                        cameraService);
            } catch (ServiceSpecificException e) {
            } catch (ServiceSpecificException e) {
                switch (e.errorCode) {
                switch (e.errorCode) {
                    case ICameraService.ERROR_INVALID_OPERATION ->
                    case ICameraService.ERROR_INVALID_OPERATION ->