!962 delete data sync perm for collaboration

Merge pull request !962 from 仝月姣/master
This commit is contained in:
openharmony_ci 2024-07-03 13:27:08 +00:00 committed by dinghao
commit 3f77882ca7
13 changed files with 152 additions and 72 deletions

View File

@ -1097,6 +1097,9 @@ void DistributedWant::RemoveParam(const std::string& key)
void DistributedWant::ClearWant(DistributedWant* want) void DistributedWant::ClearWant(DistributedWant* want)
{ {
if (want == nullptr) {
return;
}
want->SetType(""); want->SetType("");
want->SetAction(""); want->SetAction("");
want->SetFlags(0); want->SetFlags(0);

View File

@ -1110,6 +1110,9 @@ bool DistributedWantParams::ReadFromParcelWantParamWrapper(Parcel& parcel, const
bool DistributedWantParams::ReadFromParcelFD(Parcel& parcel, const std::string& key) bool DistributedWantParams::ReadFromParcelFD(Parcel& parcel, const std::string& key)
{ {
auto messageParcel = static_cast<MessageParcel*>(&parcel); auto messageParcel = static_cast<MessageParcel*>(&parcel);
if (messageParcel == nullptr) {
return false;
}
auto fd = messageParcel->ReadFileDescriptor(); auto fd = messageParcel->ReadFileDescriptor();
DistributedWantParams wp; DistributedWantParams wp;
wp.SetParam(TYPE_PROPERTY, AAFwk::String::Box(FD)); wp.SetParam(TYPE_PROPERTY, AAFwk::String::Box(FD));
@ -1122,6 +1125,9 @@ bool DistributedWantParams::ReadFromParcelFD(Parcel& parcel, const std::string&
bool DistributedWantParams::ReadFromParcelRemoteObject(Parcel& parcel, const std::string& key) bool DistributedWantParams::ReadFromParcelRemoteObject(Parcel& parcel, const std::string& key)
{ {
auto messageParcel = static_cast<MessageParcel*>(&parcel); auto messageParcel = static_cast<MessageParcel*>(&parcel);
if (messageParcel == nullptr) {
return false;
}
auto remoteObject = messageParcel->ReadRemoteObject(); auto remoteObject = messageParcel->ReadRemoteObject();
DistributedWantParams wp; DistributedWantParams wp;
wp.SetParam(TYPE_PROPERTY, AAFwk::String::Box(REMOTE_OBJECT)); wp.SetParam(TYPE_PROPERTY, AAFwk::String::Box(REMOTE_OBJECT));

View File

@ -61,7 +61,6 @@ const std::string TAG = "DistributedSchedStub";
const std::u16string DMS_STUB_INTERFACE_TOKEN = u"ohos.distributedschedule.accessToken"; const std::u16string DMS_STUB_INTERFACE_TOKEN = u"ohos.distributedschedule.accessToken";
const std::string EXTRO_INFO_JSON_KEY_ACCESS_TOKEN = "accessTokenID"; const std::string EXTRO_INFO_JSON_KEY_ACCESS_TOKEN = "accessTokenID";
const std::string EXTRO_INFO_JSON_KEY_REQUEST_CODE = "requestCode"; const std::string EXTRO_INFO_JSON_KEY_REQUEST_CODE = "requestCode";
const std::string PERMISSION_DISTRIBUTED_DATASYNC = "ohos.permission.DISTRIBUTED_DATASYNC";
const std::string PARAM_FREEINSTALL_APPID = "ohos.freeinstall.params.callingAppId"; const std::string PARAM_FREEINSTALL_APPID = "ohos.freeinstall.params.callingAppId";
const std::string PARAM_FREEINSTALL_BUNDLENAMES = "ohos.freeinstall.params.callingBundleNames"; const std::string PARAM_FREEINSTALL_BUNDLENAMES = "ohos.freeinstall.params.callingBundleNames";
const std::string CMPT_PARAM_FREEINSTALL_BUNDLENAMES = "ohos.extra.param.key.allowedBundles"; const std::string CMPT_PARAM_FREEINSTALL_BUNDLENAMES = "ohos.extra.param.key.allowedBundles";
@ -256,11 +255,6 @@ int32_t DistributedSchedStub::StartRemoteAbilityInner(MessageParcel& data, Messa
uint32_t accessToken = 0; uint32_t accessToken = 0;
PARCEL_READ_HELPER(data, Uint32, accessToken); PARCEL_READ_HELPER(data, Uint32, accessToken);
HILOGD("get callerUid = %{public}d, AccessTokenID = %{private}u", callerUid, accessToken); HILOGD("get callerUid = %{public}d, AccessTokenID = %{private}u", callerUid, accessToken);
if (DistributedSchedPermission::GetInstance().CheckPermission(accessToken,
PERMISSION_DISTRIBUTED_DATASYNC) != ERR_OK) {
HILOGE("check data_sync permission failed!");
return DMS_PERMISSION_DENIED;
}
DistributedSchedPermission::GetInstance().MarkUriPermission(*want, accessToken); DistributedSchedPermission::GetInstance().MarkUriPermission(*want, accessToken);
int32_t result = StartRemoteAbility(*want, callerUid, requestCode, accessToken); int32_t result = StartRemoteAbility(*want, callerUid, requestCode, accessToken);
ReportEvent(*want, BehaviorEvent::START_REMOTE_ABILITY, result, callerUid); ReportEvent(*want, BehaviorEvent::START_REMOTE_ABILITY, result, callerUid);
@ -723,11 +717,6 @@ int32_t DistributedSchedStub::ConnectRemoteAbilityInner(MessageParcel& data, Mes
PARCEL_READ_HELPER(data, Uint32, accessToken); PARCEL_READ_HELPER(data, Uint32, accessToken);
HILOGD("get callerUid = %{public}d, callerPid = %{public}d, AccessTokenID = %{private}u", callerUid, callerPid, HILOGD("get callerUid = %{public}d, callerPid = %{public}d, AccessTokenID = %{private}u", callerUid, callerPid,
accessToken); accessToken);
if (DistributedSchedPermission::GetInstance().CheckPermission(accessToken,
PERMISSION_DISTRIBUTED_DATASYNC) != ERR_OK) {
HILOGE("check data_sync permission failed!");
return DMS_PERMISSION_DENIED;
}
int32_t result = ConnectRemoteAbility(*want, connect, callerUid, callerPid, accessToken); int32_t result = ConnectRemoteAbility(*want, connect, callerUid, callerPid, accessToken);
ReportEvent(*want, BehaviorEvent::CONNECT_REMOTE_ABILITY, result, callerUid); ReportEvent(*want, BehaviorEvent::CONNECT_REMOTE_ABILITY, result, callerUid);
HILOGI("result = %{public}d", result); HILOGI("result = %{public}d", result);
@ -747,11 +736,6 @@ int32_t DistributedSchedStub::DisconnectRemoteAbilityInner(MessageParcel& data,
uint32_t accessToken = 0; uint32_t accessToken = 0;
PARCEL_READ_HELPER(data, Uint32, accessToken); PARCEL_READ_HELPER(data, Uint32, accessToken);
HILOGD("get callerUid = %{public}d, AccessTokenID = %{private}u", callerUid, accessToken); HILOGD("get callerUid = %{public}d, AccessTokenID = %{private}u", callerUid, accessToken);
if (DistributedSchedPermission::GetInstance().CheckPermission(accessToken,
PERMISSION_DISTRIBUTED_DATASYNC) != ERR_OK) {
HILOGE("check data_sync permission failed!");
return DMS_PERMISSION_DENIED;
}
int32_t result = DisconnectRemoteAbility(connect, callerUid, accessToken); int32_t result = DisconnectRemoteAbility(connect, callerUid, accessToken);
BehaviorEventParam eventParam = { EventCallingType::LOCAL, BehaviorEvent::DISCONNECT_REMOTE_ABILITY, result }; BehaviorEventParam eventParam = { EventCallingType::LOCAL, BehaviorEvent::DISCONNECT_REMOTE_ABILITY, result };
DmsHiSysEventReport::ReportBehaviorEvent(eventParam); DmsHiSysEventReport::ReportBehaviorEvent(eventParam);
@ -1252,11 +1236,6 @@ int32_t DistributedSchedStub::StartRemoteAbilityByCallInner(MessageParcel& data,
PARCEL_READ_HELPER(data, Int32, callerPid); PARCEL_READ_HELPER(data, Int32, callerPid);
uint32_t accessToken = 0; uint32_t accessToken = 0;
PARCEL_READ_HELPER(data, Uint32, accessToken); PARCEL_READ_HELPER(data, Uint32, accessToken);
if (DistributedSchedPermission::GetInstance().CheckPermission(accessToken,
PERMISSION_DISTRIBUTED_DATASYNC) != ERR_OK) {
HILOGE("check data_sync permission failed!");
return DMS_PERMISSION_DENIED;
}
int32_t result = StartRemoteAbilityByCall(*want, connect, callerUid, callerPid, accessToken); int32_t result = StartRemoteAbilityByCall(*want, connect, callerUid, callerPid, accessToken);
ReportEvent(*want, BehaviorEvent::START_REMOTE_ABILITY_BYCALL, result, callerUid); ReportEvent(*want, BehaviorEvent::START_REMOTE_ABILITY_BYCALL, result, callerUid);
HILOGI("result = %{public}d", result); HILOGI("result = %{public}d", result);
@ -1455,11 +1434,6 @@ int32_t DistributedSchedStub::StartRemoteFreeInstallInner(MessageParcel& data, M
HILOGE("read callback failed!"); HILOGE("read callback failed!");
return ERR_NULL_OBJECT; return ERR_NULL_OBJECT;
} }
if (DistributedSchedPermission::GetInstance().CheckPermission(accessToken,
PERMISSION_DISTRIBUTED_DATASYNC) != ERR_OK) {
HILOGE("check data_sync permission failed!");
return DMS_PERMISSION_DENIED;
}
int32_t result = StartRemoteFreeInstall(*want, callerUid, requestCode, accessToken, callback); int32_t result = StartRemoteFreeInstall(*want, callerUid, requestCode, accessToken, callback);
HILOGI("result = %{public}d", result); HILOGI("result = %{public}d", result);
PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result); PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);
@ -1571,11 +1545,6 @@ int32_t DistributedSchedStub::StopRemoteExtensionAbilityInner(MessageParcel& dat
int32_t serviceType = 0; int32_t serviceType = 0;
PARCEL_READ_HELPER(data, Int32, serviceType); PARCEL_READ_HELPER(data, Int32, serviceType);
HILOGD("get callerUid = %{private}d, AccessTokenID = %{private}u", callerUid, accessToken); HILOGD("get callerUid = %{private}d, AccessTokenID = %{private}u", callerUid, accessToken);
if (DistributedSchedPermission::GetInstance().CheckPermission(accessToken,
PERMISSION_DISTRIBUTED_DATASYNC) != ERR_OK) {
HILOGE("check data_sync permission failed!");
return DMS_PERMISSION_DENIED;
}
auto result = StopRemoteExtensionAbility(*want, callerUid, accessToken, serviceType); auto result = StopRemoteExtensionAbility(*want, callerUid, accessToken, serviceType);
HILOGD("StartRemoteAbilityInner result = %{public}d", result); HILOGD("StartRemoteAbilityInner result = %{public}d", result);
PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result); PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result);

View File

@ -33,7 +33,6 @@ using namespace OHOS::Security;
namespace OHOS { namespace OHOS {
namespace DistributedSchedule { namespace DistributedSchedule {
const std::string TAG = "DmsTokenCallback"; const std::string TAG = "DmsTokenCallback";
const std::string PERMISSION_DISTRIBUTED_DATASYNC = "ohos.permission.DISTRIBUTED_DATASYNC";
const std::string FOUNDATION_PROCESS_NAME = "foundation"; const std::string FOUNDATION_PROCESS_NAME = "foundation";
const std::string DMS_SRC_NETWORK_ID = "dmsSrcNetworkId"; const std::string DMS_SRC_NETWORK_ID = "dmsSrcNetworkId";

View File

@ -359,6 +359,10 @@ bool DmsBmStorage::CheckSyncData(const std::string &networkId)
} }
HILOGE("uuid: %{public}s", GetAnonymStr(uuid).c_str()); HILOGE("uuid: %{public}s", GetAnonymStr(uuid).c_str());
std::vector<Entry> newEntries; std::vector<Entry> newEntries;
if (kvStorePtr_ == nullptr) {
HILOGE("kvstore is null");
return false;
}
Status status = kvStorePtr_->GetDeviceEntries(uuid, newEntries); Status status = kvStorePtr_->GetDeviceEntries(uuid, newEntries);
if (newEntries.empty() || status != Status::SUCCESS) { if (newEntries.empty() || status != Status::SUCCESS) {
HILOGE("CheckSyncData fail: %{public}d", status); HILOGE("CheckSyncData fail: %{public}d", status);
@ -402,6 +406,10 @@ void DmsBmStorage::GetEntries(const std::string &networkId, const Key &allEntryK
std::promise<OHOS::DistributedKv::Status> &resultStatusSignal, std::vector<Entry> &allEntries) std::promise<OHOS::DistributedKv::Status> &resultStatusSignal, std::vector<Entry> &allEntries)
{ {
HILOGI("called."); HILOGI("called.");
if (kvStorePtr_ == nullptr) {
HILOGE("kvstore is null");
return;
}
kvStorePtr_->GetEntries(allEntryKeyPrefix, networkId, kvStorePtr_->GetEntries(allEntryKeyPrefix, networkId,
[&resultStatusSignal, &allEntries](Status innerStatus, std::vector<Entry> innerAllEntries) { [&resultStatusSignal, &allEntries](Status innerStatus, std::vector<Entry> innerAllEntries) {
HILOGI("GetEntries, result = %{public}d", innerStatus); HILOGI("GetEntries, result = %{public}d", innerStatus);

View File

@ -59,7 +59,7 @@ bool PublicRecordsInfo::Marshalling(Parcel &parcel) const
PublicRecordsInfo *PublicRecordsInfo::Unmarshalling(Parcel &parcel) PublicRecordsInfo *PublicRecordsInfo::Unmarshalling(Parcel &parcel)
{ {
PublicRecordsInfo *info = new (std::nothrow) PublicRecordsInfo(); PublicRecordsInfo *info = new (std::nothrow) PublicRecordsInfo();
if (info && !info->ReadFromParcel(parcel)) { if (info != nullptr && !info->ReadFromParcel(parcel)) {
APP_LOGW("read from parcel failed"); APP_LOGW("read from parcel failed");
delete info; delete info;
info = nullptr; info = nullptr;
@ -152,7 +152,7 @@ bool DmsAbilityInfo::Marshalling(Parcel &parcel) const
DmsAbilityInfo *DmsAbilityInfo::Unmarshalling(Parcel &parcel) DmsAbilityInfo *DmsAbilityInfo::Unmarshalling(Parcel &parcel)
{ {
DmsAbilityInfo *info = new (std::nothrow) DmsAbilityInfo(); DmsAbilityInfo *info = new (std::nothrow) DmsAbilityInfo();
if (info && !info->ReadFromParcel(parcel)) { if (info != nullptr && !info->ReadFromParcel(parcel)) {
APP_LOGW("read from parcel failed"); APP_LOGW("read from parcel failed");
delete info; delete info;
info = nullptr; info = nullptr;
@ -270,7 +270,7 @@ bool DmsBundleInfo::Marshalling(Parcel &parcel) const
DmsBundleInfo *DmsBundleInfo::Unmarshalling(Parcel &parcel) DmsBundleInfo *DmsBundleInfo::Unmarshalling(Parcel &parcel)
{ {
DmsBundleInfo *info = new (std::nothrow) DmsBundleInfo(); DmsBundleInfo *info = new (std::nothrow) DmsBundleInfo();
if (info && !info->ReadFromParcel(parcel)) { if (info != nullptr && !info->ReadFromParcel(parcel)) {
delete info; delete info;
info = nullptr; info = nullptr;
} }

View File

@ -383,6 +383,10 @@ int32_t DistributedSchedMissionManager::StartSyncRemoteMissions(const std::strin
int32_t DistributedSchedMissionManager::StartSyncRemoteMissions(const std::string& dstDevId, int32_t DistributedSchedMissionManager::StartSyncRemoteMissions(const std::string& dstDevId,
const sptr<IDistributedSched>& remoteDms) const sptr<IDistributedSched>& remoteDms)
{ {
if (remoteDms == nullptr) {
HILOGE("remoteDms is null");
return INVALID_PARAMETERS_ERR;
}
std::vector<DstbMissionInfo> missionInfos; std::vector<DstbMissionInfo> missionInfos;
CallerInfo callerInfo; CallerInfo callerInfo;
if (!GenerateCallerInfo(callerInfo)) { if (!GenerateCallerInfo(callerInfo)) {
@ -523,7 +527,7 @@ int32_t DistributedSchedMissionManager::StartSyncMissionsFromRemote(const Caller
InitAllSnapshots(missionInfoSet); InitAllSnapshots(missionInfoSet);
} }
}; };
if (!missionHandler_->PostTask(func)) { if (missionHandler_ != nullptr && !missionHandler_->PostTask(func)) {
HILOGE("post RegisterMissionListener and InitAllSnapshots Task failed"); HILOGE("post RegisterMissionListener and InitAllSnapshots Task failed");
} }
return result; return result;
@ -542,7 +546,7 @@ void DistributedSchedMissionManager::StopSyncMissionsFromRemote(const std::strin
isRegMissionChange_ = false; isRegMissionChange_ = false;
} }
}; };
if (!missionHandler_->PostTask(func)) { if (missionHandler_ != nullptr && !missionHandler_->PostTask(func)) {
HILOGE("post UnRegisterMissionListener Task failed"); HILOGE("post UnRegisterMissionListener Task failed");
} }
} }
@ -618,6 +622,10 @@ void DistributedSchedMissionManager::EnqueueCachedSnapshotInfo(const std::string
std::string keyInfo = GenerateKeyInfo(deviceId, missionId); std::string keyInfo = GenerateKeyInfo(deviceId, missionId);
auto iter = cachedSnapshotInfos_.find(keyInfo); auto iter = cachedSnapshotInfos_.find(keyInfo);
if (iter != cachedSnapshotInfos_.end()) { if (iter != cachedSnapshotInfos_.end()) {
if (iter->second == nullptr) {
HILOGE("snapshotInfo is null");
return;
}
if (snapshot->GetCreatedTime() < iter->second->GetCreatedTime()) { if (snapshot->GetCreatedTime() < iter->second->GetCreatedTime()) {
return; return;
} }
@ -627,6 +635,10 @@ void DistributedSchedMissionManager::EnqueueCachedSnapshotInfo(const std::string
int64_t oldest = -1; int64_t oldest = -1;
auto iterOldest = cachedSnapshotInfos_.end(); auto iterOldest = cachedSnapshotInfos_.end();
for (auto iterItem = cachedSnapshotInfos_.begin(); iterItem != cachedSnapshotInfos_.end(); ++iterItem) { for (auto iterItem = cachedSnapshotInfos_.begin(); iterItem != cachedSnapshotInfos_.end(); ++iterItem) {
if (iterItem->second == nullptr) {
HILOGE("snapshotInfo is null");
continue;
}
if (oldest == -1 || iterItem->second->GetLastAccessTime() < oldest) { if (oldest == -1 || iterItem->second->GetLastAccessTime() < oldest) {
oldest = iterItem->second->GetLastAccessTime(); oldest = iterItem->second->GetLastAccessTime();
iterOldest = iterItem; iterOldest = iterItem;
@ -650,6 +662,10 @@ std::unique_ptr<Snapshot> DistributedSchedMissionManager::DequeueCachedSnapshotI
auto iter = cachedSnapshotInfos_.find(GenerateKeyInfo(deviceId, missionId)); auto iter = cachedSnapshotInfos_.find(GenerateKeyInfo(deviceId, missionId));
if (iter != cachedSnapshotInfos_.end()) { if (iter != cachedSnapshotInfos_.end()) {
std::unique_ptr<Snapshot> snapshot = std::move(iter->second); std::unique_ptr<Snapshot> snapshot = std::move(iter->second);
if (snapshot == nullptr) {
HILOGE("snapshot is null");
return nullptr;
}
snapshot->UpdateLastAccessTime(GetTickCount()); snapshot->UpdateLastAccessTime(GetTickCount());
iter->second = nullptr; iter->second = nullptr;
cachedSnapshotInfos_.erase(iter); cachedSnapshotInfos_.erase(iter);
@ -778,6 +794,10 @@ void DistributedSchedMissionManager::NotifyLocalMissionsChanged()
HILOGI("NotifyMissionsChangedToRemote result = %{public}d", result); HILOGI("NotifyMissionsChangedToRemote result = %{public}d", result);
} }
}; };
if (missionChangeHandler_ == nullptr) {
HILOGE("missionChangeHandler_ is null");
return;
}
if (!missionChangeHandler_->PostTask(func)) { if (!missionChangeHandler_->PostTask(func)) {
HILOGE("postTask failed"); HILOGE("postTask failed");
} }
@ -792,6 +812,10 @@ void DistributedSchedMissionManager::NotifyMissionSnapshotCreated(int32_t missio
HILOGE("mission snapshot changed failed, missionId=%{public}d, errCode=%{public}d", missionId, errCode); HILOGE("mission snapshot changed failed, missionId=%{public}d, errCode=%{public}d", missionId, errCode);
} }
}; };
if (missionChangeHandler_ == nullptr) {
HILOGE("missionChangeHandler_ is null");
return;
}
if (!missionChangeHandler_->PostTask(func, GET_FOREGROUND_SNAPSHOT_DELAY_TIME)) { if (!missionChangeHandler_->PostTask(func, GET_FOREGROUND_SNAPSHOT_DELAY_TIME)) {
HILOGE("post MissionSnapshotChanged delay Task failed"); HILOGE("post MissionSnapshotChanged delay Task failed");
} }
@ -806,6 +830,10 @@ void DistributedSchedMissionManager::NotifyMissionSnapshotChanged(int32_t missio
HILOGE("mission snapshot changed failed, missionId=%{public}d, errCode=%{public}d", missionId, errCode); HILOGE("mission snapshot changed failed, missionId=%{public}d, errCode=%{public}d", missionId, errCode);
} }
}; };
if (missionChangeHandler_ == nullptr) {
HILOGE("missionChangeHandler_ is null");
return;
}
if (!missionChangeHandler_->PostTask(func)) { if (!missionChangeHandler_->PostTask(func)) {
HILOGE("post MissionSnapshotChanged Task failed"); HILOGE("post MissionSnapshotChanged Task failed");
} }
@ -820,6 +848,10 @@ void DistributedSchedMissionManager::NotifyMissionSnapshotDestroyed(int32_t miss
HILOGE("mission snapshot removed failed, missionId=%{public}d, errCode=%{public}d", missionId, errCode); HILOGE("mission snapshot removed failed, missionId=%{public}d, errCode=%{public}d", missionId, errCode);
} }
}; };
if (missionChangeHandler_ == nullptr) {
HILOGE("missionChangeHandler_ is null");
return;
}
if (!missionChangeHandler_->PostTask(func)) { if (!missionChangeHandler_->PostTask(func)) {
HILOGE("post MissionSnapshotDestroyed Task failed"); HILOGE("post MissionSnapshotDestroyed Task failed");
} }
@ -964,7 +996,9 @@ void DistributedSchedMissionManager::OnMissionListenerDied(const sptr<IRemoteObj
++iterItem; ++iterItem;
continue; continue;
} }
remote->RemoveDeathRecipient(listenerDeath_); if (remote != nullptr) {
remote->RemoveDeathRecipient(listenerDeath_);
}
listenerInfo.Erase(remote); listenerInfo.Erase(remote);
if (listenerInfo.Empty()) { if (listenerInfo.Empty()) {
if (listenerInfo.called) { if (listenerInfo.called) {
@ -988,7 +1022,7 @@ void DistributedSchedMissionManager::OnRemoteDmsDied(const sptr<IRemoteObject>&
{ {
std::lock_guard<std::mutex> autoLock(remoteDmsLock_); std::lock_guard<std::mutex> autoLock(remoteDmsLock_);
for (auto iter = remoteDmsMap_.begin(); iter != remoteDmsMap_.end(); ++iter) { for (auto iter = remoteDmsMap_.begin(); iter != remoteDmsMap_.end(); ++iter) {
if (iter->second->AsObject() == remote) { if (iter->second->AsObject() == remote && iter->second->AsObject() != nullptr) {
iter->second->AsObject()->RemoveDeathRecipient(remoteDmsRecipient_); iter->second->AsObject()->RemoveDeathRecipient(remoteDmsRecipient_);
devId = iter->first; devId = iter->first;
remoteDmsMap_.erase(iter); remoteDmsMap_.erase(iter);

View File

@ -72,7 +72,7 @@ void DMSContinueRecvMgr::Init()
void DMSContinueRecvMgr::UnInit() void DMSContinueRecvMgr::UnInit()
{ {
HILOGI("UnInit start"); HILOGI("UnInit start");
if (eventHandler_ != nullptr) { if (eventHandler_ != nullptr && eventHandler_->GetEventRunner() != nullptr) {
eventHandler_->GetEventRunner()->Stop(); eventHandler_->GetEventRunner()->Stop();
eventThread_.join(); eventThread_.join();
eventHandler_ = nullptr; eventHandler_ = nullptr;
@ -191,7 +191,11 @@ void DMSContinueRecvMgr::StartEvent()
eventHandler_ = std::make_shared<OHOS::AppExecFwk::EventHandler>(runner); eventHandler_ = std::make_shared<OHOS::AppExecFwk::EventHandler>(runner);
} }
eventCon_.notify_one(); eventCon_.notify_one();
runner->Run(); if (runner != nullptr) {
runner->Run();
} else {
HILOGE("runner is null");
}
HILOGI("StartEvent end"); HILOGI("StartEvent end");
} }

View File

@ -83,7 +83,7 @@ void DMSContinueSendMgr::UnInit()
{ {
HILOGI("UnInit start"); HILOGI("UnInit start");
MMIAdapter::GetInstance().UnInit(); MMIAdapter::GetInstance().UnInit();
if (eventHandler_ != nullptr) { if (eventHandler_ != nullptr && eventHandler_->GetEventRunner() != nullptr) {
eventHandler_->GetEventRunner()->Stop(); eventHandler_->GetEventRunner()->Stop();
eventThread_.join(); eventThread_.join();
eventHandler_ = nullptr; eventHandler_ = nullptr;
@ -96,14 +96,20 @@ void DMSContinueSendMgr::UnInit()
int32_t DMSContinueSendMgr::GetCurrentMissionId() int32_t DMSContinueSendMgr::GetCurrentMissionId()
{ {
HILOGI("GetCurrentMission begin"); HILOGI("GetCurrentMission begin");
auto abilityMgr = AAFwk::AbilityManagerClient::GetInstance();
if (abilityMgr == nullptr) {
HILOGE("abilityMgr is nullptr");
return INVALID_PARAMETERS_ERR;
}
sptr<IRemoteObject> token; sptr<IRemoteObject> token;
int ret = AAFwk::AbilityManagerClient::GetInstance()->GetTopAbility(token); int ret = abilityMgr->GetTopAbility(token);
if (ret != ERR_OK || token == nullptr) { if (ret != ERR_OK || token == nullptr) {
HILOGE("GetTopAbility failed, ret: %{public}d", ret); HILOGE("GetTopAbility failed, ret: %{public}d", ret);
return INVALID_MISSION_ID; return INVALID_MISSION_ID;
} }
int32_t missionId = INVALID_MISSION_ID; int32_t missionId = INVALID_MISSION_ID;
AAFwk::AbilityManagerClient::GetInstance()->GetMissionIdByToken(token, missionId); abilityMgr->GetMissionIdByToken(token, missionId);
return missionId; return missionId;
} }
@ -142,7 +148,7 @@ void DMSContinueSendMgr::NotifyMissionFocused(const int32_t missionId, FocusedRe
return; return;
} }
auto feedfunc = [this, missionId, reason]() { auto feedfunc = [this, missionId, reason]() {
if (reason == FocusedReason::NORMAL) { if (reason == FocusedReason::NORMAL && screenOffHandler_ != nullptr) {
screenOffHandler_->ClearScreenOffInfo(); screenOffHandler_->ClearScreenOffInfo();
} }
DealFocusedBusiness(missionId); DealFocusedBusiness(missionId);
@ -190,7 +196,7 @@ int32_t DMSContinueSendMgr::GetMissionIdByBundleName(const std::string& bundleNa
return ERR_OK; return ERR_OK;
} }
HILOGW("get iterItem failed from focusedMission_, try screenOffHandler_"); HILOGW("get iterItem failed from focusedMission_, try screenOffHandler_");
if (bundleName == screenOffHandler_->GetBundleName()) { if (screenOffHandler_ != nullptr && bundleName == screenOffHandler_->GetBundleName()) {
missionId = screenOffHandler_->GetMissionId(); missionId = screenOffHandler_->GetMissionId();
HILOGI("get missionId end, missionId: %{public}d", missionId); HILOGI("get missionId end, missionId: %{public}d", missionId);
return ERR_OK; return ERR_OK;
@ -209,7 +215,11 @@ void DMSContinueSendMgr::StartEvent()
eventHandler_ = std::make_shared<OHOS::AppExecFwk::EventHandler>(runner); eventHandler_ = std::make_shared<OHOS::AppExecFwk::EventHandler>(runner);
} }
eventCon_.notify_one(); eventCon_.notify_one();
runner->Run(); if (runner != nullptr) {
runner->Run();
} else {
HILOGE("runner is null");
}
HILOGI("StartEvent end"); HILOGI("StartEvent end");
} }
@ -260,10 +270,16 @@ int32_t DMSContinueSendMgr::DealFocusedBusiness(const int32_t missionId)
{ {
HILOGI("DealFocusedBusiness start, missionId: %{public}d", missionId); HILOGI("DealFocusedBusiness start, missionId: %{public}d", missionId);
AAFwk::MissionInfo info; AAFwk::MissionInfo info;
int32_t ret = AAFwk::AbilityManagerClient::GetInstance()->GetMissionInfo("", missionId, info); auto abilityMgr = AAFwk::AbilityManagerClient::GetInstance();
if (ret != ERR_OK) { if (abilityMgr != nullptr) {
HILOGE("get missionInfo failed, missionId: %{public}d, ret: %{public}d", missionId, ret); int32_t ret = abilityMgr->GetMissionInfo("", missionId, info);
return ret; if (ret != ERR_OK) {
HILOGE("get missionInfo failed, missionId: %{public}d, ret: %{public}d", missionId, ret);
return ret;
}
} else {
HILOGE("abilityMgr is null");
return INVALID_PARAMETERS_ERR;
} }
bool isMissionContinuable = info.continuable; bool isMissionContinuable = info.continuable;
{ {
@ -295,7 +311,7 @@ int32_t DMSContinueSendMgr::DealFocusedBusiness(const int32_t missionId)
AddMMIListener(); AddMMIListener();
#endif #endif
if (!SwitchStatusDependency::GetInstance().IsContinueSwitchOn()) { return DMS_PERMISSION_DENIED;} if (!SwitchStatusDependency::GetInstance().IsContinueSwitchOn()) { return DMS_PERMISSION_DENIED;}
ret = FocusedBusinessSendEvent(bundleName, abilityName); int32_t ret = FocusedBusinessSendEvent(bundleName, abilityName);
HILOGI("DealFocusedBusiness end"); HILOGI("DealFocusedBusiness end");
return ret; return ret;
} }
@ -327,8 +343,14 @@ int32_t DMSContinueSendMgr::FocusedBusinessSendEvent(std::string bundleName, con
int32_t DMSContinueSendMgr::CheckContinueState(const int32_t missionId) int32_t DMSContinueSendMgr::CheckContinueState(const int32_t missionId)
{ {
auto abilityMgr = AAFwk::AbilityManagerClient::GetInstance();
if (abilityMgr == nullptr) {
HILOGE("abilityMgr is null");
return INVALID_PARAMETERS_ERR;
}
AAFwk::MissionInfo info; AAFwk::MissionInfo info;
int32_t ret = AAFwk::AbilityManagerClient::GetInstance()->GetMissionInfo("", missionId, info); int32_t ret = abilityMgr->GetMissionInfo("", missionId, info);
if (ret != ERR_OK) { if (ret != ERR_OK) {
HILOGE("get missionInfo failed, missionId: %{public}d, ret: %{public}d", missionId, ret); HILOGE("get missionInfo failed, missionId: %{public}d, ret: %{public}d", missionId, ret);
return ERR_OK; return ERR_OK;
@ -390,7 +412,7 @@ int32_t DMSContinueSendMgr::DealUnfocusedBusiness(const int32_t missionId, Unfoc
focusedMissionAbility_.erase(missionId); focusedMissionAbility_.erase(missionId);
} }
if (reason == UnfocusedReason::NORMAL) { if (reason == UnfocusedReason::NORMAL && screenOffHandler_ != nullptr) {
screenOffHandler_->SetScreenOffInfo(missionId, bundleName, bundleNameId, abilityName); screenOffHandler_->SetScreenOffInfo(missionId, bundleName, bundleNameId, abilityName);
} }
HILOGI("DealUnfocusedBusiness end"); HILOGI("DealUnfocusedBusiness end");
@ -399,6 +421,10 @@ int32_t DMSContinueSendMgr::DealUnfocusedBusiness(const int32_t missionId, Unfoc
int32_t DMSContinueSendMgr::SendScreenOffEvent(uint8_t type) int32_t DMSContinueSendMgr::SendScreenOffEvent(uint8_t type)
{ {
if (screenOffHandler_ == nullptr) {
HILOGE("screenOffHandler_ is nullptr");
return INVALID_PARAMETERS_ERR;
}
int32_t missionId = screenOffHandler_->GetMissionId(); int32_t missionId = screenOffHandler_->GetMissionId();
std::string bundleName = screenOffHandler_->GetBundleName(); std::string bundleName = screenOffHandler_->GetBundleName();
uint16_t bundleNameId = screenOffHandler_->GetAccessTokenId(); uint16_t bundleNameId = screenOffHandler_->GetAccessTokenId();
@ -455,7 +481,7 @@ int32_t DMSContinueSendMgr::GetAbilityNameByMissionId(const int32_t missionId, s
return ERR_OK; return ERR_OK;
} }
HILOGW("get iterItem failed from focusedMissionAbility_, try screenOffHandler_"); HILOGW("get iterItem failed from focusedMissionAbility_, try screenOffHandler_");
if (missionId == screenOffHandler_->GetMissionId()) { if (screenOffHandler_ != nullptr && missionId == screenOffHandler_->GetMissionId()) {
abilityName = screenOffHandler_->GetAbilityName(); abilityName = screenOffHandler_->GetAbilityName();
HILOGI("get missionId end, abilityName: %{public}s", abilityName.c_str()); HILOGI("get missionId end, abilityName: %{public}s", abilityName.c_str());
return ERR_OK; return ERR_OK;
@ -606,7 +632,9 @@ void DMSContinueSendMgr::OnDeviceScreenOff()
} }
int32_t missionId = info_.currentMissionId; int32_t missionId = info_.currentMissionId;
auto feedfunc = [this, missionId]() { auto feedfunc = [this, missionId]() {
screenOffHandler_->OnDeviceScreenOff(missionId); if (screenOffHandler_ != nullptr) {
screenOffHandler_->OnDeviceScreenOff(missionId);
}
}; };
if (eventHandler_ == nullptr) { if (eventHandler_ == nullptr) {
HILOGE("eventHandler_ is nullptr"); HILOGE("eventHandler_ is nullptr");
@ -619,7 +647,9 @@ void DMSContinueSendMgr::OnDeviceScreenOn()
{ {
HILOGI("OnDeviceScreenOn called"); HILOGI("OnDeviceScreenOn called");
auto feedfunc = [this]() { auto feedfunc = [this]() {
screenOffHandler_->OnDeviceScreenOn(); if (screenOffHandler_ != nullptr) {
screenOffHandler_->OnDeviceScreenOn();
}
}; };
if (eventHandler_ == nullptr) { if (eventHandler_ == nullptr) {
HILOGE("eventHandler_ is nullptr"); HILOGE("eventHandler_ is nullptr");
@ -709,7 +739,7 @@ int32_t DMSContinueSendMgr::GetAccessTokenIdSendEvent(std::string bundleName,
return ret; return ret;
} }
if (screenOffHandler_->IsDeviceScreenOn()) { if (screenOffHandler_ != nullptr && screenOffHandler_->IsDeviceScreenOn()) {
ret = SendSoftbusEvent(bundleNameId, continueTypeId, DMS_UNFOCUSED_TYPE); ret = SendSoftbusEvent(bundleNameId, continueTypeId, DMS_UNFOCUSED_TYPE);
bool res = (reason != UnfocusedReason::TIMEOUT) bool res = (reason != UnfocusedReason::TIMEOUT)
? DmsRadar::GetInstance().NormalUnfocusedSendEventRes("SendSoftbusEvent", ret) ? DmsRadar::GetInstance().NormalUnfocusedSendEventRes("SendSoftbusEvent", ret)

View File

@ -59,6 +59,9 @@ int32_t SnapshotConverter::ConvertToSnapshot(AAFwk::MissionSnapshot& missionSnap
int32_t SnapshotConverter::ConvertToSnapshot(AAFwk::MissionSnapshot& missionSnapshot, int32_t SnapshotConverter::ConvertToSnapshot(AAFwk::MissionSnapshot& missionSnapshot,
std::unique_ptr<Snapshot>& snapshot) std::unique_ptr<Snapshot>& snapshot)
{ {
if (snapshot == nullptr) {
return INVALID_PARAMETERS_ERR;
}
snapshot->version_ = DMS_VERSION; snapshot->version_ = DMS_VERSION;
snapshot->orientation_ = 0; snapshot->orientation_ = 0;
std::unique_ptr<Rect> contentInsets = std::make_unique<Rect>(0, 0, 0, 0); std::unique_ptr<Rect> contentInsets = std::make_unique<Rect>(0, 0, 0, 0);
@ -92,8 +95,10 @@ int32_t SnapshotConverter::ConvertToSnapshot(AAFwk::MissionSnapshot& missionSnap
int32_t SnapshotConverter::ConvertToMissionSnapshot(Snapshot& snapshot, int32_t SnapshotConverter::ConvertToMissionSnapshot(Snapshot& snapshot,
std::unique_ptr<AAFwk::MissionSnapshot>& missionSnapshot) std::unique_ptr<AAFwk::MissionSnapshot>& missionSnapshot)
{ {
missionSnapshot->snapshot = snapshot.pixelMap_; if (missionSnapshot != nullptr) {
missionSnapshot->snapshot = snapshot.pixelMap_;
}
return ERR_OK; return ERR_OK;
} }
} } // namespace DistributedSchedule
} } // namespace OHOS

View File

@ -58,6 +58,10 @@ int32_t SoftbusAdapter::StopSoftbusEvent()
static void EventListenerReceived(const EventNotify *eventNotify) static void EventListenerReceived(const EventNotify *eventNotify)
{ {
HILOGD("called."); HILOGD("called.");
if (eventNotify == nullptr) {
HILOGE("eventNotify is null");
return;
}
std::string networkId(eventNotify->senderNetworkId); std::string networkId(eventNotify->senderNetworkId);
SoftbusAdapter::GetInstance().OnBroadCastRecv(networkId, eventNotify->data, eventNotify->dataLen); SoftbusAdapter::GetInstance().OnBroadCastRecv(networkId, eventNotify->data, eventNotify->dataLen);
} }

View File

@ -76,6 +76,10 @@ bool DSchedSoftbusSession::OnDisconnect()
int32_t DSchedSoftbusSession::OnBytesReceived(std::shared_ptr<DSchedDataBuffer> buffer) int32_t DSchedSoftbusSession::OnBytesReceived(std::shared_ptr<DSchedDataBuffer> buffer)
{ {
HILOGD("called"); HILOGD("called");
if (buffer == nullptr) {
HILOGE("buffer is null");
return INVALID_PARAMETERS_ERR;
}
PackRecvData(buffer); PackRecvData(buffer);
return ERR_OK; return ERR_OK;
} }
@ -83,6 +87,10 @@ int32_t DSchedSoftbusSession::OnBytesReceived(std::shared_ptr<DSchedDataBuffer>
int32_t DSchedSoftbusSession::SendData(std::shared_ptr<DSchedDataBuffer> buffer, int32_t dataType) int32_t DSchedSoftbusSession::SendData(std::shared_ptr<DSchedDataBuffer> buffer, int32_t dataType)
{ {
HILOGD("called"); HILOGD("called");
if (buffer == nullptr) {
HILOGE("buffer is null");
return INVALID_PARAMETERS_ERR;
}
UnPackSendData(buffer, dataType); UnPackSendData(buffer, dataType);
return ERR_OK; return ERR_OK;
} }

View File

@ -106,10 +106,13 @@ int32_t DSchedTransportSoftbusAdapter::ConnectDevice(const std::string &peerDevi
HILOGI("try to connect peer: %{public}s.", GetAnonymStr(peerDeviceId).c_str()); HILOGI("try to connect peer: %{public}s.", GetAnonymStr(peerDeviceId).c_str());
{ {
std::lock_guard<std::mutex> sessionLock(sessionMutex_); std::lock_guard<std::mutex> sessionLock(sessionMutex_);
if (!sessions_.empty()) { if (sessions_.empty()) {
for (auto iter = sessions_.begin(); iter != sessions_.end(); iter++) { return INVALID_SESSION_ID;
if (iter->second != nullptr && peerDeviceId == iter->second->GetPeerDeviceId()) { }
HILOGI("peer device already connected"); for (auto iter = sessions_.begin(); iter != sessions_.end(); iter++) {
if (iter->second != nullptr && peerDeviceId == iter->second->GetPeerDeviceId()) {
HILOGI("peer device already connected");
if (sessions_[iter->first] != nullptr) {
sessions_[iter->first]->OnConnect(); sessions_[iter->first]->OnConnect();
return iter->first; return iter->first;
} }
@ -194,7 +197,7 @@ void DSchedTransportSoftbusAdapter::DisconnectDevice(const std::string &peerDevi
break; break;
} }
} }
if (sessionId != 0 && sessions_[sessionId]->OnDisconnect()) { if (sessionId != 0 && sessions_[sessionId] != nullptr && sessions_[sessionId]->OnDisconnect()) {
HILOGI("peer %{public}s shutdown, socket sessionId: %{public}d.", HILOGI("peer %{public}s shutdown, socket sessionId: %{public}d.",
GetAnonymStr(sessions_[sessionId]->GetPeerDeviceId()).c_str(), sessionId); GetAnonymStr(sessions_[sessionId]->GetPeerDeviceId()).c_str(), sessionId);
Shutdown(sessionId); Shutdown(sessionId);
@ -221,7 +224,7 @@ void DSchedTransportSoftbusAdapter::OnShutdown(int32_t sessionId, bool isSelfcal
{ {
{ {
std::lock_guard<std::mutex> sessionLock(sessionMutex_); std::lock_guard<std::mutex> sessionLock(sessionMutex_);
if (sessions_.empty() || sessions_.count(sessionId) == 0) { if (sessions_.empty() || sessions_.count(sessionId) == 0 || sessions_[sessionId] == nullptr) {
HILOGE("error, invalid sessionId %{public}d", sessionId); HILOGE("error, invalid sessionId %{public}d", sessionId);
return; return;
} }
@ -255,8 +258,10 @@ int32_t DSchedTransportSoftbusAdapter::ReleaseChannel()
{ {
std::lock_guard<std::mutex> sessionLock(sessionMutex_); std::lock_guard<std::mutex> sessionLock(sessionMutex_);
for (auto iter = sessions_.begin(); iter != sessions_.end(); iter++) { for (auto iter = sessions_.begin(); iter != sessions_.end(); iter++) {
HILOGI("shutdown client: %{public}s, socket sessionId: %{public}d.", if (iter->second != nullptr) {
GetAnonymStr(iter->second->GetPeerDeviceId()).c_str(), iter->first); HILOGI("shutdown client: %{public}s, socket sessionId: %{public}d.",
GetAnonymStr(iter->second->GetPeerDeviceId()).c_str(), iter->first);
}
Shutdown(iter->first); Shutdown(iter->first);
} }
sessions_.clear(); sessions_.clear();
@ -271,7 +276,7 @@ int32_t DSchedTransportSoftbusAdapter::SendData(int32_t sessionId, int32_t dataT
std::shared_ptr<DSchedDataBuffer> dataBuffer) std::shared_ptr<DSchedDataBuffer> dataBuffer)
{ {
std::lock_guard<std::mutex> sessionLock(sessionMutex_); std::lock_guard<std::mutex> sessionLock(sessionMutex_);
if (!sessions_.count(sessionId)) { if (!sessions_.count(sessionId) || sessions_[sessionId] == nullptr) {
HILOGE("error, invalid session id %{public}d", sessionId); HILOGE("error, invalid session id %{public}d", sessionId);
return INVALID_SESSION_ID; return INVALID_SESSION_ID;
} }
@ -281,7 +286,12 @@ int32_t DSchedTransportSoftbusAdapter::SendData(int32_t sessionId, int32_t dataT
int32_t DSchedTransportSoftbusAdapter::SendBytesBySoftbus(int32_t sessionId, int32_t DSchedTransportSoftbusAdapter::SendBytesBySoftbus(int32_t sessionId,
std::shared_ptr<DSchedDataBuffer> dataBuffer) std::shared_ptr<DSchedDataBuffer> dataBuffer)
{ {
return SendBytes(sessionId, dataBuffer->Data(), dataBuffer->Size()); if (dataBuffer != nullptr) {
return SendBytes(sessionId, dataBuffer->Data(), dataBuffer->Size());
} else {
HILOGE("dataBuffer is nullptr");
return INVALID_PARAMETERS_ERR;
}
} }
void DSchedTransportSoftbusAdapter::OnBytes(int32_t sessionId, const void *data, uint32_t dataLen) void DSchedTransportSoftbusAdapter::OnBytes(int32_t sessionId, const void *data, uint32_t dataLen)
@ -293,7 +303,7 @@ void DSchedTransportSoftbusAdapter::OnBytes(int32_t sessionId, const void *data,
HILOGD("start, sessionId: %{public}d", sessionId); HILOGD("start, sessionId: %{public}d", sessionId);
{ {
std::lock_guard<std::mutex> sessionLock(sessionMutex_); std::lock_guard<std::mutex> sessionLock(sessionMutex_);
if (!sessions_.count(sessionId)) { if (!sessions_.count(sessionId) || sessions_[sessionId] == nullptr) {
HILOGE("invalid session id %{public}d", sessionId); HILOGE("invalid session id %{public}d", sessionId);
return; return;
} }