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

Commit 35707086 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "cameraservice: cache IPermissionChecker and IPermissionController" into 24D1-dev

parents 28053ab7 71a5eb28
Loading
Loading
Loading
Loading
+8 −9
Original line number Diff line number Diff line
@@ -795,10 +795,10 @@ bool CameraService::checkPermission(const std::string& cameraId, const std::stri
        return isAutomotiveExteriorSystemCamera(cameraId);
    }

    permission::PermissionChecker permissionChecker;
    return permissionChecker.checkPermissionForPreflight(toString16(permission), attributionSource,
            toString16(message), attributedOpCode)
            != permission::PermissionChecker::PERMISSION_HARD_DENIED;

    return mPermissionChecker->checkPermissionForPreflight(
            toString16(permission), attributionSource, toString16(message),
            attributedOpCode) != permission::PermissionChecker::PERMISSION_HARD_DENIED;
}

bool CameraService::hasPermissionsForSystemCamera(const std::string& cameraId, int callingPid,
@@ -2432,16 +2432,15 @@ bool CameraService::isCameraPrivacyEnabled(const String16& packageName, const st
std::string CameraService::getPackageNameFromUid(int clientUid) {
    std::string packageName("");

    sp<IServiceManager> sm = defaultServiceManager();
    sp<IBinder> binder = sm->getService(toString16(kPermissionServiceName));
    if (binder == 0) {
        ALOGE("Cannot get permission service");
    sp<IPermissionController> permCtrl;
    permCtrl = getPermissionController();

    if (permCtrl == nullptr) {
        // Return empty package name and the further interaction
        // with camera will likely fail
        return packageName;
    }

    sp<IPermissionController> permCtrl = interface_cast<IPermissionController>(binder);
    Vector<String16> packages;

    permCtrl->getPackagesForUid(clientUid, packages);
+26 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include <android/hardware/CameraIdRemapping.h>
#include <android/hardware/camera2/BnCameraInjectionSession.h>
#include <android/hardware/camera2/ICameraInjectionCallback.h>
#include <android/permission/PermissionChecker.h>

#include <cutils/multiuser.h>
#include <utils/Vector.h>
@@ -34,6 +35,7 @@
#include <binder/IServiceManager.h>
#include <binder/IActivityManager.h>
#include <binder/IAppOpsCallback.h>
#include <binder/IPermissionController.h>
#include <binder/IUidObserver.h>
#include <hardware/camera.h>
#include <sensorprivacy/SensorPrivacyManager.h>
@@ -666,6 +668,25 @@ private:
        return activityManager;
    }

    static const sp<IPermissionController>& getPermissionController() {
        static const char* kPermissionControllerService = "permission";
        static thread_local sp<IPermissionController> sPermissionController = nullptr;

        if (sPermissionController == nullptr ||
                !IInterface::asBinder(sPermissionController)->isBinderAlive()) {
            sp<IServiceManager> sm = defaultServiceManager();
            sp<IBinder> binder = sm->checkService(toString16(kPermissionControllerService));
            if (binder == nullptr) {
                ALOGE("%s: Could not get permission service", __FUNCTION__);
                sPermissionController = nullptr;
            } else {
                sPermissionController = interface_cast<IPermissionController>(binder);
            }
        }

        return sPermissionController;
    }

    /**
     * Pre-grants the permission if the attribution source uid is for an automotive
     * privileged client. Otherwise uses system service permission checker to check
@@ -1550,6 +1571,10 @@ private:
    // Current zoom override value
    int32_t mZoomOverrideValue = -1;

    // Utility instance over IPermissionChecker.
    std::unique_ptr<permission::PermissionChecker> mPermissionChecker =
            std::make_unique<permission::PermissionChecker>();

    /**
     * A listener class that implements the IBinder::DeathRecipient interface
     * for use to call back the error state injected by the external camera, and