Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 04613e1a authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Use libbinderthreadstateutils." am: 7d564738

Change-Id: I72b0f76a2207f8ec8c0c79dd36b80bbeb32791ea
parents 2308ec5e 7d564738
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -188,8 +188,8 @@ class VendorTagDescriptorCache : public Parcelable {
            sp<android::VendorTagDescriptor> *desc /*out*/);
            sp<android::VendorTagDescriptor> *desc /*out*/);


    // Parcelable interface
    // Parcelable interface
    status_t writeToParcel(Parcel* parcel) const override;
    status_t writeToParcel(android::Parcel* parcel) const override;
    status_t readFromParcel(const Parcel* parcel) override;
    status_t readFromParcel(const android::Parcel* parcel) override;


    // Returns the number of vendor tags defined.
    // Returns the number of vendor tags defined.
    int getTagCount(metadata_vendor_id_t id) const;
    int getTagCount(metadata_vendor_id_t id) const;
+4 −0
Original line number Original line Diff line number Diff line
@@ -112,6 +112,10 @@ cc_library_shared {
        "android.hardware.camera.device@3.5",
        "android.hardware.camera.device@3.5",
    ],
    ],


    static_libs: [
        "libbinderthreadstateutils",
    ],

    export_shared_lib_headers: [
    export_shared_lib_headers: [
        "libbinder",
        "libbinder",
        "libcamera_client",
        "libcamera_client",
+7 −5
Original line number Original line Diff line number Diff line
@@ -43,6 +43,7 @@
#include <binder/PermissionController.h>
#include <binder/PermissionController.h>
#include <binder/ProcessInfoService.h>
#include <binder/ProcessInfoService.h>
#include <binder/IResultReceiver.h>
#include <binder/IResultReceiver.h>
#include <binderthreadstate/CallerUtils.h>
#include <cutils/atomic.h>
#include <cutils/atomic.h>
#include <cutils/properties.h>
#include <cutils/properties.h>
#include <cutils/misc.h>
#include <cutils/misc.h>
@@ -1029,7 +1030,7 @@ Status CameraService::validateClientPermissionsLocked(const String8& cameraId,


    // Only allow clients who are being used by the current foreground device user, unless calling
    // 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.
    // 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())) {
            (mAllowedUsers.find(clientUserId) == mAllowedUsers.end())) {
        ALOGE("CameraService::connect X (PID %d) rejected (cannot connect from "
        ALOGE("CameraService::connect X (PID %d) rejected (cannot connect from "
                "device user %d, currently allowed device users: %s)", callingPid, clientUserId,
                "device user %d, currently allowed device users: %s)", callingPid, clientUserId,
@@ -1350,7 +1351,7 @@ bool CameraService::shouldRejectHiddenCameraConnection(const String8 & cameraId)
    // If the thread serving this call is not a hwbinder thread and the caller
    // If the thread serving this call is not a hwbinder thread and the caller
    // isn't the cameraserver itself, and the camera id being requested is to be
    // isn't the cameraserver itself, and the camera id being requested is to be
    // publically hidden, we should reject the connection.
    // publically hidden, we should reject the connection.
    if (!hardware::IPCThreadState::self()->isServingCall() &&
    if (getCurrentServingCall() != BinderCallType::HWBINDER &&
            CameraThreadState::getCallingPid() != getpid() &&
            CameraThreadState::getCallingPid() != getpid() &&
            isPublicallyHiddenSecureCamera(cameraId)) {
            isPublicallyHiddenSecureCamera(cameraId)) {
        return true;
        return true;
@@ -1371,7 +1372,8 @@ Status CameraService::connectDevice(
    String8 id = String8(cameraId);
    String8 id = String8(cameraId);
    sp<CameraDeviceClient> client = nullptr;
    sp<CameraDeviceClient> client = nullptr;
    String16 clientPackageNameAdj = clientPackageName;
    String16 clientPackageNameAdj = clientPackageName;
    if (hardware::IPCThreadState::self()->isServingCall()) {

    if (getCurrentServingCall() == BinderCallType::HWBINDER) {
        std::string vendorClient =
        std::string vendorClient =
                StringPrintf("vendor.client.pid<%d>", CameraThreadState::getCallingPid());
                StringPrintf("vendor.client.pid<%d>", CameraThreadState::getCallingPid());
        clientPackageNameAdj = String16(vendorClient.c_str());
        clientPackageNameAdj = String16(vendorClient.c_str());
@@ -2404,7 +2406,7 @@ CameraService::BasicClient::BasicClient(const sp<CameraService>& cameraService,
        }
        }
        mClientPackageName = packages[0];
        mClientPackageName = packages[0];
    }
    }
    if (!hardware::IPCThreadState::self()->isServingCall()) {
    if (getCurrentServingCall() != BinderCallType::HWBINDER) {
        mAppOpsManager = std::make_unique<AppOpsManager>();
        mAppOpsManager = std::make_unique<AppOpsManager>();
    }
    }
}
}
@@ -3027,7 +3029,7 @@ CameraService::DescriptorPtr CameraService::CameraClientManager::makeClientDescr
        const std::set<String8>& conflictingKeys, int32_t score, int32_t ownerId,
        const std::set<String8>& conflictingKeys, int32_t score, int32_t ownerId,
        int32_t state) {
        int32_t state) {


    bool isVendorClient = hardware::IPCThreadState::self()->isServingCall();
    bool isVendorClient = getCurrentServingCall() == BinderCallType::HWBINDER;
    int32_t score_adj = isVendorClient ? kVendorClientScore : score;
    int32_t score_adj = isVendorClient ? kVendorClientScore : score;
    int32_t state_adj = isVendorClient ? kVendorClientState: state;
    int32_t state_adj = isVendorClient ? kVendorClientState: state;


+5 −4
Original line number Original line Diff line number Diff line
@@ -17,33 +17,34 @@
#include "CameraThreadState.h"
#include "CameraThreadState.h"
#include <binder/IPCThreadState.h>
#include <binder/IPCThreadState.h>
#include <hwbinder/IPCThreadState.h>
#include <hwbinder/IPCThreadState.h>
#include <binderthreadstate/CallerUtils.h>
#include <unistd.h>
#include <unistd.h>


namespace android {
namespace android {


int CameraThreadState::getCallingUid() {
int CameraThreadState::getCallingUid() {
    if (hardware::IPCThreadState::self()->isServingCall()) {
    if (getCurrentServingCall() == BinderCallType::HWBINDER) {
        return hardware::IPCThreadState::self()->getCallingUid();
        return hardware::IPCThreadState::self()->getCallingUid();
    }
    }
    return IPCThreadState::self()->getCallingUid();
    return IPCThreadState::self()->getCallingUid();
}
}


int CameraThreadState::getCallingPid() {
int CameraThreadState::getCallingPid() {
    if (hardware::IPCThreadState::self()->isServingCall()) {
    if (getCurrentServingCall() == BinderCallType::HWBINDER) {
        return hardware::IPCThreadState::self()->getCallingPid();
        return hardware::IPCThreadState::self()->getCallingPid();
    }
    }
    return IPCThreadState::self()->getCallingPid();
    return IPCThreadState::self()->getCallingPid();
}
}


int64_t CameraThreadState::clearCallingIdentity() {
int64_t CameraThreadState::clearCallingIdentity() {
    if (hardware::IPCThreadState::self()->isServingCall()) {
    if (getCurrentServingCall() == BinderCallType::HWBINDER) {
        return hardware::IPCThreadState::self()->clearCallingIdentity();
        return hardware::IPCThreadState::self()->clearCallingIdentity();
    }
    }
    return IPCThreadState::self()->clearCallingIdentity();
    return IPCThreadState::self()->clearCallingIdentity();
}
}


void CameraThreadState::restoreCallingIdentity(int64_t token) {
void CameraThreadState::restoreCallingIdentity(int64_t token) {
    if (hardware::IPCThreadState::self()->isServingCall()) {
    if (getCurrentServingCall() == BinderCallType::HWBINDER) {
        hardware::IPCThreadState::self()->restoreCallingIdentity(token);
        hardware::IPCThreadState::self()->restoreCallingIdentity(token);
    } else {
    } else {
        IPCThreadState::self()->restoreCallingIdentity(token);
        IPCThreadState::self()->restoreCallingIdentity(token);
+2 −2
Original line number Original line Diff line number Diff line
@@ -35,7 +35,7 @@ class ClientPriority {
public:
public:
    /**
    /**
     * Choosing to set mIsVendorClient through a parameter instead of calling
     * 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
     * case where the construction is offloaded to another thread which isn't a
     * hwbinder thread.
     * hwbinder thread.
     */
     */
@@ -237,7 +237,7 @@ void ClientDescriptor<KEY, VALUE>::setPriority(const ClientPriority& priority) {
    // We don't use the usual copy constructor here since we want to remember
    // 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
    // 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
    // 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().
    // priorities for old clients through ProcessInfoService::getProcessStatesScoresFromPids().
    mPriority.setScore(priority.getScore());
    mPriority.setScore(priority.getScore());
    mPriority.setState(priority.getState());
    mPriority.setState(priority.getState());