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/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;