resolve merge conflicts of 6e0c00ba53 to nyc-dev-plus-aosp
Change-Id: I123a42e8cd1439177ea75a3c0aba7dca0b2f31fe
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
index 0e2969a..181c473 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;
@@ -293,9 +310,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;
}
@@ -319,7 +336,8 @@
clientToDisconnect = removeClientLocked(id);
// Notify the client of disconnection
- clientToDisconnect->notifyError(ICameraDeviceCallbacks::ERROR_CAMERA_DISCONNECTED,
+ clientToDisconnect->notifyError(
+ hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_DISCONNECTED,
CaptureResultExtras{});
}
@@ -335,27 +353,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)",
@@ -409,41 +427,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;
}
@@ -457,28 +479,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;
}
@@ -519,49 +546,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) {
/**
@@ -574,17 +606,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;
@@ -621,15 +652,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) {
@@ -653,15 +686,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() {
@@ -701,20 +740,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.
@@ -722,11 +753,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:
@@ -735,19 +768,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
@@ -756,17 +791,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) {
@@ -783,33 +820,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);
@@ -821,19 +860,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;
}
@@ -845,18 +885,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?
@@ -870,35 +911,49 @@
}
}
-status_t CameraService::validateConnectLocked(const String8& cameraId, /*inout*/int& clientUid,
- /*inout*/int& clientPid) const {
-
- int callingPid = getCallingPid();
+Status CameraService::validateConnectLocked(const String8& cameraId,
+ const String8& clientName8, /*inout*/int& clientUid, /*inout*/int& clientPid) const {
#if !defined(__BRILLO__)
- status_t allowed = validateClientPermissionsLocked(cameraId, clientUid, clientPid);
- if (allowed != OK) {
+ Status allowed = validateClientPermissionsLocked(cameraId, clientName8, clientUid, clientPid);
+ if (!allowed.isOk()) {
return allowed;
}
#endif // defined(__BRILLO__)
+ int callingPid = getCallingPid();
+
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());
}
- 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::validateClientPermissionsLocked(const String8& cameraId, int& clientUid,
- int& clientPid) const {
+Status CameraService::validateClientPermissionsLocked(const String8& cameraId,
+ const String8& clientName8, int& clientUid, int& clientPid) const {
int callingPid = getCallingPid();
int callingUid = getCallingUid();
@@ -908,7 +963,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
@@ -917,21 +976,22 @@
} 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
- // connected to camera service directly.
- clientPid = callingPid;
-
- // Check device policy for this camera
userid_t clientUserId = multiuser_get_user_id(clientUid);
// Only allow clients who are being used by the current foreground device user, unless calling
@@ -940,10 +1000,12 @@
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 OK;
+ return Status::ok();
}
status_t CameraService::checkIfDeviceIsUsable(const String8& cameraId) const {
@@ -955,7 +1017,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());
@@ -1032,11 +1094,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);
@@ -1063,6 +1120,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;
}
@@ -1135,7 +1193,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());
}
}
@@ -1187,39 +1245,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);
@@ -1232,61 +1292,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());
@@ -1296,35 +1363,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());
}
}
}
@@ -1342,12 +1421,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());
}
{
@@ -1367,34 +1459,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);
@@ -1405,7 +1499,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");
}
}
@@ -1434,17 +1528,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);
@@ -1454,7 +1548,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();
}
}
}
@@ -1462,23 +1556,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;
}
@@ -1488,10 +1582,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);
@@ -1501,40 +1595,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) {
@@ -1571,7 +1673,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());
}
}
@@ -1696,19 +1799,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]));
}
@@ -1834,7 +1937,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
@@ -1996,9 +2099,10 @@
mDestructionStarted = true;
}
-void CameraService::BasicClient::disconnect() {
+binder::Status CameraService::BasicClient::disconnect() {
+ binder::Status res = Status::ok();
if (mDisconnected) {
- return;
+ return res;
}
mDisconnected = true;
@@ -2016,6 +2120,8 @@
// client shouldn't be able to call into us anymore
mClientPid = 0;
+
+ return res;
}
status_t CameraService::BasicClient::dump(int, const Vector<String16>&) {
@@ -2097,7 +2203,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
@@ -2148,7 +2254,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();
}
}
@@ -2166,7 +2272,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;
@@ -2178,9 +2284,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 {
@@ -2209,7 +2315,7 @@
CameraService::CameraState::~CameraState() {}
-ICameraServiceListener::Status CameraService::CameraState::getStatus() const {
+int32_t CameraService::CameraState::getStatus() const {
Mutex::Autolock lock(mStatusLock);
return mStatus;
}
@@ -2571,12 +2677,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
@@ -2591,15 +2697,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;
@@ -2629,7 +2735,7 @@
status_t CameraService::getTorchStatusLocked(
const String8& cameraId,
- ICameraServiceListener::TorchStatus *status) const {
+ int32_t *status) const {
if (!status) {
return BAD_VALUE;
}
@@ -2644,12 +2750,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;