mirror of
https://github.com/openharmony/distributed_camera.git
synced 2026-07-20 00:54:12 -04:00
fix distributed camera ut bug
Signed-off-by: zhuxu <zhuxu29@huawei.com>
This commit is contained in:
@@ -85,6 +85,9 @@
|
||||
}
|
||||
],
|
||||
"test":[
|
||||
"//foundation/distributedhardware/distributedcamera/services/cameraservice/cameraoperator/client/test/unittest:camera_client_test",
|
||||
"//foundation/distributedhardware/distributedcamera/services/cameraservice/cameraoperator/handler/test/unittest:camera_handler_test",
|
||||
"//foundation/distributedhardware/distributedcamera/services/cameraservice/sinkservice/test/unittest:sink_service_test",
|
||||
"//foundation/distributedhardware/distributedcamera/services/cameraservice/sourceservice/test/unittest:source_service_test",
|
||||
"//foundation/distributedhardware/distributedcamera/services/cameraservice/base/test/unittest:services_base_test"
|
||||
]
|
||||
|
||||
@@ -87,6 +87,8 @@ ohos_shared_library("distributed_camera_client") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libtoken_setproc",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"multimedia_media_standard:media_client",
|
||||
]
|
||||
|
||||
@@ -18,14 +18,19 @@
|
||||
|
||||
#include "icamera_operator.h"
|
||||
|
||||
#include "access_token.h"
|
||||
#include "accesstoken_kit.h"
|
||||
#include "camera_info.h"
|
||||
#include "camera_input.h"
|
||||
#include "camera_manager.h"
|
||||
#include "capture_input.h"
|
||||
#include "capture_output.h"
|
||||
#include "capture_session.h"
|
||||
#include "hap_token_info.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "photo_output.h"
|
||||
#include "preview_output.h"
|
||||
#include "token_setproc.h"
|
||||
#include "video_output.h"
|
||||
|
||||
#include "dcamera_photo_surface_listener.h"
|
||||
@@ -33,6 +38,52 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
const std::string OHOS_PERMISSION_CAMERA = "ohos.permission.CAMERA";
|
||||
const std::string APP_ID_DESC = "distributed camera";
|
||||
const std::string LABEL = "label";
|
||||
const std::string DESCRIPTION = "distributed camera";
|
||||
const std::string RES_DEVICE_ID = "local";
|
||||
const std::string DOMAIN = "distribtued_camera.domain";
|
||||
const int32_t USER_ID = 1;
|
||||
const int32_t INST_INDEX = 0;
|
||||
const int32_t GRANT_MODE = 1;
|
||||
const int32_t GRANT_FLAGS = 1;
|
||||
const int32_t LABEL_ID = 1;
|
||||
const int32_t DESCRIPTION_ID = 1;
|
||||
|
||||
const Security::AccessToken::HapInfoParams HAP_INFO_PARAMS = {
|
||||
.userID = USER_ID,
|
||||
.bundleName = OHOS_PERMISSION_CAMERA,
|
||||
.instIndex = INST_INDEX,
|
||||
.appIDDesc = APP_ID_DESC
|
||||
};
|
||||
|
||||
const Security::AccessToken::PermissionDef PERMISSION_DEF = {
|
||||
.permissionName = OHOS_PERMISSION_CAMERA,
|
||||
.bundleName = OHOS_PERMISSION_CAMERA,
|
||||
.grantMode = GRANT_MODE,
|
||||
.availableLevel = Security::AccessToken::ATokenAplEnum::APL_NORMAL,
|
||||
.label = LABEL,
|
||||
.labelId = LABEL_ID,
|
||||
.description = DESCRIPTION,
|
||||
.descriptionId = DESCRIPTION_ID
|
||||
};
|
||||
|
||||
const Security::AccessToken::PermissionStateFull PERMISSION_STATE_FULL = {
|
||||
.permissionName = OHOS_PERMISSION_CAMERA,
|
||||
.isGeneral = true,
|
||||
.resDeviceID = {RES_DEVICE_ID},
|
||||
.grantStatus = {Security::AccessToken::PermissionState::PERMISSION_GRANTED},
|
||||
.grantFlags = {GRANT_FLAGS}
|
||||
};
|
||||
|
||||
const Security::AccessToken::HapPolicyParams HAP_POLICY_PARAMS = {
|
||||
.apl = Security::AccessToken::ATokenAplEnum::APL_NORMAL,
|
||||
.domain = DOMAIN,
|
||||
.permList = {PERMISSION_DEF},
|
||||
.permStateList = {PERMISSION_STATE_FULL}
|
||||
};
|
||||
|
||||
class DCameraClient : public ICameraOperator {
|
||||
public:
|
||||
explicit DCameraClient(const std::string& dhId);
|
||||
@@ -73,6 +124,7 @@ private:
|
||||
std::shared_ptr<ResultCallback> resultCallback_;
|
||||
std::shared_ptr<DCameraPhotoSurfaceListener> photoListener_;
|
||||
std::shared_ptr<DCameraVideoSurfaceListener> videoListener_;
|
||||
Security::AccessToken::AccessTokenIDEx tokenIdEx_;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -36,6 +36,21 @@ DCameraClient::DCameraClient(const std::string& dhId)
|
||||
DHLOGI("DCameraClient Constructor dhId: %s", GetAnonyString(dhId).c_str());
|
||||
cameraId_ = dhId.substr(CAMERA_ID_PREFIX.size());
|
||||
isInit_ = false;
|
||||
|
||||
tokenIdEx_ = Security::AccessToken::AccessTokenKit::AllocHapToken(HAP_INFO_PARAMS, HAP_POLICY_PARAMS);
|
||||
if (tokenIdEx_.tokenIdExStruct.tokenID == 0) {
|
||||
DHLOGE("DCameraClient Constructor alloc tokenId failed, dhId: %s", GetAnonyString(dhId).c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
(void)SetSelfTokenID(tokenIdEx_.tokenIdExStruct.tokenID);
|
||||
|
||||
int32_t ret = Security::AccessToken::AccessTokenKit::GrantPermission(tokenIdEx_.tokenIdExStruct.tokenID,
|
||||
"ohos.permission.CAMERA", Security::AccessToken::PERMISSION_USER_FIXED);
|
||||
if (ret != 0) {
|
||||
DHLOGE("DCameraClient Constructor grant permission failed, dhId: %s", GetAnonyString(dhId).c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
DCameraClient::~DCameraClient()
|
||||
@@ -43,6 +58,7 @@ DCameraClient::~DCameraClient()
|
||||
if (isInit_) {
|
||||
UnInit();
|
||||
}
|
||||
(void)Security::AccessToken::AccessTokenKit::DeleteToken(tokenIdEx_.tokenIdExStruct.tokenID);
|
||||
}
|
||||
|
||||
int32_t DCameraClient::Init()
|
||||
|
||||
@@ -35,6 +35,21 @@ DCameraClient::DCameraClient(const std::string& dhId)
|
||||
DHLOGI("DCameraClientCommon Constructor dhId: %s", GetAnonyString(dhId).c_str());
|
||||
cameraId_ = dhId.substr(CAMERA_ID_PREFIX.size());
|
||||
isInit_ = false;
|
||||
|
||||
tokenIdEx_ = Security::AccessToken::AccessTokenKit::AllocHapToken(HAP_INFO_PARAMS, HAP_POLICY_PARAMS);
|
||||
if (tokenIdEx_.tokenIdExStruct.tokenID == 0) {
|
||||
DHLOGE("DCameraClientCommon Constructor alloc tokenId failed, dhId: %s", GetAnonyString(dhId).c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
(void)SetSelfTokenID(tokenIdEx_.tokenIdExStruct.tokenID);
|
||||
|
||||
int32_t ret = Security::AccessToken::AccessTokenKit::GrantPermission(tokenIdEx_.tokenIdExStruct.tokenID,
|
||||
"ohos.permission.CAMERA", Security::AccessToken::PERMISSION_USER_FIXED);
|
||||
if (ret != 0) {
|
||||
DHLOGE("DCameraClientCommon Constructor grant permission failed, dhId: %s", GetAnonyString(dhId).c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
DCameraClient::~DCameraClient()
|
||||
@@ -42,6 +57,7 @@ DCameraClient::~DCameraClient()
|
||||
if (isInit_) {
|
||||
UnInit();
|
||||
}
|
||||
(void)Security::AccessToken::AccessTokenKit::DeleteToken(tokenIdEx_.tokenIdExStruct.tokenID);
|
||||
}
|
||||
|
||||
int32_t DCameraClient::Init()
|
||||
|
||||
+2
@@ -71,6 +71,8 @@ ohos_unittest("DCameraClientTest") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libtoken_setproc",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"eventhandler:libeventhandler",
|
||||
"ipc:ipc_core",
|
||||
|
||||
@@ -117,6 +117,8 @@ ohos_shared_library("distributed_camera_sink") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libtoken_setproc",
|
||||
"eventhandler:libeventhandler",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
|
||||
+2
-2
@@ -52,7 +52,7 @@ int32_t DCameraServiceStateListener::OnRegisterNotify(const std::string& devId,
|
||||
DHLOGE("DCameraServiceStateListener OnRegisterNotify OnNotifyRegResult failed: %d", ret);
|
||||
}
|
||||
if (status != DCAMERA_OK) {
|
||||
std::thread([this, devId, dhId]() {
|
||||
std::thread([devId, dhId]() {
|
||||
DHLOGI("DCameraServiceStateListener OnRegisterNotify thread delete devId: %s dhId: %s",
|
||||
GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str());
|
||||
DCameraIndex camIndex(devId, dhId);
|
||||
@@ -78,7 +78,7 @@ int32_t DCameraServiceStateListener::OnUnregisterNotify(const std::string& devId
|
||||
}
|
||||
|
||||
if (status == DCAMERA_OK) {
|
||||
std::thread([this, devId, dhId]() {
|
||||
std::thread([devId, dhId]() {
|
||||
DHLOGI("DCameraServiceStateListener OnUnregisterNotify thread delete devId: %s dhId: %s",
|
||||
GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str());
|
||||
DCameraIndex camIndex(devId, dhId);
|
||||
|
||||
@@ -57,6 +57,17 @@ DCameraSourceDev::~DCameraSourceDev()
|
||||
{
|
||||
DHLOGI("DCameraSourceDev Delete devId %s dhId %s", GetAnonyString(devId_).c_str(),
|
||||
GetAnonyString(dhId_).c_str());
|
||||
eventBus_ = nullptr;
|
||||
hdiCallback_ = nullptr;
|
||||
input_ = nullptr;
|
||||
controller_ = nullptr;
|
||||
stateMachine_ = nullptr;
|
||||
stateListener_ = nullptr;
|
||||
|
||||
eventResultMap_.clear();
|
||||
memberFuncMap_.clear();
|
||||
DHLOGI("DCameraSourceDev Delete devId %s dhId %s end", GetAnonyString(devId_).c_str(),
|
||||
GetAnonyString(dhId_).c_str());
|
||||
}
|
||||
|
||||
int32_t DCameraSourceDev::InitDCameraSourceDev()
|
||||
|
||||
Reference in New Issue
Block a user