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

Commit 48af7e8d authored by Eino-Ville Talvala's avatar Eino-Ville Talvala
Browse files

CameraService and Stagefright: Support AppOps

Camera:
- Signal to AppOpsService when camera usage starts and stops
- Listen to permissions revocations and act on them
- Currently just kill camera connection when permissions lost

Stagefright:
- Pass on client name, UID to camera as needed

Bug: 8181262
Change-Id: I9e33c9d05e9daa77dbb2d795045d08eb887ec8f0
parent 68e6e24c
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#define LOG_TAG "Camera"
#include <utils/Log.h>
#include <utils/threads.h>
#include <utils/String16.h>
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
#include <binder/IMemory.h>
@@ -116,14 +117,15 @@ status_t Camera::getCameraInfo(int cameraId,
    return cs->getCameraInfo(cameraId, cameraInfo);
}

sp<Camera> Camera::connect(int cameraId)
sp<Camera> Camera::connect(int cameraId, const String16& clientPackageName,
        int clientUid)
{
    ALOGV("connect");
    sp<Camera> c = new Camera();
    sp<ICameraClient> cl = c;
    const sp<ICameraService>& cs = getCameraService();
    if (cs != 0) {
        c->mCamera = cs->connect(cl, cameraId);
        c->mCamera = cs->connect(cl, cameraId, clientPackageName, clientUid);
    }
    if (c->mCamera != 0) {
        c->mCamera->asBinder()->linkToDeath(c);
+11 −3
Original line number Diff line number Diff line
@@ -56,12 +56,15 @@ public:
    }

    // connect to camera service
    virtual sp<ICamera> connect(const sp<ICameraClient>& cameraClient, int cameraId)
    virtual sp<ICamera> connect(const sp<ICameraClient>& cameraClient, int cameraId,
                                const String16 &clientPackageName, int clientUid)
    {
        Parcel data, reply;
        data.writeInterfaceToken(ICameraService::getInterfaceDescriptor());
        data.writeStrongBinder(cameraClient->asBinder());
        data.writeInt32(cameraId);
        data.writeString16(clientPackageName);
        data.writeInt32(clientUid);
        remote()->transact(BnCameraService::CONNECT, data, &reply);
        return interface_cast<ICamera>(reply.readStrongBinder());
    }
@@ -103,8 +106,13 @@ status_t BnCameraService::onTransact(
        } break;
        case CONNECT: {
            CHECK_INTERFACE(ICameraService, data, reply);
            sp<ICameraClient> cameraClient = interface_cast<ICameraClient>(data.readStrongBinder());
            sp<ICamera> camera = connect(cameraClient, data.readInt32());
            sp<ICameraClient> cameraClient =
                    interface_cast<ICameraClient>(data.readStrongBinder());
            int32_t cameraId = data.readInt32();
            const String16 clientName = data.readString16();
            int32_t clientUid = data.readInt32();
            sp<ICamera> camera = connect(cameraClient, cameraId,
                    clientName, clientUid);
            reply->writeStrongBinder(camera->asBinder());
            return NO_ERROR;
        } break;
+2 −1
Original line number Diff line number Diff line
@@ -264,7 +264,8 @@ int main(int argc, char **argv) {
#endif

#if 0
    CameraSource *source = CameraSource::Create();
    CameraSource *source = CameraSource::Create(
            String16(argv[0], strlen(argv[0])));
    source->start();

    printf("source = %p\n", source);
+9 −1
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ class ICamera;
class Surface;
class Mutex;
class String8;
class String16;

// ref-counted object for callbacks
class CameraListener: virtual public RefBase
@@ -67,12 +68,19 @@ public:
class Camera : public BnCameraClient, public IBinder::DeathRecipient
{
public:
    enum {
        USE_CALLING_UID = -1
    };

            // construct a camera client from an existing remote
    static  sp<Camera>  create(const sp<ICamera>& camera);
    static  int32_t     getNumberOfCameras();
    static  status_t    getCameraInfo(int cameraId,
                                      struct CameraInfo* cameraInfo);
    static  sp<Camera>  connect(int cameraId);
    static  sp<Camera>  connect(int cameraId,
                                const String16& clientPackageName,
                                int clientUid);

            virtual     ~Camera();
            void        init();

+15 −5
Original line number Diff line number Diff line
@@ -37,17 +37,27 @@ public:
        CONNECT_PRO
    };

    enum {
        USE_CALLING_UID = -1
    };

public:
    DECLARE_META_INTERFACE(CameraService);

    virtual int32_t         getNumberOfCameras() = 0;
    virtual status_t        getCameraInfo(int cameraId,
                                          struct CameraInfo* cameraInfo) = 0;
    /**
     * clientPackageName and clientUid are used for permissions checking.  if
     * clientUid == USE_CALLING_UID, then the calling UID is used instead. Only
     * trusted callers can set a clientUid other than USE_CALLING_UID.
     */
    virtual sp<ICamera> connect(const sp<ICameraClient>& cameraClient,
                                    int cameraId) = 0;
            int cameraId,
            const String16& clientPackageName,
            int clientUid) = 0;

    virtual sp<IProCameraUser>
                            connect(const sp<IProCameraCallbacks>& cameraCb,
    virtual sp<IProCameraUser> connect(const sp<IProCameraCallbacks>& cameraCb,
            int cameraId) = 0;
};

Loading