注意,由于这样修改破坏了android原生的camera service规则,有可能导致某些三方apk出现异常。
1. 修改CameraService.cpp (frameworks/av/services/camera/libcameraservice/)文件
1) 在connect()方法,
Mutex::Autolock lock(mServiceLock);
sp<BasicClient> clientTmp;
if (!canConnectUnsafe(cameraId, clientPackageName,
cameraClient->asBinder(),
/*out*/clientTmp)) {
return -EBUSY;
} else if (client.get() != NULL) {
device = static_cast<Client*>(clientTmp.get());
return OK;
}
修改为:
//Mutex::Autolock lock(mServiceLock); //注释掉
sp<BasicClient> clientTmp;
if (!canConnectUnsafe(cameraId, clientPackageName,
cameraClient->asBinder(),
/*out*/clientTmp)) {
return -EBUSY;
} else if (client.get() != NULL) {
device = static_cast<Client*>(clientTmp.get());
return OK;
}
Mutex::Autolock lock(mServiceLock); //将原来的代码移动到这里
2) canConnectUnsafe()方法
将原来的:
if (mClient[cameraId] != 0) {
client = mClient[cameraId].promote();
if (client != 0) {
if (remoteCallback == client->getRemote()) {
LOG1("CameraService::connect X (pid %d) (the same client)",
callingPid);
return true;
} else {
// TODOSC: need to support 1 regular client,
// multiple shared clients here
ALOGW("CameraService::connect X (pid %d) rejected"
" (existing client).", callingPid);
return false;
}
}
mClient[cameraId].clear();
}
修改为:
if(mClient[cameraId] != 0){
LOG1("CameraService::connect mClient[cameraId] != 0 ");
client = mClient[cameraId].promote();
if (client != 0) {
LOG1("CameraService::connect X (pid %d) disconnect the old client", callingPid);
client->disconnect();
return true;
}
}
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;
}