mirror of
https://github.com/openharmony/distributeddatamgr_datamgr.git
synced 2026-06-30 22:17:55 -04:00
+1
-1
@@ -98,7 +98,7 @@ DATABASE_BEHAVIOUR:
|
||||
ANONYMOUS_UID: {type: STRING, desc: uid with anonymous }
|
||||
APP_ID: {type: STRING, desc: app id }
|
||||
STORE_ID: {type: STRING, desc: store id }
|
||||
BEHAVIOUR_INFO: {type: INT32, desc: behaviour id }
|
||||
BEHAVIOUR_INFO: {type: STRING, desc: behaviour type and behaviour resulte }
|
||||
|
||||
OPEN_DATABASE_FAILED:
|
||||
__BASE: {type: FAULT, level: CRITICAL, desc: The database open failed}
|
||||
|
||||
@@ -146,13 +146,16 @@ void HiViewAdapter::ReportBehaviour(int dfxCode, const BehaviourMsg &msg)
|
||||
return;
|
||||
}
|
||||
KvStoreTask task([dfxCode, msg]() {
|
||||
std::string message;
|
||||
message.append("Behaviour type : ").append(std::to_string(static_cast<int>(msg.behaviourType)))
|
||||
.append(" behaviour result : ").append(std::to_string(static_cast<int>(msg.behaviourResult)));
|
||||
HiSysEvent::Write(HiSysEvent::Domain::DISTRIBUTED_DATAMGR,
|
||||
CoverEventID(dfxCode),
|
||||
HiSysEvent::EventType::BEHAVIOR,
|
||||
USER_ID, msg.userId,
|
||||
APP_ID, msg.appId,
|
||||
STORE_ID, msg.storeId,
|
||||
BEHAVIOUR_INFO, static_cast<int>(msg.behaviourType));
|
||||
BEHAVIOUR_INFO, message);
|
||||
});
|
||||
pool_->AddTask(std::move(task));
|
||||
}
|
||||
|
||||
@@ -77,10 +77,13 @@ enum class FaultType {
|
||||
};
|
||||
|
||||
enum class BehaviourType {
|
||||
DATABASE_BACKUP_SUCCESS = 0,
|
||||
DATABASE_BACKUP_FAILED = 1,
|
||||
DATABASE_RECOVERY_SUCCESS = 3,
|
||||
DATABASE_RECOVERY_FAILED = 4,
|
||||
DATABASE_BACKUP = 0,
|
||||
DATABASE_RECOVERY = 1,
|
||||
};
|
||||
|
||||
enum class BehaviourResult {
|
||||
BEHAVIOUR_SUCCESS = 0,
|
||||
BEHAVIOUR_FAILED = 1,
|
||||
};
|
||||
|
||||
enum class SecurityInfo {
|
||||
@@ -132,6 +135,7 @@ struct BehaviourMsg {
|
||||
std::string appId;
|
||||
std::string storeId;
|
||||
BehaviourType behaviourType;
|
||||
BehaviourResult behaviourResult;
|
||||
};
|
||||
|
||||
struct VisitStat {
|
||||
|
||||
@@ -38,7 +38,6 @@ ohos_sa_profile("distributeddata_profile") {
|
||||
config("module_private_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [
|
||||
"//foundation/distributeddatamgr/appdatamgr/interfaces/inner_api/native/preferences/include",
|
||||
"//foundation/distributeddatamgr/distributeddatamgr/frameworks/common",
|
||||
"//foundation/distributeddatamgr/distributeddatamgr/frameworks/innerkitsimpl/distributeddatafwk/include",
|
||||
"//foundation/distributeddatamgr/distributeddatamgr/services/distributeddataservice/service/bootstrap/include",
|
||||
@@ -128,7 +127,6 @@ ohos_shared_library("distributeddataservice") {
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"huks:libhukssdk",
|
||||
"ipc:ipc_core",
|
||||
"preferences:native_preferences",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr_standard:samgr_proxy",
|
||||
"startup_l2:syspara",
|
||||
|
||||
@@ -126,12 +126,14 @@ void BackupHandler::SingleKvStoreBackup(const StoreMetaData &metaData)
|
||||
ZLOGD("SingleKvStoreBackup export success.");
|
||||
RemoveFile(backupBackFullName);
|
||||
Reporter::GetInstance()->BehaviourReporter()->Report(
|
||||
{metaData.account, metaData.appId, metaData.storeId, BehaviourType::DATABASE_BACKUP_SUCCESS});
|
||||
{metaData.account, metaData.appId, metaData.storeId,
|
||||
BehaviourType::DATABASE_BACKUP, BehaviourResult::BEHAVIOUR_SUCCESS});
|
||||
} else {
|
||||
ZLOGE("SingleKvStoreBackup export failed, status is %d.", status);
|
||||
RenameFile(backupBackFullName, backupFullName);
|
||||
Reporter::GetInstance()->BehaviourReporter()->Report(
|
||||
{metaData.account, metaData.appId, metaData.storeId, BehaviourType::DATABASE_BACKUP_FAILED});
|
||||
{metaData.account, metaData.appId, metaData.storeId,
|
||||
BehaviourType::DATABASE_BACKUP, BehaviourResult::BEHAVIOUR_FAILED});
|
||||
}
|
||||
}
|
||||
delegateMgr.CloseKvStore(delegate);
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
#include "kvstore_app_accessor.h"
|
||||
#include "kvstore_utils.h"
|
||||
#include "log_print.h"
|
||||
#include "metadata/corrupted_meta_data.h"
|
||||
#include "metadata/meta_data_manager.h"
|
||||
#include "permission_validator.h"
|
||||
#include "reporter.h"
|
||||
#include "route_head_handler_impl.h"
|
||||
@@ -240,6 +242,8 @@ Status KvStoreAppManager::DeleteKvStore(const std::string &storeId)
|
||||
Status statusDE = DeleteKvStore(storeId, PATH_DE);
|
||||
Status statusCE = DeleteKvStore(storeId, PATH_CE);
|
||||
if (statusDE == Status::SUCCESS || statusCE == Status::SUCCESS) {
|
||||
CorruptedMetaData corruptedMetaData = CorruptedMetaData(trueAppId_, bundleName_, storeId);
|
||||
MetaDataManager::GetInstance().DelMeta(corruptedMetaData.GetKey(), true);
|
||||
return Status::SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "ikvstore_data_service.h"
|
||||
#include "kvstore_device_listener.h"
|
||||
#include "kvstore_user_manager.h"
|
||||
#include "metadata/corrupted_meta_data.h"
|
||||
#include "metadata/store_meta_data.h"
|
||||
#include "reporter.h"
|
||||
#include "security/security.h"
|
||||
@@ -52,6 +53,7 @@ class KvStoreDataService : public SystemAbility, public KvStoreDataServiceStub {
|
||||
DECLARE_SYSTEM_ABILITY(KvStoreDataService);
|
||||
|
||||
public:
|
||||
using CorruptedMetaData = DistributedData::CorruptedMetaData;
|
||||
using StoreMetaData = DistributedData::StoreMetaData;
|
||||
// record kvstore meta version for compatible, should update when modify kvstore meta structure.
|
||||
static constexpr uint32_t STORE_VERSION = 0x03000001;
|
||||
|
||||
@@ -29,9 +29,6 @@
|
||||
#include "ipc_skeleton.h"
|
||||
#include "log_print.h"
|
||||
#include "permission_validator.h"
|
||||
#include "preferences.h"
|
||||
#include "preferences_errno.h"
|
||||
#include "preferences_helper.h"
|
||||
#include "query_helper.h"
|
||||
#include "reporter.h"
|
||||
#include "upgrade_manager.h"
|
||||
@@ -41,7 +38,6 @@
|
||||
|
||||
namespace OHOS::DistributedKv {
|
||||
using namespace OHOS::DistributedData;
|
||||
using namespace OHOS::NativePreferences;
|
||||
static bool TaskIsBackground(pid_t pid)
|
||||
{
|
||||
std::ifstream ifs("/proc/" + std::to_string(pid) + "/cgroup", std::ios::in);
|
||||
@@ -136,24 +132,18 @@ Status SingleKvStoreImpl::CheckDbIsCorrupted(DistributedDB::DBStatus status, con
|
||||
|
||||
bool SingleKvStoreImpl::IsDbCorruptedFirstTime(bool corruptedStatus) const
|
||||
{
|
||||
int errCode = E_OK;
|
||||
std::string prefKey = bundleName_ + storeId_;
|
||||
std::shared_ptr<Preferences> pref = PreferencesHelper::GetPreferences(Constant::ROOT_PATH_PERF, errCode);
|
||||
if ((errCode =! E_OK) || pref == nullptr) {
|
||||
return true;
|
||||
}
|
||||
CorruptedMetaData corruptedMetaData = CorruptedMetaData(appId_, bundleName_, storeId_);
|
||||
MetaDataManager::GetInstance().LoadMeta(corruptedMetaData.GetKey(), corruptedMetaData, true);
|
||||
if (corruptedStatus) {
|
||||
auto ret = pref->GetBool(prefKey, false);
|
||||
if (ret) {
|
||||
if (corruptedMetaData.CorruptedStatus == true) {
|
||||
return false;
|
||||
} else {
|
||||
pref->PutBool(prefKey, corruptedStatus);
|
||||
pref->Flush();
|
||||
corruptedMetaData.CorruptedStatus = true;
|
||||
MetaDataManager::GetInstance().SaveMeta(corruptedMetaData.GetKey(), corruptedMetaData, true);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
pref->Delete(prefKey);
|
||||
pref->Flush();
|
||||
MetaDataManager::GetInstance().DelMeta(corruptedMetaData.GetKey(), true);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
@@ -1439,8 +1429,8 @@ bool SingleKvStoreImpl::Import(const std::string &bundleName) const
|
||||
auto result = std::make_unique<BackupHandler>()->SingleKvStoreRecover(metaData, kvStoreNbDelegate_);
|
||||
(void) IsDbCorruptedFirstTime((!result));
|
||||
Reporter::GetInstance()->BehaviourReporter()->Report(
|
||||
{ deviceAccountId_, bundleName_, storeId_,
|
||||
(result) ? BehaviourType::DATABASE_RECOVERY_SUCCESS : BehaviourType::DATABASE_RECOVERY_FAILED });
|
||||
{ deviceAccountId_, bundleName_, storeId_, BehaviourType::DATABASE_RECOVERY,
|
||||
(result) ? BehaviourResult::BEHAVIOUR_FAILED : BehaviourResult::BEHAVIOUR_FAILED });
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ ohos_shared_library("distributeddatasvcfwk") {
|
||||
"eventcenter/event_center.cpp",
|
||||
"metadata/capability_meta_data.cpp",
|
||||
"metadata/capability_range.cpp",
|
||||
"metadata/corrupted_meta_data.cpp",
|
||||
"metadata/meta_data.cpp",
|
||||
"metadata/meta_data_manager.cpp",
|
||||
"metadata/secret_key_meta_data.cpp",
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef DISTRIBUTEDDATAMGR_CORRUPTED_META_DATA_H
|
||||
#define DISTRIBUTEDDATAMGR_CORRUPTED_META_DATA_H
|
||||
#include "serializable/serializable.h"
|
||||
namespace OHOS {
|
||||
namespace DistributedData {
|
||||
struct API_EXPORT CorruptedMetaData final : public Serializable {
|
||||
std::string appId = "";
|
||||
std::string bundleName = "";
|
||||
std::string storeId = "";
|
||||
bool CorruptedStatus = false;
|
||||
API_EXPORT CorruptedMetaData();
|
||||
API_EXPORT CorruptedMetaData(const std::string &appId, const std::string &bundleName, const std::string &storeId);
|
||||
API_EXPORT ~CorruptedMetaData();
|
||||
API_EXPORT bool Marshal(json &node) const override;
|
||||
API_EXPORT bool Unmarshal(const json &node) override;
|
||||
|
||||
API_EXPORT std::string GetKey();
|
||||
private:
|
||||
static constexpr const char *PREFIX = "CorruptedMetaData";
|
||||
};
|
||||
} // namespace DistributedData
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // DISTRIBUTEDDATAMGR_CORRUPTED_META_DATA_H
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "metadata/corrupted_meta_data.h"
|
||||
|
||||
#include "utils/constant.h"
|
||||
namespace OHOS {
|
||||
namespace DistributedData {
|
||||
|
||||
bool CorruptedMetaData::Marshal(json &node) const
|
||||
{
|
||||
SetValue(node[GET_NAME(appId)], appId);
|
||||
SetValue(node[GET_NAME(bundleName)], bundleName);
|
||||
SetValue(node[GET_NAME(storeId)], storeId);
|
||||
SetValue(node[GET_NAME(CorruptedStatus)], CorruptedStatus);
|
||||
return true;
|
||||
}
|
||||
bool CorruptedMetaData::Unmarshal(const json &node)
|
||||
{
|
||||
GetValue(node, GET_NAME(appId), appId);
|
||||
GetValue(node, GET_NAME(bundleName), bundleName);
|
||||
GetValue(node, GET_NAME(storeId), storeId);
|
||||
GetValue(node, GET_NAME(CorruptedStatus), CorruptedStatus);
|
||||
return true;
|
||||
}
|
||||
|
||||
CorruptedMetaData::CorruptedMetaData()
|
||||
{
|
||||
}
|
||||
|
||||
CorruptedMetaData::~CorruptedMetaData()
|
||||
{
|
||||
}
|
||||
|
||||
CorruptedMetaData::CorruptedMetaData(
|
||||
const std::string &appId, const std::string &bundleName, const std::string &storeId)
|
||||
: appId(appId), bundleName(bundleName), storeId(storeId)
|
||||
{
|
||||
}
|
||||
|
||||
std::string CorruptedMetaData::GetKey()
|
||||
{
|
||||
return Constant::Join(PREFIX, Constant::KEY_SEPARATOR,
|
||||
{ appId, bundleName, storeId });
|
||||
}
|
||||
} // namespace DistributedData
|
||||
} // namespace OHOS
|
||||
Reference in New Issue
Block a user