0
点赞
收藏
分享

微信扫一扫

android Jelly Bean版本如何将camera service修改为强占式

火热如冰 2023-03-12 阅读 59

实现强占式camera service,当某些应用(如手电筒)在后台打开camera后,当camera app open camera时可以强占被后台应用占有的camera.



1. 修改CameraService.cpp (frameworks/av/services/camera/libcameraservice/)

文件的connect()方法,将

原来的

Mutex::Autolock lock(mServiceLock);

if (mClient[cameraId] != 0) {

client = mClient[cameraId].promote();

if (client != 0) {

if (cameraClient->asBinder() == client->getCameraClient()->asBinder()) {

LOG1("CameraService::connect X (pid %d) (the same client)",

callingPid);

return client;

} else {

ALOGW("CameraService::connect X (pid %d) rejected (existing client).",

callingPid);

return NULL;

}

}

mClient[cameraId].clear();

}

修改为:



if (mClient[cameraId] != 0) {

client = mClient[cameraId].promote();

if (client != 0) {

LOG1("CameraService::connect X (pid %d) disconnect the old client", callingPid);

client->disconnect();

}

mClient[cameraId].clear();

}

Mutex::Autolock lock(mServiceLock);



2. 修改CameraClient.cpp(frameworks/av/services/camera/libcameraservice/)

文件的disconnect()方法:

将原来的:

if (callingPid != mClientPid && callingPid != mServicePid) {

ALOGW("different client - don't disconnect");

return;

}

修改为:

if (callingPid != mClientPid && callingPid != mServicePid) {

ALOGW("different client but preemptive camera service! ");

//return;

}

举报

相关推荐

0 条评论