diff --git a/common/include/constants/distributed_device_profile_constants.h b/common/include/constants/distributed_device_profile_constants.h index ac16a04fc864c856a9e12898fd9cee5c6bbb90fc..02c274d8ac7ecb11f0f8fb385e9dd655db466885 100644 --- a/common/include/constants/distributed_device_profile_constants.h +++ b/common/include/constants/distributed_device_profile_constants.h @@ -339,6 +339,7 @@ extern const std::string CREATE_TURST_DEVICE_TABLE_UNIQUE_INDEX_SQL; extern const std::string CREATE_ACCESS_CONTROL_TABLE_UNIQUE_INDEX_SQL; extern const std::string CREATE_ACCESSER_TABLE_UNIQUE_INDEX_SQL; extern const std::string CREATE_ACCESSEE_TABLE_UNIQUE_INDEX_SQL; +extern const std::string PRAGMA_ACCESSEE_TABLE; extern const std::string DROP_OLD_UNIQUE_INDEX_ON_ACER; extern const std::string DROP_OLD_UNIQUE_INDEX_ON_ACEE; extern const std::string ALTER_TABLE_ACCESS_CONTROL_ADD_COLUMN_EXTRA_DATA; diff --git a/common/src/constants/distributed_device_profile_constants.cpp b/common/src/constants/distributed_device_profile_constants.cpp index 62bd445ca0e9b22f69cf0d720550b41a14290bbe..87ad9c09976b29d73560e2226c4f3fd92aabcee0 100644 --- a/common/src/constants/distributed_device_profile_constants.cpp +++ b/common/src/constants/distributed_device_profile_constants.cpp @@ -350,6 +350,7 @@ const std::string CREATE_ACCESSEE_TABLE_UNIQUE_INDEX_SQL = accesseeCredentialIdStr,\ accesseeStatus,\ accesseeSessionKeyId);"; +const std::string PRAGMA_ACCESSEE_TABLE = "PRAGMA table_info(accessee_table)"; const std::string DROP_OLD_UNIQUE_INDEX_ON_ACER = "DROP INDEX unique_accesser_table"; const std::string DROP_OLD_UNIQUE_INDEX_ON_ACEE = "DROP INDEX unique_accessee_table"; const std::string ALTER_TABLE_ACCESS_CONTROL_ADD_COLUMN_EXTRA_DATA = @@ -375,7 +376,7 @@ const std::string ALTER_TABLE_ACEE_ADD_COLUMN_ACEE_DEVICE_NAME = const std::string ALTER_TABLE_ACEE_ADD_COLUMN_ACEE_SERVICE_NAME = "ALTER TABLE accessee_table ADD COLUMN accesseeServiceName TEXT DEFAULT ''"; const std::string ALTER_TABLE_ACEE_ADD_COLUMN_ACEE_CREDENTIAL_ID = - "ALTER TABLE accessee_table ADD COLUMN accesserCredentialId INTERGER DEFAULT -1"; + "ALTER TABLE accessee_table ADD COLUMN accesseeCredentialId INTERGER DEFAULT -1"; const std::string ALTER_TABLE_ACEE_ADD_COLUMN_ACEE_CREDENTIAL_ID_STR = "ALTER TABLE accessee_table ADD COLUMN accesseeCredentialIdStr TEXT DEFAULT ''"; const std::string ALTER_TABLE_ACEE_ADD_COLUMN_ACEE_STATUS = diff --git a/services/core/include/trustprofilemanager/trust_profile_manager.h b/services/core/include/trustprofilemanager/trust_profile_manager.h index c1464b39cce0d27814b6a5f1ad8ea49ecff3d888..30801df3a2dd7f0706a2d08cad3bb803a6a1a357 100644 --- a/services/core/include/trustprofilemanager/trust_profile_manager.h +++ b/services/core/include/trustprofilemanager/trust_profile_manager.h @@ -128,6 +128,8 @@ private: int32_t NotifyCheck(const AccessControlProfile& profile, const AccessControlProfile& oldProfile); void RemoveLnnAcl(std::vector& profiles); bool IsLnnAcl(const AccessControlProfile& aclProfile); + bool IsAcerCreIdExistToAceeTable(); + int32_t AddAceeCreIdColumnToAceeTable(); private: std::shared_ptr rdbStore_; diff --git a/services/core/src/trustprofilemanager/trust_profile_manager.cpp b/services/core/src/trustprofilemanager/trust_profile_manager.cpp index 2a3b64f524d34447d166faf1e857ac05a7db63e8..395048f92ff94691592f6d6414888010a07ac23c 100644 --- a/services/core/src/trustprofilemanager/trust_profile_manager.cpp +++ b/services/core/src/trustprofilemanager/trust_profile_manager.cpp @@ -30,6 +30,7 @@ namespace DistributedDeviceProfile { IMPLEMENT_SINGLE_INSTANCE(TrustProfileManager); namespace { const std::string TAG = "TrustProfileManager"; + const std::string NAME = "name"; } int32_t TrustProfileManager::Init() @@ -49,6 +50,10 @@ int32_t TrustProfileManager::Init() } this->CreateTable(); this->CreateUniqueIndex(); + if (IsAcerCreIdExistToAceeTable() && AddAceeCreIdColumnToAceeTable() != DP_SUCCESS) { + HILOGE("acee table add aceeCreId failed"); + return DP_CREATE_TABLE_FAIL; + } HILOGI("end!"); return DP_SUCCESS; } @@ -2177,5 +2182,40 @@ bool TrustProfileManager::IsLnnAcl(const AccessControlProfile& aclProfile) cJSON_Delete(json); return false; } + +bool TrustProfileManager::IsAcerCreIdExistToAceeTable() +{ + std::shared_ptr resultSet = GetResultSet(PRAGMA_ACCESSEE_TABLE, std::vector{}); + if (resultSet == nullptr) { + HILOGE("resultSet is nullptr"); + return false; + } + while (resultSet->GoToNextRow() == DP_SUCCESS) { + int32_t columnIndex = COLUMNINDEX_INIT; + std::string columnName; + resultSet->GetColumnIndex(NAME, columnIndex); + resultSet->GetString(columnIndex, columnName); + if (columnName == ACCESSER_CREDENTIAL_ID) { + HILOGE("acerCreId exist to acee_table"); + return true; + } + } + return false; +} + +int32_t TrustProfileManager::AddAceeCreIdColumnToAceeTable() +{ + std::lock_guard lock(rdbMutex_); + if (rdbStore_ == nullptr) { + HILOGE("rdbStore_ is nullptr"); + return DP_GET_RDBSTORE_FAIL; + } + int32_t ret = rdbStore_->CreateTable(ALTER_TABLE_ACEE_ADD_COLUMN_ACEE_CREDENTIAL_ID); + if (ret != DP_SUCCESS) { + HILOGE("add column accesseeCredentialId to acee table failed"); + return DP_CREATE_TABLE_FAIL; + } + return DP_SUCCESS; +} } // namespace DistributedDeviceProfile } // namespace OHOS \ No newline at end of file