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

Commit 2823ce0c authored by Ruben Brunk's avatar Ruben Brunk
Browse files

camera: Add AIDL interface for CameraServiceProxy.

- Adds an AIDL interface to allow the proxy camera service
  running in system server to accept RPCs from the camera
  service running in mediaserver.
- Request an update to the valid user set from the proxy
  camera service when mediaserver restarts to initialize
  properly + avoid DOS after a crash.

Bug: 21267484

Change-Id: Ib821582794ddd1e3574b5dc6c79f7cb197b57f10
parent 6267b539
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ LOCAL_SRC_FILES:= \
	ICameraClient.cpp \
	ICameraService.cpp \
	ICameraServiceListener.cpp \
	ICameraServiceProxy.cpp \
	ICameraRecordingProxy.cpp \
	ICameraRecordingProxyListener.cpp \
	camera2/ICameraDeviceUser.cpp \
+55 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define LOG_TAG "BpCameraServiceProxy"

#include <stdint.h>

#include <binder/Parcel.h>

#include <camera/ICameraServiceProxy.h>

namespace android {

class BpCameraServiceProxy: public BpInterface<ICameraServiceProxy> {
public:
    BpCameraServiceProxy(const sp<IBinder>& impl) : BpInterface<ICameraServiceProxy>(impl) {}

    virtual void pingForUserUpdate() {
        Parcel data, reply;
        data.writeInterfaceToken(ICameraServiceProxy::getInterfaceDescriptor());
        remote()->transact(BnCameraServiceProxy::PING_FOR_USER_UPDATE, data, &reply,
                IBinder::FLAG_ONEWAY);
    }
};


IMPLEMENT_META_INTERFACE(CameraServiceProxy, "android.hardware.ICameraServiceProxy");

status_t BnCameraServiceProxy::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
        uint32_t flags) {
    switch(code) {
        case PING_FOR_USER_UPDATE: {
            CHECK_INTERFACE(ICameraServiceProxy, data, reply);
            pingForUserUpdate();
            return NO_ERROR;
        } break;
        default:
            return BBinder::onTransact(code, data, reply, flags);
    }
}
}; // namespace android
+52 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_HARDWARE_ICAMERASERVICEPROXY_H
#define ANDROID_HARDWARE_ICAMERASERVICEPROXY_H

#include <utils/RefBase.h>
#include <binder/IInterface.h>
#include <binder/Parcel.h>

namespace android {

class ICameraServiceProxy : public IInterface {
public:
    enum {
        PING_FOR_USER_UPDATE = IBinder::FIRST_CALL_TRANSACTION,
    };

    DECLARE_META_INTERFACE(CameraServiceProxy);

    virtual void pingForUserUpdate() = 0;
};

class BnCameraServiceProxy: public BnInterface<ICameraServiceProxy>
{
public:
    virtual status_t    onTransact( uint32_t code,
                                    const Parcel& data,
                                    Parcel* reply,
                                    uint32_t flags = 0);
};



}; // namespace android

#endif // ANDROID_HARDWARE_ICAMERASERVICEPROXY_H

+13 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
#include <binder/MemoryBase.h>
#include <binder/MemoryHeapBase.h>
#include <binder/ProcessInfoService.h>
#include <camera/ICameraServiceProxy.h>
#include <cutils/atomic.h>
#include <cutils/properties.h>
#include <gui/Surface.h>
@@ -224,6 +225,18 @@ void CameraService::onFirstRef()
    }

    CameraDeviceFactory::registerService(this);

    CameraService::pingCameraServiceProxy();
}

void CameraService::pingCameraServiceProxy() {
    sp<IServiceManager> sm = defaultServiceManager();
    sp<IBinder> binder = sm->getService(String16("media.camera.proxy"));
    if (binder == nullptr) {
        return;
    }
    sp<ICameraServiceProxy> proxyBinder = interface_cast<ICameraServiceProxy>(binder);
    proxyBinder->pingForUserUpdate();
}

CameraService::~CameraService() {
+2 −0
Original line number Diff line number Diff line
@@ -702,6 +702,8 @@ private:

    static String8 toString(std::set<userid_t> intSet);

    static void pingCameraServiceProxy();

};

template<class Func>