当前位置:网站首页>Camera flashlight modification
Camera flashlight modification
2022-07-23 15:21:00 【Insect master Kuiba】
Document content : Modify native interface , Replace the native call with a node controlled way hal Layer interface .
One 、 Application settings API
Application set flashlight code , Call the system interface setTorchMode
private final CameraManager mCameraManager;
private final Context mContext;
public FlashlightControllerImpl(Context context) {
mContext = context;
mCameraManager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);
}
public void setFlashlight(String cameraId, boolean enabled) {
synchronized (this) {
try {
mCameraManager.setTorchMode(cameraId, enabled);
} catch (CameraAccessException e) {
Log.e(TAG, "Couldn't set torch mode", e);
}
}
}here CameraManager The call will go directly to libcameraservice Of CameraService.cpp in , This is different from general XXXManager Such implementation code is framework in services.jar In the module .
Two 、 The key function
CameraService.cpp Execute several important functions in
setTorchMode Operate the flash
Status CameraService::setTorchMode(const String16& cameraId, bool enabled,
const sp<IBinder>& clientBinder) {
Mutex::Autolock lock(mServiceLock);
ATRACE_CALL();
if (enabled && clientBinder == nullptr) {
ALOGE("%s: torch client binder is NULL", __FUNCTION__);
return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT,
"Torch client Binder is null");
}
String8 id = String8(cameraId.string());
//ADD Write node open flashlight code block
std::string idStr = std::string(id);
char value[PROPERTY_VALUE_MAX];
memset(value, 0, sizeof(value));
property_get("sys.torch.rw_dev", value, "0");
int32_t serviceStatus = ICameraServiceListener::TORCH_STATUS_NOT_AVAILABLE;
if (0 == strcmp(value, "1") && idStr.compare("0") == 0) {
if (enabled) {
FILE *fp = NULL;
fp = fopen("/sys/class/leds/led:torch_0/brightness", "w");
fprintf(fp, "250");
fclose(fp);
fp = fopen("/sys/class/leds/led:switch_0/brightness", "w");
fprintf(fp, "1");
fclose(fp);
serviceStatus = ICameraServiceListener::TORCH_STATUS_AVAILABLE_ON;
} else {
FILE *fp = NULL;
fp = fopen("/sys/class/leds/led:switch_0/brightness", "w");
fprintf(fp, "0");
fclose(fp);
serviceStatus = ICameraServiceListener::TORCH_STATUS_AVAILABLE_OFF;
}
// Inform the flashlight of the state change
for (auto& i : mListenerList) {
i->getListener()->onTorchStatusChanged(serviceStatus, String16{cameraId});
}
return Status::ok();
}
//ADD
... ...
// Determine whether it is set as the system camera
int uid = CameraThreadState::getCallingUid();
if (shouldRejectSystemCameraConnection(id)) {
return STATUS_ERROR_FMT(ERROR_ILLEGAL_ARGUMENT, "Unable to set torch mode"
" for system only device %s: ", id.string());
}
... ...
// Native check Whether the flash is available
StatusInternal cameraStatus = state->getStatus();
... ...
// Native operation flash places
status_t err = mFlashlight->setTorchMode(id, enabled);
... ...
return Status::ok();
}
onTorchStatusChangedLocked Flashlight status callback function
Even if the flashlight is operated in the way of writing nodes , On off camera This function will also be executed to notify the status
void CameraService::onTorchStatusChangedLocked(const String8& cameraId,
TorchModeStatus newStatus, SystemCameraKind systemCameraKind) {
ALOGI("%s: Torch status changed for cameraId=%s, mHCameraIdStr=%s, newStatus=%d",
__FUNCTION__, cameraId.string(), mHCameraIdStr.string(), newStatus);
TorchModeStatus status;
status_t res = getTorchStatusLocked(cameraId, &status);
if (res) {
ALOGE("%s: cannot get torch status of camera %s: %s (%d)",
__FUNCTION__, cameraId.string(), strerror(-res), res);
return;
}
if (status == newStatus) {
return;
}
// Add judgment , For post shooting ( There is a flash in the back ) When open , Turn off the flashlight
char value[PROPERTY_VALUE_MAX];
memset(value, 0, sizeof(value));
property_get("sys.torch.rw_dev", value, "0");
std::string idStr = std::string(cameraId);
if (0 == strcmp(value, "1") && newStatus != TorchModeStatus::AVAILABLE_ON) {
if (idStr.compare("0") == 0) {
FILE *fp = NULL;
fp = fopen("/sys/class/leds/led:switch_0/brightness", "w");
fprintf(fp, "0");
fclose(fp);
}
}
// Native Torch Callback events , Notify the application of flashlight status
res = setTorchStatusLocked(cameraId, newStatus);
... ...
broadcastTorchModeStatus(cameraId, newStatus, systemCameraKind);
}On off Camera Execute the following functions
// closeCamera Will be executed disconnect step
binder::Status CameraService::BasicClient::disconnect() {
binder::Status res = Status::ok();
if (mDisconnected) {
return res;
}
... ...
}
// openCamera Will be executed connect step
template<class CALLBACK, class CLIENT>
Status CameraService::connectHelper(const sp<CALLBACK>& cameraCb, const String8& cameraId,
int api1CameraId, int halVersion, const String16& clientPackageName,
const std::unique_ptr<String16>& clientFeatureId, int clientUid, int clientPid,
apiLevel effectiveApiLevel, bool shimUpdateOnly,
/*out*/sp<CLIENT>& device) {
binder::Status ret = binder::Status::ok();
String8 clientName8(clientPackageName);
... ...
}边栏推荐
- [turn] functional area division based on poi ()
- 用rpm -e --nodeps进行批量删除
- STL map operation
- AVX指令集加速矩阵乘法
- 【7.16】代码源 -【数组划分】【拆拆】【选数2】【最大公约数】
- PostgreSQL has no NVL solution. PostgreSQL queries all tables
- Simulation of synchronization performance of BOC modulation and demodulation based on MATLAB, output tracking curve and identification curve under different lead lag code distance
- STL deque
- Simulation of voltage source PWM rectifier with double closed loop vector control based on Simulink
- NVIDIA vid2vid paper reproduction
猜你喜欢
随机推荐
面试官:生成订单30分钟未支付,则自动取消,该怎么实现?
Selenium in the crawler realizes automatic collection of CSDN bloggers' articles
raid homes and plunder houses!
Skills to learn before going to primary school
初识C语言函数
MySQL执行顺序
Kettle implements shared database connection and insert update component instances
bgp选路原则
What is the difference between server hosting and virtual host
Simulation of BOC modulation signal acquisition based on MATLAB
基于matlab的BOC调制信号捕获仿真
【OpenCV 例程200篇】225. 特征提取之傅里叶描述子
[ctfhub] the data of JWT header and payload are transmitted in clear text. If sensitive information is contained in it, sensitive information will be leaked. Try to find the flag. Format is flag{}
turbo编译码误码率性能matlab仿真
在一个有序数组中查找具体的某个数字(二分查找or折半查找)
基于matlab的CBOC信号调制解调仿真,输出其相关性,功率谱以及频偏跟踪
xlswriter - excel导出
Matlab simulation of depth information extraction and target ranging based on binocular camera images
Linked list review!
安全合理用电 收获清凉一“夏”









