mirror of
https://github.com/openharmony/device_manager.git
synced 2026-07-20 21:58:27 -04:00
add fa Code and buf fix
Signed-off-by: pengguanqi <pengguanqi@huawei.com>
This commit is contained in:
@@ -361,8 +361,9 @@ ON_IPC_CMD(SERVER_DEVICEMANAGER_FA_NOTIFY, IpcIo &reply, const IpcContext &ctx,
|
||||
std::string packagename = (const char *)IpcIoPopString(&reply, &len);
|
||||
size_t jsonLen = 0;
|
||||
std::string paramJson = (const char *)IpcIoPopString(&reply, &jsonLen);
|
||||
DeviceManagerNotify::GetInstance().OnFaCall(packagename,paramJson);
|
||||
DeviceManagerNotify::GetInstance().OnFaCall(packagename, paramJson);
|
||||
IpcIoPushInt32(&reply, DEVICEMANAGER_OK);
|
||||
FreeBuffer(&ctx, ipcMsg);
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -51,6 +51,7 @@ public:
|
||||
bool IsMyChannelId(long long channelId);
|
||||
void Release();
|
||||
void CancelDisplay();
|
||||
int32_t GetStatus();
|
||||
|
||||
private:
|
||||
int32_t DecodeReqMsg(std::string &message);
|
||||
|
||||
@@ -48,21 +48,22 @@ public:
|
||||
DmTimerStatus Start(uint32_t timeOut, TimeoutHandle handle, void *data);
|
||||
void Stop(int32_t code);
|
||||
void WiteforTimeout();
|
||||
void Release();
|
||||
|
||||
private:
|
||||
int32_t CreateTimeFd();
|
||||
void Release();
|
||||
|
||||
private:
|
||||
DmTimerStatus mStatus;
|
||||
uint32_t mTimeOutS;
|
||||
TimeoutHandle mHandle;
|
||||
void* mHandleData;
|
||||
int32_t mTimeFd[2];
|
||||
struct epoll_event mEv;
|
||||
struct epoll_event mEvents[MAXEVENTS];
|
||||
int32_t mEpFd;
|
||||
std::thread mThread;
|
||||
DmTimerStatus mStatus_;
|
||||
uint32_t mTimeOutSec_;
|
||||
TimeoutHandle mHandle_;
|
||||
void* mHandleData_;
|
||||
int32_t mTimeFd_[2];
|
||||
struct epoll_event mEv_;
|
||||
struct epoll_event mEvents_[MAXEVENTS];
|
||||
int32_t mEpFd_;
|
||||
std::thread mThread_;
|
||||
std::string mTimerName_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ ON_IPC_SERVER_CMD(SERVER_GET_AUTHENTCATION_INFO, IpcIo &req, IpcIo &reply)
|
||||
IpcIoPushInt32(&reply, authParam.direction);
|
||||
IpcIoPushInt32(&reply, authParam.authType);
|
||||
IpcIoPushInt32(&reply, authParam.pinToken);
|
||||
DMLOG(DM_LOG_DEBUG,"DeviceManagerStub::is Client so just return direction");
|
||||
DMLOG(DM_LOG_DEBUG, "DeviceManagerStub::is Client so just return direction");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -246,10 +246,9 @@ ON_IPC_SERVER_CMD(SERVER_GET_AUTHENTCATION_INFO, IpcIo &req, IpcIo &reply)
|
||||
IpcIoPushFlatObj(&reply, authParam.imageinfo.GetAppIcon(),appIconLen);
|
||||
}
|
||||
|
||||
if ( appThumbnailLen > 0 && authParam.imageinfo.GetAppThumbnail() != nullptr) {
|
||||
if (appThumbnailLen > 0 && authParam.imageinfo.GetAppThumbnail() != nullptr) {
|
||||
IpcIoPushFlatObj(&reply, authParam.imageinfo.GetAppThumbnail(), appThumbnailLen);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ON_IPC_SERVER_CMD(SERVER_USER_AUTHORIZATION_OPERATION, IpcIo &req, IpcIo &reply)
|
||||
|
||||
@@ -290,7 +290,7 @@ ON_IPC_CMD(SERVER_GET_AUTHENTCATION_INFO, MessageParcel &data, MessageParcel &re
|
||||
if (authParam.direction == AUTH_SESSION_SIDE_CLIENT) {
|
||||
if (!reply.WriteInt32(authParam.direction) || !reply.WriteInt32(authParam.authType) ||
|
||||
!reply.WriteInt32(authParam.pinToken)) {
|
||||
DMLOG(DM_LOG_ERROR,"DeviceManagerStub::wirte client fail");
|
||||
DMLOG(DM_LOG_ERROR, "DeviceManagerStub::wirte client fail");
|
||||
ret = DEVICEMANAGER_WRITE_FAILED;
|
||||
}
|
||||
return ret;
|
||||
|
||||
@@ -128,15 +128,25 @@ bool ResponseSession::IsMyChannelId(long long channelId)
|
||||
|
||||
void OnReceiveTimeOut(void *data)
|
||||
{
|
||||
DMLOG(DM_LOG_ERROR, "Receive TimeOut");
|
||||
DMLOG(DM_LOG_ERROR, "OnReceiveTimeOut TimeOut called");
|
||||
ResponseSession *respSess = (ResponseSession*)data;
|
||||
if (respSess == nullptr || respSess->GetStatus() == ResponseSessionStatus::SESSION_INIT) {
|
||||
DMLOG(DM_LOG_ERROR, "respSess Status is INIT");
|
||||
return;
|
||||
}
|
||||
|
||||
respSess->Release();
|
||||
}
|
||||
|
||||
void OnMemberJoinTimeOut(void *data)
|
||||
{
|
||||
DMLOG(DM_LOG_ERROR, "Receive TimeOut");
|
||||
DMLOG(DM_LOG_ERROR, "OnMemberJoinTimeOut TimeOut caled");
|
||||
ResponseSession *respSess = (ResponseSession*)data;
|
||||
if (respSess == nullptr || respSess->GetStatus() == ResponseSessionStatus::SESSION_INIT) {
|
||||
DMLOG(DM_LOG_ERROR, "respSess Status is INIT");
|
||||
return;
|
||||
}
|
||||
|
||||
respSess->SendResponseMessage(SESSION_REPLY_TIMEOUT);
|
||||
respSess->CancelDisplay();
|
||||
respSess->Release();
|
||||
@@ -151,7 +161,7 @@ void ResponseSession::OnReceiveMsg(long long channelId, std::string &message)
|
||||
}
|
||||
|
||||
if (!mReceiveTimerPtr_) {
|
||||
mReceiveTimerPtr_ = std::make_shared<DmTimer>();
|
||||
mReceiveTimerPtr_ = std::make_shared<DmTimer>("mReceiveTimer");
|
||||
}
|
||||
|
||||
mReceiveTimerPtr_->Start(SESSION_MSG_RECEIVE_TIMEOUT, OnReceiveTimeOut, this);
|
||||
@@ -170,7 +180,7 @@ void ResponseSession::OnReceiveMsg(long long channelId, std::string &message)
|
||||
|
||||
mSessionStatus_ = ResponseSessionStatus::SESSION_WAITTING_USER_CONFIRM;
|
||||
if (!mMemberJoinTimerPtr_) {
|
||||
mMemberJoinTimerPtr_ = std::make_shared<DmTimer>();
|
||||
mMemberJoinTimerPtr_ = std::make_shared<DmTimer>("mMemberJoinTimer");
|
||||
}
|
||||
|
||||
mMemberJoinTimerPtr_->Start(SESSION_WAIT_MEMBER_JOIN_TIMEOUT, OnMemberJoinTimeOut, this);
|
||||
@@ -236,7 +246,7 @@ void ResponseSession::OnGroupCreated(int64_t requestId, const std::string &group
|
||||
DMLOG(DM_LOG_INFO, "ResponseSession OnGroupCreated in requestId= %lld groupId = %s ", requestId, groupId.c_str());
|
||||
|
||||
if (requestId != mRequestId_ || groupId.length() == 0) {
|
||||
DMLOG(DM_LOG_ERROR, "ResponseSession::OnGroupCreated failed, requestId %d, requestId %d, groupId %s",
|
||||
DMLOG(DM_LOG_ERROR, "ResponseSession::OnGroupCreated failed, requestId %lld, requestId %lld, groupId %s",
|
||||
requestId, mRequestId_, groupId.c_str());
|
||||
SendResponseMessage(SESSION_REPLY_CREAT_GROUP_FAILED);
|
||||
CancelDisplay();
|
||||
@@ -263,7 +273,6 @@ void ResponseSession::OnMemberJoin(int64_t requestId, int32_t status)
|
||||
DMLOG(DM_LOG_INFO, "ResponseSession::OnMemberJoin, result: %d", status);
|
||||
CancelDisplay();
|
||||
mMemberJoinTimerPtr_->Stop(SESSION_CANCEL_TIMEOUT);
|
||||
mMemberJoinTimerPtr_->Release();
|
||||
Release();
|
||||
}
|
||||
|
||||
@@ -304,6 +313,7 @@ void ResponseSession::OnUserReject(int32_t errorCode)
|
||||
void ResponseSession::Release()
|
||||
{
|
||||
DMLOG(DM_LOG_INFO, "ResponseSession::Release in");
|
||||
mSessionStatus_ = ResponseSessionStatus::SESSION_INIT;
|
||||
mRequestId_ = -1;
|
||||
mGroupId_ = "";
|
||||
mGroupName_ = "";
|
||||
@@ -311,9 +321,6 @@ void ResponseSession::Release()
|
||||
mMsgRequestAuthPtr_ = nullptr;
|
||||
mChannelId_ = -1;
|
||||
mPincode_ = -1;
|
||||
mSessionStatus_ = ResponseSessionStatus::SESSION_INIT;
|
||||
mReceiveTimerPtr_ = nullptr;
|
||||
mMemberJoinTimerPtr_ = nullptr;
|
||||
}
|
||||
|
||||
void ResponseSession::CancelDisplay()
|
||||
@@ -323,7 +330,12 @@ void ResponseSession::CancelDisplay()
|
||||
std::string paramJson = jsonObj.dump();
|
||||
std::string pkgName = "com.ohos.devicemanagerui";
|
||||
IpcServerListenerAdapter::GetInstance().OnFaCall(pkgName, paramJson);
|
||||
DMLOG(DM_LOG_INFO, "CancelDisplay close pin code window %s", mMsgRequestAuthPtr_->mTargetPkg_.c_str());
|
||||
DMLOG(DM_LOG_INFO, "CancelDisplay close pin code window");
|
||||
}
|
||||
|
||||
int32_t ResponseSession::GetStatus()
|
||||
{
|
||||
return mSessionStatus_;
|
||||
}
|
||||
|
||||
int32_t ResponseSession::GeneratePincode()
|
||||
|
||||
@@ -19,41 +19,45 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
DmTimer::DmTimer() {
|
||||
mStatus = DmTimerStatus::DM_STATUS_INIT;
|
||||
DmTimer::DmTimer(std::string &name)
|
||||
{
|
||||
mStatus_ = DmTimerStatus::DM_STATUS_INIT;
|
||||
mTimerName_ = name;
|
||||
}
|
||||
|
||||
DmTimerStatus DmTimer::Start(uint32_t timeOut, TimeoutHandle handle, void *data)
|
||||
{
|
||||
DMLOG(DM_LOG_ERROR, "DmTimer start timeout(%d)\n", timeOut);
|
||||
if (mStatus != DmTimerStatus::DM_STATUS_INIT) {
|
||||
DMLOG(DM_LOG_INFO, "DmTimer %s start timeout(%d)", mTimerName_.c_str(), timeOut);
|
||||
if (mStatus_ != DmTimerStatus::DM_STATUS_INIT) {
|
||||
return DmTimerStatus::DM_STATUS_BUSY;
|
||||
}
|
||||
|
||||
mTimeOutS = timeOut;
|
||||
mHandle = handle;
|
||||
mHandleData = data;
|
||||
mTimeOutSec_ = timeOut;
|
||||
mHandle_ = handle;
|
||||
mHandleData_ = data;
|
||||
|
||||
if (CreateTimeFd()) {
|
||||
return DmTimerStatus::DM_STATUS_CREATE_ERROR;
|
||||
}
|
||||
|
||||
mStatus = DmTimerStatus::DM_STATUS_RUNNING;
|
||||
mThread = std::thread(&DmTimer::WiteforTimeout, this);
|
||||
mThread.detach();
|
||||
mStatus_ = DmTimerStatus::DM_STATUS_RUNNING;
|
||||
mThread_ = std::thread(&DmTimer::WiteforTimeout, this);
|
||||
mThread_.detach();
|
||||
|
||||
return mStatus;
|
||||
return mStatus_;
|
||||
}
|
||||
|
||||
void DmTimer::Stop(int32_t code)
|
||||
{
|
||||
DMLOG(DM_LOG_ERROR, "DmTimer Stop code (%d)\n", code);
|
||||
DMLOG(DM_LOG_INFO, "DmTimer %s Stop code (%d)", mTimerName_.c_str(), code);
|
||||
char event;
|
||||
event = 'S';
|
||||
if (mTimeFd[1]) {
|
||||
if (write(mTimeFd[1], &event, 1) < 0) {
|
||||
DMLOG(DM_LOG_ERROR, "DmTimer Stop timer failed %d \n", errno);
|
||||
if (mTimeFd_[1]) {
|
||||
if (write(mTimeFd_[1], &event, 1) < 0) {
|
||||
DMLOG(DM_LOG_ERROR, "DmTimer %s Stop timer failed, errno %d", mTimerName_.c_str(), errno);
|
||||
return;
|
||||
}
|
||||
DMLOG(DM_LOG_INFO, "DmTimer %s Stop success", mTimerName_.c_str());
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -61,48 +65,49 @@ void DmTimer::Stop(int32_t code)
|
||||
|
||||
void DmTimer::WiteforTimeout()
|
||||
{
|
||||
DMLOG(DM_LOG_ERROR, "DmTimer start timer at (%d)s" ,mTimeOutS);
|
||||
DMLOG(DM_LOG_INFO, "DmTimer %s start timer at (%d)s", mTimerName_.c_str(), mTimeOutSec_);
|
||||
|
||||
int32_t nfds = epoll_wait(mEpFd, mEvents, MAXEVENTS, mTimeOutS * 1000);
|
||||
int32_t nfds = epoll_wait(mEpFd_, mEvents_, MAXEVENTS, mTimeOutSec_ * 1000);
|
||||
if (nfds < 0) {
|
||||
DMLOG(DM_LOG_ERROR, "epoll_wait returned n=%d, error: %d", nfds, errno);
|
||||
DMLOG(DM_LOG_ERROR, "DmTimer %s epoll_wait returned n=%d, error: %d", mTimerName_.c_str(), nfds, errno);
|
||||
}
|
||||
|
||||
char event = 0;
|
||||
if (nfds > 0) {
|
||||
if (mEvents[0].events & EPOLLIN) {
|
||||
int num= read(mTimeFd[0], &event, 1);
|
||||
if (mEvents_[0].events & EPOLLIN) {
|
||||
int num= read(mTimeFd_[0], &event, 1);
|
||||
if (num > 0) {
|
||||
DMLOG(DM_LOG_INFO, "DmTimer exit with event %d", event);
|
||||
DMLOG(DM_LOG_INFO, "DmTimer %s exit with event %d", mTimerName_.c_str(), event);
|
||||
} else {
|
||||
DMLOG(DM_LOG_ERROR, "DmTimer exit with errno %d", errno);
|
||||
DMLOG(DM_LOG_ERROR, "DmTimer %s exit with errno %d", mTimerName_.c_str(), errno);
|
||||
}
|
||||
}
|
||||
Release();
|
||||
return;
|
||||
}
|
||||
|
||||
mHandle(mHandleData);
|
||||
mHandle_(mHandleData_);
|
||||
Release();
|
||||
|
||||
DMLOG(DM_LOG_ERROR, "DmTimer end timer at (%d)s" ,mTimeOutS);
|
||||
DMLOG(DM_LOG_ERROR, "DmTimer %s end timer at (%d)s", mTimerName_.c_str(), mTimeOutSec_);
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t DmTimer::CreateTimeFd()
|
||||
{
|
||||
DMLOG(DM_LOG_ERROR, "DmTimer creatTimeFd" );
|
||||
DMLOG(DM_LOG_INFO, "DmTimer %s creatTimeFd", mTimerName_.c_str());
|
||||
int ret = 0;
|
||||
|
||||
ret = pipe(mTimeFd);
|
||||
if ( ret < 0) {
|
||||
DMLOG(DM_LOG_ERROR, "DmTimer CreateTimeFd fail:(%d) errno(%d)" ,ret, errno);
|
||||
ret = pipe(mTimeFd_);
|
||||
if (ret < 0) {
|
||||
DMLOG(DM_LOG_ERROR, "DmTimer %s CreateTimeFd fail:(%d) errno(%d)", mTimerName_.c_str(), ret, errno);
|
||||
return ret;
|
||||
}
|
||||
|
||||
mEv.data.fd = mTimeFd[0];
|
||||
mEv.events = EPOLLIN | EPOLLET;
|
||||
mEpFd = epoll_create(MAXEVENTS);
|
||||
ret = epoll_ctl(mEpFd, EPOLL_CTL_ADD, mTimeFd[0], &mEv);
|
||||
mEv_.data.fd = mTimeFd_[0];
|
||||
mEv_.events = EPOLLIN | EPOLLET;
|
||||
mEpFd_ = epoll_create(MAXEVENTS);
|
||||
ret = epoll_ctl(mEpFd_, EPOLL_CTL_ADD, mTimeFd_[0], &mEv_);
|
||||
if (ret != 0) {
|
||||
Release();
|
||||
}
|
||||
@@ -112,13 +117,14 @@ int32_t DmTimer::CreateTimeFd()
|
||||
|
||||
void DmTimer::Release()
|
||||
{
|
||||
mStatus = DmTimerStatus::DM_STATUS_INIT;
|
||||
close(mTimeFd[0]);
|
||||
close(mTimeFd[1]);
|
||||
close(mEpFd);
|
||||
mTimeFd[0] = 0;
|
||||
mTimeFd[1] = 0;
|
||||
mEpFd = 0;
|
||||
DMLOG(DM_LOG_INFO, "DmTimer %s Release in", mTimerName_.c_str());
|
||||
mStatus_ = DmTimerStatus::DM_STATUS_INIT;
|
||||
close(mTimeFd_[0]);
|
||||
close(mTimeFd_[1]);
|
||||
close(mEpFd_);
|
||||
mTimeFd_[0] = 0;
|
||||
mTimeFd_[1] = 0;
|
||||
mEpFd_ = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user