mirror of
https://gitee.com/openharmony/distributedhardware_distributed_hardware_fwk
synced 2024-11-23 15:50:09 +00:00
commit
b3af831f59
@ -29,7 +29,8 @@ namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class AccessManager : public std::enable_shared_from_this<AccessManager>,
|
||||
public DmInitCallback,
|
||||
public DeviceStateCallback {
|
||||
public DeviceStateCallback,
|
||||
public DevTrustChangeCallback {
|
||||
public:
|
||||
AccessManager(const AccessManager &) = delete;
|
||||
AccessManager &operator = (const AccessManager &) = delete;
|
||||
@ -46,6 +47,8 @@ public:
|
||||
virtual void OnDeviceOffline(const DmDeviceInfo &deviceInfo) override;
|
||||
virtual void OnDeviceReady(const DmDeviceInfo &deviceInfo) override;
|
||||
virtual void OnDeviceChanged(const DmDeviceInfo &deviceInfo) override;
|
||||
virtual void OnDeviceTrustChange(const std::string &peerudid, const std::string &peeruuid,
|
||||
DmAuthForm authform) override;
|
||||
/* Send device online event which is already online */
|
||||
void CheckTrustedDeviceOnline();
|
||||
int32_t Dump(const std::vector<std::string> &argsStr, std::string &result);
|
||||
@ -55,6 +58,7 @@ private:
|
||||
int32_t UnRegisterDevStateCallback();
|
||||
int32_t InitDeviceManager();
|
||||
int32_t UnInitDeviceManager();
|
||||
int32_t RegDevTrustChangeCallback();
|
||||
std::mutex accessMutex_;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
|
@ -36,6 +36,7 @@ public:
|
||||
int32_t SendOffLineEvent(const std::string &networkId, const std::string &uuid, const std::string &udid,
|
||||
uint16_t deviceType);
|
||||
int32_t GetComponentVersion(std::unordered_map<DHType, std::string> &versionMap);
|
||||
void ClearDataWhenPeerLogout(const std::string &peerudid, const std::string &peeruuid);
|
||||
|
||||
int Dump(const std::vector<std::string> &argsStr, std::string &result);
|
||||
void UnInit();
|
||||
|
@ -54,6 +54,7 @@ public:
|
||||
int32_t RemoveDataByKey(const std::string &key);
|
||||
std::vector<DistributedKv::Entry> GetEntriesByKeys(const std::vector<std::string> &keys);
|
||||
bool SyncDataByNetworkId(const std::string &networkId);
|
||||
bool ClearDataWhenPeerLogout(const std::string &peerudid, const std::string &peeruuid);
|
||||
|
||||
private:
|
||||
int32_t RegisterChangeListener();
|
||||
|
@ -51,6 +51,7 @@ public:
|
||||
std::vector<std::shared_ptr<MetaCapabilityInfo>> &metaCapInfos);
|
||||
int32_t GetMetaDataByDHType(const DHType dhType, MetaCapInfoMap &metaInfoMap);
|
||||
int32_t SyncDataByNetworkId(const std::string &networkId);
|
||||
int32_t ClearDataWhenPeerLogout(const std::string &peerudid, const std::string &peeruuid);
|
||||
/* Database data changes callback */
|
||||
virtual void OnChange(const DistributedKv::ChangeNotification &changeNotification) override;
|
||||
/* Cloud data changes callback */
|
||||
|
@ -58,6 +58,10 @@ int32_t AccessManager::Init()
|
||||
DHLOGE("RegisterDevStateCallback failed");
|
||||
return ERR_DH_FWK_ACCESS_REGISTER_DM_FAILED;
|
||||
}
|
||||
if (RegDevTrustChangeCallback() != DH_FWK_SUCCESS) {
|
||||
DHLOGE("RegDevTrustChangeCallback failed");
|
||||
return ERR_DH_FWK_ACCESS_REGISTER_DM_FAILED;
|
||||
}
|
||||
return DH_FWK_SUCCESS;
|
||||
}
|
||||
|
||||
@ -98,6 +102,11 @@ int32_t AccessManager::UnRegisterDevStateCallback()
|
||||
return DeviceManager::GetInstance().UnRegisterDevStateCallback(DH_FWK_PKG_NAME);
|
||||
}
|
||||
|
||||
int32_t AccessManager::RegDevTrustChangeCallback()
|
||||
{
|
||||
return DeviceManager::GetInstance().RegDevTrustChangeCallback(DH_FWK_PKG_NAME, shared_from_this());
|
||||
}
|
||||
|
||||
void AccessManager::OnRemoteDied()
|
||||
{
|
||||
for (int32_t tryCount = 0; tryCount < DH_RETRY_INIT_DM_COUNT; ++tryCount) {
|
||||
@ -176,6 +185,21 @@ void AccessManager::OnDeviceChanged(const DmDeviceInfo &deviceInfo)
|
||||
return;
|
||||
}
|
||||
|
||||
void AccessManager::OnDeviceTrustChange(const std::string &peerudid, const std::string &peeruuid, DmAuthForm authform)
|
||||
{
|
||||
DHLOGI("Peerdevice logout, peerudid: %{public}s, peeruuid: %{public}s", GetAnonyString(peerudid).c_str(),
|
||||
GetAnonyString(peeruuid).c_str());
|
||||
if (!IsIdLengthValid(peerudid) || !IsIdLengthValid(peeruuid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (authform != DmAuthForm::IDENTICAL_ACCOUNT) {
|
||||
DHLOGE("Peer is not same account");
|
||||
return;
|
||||
}
|
||||
DistributedHardwareManagerFactory::GetInstance().ClearDataWhenPeerLogout(peerudid, peeruuid);
|
||||
}
|
||||
|
||||
void AccessManager::CheckTrustedDeviceOnline()
|
||||
{
|
||||
std::vector<DmDeviceInfo> deviceList;
|
||||
|
@ -236,5 +236,11 @@ bool DistributedHardwareManagerFactory::GetUnInitFlag()
|
||||
{
|
||||
return flagUnInit_.load();
|
||||
}
|
||||
|
||||
void DistributedHardwareManagerFactory::ClearDataWhenPeerLogout(const std::string &peerudid,
|
||||
const std::string &peeruuid)
|
||||
{
|
||||
MetaInfoManager::GetInstance()->ClearDataWhenPeerLogout(peerudid, peeruuid);
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
@ -551,6 +551,11 @@ std::vector<DistributedKv::Entry> DBAdapter::GetEntriesByKeys(const std::vector<
|
||||
bool DBAdapter::SyncDataByNetworkId(const std::string &networkId)
|
||||
{
|
||||
DHLOGI("Try initiative sync data by networId: %{public}s", GetAnonyString(networkId).c_str());
|
||||
std::lock_guard<std::mutex> lock(dbAdapterMutex_);
|
||||
if (kvStoragePtr_ == nullptr) {
|
||||
DHLOGE("kvStoragePtr_ is nullptr!");
|
||||
return false;
|
||||
}
|
||||
std::vector<std::string> networkIdVec;
|
||||
networkIdVec.push_back(networkId);
|
||||
DistributedKv::Status status = kvStoragePtr_->Sync(networkIdVec, DistributedKv::SyncMode::PUSH_PULL);
|
||||
@ -560,5 +565,38 @@ bool DBAdapter::SyncDataByNetworkId(const std::string &networkId)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DBAdapter::ClearDataWhenPeerLogout(const std::string &peerudid, const std::string &peeruuid)
|
||||
{
|
||||
DHLOGI("Clear cloudData start.");
|
||||
std::lock_guard<std::mutex> lock(dbAdapterMutex_);
|
||||
if (kvStoragePtr_ == nullptr) {
|
||||
DHLOGE("kvStoragePtr_ is nullptr!");
|
||||
return false;
|
||||
}
|
||||
std::string udIdHash = Sha256(peerudid);
|
||||
DistributedKv::Key allEntryKeyPrefix(udIdHash);
|
||||
std::vector<DistributedKv::Entry> peerEntries;
|
||||
DistributedKv::Status status = kvStoragePtr_->GetEntries(allEntryKeyPrefix, peerEntries);
|
||||
if (status != DistributedKv::Status::SUCCESS || peerEntries.size() == 0) {
|
||||
DHLOGE("GetEntries error: %{public}d, or peerEntries is empty", status);
|
||||
return false;
|
||||
}
|
||||
std::vector<DistributedKv::Key> peerkeys;
|
||||
for (const auto &entry : peerEntries) {
|
||||
peerkeys.push_back(entry.key);
|
||||
}
|
||||
|
||||
if (kvStoragePtr_->DeleteBatch(peerkeys) != DistributedKv::Status::SUCCESS) {
|
||||
DHLOGE("DeleteBatch failed, error: %{public}d", status);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (kvStoragePtr_->RemoveDeviceData(peeruuid) != DistributedKv::Status::SUCCESS) {
|
||||
DHLOGE("RemoveDeviceData failed, peeruuid=%{public}s", GetAnonyString(peeruuid).c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
@ -339,6 +339,16 @@ int32_t MetaInfoManager::SyncDataByNetworkId(const std::string &networkId)
|
||||
return DH_FWK_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t MetaInfoManager::ClearDataWhenPeerLogout(const std::string &peerudid, const std::string &peeruuid)
|
||||
{
|
||||
if (dbAdapterPtr_ == nullptr) {
|
||||
DHLOGE("dbAdapterPtr is null");
|
||||
return ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL;
|
||||
}
|
||||
dbAdapterPtr_->ClearDataWhenPeerLogout(peerudid, peeruuid);
|
||||
return DH_FWK_SUCCESS;
|
||||
}
|
||||
|
||||
void MetaInfoManager::OnChange(const DistributedKv::ChangeNotification &changeNotification)
|
||||
{
|
||||
DHLOGI("MetaInfoManager: DB data OnChange");
|
||||
|
@ -1219,5 +1219,18 @@ HWTEST_F(ResourceManagerTest, SyncDataByNetworkId_001, TestSize.Level0)
|
||||
ret = MetaInfoManager::GetInstance()->SyncDataByNetworkId(networkId);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceManagerTest, ClearDataWhenPeerLogout_001, TestSize.Level0)
|
||||
{
|
||||
MetaInfoManager::GetInstance()->Init();
|
||||
std::string peerudid = "peerudid_test";
|
||||
std::string peeruuid = "peeruuid_test";
|
||||
auto ret = MetaInfoManager::GetInstance()->ClearDataWhenPeerLogout(peerudid, peeruuid);
|
||||
EXPECT_EQ(DH_FWK_SUCCESS, ret);
|
||||
|
||||
MetaInfoManager::GetInstance()->dbAdapterPtr_ = nullptr;
|
||||
ret = MetaInfoManager::GetInstance()->ClearDataWhenPeerLogout(peerudid, peeruuid);
|
||||
EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret);
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user