From 89a2c5ceef75fbefca117d9df56a8047a36005fa Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Fri, 31 Jan 2020 15:02:25 -0800 Subject: [PATCH] Use libbinderthreadstateutils. Clients needing to differentiate between system/vendor used to be able to use isServingCall. However, this was expensive to implement. This alternative approach instead requires users of this API to use libbinderthreadstateutils which does a slighty different operation. Bug: 148692216 Test: atest VtsHalCameraServiceV2_0TargetTest Test: running AImageReaderVendorTest Test: try face unlock Change-Id: I5615f4e8863487d0de8dad2d0529214750897036 --- camera/include/camera/VendorTagDescriptor.h | 4 ++-- services/camera/libcameraservice/Android.bp | 4 ++++ services/camera/libcameraservice/CameraService.cpp | 13 +++++++------ .../libcameraservice/utils/CameraThreadState.cpp | 9 +++++---- .../camera/libcameraservice/utils/ClientManager.h | 4 ++-- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/camera/include/camera/VendorTagDescriptor.h b/camera/include/camera/VendorTagDescriptor.h index 6f55890149..b2fbf3a923 100644 --- a/camera/include/camera/VendorTagDescriptor.h +++ b/camera/include/camera/VendorTagDescriptor.h @@ -188,8 +188,8 @@ class VendorTagDescriptorCache : public Parcelable { sp *desc /*out*/); // Parcelable interface - status_t writeToParcel(Parcel* parcel) const override; - status_t readFromParcel(const Parcel* parcel) override; + status_t writeToParcel(android::Parcel* parcel) const override; + status_t readFromParcel(const android::Parcel* parcel) override; // Returns the number of vendor tags defined. int getTagCount(metadata_vendor_id_t id) const; diff --git a/services/camera/libcameraservice/Android.bp b/services/camera/libcameraservice/Android.bp index 98fee12634..883eb372a0 100644 --- a/services/camera/libcameraservice/Android.bp +++ b/services/camera/libcameraservice/Android.bp @@ -129,6 +129,10 @@ cc_library_shared { "android.hardware.camera.device@3.6" ], + static_libs: [ + "libbinderthreadstateutils", + ], + export_shared_lib_headers: [ "libbinder", "libcamera_client", diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp index 5358307779..515ef324d2 100644 --- a/services/camera/libcameraservice/CameraService.cpp +++ b/services/camera/libcameraservice/CameraService.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -1179,7 +1180,7 @@ Status CameraService::validateClientPermissionsLocked(const String8& cameraId, // Only allow clients who are being used by the current foreground device user, unless calling // from our own process OR the caller is using the cameraserver's HIDL interface. - if (!hardware::IPCThreadState::self()->isServingCall() && callingPid != getpid() && + if (getCurrentServingCall() != BinderCallType::HWBINDER && callingPid != getpid() && (mAllowedUsers.find(clientUserId) == mAllowedUsers.end())) { ALOGE("CameraService::connect X (PID %d) rejected (cannot connect from " "device user %d, currently allowed device users: %s)", callingPid, clientUserId, @@ -1534,7 +1535,7 @@ bool CameraService::shouldRejectSystemCameraConnection(const String8& cameraId) return false; } // (2) - if (!hardware::IPCThreadState::self()->isServingCall() && + if (getCurrentServingCall() != BinderCallType::HWBINDER && systemCameraKind == SystemCameraKind::HIDDEN_SECURE_CAMERA) { ALOGW("Rejecting access to secure hidden camera %s", cameraId.c_str()); return true; @@ -1543,7 +1544,7 @@ bool CameraService::shouldRejectSystemCameraConnection(const String8& cameraId) // getCameraCharacteristics() allows for calls to succeed (albeit after hiding some // characteristics) even if clients don't have android.permission.CAMERA. We do not want the // same behavior for system camera devices. - if (!hardware::IPCThreadState::self()->isServingCall() && + if (getCurrentServingCall() != BinderCallType::HWBINDER && systemCameraKind == SystemCameraKind::SYSTEM_ONLY_CAMERA && !hasPermissionsForSystemCamera(cPid, cUid)) { ALOGW("Rejecting access to system only camera %s, inadequete permissions", @@ -1569,7 +1570,7 @@ Status CameraService::connectDevice( sp client = nullptr; String16 clientPackageNameAdj = clientPackageName; - if (hardware::IPCThreadState::self()->isServingCall()) { + if (getCurrentServingCall() == BinderCallType::HWBINDER) { std::string vendorClient = StringPrintf("vendor.client.pid<%d>", CameraThreadState::getCallingPid()); clientPackageNameAdj = String16(vendorClient.c_str()); @@ -2778,7 +2779,7 @@ CameraService::BasicClient::BasicClient(const sp& cameraService, } mClientPackageName = packages[0]; } - if (!hardware::IPCThreadState::self()->isServingCall()) { + if (getCurrentServingCall() != BinderCallType::HWBINDER) { mAppOpsManager = std::make_unique(); } } @@ -3450,7 +3451,7 @@ CameraService::DescriptorPtr CameraService::CameraClientManager::makeClientDescr const std::set& conflictingKeys, int32_t score, int32_t ownerId, int32_t state) { - bool isVendorClient = hardware::IPCThreadState::self()->isServingCall(); + bool isVendorClient = getCurrentServingCall() == BinderCallType::HWBINDER; int32_t score_adj = isVendorClient ? kVendorClientScore : score; int32_t state_adj = isVendorClient ? kVendorClientState: state; diff --git a/services/camera/libcameraservice/utils/CameraThreadState.cpp b/services/camera/libcameraservice/utils/CameraThreadState.cpp index b9e344bc9e..2352b800cb 100644 --- a/services/camera/libcameraservice/utils/CameraThreadState.cpp +++ b/services/camera/libcameraservice/utils/CameraThreadState.cpp @@ -17,33 +17,34 @@ #include "CameraThreadState.h" #include #include +#include #include namespace android { int CameraThreadState::getCallingUid() { - if (hardware::IPCThreadState::self()->isServingCall()) { + if (getCurrentServingCall() == BinderCallType::HWBINDER) { return hardware::IPCThreadState::self()->getCallingUid(); } return IPCThreadState::self()->getCallingUid(); } int CameraThreadState::getCallingPid() { - if (hardware::IPCThreadState::self()->isServingCall()) { + if (getCurrentServingCall() == BinderCallType::HWBINDER) { return hardware::IPCThreadState::self()->getCallingPid(); } return IPCThreadState::self()->getCallingPid(); } int64_t CameraThreadState::clearCallingIdentity() { - if (hardware::IPCThreadState::self()->isServingCall()) { + if (getCurrentServingCall() == BinderCallType::HWBINDER) { return hardware::IPCThreadState::self()->clearCallingIdentity(); } return IPCThreadState::self()->clearCallingIdentity(); } void CameraThreadState::restoreCallingIdentity(int64_t token) { - if (hardware::IPCThreadState::self()->isServingCall()) { + if (getCurrentServingCall() == BinderCallType::HWBINDER) { hardware::IPCThreadState::self()->restoreCallingIdentity(token); } else { IPCThreadState::self()->restoreCallingIdentity(token); diff --git a/services/camera/libcameraservice/utils/ClientManager.h b/services/camera/libcameraservice/utils/ClientManager.h index ec6f01c040..35d25bf882 100644 --- a/services/camera/libcameraservice/utils/ClientManager.h +++ b/services/camera/libcameraservice/utils/ClientManager.h @@ -35,7 +35,7 @@ class ClientPriority { public: /** * Choosing to set mIsVendorClient through a parameter instead of calling - * hardware::IPCThreadState::self()->isServingCall() to protect against the + * getCurrentServingCall() == BinderCallType::HWBINDER to protect against the * case where the construction is offloaded to another thread which isn't a * hwbinder thread. */ @@ -237,7 +237,7 @@ void ClientDescriptor::setPriority(const ClientPriority& priority) { // We don't use the usual copy constructor here since we want to remember // whether a client is a vendor client or not. This could have been wiped // off in the incoming priority argument since an AIDL thread might have - // called hardware::IPCThreadState::self()->isServingCall() after refreshing + // called getCurrentServingCall() == BinderCallType::HWBINDER after refreshing // priorities for old clients through ProcessInfoService::getProcessStatesScoresFromPids(). mPriority.setScore(priority.getScore()); mPriority.setState(priority.getState());