diff --git a/interfaces/inner_api/appexecfwk_core/include/app_control/app_control_host.h b/interfaces/inner_api/appexecfwk_core/include/app_control/app_control_host.h index c7ef072f707572b587a274abcb81931de8b77053..0abe162574416ae6475c0716dfe227b3f85dc910 100644 --- a/interfaces/inner_api/appexecfwk_core/include/app_control/app_control_host.h +++ b/interfaces/inner_api/appexecfwk_core/include/app_control/app_control_host.h @@ -58,6 +58,7 @@ private: ErrCode HandleSetDisposedStatus(MessageParcel& data, MessageParcel& reply); ErrCode HandleDeleteDisposedStatus(MessageParcel& data, MessageParcel& reply); ErrCode HandleGetDisposedRule(MessageParcel& data, MessageParcel& reply); + ErrCode HandleGetDisposedRules(MessageParcel& data, MessageParcel& reply); ErrCode HandleSetDisposedRule(MessageParcel& data, MessageParcel& reply); ErrCode HandleSetDisposedRules(MessageParcel& data, MessageParcel& reply); ErrCode HandleDeleteDisposedRules(MessageParcel& data, MessageParcel& reply); @@ -73,6 +74,8 @@ private: DISALLOW_COPY_AND_MOVE(AppControlHost); template ErrCode GetVectorParcelInfo(MessageParcel &data, std::vector &parcelInfos); + template + ErrCode WriteVectorToParcel(std::vector &parcelVector, MessageParcel &reply); }; } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/appexecfwk_core/include/app_control/app_control_interface.h b/interfaces/inner_api/appexecfwk_core/include/app_control/app_control_interface.h index 5787776771a3ade914918c6994671fd09bb54a50..4042f02fafd0ec5b063333b65864f4024e56cdd5 100644 --- a/interfaces/inner_api/appexecfwk_core/include/app_control/app_control_interface.h +++ b/interfaces/inner_api/appexecfwk_core/include/app_control/app_control_interface.h @@ -134,6 +134,11 @@ public: { return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR; } + virtual ErrCode GetDisposedRules( + int32_t userId, std::vector& disposedRuleConfigurations) + { + return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR; + } virtual ErrCode SetDisposedRule( const std::string &appId, DisposedRule& disposedRule, int32_t userId = Constants::UNSPECIFIED_USERID) { diff --git a/interfaces/inner_api/appexecfwk_core/include/app_control/app_control_proxy.h b/interfaces/inner_api/appexecfwk_core/include/app_control/app_control_proxy.h index cb16d4289e4cc6bf455312db8f40a8160ed2c9a6..041408f54d234fb57050a85a4bb41033163a42dc 100644 --- a/interfaces/inner_api/appexecfwk_core/include/app_control/app_control_proxy.h +++ b/interfaces/inner_api/appexecfwk_core/include/app_control/app_control_proxy.h @@ -65,6 +65,8 @@ public: int32_t userId = Constants::UNSPECIFIED_USERID) override; virtual ErrCode GetDisposedRule(const std::string &appId, DisposedRule& disposedRule, int32_t userId = Constants::UNSPECIFIED_USERID) override; + virtual ErrCode GetDisposedRules( + int32_t userId, std::vector& disposedRuleConfigurations) override; virtual ErrCode SetDisposedRules(std::vector &disposedRuleConfigurations, int32_t userId) override; virtual ErrCode DeleteDisposedRules( @@ -105,6 +107,9 @@ private: static inline BrokerDelegator delegator_; template ErrCode WriteVectorToParcel(std::vector &parcelVector, MessageParcel &reply); + template + ErrCode GetVectorParcelInfo(AppControlManagerInterfaceCode code, + MessageParcel &data, std::vector &parcelInfos); }; } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/appexecfwk_core/include/bundle_framework_core_ipc_interface_code.h b/interfaces/inner_api/appexecfwk_core/include/bundle_framework_core_ipc_interface_code.h index be59b80bd80fd7deb315363bbc87c8bade0ed27f..44f2aa408ff7632c4e2481813ae79f9fee1602ce 100644 --- a/interfaces/inner_api/appexecfwk_core/include/bundle_framework_core_ipc_interface_code.h +++ b/interfaces/inner_api/appexecfwk_core/include/bundle_framework_core_ipc_interface_code.h @@ -261,6 +261,7 @@ enum class AppControlManagerInterfaceCode : uint8_t { DELETE_UNINSTALL_DISPOSED_RULE = 26, SET_DISPOSED_RULES = 27, DELETE_DISPOSED_RULES = 28, + GET_DISPOSED_RULES = 29, }; /* SAID: 401-96 Interface No.96 subservice also provides the following interfaces */ diff --git a/interfaces/inner_api/appexecfwk_core/src/app_control/app_control_host.cpp b/interfaces/inner_api/appexecfwk_core/src/app_control/app_control_host.cpp index 67b5241349027dd302c6dfc0d5953bd13345711f..ebb51e843bbea1d8f1f126d535a1b0605aed1137 100644 --- a/interfaces/inner_api/appexecfwk_core/src/app_control/app_control_host.cpp +++ b/interfaces/inner_api/appexecfwk_core/src/app_control/app_control_host.cpp @@ -137,6 +137,8 @@ int AppControlHost::OnRemoteRequest( return HandleGetUninstallDisposedRule(data, reply); case static_cast(AppControlManagerInterfaceCode::DELETE_UNINSTALL_DISPOSED_RULE): return HandleDeleteUninstallDisposedRule(data, reply); + case static_cast(AppControlManagerInterfaceCode::GET_DISPOSED_RULES): + return HandleGetDisposedRules(data, reply); default: LOG_W(BMS_TAG_DEFAULT, "AppControlHost receive unknown code, code = %{public}d", code); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); @@ -434,6 +436,24 @@ ErrCode AppControlHost::HandleGetDisposedRule(MessageParcel& data, MessageParcel return ERR_OK; } +ErrCode AppControlHost::HandleGetDisposedRules(MessageParcel& data, MessageParcel &reply) +{ + int32_t userId = data.ReadInt32(); + std::vector disposedRuleConfigurations; + ErrCode ret = GetDisposedRules(userId, disposedRuleConfigurations); + if (!reply.WriteInt32(ret)) { + LOG_E(BMS_TAG_DEFAULT, "write ret failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (ret == ERR_OK) { + if (WriteVectorToParcel(disposedRuleConfigurations, reply) != ERR_OK) { + LOG_E(BMS_TAG_DEFAULT, "write failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + } + return ERR_OK; +} + ErrCode AppControlHost::HandleSetDisposedRule(MessageParcel& data, MessageParcel& reply) { std::string appId = data.ReadString(); @@ -707,5 +727,40 @@ ErrCode AppControlHost::GetVectorParcelInfo(MessageParcel &data, std::vector return ERR_OK; } + +template +ErrCode AppControlHost::WriteVectorToParcel(std::vector &parcelVector, MessageParcel &reply) +{ + MessageParcel tempParcel; + (void)tempParcel.SetMaxCapacity(Constants::MAX_PARCEL_CAPACITY); + if (!tempParcel.WriteInt32(static_cast(parcelVector.size()))) { + APP_LOGE("write failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + for (auto &parcel : parcelVector) { + if (!tempParcel.WriteParcelable(&parcel)) { + APP_LOGE("write failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + } + std::vector().swap(parcelVector); + + size_t dataSize = tempParcel.GetDataSize(); + if (!reply.WriteUint32(dataSize)) { + APP_LOGE("write failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + if (dataSize > MAX_IPC_ALLOWED_CAPACITY) { + APP_LOGE("datasize is too large"); + return ERR_BUNDLE_MANAGER_PARAM_ERROR; + } + if (!reply.WriteRawData(reinterpret_cast(tempParcel.GetData()), dataSize)) { + APP_LOGE("write parcel failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + return ERR_OK; +} } // AppExecFwk } // OHOS diff --git a/interfaces/inner_api/appexecfwk_core/src/app_control/app_control_proxy.cpp b/interfaces/inner_api/appexecfwk_core/src/app_control/app_control_proxy.cpp index 4052b96fbd28b147d293d21d60c7d1cfc8d02a5a..72e01dbe17c6b2c24f02b937b7591d8a02598e8e 100644 --- a/interfaces/inner_api/appexecfwk_core/src/app_control/app_control_proxy.cpp +++ b/interfaces/inner_api/appexecfwk_core/src/app_control/app_control_proxy.cpp @@ -15,6 +15,8 @@ #include "app_control_proxy.h" +#include "securec.h" + #include "app_log_tag_wrapper.h" #include "app_log_wrapper.h" #include "appexecfwk_errors.h" @@ -27,6 +29,28 @@ namespace AppExecFwk { namespace { const int16_t MAX_VECTOR_NUM = 1000; constexpr size_t MAX_IPC_ALLOWED_CAPACITY = 100 * 1024 * 1024; // max ipc size 100MB +bool GetData(size_t size, const void *data, void *&buffer) +{ + if (data == nullptr) { + APP_LOGE("failed due to null data"); + return false; + } + if ((size == 0) || size > Constants::MAX_PARCEL_CAPACITY) { + APP_LOGE("failed due to wrong size"); + return false; + } + buffer = malloc(size); + if (buffer == nullptr) { + APP_LOGE("failed due to malloc buffer failed"); + return false; + } + if (memcpy_s(buffer, size, data, size) != EOK) { + free(buffer); + APP_LOGE("failed due to memcpy_s failed"); + return false; + } + return true; +} } AppControlProxy::AppControlProxy(const sptr &object) : IRemoteProxy(object) { @@ -596,6 +620,29 @@ ErrCode AppControlProxy::GetDisposedRule(const std::string &appId, DisposedRule return ERR_OK; } +ErrCode AppControlProxy::GetDisposedRules( + int32_t userId, std::vector &disposedRuleConfigurations) +{ + LOG_D(BMS_TAG_DEFAULT, "proxy begin to GetDisposedRules"); + MessageParcel data; + if (!data.WriteInterfaceToken(GetDescriptor())) { + LOG_E(BMS_TAG_DEFAULT, "WriteInterfaceToken failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + if (!data.WriteInt32(userId)) { + LOG_E(BMS_TAG_DEFAULT, "write userId failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + ErrCode ret = GetVectorParcelInfo(AppControlManagerInterfaceCode::GET_DISPOSED_RULES, + data, disposedRuleConfigurations); + if (ret != ERR_OK) { + LOG_E(BMS_TAG_DEFAULT, "host return error : %{public}d", ret); + return ret; + } + return ERR_OK; +} + ErrCode AppControlProxy::GetAbilityRunningControlRule( const std::string &bundleName, int32_t userId, std::vector &rules, int32_t appIndex) { @@ -1002,5 +1049,58 @@ ErrCode AppControlProxy::WriteVectorToParcel(std::vector &parcelVector, Messa } return ERR_OK; } + +template +ErrCode AppControlProxy::GetVectorParcelInfo(AppControlManagerInterfaceCode code, + MessageParcel &data, std::vector &parcelInfos) +{ + MessageParcel reply; + if (SendRequest(code, data, reply) != ERR_OK) { + APP_LOGE("SendTransactCmd failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + ErrCode res = reply.ReadInt32(); + if (res != ERR_OK) { + APP_LOGE("failed err %{public}d", res); + return res; + } + + size_t dataSize = reply.ReadUint32(); + if (dataSize == 0) { + APP_LOGW("Parcel no data"); + return ERR_OK; + } + + void *buffer = nullptr; + if (dataSize > MAX_IPC_ALLOWED_CAPACITY) { + APP_LOGE("dataSize is too large"); + return ERR_BUNDLE_MANAGER_PARAM_ERROR; + } else { + if (!GetData(dataSize, reply.ReadRawData(dataSize), buffer)) { + APP_LOGE("GetData failed dataSize: %{public}zu", dataSize); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + } + + MessageParcel tempParcel; + if (!tempParcel.ParseFrom(reinterpret_cast(buffer), dataSize)) { + APP_LOGE("Fail to ParseFrom"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + int32_t infoSize = tempParcel.ReadInt32(); + CONTAINER_SECURITY_VERIFY(tempParcel, infoSize, &parcelInfos); + for (int32_t i = 0; i < infoSize; i++) { + std::unique_ptr info(tempParcel.ReadParcelable()); + if (info == nullptr) { + APP_LOGE("Read Parcelable infos failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + parcelInfos.emplace_back(*info); + } + + return ERR_OK; +} } // AppExecFwk } // OHOS \ No newline at end of file diff --git a/services/bundlemgr/include/app_control/app_control_manager.h b/services/bundlemgr/include/app_control/app_control_manager.h index 3dd4c447b1edf7ad5c9529c1ef3d91529dfdf656..c79ba94a83bce2d35795a4c355defa6c00008688 100644 --- a/services/bundlemgr/include/app_control/app_control_manager.h +++ b/services/bundlemgr/include/app_control/app_control_manager.h @@ -85,6 +85,9 @@ public: ErrCode GetDisposedRule(const std::string &callerName, const std::string &appId, DisposedRule &DisposedRule, int32_t appIndex, int32_t userId); + + ErrCode GetDisposedRules(const std::string &callingName, + int32_t userId, std::vector &disposedRuleConfigurations); ErrCode DeleteDisposedRule(const std::string &callerName, const std::string &appId, int32_t appIndex, int32_t userId); diff --git a/services/bundlemgr/include/app_control/app_control_manager_db_interface.h b/services/bundlemgr/include/app_control/app_control_manager_db_interface.h index d3fb12db317a5807b409d8d61350003bdce42b30..c6e6c813a6083f614c88ebefc50110b1a80d82bb 100644 --- a/services/bundlemgr/include/app_control/app_control_manager_db_interface.h +++ b/services/bundlemgr/include/app_control/app_control_manager_db_interface.h @@ -58,6 +58,8 @@ public: const std::string &appId, const DisposedRule& rule, int32_t appIndex, int32_t userId) = 0; virtual ErrCode GetDisposedRule(const std::string &callingName, const std::string &appId, DisposedRule& rule, int32_t appIndex, int32_t userId) = 0; + virtual ErrCode GetDisposedRules(const std::string &callingName, + int32_t userId, std::vector& disposedRuleConfigurations) = 0; virtual ErrCode DeleteDisposedRule(const std::string &callingName, const std::vector &appIdList, int32_t appIndex, int32_t userId) = 0; virtual ErrCode GetAbilityRunningControlRule(const std::vector &appIdList, int32_t appIndex, diff --git a/services/bundlemgr/include/app_control/app_control_manager_host_impl.h b/services/bundlemgr/include/app_control/app_control_manager_host_impl.h index f31794973267f6a37d9e410b9e1a189a78f6debb..0aa464c373da8d7718be667c4cf819a7624c5de7 100644 --- a/services/bundlemgr/include/app_control/app_control_manager_host_impl.h +++ b/services/bundlemgr/include/app_control/app_control_manager_host_impl.h @@ -83,6 +83,9 @@ public: virtual ErrCode GetDisposedRule( const std::string &appId, DisposedRule &DisposedRule, int32_t userId) override; + virtual ErrCode GetDisposedRules( + int32_t userId, std::vector &disposedRuleConfigurations) override; + virtual ErrCode GetAbilityRunningControlRule(const std::string &bundleName, int32_t userId, std::vector& disposedRules, int32_t appIndex = Constants::MAIN_APP_INDEX) override; diff --git a/services/bundlemgr/include/app_control/app_control_manager_rdb.h b/services/bundlemgr/include/app_control/app_control_manager_rdb.h index 5a8a7e3b9208a677a96d48d8516c0e5f8b252cee..67239bb3c0400672bee58ed47597f63e8b72f618 100644 --- a/services/bundlemgr/include/app_control/app_control_manager_rdb.h +++ b/services/bundlemgr/include/app_control/app_control_manager_rdb.h @@ -55,6 +55,8 @@ public: const std::string &appId, const DisposedRule& rule, int32_t appIndex, int32_t userId) override; virtual ErrCode GetDisposedRule(const std::string &callingName, const std::string &appId, DisposedRule& rule, int32_t appIndex, int32_t userId) override; + virtual ErrCode GetDisposedRules(const std::string &callingName, + int32_t userId, std::vector &disposedRuleConfigurations) override; virtual ErrCode DeleteDisposedRule(const std::string &callingName, const std::vector &appIdList, int32_t appIndex, int32_t userId) override; virtual ErrCode DeleteAllDisposedRuleByBundle(const std::vector &appIdList, @@ -80,6 +82,9 @@ private: int32_t userId, int32_t appIndex, NativeRdb::AbsRdbPredicates &absRdbPredicates); ErrCode GetDisposedRuleFromResultSet( std::shared_ptr absSharedResultSet, std::vector &disposedRules); + ErrCode ConvertToDisposedRuleConfiguration( + const std::shared_ptr &absSharedResultSet, + DisposedRuleConfiguration &disposedRuleConfiguration); std::shared_ptr rdbDataManager_; }; } // namespace AppExecFwk diff --git a/services/bundlemgr/src/app_control/app_control_manager.cpp b/services/bundlemgr/src/app_control/app_control_manager.cpp index dc87411c5ce21f7ed06cf84eb5ec12f1ab7e9002..9bba27fa2e41b743adf019e31092e203a0914c6a 100644 --- a/services/bundlemgr/src/app_control/app_control_manager.cpp +++ b/services/bundlemgr/src/app_control/app_control_manager.cpp @@ -569,6 +569,17 @@ ErrCode AppControlManager::GetDisposedRule( return ERR_OK; } +ErrCode AppControlManager::GetDisposedRules(const std::string &callerName, + int32_t userId, std::vector &disposedRuleConfigurations) +{ + auto ret = appControlManagerDb_->GetDisposedRules(callerName, userId, disposedRuleConfigurations); + if (ret != ERR_OK) { + LOG_E(BMS_TAG_DEFAULT, "GetDisposedRules to rdb failed"); + return ret; + } + return ERR_OK; +} + ErrCode AppControlManager::DeleteDisposedRule( const std::string &callerName, const std::string &appId, int32_t appIndex, int32_t userId) { diff --git a/services/bundlemgr/src/app_control/app_control_manager_host_impl.cpp b/services/bundlemgr/src/app_control/app_control_manager_host_impl.cpp index d5432c7d7b52097b9feced9217578a7049ba0482..e9fb9422a1ca338e72be41382d94ef02a155e963 100644 --- a/services/bundlemgr/src/app_control/app_control_manager_host_impl.cpp +++ b/services/bundlemgr/src/app_control/app_control_manager_host_impl.cpp @@ -601,6 +601,37 @@ ErrCode AppControlManagerHostImpl::GetDisposedRule(const std::string &appId, Dis return ret; } +ErrCode AppControlManagerHostImpl::GetDisposedRules( + int32_t userId, std::vector &disposedRuleConfigurations) +{ + LOG_D(BMS_TAG_DEFAULT, "host begin to GetDisposedRules"); + if (!BundlePermissionMgr::IsSystemApp()) { + LOG_E(BMS_TAG_DEFAULT, "non-system app calling system api"); + return ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED; + } + if (!BundlePermissionMgr::VerifyCallingPermissionsForAll({PERMISSION_DISPOSED_STATUS, + PERMISSION_GET_DISPOSED_STATUS})) { + LOG_W(BMS_TAG_DEFAULT, "verify get disposed rule permission failed"); + return ERR_BUNDLE_MANAGER_PERMISSION_DENIED; + } + + int32_t uid = OHOS::IPCSkeleton::GetCallingUid(); + std::string callerName; + GetCallerByUid(uid, callerName); + if (userId == Constants::UNSPECIFIED_USERID) { + userId = GetCallingUserId(); + } + if (!appControlManager_) { + LOG_E(BMS_TAG_DEFAULT, "appControlManager_ is nullptr"); + return ERR_APPEXECFWK_NULL_PTR; + } + auto ret = appControlManager_->GetDisposedRules(callerName, userId, disposedRuleConfigurations); + if (ret != ERR_OK) { + LOG_W(BMS_TAG_DEFAULT, "host GetDisposedRules error:%{public}d", ret); + } + return ret; +} + ErrCode AppControlManagerHostImpl::SetDisposedRules( std::vector &disposedRuleConfigurations, int32_t userId) { diff --git a/services/bundlemgr/src/app_control/app_control_manager_rdb.cpp b/services/bundlemgr/src/app_control/app_control_manager_rdb.cpp index 336b60b9b9b38869914011b7c2d56646e46d4c67..3f34a3afbce6091c83c46ffdcb7937f0d8c86fb9 100644 --- a/services/bundlemgr/src/app_control/app_control_manager_rdb.cpp +++ b/services/bundlemgr/src/app_control/app_control_manager_rdb.cpp @@ -35,6 +35,7 @@ namespace { constexpr int8_t CONTROL_MESSAGE_INDEX = 5; constexpr int8_t DISPOSED_STATUS_INDEX = 6; constexpr int8_t TIME_STAMP_INDEX = 8; + constexpr int8_t APP_INDEX_INDEX = 9; constexpr int8_t ALLOW_RUNNING_INDEX = 10; // app control table key constexpr const char* CALLING_NAME = "CALLING_NAME"; @@ -707,6 +708,82 @@ ErrCode AppControlManagerRdb::GetDisposedRule(const std::string &callingName, return ERR_OK; } +ErrCode AppControlManagerRdb::GetDisposedRules(const std::string &callingName, + int32_t userId, std::vector &disposedRuleConfigurations) +{ + HITRACE_METER_NAME_EX(HITRACE_LEVEL_INFO, HITRACE_TAG_APP, __PRETTY_FUNCTION__, nullptr); + LOG_D(BMS_TAG_DEFAULT, "rdb begin to GetDisposedRules"); + NativeRdb::AbsRdbPredicates absRdbPredicates(APP_CONTROL_RDB_TABLE_NAME); + absRdbPredicates.EqualTo(CALLING_NAME, callingName); + absRdbPredicates.EqualTo(APP_CONTROL_LIST, DISPOSED_RULE); + absRdbPredicates.EqualTo(USER_ID, std::to_string(userId)); + auto absSharedResultSet = rdbDataManager_->QueryData(absRdbPredicates); + if (absSharedResultSet == nullptr) { + LOG_E(BMS_TAG_DEFAULT, "GetDisposedRules failed"); + return ERR_APPEXECFWK_DB_RESULT_SET_EMPTY; + } + + ScopeGuard stateGuard([&] { absSharedResultSet->Close(); }); + int32_t count; + int ret = absSharedResultSet->GetRowCount(count); + if (ret != NativeRdb::E_OK) { + LOG_E(BMS_TAG_DEFAULT, "GetRowCount failed, ret: %{public}d", ret); + return ERR_APPEXECFWK_DB_RESULT_SET_OPT_ERROR; + } + if (count == 0) { + LOG_D(BMS_TAG_DEFAULT, "GetDisposedRule size 0"); + return ERR_OK; + } + LOG_D(BMS_TAG_DEFAULT, "GetDisposedRule size:%{public}d", count); + ret = absSharedResultSet->GoToFirstRow(); + if (ret != NativeRdb::E_OK) { + LOG_E(BMS_TAG_DEFAULT, "GoToFirstRow failed, ret: %{public}d", ret); + return ERR_APPEXECFWK_DB_RESULT_SET_OPT_ERROR; + } + do { + DisposedRuleConfiguration disposedRuleConfiguration; + if (ConvertToDisposedRuleConfiguration(absSharedResultSet, disposedRuleConfiguration) == ERR_OK) { + disposedRuleConfigurations.push_back(disposedRuleConfiguration); + } + } while (absSharedResultSet->GoToNextRow() == NativeRdb::E_OK); + return ERR_OK; +} + +ErrCode AppControlManagerRdb::ConvertToDisposedRuleConfiguration( + const std::shared_ptr &absSharedResultSet, + DisposedRuleConfiguration &disposedRuleConfiguration +) +{ + if (absSharedResultSet == nullptr) { + LOG_E(BMS_TAG_DEFAULT, "ConvertToDisposedRuleConfiguration failed"); + return ERR_APPEXECFWK_DB_RESULT_SET_EMPTY; + } + std::string appIndex; + std::string ruleString; + int ret = absSharedResultSet->GetString(APP_ID_INDEX, disposedRuleConfiguration.appId); + if (ret != NativeRdb::E_OK) { + LOG_E(BMS_TAG_DEFAULT, "Get appId failed, ret: %{public}d", ret); + return ERR_APPEXECFWK_DB_RESULT_SET_OPT_ERROR; + } + + ret = absSharedResultSet->GetString(DISPOSED_STATUS_INDEX, ruleString); + if (ret != NativeRdb::E_OK) { + LOG_E(BMS_TAG_DEFAULT, "Get disposedRule failed, ret: %{public}d", ret); + return ERR_APPEXECFWK_DB_RESULT_SET_OPT_ERROR; + } + DisposedRule::FromString(ruleString, disposedRuleConfiguration.disposedRule); + + ret = absSharedResultSet->GetString(APP_INDEX_INDEX, appIndex); + if (ret != NativeRdb::E_OK) { + LOG_E(BMS_TAG_DEFAULT, "Get appIndex failed, ret: %{public}d", ret); + return ERR_APPEXECFWK_DB_RESULT_SET_OPT_ERROR; + } + if (!OHOS::StrToInt(appIndex, disposedRuleConfiguration.appIndex)) { + LOG_W(BMS_TAG_DEFAULT, "parse appIndex failed"); + } + return ERR_OK; +} + ErrCode AppControlManagerRdb::GetAbilityRunningControlRule(const std::vector &appIdList, int32_t appIndex, int32_t userId, std::vector& disposedRules) { diff --git a/services/bundlemgr/test/unittest/bms_app_control_proxy_test/bms_app_control_proxy_test.cpp b/services/bundlemgr/test/unittest/bms_app_control_proxy_test/bms_app_control_proxy_test.cpp index f216fe131d7af4d7c2e3dae209314a17036429fd..2de389f2dc5231b2bb57aa09bf999cf9a8d09c47 100644 --- a/services/bundlemgr/test/unittest/bms_app_control_proxy_test/bms_app_control_proxy_test.cpp +++ b/services/bundlemgr/test/unittest/bms_app_control_proxy_test/bms_app_control_proxy_test.cpp @@ -500,6 +500,21 @@ HWTEST_F(BmsAppControlProxyTest, GetDisposedRule_0100, Function | MediumTest | L EXPECT_EQ(res, ERR_BUNDLE_MANAGER_INTERNAL_ERROR); } +/** + * @tc.number: GetDisposedRules_0100 + * @tc.name: test the GetDisposedRules + * @tc.desc: 1. system running normally + * 2. test GetDisposedRules + */ +HWTEST_F(BmsAppControlProxyTest, GetDisposedRules_0100, Function | MediumTest | Level1) +{ + AppControlProxy appControlProxy(nullptr); + int32_t userId = 100; + std::vector disposedRuleConfigurations; + auto res = appControlProxy.GetDisposedRules(userId, disposedRuleConfigurations); + EXPECT_EQ(res, ERR_APPEXECFWK_PARCEL_ERROR); +} + /** * @tc.number: GetAbilityRunningControlRule_0100 * @tc.name: test the GetAbilityRunningControlRule diff --git a/services/bundlemgr/test/unittest/bms_bundle_app_control_test/bms_bundle_app_control_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_app_control_test/bms_bundle_app_control_test.cpp index c6db99252db1233853063c5dab7590a712778f21..559fabd5e8e625424077d98c6dbea933be7a7be4 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_app_control_test/bms_bundle_app_control_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_app_control_test/bms_bundle_app_control_test.cpp @@ -60,6 +60,7 @@ const std::string PERMISSION_DISPOSED_STATUS = "ohos.permission.MANAGE_DISPOSED_ const std::string ABILITY_RUNNING_KEY = "ABILITY_RUNNING_KEY"; const std::string INVALID_MESSAGE = "INVALID_MESSAGE"; const int32_t USERID = 100; +const int32_t TEST_USERID = 2000; const int32_t WAIT_TIME = 5; // init mocked bms const int NOT_EXIST_USERID = -5; const int ALL_USERID = -3; @@ -4312,6 +4313,145 @@ HWTEST_F(BmsBundleAppControlTest, DeleteDisposedRules_0200, Function | SmallTest EXPECT_EQ(res, ERR_OK); } +/** + * @tc.number: GetDisposedRules_0100 + * @tc.name: test GetDisposedRules by AppControlProxy + * @tc.desc: 1.GetDisposedRules test + */ +HWTEST_F(BmsBundleAppControlTest, GetDisposedRules_0100, Function | SmallTest | Level1) +{ + auto bundleMgrProxy = GetBundleMgrProxy(); + ASSERT_NE(bundleMgrProxy, nullptr); + sptr appControlProxy = bundleMgrProxy->GetAppControlProxy(); + ASSERT_NE(appControlProxy, nullptr); + std::vector disposedRuleConfigurations; + ErrCode ret = appControlProxy->GetDisposedRules(TEST_USERID, disposedRuleConfigurations); + EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_PERMISSION_DENIED); +} + +/** + * @tc.number: GetDisposedRules_0200 + * @tc.name: test GetDisposedRules by AppControlManagerHostImpl + * @tc.desc: 1.GetDisposedRules test + */ +HWTEST_F(BmsBundleAppControlTest, GetDisposedRules_0200, Function | SmallTest | Level1) +{ + auto impl = std::make_shared(); + ASSERT_NE(impl, nullptr); + std::vector disposedRuleConfigurations; + auto ret = impl->GetDisposedRules(TEST_USERID, disposedRuleConfigurations); + EXPECT_EQ(ret, ERR_OK); + EXPECT_EQ(disposedRuleConfigurations.size(), 0); +} + +/** + * @tc.number: GetDisposedRules_0300 + * @tc.name: test GetDisposedRules by AppControlManager + * @tc.desc: 1.GetDisposedRules test + */ +HWTEST_F(BmsBundleAppControlTest, GetDisposedRules_0300, Function | SmallTest | Level1) +{ + AppControlManager appControlManager; + std::vector disposedRuleConfigurations; + auto ret = appControlManager.GetDisposedRules(CALLER_BUNDLE_NAME, TEST_USERID, disposedRuleConfigurations); + EXPECT_EQ(ret, ERR_OK); + EXPECT_EQ(disposedRuleConfigurations.size(), 0); +} + +/** + * @tc.number: GetDisposedRules_0400 + * @tc.name: test GetDisposedRules by AppControlManager + * @tc.desc: 1.GetDisposedRules test + */ +HWTEST_F(BmsBundleAppControlTest, GetDisposedRules_0400, Function | SmallTest | Level1) +{ + AppControlManager appControlManager; + auto rdb = std::make_shared(); + ASSERT_NE(rdb, nullptr); + ASSERT_NE(rdb->rdbDataManager_, nullptr); + rdb->rdbDataManager_->bmsRdbConfig_.tableName = "name"; + appControlManager.appControlManagerDb_ = rdb; + std::vector disposedRuleConfigurations; + auto ret = appControlManager.GetDisposedRules(CALLER_BUNDLE_NAME, TEST_USERID, disposedRuleConfigurations); + EXPECT_EQ(ret, ERR_APPEXECFWK_DB_RESULT_SET_EMPTY); +} + +/** + * @tc.number: GetDisposedRules_0500 + * @tc.name: test GetDisposedRules by AppControlManagerRdb + * @tc.desc: 1.GetDisposedRules test + */ +HWTEST_F(BmsBundleAppControlTest, GetDisposedRules_0500, Function | SmallTest | Level1) +{ + auto rdb = std::make_shared(); + ASSERT_NE(rdb, nullptr); + ASSERT_NE(rdb->rdbDataManager_, nullptr); + rdb->rdbDataManager_->bmsRdbConfig_.tableName = "name"; + std::vector disposedRuleConfigurations; + auto ret = rdb->GetDisposedRules(CALLER_BUNDLE_NAME, TEST_USERID, disposedRuleConfigurations); + EXPECT_EQ(ret, ERR_APPEXECFWK_DB_RESULT_SET_EMPTY); +} + +/** + * @tc.number: GetDisposedRules_0600 + * @tc.name: test GetDisposedRules by AppControlManagerRdb + * @tc.desc: 1.GetDisposedRules test + */ +HWTEST_F(BmsBundleAppControlTest, GetDisposedRules_0600, Function | SmallTest | Level1) +{ + auto rdb = std::make_shared(); + ASSERT_NE(rdb, nullptr); + std::vector disposedRuleConfigurations; + auto ret = rdb->GetDisposedRules(CALLER_BUNDLE_NAME, TEST_USERID, disposedRuleConfigurations); + EXPECT_EQ(ret, ERR_OK); +} + +/** + * @tc.number: GetDisposedRules_0700 + * @tc.name: test GetDisposedRules by AppControlManagerRdb + * @tc.desc: 1.GetDisposedRules test + */ +HWTEST_F(BmsBundleAppControlTest, GetDisposedRules_0700, Function | SmallTest | Level1) +{ + auto rdb = std::make_shared(); + ASSERT_NE(rdb, nullptr); + std::string appId = "appId"; + int32_t appIndex = 100; + DisposedRule disposedRule; + disposedRule.componentType = ComponentType::UI_ABILITY; + disposedRule.disposedType = DisposedType::BLOCK_APPLICATION; + disposedRule.controlType = ControlType::DISALLOWED_LIST; + auto ret = rdb->SetDisposedRule(CALLER_BUNDLE_NAME, appId, disposedRule, appIndex, TEST_USERID); + EXPECT_EQ(ret, ERR_OK); + + std::vector disposedRuleConfigurations; + ret = rdb->GetDisposedRules(CALLER_BUNDLE_NAME, TEST_USERID, disposedRuleConfigurations); + EXPECT_EQ(ret, ERR_OK); + EXPECT_EQ(disposedRuleConfigurations.size(), 1); + EXPECT_EQ(disposedRuleConfigurations[0].appId, appId); + EXPECT_EQ(disposedRuleConfigurations[0].appIndex, appIndex); + EXPECT_EQ(disposedRuleConfigurations[0].disposedRule.componentType, disposedRule.componentType); + EXPECT_EQ(disposedRuleConfigurations[0].disposedRule.disposedType, disposedRule.disposedType); + EXPECT_EQ(disposedRuleConfigurations[0].disposedRule.controlType, disposedRule.controlType); + + ret = rdb->DeleteDisposedRule(CALLER_BUNDLE_NAME, { appId }, appIndex, TEST_USERID); + EXPECT_EQ(ret, ERR_OK); +} + +/** + * @tc.number: ConvertToDisposedRuleConfiguration_0100 + * @tc.name: Test ConvertToDisposedRuleConfiguration by AppControlManagerRdb + * @tc.desc: 1.ConvertToDisposedRuleConfiguration test + */ +HWTEST_F(BmsBundleAppControlTest, ConvertToDisposedRuleConfiguration_0100, Function | SmallTest | Level1) +{ + auto rdb = std::make_shared(); + ASSERT_NE(rdb, nullptr); + DisposedRuleConfiguration disposedRuleConfiguration; + auto ret = rdb->ConvertToDisposedRuleConfiguration(nullptr, disposedRuleConfiguration); + EXPECT_EQ(ret, ERR_APPEXECFWK_DB_RESULT_SET_EMPTY); +} + /** * @tc.number: AppRunningControlRule_1100 * @tc.name: test running control rule diff --git a/test/systemtest/common/bms/bms_app_control_host_test/bms_app_control_host_test.cpp b/test/systemtest/common/bms/bms_app_control_host_test/bms_app_control_host_test.cpp index 0fa3cf83993a18c585beadae730718680c1edb10..c03a44c3b2650b53f6d57d0ffbb092d834c23d2b 100644 --- a/test/systemtest/common/bms/bms_app_control_host_test/bms_app_control_host_test.cpp +++ b/test/systemtest/common/bms/bms_app_control_host_test/bms_app_control_host_test.cpp @@ -330,6 +330,21 @@ HWTEST_F(BmsAppControlHostTest, HandleGetDisposedRule_0100, Function | MediumTes EXPECT_EQ(res, ERR_OK); } +/** + * @tc.number: HandleGetDisposedRules_0100 + * @tc.name: test the HandleGetDisposedRules + * @tc.desc: 1. system running normally + * 2. test HandleGetDisposedRules + */ +HWTEST_F(BmsAppControlHostTest, HandleGetDisposedRules_0100, Function | MediumTest | Level1) +{ + AppControlHost appControlHost; + MessageParcel data; + MessageParcel reply; + ErrCode res = appControlHost.HandleGetDisposedRules(data, reply); + EXPECT_EQ(res, ERR_OK); +} + /** * @tc.number: HandleSetDisposedRule_0100 * @tc.name: test the HandleSetDisposedRule