@ -135,6 +135,7 @@ sp<hardware::ICameraServiceProxy> CameraService::sCameraServiceProxy;
CameraService : : CameraService ( ) :
mEventLog ( DEFAULT_EVENT_LOG_LENGTH ) ,
mNumberOfCameras ( 0 ) ,
mNumberOfCamerasWithoutSystemCamera ( 0 ) ,
mSoundRef ( 0 ) , mInitialized ( false ) ,
mAudioRestriction ( hardware : : camera2 : : ICameraDeviceUser : : AUDIO_RESTRICTION_NONE ) {
ALOGI ( " CameraService started (pid=%d) " , getpid ( ) ) ;
@ -260,11 +261,32 @@ void CameraService::onNewProviderRegistered() {
enumerateProviders ( ) ;
}
void CameraService : : filterAPI1SystemCameraLocked (
const std : : vector < std : : string > & normalDeviceIds ) {
mNormalDeviceIdsWithoutSystemCamera . clear ( ) ;
for ( auto & deviceId : normalDeviceIds ) {
if ( getSystemCameraKind ( String8 ( deviceId . c_str ( ) ) ) = =
SystemCameraKind : : SYSTEM_ONLY_CAMERA ) {
// All system camera ids will necessarily come after public camera
// device ids as per the HAL interface contract.
break ;
}
mNormalDeviceIdsWithoutSystemCamera . push_back ( deviceId ) ;
}
ALOGV ( " %s: number of API1 compatible public cameras is %zu " , __FUNCTION__ ,
mNormalDeviceIdsWithoutSystemCamera . size ( ) ) ;
}
void CameraService : : updateCameraNumAndIds ( ) {
Mutex : : Autolock l ( mServiceLock ) ;
mNumberOfCameras = mCameraProviderManager - > getCameraCount ( ) ;
std : : pair < int , int > systemAndNonSystemCameras = mCameraProviderManager - > getCameraCount ( ) ;
// Excludes hidden secure cameras
mNumberOfCameras =
systemAndNonSystemCameras . first + systemAndNonSystemCameras . second ;
mNumberOfCamerasWithoutSystemCamera = systemAndNonSystemCameras . second ;
mNormalDeviceIds =
mCameraProviderManager - > getAPI1CompatibleCameraDeviceIds ( ) ;
filterAPI1SystemCameraLocked ( mNormalDeviceIds ) ;
}
void CameraService : : addStates ( const String8 id ) {
@ -446,15 +468,31 @@ void CameraService::onTorchStatusChangedLocked(const String8& cameraId,
broadcastTorchModeStatus ( cameraId , newStatus ) ;
}
static bool hasPermissionsForSystemCamera ( int callingPid , int callingUid ) {
return checkPermission ( sSystemCameraPermission , callingPid , callingUid ) & &
checkPermission ( sCameraPermission , callingPid , callingUid ) ;
}
Status CameraService : : getNumberOfCameras ( int32_t type , int32_t * numCameras ) {
ATRACE_CALL ( ) ;
Mutex : : Autolock l ( mServiceLock ) ;
bool hasSystemCameraPermissions =
hasPermissionsForSystemCamera ( CameraThreadState : : getCallingPid ( ) ,
CameraThreadState : : getCallingUid ( ) ) ;
switch ( type ) {
case CAMERA_TYPE_BACKWARD_COMPATIBLE :
* numCameras = static_cast < int > ( mNormalDeviceIds . size ( ) ) ;
if ( hasSystemCameraPermissions ) {
* numCameras = static_cast < int > ( mNormalDeviceIds . size ( ) ) ;
} else {
* numCameras = static_cast < int > ( mNormalDeviceIdsWithoutSystemCamera . size ( ) ) ;
}
break ;
case CAMERA_TYPE_ALL :
* numCameras = mNumberOfCameras ;
if ( hasSystemCameraPermissions ) {
* numCameras = mNumberOfCameras ;
} else {
* numCameras = mNumberOfCamerasWithoutSystemCamera ;
}
break ;
default :
ALOGW ( " %s: Unknown camera type %d " ,
@ -469,20 +507,31 @@ Status CameraService::getCameraInfo(int cameraId,
CameraInfo * cameraInfo ) {
ATRACE_CALL ( ) ;
Mutex : : Autolock l ( mServiceLock ) ;
std : : string cameraIdStr = cameraIdIntToStrLocked ( cameraId ) ;
if ( shouldRejectSystemCameraConnection ( String8 ( cameraIdStr . c_str ( ) ) ) ) {
return STATUS_ERROR_FMT ( ERROR_INVALID_OPERATION , " Unable to retrieve camera "
" characteristics for system only device %s: " , cameraIdStr . c_str ( ) ) ;
}
if ( ! mInitialized ) {
return STATUS_ERROR ( ERROR_DISCONNECTED ,
" Camera subsystem is not available " ) ;
}
if ( cameraId < 0 | | cameraId > = mNumberOfCameras ) {
bool hasSystemCameraPermissions =
hasPermissionsForSystemCamera ( CameraThreadState : : getCallingPid ( ) ,
CameraThreadState : : getCallingUid ( ) ) ;
int cameraIdBound = mNumberOfCamerasWithoutSystemCamera ;
if ( hasSystemCameraPermissions ) {
cameraIdBound = mNumberOfCameras ;
}
if ( cameraId < 0 | | cameraId > = cameraIdBound ) {
return STATUS_ERROR ( ERROR_ILLEGAL_ARGUMENT ,
" CameraId is not valid " ) ;
}
Status ret = Status : : ok ( ) ;
status_t err = mCameraProviderManager - > getCameraInfo (
cameraId IntToStrLocked( cameraId ) , cameraInfo ) ;
cameraId Str. c_str ( ) , cameraInfo ) ;
if ( err ! = OK ) {
ret = STATUS_ERROR_FMT ( ERROR_INVALID_OPERATION ,
" Error retrieving camera info from device %d: %s (%d) " , cameraId ,
@ -493,13 +542,20 @@ Status CameraService::getCameraInfo(int cameraId,
}
std : : string CameraService : : cameraIdIntToStrLocked ( int cameraIdInt ) {
if ( cameraIdInt < 0 | | cameraIdInt > = static_cast < int > ( mNormalDeviceIds . size ( ) ) ) {
const std : : vector < std : : string > * deviceIds = & mNormalDeviceIdsWithoutSystemCamera ;
auto callingPid = CameraThreadState : : getCallingPid ( ) ;
auto callingUid = CameraThreadState : : getCallingUid ( ) ;
if ( checkPermission ( sSystemCameraPermission , callingPid , callingUid ) | |
getpid ( ) = = callingPid ) {
deviceIds = & mNormalDeviceIds ;
}
if ( cameraIdInt < 0 | | cameraIdInt > = static_cast < int > ( deviceIds - > size ( ) ) ) {
ALOGE ( " %s: input id %d invalid: valid range (0, %zu) " ,
__FUNCTION__ , cameraIdInt , mNormalDeviceIds . size ( ) ) ;
__FUNCTION__ , cameraIdInt , deviceIds- > size ( ) ) ;
return std : : string { } ;
}
return mNormalDeviceIds [ cameraIdInt ] ;
return ( * deviceIds ) [ cameraIdInt ] ;
}
String8 CameraService : : cameraIdIntToStr ( int cameraIdInt ) {
@ -1348,11 +1404,6 @@ Status CameraService::connectLegacy(
return ret ;
}
static bool hasPermissionsForSystemCamera ( int callingPid , int callingUid ) {
return checkPermission ( sSystemCameraPermission , callingPid , callingUid ) & &
checkPermission ( sCameraPermission , callingPid , callingUid ) ;
}
bool CameraService : : shouldSkipStatusUpdates ( const String8 & cameraId , bool isVendorListener ,
int clientPid , int clientUid ) const {
SystemCameraKind systemCameraKind = getSystemCameraKind ( cameraId ) ;
@ -3151,6 +3202,8 @@ status_t CameraService::dump(int fd, const Vector<String16>& args) {
dprintf ( fd , " \n == Service global info: == \n \n " ) ;
dprintf ( fd , " Number of camera devices: %d \n " , mNumberOfCameras ) ;
dprintf ( fd , " Number of normal camera devices: %zu \n " , mNormalDeviceIds . size ( ) ) ;
dprintf ( fd , " Number of public camera devices visible to API1: %zu \n " ,
mNormalDeviceIdsWithoutSystemCamera . size ( ) ) ;
for ( size_t i = 0 ; i < mNormalDeviceIds . size ( ) ; i + + ) {
dprintf ( fd , " Device %zu maps to \" %s \" \n " , i , mNormalDeviceIds [ i ] . c_str ( ) ) ;
}