Camera: Switch camera2 to auto-gen C++ binder interfaces

 - Move camera service AIDL files to frameworks/av
 - Build C++ interface stubs with AIDL tools
 - Add necessary native-side parcelables and update existing ones
 - Remove manually-written stubs, rearrange remaining manual stubs
 - Adjust implementations to work with auto-generated stubs
   - Adjust method signatures for auto-gen differences
   - Add rich error messages using binder::Status

Bug: 25091611
Change-Id: I6f69f34b9d1a3f8d1fb7db87357363f8fa8483ff
diff --git a/services/camera/libcameraservice/Android.mk b/services/camera/libcameraservice/Android.mk
index d416353..bb3a685 100644
--- a/services/camera/libcameraservice/Android.mk
+++ b/services/camera/libcameraservice/Android.mk
@@ -20,7 +20,9 @@
 
 include $(CLEAR_VARS)
 
-LOCAL_SRC_FILES:=               \
+# Camera service source
+
+LOCAL_SRC_FILES :=  \
     CameraService.cpp \
     CameraFlashlight.cpp \
     common/Camera2ClientBase.cpp \
@@ -67,11 +69,12 @@
     libjpeg
 
 LOCAL_C_INCLUDES += \
-    system/media/camera/include \
     system/media/private/camera/include \
     frameworks/native/include/media/openmax \
     external/jpeg
 
+LOCAL_EXPORT_C_INCLUDE_DIRS := \
+    frameworks/av/services/camera/libcameraservice
 
 LOCAL_CFLAGS += -Wall -Wextra
 
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
index f0bcc0b..7446c3e 100644
--- a/services/camera/libcameraservice/CameraService.cpp
+++ b/services/camera/libcameraservice/CameraService.cpp
@@ -28,6 +28,9 @@
 #include <inttypes.h>
 #include <pthread.h>
 
+#include <android/hardware/ICamera.h>
+#include <android/hardware/ICameraClient.h>
+
 #include <binder/AppOpsManager.h>
 #include <binder/IPCThreadState.h>
 #include <binder/IServiceManager.h>
@@ -63,6 +66,9 @@
 
 namespace android {
 
+using binder::Status;
+using namespace hardware;
+
 // ----------------------------------------------------------------------------
 // Logging support -- this is for debugging only
 // Use "adb shell dumpsys media.camera -v 1" to change it.
@@ -75,6 +81,17 @@
     android_atomic_write(level, &gLogLevel);
 }
 
+// Convenience methods for constructing binder::Status objects for error returns
+
+#define STATUS_ERROR(errorCode, errorString) \
+    binder::Status::fromServiceSpecificError(errorCode, \
+            String8::format("%s:%d: %s", __FUNCTION__, __LINE__, errorString))
+
+#define STATUS_ERROR_FMT(errorCode, errorString, ...) \
+    binder::Status::fromServiceSpecificError(errorCode, \
+            String8::format("%s:%d: " errorString, __FUNCTION__, __LINE__, \
+                    __VA_ARGS__))
+
 // ----------------------------------------------------------------------------
 
 extern "C" {
@@ -100,7 +117,7 @@
     sp<CameraService> cs = const_cast<CameraService*>(
                                 static_cast<const CameraService*>(callbacks));
 
-    ICameraServiceListener::TorchStatus status;
+    int32_t status;
     switch (new_status) {
         case TORCH_MODE_STATUS_NOT_AVAILABLE:
             status = ICameraServiceListener::TORCH_STATUS_NOT_AVAILABLE;
@@ -130,8 +147,8 @@
 
 CameraService::CameraService() :
         mEventLog(DEFAULT_EVENT_LOG_LENGTH),
-        mSoundRef(0), mModule(nullptr),
-        mNumberOfCameras(0), mNumberOfNormalCameras(0) {
+        mNumberOfCameras(0), mNumberOfNormalCameras(0),
+        mSoundRef(0), mModule(nullptr) {
     ALOGI("CameraService started (pid=%d)", getpid());
     gCameraService = this;
 
@@ -291,9 +308,9 @@
         return;
     }
 
-    ICameraServiceListener::Status oldStatus = state->getStatus();
+    int32_t oldStatus = state->getStatus();
 
-    if (oldStatus == static_cast<ICameraServiceListener::Status>(newStatus)) {
+    if (oldStatus == static_cast<int32_t>(newStatus)) {
         ALOGE("%s: State transition to the same status %#x not allowed", __FUNCTION__, newStatus);
         return;
     }
@@ -317,7 +334,8 @@
             clientToDisconnect = removeClientLocked(id);
 
             // Notify the client of disconnection
-            clientToDisconnect->notifyError(ICameraDeviceCallbacks::ERROR_CAMERA_DISCONNECTED,
+            clientToDisconnect->notifyError(
+                    hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_DISCONNECTED,
                     CaptureResultExtras{});
         }
 
@@ -333,27 +351,27 @@
         }
 
     } else {
-        if (oldStatus == ICameraServiceListener::Status::STATUS_NOT_PRESENT) {
+        if (oldStatus == ICameraServiceListener::STATUS_NOT_PRESENT) {
             logDeviceAdded(id, String8::format("Device status changed from %d to %d", oldStatus,
                     newStatus));
         }
-        updateStatus(static_cast<ICameraServiceListener::Status>(newStatus), id);
+        updateStatus(static_cast<int32_t>(newStatus), id);
     }
 
 }
 
 void CameraService::onTorchStatusChanged(const String8& cameraId,
-        ICameraServiceListener::TorchStatus newStatus) {
+        int32_t newStatus) {
     Mutex::Autolock al(mTorchStatusMutex);
     onTorchStatusChangedLocked(cameraId, newStatus);
 }
 
 void CameraService::onTorchStatusChangedLocked(const String8& cameraId,
-        ICameraServiceListener::TorchStatus newStatus) {
+        int32_t newStatus) {
     ALOGI("%s: Torch status changed for cameraId=%s, newStatus=%d",
             __FUNCTION__, cameraId.string(), newStatus);
 
-    ICameraServiceListener::TorchStatus status;
+    int32_t status;
     status_t res = getTorchStatusLocked(cameraId, &status);
     if (res) {
         ALOGE("%s: cannot get torch status of camera %s: %s (%d)",
@@ -407,41 +425,45 @@
     }
 }
 
-int32_t CameraService::getNumberOfCameras() {
-    ATRACE_CALL();
-    return getNumberOfCameras(CAMERA_TYPE_BACKWARD_COMPATIBLE);
-}
-
-int32_t CameraService::getNumberOfCameras(int type) {
+Status CameraService::getNumberOfCameras(int32_t type, int32_t* numCameras) {
     ATRACE_CALL();
     switch (type) {
         case CAMERA_TYPE_BACKWARD_COMPATIBLE:
-            return mNumberOfNormalCameras;
+            *numCameras = mNumberOfNormalCameras;
+            break;
         case CAMERA_TYPE_ALL:
-            return mNumberOfCameras;
+            *numCameras = mNumberOfCameras;
+            break;
         default:
-            ALOGW("%s: Unknown camera type %d, returning 0",
+            ALOGW("%s: Unknown camera type %d",
                     __FUNCTION__, type);
-            return 0;
+            return STATUS_ERROR_FMT(ERROR_ILLEGAL_ARGUMENT,
+                    "Unknown camera type %d", type);
     }
+    return Status::ok();
 }
 
-status_t CameraService::getCameraInfo(int cameraId,
-                                      struct CameraInfo* cameraInfo) {
+Status CameraService::getCameraInfo(int cameraId,
+        CameraInfo* cameraInfo) {
     ATRACE_CALL();
     if (!mModule) {
-        return -ENODEV;
+        return STATUS_ERROR(ERROR_DISCONNECTED,
+                "Camera subsystem is not available");
     }
 
     if (cameraId < 0 || cameraId >= mNumberOfCameras) {
-        return BAD_VALUE;
+        return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT,
+                "CameraId is not valid");
     }
 
     struct camera_info info;
-    status_t rc = filterGetInfoErrorCode(
+    Status rc = filterGetInfoErrorCode(
         mModule->getCameraInfo(cameraId, &info));
-    cameraInfo->facing = info.facing;
-    cameraInfo->orientation = info.orientation;
+
+    if (rc.isOk()) {
+        cameraInfo->facing = info.facing;
+        cameraInfo->orientation = info.orientation;
+    }
     return rc;
 }
 
@@ -455,28 +477,33 @@
     return ret;
 }
 
-status_t CameraService::generateShimMetadata(int cameraId, /*out*/CameraMetadata* cameraInfo) {
+Status CameraService::generateShimMetadata(int cameraId, /*out*/CameraMetadata* cameraInfo) {
     ATRACE_CALL();
-    status_t ret = OK;
+
+    Status ret = Status::ok();
+
     struct CameraInfo info;
-    if ((ret = getCameraInfo(cameraId, &info)) != OK) {
+    if (!(ret = getCameraInfo(cameraId, &info)).isOk()) {
         return ret;
     }
 
     CameraMetadata shimInfo;
     int32_t orientation = static_cast<int32_t>(info.orientation);
-    if ((ret = shimInfo.update(ANDROID_SENSOR_ORIENTATION, &orientation, 1)) != OK) {
-        return ret;
+    status_t rc;
+    if ((rc = shimInfo.update(ANDROID_SENSOR_ORIENTATION, &orientation, 1)) != OK) {
+        return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION,
+                "Error updating metadata: %d (%s)", rc, strerror(-rc));
     }
 
     uint8_t facing = (info.facing == CAMERA_FACING_FRONT) ?
             ANDROID_LENS_FACING_FRONT : ANDROID_LENS_FACING_BACK;
-    if ((ret = shimInfo.update(ANDROID_LENS_FACING, &facing, 1)) != OK) {
-        return ret;
+    if ((rc = shimInfo.update(ANDROID_LENS_FACING, &facing, 1)) != OK) {
+        return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION,
+                "Error updating metadata: %d (%s)", rc, strerror(-rc));
     }
 
     CameraParameters shimParams;
-    if ((ret = getLegacyParametersLazy(cameraId, /*out*/&shimParams)) != OK) {
+    if (!(ret = getLegacyParametersLazy(cameraId, /*out*/&shimParams)).isOk()) {
         // Error logged by callee
         return ret;
     }
@@ -517,49 +544,54 @@
         streamConfigs.add(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT);
     }
 
-    if ((ret = shimInfo.update(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS,
+    if ((rc = shimInfo.update(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS,
             streamConfigs.array(), streamConfigSize)) != OK) {
-        return ret;
+        return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION,
+                "Error updating metadata: %d (%s)", rc, strerror(-rc));
     }
 
     int64_t fakeMinFrames[0];
     // TODO: Fixme, don't fake min frame durations.
-    if ((ret = shimInfo.update(ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS,
+    if ((rc = shimInfo.update(ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS,
             fakeMinFrames, 0)) != OK) {
-        return ret;
+        return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION,
+                "Error updating metadata: %d (%s)", rc, strerror(-rc));
     }
 
     int64_t fakeStalls[0];
     // TODO: Fixme, don't fake stall durations.
-    if ((ret = shimInfo.update(ANDROID_SCALER_AVAILABLE_STALL_DURATIONS,
+    if ((rc = shimInfo.update(ANDROID_SCALER_AVAILABLE_STALL_DURATIONS,
             fakeStalls, 0)) != OK) {
-        return ret;
+        return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION,
+                "Error updating metadata: %d (%s)", rc, strerror(-rc));
     }
 
     *cameraInfo = shimInfo;
-    return OK;
+    return ret;
 }
 
-status_t CameraService::getCameraCharacteristics(int cameraId,
+Status CameraService::getCameraCharacteristics(int cameraId,
                                                 CameraMetadata* cameraInfo) {
     ATRACE_CALL();
     if (!cameraInfo) {
         ALOGE("%s: cameraInfo is NULL", __FUNCTION__);
-        return BAD_VALUE;
+        return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "cameraInfo is NULL");
     }
 
     if (!mModule) {
         ALOGE("%s: camera hardware module doesn't exist", __FUNCTION__);
-        return -ENODEV;
+        return STATUS_ERROR(ERROR_DISCONNECTED,
+                "Camera subsystem is not available");;
     }
 
     if (cameraId < 0 || cameraId >= mNumberOfCameras) {
         ALOGE("%s: Invalid camera id: %d", __FUNCTION__, cameraId);
-        return BAD_VALUE;
+        return STATUS_ERROR_FMT(ERROR_ILLEGAL_ARGUMENT,
+                "Invalid camera id: %d", cameraId);
     }
 
     int facing;
-    status_t ret = OK;
+    Status ret;
     if (mModule->getModuleApiVersion() < CAMERA_MODULE_API_VERSION_2_0 ||
             getDeviceVersion(cameraId, &facing) < CAMERA_DEVICE_API_VERSION_3_0) {
         /**
@@ -572,17 +604,16 @@
          */
         ALOGI("%s: Switching to HAL1 shim implementation...", __FUNCTION__);
 
-        if ((ret = generateShimMetadata(cameraId, cameraInfo)) != OK) {
-            return ret;
-        }
-
+        ret = generateShimMetadata(cameraId, cameraInfo);
     } else {
         /**
          * Normal HAL 2.1+ codepath.
          */
         struct camera_info info;
         ret = filterGetInfoErrorCode(mModule->getCameraInfo(cameraId, &info));
-        *cameraInfo = info.static_camera_characteristics;
+        if (ret.isOk()) {
+            *cameraInfo = info.static_camera_characteristics;
+        }
     }
 
     return ret;
@@ -619,15 +650,17 @@
     return INT_MAX - procState;
 }
 
-status_t CameraService::getCameraVendorTagDescriptor(/*out*/sp<VendorTagDescriptor>& desc) {
+Status CameraService::getCameraVendorTagDescriptor(
+        /*out*/
+        hardware::camera2::params::VendorTagDescriptor* desc) {
     ATRACE_CALL();
     if (!mModule) {
         ALOGE("%s: camera hardware module doesn't exist", __FUNCTION__);
-        return -ENODEV;
+        return STATUS_ERROR(ERROR_DISCONNECTED, "Camera subsystem not available");
     }
 
-    desc = VendorTagDescriptor::getGlobalVendorTagDescriptor();
-    return OK;
+    *desc = *(VendorTagDescriptor::getGlobalVendorTagDescriptor().get());
+    return Status::ok();
 }
 
 int CameraService::getDeviceVersion(int cameraId, int* facing) {
@@ -651,15 +684,21 @@
     return deviceVersion;
 }
 
-status_t CameraService::filterGetInfoErrorCode(status_t err) {
+Status CameraService::filterGetInfoErrorCode(status_t err) {
     switch(err) {
         case NO_ERROR:
+            return Status::ok();
         case -EINVAL:
-            return err;
+            return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT,
+                    "CameraId is not valid for HAL module");
+        case -ENODEV:
+            return STATUS_ERROR(ERROR_DISCONNECTED,
+                    "Camera device not available");
         default:
-            break;
+            return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION,
+                    "Camera HAL encountered error %d: %s",
+                    err, strerror(-err));
     }
-    return -ENODEV;
 }
 
 bool CameraService::setUpVendorTags() {
@@ -699,20 +738,12 @@
     return true;
 }
 
-status_t CameraService::makeClient(const sp<CameraService>& cameraService,
-        const sp<IInterface>& cameraCb, const String16& packageName, const String8& cameraId,
+Status CameraService::makeClient(const sp<CameraService>& cameraService,
+        const sp<IInterface>& cameraCb, const String16& packageName, int cameraId,
         int facing, int clientPid, uid_t clientUid, int servicePid, bool legacyMode,
         int halVersion, int deviceVersion, apiLevel effectiveApiLevel,
         /*out*/sp<BasicClient>* client) {
 
-    // TODO: Update CameraClients + HAL interface to use strings for Camera IDs
-    int id = cameraIdToInt(cameraId);
-    if (id == -1) {
-        ALOGE("%s: Invalid camera ID %s, cannot convert to integer.", __FUNCTION__,
-                cameraId.string());
-        return BAD_VALUE;
-    }
-
     if (halVersion < 0 || halVersion == deviceVersion) {
         // Default path: HAL version is unspecified by caller, create CameraClient
         // based on device version reported by the HAL.
@@ -720,11 +751,13 @@
           case CAMERA_DEVICE_API_VERSION_1_0:
             if (effectiveApiLevel == API_1) {  // Camera1 API route
                 sp<ICameraClient> tmp = static_cast<ICameraClient*>(cameraCb.get());
-                *client = new CameraClient(cameraService, tmp, packageName, id, facing,
+                *client = new CameraClient(cameraService, tmp, packageName, cameraId, facing,
                         clientPid, clientUid, getpid(), legacyMode);
             } else { // Camera2 API route
                 ALOGW("Camera using old HAL version: %d", deviceVersion);
-                return -EOPNOTSUPP;
+                return STATUS_ERROR_FMT(ERROR_DEPRECATED_HAL,
+                        "Camera device \"%d\" HAL version %d does not support camera2 API",
+                        cameraId, deviceVersion);
             }
             break;
           case CAMERA_DEVICE_API_VERSION_3_0:
@@ -733,19 +766,21 @@
           case CAMERA_DEVICE_API_VERSION_3_3:
             if (effectiveApiLevel == API_1) { // Camera1 API route
                 sp<ICameraClient> tmp = static_cast<ICameraClient*>(cameraCb.get());
-                *client = new Camera2Client(cameraService, tmp, packageName, id, facing,
+                *client = new Camera2Client(cameraService, tmp, packageName, cameraId, facing,
                         clientPid, clientUid, servicePid, legacyMode);
             } else { // Camera2 API route
-                sp<ICameraDeviceCallbacks> tmp =
-                        static_cast<ICameraDeviceCallbacks*>(cameraCb.get());
-                *client = new CameraDeviceClient(cameraService, tmp, packageName, id,
+                sp<hardware::camera2::ICameraDeviceCallbacks> tmp =
+                        static_cast<hardware::camera2::ICameraDeviceCallbacks*>(cameraCb.get());
+                *client = new CameraDeviceClient(cameraService, tmp, packageName, cameraId,
                         facing, clientPid, clientUid, servicePid);
             }
             break;
           default:
             // Should not be reachable
             ALOGE("Unknown camera device HAL version: %d", deviceVersion);
-            return INVALID_OPERATION;
+            return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION,
+                    "Camera device \"%d\" has unknown HAL version %d",
+                    cameraId, deviceVersion);
         }
     } else {
         // A particular HAL version is requested by caller. Create CameraClient
@@ -754,17 +789,19 @@
             halVersion == CAMERA_DEVICE_API_VERSION_1_0) {
             // Only support higher HAL version device opened as HAL1.0 device.
             sp<ICameraClient> tmp = static_cast<ICameraClient*>(cameraCb.get());
-            *client = new CameraClient(cameraService, tmp, packageName, id, facing,
+            *client = new CameraClient(cameraService, tmp, packageName, cameraId, facing,
                     clientPid, clientUid, servicePid, legacyMode);
         } else {
             // Other combinations (e.g. HAL3.x open as HAL2.x) are not supported yet.
             ALOGE("Invalid camera HAL version %x: HAL %x device can only be"
                     " opened as HAL %x device", halVersion, deviceVersion,
                     CAMERA_DEVICE_API_VERSION_1_0);
-            return INVALID_OPERATION;
+            return STATUS_ERROR_FMT(ERROR_ILLEGAL_ARGUMENT,
+                    "Camera device \"%d\" (HAL version %d) cannot be opened as HAL version %d",
+                    cameraId, deviceVersion, halVersion);
         }
     }
-    return NO_ERROR;
+    return Status::ok();
 }
 
 String8 CameraService::toString(std::set<userid_t> intSet) {
@@ -781,33 +818,35 @@
     return s;
 }
 
-status_t CameraService::initializeShimMetadata(int cameraId) {
+Status CameraService::initializeShimMetadata(int cameraId) {
     int uid = getCallingUid();
 
     String16 internalPackageName("cameraserver");
     String8 id = String8::format("%d", cameraId);
-    status_t ret = NO_ERROR;
+    Status ret = Status::ok();
     sp<Client> tmp = nullptr;
-    if ((ret = connectHelper<ICameraClient,Client>(sp<ICameraClient>{nullptr}, id,
-            static_cast<int>(CAMERA_HAL_API_VERSION_UNSPECIFIED), internalPackageName, uid,
-            USE_CALLING_PID, API_1, false, true, tmp)) != NO_ERROR) {
-        ALOGE("%s: Error %d (%s) initializing shim metadata.", __FUNCTION__, ret, strerror(ret));
-        return ret;
+    if (!(ret = connectHelper<ICameraClient,Client>(
+            sp<ICameraClient>{nullptr}, id, static_cast<int>(CAMERA_HAL_API_VERSION_UNSPECIFIED),
+            internalPackageName, uid, USE_CALLING_PID,
+            API_1, /*legacyMode*/ false, /*shimUpdateOnly*/ true,
+            /*out*/ tmp)
+            ).isOk()) {
+        ALOGE("%s: Error initializing shim metadata: %s", __FUNCTION__, ret.toString8().string());
     }
-    return NO_ERROR;
+    return ret;
 }
 
-status_t CameraService::getLegacyParametersLazy(int cameraId,
+Status CameraService::getLegacyParametersLazy(int cameraId,
         /*out*/
         CameraParameters* parameters) {
 
     ALOGV("%s: for cameraId: %d", __FUNCTION__, cameraId);
 
-    status_t ret = 0;
+    Status ret = Status::ok();
 
     if (parameters == NULL) {
         ALOGE("%s: parameters must not be null", __FUNCTION__);
-        return BAD_VALUE;
+        return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "Parameters must not be null");
     }
 
     String8 id = String8::format("%d", cameraId);
@@ -819,19 +858,20 @@
         auto cameraState = getCameraState(id);
         if (cameraState == nullptr) {
             ALOGE("%s: Invalid camera ID: %s", __FUNCTION__, id.string());
-            return BAD_VALUE;
+            return STATUS_ERROR_FMT(ERROR_ILLEGAL_ARGUMENT,
+                    "Invalid camera ID: %s", id.string());
         }
         CameraParameters p = cameraState->getShimParams();
         if (!p.isEmpty()) {
             *parameters = p;
-            return NO_ERROR;
+            return ret;
         }
     }
 
     int64_t token = IPCThreadState::self()->clearCallingIdentity();
     ret = initializeShimMetadata(cameraId);
     IPCThreadState::self()->restoreCallingIdentity(token);
-    if (ret != NO_ERROR) {
+    if (!ret.isOk()) {
         // Error already logged by callee
         return ret;
     }
@@ -843,18 +883,19 @@
         auto cameraState = getCameraState(id);
         if (cameraState == nullptr) {
             ALOGE("%s: Invalid camera ID: %s", __FUNCTION__, id.string());
-            return BAD_VALUE;
+            return STATUS_ERROR_FMT(ERROR_ILLEGAL_ARGUMENT,
+                    "Invalid camera ID: %s", id.string());
         }
         CameraParameters p = cameraState->getShimParams();
         if (!p.isEmpty()) {
             *parameters = p;
-            return NO_ERROR;
+            return ret;
         }
     }
 
     ALOGE("%s: Parameters were not initialized, or were empty.  Device may not be present.",
             __FUNCTION__);
-    return INVALID_OPERATION;
+    return STATUS_ERROR(ERROR_INVALID_OPERATION, "Unable to initialize legacy parameters");
 }
 
 // Can camera service trust the caller based on the calling UID?
@@ -868,8 +909,8 @@
     }
 }
 
-status_t CameraService::validateConnectLocked(const String8& cameraId, /*inout*/int& clientUid,
-        /*inout*/int& clientPid) const {
+Status CameraService::validateConnectLocked(const String8& cameraId,
+        const String8& clientName8, /*inout*/int& clientUid, /*inout*/int& clientPid) const {
 
     int callingPid = getCallingPid();
     int callingUid = getCallingUid();
@@ -880,7 +921,11 @@
     } else if (!isTrustedCallingUid(callingUid)) {
         ALOGE("CameraService::connect X (calling PID %d, calling UID %d) rejected "
                 "(don't trust clientUid %d)", callingPid, callingUid, clientUid);
-        return PERMISSION_DENIED;
+        return STATUS_ERROR_FMT(ERROR_PERMISSION_DENIED,
+                "Untrusted caller (calling PID %d, UID %d) trying to "
+                "forward camera access to camera %s for client %s (PID %d, UID %d)",
+                callingPid, callingUid, cameraId.string(),
+                clientName8.string(), clientUid, clientPid);
     }
 
     // Check if we can trust clientPid
@@ -889,14 +934,20 @@
     } else if (!isTrustedCallingUid(callingUid)) {
         ALOGE("CameraService::connect X (calling PID %d, calling UID %d) rejected "
                 "(don't trust clientPid %d)", callingPid, callingUid, clientPid);
-        return PERMISSION_DENIED;
+        return STATUS_ERROR_FMT(ERROR_PERMISSION_DENIED,
+                "Untrusted caller (calling PID %d, UID %d) trying to "
+                "forward camera access to camera %s for client %s (PID %d, UID %d)",
+                callingPid, callingUid, cameraId.string(),
+                clientName8.string(), clientUid, clientPid);
     }
 
     // If it's not calling from cameraserver, check the permission.
     if (callingPid != getpid() &&
             !checkPermission(String16("android.permission.CAMERA"), clientPid, clientUid)) {
         ALOGE("Permission Denial: can't use the camera pid=%d, uid=%d", clientPid, clientUid);
-        return PERMISSION_DENIED;
+        return STATUS_ERROR_FMT(ERROR_PERMISSION_DENIED,
+                "Caller \"%s\" (PID %d, UID %d) cannot open camera \"%s\" without camera permission",
+                clientName8.string(), clientUid, clientPid, cameraId.string());
     }
 
     // Only use passed in clientPid to check permission. Use calling PID as the client PID that's
@@ -906,13 +957,15 @@
     if (!mModule) {
         ALOGE("CameraService::connect X (PID %d) rejected (camera HAL module not loaded)",
                 callingPid);
-        return -ENODEV;
+        return STATUS_ERROR_FMT(ERROR_DISCONNECTED,
+                "No camera HAL module available to open camera device \"%s\"", cameraId.string());
     }
 
     if (getCameraState(cameraId) == nullptr) {
         ALOGE("CameraService::connect X (PID %d) rejected (invalid camera ID %s)", callingPid,
                 cameraId.string());
-        return -ENODEV;
+        return STATUS_ERROR_FMT(ERROR_DISCONNECTED,
+                "No camera device with ID \"%s\" available", cameraId.string());
     }
 
     userid_t clientUserId = multiuser_get_user_id(clientUid);
@@ -923,10 +976,24 @@
         ALOGE("CameraService::connect X (PID %d) rejected (cannot connect from "
                 "device user %d, currently allowed device users: %s)", callingPid, clientUserId,
                 toString(mAllowedUsers).string());
-        return PERMISSION_DENIED;
+        return STATUS_ERROR_FMT(ERROR_PERMISSION_DENIED,
+                "Callers from device user %d are not currently allowed to connect to camera \"%s\"",
+                clientUserId, cameraId.string());
     }
 
-    return checkIfDeviceIsUsable(cameraId);
+    status_t err = checkIfDeviceIsUsable(cameraId);
+    if (err != NO_ERROR) {
+        switch(err) {
+            case -ENODEV:
+            case -EBUSY:
+                return STATUS_ERROR_FMT(ERROR_DISCONNECTED,
+                        "No camera device with ID \"%s\" currently available", cameraId.string());
+            default:
+                return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION,
+                        "Unknown error connecting to ID \"%s\"", cameraId.string());
+        }
+    }
+    return Status::ok();
 }
 
 status_t CameraService::checkIfDeviceIsUsable(const String8& cameraId) const {
@@ -938,7 +1005,7 @@
         return -ENODEV;
     }
 
-    ICameraServiceListener::Status currentStatus = cameraState->getStatus();
+    int32_t currentStatus = cameraState->getStatus();
     if (currentStatus == ICameraServiceListener::STATUS_NOT_PRESENT) {
         ALOGE("CameraService::connect X (PID %d) rejected (camera %s is not connected)",
                 callingPid, cameraId.string());
@@ -1015,11 +1082,6 @@
             }
         }
 
-        // Return error if the device was unplugged or removed by the HAL for some reason
-        if ((ret = checkIfDeviceIsUsable(cameraId)) != NO_ERROR) {
-            return ret;
-        }
-
         // Get current active client PIDs
         std::vector<int> ownerPids(mActiveClientManager.getAllOwners());
         ownerPids.push_back(clientPid);
@@ -1046,6 +1108,7 @@
         if (state == nullptr) {
             ALOGE("CameraService::connect X (PID %d) rejected (no camera device with ID %s)",
                 clientPid, cameraId.string());
+            // Should never get here because validateConnectLocked should have errored out
             return BAD_VALUE;
         }
 
@@ -1118,7 +1181,7 @@
                     getCameraPriorityFromProcState(priorities[priorities.size() - 1])));
 
             // Notify the client of disconnection
-            clientSp->notifyError(ICameraDeviceCallbacks::ERROR_CAMERA_DISCONNECTED,
+            clientSp->notifyError(hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_DISCONNECTED,
                     CaptureResultExtras());
         }
     }
@@ -1170,39 +1233,41 @@
     return NO_ERROR;
 }
 
-status_t CameraService::connect(
+Status CameraService::connect(
         const sp<ICameraClient>& cameraClient,
         int cameraId,
         const String16& clientPackageName,
         int clientUid,
         int clientPid,
         /*out*/
-        sp<ICamera>& device) {
+        sp<ICamera>* device) {
 
     ATRACE_CALL();
-    status_t ret = NO_ERROR;
+    Status ret = Status::ok();
     String8 id = String8::format("%d", cameraId);
     sp<Client> client = nullptr;
-    ret = connectHelper<ICameraClient,Client>(cameraClient, id, CAMERA_HAL_API_VERSION_UNSPECIFIED,
-            clientPackageName, clientUid, clientPid, API_1, false, false, /*out*/client);
+    ret = connectHelper<ICameraClient,Client>(cameraClient, id,
+            CAMERA_HAL_API_VERSION_UNSPECIFIED, clientPackageName, clientUid, clientPid, API_1,
+            /*legacyMode*/ false, /*shimUpdateOnly*/ false,
+            /*out*/client);
 
-    if(ret != NO_ERROR) {
+    if(!ret.isOk()) {
         logRejected(id, getCallingPid(), String8(clientPackageName),
-                String8::format("%s (%d)", strerror(-ret), ret));
+                ret.toString8());
         return ret;
     }
 
-    device = client;
-    return NO_ERROR;
+    *device = client;
+    return ret;
 }
 
-status_t CameraService::connectLegacy(
+Status CameraService::connectLegacy(
         const sp<ICameraClient>& cameraClient,
         int cameraId, int halVersion,
         const String16& clientPackageName,
         int clientUid,
         /*out*/
-        sp<ICamera>& device) {
+        sp<ICamera>* device) {
 
     ATRACE_CALL();
     String8 id = String8::format("%d", cameraId);
@@ -1215,61 +1280,68 @@
          * it's a particular version in which case the HAL must supported
          * the open_legacy call
          */
-        ALOGE("%s: camera HAL module version %x doesn't support connecting to legacy HAL devices!",
-                __FUNCTION__, apiVersion);
+        String8 msg = String8::format("Camera HAL module version %x too old for connectLegacy!",
+                apiVersion);
+        ALOGE("%s: %s",
+                __FUNCTION__, msg.string());
         logRejected(id, getCallingPid(), String8(clientPackageName),
-                String8("HAL module version doesn't support legacy HAL connections"));
-        return INVALID_OPERATION;
+                msg);
+        return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, msg.string());
     }
 
-    status_t ret = NO_ERROR;
+    Status ret = Status::ok();
     sp<Client> client = nullptr;
-    ret = connectHelper<ICameraClient,Client>(cameraClient, id, halVersion, clientPackageName,
-            clientUid, USE_CALLING_PID, API_1, true, false, /*out*/client);
+    ret = connectHelper<ICameraClient,Client>(cameraClient, id, halVersion,
+            clientPackageName, clientUid, USE_CALLING_PID, API_1,
+            /*legacyMode*/ true, /*shimUpdateOnly*/ false,
+            /*out*/client);
 
-    if(ret != NO_ERROR) {
+    if(!ret.isOk()) {
         logRejected(id, getCallingPid(), String8(clientPackageName),
-                String8::format("%s (%d)", strerror(-ret), ret));
+                ret.toString8());
         return ret;
     }
 
-    device = client;
-    return NO_ERROR;
+    *device = client;
+    return ret;
 }
 
-status_t CameraService::connectDevice(
-        const sp<ICameraDeviceCallbacks>& cameraCb,
+Status CameraService::connectDevice(
+        const sp<hardware::camera2::ICameraDeviceCallbacks>& cameraCb,
         int cameraId,
         const String16& clientPackageName,
         int clientUid,
         /*out*/
-        sp<ICameraDeviceUser>& device) {
+        sp<hardware::camera2::ICameraDeviceUser>* device) {
 
     ATRACE_CALL();
-    status_t ret = NO_ERROR;
+    Status ret = Status::ok();
     String8 id = String8::format("%d", cameraId);
     sp<CameraDeviceClient> client = nullptr;
-    ret = connectHelper<ICameraDeviceCallbacks,CameraDeviceClient>(cameraCb, id,
-            CAMERA_HAL_API_VERSION_UNSPECIFIED, clientPackageName, clientUid, USE_CALLING_PID,
-            API_2, false, false, /*out*/client);
+    ret = connectHelper<hardware::camera2::ICameraDeviceCallbacks,CameraDeviceClient>(cameraCb, id,
+            CAMERA_HAL_API_VERSION_UNSPECIFIED, clientPackageName,
+            clientUid, USE_CALLING_PID, API_2,
+            /*legacyMode*/ false, /*shimUpdateOnly*/ false,
+            /*out*/client);
 
-    if(ret != NO_ERROR) {
+    if(!ret.isOk()) {
         logRejected(id, getCallingPid(), String8(clientPackageName),
-                String8::format("%s (%d)", strerror(-ret), ret));
+                ret.toString8());
         return ret;
     }
 
-    device = client;
-    return NO_ERROR;
+    *device = client;
+    return ret;
 }
 
-status_t CameraService::setTorchMode(const String16& cameraId, bool enabled,
+Status CameraService::setTorchMode(const String16& cameraId, bool enabled,
         const sp<IBinder>& clientBinder) {
 
     ATRACE_CALL();
     if (enabled && clientBinder == nullptr) {
         ALOGE("%s: torch client binder is NULL", __FUNCTION__);
-        return -EINVAL;
+        return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT,
+                "Torch client Binder is null");
     }
 
     String8 id = String8(cameraId.string());
@@ -1279,35 +1351,47 @@
     auto state = getCameraState(id);
     if (state == nullptr) {
         ALOGE("%s: camera id is invalid %s", __FUNCTION__, id.string());
-        return -EINVAL;
+        return STATUS_ERROR_FMT(ERROR_ILLEGAL_ARGUMENT,
+                "Camera ID \"%s\" is a not valid camera ID", id.string());
     }
 
-    ICameraServiceListener::Status cameraStatus = state->getStatus();
+    int32_t cameraStatus = state->getStatus();
     if (cameraStatus != ICameraServiceListener::STATUS_PRESENT &&
             cameraStatus != ICameraServiceListener::STATUS_NOT_AVAILABLE) {
         ALOGE("%s: camera id is invalid %s", __FUNCTION__, id.string());
-        return -EINVAL;
+        return STATUS_ERROR_FMT(ERROR_ILLEGAL_ARGUMENT,
+                "Camera ID \"%s\" is a not valid camera ID", id.string());
     }
 
     {
         Mutex::Autolock al(mTorchStatusMutex);
-        ICameraServiceListener::TorchStatus status;
-        status_t res = getTorchStatusLocked(id, &status);
-        if (res) {
+        int32_t status;
+        status_t err = getTorchStatusLocked(id, &status);
+        if (err != OK) {
+            if (err == NAME_NOT_FOUND) {
+                return STATUS_ERROR_FMT(ERROR_ILLEGAL_ARGUMENT,
+                        "Camera \"%s\" does not have a flash unit", id.string());
+            }
             ALOGE("%s: getting current torch status failed for camera %s",
                     __FUNCTION__, id.string());
-            return -EINVAL;
+            return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION,
+                    "Error updating torch status for camera \"%s\": %s (%d)", id.string(),
+                    strerror(-err), err);
         }
 
         if (status == ICameraServiceListener::TORCH_STATUS_NOT_AVAILABLE) {
             if (cameraStatus == ICameraServiceListener::STATUS_NOT_AVAILABLE) {
                 ALOGE("%s: torch mode of camera %s is not available because "
                         "camera is in use", __FUNCTION__, id.string());
-                return -EBUSY;
+                return STATUS_ERROR_FMT(ERROR_CAMERA_IN_USE,
+                        "Torch for camera \"%s\" is not available due to an existing camera user",
+                        id.string());
             } else {
                 ALOGE("%s: torch mode of camera %s is not available due to "
                         "insufficient resources", __FUNCTION__, id.string());
-                return -EUSERS;
+                return STATUS_ERROR_FMT(ERROR_MAX_CAMERAS_IN_USE,
+                        "Torch for camera \"%s\" is not available due to insufficient resources",
+                        id.string());
             }
         }
     }
@@ -1325,12 +1409,25 @@
         }
     }
 
-    status_t res = mFlashlight->setTorchMode(id, enabled);
+    status_t err = mFlashlight->setTorchMode(id, enabled);
 
-    if (res) {
-        ALOGE("%s: setting torch mode of camera %s to %d failed. %s (%d)",
-                __FUNCTION__, id.string(), enabled, strerror(-res), res);
-        return res;
+    if (err != OK) {
+        int32_t errorCode;
+        String8 msg;
+        switch (err) {
+            case -ENOSYS:
+                msg = String8::format("Camera \"%s\" has no flashlight",
+                    id.string());
+                errorCode = ERROR_ILLEGAL_ARGUMENT;
+                break;
+            default:
+                msg = String8::format(
+                    "Setting torch mode of camera \"%s\" to %d failed: %s (%d)",
+                    id.string(), enabled, strerror(-err), err);
+                errorCode = ERROR_INVALID_OPERATION;
+        }
+        ALOGE("%s: %s", __FUNCTION__, msg.string());
+        return STATUS_ERROR(errorCode, msg.string());
     }
 
     {
@@ -1350,34 +1447,36 @@
         }
     }
 
-    return OK;
+    return Status::ok();
 }
 
-void CameraService::notifySystemEvent(int32_t eventId, const int32_t* args, size_t length) {
+Status CameraService::notifySystemEvent(int32_t eventId,
+        const std::vector<int32_t>& args) {
     ATRACE_CALL();
 
     switch(eventId) {
-        case ICameraService::USER_SWITCHED: {
-            doUserSwitch(/*newUserIds*/args, /*length*/length);
+        case ICameraService::EVENT_USER_SWITCHED: {
+            doUserSwitch(/*newUserIds*/ args);
             break;
         }
-        case ICameraService::NO_EVENT:
+        case ICameraService::EVENT_NONE:
         default: {
             ALOGW("%s: Received invalid system event from system_server: %d", __FUNCTION__,
                     eventId);
             break;
         }
     }
+    return Status::ok();
 }
 
-status_t CameraService::addListener(const sp<ICameraServiceListener>& listener) {
+Status CameraService::addListener(const sp<ICameraServiceListener>& listener) {
     ATRACE_CALL();
 
     ALOGV("%s: Add listener %p", __FUNCTION__, listener.get());
 
     if (listener == nullptr) {
         ALOGE("%s: Listener must not be null", __FUNCTION__);
-        return BAD_VALUE;
+        return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "Null listener given to addListener");
     }
 
     Mutex::Autolock lock(mServiceLock);
@@ -1388,7 +1487,7 @@
             if (IInterface::asBinder(it) == IInterface::asBinder(listener)) {
                 ALOGW("%s: Tried to add listener %p which was already subscribed",
                       __FUNCTION__, listener.get());
-                return ALREADY_EXISTS;
+                return STATUS_ERROR(ERROR_ALREADY_EXISTS, "Listener already registered");
             }
         }
 
@@ -1417,17 +1516,17 @@
         }
     }
 
-    return OK;
+    return Status::ok();
 }
 
-status_t CameraService::removeListener(const sp<ICameraServiceListener>& listener) {
+Status CameraService::removeListener(const sp<ICameraServiceListener>& listener) {
     ATRACE_CALL();
 
     ALOGV("%s: Remove listener %p", __FUNCTION__, listener.get());
 
     if (listener == 0) {
         ALOGE("%s: Listener must not be null", __FUNCTION__);
-        return BAD_VALUE;
+        return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "Null listener given to removeListener");
     }
 
     Mutex::Autolock lock(mServiceLock);
@@ -1437,7 +1536,7 @@
         for (auto it = mListenerList.begin(); it != mListenerList.end(); it++) {
             if (IInterface::asBinder(*it) == IInterface::asBinder(listener)) {
                 mListenerList.erase(it);
-                return OK;
+                return Status::ok();
             }
         }
     }
@@ -1445,23 +1544,23 @@
     ALOGW("%s: Tried to remove a listener %p which was not subscribed",
           __FUNCTION__, listener.get());
 
-    return BAD_VALUE;
+    return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "Unregistered listener given to removeListener");
 }
 
-status_t CameraService::getLegacyParameters(int cameraId, /*out*/String16* parameters) {
+Status CameraService::getLegacyParameters(int cameraId, /*out*/String16* parameters) {
 
     ATRACE_CALL();
     ALOGV("%s: for camera ID = %d", __FUNCTION__, cameraId);
 
     if (parameters == NULL) {
         ALOGE("%s: parameters must not be null", __FUNCTION__);
-        return BAD_VALUE;
+        return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "Parameters must not be null");
     }
 
-    status_t ret = 0;
+    Status ret = Status::ok();
 
     CameraParameters shimParams;
-    if ((ret = getLegacyParametersLazy(cameraId, /*out*/&shimParams)) != OK) {
+    if (!(ret = getLegacyParametersLazy(cameraId, /*out*/&shimParams)).isOk()) {
         // Error logged by caller
         return ret;
     }
@@ -1471,10 +1570,10 @@
 
     *parameters = shimParamsString16;
 
-    return OK;
+    return ret;
 }
 
-status_t CameraService::supportsCameraApi(int cameraId, int apiVersion) {
+Status CameraService::supportsCameraApi(int cameraId, int apiVersion, bool *isSupported) {
     ATRACE_CALL();
 
     ALOGV("%s: for camera ID = %d", __FUNCTION__, cameraId);
@@ -1484,40 +1583,48 @@
         case API_VERSION_2:
             break;
         default:
-            ALOGE("%s: Bad API version %d", __FUNCTION__, apiVersion);
-            return BAD_VALUE;
+            String8 msg = String8::format("Unknown API version %d", apiVersion);
+            ALOGE("%s: %s", __FUNCTION__, msg.string());
+            return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, msg.string());
     }
 
     int facing = -1;
     int deviceVersion = getDeviceVersion(cameraId, &facing);
 
     switch(deviceVersion) {
-      case CAMERA_DEVICE_API_VERSION_1_0:
-      case CAMERA_DEVICE_API_VERSION_3_0:
-      case CAMERA_DEVICE_API_VERSION_3_1:
-        if (apiVersion == API_VERSION_2) {
-            ALOGV("%s: Camera id %d uses HAL prior to HAL3.2, doesn't support api2 without shim",
+        case CAMERA_DEVICE_API_VERSION_1_0:
+        case CAMERA_DEVICE_API_VERSION_3_0:
+        case CAMERA_DEVICE_API_VERSION_3_1:
+            if (apiVersion == API_VERSION_2) {
+                ALOGV("%s: Camera id %d uses HAL version %d <3.2, doesn't support api2 without shim",
+                        __FUNCTION__, cameraId, deviceVersion);
+                *isSupported = false;
+            } else { // if (apiVersion == API_VERSION_1) {
+                ALOGV("%s: Camera id %d uses older HAL before 3.2, but api1 is always supported",
+                        __FUNCTION__, cameraId);
+                *isSupported = true;
+            }
+            break;
+        case CAMERA_DEVICE_API_VERSION_3_2:
+        case CAMERA_DEVICE_API_VERSION_3_3:
+            ALOGV("%s: Camera id %d uses HAL3.2 or newer, supports api1/api2 directly",
                     __FUNCTION__, cameraId);
-            return -EOPNOTSUPP;
-        } else { // if (apiVersion == API_VERSION_1) {
-            ALOGV("%s: Camera id %d uses older HAL before 3.2, but api1 is always supported",
-                    __FUNCTION__, cameraId);
-            return OK;
+            *isSupported = true;
+            break;
+        case -1: {
+            String8 msg = String8::format("Unknown camera ID %d", cameraId);
+            ALOGE("%s: %s", __FUNCTION__, msg.string());
+            return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, msg.string());
         }
-      case CAMERA_DEVICE_API_VERSION_3_2:
-      case CAMERA_DEVICE_API_VERSION_3_3:
-        ALOGV("%s: Camera id %d uses HAL3.2 or newer, supports api1/api2 directly",
-                __FUNCTION__, cameraId);
-        return OK;
-      case -1:
-        ALOGE("%s: Invalid camera id %d", __FUNCTION__, cameraId);
-        return BAD_VALUE;
-      default:
-        ALOGE("%s: Unknown camera device HAL version: %d", __FUNCTION__, deviceVersion);
-        return INVALID_OPERATION;
+        default: {
+            String8 msg = String8::format("Unknown device version %d for device %d",
+                    deviceVersion, cameraId);
+            ALOGE("%s: %s", __FUNCTION__, msg.string());
+            return STATUS_ERROR(ERROR_INVALID_OPERATION, msg.string());
+        }
     }
 
-    return OK;
+    return Status::ok();
 }
 
 void CameraService::removeByClient(const BasicClient* client) {
@@ -1554,7 +1661,8 @@
                 evicted.push_back(clientSp);
 
                 // Notify the client of disconnection
-                clientSp->notifyError(ICameraDeviceCallbacks::ERROR_CAMERA_DISCONNECTED,
+                clientSp->notifyError(
+                        hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_DISCONNECTED,
                         CaptureResultExtras());
             }
         }
@@ -1679,19 +1787,19 @@
     return clientDescriptorPtr->getValue();
 }
 
-void CameraService::doUserSwitch(const int32_t* newUserId, size_t length) {
+void CameraService::doUserSwitch(const std::vector<int32_t>& newUserIds) {
     // Acquire mServiceLock and prevent other clients from connecting
     std::unique_ptr<AutoConditionLock> lock =
             AutoConditionLock::waitAndAcquire(mServiceLockWrapper);
 
     std::set<userid_t> newAllowedUsers;
-    for (size_t i = 0; i < length; i++) {
-        if (newUserId[i] < 0) {
+    for (size_t i = 0; i < newUserIds.size(); i++) {
+        if (newUserIds[i] < 0) {
             ALOGE("%s: Bad user ID %d given during user switch, ignoring.",
-                    __FUNCTION__, newUserId[i]);
+                    __FUNCTION__, newUserIds[i]);
             return;
         }
-        newAllowedUsers.insert(static_cast<userid_t>(newUserId[i]));
+        newAllowedUsers.insert(static_cast<userid_t>(newUserIds[i]));
     }
 
 
@@ -1817,7 +1925,7 @@
 
     // Permission checks
     switch (code) {
-        case BnCameraService::NOTIFY_SYSTEM_EVENT: {
+        case BnCameraService::NOTIFYSYSTEMEVENT: {
             if (pid != selfPid) {
                 // Ensure we're being called by system_server, or similar process with
                 // permissions to notify the camera service about system events
@@ -1979,9 +2087,10 @@
     mDestructionStarted = true;
 }
 
-void CameraService::BasicClient::disconnect() {
+binder::Status CameraService::BasicClient::disconnect() {
+    binder::Status res = Status::ok();
     if (mDisconnected) {
-        return;
+        return res;
     }
     mDisconnected = true;
 
@@ -1999,6 +2108,8 @@
 
     // client shouldn't be able to call into us anymore
     mClientPid = 0;
+
+    return res;
 }
 
 status_t CameraService::BasicClient::dump(int, const Vector<String16>&) {
@@ -2080,7 +2191,7 @@
                 mClientPackageName);
         mOpsActive = false;
 
-        auto rejected = {ICameraServiceListener::STATUS_NOT_PRESENT,
+        std::initializer_list<int32_t> rejected = {ICameraServiceListener::STATUS_NOT_PRESENT,
                 ICameraServiceListener::STATUS_ENUMERATING};
 
         // Transition to PRESENT if the camera is not in either of the rejected states
@@ -2131,7 +2242,7 @@
         // and to prevent further calls by client.
         mClientPid = getCallingPid();
         CaptureResultExtras resultExtras; // a dummy result (invalid)
-        notifyError(ICameraDeviceCallbacks::ERROR_CAMERA_SERVICE, resultExtras);
+        notifyError(hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_SERVICE, resultExtras);
         disconnect();
     }
 }
@@ -2149,7 +2260,7 @@
     return sp<Client>{nullptr};
 }
 
-void CameraService::Client::notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
+void CameraService::Client::notifyError(int32_t errorCode,
         const CaptureResultExtras& resultExtras) {
     (void) errorCode;
     (void) resultExtras;
@@ -2161,9 +2272,9 @@
 }
 
 // NOTE: function is idempotent
-void CameraService::Client::disconnect() {
+binder::Status CameraService::Client::disconnect() {
     ALOGV("Client::disconnect");
-    BasicClient::disconnect();
+    return BasicClient::disconnect();
 }
 
 bool CameraService::Client::canCastToApiClient(apiLevel level) const {
@@ -2192,7 +2303,7 @@
 
 CameraService::CameraState::~CameraState() {}
 
-ICameraServiceListener::Status CameraService::CameraState::getStatus() const {
+int32_t CameraService::CameraState::getStatus() const {
     Mutex::Autolock lock(mStatusLock);
     return mStatus;
 }
@@ -2554,12 +2665,12 @@
             __FUNCTION__);
 }
 
-void CameraService::updateStatus(ICameraServiceListener::Status status, const String8& cameraId) {
+void CameraService::updateStatus(int32_t status, const String8& cameraId) {
     updateStatus(status, cameraId, {});
 }
 
-void CameraService::updateStatus(ICameraServiceListener::Status status, const String8& cameraId,
-        std::initializer_list<ICameraServiceListener::Status> rejectSourceStates) {
+void CameraService::updateStatus(int32_t status, const String8& cameraId,
+        std::initializer_list<int32_t> rejectSourceStates) {
     // Do not lock mServiceLock here or can get into a deadlock from
     // connect() -> disconnect -> updateStatus
 
@@ -2574,15 +2685,15 @@
     // Update the status for this camera state, then send the onStatusChangedCallbacks to each
     // of the listeners with both the mStatusStatus and mStatusListenerLock held
     state->updateStatus(status, cameraId, rejectSourceStates, [this]
-            (const String8& cameraId, ICameraServiceListener::Status status) {
+            (const String8& cameraId, int32_t status) {
 
             if (status != ICameraServiceListener::STATUS_ENUMERATING) {
                 // Update torch status if it has a flash unit.
                 Mutex::Autolock al(mTorchStatusMutex);
-                ICameraServiceListener::TorchStatus torchStatus;
+                int32_t torchStatus;
                 if (getTorchStatusLocked(cameraId, &torchStatus) !=
                         NAME_NOT_FOUND) {
-                    ICameraServiceListener::TorchStatus newTorchStatus =
+                    int32_t newTorchStatus =
                             status == ICameraServiceListener::STATUS_PRESENT ?
                             ICameraServiceListener::TORCH_STATUS_AVAILABLE_OFF :
                             ICameraServiceListener::TORCH_STATUS_NOT_AVAILABLE;
@@ -2612,7 +2723,7 @@
 
 status_t CameraService::getTorchStatusLocked(
         const String8& cameraId,
-        ICameraServiceListener::TorchStatus *status) const {
+        int32_t *status) const {
     if (!status) {
         return BAD_VALUE;
     }
@@ -2627,12 +2738,12 @@
 }
 
 status_t CameraService::setTorchStatusLocked(const String8& cameraId,
-        ICameraServiceListener::TorchStatus status) {
+        int32_t status) {
     ssize_t index = mTorchStatusMap.indexOfKey(cameraId);
     if (index == NAME_NOT_FOUND) {
         return BAD_VALUE;
     }
-    ICameraServiceListener::TorchStatus& item =
+    int32_t& item =
             mTorchStatusMap.editValueAt(index);
     item = status;
 
diff --git a/services/camera/libcameraservice/CameraService.h b/services/camera/libcameraservice/CameraService.h
index 66de77f..e29b01c 100644
--- a/services/camera/libcameraservice/CameraService.h
+++ b/services/camera/libcameraservice/CameraService.h
@@ -17,25 +17,22 @@
 #ifndef ANDROID_SERVERS_CAMERA_CAMERASERVICE_H
 #define ANDROID_SERVERS_CAMERA_CAMERASERVICE_H
 
+#include <android/hardware/BnCameraService.h>
+#include <android/hardware/ICameraServiceListener.h>
+
 #include <cutils/multiuser.h>
 #include <utils/Vector.h>
 #include <utils/KeyedVector.h>
 #include <binder/AppOpsManager.h>
 #include <binder/BinderService.h>
 #include <binder/IAppOpsCallback.h>
-#include <camera/ICameraService.h>
 #include <camera/ICameraServiceProxy.h>
 #include <hardware/camera.h>
 
-#include <camera/ICamera.h>
-#include <camera/ICameraClient.h>
-#include <camera/camera2/ICameraDeviceUser.h>
-#include <camera/camera2/ICameraDeviceCallbacks.h>
 #include <camera/VendorTagDescriptor.h>
 #include <camera/CaptureResult.h>
 #include <camera/CameraParameters.h>
 
-#include <camera/ICameraServiceListener.h>
 #include "CameraFlashlight.h"
 
 #include "common/CameraModule.h"
@@ -58,7 +55,7 @@
 
 class CameraService :
     public BinderService<CameraService>,
-    public BnCameraService,
+    public ::android::hardware::BnCameraService,
     public IBinder::DeathRecipient,
     public camera_module_callbacks_t
 {
@@ -101,55 +98,58 @@
     virtual void        onDeviceStatusChanged(camera_device_status_t cameraId,
                                               camera_device_status_t newStatus);
     virtual void        onTorchStatusChanged(const String8& cameraId,
-                                             ICameraServiceListener::TorchStatus
-                                                   newStatus);
+                                             int32_t newStatus);
 
     /////////////////////////////////////////////////////////////////////
     // ICameraService
-    virtual int32_t     getNumberOfCameras(int type);
-    virtual int32_t     getNumberOfCameras();
+    virtual binder::Status     getNumberOfCameras(int32_t type, int32_t* numCameras);
 
-    virtual status_t    getCameraInfo(int cameraId,
-                                      struct CameraInfo* cameraInfo);
-    virtual status_t    getCameraCharacteristics(int cameraId,
-                                                 CameraMetadata* cameraInfo);
-    virtual status_t    getCameraVendorTagDescriptor(/*out*/ sp<VendorTagDescriptor>& desc);
-
-    virtual status_t connect(const sp<ICameraClient>& cameraClient, int cameraId,
-            const String16& clientPackageName, int clientUid, int clientPid,
+    virtual binder::Status     getCameraInfo(int cameraId,
+            hardware::CameraInfo* cameraInfo);
+    virtual binder::Status     getCameraCharacteristics(int cameraId,
+            CameraMetadata* cameraInfo);
+    virtual binder::Status     getCameraVendorTagDescriptor(
             /*out*/
-            sp<ICamera>& device);
+            hardware::camera2::params::VendorTagDescriptor* desc);
 
-    virtual status_t connectLegacy(const sp<ICameraClient>& cameraClient, int cameraId,
-            int halVersion, const String16& clientPackageName, int clientUid,
+    virtual binder::Status     connect(const sp<hardware::ICameraClient>& cameraClient,
+            int32_t cameraId, const String16& clientPackageName,
+            int32_t clientUid, int clientPid,
             /*out*/
-            sp<ICamera>& device);
+            sp<hardware::ICamera>* device);
 
-    virtual status_t connectDevice(
-            const sp<ICameraDeviceCallbacks>& cameraCb,
-            int cameraId,
-            const String16& clientPackageName,
-            int clientUid,
+    virtual binder::Status     connectLegacy(const sp<hardware::ICameraClient>& cameraClient,
+            int32_t cameraId, int32_t halVersion,
+            const String16& clientPackageName, int32_t clientUid,
             /*out*/
-            sp<ICameraDeviceUser>& device);
+            sp<hardware::ICamera>* device);
 
-    virtual status_t    addListener(const sp<ICameraServiceListener>& listener);
-    virtual status_t    removeListener(
-                                    const sp<ICameraServiceListener>& listener);
+    virtual binder::Status     connectDevice(
+            const sp<hardware::camera2::ICameraDeviceCallbacks>& cameraCb, int32_t cameraId,
+            const String16& clientPackageName, int32_t clientUid,
+            /*out*/
+            sp<hardware::camera2::ICameraDeviceUser>* device);
 
-    virtual status_t    getLegacyParameters(
-            int cameraId,
+    virtual binder::Status    addListener(const sp<hardware::ICameraServiceListener>& listener);
+    virtual binder::Status    removeListener(
+            const sp<hardware::ICameraServiceListener>& listener);
+
+    virtual binder::Status    getLegacyParameters(
+            int32_t cameraId,
             /*out*/
             String16* parameters);
 
-    virtual status_t    setTorchMode(const String16& cameraId, bool enabled,
+    virtual binder::Status    setTorchMode(const String16& cameraId, bool enabled,
             const sp<IBinder>& clientBinder);
 
-    virtual void notifySystemEvent(int32_t eventId, const int32_t* args, size_t length);
+    virtual binder::Status    notifySystemEvent(int32_t eventId,
+            const std::vector<int32_t>& args);
 
     // OK = supports api of that version, -EOPNOTSUPP = does not support
-    virtual status_t    supportsCameraApi(
-            int cameraId, int apiVersion);
+    virtual binder::Status    supportsCameraApi(
+            int32_t cameraId, int32_t apiVersion,
+            /*out*/
+            bool *isSupported);
 
     // Extra permissions checks
     virtual status_t    onTransact(uint32_t code, const Parcel& data,
@@ -185,35 +185,35 @@
 
     /////////////////////////////////////////////////////////////////////
     // Shared utilities
-    static status_t     filterGetInfoErrorCode(status_t err);
+    static binder::Status filterGetInfoErrorCode(status_t err);
 
     /////////////////////////////////////////////////////////////////////
     // CameraClient functionality
 
     class BasicClient : public virtual RefBase {
     public:
-        virtual status_t    initialize(CameraModule *module) = 0;
-        virtual void        disconnect();
+        virtual status_t       initialize(CameraModule *module) = 0;
+        virtual binder::Status disconnect();
 
         // because we can't virtually inherit IInterface, which breaks
         // virtual inheritance
-        virtual sp<IBinder> asBinderWrapper() = 0;
+        virtual sp<IBinder>    asBinderWrapper() = 0;
 
         // Return the remote callback binder object (e.g. ICameraDeviceCallbacks)
-        sp<IBinder>         getRemote() {
+        sp<IBinder>            getRemote() {
             return mRemoteBinder;
         }
 
         // Disallows dumping over binder interface
-        virtual status_t      dump(int fd, const Vector<String16>& args);
+        virtual status_t dump(int fd, const Vector<String16>& args);
         // Internal dump method to be called by CameraService
-        virtual status_t      dumpClient(int fd, const Vector<String16>& args) = 0;
+        virtual status_t dumpClient(int fd, const Vector<String16>& args) = 0;
 
         // Return the package name for this client
         virtual String16 getPackageName() const;
 
         // Notify client about a fatal error
-        virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
+        virtual void notifyError(int32_t errorCode,
                 const CaptureResultExtras& resultExtras) = 0;
 
         // Get the UID of the application client using this
@@ -282,14 +282,14 @@
         virtual void opChanged(int32_t op, const String16& packageName);
     }; // class BasicClient
 
-    class Client : public BnCamera, public BasicClient
+    class Client : public hardware::BnCamera, public BasicClient
     {
     public:
-        typedef ICameraClient TCamCallbacks;
+        typedef hardware::ICameraClient TCamCallbacks;
 
         // ICamera interface (see ICamera for details)
-        virtual void          disconnect();
-        virtual status_t      connect(const sp<ICameraClient>& client) = 0;
+        virtual binder::Status disconnect();
+        virtual status_t      connect(const sp<hardware::ICameraClient>& client) = 0;
         virtual status_t      lock() = 0;
         virtual status_t      unlock() = 0;
         virtual status_t      setPreviewTarget(const sp<IGraphicBufferProducer>& bufferProducer)=0;
@@ -314,7 +314,7 @@
 
         // Interface used by CameraService
         Client(const sp<CameraService>& cameraService,
-                const sp<ICameraClient>& cameraClient,
+                const sp<hardware::ICameraClient>& cameraClient,
                 const String16& clientPackageName,
                 int cameraId,
                 int cameraFacing,
@@ -324,7 +324,7 @@
         ~Client();
 
         // return our camera client
-        const sp<ICameraClient>&    getRemoteCallback() {
+        const sp<hardware::ICameraClient>&    getRemoteCallback() {
             return mRemoteCallback;
         }
 
@@ -332,7 +332,7 @@
             return asBinder(this);
         }
 
-        virtual void         notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
+        virtual void         notifyError(int32_t errorCode,
                                          const CaptureResultExtras& resultExtras);
 
         // Check what API level is used for this client. This is used to determine which
@@ -345,7 +345,7 @@
         // Initialized in constructor
 
         // - The app-side Binder interface to receive callbacks from us
-        sp<ICameraClient>               mRemoteCallback;
+        sp<hardware::ICameraClient>               mRemoteCallback;
 
     }; // class Client
 
@@ -432,12 +432,12 @@
          *
          * This method acquires mStatusLock.
          */
-        ICameraServiceListener::Status getStatus() const;
+        int32_t getStatus() const;
 
         /**
          * This function updates the status for this camera device, unless the given status
          * is in the given list of rejected status states, and execute the function passed in
-         * with a signature onStatusUpdateLocked(const String8&, ICameraServiceListener::Status)
+         * with a signature onStatusUpdateLocked(const String8&, int32_t)
          * if the status has changed.
          *
          * This method is idempotent, and will not result in the function passed to
@@ -445,8 +445,8 @@
          * This method aquires mStatusLock.
          */
         template<class Func>
-        void updateStatus(ICameraServiceListener::Status status, const String8& cameraId,
-                std::initializer_list<ICameraServiceListener::Status> rejectSourceStates,
+        void updateStatus(int32_t status, const String8& cameraId,
+                std::initializer_list<int32_t> rejectSourceStates,
                 Func onStatusUpdatedLocked);
 
         /**
@@ -477,7 +477,7 @@
 
     private:
         const String8 mId;
-        ICameraServiceListener::Status mStatus; // protected by mStatusLock
+        int32_t mStatus; // protected by mStatusLock
         const int mCost;
         std::set<String8> mConflicting;
         mutable Mutex mStatusLock;
@@ -488,8 +488,8 @@
     virtual void onFirstRef();
 
     // Check if we can connect, before we acquire the service lock.
-    status_t validateConnectLocked(const String8& cameraId, /*inout*/int& clientUid,
-            /*inout*/int& clientPid) const;
+    binder::Status validateConnectLocked(const String8& cameraId, const String8& clientName8,
+          /*inout*/int& clientUid, /*inout*/int& clientPid) const;
 
     // Handle active client evictions, and update service state.
     // Only call with with mServiceLock held.
@@ -501,8 +501,9 @@
 
     // Single implementation shared between the various connect calls
     template<class CALLBACK, class CLIENT>
-    status_t connectHelper(const sp<CALLBACK>& cameraCb, const String8& cameraId, int halVersion,
-            const String16& clientPackageName, int clientUid, int clientPid,
+    binder::Status connectHelper(const sp<CALLBACK>& cameraCb, const String8& cameraId,
+            int halVersion, const String16& clientPackageName,
+            int clientUid, int clientPid,
             apiLevel effectiveApiLevel, bool legacyMode, bool shimUpdateOnly,
             /*out*/sp<CLIENT>& device);
 
@@ -583,7 +584,7 @@
     /**
      * Handle a notification that the current device user has changed.
      */
-    void doUserSwitch(const int32_t* newUserId, size_t length);
+    void doUserSwitch(const std::vector<int32_t>& newUserIds);
 
     /**
      * Add an event log message.
@@ -651,7 +652,7 @@
     CameraModule*     mModule;
 
     // Guarded by mStatusListenerMutex
-    std::vector<sp<ICameraServiceListener>> mListenerList;
+    std::vector<sp<hardware::ICameraServiceListener>> mListenerList;
     Mutex       mStatusListenerLock;
 
     /**
@@ -662,9 +663,9 @@
      * This method must be idempotent.
      * This method acquires mStatusLock and mStatusListenerLock.
      */
-    void updateStatus(ICameraServiceListener::Status status, const String8& cameraId,
-            std::initializer_list<ICameraServiceListener::Status> rejectedSourceStates);
-    void updateStatus(ICameraServiceListener::Status status, const String8& cameraId);
+    void updateStatus(int32_t status, const String8& cameraId,
+            std::initializer_list<int32_t> rejectedSourceStates);
+    void updateStatus(int32_t status, const String8& cameraId);
 
     // flashlight control
     sp<CameraFlashlight> mFlashlight;
@@ -675,7 +676,7 @@
     // guard mTorchUidMap
     Mutex                mTorchUidMapMutex;
     // camera id -> torch status
-    KeyedVector<String8, ICameraServiceListener::TorchStatus> mTorchStatusMap;
+    KeyedVector<String8, int32_t> mTorchStatusMap;
     // camera id -> torch client binder
     // only store the last client that turns on each camera's torch mode
     KeyedVector<String8, sp<IBinder>> mTorchClientMap;
@@ -688,15 +689,15 @@
     // handle torch mode status change and invoke callbacks. mTorchStatusMutex
     // should be locked.
     void onTorchStatusChangedLocked(const String8& cameraId,
-            ICameraServiceListener::TorchStatus newStatus);
+            int32_t newStatus);
 
     // get a camera's torch status. mTorchStatusMutex should be locked.
     status_t getTorchStatusLocked(const String8 &cameraId,
-            ICameraServiceListener::TorchStatus *status) const;
+            int32_t *status) const;
 
     // set a camera's torch status. mTorchStatusMutex should be locked.
     status_t setTorchStatusLocked(const String8 &cameraId,
-            ICameraServiceListener::TorchStatus status);
+            int32_t status);
 
     // IBinder::DeathRecipient implementation
     virtual void        binderDied(const wp<IBinder> &who);
@@ -708,25 +709,25 @@
     /**
      * Initialize and cache the metadata used by the HAL1 shim for a given cameraId.
      *
-     * Returns OK on success, or a negative error code.
+     * Sets Status to a service-specific error on failure
      */
-    status_t            initializeShimMetadata(int cameraId);
+    binder::Status      initializeShimMetadata(int cameraId);
 
     /**
      * Get the cached CameraParameters for the camera. If they haven't been
      * cached yet, then initialize them for the first time.
      *
-     * Returns OK on success, or a negative error code.
+     * Sets Status to a service-specific error on failure
      */
-    status_t            getLegacyParametersLazy(int cameraId, /*out*/CameraParameters* parameters);
+    binder::Status      getLegacyParametersLazy(int cameraId, /*out*/CameraParameters* parameters);
 
     /**
      * Generate the CameraCharacteristics metadata required by the Camera2 API
      * from the available HAL1 CameraParameters and CameraInfo.
      *
-     * Returns OK on success, or a negative error code.
+     * Sets Status to a service-specific error on failure
      */
-    status_t            generateShimMetadata(int cameraId, /*out*/CameraMetadata* cameraInfo);
+    binder::Status      generateShimMetadata(int cameraId, /*out*/CameraMetadata* cameraInfo);
 
     static int getCallingPid();
 
@@ -742,8 +743,8 @@
      */
     static int getCameraPriorityFromProcState(int procState);
 
-    static status_t makeClient(const sp<CameraService>& cameraService,
-            const sp<IInterface>& cameraCb, const String16& packageName, const String8& cameraId,
+    static binder::Status makeClient(const sp<CameraService>& cameraService,
+            const sp<IInterface>& cameraCb, const String16& packageName, int cameraId,
             int facing, int clientPid, uid_t clientUid, int servicePid, bool legacyMode,
             int halVersion, int deviceVersion, apiLevel effectiveApiLevel,
             /*out*/sp<BasicClient>* client);
@@ -758,12 +759,12 @@
 };
 
 template<class Func>
-void CameraService::CameraState::updateStatus(ICameraServiceListener::Status status,
+void CameraService::CameraState::updateStatus(int32_t status,
         const String8& cameraId,
-        std::initializer_list<ICameraServiceListener::Status> rejectSourceStates,
+        std::initializer_list<int32_t> rejectSourceStates,
         Func onStatusUpdatedLocked) {
     Mutex::Autolock lock(mStatusLock);
-    ICameraServiceListener::Status oldStatus = mStatus;
+    int32_t oldStatus = mStatus;
     mStatus = status;
 
     if (oldStatus == status) {
@@ -773,9 +774,9 @@
     ALOGV("%s: Status has changed for camera ID %s from %#x to %#x", __FUNCTION__,
             cameraId.string(), oldStatus, status);
 
-    if (oldStatus == ICameraServiceListener::STATUS_NOT_PRESENT &&
-        (status != ICameraServiceListener::STATUS_PRESENT &&
-         status != ICameraServiceListener::STATUS_ENUMERATING)) {
+    if (oldStatus == hardware::ICameraServiceListener::STATUS_NOT_PRESENT &&
+            (status != hardware::ICameraServiceListener::STATUS_PRESENT &&
+             status != hardware::ICameraServiceListener::STATUS_ENUMERATING)) {
 
         ALOGW("%s: From NOT_PRESENT can only transition into PRESENT or ENUMERATING",
                 __FUNCTION__);
@@ -800,13 +801,22 @@
     onStatusUpdatedLocked(cameraId, status);
 }
 
+#define STATUS_ERROR(errorCode, errorString) \
+    binder::Status::fromServiceSpecificError(errorCode, \
+            String8::format("%s:%d: %s", __FUNCTION__, __LINE__, errorString))
+
+#define STATUS_ERROR_FMT(errorCode, errorString, ...) \
+    binder::Status::fromServiceSpecificError(errorCode, \
+            String8::format("%s:%d: " errorString, __FUNCTION__, __LINE__, __VA_ARGS__))
+
 
 template<class CALLBACK, class CLIENT>
-status_t CameraService::connectHelper(const sp<CALLBACK>& cameraCb, const String8& cameraId,
+binder::Status CameraService::connectHelper(const sp<CALLBACK>& cameraCb, const String8& cameraId,
         int halVersion, const String16& clientPackageName, int clientUid, int clientPid,
         apiLevel effectiveApiLevel, bool legacyMode, bool shimUpdateOnly,
         /*out*/sp<CLIENT>& device) {
-    status_t ret = NO_ERROR;
+    binder::Status ret = binder::Status::ok();
+
     String8 clientName8(clientPackageName);
 
     ALOGI("CameraService::connect call (PID %d \"%s\", camera ID %s) for HAL version %s and "
@@ -821,14 +831,16 @@
                 AutoConditionLock::waitAndAcquire(mServiceLockWrapper, DEFAULT_CONNECT_TIMEOUT_NS);
 
         if (lock == nullptr) {
-            ALOGE("CameraService::connect X (PID %d) rejected (too many other clients connecting)."
+            ALOGE("CameraService::connect (PID %d) rejected (too many other clients connecting)."
                     , clientPid);
-            return -EBUSY;
+            return STATUS_ERROR_FMT(ERROR_MAX_CAMERAS_IN_USE,
+                    "Cannot open camera %s for \"%s\" (PID %d): Too many other clients connecting",
+                    cameraId.string(), clientName8.string(), clientPid);
         }
 
         // Enforce client permissions and do basic sanity checks
-        if((ret = validateConnectLocked(cameraId, /*inout*/clientUid, /*inout*/clientPid)) !=
-                NO_ERROR) {
+        if(!(ret = validateConnectLocked(cameraId, clientName8,
+                /*inout*/clientUid, /*inout*/clientPid)).isOk()) {
             return ret;
         }
 
@@ -837,22 +849,37 @@
         if (shimUpdateOnly) {
             auto cameraState = getCameraState(cameraId);
             if (cameraState != nullptr) {
-                if (!cameraState->getShimParams().isEmpty()) return NO_ERROR;
+                if (!cameraState->getShimParams().isEmpty()) return ret;
             }
         }
 
+        status_t err;
+
         sp<BasicClient> clientTmp = nullptr;
         std::shared_ptr<resource_policy::ClientDescriptor<String8, sp<BasicClient>>> partial;
-        if ((ret = handleEvictionsLocked(cameraId, clientPid, effectiveApiLevel,
+        if ((err = handleEvictionsLocked(cameraId, clientPid, effectiveApiLevel,
                 IInterface::asBinder(cameraCb), clientName8, /*out*/&clientTmp,
                 /*out*/&partial)) != NO_ERROR) {
-            return ret;
+            switch (err) {
+                case -ENODEV:
+                    return STATUS_ERROR_FMT(ERROR_DISCONNECTED,
+                            "No camera device with ID \"%s\" currently available",
+                            cameraId.string());
+                case -EBUSY:
+                    return STATUS_ERROR_FMT(ERROR_CAMERA_IN_USE,
+                            "Higher-priority client using camera, ID \"%s\" currently unavailable",
+                            cameraId.string());
+                default:
+                    return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION,
+                            "Unexpected error %s (%d) opening camera \"%s\"",
+                            strerror(-err), err, cameraId.string());
+            }
         }
 
         if (clientTmp.get() != nullptr) {
             // Handle special case for API1 MediaRecorder where the existing client is returned
             device = static_cast<CLIENT*>(clientTmp.get());
-            return NO_ERROR;
+            return ret;
         }
 
         // give flashlight a chance to close devices if necessary.
@@ -863,15 +890,16 @@
         if (id == -1) {
             ALOGE("%s: Invalid camera ID %s, cannot get device version from HAL.", __FUNCTION__,
                     cameraId.string());
-            return BAD_VALUE;
+            return STATUS_ERROR_FMT(ERROR_ILLEGAL_ARGUMENT,
+                    "Bad camera ID \"%s\" passed to camera open", cameraId.string());
         }
 
         int facing = -1;
         int deviceVersion = getDeviceVersion(id, /*out*/&facing);
         sp<BasicClient> tmp = nullptr;
-        if((ret = makeClient(this, cameraCb, clientPackageName, cameraId, facing, clientPid,
+        if(!(ret = makeClient(this, cameraCb, clientPackageName, id, facing, clientPid,
                 clientUid, getpid(), legacyMode, halVersion, deviceVersion, effectiveApiLevel,
-                /*out*/&tmp)) != NO_ERROR) {
+                /*out*/&tmp)).isOk()) {
             return ret;
         }
         client = static_cast<CLIENT*>(tmp.get());
@@ -879,9 +907,11 @@
         LOG_ALWAYS_FATAL_IF(client.get() == nullptr, "%s: CameraService in invalid state",
                 __FUNCTION__);
 
-        if ((ret = client->initialize(mModule)) != OK) {
+        if ((err = client->initialize(mModule)) != OK) {
             ALOGE("%s: Could not initialize client from HAL module.", __FUNCTION__);
-            return ret;
+            return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION,
+                    "Failed to initialize camera \"%s\": %s (%d)", cameraId.string(),
+                    strerror(-err), err);
         }
 
         // Update shim paremeters for legacy clients
@@ -914,9 +944,12 @@
     // Important: release the mutex here so the client can call back into the service from its
     // destructor (can be at the end of the call)
     device = client;
-    return NO_ERROR;
+    return ret;
 }
 
+#undef STATUS_ERROR_FMT
+#undef STATUS_ERROR
+
 } // namespace android
 
 #endif
diff --git a/services/camera/libcameraservice/api1/Camera2Client.cpp b/services/camera/libcameraservice/api1/Camera2Client.cpp
index 5ac5743..4eb7b03 100644
--- a/services/camera/libcameraservice/api1/Camera2Client.cpp
+++ b/services/camera/libcameraservice/api1/Camera2Client.cpp
@@ -24,6 +24,7 @@
 
 #include <cutils/properties.h>
 #include <gui/Surface.h>
+#include <android/hardware/camera2/ICameraDeviceCallbacks.h>
 
 #include "api1/Camera2Client.h"
 
@@ -46,7 +47,7 @@
 // Interface used by CameraService
 
 Camera2Client::Camera2Client(const sp<CameraService>& cameraService,
-        const sp<ICameraClient>& cameraClient,
+        const sp<hardware::ICameraClient>& cameraClient,
         const String16& clientPackageName,
         int cameraId,
         int cameraFacing,
@@ -367,15 +368,16 @@
 
 // ICamera interface
 
-void Camera2Client::disconnect() {
+binder::Status Camera2Client::disconnect() {
     ATRACE_CALL();
     Mutex::Autolock icl(mBinderSerializationLock);
 
+    binder::Status res = binder::Status::ok();
     // Allow both client and the cameraserver to disconnect at all times
     int callingPid = getCallingPid();
-    if (callingPid != mClientPid && callingPid != mServicePid) return;
+    if (callingPid != mClientPid && callingPid != mServicePid) return res;
 
-    if (mDevice == 0) return;
+    if (mDevice == 0) return res;
 
     ALOGV("Camera %d: Shutting down", mCameraId);
 
@@ -389,7 +391,7 @@
 
     {
         SharedParameters::Lock l(mParameters);
-        if (l.mParameters.state == Parameters::DISCONNECTED) return;
+        if (l.mParameters.state == Parameters::DISCONNECTED) return res;
         l.mParameters.state = Parameters::DISCONNECTED;
     }
 
@@ -430,9 +432,11 @@
     mDevice.clear();
 
     CameraService::Client::disconnect();
+
+    return res;
 }
 
-status_t Camera2Client::connect(const sp<ICameraClient>& client) {
+status_t Camera2Client::connect(const sp<hardware::ICameraClient>& client) {
     ATRACE_CALL();
     ALOGV("%s: E", __FUNCTION__);
     Mutex::Autolock icl(mBinderSerializationLock);
@@ -1682,22 +1686,22 @@
     }
 }
 
-void Camera2Client::notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
+void Camera2Client::notifyError(int32_t errorCode,
         const CaptureResultExtras& resultExtras) {
     int32_t err = CAMERA_ERROR_UNKNOWN;
     switch(errorCode) {
-        case ICameraDeviceCallbacks::ERROR_CAMERA_DISCONNECTED:
+        case hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_DISCONNECTED:
             err = CAMERA_ERROR_RELEASED;
             break;
-        case ICameraDeviceCallbacks::ERROR_CAMERA_DEVICE:
+        case hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_DEVICE:
             err = CAMERA_ERROR_UNKNOWN;
             break;
-        case ICameraDeviceCallbacks::ERROR_CAMERA_SERVICE:
+        case hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_SERVICE:
             err = CAMERA_ERROR_SERVER_DIED;
             break;
-        case ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST:
-        case ICameraDeviceCallbacks::ERROR_CAMERA_RESULT:
-        case ICameraDeviceCallbacks::ERROR_CAMERA_BUFFER:
+        case hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST:
+        case hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_RESULT:
+        case hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_BUFFER:
             ALOGW("%s: Received recoverable error %d from HAL - ignoring, requestId %" PRId32,
                     __FUNCTION__, errorCode, resultExtras.requestId);
             return;
diff --git a/services/camera/libcameraservice/api1/Camera2Client.h b/services/camera/libcameraservice/api1/Camera2Client.h
index 9155e43..12ee157 100644
--- a/services/camera/libcameraservice/api1/Camera2Client.h
+++ b/services/camera/libcameraservice/api1/Camera2Client.h
@@ -53,8 +53,8 @@
      * ICamera interface (see ICamera for details)
      */
 
-    virtual void            disconnect();
-    virtual status_t        connect(const sp<ICameraClient>& client);
+    virtual binder::Status  disconnect();
+    virtual status_t        connect(const sp<hardware::ICameraClient>& client);
     virtual status_t        lock();
     virtual status_t        unlock();
     virtual status_t        setPreviewTarget(
@@ -77,7 +77,7 @@
     virtual status_t        setParameters(const String8& params);
     virtual String8         getParameters() const;
     virtual status_t        sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
-    virtual void            notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
+    virtual void            notifyError(int32_t errorCode,
                                         const CaptureResultExtras& resultExtras);
     virtual status_t        setVideoTarget(const sp<IGraphicBufferProducer>& bufferProducer);
 
@@ -86,7 +86,7 @@
      */
 
     Camera2Client(const sp<CameraService>& cameraService,
-            const sp<ICameraClient>& cameraClient,
+            const sp<hardware::ICameraClient>& cameraClient,
             const String16& clientPackageName,
             int cameraId,
             int cameraFacing,
diff --git a/services/camera/libcameraservice/api1/CameraClient.cpp b/services/camera/libcameraservice/api1/CameraClient.cpp
index 8ab9a65..37f4c8f 100644
--- a/services/camera/libcameraservice/api1/CameraClient.cpp
+++ b/services/camera/libcameraservice/api1/CameraClient.cpp
@@ -34,7 +34,7 @@
 }
 
 CameraClient::CameraClient(const sp<CameraService>& cameraService,
-        const sp<ICameraClient>& cameraClient,
+        const sp<hardware::ICameraClient>& cameraClient,
         const String16& clientPackageName,
         int cameraId, int cameraFacing,
         int clientPid, int clientUid,
@@ -193,7 +193,7 @@
 }
 
 // connect a new client to the camera
-status_t CameraClient::connect(const sp<ICameraClient>& client) {
+status_t CameraClient::connect(const sp<hardware::ICameraClient>& client) {
     int callingPid = getCallingPid();
     LOG1("connect E (pid %d)", callingPid);
     Mutex::Autolock lock(mLock);
@@ -229,20 +229,21 @@
     }
 }
 
-void CameraClient::disconnect() {
+binder::Status CameraClient::disconnect() {
     int callingPid = getCallingPid();
     LOG1("disconnect E (pid %d)", callingPid);
     Mutex::Autolock lock(mLock);
 
+    binder::Status res = binder::Status::ok();
     // Allow both client and the cameraserver to disconnect at all times
     if (callingPid != mClientPid && callingPid != mServicePid) {
         ALOGW("different client - don't disconnect");
-        return;
+        return res;
     }
 
     // Make sure disconnect() is done once and once only, whether it is called
     // from the user directly, or called by the destructor.
-    if (mHardware == 0) return;
+    if (mHardware == 0) return res;
 
     LOG1("hardware teardown");
     // Before destroying mHardware, we must make sure it's in the
@@ -268,6 +269,8 @@
     CameraService::Client::disconnect();
 
     LOG1("disconnect X (pid %d)", callingPid);
+
+    return res;
 }
 
 // ----------------------------------------------------------------------------
@@ -797,7 +800,7 @@
         mCameraService->playSound(CameraService::SOUND_SHUTTER);
     }
 
-    sp<ICameraClient> c = mRemoteCallback;
+    sp<hardware::ICameraClient> c = mRemoteCallback;
     if (c != 0) {
         mLock.unlock();
         c->notifyCallback(CAMERA_MSG_SHUTTER, 0, 0);
@@ -834,7 +837,7 @@
     }
 
     // hold a strong pointer to the client
-    sp<ICameraClient> c = mRemoteCallback;
+    sp<hardware::ICameraClient> c = mRemoteCallback;
 
     // clear callback flags if no client or one-shot mode
     if (c == 0 || (mPreviewCallbackFlag & CAMERA_FRAME_CALLBACK_FLAG_ONE_SHOT_MASK)) {
@@ -864,7 +867,7 @@
 void CameraClient::handlePostview(const sp<IMemory>& mem) {
     disableMsgType(CAMERA_MSG_POSTVIEW_FRAME);
 
-    sp<ICameraClient> c = mRemoteCallback;
+    sp<hardware::ICameraClient> c = mRemoteCallback;
     mLock.unlock();
     if (c != 0) {
         c->dataCallback(CAMERA_MSG_POSTVIEW_FRAME, mem, NULL);
@@ -879,7 +882,7 @@
     size_t size;
     sp<IMemoryHeap> heap = mem->getMemory(&offset, &size);
 
-    sp<ICameraClient> c = mRemoteCallback;
+    sp<hardware::ICameraClient> c = mRemoteCallback;
     mLock.unlock();
     if (c != 0) {
         c->dataCallback(CAMERA_MSG_RAW_IMAGE, mem, NULL);
@@ -890,7 +893,7 @@
 void CameraClient::handleCompressedPicture(const sp<IMemory>& mem) {
     disableMsgType(CAMERA_MSG_COMPRESSED_IMAGE);
 
-    sp<ICameraClient> c = mRemoteCallback;
+    sp<hardware::ICameraClient> c = mRemoteCallback;
     mLock.unlock();
     if (c != 0) {
         c->dataCallback(CAMERA_MSG_COMPRESSED_IMAGE, mem, NULL);
@@ -900,7 +903,7 @@
 
 void CameraClient::handleGenericNotify(int32_t msgType,
     int32_t ext1, int32_t ext2) {
-    sp<ICameraClient> c = mRemoteCallback;
+    sp<hardware::ICameraClient> c = mRemoteCallback;
     mLock.unlock();
     if (c != 0) {
         c->notifyCallback(msgType, ext1, ext2);
@@ -909,7 +912,7 @@
 
 void CameraClient::handleGenericData(int32_t msgType,
     const sp<IMemory>& dataPtr, camera_frame_metadata_t *metadata) {
-    sp<ICameraClient> c = mRemoteCallback;
+    sp<hardware::ICameraClient> c = mRemoteCallback;
     mLock.unlock();
     if (c != 0) {
         c->dataCallback(msgType, dataPtr, metadata);
@@ -918,7 +921,7 @@
 
 void CameraClient::handleGenericDataTimestamp(nsecs_t timestamp,
     int32_t msgType, const sp<IMemory>& dataPtr) {
-    sp<ICameraClient> c = mRemoteCallback;
+    sp<hardware::ICameraClient> c = mRemoteCallback;
     mLock.unlock();
     if (c != 0) {
         c->dataCallbackTimestamp(timestamp, msgType, dataPtr);
@@ -926,7 +929,7 @@
 }
 
 void CameraClient::copyFrameAndPostCopiedFrame(
-        int32_t msgType, const sp<ICameraClient>& client,
+        int32_t msgType, const sp<hardware::ICameraClient>& client,
         const sp<IMemoryHeap>& heap, size_t offset, size_t size,
         camera_frame_metadata_t *metadata) {
     LOG2("copyFrameAndPostCopiedFrame");
diff --git a/services/camera/libcameraservice/api1/CameraClient.h b/services/camera/libcameraservice/api1/CameraClient.h
index 9b32774..603fd17 100644
--- a/services/camera/libcameraservice/api1/CameraClient.h
+++ b/services/camera/libcameraservice/api1/CameraClient.h
@@ -33,8 +33,8 @@
 {
 public:
     // ICamera interface (see ICamera for details)
-    virtual void            disconnect();
-    virtual status_t        connect(const sp<ICameraClient>& client);
+    virtual binder::Status  disconnect();
+    virtual status_t        connect(const sp<hardware::ICameraClient>& client);
     virtual status_t        lock();
     virtual status_t        unlock();
     virtual status_t        setPreviewTarget(const sp<IGraphicBufferProducer>& bufferProducer);
@@ -59,7 +59,7 @@
 
     // Interface used by CameraService
     CameraClient(const sp<CameraService>& cameraService,
-            const sp<ICameraClient>& cameraClient,
+            const sp<hardware::ICameraClient>& cameraClient,
             const String16& clientPackageName,
             int cameraId,
             int cameraFacing,
@@ -116,7 +116,7 @@
 
     void                    copyFrameAndPostCopiedFrame(
         int32_t msgType,
-        const sp<ICameraClient>& client,
+        const sp<hardware::ICameraClient>& client,
         const sp<IMemoryHeap>& heap,
         size_t offset, size_t size,
         camera_frame_metadata_t *metadata);
diff --git a/services/camera/libcameraservice/api1/client2/Parameters.cpp b/services/camera/libcameraservice/api1/client2/Parameters.cpp
index 7a97396..d4022cd 100644
--- a/services/camera/libcameraservice/api1/client2/Parameters.cpp
+++ b/services/camera/libcameraservice/api1/client2/Parameters.cpp
@@ -30,7 +30,7 @@
 #include "Parameters.h"
 #include "system/camera.h"
 #include "hardware/camera_common.h"
-#include <camera/ICamera.h>
+#include <android/hardware/ICamera.h>
 #include <media/MediaProfiles.h>
 #include <media/mediarecorder.h>
 
@@ -873,7 +873,7 @@
     // Set up initial state for non-Camera.Parameters state variables
     videoFormat = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
     videoDataSpace = HAL_DATASPACE_BT709;
-    videoBufferMode = ICamera::VIDEO_BUFFER_MODE_DATA_CALLBACK_YUV;
+    videoBufferMode = hardware::ICamera::VIDEO_BUFFER_MODE_DATA_CALLBACK_YUV;
     playShutterSound = true;
     enableFaceDetect = false;
 
diff --git a/services/camera/libcameraservice/api2/CameraDeviceClient.cpp b/services/camera/libcameraservice/api2/CameraDeviceClient.cpp
index 7be5696..6f9bc7c 100644
--- a/services/camera/libcameraservice/api2/CameraDeviceClient.cpp
+++ b/services/camera/libcameraservice/api2/CameraDeviceClient.cpp
@@ -28,14 +28,26 @@
 #include "common/CameraDeviceBase.h"
 #include "api2/CameraDeviceClient.h"
 
+// Convenience methods for constructing binder::Status objects for error returns
 
+#define STRINGIZE_IMPL(x) #x
+#define STRINGIZE(x) STRINGIZE_IMPL(x)
+
+#define STATUS_ERROR(errorCode, errorString) \
+    binder::Status::fromServiceSpecificError(errorCode, \
+            String8(STRINGIZE(__FUNCTION__) ":" STRINGIZE(__LINE__) ":" # errorString))
+
+#define STATUS_ERROR_FMT(errorCode, errorString, ...) \
+    binder::Status::fromServiceSpecificError(errorCode, \
+            String8::format(STRINGIZE(__FUNCTION__) ":" STRINGIZE(__LINE__) ":" # errorString, \
+                    __VA_ARGS__))
 
 namespace android {
 using namespace camera2;
 
 CameraDeviceClientBase::CameraDeviceClientBase(
         const sp<CameraService>& cameraService,
-        const sp<ICameraDeviceCallbacks>& remoteCallback,
+        const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback,
         const String16& clientPackageName,
         int cameraId,
         int cameraFacing,
@@ -56,13 +68,13 @@
 // Interface used by CameraService
 
 CameraDeviceClient::CameraDeviceClient(const sp<CameraService>& cameraService,
-                                   const sp<ICameraDeviceCallbacks>& remoteCallback,
-                                   const String16& clientPackageName,
-                                   int cameraId,
-                                   int cameraFacing,
-                                   int clientPid,
-                                   uid_t clientUid,
-                                   int servicePid) :
+        const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback,
+        const String16& clientPackageName,
+        int cameraId,
+        int cameraFacing,
+        int clientPid,
+        uid_t clientUid,
+        int servicePid) :
     Camera2ClientBase(cameraService, remoteCallback, clientPackageName,
                 cameraId, cameraFacing, clientPid, clientUid, servicePid),
     mInputStream(),
@@ -98,68 +110,77 @@
 CameraDeviceClient::~CameraDeviceClient() {
 }
 
-status_t CameraDeviceClient::submitRequest(sp<CaptureRequest> request,
-                                         bool streaming,
-                                         /*out*/
-                                         int64_t* lastFrameNumber) {
-    List<sp<CaptureRequest> > requestList;
-    requestList.push_back(request);
-    return submitRequestList(requestList, streaming, lastFrameNumber);
+binder::Status CameraDeviceClient::submitRequest(
+        const hardware::camera2::CaptureRequest& request,
+        bool streaming,
+        /*out*/
+        hardware::camera2::utils::SubmitInfo *submitInfo) {
+    std::vector<hardware::camera2::CaptureRequest> requestList = { request };
+    return submitRequestList(requestList, streaming, submitInfo);
 }
 
-status_t CameraDeviceClient::submitRequestList(List<sp<CaptureRequest> > requests,
-                                               bool streaming, int64_t* lastFrameNumber) {
+binder::Status CameraDeviceClient::submitRequestList(
+        const std::vector<hardware::camera2::CaptureRequest>& requests,
+        bool streaming,
+        /*out*/
+        hardware::camera2::utils::SubmitInfo *submitInfo) {
     ATRACE_CALL();
     ALOGV("%s-start of function. Request list size %zu", __FUNCTION__, requests.size());
 
-    status_t res;
-    if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+    binder::Status res = binder::Status::ok();
+    status_t err;
+    if ( !(res = checkPidStatus(__FUNCTION__) ).isOk()) {
+        return res;
+    }
 
     Mutex::Autolock icl(mBinderSerializationLock);
 
-    if (!mDevice.get()) return DEAD_OBJECT;
+    if (!mDevice.get()) {
+        return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
+    }
 
     if (requests.empty()) {
         ALOGE("%s: Camera %d: Sent null request. Rejecting request.",
               __FUNCTION__, mCameraId);
-        return BAD_VALUE;
+        return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Empty request list");
     }
 
     List<const CameraMetadata> metadataRequestList;
-    int32_t requestId = mRequestIdCounter;
+    submitInfo->mRequestId = mRequestIdCounter;
     uint32_t loopCounter = 0;
 
-    for (List<sp<CaptureRequest> >::iterator it = requests.begin(); it != requests.end(); ++it) {
-        sp<CaptureRequest> request = *it;
-        if (request == 0) {
-            ALOGE("%s: Camera %d: Sent null request.",
-                    __FUNCTION__, mCameraId);
-            return BAD_VALUE;
-        } else if (request->mIsReprocess) {
+    for (auto&& request: requests) {
+        if (request.mIsReprocess) {
             if (!mInputStream.configured) {
                 ALOGE("%s: Camera %d: no input stream is configured.", __FUNCTION__, mCameraId);
-                return BAD_VALUE;
+                return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
+                        "No input configured for camera %d but request is for reprocessing",
+                        mCameraId);
             } else if (streaming) {
                 ALOGE("%s: Camera %d: streaming reprocess requests not supported.", __FUNCTION__,
                         mCameraId);
-                return BAD_VALUE;
+                return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
+                        "Repeating reprocess requests not supported");
             }
         }
 
-        CameraMetadata metadata(request->mMetadata);
+        CameraMetadata metadata(request.mMetadata);
         if (metadata.isEmpty()) {
             ALOGE("%s: Camera %d: Sent empty metadata packet. Rejecting request.",
                    __FUNCTION__, mCameraId);
-            return BAD_VALUE;
-        } else if (request->mSurfaceList.isEmpty()) {
+            return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
+                    "Request settings are empty");
+        } else if (request.mSurfaceList.isEmpty()) {
             ALOGE("%s: Camera %d: Requests must have at least one surface target. "
-                  "Rejecting request.", __FUNCTION__, mCameraId);
-            return BAD_VALUE;
+                    "Rejecting request.", __FUNCTION__, mCameraId);
+            return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
+                    "Request has no output targets");
         }
 
         if (!enforceRequestPermissions(metadata)) {
             // Callee logs
-            return PERMISSION_DENIED;
+            return STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
+                    "Caller does not have permission to change restricted controls");
         }
 
         /**
@@ -167,9 +188,8 @@
          * the capture request's list of surface targets
          */
         Vector<int32_t> outputStreamIds;
-        outputStreamIds.setCapacity(request->mSurfaceList.size());
-        for (size_t i = 0; i < request->mSurfaceList.size(); ++i) {
-            sp<Surface> surface = request->mSurfaceList[i];
+        outputStreamIds.setCapacity(request.mSurfaceList.size());
+        for (sp<Surface> surface : request.mSurfaceList) {
             if (surface == 0) continue;
 
             sp<IGraphicBufferProducer> gbp = surface->getIGraphicBufferProducer();
@@ -178,69 +198,80 @@
             // Trying to submit request with surface that wasn't created
             if (idx == NAME_NOT_FOUND) {
                 ALOGE("%s: Camera %d: Tried to submit a request with a surface that"
-                      " we have not called createStream on",
-                      __FUNCTION__, mCameraId);
-                return BAD_VALUE;
+                        " we have not called createStream on",
+                        __FUNCTION__, mCameraId);
+                return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
+                        "Request targets Surface that is not part of current capture session");
             }
 
             int streamId = mStreamMap.valueAt(idx);
             outputStreamIds.push_back(streamId);
             ALOGV("%s: Camera %d: Appending output stream %d to request",
-                  __FUNCTION__, mCameraId, streamId);
+                    __FUNCTION__, mCameraId, streamId);
         }
 
         metadata.update(ANDROID_REQUEST_OUTPUT_STREAMS, &outputStreamIds[0],
                         outputStreamIds.size());
 
-        if (request->mIsReprocess) {
+        if (request.mIsReprocess) {
             metadata.update(ANDROID_REQUEST_INPUT_STREAMS, &mInputStream.id, 1);
         }
 
-        metadata.update(ANDROID_REQUEST_ID, &requestId, /*size*/1);
+        metadata.update(ANDROID_REQUEST_ID, &(submitInfo->mRequestId), /*size*/1);
         loopCounter++; // loopCounter starts from 1
         ALOGV("%s: Camera %d: Creating request with ID %d (%d of %zu)",
-              __FUNCTION__, mCameraId, requestId, loopCounter, requests.size());
+              __FUNCTION__, mCameraId, submitInfo->mRequestId, loopCounter, requests.size());
 
         metadataRequestList.push_back(metadata);
     }
     mRequestIdCounter++;
 
     if (streaming) {
-        res = mDevice->setStreamingRequestList(metadataRequestList, lastFrameNumber);
-        if (res != OK) {
-            ALOGE("%s: Camera %d:  Got error %d after trying to set streaming "
-                  "request", __FUNCTION__, mCameraId, res);
+        err = mDevice->setStreamingRequestList(metadataRequestList, &(submitInfo->mLastFrameNumber));
+        if (err != OK) {
+            String8 msg = String8::format(
+                "Camera %d:  Got error %s (%d) after trying to set streaming request",
+                mCameraId, strerror(-err), err);
+            ALOGE("%s: %s", __FUNCTION__, msg.string());
+            res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
+                    msg.string());
         } else {
-            mStreamingRequestList.push_back(requestId);
+            mStreamingRequestList.push_back(submitInfo->mRequestId);
         }
     } else {
-        res = mDevice->captureList(metadataRequestList, lastFrameNumber);
-        if (res != OK) {
-            ALOGE("%s: Camera %d: Got error %d after trying to set capture",
-                __FUNCTION__, mCameraId, res);
+        err = mDevice->captureList(metadataRequestList, &(submitInfo->mLastFrameNumber));
+        if (err != OK) {
+            String8 msg = String8::format(
+                "Camera %d: Got error %s (%d) after trying to submit capture request",
+                mCameraId, strerror(-err), err);
+            ALOGE("%s: %s", __FUNCTION__, msg.string());
+            res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
+                    msg.string());
         }
-        ALOGV("%s: requestId = %d ", __FUNCTION__, requestId);
+        ALOGV("%s: requestId = %d ", __FUNCTION__, submitInfo->mRequestId);
     }
 
     ALOGV("%s: Camera %d: End of function", __FUNCTION__, mCameraId);
-    if (res == OK) {
-        return requestId;
-    }
-
     return res;
 }
 
-status_t CameraDeviceClient::cancelRequest(int requestId, int64_t* lastFrameNumber) {
+binder::Status CameraDeviceClient::cancelRequest(
+        int requestId,
+        /*out*/
+        int64_t* lastFrameNumber) {
     ATRACE_CALL();
     ALOGV("%s, requestId = %d", __FUNCTION__, requestId);
 
-    status_t res;
+    status_t err;
+    binder::Status res;
 
-    if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+    if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
 
     Mutex::Autolock icl(mBinderSerializationLock);
 
-    if (!mDevice.get()) return DEAD_OBJECT;
+    if (!mDevice.get()) {
+        return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
+    }
 
     Vector<int>::iterator it, end;
     for (it = mStreamingRequestList.begin(), end = mStreamingRequestList.end();
@@ -251,29 +282,34 @@
     }
 
     if (it == end) {
-        ALOGE("%s: Camera%d: Did not find request id %d in list of streaming "
-              "requests", __FUNCTION__, mCameraId, requestId);
-        return BAD_VALUE;
+        String8 msg = String8::format("Camera %d: Did not find request ID %d in list of "
+                "streaming requests", mCameraId, requestId);
+        ALOGE("%s: %s", __FUNCTION__, msg.string());
+        return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
     }
 
-    res = mDevice->clearStreamingRequest(lastFrameNumber);
+    err = mDevice->clearStreamingRequest(lastFrameNumber);
 
-    if (res == OK) {
+    if (err == OK) {
         ALOGV("%s: Camera %d: Successfully cleared streaming request",
               __FUNCTION__, mCameraId);
         mStreamingRequestList.erase(it);
+    } else {
+        res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
+                "Camera %d: Error clearing streaming request: %s (%d)",
+                mCameraId, strerror(-err), err);
     }
 
     return res;
 }
 
-status_t CameraDeviceClient::beginConfigure() {
+binder::Status CameraDeviceClient::beginConfigure() {
     // TODO: Implement this.
     ALOGV("%s: Not implemented yet.", __FUNCTION__);
-    return OK;
+    return binder::Status::ok();
 }
 
-status_t CameraDeviceClient::endConfigure(bool isConstrainedHighSpeed) {
+binder::Status CameraDeviceClient::endConfigure(bool isConstrainedHighSpeed) {
     ALOGV("%s: ending configure (%d input stream, %zu output streams)",
             __FUNCTION__, mInputStream.configured ? 1 : 0, mStreamMap.size());
 
@@ -290,33 +326,46 @@
             }
         }
         if (!isConstrainedHighSpeedSupported) {
-            ALOGE("%s: Camera %d: Try to create a constrained high speed configuration on a device"
-                    " that doesn't support it.",
-                          __FUNCTION__, mCameraId);
-            return INVALID_OPERATION;
+            String8 msg = String8::format(
+                "Camera %d: Try to create a constrained high speed configuration on a device"
+                " that doesn't support it.", mCameraId);
+            ALOGE("%s: %s", __FUNCTION__, msg.string());
+            return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
+                    msg.string());
         }
     }
 
-    status_t res;
-    if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+    binder::Status res;
+    if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
 
     Mutex::Autolock icl(mBinderSerializationLock);
 
-    if (!mDevice.get()) return DEAD_OBJECT;
+    if (!mDevice.get()) {
+        return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
+    }
 
-    return mDevice->configureStreams(isConstrainedHighSpeed);
+    status_t err = mDevice->configureStreams(isConstrainedHighSpeed);
+    if (err != OK) {
+        res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
+                "Camera %d: Error configuring streams: %s (%d)",
+                mCameraId, strerror(-err), err);
+    }
+
+    return res;
 }
 
-status_t CameraDeviceClient::deleteStream(int streamId) {
+binder::Status CameraDeviceClient::deleteStream(int streamId) {
     ATRACE_CALL();
     ALOGV("%s (streamId = 0x%x)", __FUNCTION__, streamId);
 
-    status_t res;
-    if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+    binder::Status res;
+    if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
 
     Mutex::Autolock icl(mBinderSerializationLock);
 
-    if (!mDevice.get()) return DEAD_OBJECT;
+    if (!mDevice.get()) {
+        return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
+    }
 
     bool isInput = false;
     ssize_t index = NAME_NOT_FOUND;
@@ -333,20 +382,22 @@
         }
 
         if (index == NAME_NOT_FOUND) {
-            ALOGW("%s: Camera %d: Invalid stream ID (%d) specified, no stream "
-                  "created yet", __FUNCTION__, mCameraId, streamId);
-            return BAD_VALUE;
+            String8 msg = String8::format("Camera %d: Invalid stream ID (%d) specified, no such "
+                    "stream created yet", mCameraId, streamId);
+            ALOGW("%s: %s", __FUNCTION__, msg.string());
+            return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
         }
     }
 
     // Also returns BAD_VALUE if stream ID was not valid
-    res = mDevice->deleteStream(streamId);
+    status_t err = mDevice->deleteStream(streamId);
 
-    if (res == BAD_VALUE) {
-        ALOGE("%s: Camera %d: Unexpected BAD_VALUE when deleting stream, but we"
-              " already checked and the stream ID (%d) should be valid.",
-              __FUNCTION__, mCameraId, streamId);
-    } else if (res == OK) {
+    if (err != OK) {
+        String8 msg = String8::format("Camera %d: Unexpected error %s (%d) when deleting stream %d",
+                mCameraId, strerror(-err), err, streamId);
+        ALOGE("%s: %s", __FUNCTION__, msg.string());
+        res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
+    } else {
         if (isInput) {
             mInputStream.configured = false;
         } else {
@@ -357,44 +408,50 @@
     return res;
 }
 
-status_t CameraDeviceClient::createStream(const OutputConfiguration &outputConfiguration)
-{
+binder::Status CameraDeviceClient::createStream(
+        const hardware::camera2::params::OutputConfiguration &outputConfiguration,
+        /*out*/
+        int32_t* newStreamId) {
     ATRACE_CALL();
 
-    status_t res;
-    if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+    binder::Status res;
+    if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
 
     Mutex::Autolock icl(mBinderSerializationLock);
 
-
     sp<IGraphicBufferProducer> bufferProducer = outputConfiguration.getGraphicBufferProducer();
     if (bufferProducer == NULL) {
         ALOGE("%s: bufferProducer must not be null", __FUNCTION__);
-        return BAD_VALUE;
+        return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Target Surface is invalid");
     }
-    if (!mDevice.get()) return DEAD_OBJECT;
+    if (!mDevice.get()) {
+        return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
+    }
 
     // Don't create multiple streams for the same target surface
     {
         ssize_t index = mStreamMap.indexOfKey(IInterface::asBinder(bufferProducer));
         if (index != NAME_NOT_FOUND) {
-            ALOGW("%s: Camera %d: Buffer producer already has a stream for it "
-                  "(ID %zd)",
-                  __FUNCTION__, mCameraId, index);
-            return ALREADY_EXISTS;
+            String8 msg = String8::format("Camera %d: Surface already has a stream created for it "
+                    "(ID %zd)", mCameraId, index);
+            ALOGW("%s: %s", __FUNCTION__, msg.string());
+            return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.string());
         }
     }
 
+    status_t err;
+
     // HACK b/10949105
     // Query consumer usage bits to set async operation mode for
     // GLConsumer using controlledByApp parameter.
     bool useAsync = false;
     int32_t consumerUsage;
-    if ((res = bufferProducer->query(NATIVE_WINDOW_CONSUMER_USAGE_BITS,
+    if ((err = bufferProducer->query(NATIVE_WINDOW_CONSUMER_USAGE_BITS,
             &consumerUsage)) != OK) {
-        ALOGE("%s: Camera %d: Failed to query consumer usage", __FUNCTION__,
-              mCameraId);
-        return res;
+        String8 msg = String8::format("Camera %d: Failed to query Surface consumer usage: %s (%d)",
+                mCameraId, strerror(-err), err);
+        ALOGE("%s: %s", __FUNCTION__, msg.string());
+        return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
     }
     if (consumerUsage & GraphicBuffer::USAGE_HW_TEXTURE) {
         ALOGW("%s: Camera %d: Forcing asynchronous mode for stream",
@@ -417,26 +474,30 @@
     int width, height, format;
     android_dataspace dataSpace;
 
-    if ((res = anw->query(anw, NATIVE_WINDOW_WIDTH, &width)) != OK) {
-        ALOGE("%s: Camera %d: Failed to query Surface width", __FUNCTION__,
-              mCameraId);
-        return res;
+    if ((err = anw->query(anw, NATIVE_WINDOW_WIDTH, &width)) != OK) {
+        String8 msg = String8::format("Camera %d: Failed to query Surface width: %s (%d)",
+                mCameraId, strerror(-err), err);
+        ALOGE("%s: %s", __FUNCTION__, msg.string());
+        return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
     }
-    if ((res = anw->query(anw, NATIVE_WINDOW_HEIGHT, &height)) != OK) {
-        ALOGE("%s: Camera %d: Failed to query Surface height", __FUNCTION__,
-              mCameraId);
-        return res;
+    if ((err = anw->query(anw, NATIVE_WINDOW_HEIGHT, &height)) != OK) {
+        String8 msg = String8::format("Camera %d: Failed to query Surface height: %s (%d)",
+                mCameraId, strerror(-err), err);
+        ALOGE("%s: %s", __FUNCTION__, msg.string());
+        return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
     }
-    if ((res = anw->query(anw, NATIVE_WINDOW_FORMAT, &format)) != OK) {
-        ALOGE("%s: Camera %d: Failed to query Surface format", __FUNCTION__,
-              mCameraId);
-        return res;
+    if ((err = anw->query(anw, NATIVE_WINDOW_FORMAT, &format)) != OK) {
+        String8 msg = String8::format("Camera %d: Failed to query Surface format: %s (%d)",
+                mCameraId, strerror(-err), err);
+        ALOGE("%s: %s", __FUNCTION__, msg.string());
+        return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
     }
-    if ((res = anw->query(anw, NATIVE_WINDOW_DEFAULT_DATASPACE,
+    if ((err = anw->query(anw, NATIVE_WINDOW_DEFAULT_DATASPACE,
                             reinterpret_cast<int*>(&dataSpace))) != OK) {
-        ALOGE("%s: Camera %d: Failed to query Surface dataSpace", __FUNCTION__,
-              mCameraId);
-        return res;
+        String8 msg = String8::format("Camera %d: Failed to query Surface dataspace: %s (%d)",
+                mCameraId, strerror(-err), err);
+        ALOGE("%s: %s", __FUNCTION__, msg.string());
+        return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
     }
 
     // FIXME: remove this override since the default format should be
@@ -451,18 +512,22 @@
     // Round dimensions to the nearest dimensions available for this format
     if (flexibleConsumer && !CameraDeviceClient::roundBufferDimensionNearest(width, height,
             format, dataSpace, mDevice->info(), /*out*/&width, /*out*/&height)) {
-        ALOGE("%s: No stream configurations with the format %#x defined, failed to create stream.",
-                __FUNCTION__, format);
-        return BAD_VALUE;
+        String8 msg = String8::format("Camera %d: No supported stream configurations with "
+                "format %#x defined, failed to create output stream", mCameraId, format);
+        ALOGE("%s: %s", __FUNCTION__, msg.string());
+        return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
     }
 
     int streamId = camera3::CAMERA3_STREAM_ID_INVALID;
-    res = mDevice->createStream(surface, width, height, format, dataSpace,
-                                static_cast<camera3_stream_rotation_t>
-                                        (outputConfiguration.getRotation()),
-                                &streamId, outputConfiguration.getSurfaceSetID());
+    err = mDevice->createStream(surface, width, height, format, dataSpace,
+            static_cast<camera3_stream_rotation_t>(outputConfiguration.getRotation()),
+            &streamId, outputConfiguration.getSurfaceSetID());
 
-    if (res == OK) {
+    if (err != OK) {
+        res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
+                "Camera %d: Error creating output stream (%d x %d, fmt %x, dataSpace %x): %s (%d)",
+                mCameraId, width, height, format, dataSpace, strerror(-err), err);
+    } else {
         mStreamMap.add(binder, streamId);
 
         ALOGV("%s: Camera %d: Successfully created a new stream ID %d",
@@ -473,49 +538,56 @@
          * rotate the camera stream for preview use cases.
          */
         int32_t transform = 0;
-        res = getRotationTransformLocked(&transform);
+        err = getRotationTransformLocked(&transform);
 
-        if (res != OK) {
+        if (err != OK) {
             // Error logged by getRotationTransformLocked.
-            return res;
+            return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
+                    "Unable to calculate rotation transform for new stream");
         }
 
-        res = mDevice->setStreamTransform(streamId, transform);
-        if (res != OK) {
-            ALOGE("%s: Failed to set stream transform (stream id %d)",
-                  __FUNCTION__, streamId);
-            return res;
+        err = mDevice->setStreamTransform(streamId, transform);
+        if (err != OK) {
+            String8 msg = String8::format("Failed to set stream transform (stream id %d)",
+                    streamId);
+            ALOGE("%s: %s", __FUNCTION__, msg.string());
+            return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
         }
 
-        return streamId;
+        *newStreamId = streamId;
     }
 
     return res;
 }
 
 
-status_t CameraDeviceClient::createInputStream(int width, int height,
-        int format) {
+binder::Status CameraDeviceClient::createInputStream(
+        int width, int height, int format,
+        /*out*/
+        int32_t* newStreamId) {
 
     ATRACE_CALL();
     ALOGV("%s (w = %d, h = %d, f = 0x%x)", __FUNCTION__, width, height, format);
 
-    status_t res;
-    if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+    binder::Status res;
+    if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
 
     Mutex::Autolock icl(mBinderSerializationLock);
-    if (!mDevice.get()) return DEAD_OBJECT;
+
+    if (!mDevice.get()) {
+        return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
+    }
 
     if (mInputStream.configured) {
-        ALOGE("%s: Camera %d: Already has an input stream "
-                " configuration. (ID %zd)", __FUNCTION__, mCameraId,
-                mInputStream.id);
-        return ALREADY_EXISTS;
+        String8 msg = String8::format("Camera %d: Already has an input stream "
+                "configured (ID %zd)", mCameraId, mInputStream.id);
+        ALOGE("%s: %s", __FUNCTION__, msg.string() );
+        return STATUS_ERROR(CameraService::ERROR_ALREADY_EXISTS, msg.string());
     }
 
     int streamId = -1;
-    res = mDevice->createInputStream(width, height, format, &streamId);
-    if (res == OK) {
+    status_t err = mDevice->createInputStream(width, height, format, &streamId);
+    if (err == OK) {
         mInputStream.configured = true;
         mInputStream.width = width;
         mInputStream.height = height;
@@ -523,27 +595,42 @@
         mInputStream.id = streamId;
 
         ALOGV("%s: Camera %d: Successfully created a new input stream ID %d",
-              __FUNCTION__, mCameraId, streamId);
+                __FUNCTION__, mCameraId, streamId);
 
-        return streamId;
+        *newStreamId = streamId;
+    } else {
+        res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
+                "Camera %d: Error creating new input stream: %s (%d)", mCameraId,
+                strerror(-err), err);
     }
 
     return res;
 }
 
-status_t CameraDeviceClient::getInputBufferProducer(
-        /*out*/sp<IGraphicBufferProducer> *producer) {
-    status_t res;
-    if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+binder::Status CameraDeviceClient::getInputSurface(/*out*/ view::Surface *inputSurface) {
 
-    if (producer == NULL) {
-        return BAD_VALUE;
+    binder::Status res;
+    if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
+
+    if (inputSurface == NULL) {
+        return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Null input surface");
     }
 
     Mutex::Autolock icl(mBinderSerializationLock);
-    if (!mDevice.get()) return DEAD_OBJECT;
-
-    return mDevice->getInputBufferProducer(producer);
+    if (!mDevice.get()) {
+        return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
+    }
+    sp<IGraphicBufferProducer> producer;
+    status_t err = mDevice->getInputBufferProducer(&producer);
+    if (err != OK) {
+        res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
+                "Camera %d: Error getting input Surface: %s (%d)",
+                mCameraId, strerror(-err), err);
+    } else {
+        inputSurface->name = String16("CameraInput");
+        inputSurface->graphicBufferProducer = producer;
+    }
+    return res;
 }
 
 bool CameraDeviceClient::roundBufferDimensionNearest(int32_t width, int32_t height,
@@ -604,42 +691,52 @@
 }
 
 // Create a request object from a template.
-status_t CameraDeviceClient::createDefaultRequest(int templateId,
-                                                  /*out*/
-                                                  CameraMetadata* request)
+binder::Status CameraDeviceClient::createDefaultRequest(int templateId,
+        /*out*/
+        hardware::camera2::impl::CameraMetadataNative* request)
 {
     ATRACE_CALL();
     ALOGV("%s (templateId = 0x%x)", __FUNCTION__, templateId);
 
-    status_t res;
-    if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+    binder::Status res;
+    if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
 
     Mutex::Autolock icl(mBinderSerializationLock);
 
-    if (!mDevice.get()) return DEAD_OBJECT;
+    if (!mDevice.get()) {
+        return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
+    }
 
     CameraMetadata metadata;
-    if ( (res = mDevice->createDefaultRequest(templateId, &metadata) ) == OK &&
+    status_t err;
+    if ( (err = mDevice->createDefaultRequest(templateId, &metadata) ) == OK &&
         request != NULL) {
 
         request->swap(metadata);
+    } else {
+        res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
+                "Camera %d: Error creating default request for template %d: %s (%d)",
+                mCameraId, templateId, strerror(-err), err);
     }
-
     return res;
 }
 
-status_t CameraDeviceClient::getCameraInfo(/*out*/CameraMetadata* info)
+binder::Status CameraDeviceClient::getCameraInfo(
+        /*out*/
+        hardware::camera2::impl::CameraMetadataNative* info)
 {
     ATRACE_CALL();
     ALOGV("%s", __FUNCTION__);
 
-    status_t res = OK;
+    binder::Status res;
 
-    if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+    if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
 
     Mutex::Autolock icl(mBinderSerializationLock);
 
-    if (!mDevice.get()) return DEAD_OBJECT;
+    if (!mDevice.get()) {
+        return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
+    }
 
     if (info != NULL) {
         *info = mDevice->info(); // static camera metadata
@@ -649,51 +746,68 @@
     return res;
 }
 
-status_t CameraDeviceClient::waitUntilIdle()
+binder::Status CameraDeviceClient::waitUntilIdle()
 {
     ATRACE_CALL();
     ALOGV("%s", __FUNCTION__);
 
-    status_t res = OK;
-    if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+    binder::Status res;
+    if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
 
     Mutex::Autolock icl(mBinderSerializationLock);
 
-    if (!mDevice.get()) return DEAD_OBJECT;
+    if (!mDevice.get()) {
+        return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
+    }
 
     // FIXME: Also need check repeating burst.
     if (!mStreamingRequestList.isEmpty()) {
-        ALOGE("%s: Camera %d: Try to waitUntilIdle when there are active streaming requests",
-              __FUNCTION__, mCameraId);
-        return INVALID_OPERATION;
+        String8 msg = String8::format(
+            "Camera %d: Try to waitUntilIdle when there are active streaming requests",
+            mCameraId);
+        ALOGE("%s: %s", __FUNCTION__, msg.string());
+        return STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
     }
-    res = mDevice->waitUntilDrained();
+    status_t err = mDevice->waitUntilDrained();
+    if (err != OK) {
+        res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
+                "Camera %d: Error waiting to drain: %s (%d)",
+                mCameraId, strerror(-err), err);
+    }
     ALOGV("%s Done", __FUNCTION__);
-
     return res;
 }
 
-status_t CameraDeviceClient::flush(int64_t* lastFrameNumber) {
+binder::Status CameraDeviceClient::flush(
+        /*out*/
+        int64_t* lastFrameNumber) {
     ATRACE_CALL();
     ALOGV("%s", __FUNCTION__);
 
-    status_t res = OK;
-    if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+    binder::Status res;
+    if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
 
     Mutex::Autolock icl(mBinderSerializationLock);
 
-    if (!mDevice.get()) return DEAD_OBJECT;
+    if (!mDevice.get()) {
+        return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
+    }
 
     mStreamingRequestList.clear();
-    return mDevice->flush(lastFrameNumber);
+    status_t err = mDevice->flush(lastFrameNumber);
+    if (err != OK) {
+        res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
+                "Camera %d: Error flushing device: %s (%d)", mCameraId, strerror(-err), err);
+    }
+    return res;
 }
 
-status_t CameraDeviceClient::prepare(int streamId) {
+binder::Status CameraDeviceClient::prepare(int streamId) {
     ATRACE_CALL();
     ALOGV("%s", __FUNCTION__);
 
-    status_t res = OK;
-    if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+    binder::Status res;
+    if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
 
     Mutex::Autolock icl(mBinderSerializationLock);
 
@@ -707,24 +821,33 @@
     }
 
     if (index == NAME_NOT_FOUND) {
-        ALOGW("%s: Camera %d: Invalid stream ID (%d) specified, no stream "
-              "created yet", __FUNCTION__, mCameraId, streamId);
-        return BAD_VALUE;
+        String8 msg = String8::format("Camera %d: Invalid stream ID (%d) specified, no stream "
+              "with that ID exists", mCameraId, streamId);
+        ALOGW("%s: %s", __FUNCTION__, msg.string());
+        return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
     }
 
     // Also returns BAD_VALUE if stream ID was not valid, or stream already
     // has been used
-    res = mDevice->prepare(streamId);
-
+    status_t err = mDevice->prepare(streamId);
+    if (err == BAD_VALUE) {
+        res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
+                "Camera %d: Stream %d has already been used, and cannot be prepared",
+                mCameraId, streamId);
+    } else if (err != OK) {
+        res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
+                "Camera %d: Error preparing stream %d: %s (%d)", mCameraId, streamId,
+                strerror(-err), err);
+    }
     return res;
 }
 
-status_t CameraDeviceClient::prepare2(int maxCount, int streamId) {
+binder::Status CameraDeviceClient::prepare2(int maxCount, int streamId) {
     ATRACE_CALL();
     ALOGV("%s", __FUNCTION__);
 
-    status_t res = OK;
-    if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+    binder::Status res;
+    if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
 
     Mutex::Autolock icl(mBinderSerializationLock);
 
@@ -738,30 +861,41 @@
     }
 
     if (index == NAME_NOT_FOUND) {
-        ALOGW("%s: Camera %d: Invalid stream ID (%d) specified, no stream created yet",
-                __FUNCTION__, mCameraId, streamId);
-        return BAD_VALUE;
+        String8 msg = String8::format("Camera %d: Invalid stream ID (%d) specified, no stream "
+              "with that ID exists", mCameraId, streamId);
+        ALOGW("%s: %s", __FUNCTION__, msg.string());
+        return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
     }
 
     if (maxCount <= 0) {
-        ALOGE("%s: Camera %d: Invalid maxCount (%d) specified, must be greater than 0.",
-                __FUNCTION__, mCameraId, maxCount);
-        return BAD_VALUE;
+        String8 msg = String8::format("Camera %d: maxCount (%d) must be greater than 0",
+                mCameraId, maxCount);
+        ALOGE("%s: %s", __FUNCTION__, msg.string());
+        return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
     }
 
     // Also returns BAD_VALUE if stream ID was not valid, or stream already
     // has been used
-    res = mDevice->prepare(maxCount, streamId);
+    status_t err = mDevice->prepare(maxCount, streamId);
+    if (err == BAD_VALUE) {
+        res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
+                "Camera %d: Stream %d has already been used, and cannot be prepared",
+                mCameraId, streamId);
+    } else if (err != OK) {
+        res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
+                "Camera %d: Error preparing stream %d: %s (%d)", mCameraId, streamId,
+                strerror(-err), err);
+    }
 
     return res;
 }
 
-status_t CameraDeviceClient::tearDown(int streamId) {
+binder::Status CameraDeviceClient::tearDown(int streamId) {
     ATRACE_CALL();
     ALOGV("%s", __FUNCTION__);
 
-    status_t res = OK;
-    if ( (res = checkPid(__FUNCTION__) ) != OK) return res;
+    binder::Status res;
+    if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
 
     Mutex::Autolock icl(mBinderSerializationLock);
 
@@ -775,14 +909,24 @@
     }
 
     if (index == NAME_NOT_FOUND) {
-        ALOGW("%s: Camera %d: Invalid stream ID (%d) specified, no stream "
-              "created yet", __FUNCTION__, mCameraId, streamId);
-        return BAD_VALUE;
+        String8 msg = String8::format("Camera %d: Invalid stream ID (%d) specified, no stream "
+              "with that ID exists", mCameraId, streamId);
+        ALOGW("%s: %s", __FUNCTION__, msg.string());
+        return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
     }
 
     // Also returns BAD_VALUE if stream ID was not valid or if the stream is in
     // use
-    res = mDevice->tearDown(streamId);
+    status_t err = mDevice->tearDown(streamId);
+    if (err == BAD_VALUE) {
+        res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
+                "Camera %d: Stream %d is still in use, cannot be torn down",
+                mCameraId, streamId);
+    } else if (err != OK) {
+        res = STATUS_ERROR_FMT(CameraService::ERROR_INVALID_OPERATION,
+                "Camera %d: Error tearing down stream %d: %s (%d)", mCameraId, streamId,
+                strerror(-err), err);
+    }
 
     return res;
 }
@@ -822,10 +966,10 @@
     return dumpDevice(fd, args);
 }
 
-void CameraDeviceClient::notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
+void CameraDeviceClient::notifyError(int32_t errorCode,
                                      const CaptureResultExtras& resultExtras) {
     // Thread safe. Don't bother locking.
-    sp<ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
+    sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
 
     if (remoteCb != 0) {
         remoteCb->onDeviceError(errorCode, resultExtras);
@@ -834,7 +978,7 @@
 
 void CameraDeviceClient::notifyIdle() {
     // Thread safe. Don't bother locking.
-    sp<ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
+    sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
 
     if (remoteCb != 0) {
         remoteCb->onDeviceIdle();
@@ -845,7 +989,7 @@
 void CameraDeviceClient::notifyShutter(const CaptureResultExtras& resultExtras,
         nsecs_t timestamp) {
     // Thread safe. Don't bother locking.
-    sp<ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
+    sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
     if (remoteCb != 0) {
         remoteCb->onCaptureStarted(resultExtras, timestamp);
     }
@@ -854,7 +998,7 @@
 
 void CameraDeviceClient::notifyPrepared(int streamId) {
     // Thread safe. Don't bother locking.
-    sp<ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
+    sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = getRemoteCallback();
     if (remoteCb != 0) {
         remoteCb->onPrepared(streamId);
     }
@@ -893,12 +1037,19 @@
     ALOGV("%s", __FUNCTION__);
 
     // Thread-safe. No lock necessary.
-    sp<ICameraDeviceCallbacks> remoteCb = mRemoteCallback;
+    sp<hardware::camera2::ICameraDeviceCallbacks> remoteCb = mRemoteCallback;
     if (remoteCb != NULL) {
         remoteCb->onResultReceived(result.mMetadata, result.mResultExtras);
     }
 }
 
+binder::Status CameraDeviceClient::checkPidStatus(const char* checkLocation) {
+    status_t res = checkPid(checkLocation);
+    return (res == OK) ? binder::Status::ok() :
+            STATUS_ERROR(CameraService::ERROR_PERMISSION_DENIED,
+                    "Attempt to use camera from a different process than original client");
+}
+
 // TODO: move to Camera2ClientBase
 bool CameraDeviceClient::enforceRequestPermissions(CameraMetadata& metadata) {
 
diff --git a/services/camera/libcameraservice/api2/CameraDeviceClient.h b/services/camera/libcameraservice/api2/CameraDeviceClient.h
index b1d1762..38137a2 100644
--- a/services/camera/libcameraservice/api2/CameraDeviceClient.h
+++ b/services/camera/libcameraservice/api2/CameraDeviceClient.h
@@ -17,9 +17,10 @@
 #ifndef ANDROID_SERVERS_CAMERA_PHOTOGRAPHY_CAMERADEVICECLIENT_H
 #define ANDROID_SERVERS_CAMERA_PHOTOGRAPHY_CAMERADEVICECLIENT_H
 
-#include <camera/camera2/ICameraDeviceUser.h>
-#include <camera/camera2/ICameraDeviceCallbacks.h>
+#include <android/hardware/camera2/BnCameraDeviceUser.h>
+#include <android/hardware/camera2/ICameraDeviceCallbacks.h>
 #include <camera/camera2/OutputConfiguration.h>
+#include <camera/camera2/SubmitInfo.h>
 
 #include "CameraService.h"
 #include "common/FrameProcessorBase.h"
@@ -27,17 +28,19 @@
 
 namespace android {
 
-struct CameraDeviceClientBase : public CameraService::BasicClient, public BnCameraDeviceUser
+struct CameraDeviceClientBase :
+         public CameraService::BasicClient,
+         public hardware::camera2::BnCameraDeviceUser
 {
-    typedef ICameraDeviceCallbacks TCamCallbacks;
+    typedef hardware::camera2::ICameraDeviceCallbacks TCamCallbacks;
 
-    const sp<ICameraDeviceCallbacks>& getRemoteCallback() {
+    const sp<hardware::camera2::ICameraDeviceCallbacks>& getRemoteCallback() {
         return mRemoteCallback;
     }
 
 protected:
     CameraDeviceClientBase(const sp<CameraService>& cameraService,
-            const sp<ICameraDeviceCallbacks>& remoteCallback,
+            const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback,
             const String16& clientPackageName,
             int cameraId,
             int cameraFacing,
@@ -45,7 +48,7 @@
             uid_t clientUid,
             int servicePid);
 
-    sp<ICameraDeviceCallbacks> mRemoteCallback;
+    sp<hardware::camera2::ICameraDeviceCallbacks> mRemoteCallback;
 };
 
 /**
@@ -63,66 +66,77 @@
      */
 
     // Note that the callee gets a copy of the metadata.
-    virtual status_t           submitRequest(sp<CaptureRequest> request,
-                                             bool streaming = false,
-                                             /*out*/
-                                             int64_t* lastFrameNumber = NULL);
+    virtual binder::Status submitRequest(
+            const hardware::camera2::CaptureRequest& request,
+            bool streaming = false,
+            /*out*/
+            hardware::camera2::utils::SubmitInfo *submitInfo = nullptr);
     // List of requests are copied.
-    virtual status_t           submitRequestList(List<sp<CaptureRequest> > requests,
-                                                 bool streaming = false,
-                                                 /*out*/
-                                                 int64_t* lastFrameNumber = NULL);
-    virtual status_t      cancelRequest(int requestId,
-                                        /*out*/
-                                        int64_t* lastFrameNumber = NULL);
+    virtual binder::Status submitRequestList(
+            const std::vector<hardware::camera2::CaptureRequest>& requests,
+            bool streaming = false,
+            /*out*/
+            hardware::camera2::utils::SubmitInfo *submitInfo = nullptr);
+    virtual binder::Status cancelRequest(int requestId,
+            /*out*/
+            int64_t* lastFrameNumber = NULL);
 
-    virtual status_t beginConfigure();
+    virtual binder::Status beginConfigure();
 
-    virtual status_t endConfigure(bool isConstrainedHighSpeed = false);
+    virtual binder::Status endConfigure(bool isConstrainedHighSpeed = false);
 
     // Returns -EBUSY if device is not idle
-    virtual status_t      deleteStream(int streamId);
+    virtual binder::Status deleteStream(int streamId);
 
-    virtual status_t      createStream(const OutputConfiguration &outputConfiguration);
+    virtual binder::Status createStream(
+            const hardware::camera2::params::OutputConfiguration &outputConfiguration,
+            /*out*/
+            int32_t* newStreamId = NULL);
 
     // Create an input stream of width, height, and format.
-    virtual status_t      createInputStream(int width, int height, int format);
+    virtual binder::Status createInputStream(int width, int height, int format,
+            /*out*/
+            int32_t* newStreamId = NULL);
 
     // Get the buffer producer of the input stream
-    virtual status_t      getInputBufferProducer(
-                                /*out*/sp<IGraphicBufferProducer> *producer);
+    virtual binder::Status getInputSurface(
+            /*out*/
+            view::Surface *inputSurface);
 
     // Create a request object from a template.
-    virtual status_t      createDefaultRequest(int templateId,
-                                               /*out*/
-                                               CameraMetadata* request);
+    virtual binder::Status createDefaultRequest(int templateId,
+            /*out*/
+            hardware::camera2::impl::CameraMetadataNative* request);
 
     // Get the static metadata for the camera
     // -- Caller owns the newly allocated metadata
-    virtual status_t      getCameraInfo(/*out*/CameraMetadata* info);
+    virtual binder::Status getCameraInfo(
+            /*out*/
+            hardware::camera2::impl::CameraMetadataNative* cameraCharacteristics);
 
     // Wait until all the submitted requests have finished processing
-    virtual status_t      waitUntilIdle();
+    virtual binder::Status waitUntilIdle();
 
     // Flush all active and pending requests as fast as possible
-    virtual status_t      flush(/*out*/
-                                int64_t* lastFrameNumber = NULL);
+    virtual binder::Status flush(
+            /*out*/
+            int64_t* lastFrameNumber = NULL);
 
     // Prepare stream by preallocating its buffers
-    virtual status_t      prepare(int streamId);
+    virtual binder::Status prepare(int32_t streamId);
 
     // Tear down stream resources by freeing its unused buffers
-    virtual status_t      tearDown(int streamId);
+    virtual binder::Status tearDown(int32_t streamId);
 
     // Prepare stream by preallocating up to maxCount of its buffers
-    virtual status_t      prepare2(int maxCount, int streamId);
+    virtual binder::Status prepare2(int32_t maxCount, int32_t streamId);
 
     /**
      * Interface used by CameraService
      */
 
     CameraDeviceClient(const sp<CameraService>& cameraService,
-            const sp<ICameraDeviceCallbacks>& remoteCallback,
+            const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback,
             const String16& clientPackageName,
             int cameraId,
             int cameraFacing,
@@ -142,7 +156,7 @@
      */
 
     virtual void notifyIdle();
-    virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
+    virtual void notifyError(int32_t errorCode,
                              const CaptureResultExtras& resultExtras);
     virtual void notifyShutter(const CaptureResultExtras& resultExtras, nsecs_t timestamp);
     virtual void notifyPrepared(int streamId);
@@ -167,6 +181,7 @@
     static const int32_t FRAME_PROCESSOR_LISTENER_MAX_ID = 0x7fffffffL;
 
     /** Utility members */
+    binder::Status checkPidStatus(const char* checkLocation);
     bool enforceRequestPermissions(CameraMetadata& metadata);
 
     // Find the square of the euclidean distance between two points
diff --git a/services/camera/libcameraservice/common/Camera2ClientBase.cpp b/services/camera/libcameraservice/common/Camera2ClientBase.cpp
index 4a812b4..2cc150d 100644
--- a/services/camera/libcameraservice/common/Camera2ClientBase.cpp
+++ b/services/camera/libcameraservice/common/Camera2ClientBase.cpp
@@ -169,14 +169,15 @@
 
 
 template <typename TClientBase>
-void Camera2ClientBase<TClientBase>::disconnect() {
+binder::Status Camera2ClientBase<TClientBase>::disconnect() {
     ATRACE_CALL();
     Mutex::Autolock icl(mBinderSerializationLock);
 
+    binder::Status res = binder::Status::ok();
     // Allow both client and the media server to disconnect at all times
     int callingPid = getCallingPid();
     if (callingPid != TClientBase::mClientPid &&
-        callingPid != TClientBase::mServicePid) return;
+        callingPid != TClientBase::mServicePid) return res;
 
     ALOGV("Camera %d: Shutting down", TClientBase::mCameraId);
 
@@ -185,6 +186,8 @@
     CameraService::BasicClient::disconnect();
 
     ALOGV("Camera %d: Shut down complete complete", TClientBase::mCameraId);
+
+    return res;
 }
 
 template <typename TClientBase>
@@ -228,7 +231,7 @@
 
 template <typename TClientBase>
 void Camera2ClientBase<TClientBase>::notifyError(
-        ICameraDeviceCallbacks::CameraErrorCode errorCode,
+        int32_t errorCode,
         const CaptureResultExtras& resultExtras) {
     ALOGE("Error condition %d reported by HAL, requestId %" PRId32, errorCode,
           resultExtras.requestId);
diff --git a/services/camera/libcameraservice/common/Camera2ClientBase.h b/services/camera/libcameraservice/common/Camera2ClientBase.h
index 81bae7b..6eea2f4 100644
--- a/services/camera/libcameraservice/common/Camera2ClientBase.h
+++ b/services/camera/libcameraservice/common/Camera2ClientBase.h
@@ -38,8 +38,8 @@
     /**
      * Base binder interface (see ICamera/ICameraDeviceUser for details)
      */
-    virtual status_t      connect(const sp<TCamCallbacks>& callbacks);
-    virtual void          disconnect();
+    virtual status_t       connect(const sp<TCamCallbacks>& callbacks);
+    virtual binder::Status disconnect();
 
     /**
      * Interface used by CameraService
@@ -63,7 +63,7 @@
      * CameraDeviceBase::NotificationListener implementation
      */
 
-    virtual void          notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
+    virtual void          notifyError(int32_t errorCode,
                                       const CaptureResultExtras& resultExtras);
     virtual void          notifyIdle();
     virtual void          notifyShutter(const CaptureResultExtras& resultExtras,
diff --git a/services/camera/libcameraservice/common/CameraDeviceBase.h b/services/camera/libcameraservice/common/CameraDeviceBase.h
index 6fd2b39..ccb3bc8 100644
--- a/services/camera/libcameraservice/common/CameraDeviceBase.h
+++ b/services/camera/libcameraservice/common/CameraDeviceBase.h
@@ -24,7 +24,6 @@
 #include <utils/Timers.h>
 #include <utils/List.h>
 
-#include <camera/camera2/ICameraDeviceCallbacks.h>
 #include "hardware/camera2.h"
 #include "hardware/camera3.h"
 #include "camera/CameraMetadata.h"
@@ -32,6 +31,7 @@
 #include "common/CameraModule.h"
 #include "gui/IGraphicBufferProducer.h"
 #include "device3/Camera3StreamInterface.h"
+#include "binder/Status.h"
 
 namespace android {
 
@@ -195,7 +195,7 @@
         // API1 and API2.
 
         // Required for API 1 and 2
-        virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
+        virtual void notifyError(int32_t errorCode,
                                  const CaptureResultExtras &resultExtras) = 0;
 
         // Required only for API2
diff --git a/services/camera/libcameraservice/device1/CameraHardwareInterface.h b/services/camera/libcameraservice/device1/CameraHardwareInterface.h
index 0fe76e5..bce0762 100644
--- a/services/camera/libcameraservice/device1/CameraHardwareInterface.h
+++ b/services/camera/libcameraservice/device1/CameraHardwareInterface.h
@@ -102,7 +102,9 @@
         ALOGI("Opening camera %s", mName.string());
         camera_info info;
         status_t res = module->getCameraInfo(atoi(mName.string()), &info);
-        if (res != OK) return res;
+        if (res != OK) {
+            return res;
+        }
 
         int rc = OK;
         if (module->getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_3 &&
diff --git a/services/camera/libcameraservice/device3/Camera3Device.cpp b/services/camera/libcameraservice/device3/Camera3Device.cpp
index 5f990a9..0de956b 100644
--- a/services/camera/libcameraservice/device3/Camera3Device.cpp
+++ b/services/camera/libcameraservice/device3/Camera3Device.cpp
@@ -43,6 +43,8 @@
 #include <utils/Trace.h>
 #include <utils/Timers.h>
 
+#include <android/hardware/camera2/ICameraDeviceUser.h>
+
 #include "utils/CameraTraces.h"
 #include "mediautils/SchedulingPolicyService.h"
 #include "device3/Camera3Device.h"
@@ -132,8 +134,7 @@
     }
 
     camera_info info;
-    res = CameraService::filterGetInfoErrorCode(module->getCameraInfo(
-        mId, &info));
+    res = module->getCameraInfo(mId, &info);
     if (res != OK) return res;
 
     if (info.device_version != device->common.version) {
@@ -453,7 +454,7 @@
     return maxBytesForPointCloud;
 }
 
-ssize_t Camera3Device::getRawOpaqueBufferSize(uint32_t width, uint32_t height) const {
+ssize_t Camera3Device::getRawOpaqueBufferSize(int32_t width, int32_t height) const {
     const int PER_CONFIGURATION_SIZE = 3;
     const int WIDTH_OFFSET = 0;
     const int HEIGHT_OFFSET = 1;
@@ -2021,7 +2022,7 @@
 
     // Notify upstream about a device error
     if (mListener != NULL) {
-        mListener->notifyError(ICameraDeviceCallbacks::ERROR_CAMERA_DEVICE,
+        mListener->notifyError(hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_DEVICE,
                 CaptureResultExtras());
     }
 
@@ -2587,25 +2588,24 @@
 
     // Map camera HAL error codes to ICameraDeviceCallback error codes
     // Index into this with the HAL error code
-    static const ICameraDeviceCallbacks::CameraErrorCode
-            halErrorMap[CAMERA3_MSG_NUM_ERRORS] = {
+    static const int32_t halErrorMap[CAMERA3_MSG_NUM_ERRORS] = {
         // 0 = Unused error code
-        ICameraDeviceCallbacks::ERROR_CAMERA_INVALID_ERROR,
+        hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_INVALID_ERROR,
         // 1 = CAMERA3_MSG_ERROR_DEVICE
-        ICameraDeviceCallbacks::ERROR_CAMERA_DEVICE,
+        hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_DEVICE,
         // 2 = CAMERA3_MSG_ERROR_REQUEST
-        ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST,
+        hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST,
         // 3 = CAMERA3_MSG_ERROR_RESULT
-        ICameraDeviceCallbacks::ERROR_CAMERA_RESULT,
+        hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_RESULT,
         // 4 = CAMERA3_MSG_ERROR_BUFFER
-        ICameraDeviceCallbacks::ERROR_CAMERA_BUFFER
+        hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_BUFFER
     };
 
-    ICameraDeviceCallbacks::CameraErrorCode errorCode =
+    int32_t errorCode =
             ((msg.error_code >= 0) &&
                     (msg.error_code < CAMERA3_MSG_NUM_ERRORS)) ?
             halErrorMap[msg.error_code] :
-            ICameraDeviceCallbacks::ERROR_CAMERA_INVALID_ERROR;
+            hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_INVALID_ERROR;
 
     int streamId = 0;
     if (msg.error_stream != NULL) {
@@ -2619,13 +2619,13 @@
 
     CaptureResultExtras resultExtras;
     switch (errorCode) {
-        case ICameraDeviceCallbacks::ERROR_CAMERA_DEVICE:
+        case hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_DEVICE:
             // SET_ERR calls notifyError
             SET_ERR("Camera HAL reported serious device error");
             break;
-        case ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST:
-        case ICameraDeviceCallbacks::ERROR_CAMERA_RESULT:
-        case ICameraDeviceCallbacks::ERROR_CAMERA_BUFFER:
+        case hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST:
+        case hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_RESULT:
+        case hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_BUFFER:
             {
                 Mutex::Autolock l(mInFlightLock);
                 ssize_t idx = mInFlightMap.indexOfKey(msg.frame_number);
@@ -2749,7 +2749,8 @@
         mLatestRequestId(NAME_NOT_FOUND),
         mCurrentAfTriggerId(0),
         mCurrentPreCaptureTriggerId(0),
-        mRepeatingLastFrameNumber(NO_IN_FLIGHT_REPEATING_FRAMES),
+        mRepeatingLastFrameNumber(
+            hardware::camera2::ICameraDeviceUser::NO_IN_FLIGHT_REPEATING_FRAMES),
         mAeLockAvailable(aeLockAvailable) {
     mStatusId = statusTracker->addComponent();
 }
@@ -2857,7 +2858,7 @@
 
     unpauseForNewRequests();
 
-    mRepeatingLastFrameNumber = NO_IN_FLIGHT_REPEATING_FRAMES;
+    mRepeatingLastFrameNumber = hardware::camera2::ICameraDeviceUser::NO_IN_FLIGHT_REPEATING_FRAMES;
     return OK;
 }
 
@@ -2878,7 +2879,7 @@
     if (lastFrameNumber != NULL) {
         *lastFrameNumber = mRepeatingLastFrameNumber;
     }
-    mRepeatingLastFrameNumber = NO_IN_FLIGHT_REPEATING_FRAMES;
+    mRepeatingLastFrameNumber = hardware::camera2::ICameraDeviceUser::NO_IN_FLIGHT_REPEATING_FRAMES;
     return OK;
 }
 
@@ -2915,7 +2916,7 @@
             // The requestId and burstId fields were set when the request was
             // submitted originally (in convertMetadataListToRequestListLocked)
             (*it)->mResultExtras.frameNumber = mFrameNumber++;
-            listener->notifyError(ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST,
+            listener->notifyError(hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST,
                     (*it)->mResultExtras);
         }
     }
@@ -2924,7 +2925,7 @@
     if (lastFrameNumber != NULL) {
         *lastFrameNumber = mRepeatingLastFrameNumber;
     }
-    mRepeatingLastFrameNumber = NO_IN_FLIGHT_REPEATING_FRAMES;
+    mRepeatingLastFrameNumber = hardware::camera2::ICameraDeviceUser::NO_IN_FLIGHT_REPEATING_FRAMES;
     return OK;
 }
 
@@ -3344,7 +3345,7 @@
             Mutex::Autolock l(mRequestLock);
             if (mListener != NULL) {
                 mListener->notifyError(
-                        ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST,
+                        hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST,
                         captureRequest->mResultExtras);
             }
         }
@@ -3484,7 +3485,7 @@
                         " %s (%d)", __FUNCTION__, strerror(-res), res);
                 if (mListener != NULL) {
                     mListener->notifyError(
-                            ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST,
+                            hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST,
                             nextRequest->mResultExtras);
                 }
                 return NULL;
diff --git a/services/camera/libcameraservice/device3/Camera3Device.h b/services/camera/libcameraservice/device3/Camera3Device.h
index 3848200..bee69ee 100644
--- a/services/camera/libcameraservice/device3/Camera3Device.h
+++ b/services/camera/libcameraservice/device3/Camera3Device.h
@@ -26,7 +26,6 @@
 #include <utils/Timers.h>
 #include <hardware/camera3.h>
 #include <camera/CaptureResult.h>
-#include <camera/camera2/ICameraDeviceUser.h>
 
 #include "common/CameraDeviceBase.h"
 #include "device3/StatusTracker.h"
@@ -153,7 +152,7 @@
 
     virtual ssize_t getJpegBufferSize(uint32_t width, uint32_t height) const;
     ssize_t getPointCloudBufferSize() const;
-    ssize_t getRawOpaqueBufferSize(uint32_t width, uint32_t height) const;
+    ssize_t getRawOpaqueBufferSize(int32_t width, int32_t height) const;
 
     // Methods called by subclasses
     void             notifyStatus(bool idle); // updates from StatusTracker