Skip to content

Commit

Permalink
[droidmedia] Additional Android 6 definitions and uid setting. Contri…
Browse files Browse the repository at this point in the history
…butes JB#37491

Add Android6 to ifdefs in new droidmediarecorder.
Make the newest API the default to make future versions easier - reverse a few ifdefs, switch others to >= instead of ==
Implemented fake ProcessInfoService and CameraServiceProxy.
Notify CameraService of the permitted userids during minimedia startup (didn't get called in pingForUserUpdate).
  • Loading branch information
Andrew Branson committed Feb 6, 2017
1 parent b24afea commit 0a8bbdb
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 64 deletions.
1 change: 1 addition & 0 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ LOCAL_C_INCLUDES := frameworks/av/services/camera/libcameraservice \
system/media/camera/include
LOCAL_SHARED_LIBRARIES := libcameraservice \
libmediaplayerservice \
libcamera_client \
libutils \
libbinder \
libgui \
Expand Down
10 changes: 5 additions & 5 deletions allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ DroidMediaAllocator::createGraphicBuffer(uint32_t w, uint32_t h,
{
// Copied from SurfaceFlinger.cpp
android::sp<android::GraphicBuffer>
#if (ANDROID_MAJOR == 4 && ANDROID_MINOR >= 2) || ANDROID_MAJOR == 5 || ANDROID_MAJOR == 6
graphicBuffer(new android::GraphicBuffer(w, h, format,
usage));
#if (ANDROID_MAJOR == 4 && ANDROID_MINOR < 2)
graphicBuffer(new android::GraphicBuffer(w, h, format,
usage, m_size));
#else
graphicBuffer(new android::GraphicBuffer(w, h, format,
usage, m_size));
graphicBuffer(new android::GraphicBuffer(w, h, format,
usage));
#endif
android::status_t err = graphicBuffer->initCheck();

Expand Down
4 changes: 4 additions & 0 deletions droidmedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@
#include <binder/ProcessState.h>
#include <binder/IPCThreadState.h>


extern "C" {

void droid_media_init()
{



android::ProcessState::self()->startThreadPool();
}

Expand Down
12 changes: 6 additions & 6 deletions droidmediabuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
#include "droidmediabuffer.h"
#include "private.h"

#if ANDROID_MAJOR == 5 || ANDROID_MAJOR == 6
static const int staleBuffer = android::IGraphicBufferConsumer::STALE_BUFFER_SLOT;
#else
#if ANDROID_MAJOR < 5
static const int staleBuffer = android::BufferQueue::STALE_BUFFER_SLOT;
#else
static const int staleBuffer = android::IGraphicBufferConsumer::STALE_BUFFER_SLOT;
#endif

#if ANDROID_MAJOR == 6
_DroidMediaBuffer::_DroidMediaBuffer(android::BufferItem& buffer,
#else
#if ANDROID_MAJOR < 6
_DroidMediaBuffer::_DroidMediaBuffer(android::BufferQueue::BufferItem& buffer,
#else
_DroidMediaBuffer::_DroidMediaBuffer(android::BufferItem& buffer,
#endif
android::sp<DroidMediaBufferQueue> queue,
void *data,
Expand Down
6 changes: 3 additions & 3 deletions droidmediabuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
struct _DroidMediaBuffer : public ANativeWindowBuffer
{
public:
#if ANDROID_MAJOR == 6
_DroidMediaBuffer(android::BufferItem& buffer,
#else
#if ANDROID_MAJOR < 6
_DroidMediaBuffer(android::BufferQueue::BufferItem& buffer,
#else
_DroidMediaBuffer(android::BufferItem& buffer,
#endif
android::sp<DroidMediaBufferQueue> queue,
void *data,
Expand Down
7 changes: 5 additions & 2 deletions droidmediacamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,14 @@ DroidMediaCamera *droid_media_camera_connect(int camera_number)
return NULL;
}

#if (ANDROID_MAJOR == 4 && ANDROID_MINOR == 4) || ANDROID_MAJOR == 5 || ANDROID_MAJOR == 6
#if (ANDROID_MAJOR == 4 && ANDROID_MINOR < 4)
cam->m_camera = android::Camera::connect(camera_number);
#elif ANDROID_MAJOR <= 6
cam->m_camera = android::Camera::connect(camera_number, android::String16("droidmedia"),
android::Camera::USE_CALLING_UID);
#else
cam->m_camera = android::Camera::connect(camera_number);
cam->m_camera = android::Camera::connect(camera_number, android::String16("droidmedia"),
android::Camera::USE_CALLING_UID, android::Camera::USE_CALLING_PID);
#endif
if (cam->m_camera.get() == NULL) {
delete cam;
Expand Down
2 changes: 1 addition & 1 deletion droidmediacodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ DroidMediaCodecLoopReturn droid_media_codec_loop(DroidMediaCodec *codec)
}

int err = codec->m_window->queueBuffer(codec->m_window.get(), buff.get()
#if (ANDROID_MAJOR == 4 && ANDROID_MINOR >= 2) || ANDROID_MAJOR == 5 || ANDROID_MAJOR == 6
#if (ANDROID_MAJOR == 4 && ANDROID_MINOR >= 2) || ANDROID_MAJOR >= 5
, -1 /* TODO: Where do we get the fence from? */
#endif
);
Expand Down
6 changes: 3 additions & 3 deletions droidmediaconstants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ void droid_media_camera_constants_init(DroidMediaCameraConstants *c)
void droid_media_pixel_format_constants_init(DroidMediaPixelFormatConstants *c)
{
c->HAL_PIXEL_FORMAT_YV12 = HAL_PIXEL_FORMAT_YV12;
#if ANDROID_MAJOR == 6
c->HAL_PIXEL_FORMAT_RAW_SENSOR = HAL_PIXEL_FORMAT_RAW16;
#else
#if ANDROID_MAJOR < 6
c->HAL_PIXEL_FORMAT_RAW_SENSOR = HAL_PIXEL_FORMAT_RAW_SENSOR;
#else
c->HAL_PIXEL_FORMAT_RAW_SENSOR = HAL_PIXEL_FORMAT_RAW16;
#endif
c->HAL_PIXEL_FORMAT_YCrCb_420_SP = HAL_PIXEL_FORMAT_YCrCb_420_SP;
}
Expand Down
4 changes: 2 additions & 2 deletions droidmediarecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <media/stagefright/MetaData.h>
#include "droidmediarecorder.h"
#include "private.h"
#if !((ANDROID_MAJOR == 4 && ANDROID_MINOR == 4) || ANDROID_MAJOR == 5)
#if (ANDROID_MAJOR == 4 && ANDROID_MINOR < 4)
#include <gui/Surface.h>
#endif

Expand Down Expand Up @@ -110,7 +110,7 @@ DroidMediaRecorder *droid_media_recorder_create(DroidMediaCamera *camera, DroidM
recorder->m_src = android::CameraSource::CreateFromCamera(cam->remote(),
cam->getRecordingProxy(), // proxy
-1, // cameraId
#if (ANDROID_MAJOR == 4 && ANDROID_MINOR == 4) || ANDROID_MAJOR == 5
#if (ANDROID_MAJOR == 4 && ANDROID_MINOR == 4) || ANDROID_MAJOR >= 5
android::String16(), // clientName
-1, // clientUid
#endif
Expand Down
49 changes: 49 additions & 0 deletions minimedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,40 @@
#include <CameraService.h>
#include <binder/MemoryHeapBase.h>
#include <MediaPlayerService.h>
#if ANDROID_MAJOR >= 6
#include <binder/BinderService.h>
#include <camera/ICameraService.h>
#include <binder/IInterface.h>
#include <cutils/multiuser.h>
#endif

// echo "persist.camera.shutter.disable=1" >> /system/build.prop

using namespace android;

#define BINDER_SERVICE_CHECK_INTERVAL 500000


#if ANDROID_MAJOR >= 6

#include <camera/ICameraServiceProxy.h>

class FakeCameraServiceProxy : public BinderService<FakeCameraServiceProxy>,
public BnCameraServiceProxy
{
public:
static char const *getServiceName() {
return "media.camera.proxy";
}

void pingForUserUpdate() {
}

void notifyCameraState(String16 cameraId, CameraState newCameraState) {
}
};
#endif

int
main(int, char**)
{
Expand All @@ -36,6 +65,26 @@ main(int, char**)
MediaPlayerService::instantiate();
CameraService::instantiate();

#if ANDROID_MAJOR >= 6
FakeCameraServiceProxy::instantiate();
// Camera service needs to be told which users may use the camera
sp<IBinder> binder;
do {
binder = sm->getService(String16("media.camera"));
if (binder != NULL) {
break;
}
ALOGW("DroidMedia: Camera service is not yet available, waiting...");
usleep(BINDER_SERVICE_CHECK_INTERVAL);
} while (true);

sp<ICameraService> gCameraService = interface_cast<ICameraService>(binder);
ALOGD("DroidMedia: Allowing use of the camera for users root and bin");
int32_t users[2];
users[0] = 0; users[1] = 1;
gCameraService->notifySystemEvent(1, users, 2);
#endif

ProcessState::self()->startThreadPool();
IPCThreadState::self()->joinThreadPool();

Expand Down
32 changes: 28 additions & 4 deletions minisf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#include "services/services_6_0_0.h"
#endif

#if (ANDROID_MAJOR == 4 && ANDROID_MINOR == 4) || ANDROID_MAJOR == 5 || ANDROID_MAJOR == 6
#if (ANDROID_MAJOR == 4 && ANDROID_MINOR == 4) || ANDROID_MAJOR >= 5
#include <binder/AppOpsManager.h>
#include <binder/IAppOpsService.h>
class FakeAppOps : public BinderService<FakeAppOps>,
Expand Down Expand Up @@ -86,7 +86,7 @@ class FakeAppOps : public BinderService<FakeAppOps>,
return NULL;
}

#if ANDROID_MAJOR == 6
#if ANDROID_MAJOR >= 6
virtual int32_t permissionToOpCode(const String16& permission) {
return 0;
}
Expand All @@ -95,6 +95,26 @@ class FakeAppOps : public BinderService<FakeAppOps>,

#endif

#if ANDROID_MAJOR >= 6

#include <binder/IProcessInfoService.h>

class FakeProcessInfoService : public BinderService<FakeProcessInfoService>,
public BnProcessInfoService
{
public:
static char const *getServiceName() {
return "processinfo";
}

status_t getProcessStatesFromPids(size_t length, int32_t* pids, int32_t* states) {
for (int i=0; i< length; i++)
states[i] = 0;
return 0;
}
};
#endif

using namespace android;

class FakePermissionController : public BinderService<FakePermissionController>,
Expand All @@ -113,7 +133,7 @@ class FakePermissionController : public BinderService<FakePermissionController>,
return false;
}

#if ANDROID_MAJOR == 6
#if ANDROID_MAJOR >= 6
void getPackagesForUid(const uid_t uid, Vector<String16> &packages) {
}

Expand All @@ -132,10 +152,14 @@ main(int, char**)
FakePermissionController::instantiate();
MiniSurfaceFlinger::instantiate();

#if (ANDROID_MAJOR == 4 && ANDROID_MINOR == 4) || ANDROID_MAJOR == 5 || ANDROID_MAJOR == 6
#if (ANDROID_MAJOR == 4 && ANDROID_MINOR == 4) || ANDROID_MAJOR >= 5
FakeAppOps::instantiate();
#endif

#if ANDROID_MAJOR >= 6
FakeProcessInfoService::instantiate();
#endif

ProcessState::self()->startThreadPool();
IPCThreadState::self()->joinThreadPool();

Expand Down
Loading

0 comments on commit 0a8bbdb

Please sign in to comment.