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 648cb4b6e44b2df32baab9f361fdfbac5951ff47..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,8 +58,10 @@ 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); ErrCode HandleGetAbilityRunningControlRule(MessageParcel& data, MessageParcel& reply); ErrCode HandleGetDisposedRuleForCloneApp(MessageParcel& data, MessageParcel& reply); ErrCode HandleSetDisposedRuleForCloneApp(MessageParcel& data, MessageParcel& reply); @@ -72,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 5f7cb2f8f3fb67aeb1f2c8a398394a066a695101..cbab5b517cf1dc67bd92ca58333c6499b3134950 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) { @@ -143,6 +148,11 @@ public: { return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR; } + virtual ErrCode DeleteDisposedRules( + std::vector &disposedRuleConfigurations, int32_t userId) + { + return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR; + } virtual ErrCode GetAbilityRunningControlRule(const std::string &bundleName, int32_t userId, std::vector& disposedRules, int32_t appIndex = Constants::MAIN_APP_INDEX) { 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 997765c4f26c6ed7f1b67f1be89d233af79f41a2..2eb8daffe2d347ca1b5eb2d8f8d3cbcdad30488e 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 @@ -64,8 +64,12 @@ 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( + std::vector &disposedRuleConfigurations, int32_t userId) override; virtual ErrCode SetDisposedRule(const std::string &appId, DisposedRule& disposedRule, int32_t userId = Constants::UNSPECIFIED_USERID) override; virtual ErrCode GetAbilityRunningControlRule(const std::string &bundleName, int32_t userId, @@ -100,6 +104,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 92acf4bd41f18473dec31f8506cb795001bda6a5..9df8c7a0fa36f34bb776f6c41e2e94d69f2bc057 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 @@ -256,6 +256,8 @@ enum class AppControlManagerInterfaceCode : uint8_t { GET_UNINSTALL_DISPOSED_RULE = 25, 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 752eb8cc68b762611a3e646541d0fca01997d4b5..992d648861eb5d57738c3c73034b0219e3962ffb 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 @@ -119,6 +119,8 @@ int AppControlHost::OnRemoteRequest( return HandleSetDisposedRule(data, reply); case static_cast(AppControlManagerInterfaceCode::SET_DISPOSED_RULES): return HandleSetDisposedRules(data, reply); + case static_cast(AppControlManagerInterfaceCode::DELETE_DISPOSED_RULES): + return HandleDeleteDisposedRules(data, reply); case static_cast(AppControlManagerInterfaceCode::GET_DISPOSED_RULE): return HandleGetDisposedRule(data, reply); case static_cast(AppControlManagerInterfaceCode::GET_ABILITY_RUNNING_CONTROL_RULE): @@ -135,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); @@ -427,6 +431,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(); @@ -465,6 +487,27 @@ ErrCode AppControlHost::HandleSetDisposedRules(MessageParcel& data, MessageParce return ERR_OK; } +ErrCode AppControlHost::HandleDeleteDisposedRules(MessageParcel& data, MessageParcel& reply) +{ + std::vector disposedRuleConfigurations; + auto ret = GetVectorParcelInfo(data, disposedRuleConfigurations); + if (ret != ERR_OK) { + LOG_E(BMS_TAG_DEFAULT, "read DisposedRuleConfiguration failed"); + return ret; + } + if (disposedRuleConfigurations.empty() || disposedRuleConfigurations.size() > MAX_VECTOR_NUM) { + LOG_E(BMS_TAG_DEFAULT, "disposedRuleConfiguration count is error"); + return ERR_BUNDLE_MANAGER_PARAM_ERROR; + } + int32_t userId = data.ReadInt32(); + ret = DeleteDisposedRules(disposedRuleConfigurations, userId); + if (!reply.WriteInt32(ret)) { + LOG_E(BMS_TAG_DEFAULT, "write ret failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + return ERR_OK; +} + ErrCode AppControlHost::HandleGetAbilityRunningControlRule(MessageParcel& data, MessageParcel& reply) { std::string bundleName = data.ReadString(); @@ -679,5 +722,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 71711f25bb035d29819ec03c7ecda6f7d35e34fb..e26608d23fb62e8cf386ddbd7a0e0d4853f4388e 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) { @@ -537,6 +561,41 @@ ErrCode AppControlProxy::SetDisposedRules( return ERR_OK; } +ErrCode AppControlProxy::DeleteDisposedRules( + std::vector &disposedRuleConfigurations, int32_t userId) +{ + if (disposedRuleConfigurations.empty() || disposedRuleConfigurations.size() > MAX_VECTOR_NUM) { + LOG_E(BMS_TAG_DEFAULT, "params error"); + return ERR_BUNDLE_MANAGER_PARAM_ERROR; + } + MessageParcel data; + if (!data.WriteInterfaceToken(GetDescriptor())) { + LOG_E(BMS_TAG_DEFAULT, "WriteInterfaceToken failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + auto ret = WriteVectorToParcel(disposedRuleConfigurations, data); + if (ret != ERR_OK) { + LOG_E(BMS_TAG_DEFAULT, "write DisposedRuleConfiguration failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!data.WriteInt32(userId)) { + LOG_E(BMS_TAG_DEFAULT, "write userId failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + MessageParcel reply; + ret = SendRequest(AppControlManagerInterfaceCode::DELETE_DISPOSED_RULES, data, reply); + if (ret != ERR_OK) { + LOG_E(BMS_TAG_DEFAULT, "SendRequest failed"); + return ret; + } + ret = reply.ReadInt32(); + if (ret != ERR_OK) { + LOG_E(BMS_TAG_DEFAULT, "host return error : %{public}d", ret); + return ret; + } + return ERR_OK; +} + ErrCode AppControlProxy::GetDisposedRule(const std::string &appId, DisposedRule &rule, int32_t userId) { LOG_D(BMS_TAG_DEFAULT, "proxy begin to GetDisposedRule"); @@ -561,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) { @@ -944,5 +1026,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 f95530a5048aba0d8d0ecf136e6304c531ac64ba..8a92ff66587543a8ee7935ae9375b1553a42af81 100644 --- a/services/bundlemgr/include/app_control/app_control_manager.h +++ b/services/bundlemgr/include/app_control/app_control_manager.h @@ -79,6 +79,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 b98a1c699a91778deb40e9e895146343edf18865..4bbff6b7629ab4022345d5c1ea68d156a9736cbf 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 @@ -59,6 +59,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 a9e7128c900c30c2de760c1659f73f2b956147c3..4a74d742a413bc92cf85a1a9cbb21ee58f805d90 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 @@ -76,9 +76,15 @@ public: virtual ErrCode SetDisposedRules( std::vector &disposedRuleConfigurations, int32_t userId) override; + virtual ErrCode DeleteDisposedRules( + std::vector &disposedRuleConfigurations, int32_t userId) override; + 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 a054a4573ab8dd9516ba0fa51b633cf0b9ea4b5d..49ba9329926e05bd7f39290b31d0c16ff32ade67 100644 --- a/services/bundlemgr/include/app_control/app_control_manager_rdb.h +++ b/services/bundlemgr/include/app_control/app_control_manager_rdb.h @@ -56,6 +56,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, @@ -77,6 +79,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 c4a0fe226d3a76347cabbb8fcb189cd55d4a6152..4192d802d98da15fdb044b9d750b4f996aacd63d 100644 --- a/services/bundlemgr/src/app_control/app_control_manager.cpp +++ b/services/bundlemgr/src/app_control/app_control_manager.cpp @@ -378,6 +378,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 aca8dfaa5d2c9b96d3abf302cce03cf3fc5cf3a1..474b735ecd85dcedbbd5f70e0589bccb20a1f729 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 @@ -544,6 +544,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) { @@ -581,6 +612,41 @@ ErrCode AppControlManagerHostImpl::SetDisposedRules( return ERR_OK; } +ErrCode AppControlManagerHostImpl::DeleteDisposedRules( + std::vector &disposedRuleConfigurations, int32_t userId) +{ + LOG_NOFUNC_I(BMS_TAG_DEFAULT, "begin DeleteDisposedRules -u %{public}d", userId); + if (!BundlePermissionMgr::IsSystemApp()) { + LOG_E(BMS_TAG_DEFAULT, "non-system app calling system api"); + return ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED; + } + if (!BundlePermissionMgr::VerifyCallingPermissionForAll(PERMISSION_DISPOSED_STATUS)) { + LOG_W(BMS_TAG_DEFAULT, "verify permission ohos.permission.MANAGE_DISPOSED_STATUS failed"); + return ERR_BUNDLE_MANAGER_PERMISSION_DENIED; + } + if (!appControlManager_) { + LOG_E(BMS_TAG_DEFAULT, "appControlManager_ is nullptr"); + return ERR_APPEXECFWK_NULL_PTR; + } + + int32_t uid = OHOS::IPCSkeleton::GetCallingUid(); + std::string callerName; + GetCallerByUid(uid, callerName); + for (auto &disposedRuleConfiguration : disposedRuleConfigurations) { + ErrCode ret = appControlManager_->DeleteDisposedRule( + callerName, disposedRuleConfiguration.appId, disposedRuleConfiguration.appIndex, userId); + if (ret != ERR_OK) { + LOG_NOFUNC_W(BMS_TAG_DEFAULT, "DeleteDisposedRules err:%{public}d appId:%{private}s -i %{public}d", + ret, disposedRuleConfiguration.appId.c_str(), disposedRuleConfiguration.appIndex); + continue; + } + SendAppControlEvent(ControlActionType::DISPOSE_RULE, ControlOperationType::REMOVE_RULE, + callerName, userId, disposedRuleConfiguration.appIndex, { disposedRuleConfiguration.appId }, + Constants::EMPTY_STRING); + } + return ERR_OK; +} + ErrCode AppControlManagerHostImpl::SetDisposedRule(const std::string &appId, DisposedRule &rule, int32_t userId) { LOG_D(BMS_TAG_DEFAULT, "host begin to SetDisposedRule"); 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 e9a5f12adbef688bf7e5306c68c301fcce2576cd..5f307b38301487c208fa013a183b724b61e5d5c0 100644 --- a/services/bundlemgr/src/app_control/app_control_manager_rdb.cpp +++ b/services/bundlemgr/src/app_control/app_control_manager_rdb.cpp @@ -36,6 +36,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; // app control table key constexpr const char* CALLING_NAME = "CALLING_NAME"; constexpr const char* APP_CONTROL_LIST = "APP_CONTROL_LIST"; @@ -566,6 +567,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 9682ed579fede42bb7a6c925a91208bc6aea0dcd..d2a49c5272eeffa6e336b6027a5699979099bb20 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 @@ -499,6 +499,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 @@ -825,5 +840,77 @@ HWTEST_F(BmsAppControlProxyTest, SetDisposedRules_0400, Function | MediumTest | auto res = appControlProxy.SetDisposedRules(disposedRuleConfigurations, USERID); EXPECT_EQ(res, ERR_BUNDLE_MANAGER_PARAM_ERROR); } + +/** + * @tc.number: DeleteDisposedRules_0100 + * @tc.name: test the DeleteDisposedRules_0100 + * @tc.desc: test the DeleteDisposedRules_0100 + */ +HWTEST_F(BmsAppControlProxyTest, DeleteDisposedRules_0100, Function | MediumTest | Level1) +{ + AppControlProxy appControlProxy(nullptr); + DisposedRuleConfiguration disposedRuleConfiguration; + disposedRuleConfiguration.appId = APPID; + disposedRuleConfiguration.appIndex = APP_INDEX; + std::vector disposedRuleConfigurations; + disposedRuleConfigurations.push_back(disposedRuleConfiguration); + auto res = appControlProxy.DeleteDisposedRules(disposedRuleConfigurations, USERID); + EXPECT_EQ(res, ERR_BUNDLE_MANAGER_INTERNAL_ERROR); +} + +/** + * @tc.number: DeleteDisposedRules_0200 + * @tc.name: test the DeleteDisposedRules_0200 + * @tc.desc: test the DeleteDisposedRules_0200 + */ +HWTEST_F(BmsAppControlProxyTest, DeleteDisposedRules_0200, Function | MediumTest | Level1) +{ + sptr mockRemoteObject = new MockRemoteObject(); + AppControlProxy appControlProxy(mockRemoteObject); + DisposedRuleConfiguration disposedRuleConfiguration; + disposedRuleConfiguration.appId = APPID; + disposedRuleConfiguration.appIndex = APP_INDEX; + std::vector disposedRuleConfigurations; + disposedRuleConfigurations.push_back(disposedRuleConfiguration); + auto res = appControlProxy.DeleteDisposedRules(disposedRuleConfigurations, USERID); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: DeleteDisposedRules_0300 + * @tc.name: test the DeleteDisposedRules_0300 + * @tc.desc: test the DeleteDisposedRules_0300 + */ +HWTEST_F(BmsAppControlProxyTest, DeleteDisposedRules_0300, Function | MediumTest | Level1) +{ + sptr mockRemoteObject = new MockRemoteObject(); + AppControlProxy appControlProxy(mockRemoteObject); + std::vector disposedRuleConfigurations; + disposedRuleConfigurations.clear(); + auto res = appControlProxy.DeleteDisposedRules(disposedRuleConfigurations, USERID); + EXPECT_EQ(res, ERR_BUNDLE_MANAGER_PARAM_ERROR); +} + +/** + * @tc.number: DeleteDisposedRules_0400 + * @tc.name: test DeleteDisposedRules_0400 + * @tc.desc: test DeleteDisposedRules_0400 + */ +HWTEST_F(BmsAppControlProxyTest, DeleteDisposedRules_0400, Function | MediumTest | Level1) +{ + sptr mockRemoteObject = new MockRemoteObject(); + AppControlProxy appControlProxy(mockRemoteObject); + DisposedRuleConfiguration disposedRuleConfiguration; + disposedRuleConfiguration.appId = APPID; + disposedRuleConfiguration.appIndex = APP_INDEX; + std::vector disposedRuleConfigurations; + disposedRuleConfigurations.reserve(MAX_VECTOR_NUM); + + for (int i = 0; i < MAX_VECTOR_NUM; ++i) { + disposedRuleConfigurations.push_back(disposedRuleConfiguration); + } + auto res = appControlProxy.DeleteDisposedRules(disposedRuleConfigurations, USERID); + EXPECT_EQ(res, ERR_BUNDLE_MANAGER_PARAM_ERROR); +} } // AppExecFwk } // OHOS \ No newline at end of file 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 e181c7cd4c2be5a9bd35937ce3cb64fcda8e830e..3adb4399f80987157281f8e59a61f8fa7b05bab9 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 @@ -59,6 +59,7 @@ const std::string APP_CONTROL_EDM_DEFAULT_MESSAGE = "The app has been disabled b const std::string PERMISSION_DISPOSED_STATUS = "ohos.permission.MANAGE_DISPOSED_APP_STATUS"; const std::string ABILITY_RUNNING_KEY = "ABILITY_RUNNING_KEY"; 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; @@ -3285,6 +3286,59 @@ HWTEST_F(BmsBundleAppControlTest, OnRemoteRequest_3000, Function | MediumTest | EXPECT_EQ(res, OBJECT_NULL); } +/** + * @tc.number: OnRemoteRequest_3100 + * @tc.name: test the OnRemoteRequest + * @tc.desc: 1. system running normally + * 2. test OnRemoteRequest + */ +HWTEST_F(BmsBundleAppControlTest, OnRemoteRequest_3100, Function | MediumTest | Level0) +{ + AppControlHost appControlHost; + MessageParcel data; + data.WriteInterfaceToken(AppControlHost::GetDescriptor()); + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + ErrCode res = appControlHost.OnRemoteRequest( + static_cast(AppControlManagerInterfaceCode::DELETE_DISPOSED_RULES), data, reply, option); + EXPECT_EQ(res, ERR_BUNDLE_MANAGER_PARAM_ERROR); +} + +/** + * @tc.number: OnRemoteRequest_3200 + * @tc.name: test the OnRemoteRequest + * @tc.desc: 1. system running normally + * 2. test OnRemoteRequest + */ +HWTEST_F(BmsBundleAppControlTest, OnRemoteRequest_3200, Function | MediumTest | Level0) +{ + AppControlHost appControlHost; + MessageParcel data; + MessageParcel reply; + data.WriteInt32(2); + ErrCode res = appControlHost.HandleDeleteDisposedRules(data, reply); + EXPECT_EQ(res, ERR_APPEXECFWK_PARCEL_ERROR); +} + +/** + * @tc.number: OnRemoteRequest_3300 + * @tc.name: test the OnRemoteRequest + * @tc.desc: 1. system running normally + * 2. test OnRemoteRequest + */ +HWTEST_F(BmsBundleAppControlTest, OnRemoteRequest_3300, Function | MediumTest | Level0) +{ + AppControlHost appControlHost; + MessageParcel data; + MessageParcel reply; + data.WriteInt32(1); + DisposedRuleConfiguration config; + data.WriteParcelable(&config); + data.WriteInt32(100); + ErrCode res = appControlHost.HandleDeleteDisposedRules(data, reply); + EXPECT_EQ(res, ERR_BUNDLE_MANAGER_PARAM_ERROR); +} + /** * @tc.number: DisposeRuleCacheOnlyForBms_1000 * @tc.name: test DisposeRuleCacheOnlyForBms @@ -3308,4 +3362,181 @@ HWTEST_F(BmsBundleAppControlTest, DisposeRuleCacheOnlyForBms_0100, Function | Me ret = appControlManager->GetDisposedRuleOnlyForBms(appId, disposedRules); EXPECT_FALSE(ret); } + +/** + * @tc.number: DeleteDisposedRules_0100 + * @tc.name: test DeleteDisposedRules_0100 + * @tc.desc: test DeleteDisposedRules_0100 + */ +HWTEST_F(BmsBundleAppControlTest, DeleteDisposedRules_0100, Function | SmallTest | Level1) +{ + auto impl = std::make_shared(); + DisposedRuleConfiguration disposedRuleConfiguration; + disposedRuleConfiguration.appId = APPID; + disposedRuleConfiguration.appIndex = APP_INDEX; + std::vector disposedRuleConfigurations; + disposedRuleConfigurations.push_back(disposedRuleConfiguration); + + impl->appControlManager_ = nullptr; + ErrCode res = impl->DeleteDisposedRules(disposedRuleConfigurations, USERID); + EXPECT_EQ(res, ERR_APPEXECFWK_NULL_PTR); +} + +/** + * @tc.number: DeleteDisposedRules_0200 + * @tc.name: test DeleteDisposedRules_0200 + * @tc.desc: test DeleteDisposedRules_0200 + */ +HWTEST_F(BmsBundleAppControlTest, DeleteDisposedRules_0200, Function | SmallTest | Level1) +{ + auto impl = std::make_shared(); + DisposedRuleConfiguration disposedRuleConfiguration; + disposedRuleConfiguration.appId = APPID; + disposedRuleConfiguration.appIndex = APP_INDEX; + std::vector disposedRuleConfigurations; + disposedRuleConfigurations.push_back(disposedRuleConfiguration); + + impl->appControlManager_ = DelayedSingleton::GetInstance(); + ErrCode res = impl->DeleteDisposedRules(disposedRuleConfigurations, USERID); + 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); +} } // OHOS \ No newline at end of file diff --git a/services/bundlemgr/test/unittest/bms_bundle_permission_grant_test/bms_bundle_permission_false_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_permission_grant_test/bms_bundle_permission_false_test.cpp index e087e9845a70906e6be82a2fdf71eb1ae28af627..7b1ff47f7d9915f290f197c78772cd14735c11b1 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_permission_grant_test/bms_bundle_permission_false_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_permission_grant_test/bms_bundle_permission_false_test.cpp @@ -1344,6 +1344,9 @@ HWTEST_F(BmsBundlePermissionFalseTest, BmsBundlePermissionFalseTest_8900, Functi res = impl->SetDisposedRules(disposedRuleConfigurations, USERID); EXPECT_EQ(res, ERR_BUNDLE_MANAGER_PERMISSION_DENIED); + + res = impl->DeleteDisposedRules(disposedRuleConfigurations, USERID); + EXPECT_EQ(res, ERR_BUNDLE_MANAGER_PERMISSION_DENIED); } /** diff --git a/services/bundlemgr/test/unittest/bms_bundle_permission_grant_test/bms_bundle_permission_system_app_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_permission_grant_test/bms_bundle_permission_system_app_test.cpp index 900d0c034dbbdceba9f9778ed466b7262af4ce7d..a8c9df30da2117bd13fb54bafbdeb3bb86412a35 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_permission_grant_test/bms_bundle_permission_system_app_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_permission_grant_test/bms_bundle_permission_system_app_test.cpp @@ -940,6 +940,9 @@ HWTEST_F(BmsBundlePermissionSyetemAppFalseTest, BmsBundleSyetemAppFalseTest_5800 res = impl->SetDisposedRules(disposedRuleConfigurations, USERID); EXPECT_EQ(res, ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED); + + res = impl->DeleteDisposedRules(disposedRuleConfigurations, USERID); + EXPECT_EQ(res, ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED); } /** 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