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

Commit 59bc67c7 authored by Igor Murashkin's avatar Igor Murashkin
Browse files

Initial camera device implementation

* Working streaming preview requests only
* Almost everything else returns empty objects that don't do anything

Bug: 9213377
Change-Id: I183dd47ddd737ec2c3c374e5c3461542a97f09b0
parent e473f7d8
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -125,6 +125,8 @@ LOCAL_SRC_FILES += \
	core/java/android/hardware/ICameraClient.aidl \
	core/java/android/hardware/IProCameraUser.aidl \
	core/java/android/hardware/IProCameraCallbacks.aidl \
	core/java/android/hardware/photography/ICameraDeviceUser.aidl \
	core/java/android/hardware/photography/ICameraDeviceCallbacks.aidl \
	core/java/android/hardware/ISerialManager.aidl \
	core/java/android/hardware/display/IDisplayManager.aidl \
	core/java/android/hardware/display/IDisplayManagerCallback.aidl \
+17 −14
Original line number Diff line number Diff line
@@ -10665,18 +10665,18 @@ package android.hardware.photography {
    field public static final int MAX_CAMERAS_IN_USE = 2; // 0x2
  }
  public final class CameraDevice implements java.lang.AutoCloseable {
    method public void capture(android.hardware.photography.CaptureRequest, android.hardware.photography.CameraDevice.CaptureListener) throws android.hardware.photography.CameraAccessException;
    method public void captureBurst(java.util.List<android.hardware.photography.CaptureRequest>, android.hardware.photography.CameraDevice.CaptureListener) throws android.hardware.photography.CameraAccessException;
    method public void close();
    method public void configureOutputs(java.util.List<android.view.Surface>);
    method public android.hardware.photography.CaptureRequest createCaptureRequest(int) throws android.hardware.photography.CameraAccessException;
    method public android.hardware.photography.CameraProperties getProperties() throws android.hardware.photography.CameraAccessException;
    method public void setErrorListener(android.hardware.photography.CameraDevice.ErrorListener);
    method public void setRepeatingBurst(java.util.List<android.hardware.photography.CaptureRequest>, android.hardware.photography.CameraDevice.CaptureListener) throws android.hardware.photography.CameraAccessException;
    method public void setRepeatingRequest(android.hardware.photography.CaptureRequest, android.hardware.photography.CameraDevice.CaptureListener) throws android.hardware.photography.CameraAccessException;
    method public void stopRepeating() throws android.hardware.photography.CameraAccessException;
    method public void waitUntilIdle() throws android.hardware.photography.CameraAccessException;
  public abstract interface CameraDevice implements java.lang.AutoCloseable {
    method public abstract void capture(android.hardware.photography.CaptureRequest, android.hardware.photography.CameraDevice.CaptureListener) throws android.hardware.photography.CameraAccessException;
    method public abstract void captureBurst(java.util.List<android.hardware.photography.CaptureRequest>, android.hardware.photography.CameraDevice.CaptureListener) throws android.hardware.photography.CameraAccessException;
    method public abstract void close() throws java.lang.Exception;
    method public abstract void configureOutputs(java.util.List<android.view.Surface>) throws android.hardware.photography.CameraAccessException;
    method public abstract android.hardware.photography.CaptureRequest createCaptureRequest(int) throws android.hardware.photography.CameraAccessException;
    method public abstract android.hardware.photography.CameraProperties getProperties() throws android.hardware.photography.CameraAccessException;
    method public abstract void setErrorListener(android.hardware.photography.CameraDevice.ErrorListener);
    method public abstract void setRepeatingBurst(java.util.List<android.hardware.photography.CaptureRequest>, android.hardware.photography.CameraDevice.CaptureListener) throws android.hardware.photography.CameraAccessException;
    method public abstract void setRepeatingRequest(android.hardware.photography.CaptureRequest, android.hardware.photography.CameraDevice.CaptureListener) throws android.hardware.photography.CameraAccessException;
    method public abstract void stopRepeating() throws android.hardware.photography.CameraAccessException;
    method public abstract void waitUntilIdle() throws android.hardware.photography.CameraAccessException;
    field public static final int TEMPLATE_MANUAL = 5; // 0x5
    field public static final int TEMPLATE_PREVIEW = 1; // 0x1
    field public static final int TEMPLATE_RECORD = 2; // 0x2
@@ -10709,10 +10709,12 @@ package android.hardware.photography {
    method public abstract void onCameraUnavailable(java.lang.String);
  }
  public class CameraMetadata implements android.os.Parcelable {
  public class CameraMetadata implements java.lang.AutoCloseable android.os.Parcelable {
    ctor public CameraMetadata();
    method public void close() throws java.lang.Exception;
    method public int describeContents();
    method public T get(android.hardware.photography.CameraMetadata.Key<T>);
    method public void readFromParcel(android.os.Parcel);
    method public void set(android.hardware.photography.CameraMetadata.Key<T>, T);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator CREATOR;
@@ -10741,9 +10743,10 @@ package android.hardware.photography {
    field public static final android.hardware.photography.CameraMetadata.Key SENSOR_PIXEL_ARRAY_SIZE;
  }
  public final class CaptureRequest extends android.hardware.photography.CameraMetadata {
  public final class CaptureRequest extends android.hardware.photography.CameraMetadata implements android.os.Parcelable {
    method public void addTarget(android.view.Surface);
    method public void removeTarget(android.view.Surface);
    field public static final android.os.Parcelable.Creator CREATOR;
    field public static final android.hardware.photography.CameraMetadata.Key SENSOR_EXPOSURE_TIME;
    field public static final android.hardware.photography.CameraMetadata.Key SENSOR_SENSITIVITY;
  }
+6 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import android.hardware.ICamera;
import android.hardware.ICameraClient;
import android.hardware.IProCameraUser;
import android.hardware.IProCameraCallbacks;
import android.hardware.photography.ICameraDeviceUser;
import android.hardware.photography.ICameraDeviceCallbacks;
import android.hardware.ICameraServiceListener;
import android.hardware.CameraInfo;

@@ -43,6 +45,10 @@ interface ICameraService
                              String clientPackageName,
                              int clientUid);

    ICameraDeviceUser connectDevice(ICameraDeviceCallbacks callbacks, int cameraId,
                              String clientPackageName,
                              int clientUid);

    int addListener(ICameraServiceListener listener);
    int removeListener(ICameraServiceListener listener);
}
+14 −41
Original line number Diff line number Diff line
@@ -16,11 +16,6 @@

package android.hardware.photography;

import android.graphics.ImageFormat;
import android.os.IBinder;
import android.renderscript.Allocation;
import android.renderscript.RenderScript;
import android.util.Log;
import android.view.Surface;

import java.lang.AutoCloseable;
@@ -49,7 +44,7 @@ import java.util.List;
 * @see CameraManager#openCamera
 * @see android.Manifest.permission#CAMERA
 */
public final class CameraDevice implements AutoCloseable {
public interface CameraDevice extends AutoCloseable {

    /**
     * Create a request suitable for a camera preview window. Specifically, this
@@ -103,8 +98,6 @@ public final class CameraDevice implements AutoCloseable {
     */
    public static final int TEMPLATE_MANUAL = 5;

    private static final String TAG = "CameraDevice";

    /**
     * Get the static properties for this camera. These are identical to the
     * properties returned by {@link CameraManager#getCameraProperties}.
@@ -115,10 +108,7 @@ public final class CameraDevice implements AutoCloseable {
     *
     * @see CameraManager#getCameraProperties
     */
    public CameraProperties getProperties() throws CameraAccessException {
        return null;
    }

    public CameraProperties getProperties() throws CameraAccessException;
    /**
     * <p>Set up a new output set of Surfaces for the camera device.</p>
     *
@@ -200,8 +190,7 @@ public final class CameraDevice implements AutoCloseable {
     * @throws IllegalStateException if the camera device is not idle, or has
     * encountered a fatal error
     */
    public void configureOutputs(List<Surface> outputs) {
    }
    public void configureOutputs(List<Surface> outputs) throws CameraAccessException;

    /**
     * <p>Create a {@link CaptureRequest} initialized with template for a target
@@ -227,9 +216,7 @@ public final class CameraDevice implements AutoCloseable {
     * @see #TEMPLATE_MANUAL
     */
    public CaptureRequest createCaptureRequest(int templateType)
            throws CameraAccessException {
        return null;
    }
            throws CameraAccessException;

    /**
     * <p>Submit a request for an image to be captured by this CameraDevice.</p>
@@ -261,8 +248,7 @@ public final class CameraDevice implements AutoCloseable {
     * @see #setRepeatingBurst
     */
    public void capture(CaptureRequest request, CaptureListener listener)
            throws CameraAccessException {
    }
            throws CameraAccessException;

    /**
     * <p>Submit a list of requests to be captured in sequence as a burst. The
@@ -293,8 +279,7 @@ public final class CameraDevice implements AutoCloseable {
     * @see #setRepeatingBurst
     */
    public void captureBurst(List<CaptureRequest> requests,
            CaptureListener listener) throws CameraAccessException {
    }
            CaptureListener listener) throws CameraAccessException;

    /**
     * <p>Request endlessly repeating capture of images by this
@@ -336,8 +321,7 @@ public final class CameraDevice implements AutoCloseable {
     * @see #setRepeatingBurst
     */
    public void setRepeatingRequest(CaptureRequest request, CaptureListener listener)
            throws CameraAccessException {
    }
            throws CameraAccessException;

    /**
     * <p>Request endlessly repeating capture of a sequence of images by this
@@ -381,8 +365,7 @@ public final class CameraDevice implements AutoCloseable {
     * @see #setRepeatingRequest
     */
    public void setRepeatingBurst(List<CaptureRequest> requests, CaptureListener listener)
            throws CameraAccessException {
    }
            throws CameraAccessException;

    /**
     * <p>Cancel any ongoing repeating capture set by either
@@ -408,8 +391,7 @@ public final class CameraDevice implements AutoCloseable {
     * device has encountered a fatal error, or if there is an active repeating
     * request or burst.
     */
    public void stopRepeating() throws CameraAccessException {
    }
    public void stopRepeating() throws CameraAccessException;

    /**
     * <p>Wait until all the submitted requests have finished processing</p>
@@ -434,8 +416,7 @@ public final class CameraDevice implements AutoCloseable {
     * device has encountered a fatal error, or if there is an active repeating
     * request or burst.
     */
    public void waitUntilIdle() throws CameraAccessException {
    }
    public void waitUntilIdle() throws CameraAccessException;

    /**
     * Set the error listener object to call when an asynchronous error
@@ -447,17 +428,17 @@ public final class CameraDevice implements AutoCloseable {
     * notifications to. Setting this to null will stop notifications about
     * asynchronous errors.
     */
    public void setErrorListener(ErrorListener listener) {
    }
    public void setErrorListener(ErrorListener listener);

    /**
     * Close the connection to this camera device. After this call, all calls to
     * the camera device interface will throw a {@link IllegalStateException},
     * except for calls to close().
     * @throws Exception
     */
    @Override
    public void close() {
    }
    public void close() throws Exception;
    // TODO: We should decide on the behavior of in-flight requests should be on close.

    /**
     * A listener for receiving metadata about completed image captures. The
@@ -556,12 +537,4 @@ public final class CameraDevice implements AutoCloseable {
         */
        public void onCameraDeviceError(CameraDevice camera, int error);
    }

    /**
     * @hide
     */
    public CameraDevice(IBinder binder) {
        Log.e(TAG, "CameraDevice constructor not implemented yet");
    }

}
+27 −6
Original line number Diff line number Diff line
@@ -94,7 +94,13 @@ public final class CameraManager {
     */
    public String[] getDeviceIdList() throws CameraAccessException {
        synchronized (mLock) {
            return (String[]) getOrCreateDeviceIdListLocked().toArray();
            try {
                return getOrCreateDeviceIdListLocked().toArray(new String[0]);
            } catch(CameraAccessException e) {
                // this should almost never happen, except if mediaserver crashes
                throw new IllegalStateException(
                        "Failed to query camera service for device ID list", e);
            }
        }
    }

@@ -179,17 +185,32 @@ public final class CameraManager {
    public CameraDevice openCamera(String cameraId) throws CameraAccessException {

        try {
            IProCameraUser cameraUser;

            synchronized (mLock) {
                // TODO: Use ICameraDevice or some such instead of this...
                cameraUser = mCameraService.connectPro(null,

                ICameraDeviceUser cameraUser;

                android.hardware.photography.impl.CameraDevice device =
                        new android.hardware.photography.impl.CameraDevice(cameraId);

                cameraUser = mCameraService.connectDevice(device.getCallbacks(),
                        Integer.parseInt(cameraId),
                        mContext.getPackageName(), USE_CALLING_UID);

                // TODO: change ICameraService#connectDevice to return status_t
                if (cameraUser == null) {
                    // TEMPORARY CODE.
                    // catch-all exception since we aren't yet getting the actual error code
                    throw new IllegalStateException("Failed to open camera device");
                }

                // TODO: factor out listener to be non-nested, then move setter to constructor
                device.setRemoteDevice(cameraUser);

                return device;

            }

            return new CameraDevice(cameraUser.asBinder());
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("Expected cameraId to be numeric, but it was: "
                    + cameraId);
@@ -306,7 +327,7 @@ public final class CameraManager {

        @Override
        public void onStatusChanged(int status, int cameraId) throws RemoteException {
            synchronized(CameraManager.this) {
            synchronized(CameraManager.this.mLock) {

                Log.v(TAG,
                        String.format("Camera id %d has status changed to 0x%x", cameraId, status));
Loading