mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-11-23 06:20:07 +00:00
退账号时,删除云端数据
Signed-off-by: m30043719 <maxiaodong25@huawei.com>
This commit is contained in:
parent
6e43a796af
commit
a8cfebdf26
@ -73,6 +73,7 @@ private:
|
||||
static std::set<std::shared_ptr<DeviceListener>> listenerSet_;
|
||||
|
||||
std::shared_ptr<DistributedHardware::DeviceStateCallback> stateCallback_;
|
||||
std::shared_ptr<DistributedHardware::DevTrustChangeCallback> devTrustChangeCallback_;
|
||||
std::shared_ptr<DistributedHardware::DmInitCallback> initCallback_;
|
||||
class DeviceInitCallBack : public DistributedHardware::DmInitCallback {
|
||||
void OnRemoteDied() override;
|
||||
@ -84,6 +85,11 @@ class DmsDeviceStateCallback : public DistributedHardware::DeviceStateCallback {
|
||||
void OnDeviceChanged(const DistributedHardware::DmDeviceInfo& deviceInfo) override;
|
||||
void OnDeviceReady(const DistributedHardware::DmDeviceInfo& deviceInfo) override;
|
||||
};
|
||||
|
||||
class DmsDevTrustChangeCallback : public DistributedHardware::DevTrustChangeCallback {
|
||||
void OnDeviceTrustChange(const std::string &udid, const std::string &uuid,
|
||||
const DistributedHardware::DmAuthForm authform) override;
|
||||
};
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
@ -76,6 +76,7 @@ public:
|
||||
uint32_t result, const std::string& bundleName);
|
||||
void DmsPutBatch(const std::vector<DmsBundleInfo> &dmsBundleInfos);
|
||||
bool UpdatePublicRecords(const std::string &localUdid);
|
||||
bool DelDataOfLogoutDev(const std::string &udid, const std::string &uuid);
|
||||
|
||||
private:
|
||||
std::string DeviceAndNameToKey(const std::string &udid, const std::string &bundleName) const;
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "distributed_sched_utils.h"
|
||||
#include "dtbschedmgr_device_info_storage.h"
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "mission/distributed_bm_storage.h"
|
||||
#include "mission/dsched_sync_e2e.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -56,6 +57,7 @@ void DnetworkAdapter::Init()
|
||||
{
|
||||
initCallback_ = std::make_shared<DeviceInitCallBack>();
|
||||
stateCallback_ = std::make_shared<DmsDeviceStateCallback>();
|
||||
devTrustChangeCallback_ = std::make_shared<DmsDevTrustChangeCallback>();
|
||||
auto runner = AppExecFwk::EventRunner::Create("dmsDnetwork");
|
||||
dnetworkHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
|
||||
}
|
||||
@ -117,6 +119,23 @@ void DnetworkAdapter::DmsDeviceStateCallback::OnDeviceReady(const DmDeviceInfo&
|
||||
HILOGI("called");
|
||||
}
|
||||
|
||||
void DnetworkAdapter::DmsDevTrustChangeCallback::OnDeviceTrustChange(const std::string &udid,
|
||||
const std::string &uuid, const DmAuthForm authform)
|
||||
{
|
||||
HILOGI("called");
|
||||
if (udid.empty() || uuid.empty()) {
|
||||
HILOGE("udid or uuid is empty!");
|
||||
return;
|
||||
}
|
||||
if (authform != DmAuthForm::IDENTICAL_ACCOUNT) {
|
||||
HILOGE("peer is not same account");
|
||||
return;
|
||||
}
|
||||
if (DmsBmStorage::GetInstance()->DelDataOfLogoutDev(udid, uuid)) {
|
||||
HILOGE("DelDataOfLogoutDev failed");
|
||||
}
|
||||
}
|
||||
|
||||
bool DnetworkAdapter::AddDeviceChangeListener(const std::shared_ptr<DeviceListener>& listener)
|
||||
{
|
||||
HILOGD("AddDeviceChangeListener called");
|
||||
|
@ -855,6 +855,39 @@ void DmsBmStorage::DmsPutBatch(const std::vector<DmsBundleInfo> &dmsBundleInfos)
|
||||
HILOGI("end.");
|
||||
}
|
||||
|
||||
bool DmsBmStorage::DelDataOfLogoutDev(const std::string &udid, const std::string &uuid)
|
||||
{
|
||||
if (!CheckKvStore()) {
|
||||
HILOGE("kvStore is nullptr");
|
||||
return false;
|
||||
}
|
||||
if (udid.empty() || uuid.empty()) {
|
||||
HILOGE("udid or uuid is empty!");
|
||||
return false;
|
||||
}
|
||||
Key remoteKeyPrefix(udid);
|
||||
std::vector<Entry> remoteEntries;
|
||||
Status status = kvStorePtr_->GetEntries(remoteKeyPrefix, remoteEntries);
|
||||
if (status != Status::SUCCESS || remoteEntries.empty()) {
|
||||
HILOGE("GetEntries error: %{public}d, or remoteEntries is empty", status);
|
||||
return false;
|
||||
}
|
||||
std::vector<Key> remoteKeyArr;
|
||||
for (auto remoteEntry : remoteEntries) {
|
||||
remoteKeyArr.push_back(remoteEntry.key);
|
||||
}
|
||||
status = kvStorePtr_->DeleteBatch(remoteKeyArr);
|
||||
if (status != Status::SUCCESS) {
|
||||
HILOGE("DeleteBatch error: %{public}d", status);
|
||||
return false;
|
||||
}
|
||||
if (kvStorePtr_->RemoveDeviceData(uuid) != Status::SUCCESS) {
|
||||
HILOGE("RemoveDeviceData fail, uuid=%{public}s", GetAnonymStr(uuid).c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void DmsBmStorage::AddBundleNameId(const uint16_t &bundleNameId, const std::string &bundleName)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock_l(mutex_);
|
||||
|
@ -544,5 +544,25 @@ HWTEST_F(DistributedBmStorageTest, ConvertToDistributedBundleInfoTest_001, TestS
|
||||
}
|
||||
DTEST_LOG << "DistributedBmStorageTest ConvertToDistributedBundleInfoTest_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DmsPutBatchTest_001
|
||||
* @tc.desc: test delete DistributedBmStorage
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DistributedBmStorageTest, DelDataOfLogoutDevTest_001, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "DistributedBmStorageTest DelDataOfLogoutDevTest_001 start" << std::endl;
|
||||
ASSERT_NE(dmsBmStorage_, nullptr);
|
||||
auto distributedDataStorage = GetDmsBmStorage();
|
||||
EXPECT_NE(distributedDataStorage, nullptr);
|
||||
if (distributedDataStorage != nullptr) {
|
||||
const std::string udid = "";
|
||||
const std::string uuid = "";
|
||||
bool ret = dmsBmStorage_->GetInstance()->DelDataOfLogoutDev(udid, uuid);
|
||||
EXPECT_EQ(ret, false);
|
||||
}
|
||||
DTEST_LOG << "DistributedBmStorageTest DelDataOfLogoutDevTest_001 end" << std::endl;
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
Loading…
Reference in New Issue
Block a user