diff --git a/frameworks/bundle_lite/BUILD.gn b/frameworks/bundle_lite/BUILD.gn index 090f17bae2196e5cf338934b06834ebc0b4b1eb9..2a1328e340789553d2cc893b10d74f79faa48e4e 100644 --- a/frameworks/bundle_lite/BUILD.gn +++ b/frameworks/bundle_lite/BUILD.gn @@ -61,7 +61,7 @@ lite_library("bundle") { "${aafwk_lite_path}/interfaces/kits/want_lite", "${aafwk_lite_path}/interfaces/kits/ability_lite/slite", "${aafwk_lite_path}/interfaces/innerkits/abilitymgr_lite", - "//foundation/communication/ipc_lite/interfaces/kits", + "//foundation/communication/ipc/interfaces/innerkits/c/ipc/include", "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", "//foundation/distributedschedule/samgr_lite/interfaces/kits/registry", "//third_party/bounds_checking_function/include", @@ -104,7 +104,7 @@ lite_library("bundle") { "${appexecfwk_lite_path}/interfaces/innerkits/bundlemgr_lite", "${appexecfwk_lite_path}/interfaces/kits/bundle_lite", "${appexecfwk_lite_path}/utils/bundle_lite", - "//foundation/communication/ipc_lite/interfaces/kits", + "//foundation/communication/ipc/interfaces/innerkits/c/ipc/include", "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", "//foundation/distributedschedule/samgr_lite/interfaces/kits/registry", "//third_party/bounds_checking_function/include", diff --git a/frameworks/bundle_lite/include/bundle_callback.h b/frameworks/bundle_lite/include/bundle_callback.h index 0760f4ed7257fdda78f3b066e989f75a2ce53bd3..2d204b0fb4f9d92c580107f74dc64a33b3ddd684 100644 --- a/frameworks/bundle_lite/include/bundle_callback.h +++ b/frameworks/bundle_lite/include/bundle_callback.h @@ -24,7 +24,7 @@ #include "appexecfwk_errors.h" #include "bundle_callback_utils.h" -#include "liteipc_adapter.h" +#include "ipc_skeleton.h" #include "nocopyable.h" namespace OHOS { @@ -47,6 +47,7 @@ private: BundleStateCallback bundleStateCallback_ { nullptr }; // register callback for all apps SvcIdentity *svcIdentity_ { nullptr }; + IpcObjectStub objectStub_ {}; void *innerData_ { nullptr }; std::unordered_map callbackMap_ {}; diff --git a/frameworks/bundle_lite/include/bundle_self_callback.h b/frameworks/bundle_lite/include/bundle_self_callback.h old mode 100755 new mode 100644 index 9fce2d4a1d41d01e3a1f3370c32474e6a64f9b5e..12b36e8f6238e96a94b21a028ee173df09f1686a --- a/frameworks/bundle_lite/include/bundle_self_callback.h +++ b/frameworks/bundle_lite/include/bundle_self_callback.h @@ -21,7 +21,7 @@ #include "appexecfwk_errors.h" #include "bundle_manager.h" -#include "liteipc_adapter.h" +#include "ipc_skeleton.h" #include "nocopyable.h" namespace OHOS { @@ -37,11 +37,11 @@ public: const InstallerCallback GetCallback(); private: BundleSelfCallback() = default; - static int32_t Callback(const IpcContext* context, void *ipcMsg, IpcIo *io, void *arg); + static int32_t Callback(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option); int32_t GenerateLocalServiceId(); InstallerCallback installerCallback_ { nullptr }; SvcIdentity *svcIdentity_ { nullptr }; - + IpcObjectStub objectStub_ {}; DISALLOW_COPY_AND_MOVE(BundleSelfCallback); }; } // namespace diff --git a/frameworks/bundle_lite/src/bundle_callback.cpp b/frameworks/bundle_lite/src/bundle_callback.cpp old mode 100755 new mode 100644 index 7ae2b9c60e83cdc09c0e024f3524b1d6d753e500..fa76c9f17b8630f222c7a83daf798b1a4375a7a4 --- a/frameworks/bundle_lite/src/bundle_callback.cpp +++ b/frameworks/bundle_lite/src/bundle_callback.cpp @@ -23,12 +23,12 @@ #include "log.h" #include "ohos_types.h" #include "samgr_lite.h" +#include "rpc_errno.h" namespace OHOS { BundleCallback::~BundleCallback() { if (svcIdentity_ != nullptr) { - UnregisterIpcCallback(*svcIdentity_); TransmitServiceId(*svcIdentity_, false); AdapterFree(svcIdentity_); } @@ -40,11 +40,13 @@ static int Notify(IOwner owner, int code, IpcIo *reply) if ((reply == nullptr) || (owner == nullptr)) { return EC_INVALID; } - if (IpcIoPopUint8(reply) != CHANGE_CALLBACK_SERVICE_IDENTITY) { + uint8_t cmd; + ReadUint8(reply, &cmd); + if (cmd != CHANGE_CALLBACK_SERVICE_IDENTITY) { return EC_INVALID; } uint8_t *result = reinterpret_cast(owner); - *result = IpcIoPopUint8(reply); + ReadUint8(reply, result); return EC_SUCCESS; } @@ -78,36 +80,22 @@ int32_t InnerCallback(uint32_t installType, uint8_t resultCode, const char *bund return ERR_APPEXECFWK_CALLBACK_GET_ERROR_INSTALLTYPE; } -static int32_t Callback(const IpcContext* context, void *ipcMsg, IpcIo *io, void *arg) +static int32_t Callback(uint32_t code, IpcIo* data, IpcIo* reply, MessageOption option) { - // at here, arg is always been nullptr - if (ipcMsg == nullptr) { - HILOG_ERROR(HILOG_MODULE_APP, "BundleCallback ipcMsg is nullptr"); + if (data == nullptr) { + HILOG_ERROR(HILOG_MODULE_APP, "BundleCallback data is nullptr"); return ERR_APPEXECFWK_OBJECT_NULL; } - if (io == nullptr) { - HILOG_ERROR(HILOG_MODULE_APP, "BundleCallback io is nullptr"); - FreeBuffer(NULL, ipcMsg); - return ERR_APPEXECFWK_OBJECT_NULL; - } - - uint32_t installType = 0; - int32_t ret = GetCode(ipcMsg, &installType); - if (ret != LITEIPC_OK) { - FreeBuffer(NULL, ipcMsg); - HILOG_ERROR(HILOG_MODULE_APP, "BundleCallback Get install type failed"); - return ERR_APPEXECFWK_CALLBACK_GET_INSTALLTYPE_FAILED; - } - if ((installType == INSTALL_CALLBACK) || (installType == UNINSTALL_CALLBACK)) { - uint8_t resultCode = static_cast(IpcIoPopInt32(io)); + if ((code == INSTALL_CALLBACK) || (code == UNINSTALL_CALLBACK)) { + int32_t readCode; + ReadInt32(data, &readCode); + uint8_t resultCode = static_cast(readCode); size_t size = 0; - char *bundleName = reinterpret_cast(IpcIoPopString(io, &size)); - ret = InnerCallback(installType, resultCode, bundleName); - FreeBuffer(NULL, ipcMsg); + char *bundleName = reinterpret_cast(ReadString(data, &size)); + int32_t ret = InnerCallback(code, resultCode, bundleName); return ret; } - FreeBuffer(NULL, ipcMsg); HILOG_ERROR(HILOG_MODULE_APP, "BundleSelfCallback get error install type"); return ERR_APPEXECFWK_CALLBACK_GET_ERROR_INSTALLTYPE; } @@ -124,11 +112,11 @@ int32_t BundleCallback::TransmitServiceId(const SvcIdentity &svc, bool flag) return ERR_APPEXECFWK_CALLBACK_SERVICEID_TRANSMITTED_FAILED; } IpcIo ipcIo; - uint32_t data[IPC_IO_DATA_MAX]; - IpcIoInit(&ipcIo, data, IPC_IO_DATA_MAX, 1); - IpcIoPushBool(&ipcIo, flag); - IpcIoPushSvc(&ipcIo, &svc); - if (!IpcIoAvailable(&ipcIo)) { + uint32_t data[MAX_IO_SIZE]; + IpcIoInit(&ipcIo, data, MAX_IO_SIZE, 1); + WriteBool(&ipcIo, flag); + bool writeRemote = WriteRemoteObject(&ipcIo, &svc); + if (!writeRemote) { HILOG_ERROR(HILOG_MODULE_APP, "BundleCallback TransmitServiceId ipc failed"); return ERR_APPEXECFWK_IPCIO_UNAVAILABLED; } @@ -151,14 +139,17 @@ int32_t BundleCallback::GenerateLocalServiceId() if (svcIdentity_ == nullptr) { return ERR_APPEXECFWK_CALLBACK_GENERATE_LOCAL_SERVICEID_FAILED; } - int32_t ret = RegisterIpcCallback(Callback, 0, IPC_WAIT_FOREVER, svcIdentity_, NULL); - if ((ret != LITEIPC_OK)) { - AdapterFree(svcIdentity_); - return ERR_APPEXECFWK_CALLBACK_GENERATE_LOCAL_SERVICEID_FAILED; - } - ret = TransmitServiceId(*svcIdentity_, true); + + objectStub_.func = Callback; + objectStub_.args = nullptr; + objectStub_.isRemote = false; + + svcIdentity_->handle = IPC_INVALID_HANDLE; + svcIdentity_->token = SERVICE_TYPE_ANONYMOUS; + svcIdentity_->cookie = (uintptr_t)&objectStub_; + + int32_t ret = TransmitServiceId(*svcIdentity_, true); if (ret != ERR_OK) { - UnregisterIpcCallback(*svcIdentity_); AdapterFree(svcIdentity_); return ERR_APPEXECFWK_CALLBACK_SERVICEID_TRANSMITTED_FAILED; } @@ -211,7 +202,6 @@ int32_t BundleCallback::UnregisterBundleStateCallback() innerData_ = nullptr; callbackMap_.clear(); (void) TransmitServiceId(*svcIdentity_, false); - (void) UnregisterIpcCallback(*svcIdentity_); AdapterFree(svcIdentity_); return ERR_OK; } diff --git a/frameworks/bundle_lite/src/bundle_manager.cpp b/frameworks/bundle_lite/src/bundle_manager.cpp old mode 100755 new mode 100644 index 2a8aff0cb0e62c9fcf10f9dd763fcac4e8f908af..4cd86d185647f853f9650b7ecab749a5acdb2ee3 --- a/frameworks/bundle_lite/src/bundle_manager.cpp +++ b/frameworks/bundle_lite/src/bundle_manager.cpp @@ -23,7 +23,7 @@ #include "bundle_self_callback.h" #include "convert_utils.h" #include "iproxy_client.h" -#include "liteipc_adapter.h" +#include "ipc_skeleton.h" #include "log.h" #include "ohos_types.h" #include "pms_interface.h" @@ -67,32 +67,21 @@ static uint8_t DeserializeInnerAbilityInfo(IOwner owner, IpcIo *reply) if ((reply == nullptr) || (owner == nullptr)) { return OHOS_FAILURE; } - uint8_t resultCode = IpcIoPopUint8(reply); + uint8_t resultCode; + ReadUint8(reply, &resultCode); ResultOfQueryAbilityInfo *info = reinterpret_cast(owner); if (resultCode != ERR_OK) { info->resultCode = resultCode; return resultCode; } -#ifdef __LINUX__ size_t len = 0; - char *jsonStr = reinterpret_cast(IpcIoPopString(reply, &len)); + char *jsonStr = reinterpret_cast(ReadString(reply, &len)); if (jsonStr == nullptr) { info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED; HILOG_ERROR(HILOG_MODULE_APP, "AbilityInfo DeserializeAbilityInfo buff is empty!"); return ERR_APPEXECFWK_DESERIALIZATION_FAILED; } info->abilityInfo = OHOS::ConvertUtils::ConvertStringToAbilityInfo(jsonStr, len); -#else - BuffPtr *buff = IpcIoPopDataBuff(reply); - if (buff == nullptr) { - info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED; - HILOG_ERROR(HILOG_MODULE_APP, "AbilityInfo DeserializeAbilityInfo buff is empty!"); - return ERR_APPEXECFWK_DESERIALIZATION_FAILED; - } - char* jsonStr = reinterpret_cast(buff->buff); - info->abilityInfo = OHOS::ConvertUtils::ConvertStringToAbilityInfo(jsonStr, buff->buffSz); - FreeBuffer(NULL, buff->buff); -#endif if (info->abilityInfo == nullptr) { info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED; return ERR_APPEXECFWK_DESERIALIZATION_FAILED; @@ -106,32 +95,21 @@ static uint8_t DeserializeInnerBundleInfo(IOwner owner, IpcIo *reply) if ((reply == nullptr) || (owner == nullptr)) { return OHOS_FAILURE; } - uint8_t resultCode = IpcIoPopUint8(reply); + uint8_t resultCode; + ReadUint8(reply, &resultCode); ResultOfGetBundleInfo *info = reinterpret_cast(owner); if (resultCode != ERR_OK) { info->resultCode = resultCode; return resultCode; } -#ifdef __LINUX__ size_t len = 0; - char *jsonStr = reinterpret_cast(IpcIoPopString(reply, &len)); + char *jsonStr = reinterpret_cast(ReadString(reply, &len)); if (jsonStr == nullptr) { info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED; HILOG_ERROR(HILOG_MODULE_APP, "BundleInfo DeserializeBundleInfo buff is empty!"); return ERR_APPEXECFWK_DESERIALIZATION_FAILED; } info->bundleInfo = OHOS::ConvertUtils::ConvertStringToBundleInfo(jsonStr, len); -#else - BuffPtr *buff = IpcIoPopDataBuff(reply); - if (buff == nullptr) { - info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED; - HILOG_ERROR(HILOG_MODULE_APP, "BundleInfo DeserializeBundleInfo buff is empty!"); - return ERR_APPEXECFWK_DESERIALIZATION_FAILED; - } - char* jsonStr = reinterpret_cast(buff->buff); - info->bundleInfo = OHOS::ConvertUtils::ConvertStringToBundleInfo(jsonStr, buff->buffSz); - FreeBuffer(NULL, buff->buff); -#endif if (info->bundleInfo == nullptr) { info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED; return ERR_APPEXECFWK_DESERIALIZATION_FAILED; @@ -145,17 +123,17 @@ static uint8_t DeserializeInnerBundleInfos(IOwner owner, IpcIo *reply) if ((reply == nullptr) || (owner == nullptr)) { return OHOS_FAILURE; } - uint8_t resultCode = IpcIoPopUint8(reply); + uint8_t resultCode; + ReadUint8(reply, &resultCode); ResultOfGetBundleInfos *info = reinterpret_cast(owner); if (resultCode != ERR_OK) { info->resultCode = resultCode; return resultCode; } - info->length = IpcIoPopInt32(reply); -#ifdef __LINUX__ + ReadInt32(reply, &(info->length)); size_t len = 0; - char *jsonStr = reinterpret_cast(IpcIoPopString(reply, &len)); + char *jsonStr = reinterpret_cast(ReadString(reply, &len)); if (jsonStr == nullptr) { info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED; HILOG_ERROR(HILOG_MODULE_APP, "BundleInfo DeserializeBundleInfos buff is empty!"); @@ -165,22 +143,7 @@ static uint8_t DeserializeInnerBundleInfos(IOwner owner, IpcIo *reply) info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED; return ERR_APPEXECFWK_DESERIALIZATION_FAILED; } -#else - BuffPtr *buff = IpcIoPopDataBuff(reply); - if (buff == nullptr) { - info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED; - HILOG_ERROR(HILOG_MODULE_APP, "BundleInfo DeserializeBundleInfos buff is empty!"); - return ERR_APPEXECFWK_DESERIALIZATION_FAILED; - } - char *jsonStr = reinterpret_cast(buff->buff); - if (!OHOS::ConvertUtils::ConvertStringToBundleInfos(jsonStr, &(info->bundleInfo), info->length, - buff->buffSz)) { - FreeBuffer(NULL, buff->buff); - info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED; - return ERR_APPEXECFWK_DESERIALIZATION_FAILED; - } - FreeBuffer(NULL, buff->buff); -#endif + info->resultCode = resultCode; return resultCode; } @@ -190,7 +153,8 @@ static uint8_t DeserializeInnerBundleName(IOwner owner, IpcIo *reply) if ((reply == nullptr) || (owner == nullptr)) { return OHOS_FAILURE; } - uint8_t resultCode = IpcIoPopUint8(reply); + uint8_t resultCode; + ReadUint8(reply, &resultCode); ResultOfGetBundleNameForUid *info = reinterpret_cast(owner); if (resultCode != ERR_OK) { info->resultCode = resultCode; @@ -198,7 +162,7 @@ static uint8_t DeserializeInnerBundleName(IOwner owner, IpcIo *reply) } size_t length = 0; - char *bundleName = reinterpret_cast(IpcIoPopString(reply, &length)); + char *bundleName = reinterpret_cast(ReadString(reply, &length)); if (bundleName == nullptr) { info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED; return ERR_APPEXECFWK_DESERIALIZATION_FAILED; @@ -229,13 +193,14 @@ static uint8_t DeserializeBundleSize(IOwner owner, IpcIo *reply) if ((reply == nullptr) || (owner == nullptr)) { return OHOS_FAILURE; } - uint8_t resultCode = IpcIoPopUint8(reply); + uint8_t resultCode; + ReadUint8(reply, &resultCode); ResultOfGetBundleSize *info = reinterpret_cast(owner); if (resultCode != ERR_OK) { info->resultCode = resultCode; return resultCode; } - info->bundleSize = IpcIoPopUint32(reply); + ReadUint32(reply, &(info->bundleSize)); info->resultCode = resultCode; return resultCode; } @@ -245,13 +210,15 @@ static uint8_t DeserializeSystemCapabilities(IOwner owner, IpcIo *reply) if ((reply == nullptr) || (owner == nullptr)) { return OHOS_FAILURE; } - uint8_t resultCode = IpcIoPopUint8(reply); + uint8_t resultCode; + ReadUint8(reply, &resultCode); ResultOfGetSysCap *info = reinterpret_cast(owner); if (resultCode != ERR_OK) { info->resultCode = resultCode; return resultCode; } - int32_t sysCapCount = IpcIoPopInt32(reply); + int32_t sysCapCount; + ReadInt32(reply, &sysCapCount); info->systemCap.systemCapName = reinterpret_cast(AdapterMalloc(sizeof(SystemCapName) * sysCapCount)); if (info->systemCap.systemCapName == nullptr) { @@ -268,7 +235,7 @@ static uint8_t DeserializeSystemCapabilities(IOwner owner, IpcIo *reply) } for (int32_t index = 0; index < sysCapCount; index++) { size_t sysCapNameLen; - char *sysCapName = reinterpret_cast(IpcIoPopString(reply, &sysCapNameLen)); + char *sysCapName = reinterpret_cast(ReadString(reply, &sysCapNameLen)); errno_t err = strncpy_s(info->systemCap.systemCapName[index].name, MAX_SYSCAP_NAME_LEN, sysCapName, sysCapNameLen); if (err != EOK) { @@ -288,11 +255,13 @@ static int Notify(IOwner owner, int code, IpcIo *reply) HILOG_ERROR(HILOG_MODULE_APP, "BundleManager Notify ipc is nullptr"); return OHOS_FAILURE; } - switch (IpcIoPopUint8(reply)) { + uint8_t resultCode; + ReadUint8(reply, &resultCode); + switch (resultCode) { case INSTALL: case UNINSTALL: { uint8_t *ret = reinterpret_cast(owner); - *ret = IpcIoPopUint8(reply); + ReadUint8(reply, ret); HILOG_INFO(HILOG_MODULE_APP, "BundleManager install or uninstall invoke return: %{public}d", *ret); break; } @@ -312,7 +281,7 @@ static int Notify(IOwner owner, int code, IpcIo *reply) } case CHECK_SYS_CAP: { uint8_t *ret = reinterpret_cast(owner); - *ret = IpcIoPopUint8(reply); + ReadUint8(reply, ret); HILOG_INFO(HILOG_MODULE_APP, "BundleManager HasSystemCapability invoke return: %{public}d", *ret); break; } @@ -327,7 +296,7 @@ static int Notify(IOwner owner, int code, IpcIo *reply) case SET_SIGN_DEBUG_MODE: case SET_SIGN_MODE: { uint8_t *ret = reinterpret_cast(owner); - *ret = IpcIoPopUint8(reply); + ReadUint8(reply, ret); break; } #endif @@ -385,28 +354,20 @@ bool Install(const char *hapPath, const InstallParam *installParam, InstallerCal } IpcIo ipcIo; - char data[IPC_IO_DATA_MAX]; - IpcIoInit(&ipcIo, data, IPC_IO_DATA_MAX, OBJECT_NUMBER_IN_INSTALLATION); -#ifdef __LINUX__ - IpcIoPushString(&ipcIo, hapPath); -#else - BuffPtr dataBuff = { - .buffSz = strlen(hapPath) + 1, // include \0 - .buff = const_cast(hapPath) - }; - IpcIoPushDataBuff(&ipcIo, &dataBuff); -#endif + char data[MAX_IO_SIZE]; + IpcIoInit(&ipcIo, data, MAX_IO_SIZE, OBJECT_NUMBER_IN_INSTALLATION); + WriteString(&ipcIo, hapPath); const SvcIdentity *svc = OHOS::BundleSelfCallback::GetInstance().RegisterBundleSelfCallback(installerCallback); if (svc == nullptr) { HILOG_ERROR(HILOG_MODULE_APP, "BundleManager Install svc is nullptr"); return false; } - IpcIoPushSvc(&ipcIo, svc); - IpcIoPushInt32(&ipcIo, installParam->installLocation); - if (!IpcIoAvailable(&ipcIo)) { + bool writeRemote = WriteRemoteObject(&ipcIo, svc); + if (!writeRemote) { HILOG_ERROR(HILOG_MODULE_APP, "BundleManager Install ipc failed"); return false; } + WriteInt32(&ipcIo, installParam->installLocation); HILOG_DEBUG(HILOG_MODULE_APP, "BMS client invoke install"); uint8_t result = 0; int32_t ret = bmsInnerClient->Invoke(bmsInnerClient, INSTALL, &ipcIo, &result, Notify); @@ -441,15 +402,15 @@ bool Uninstall(const char *bundleName, const InstallParam *installParam, Install return false; } IpcIo ipcIo; - char data[IPC_IO_DATA_MAX]; - IpcIoInit(&ipcIo, data, IPC_IO_DATA_MAX, 1); - IpcIoPushString(&ipcIo, bundleName); - IpcIoPushSvc(&ipcIo, svc); - IpcIoPushBool(&ipcIo, installParam->keepData); - if (!IpcIoAvailable(&ipcIo)) { + char data[MAX_IO_SIZE]; + IpcIoInit(&ipcIo, data, MAX_IO_SIZE, 1); + WriteString(&ipcIo, bundleName); + bool writeRemote = WriteRemoteObject(&ipcIo, svc); + if (!writeRemote) { HILOG_ERROR(HILOG_MODULE_APP, "BundleManager Uninstall ipc failed"); return false; } + WriteBool(&ipcIo, installParam->keepData); HILOG_DEBUG(HILOG_MODULE_APP, "BMS client invoke uninstall"); uint8_t result = 0; int32_t ret = bmsInnerClient->Invoke(bmsInnerClient, UNINSTALL, &ipcIo, &result, Notify); @@ -476,15 +437,11 @@ uint8_t QueryAbilityInfo(const Want *want, AbilityInfo *abilityInfo) } IpcIo ipcIo; - char data[IPC_IO_DATA_MAX]; - IpcIoInit(&ipcIo, data, IPC_IO_DATA_MAX, OBJECT_NUMBER_IN_WANT); + char data[MAX_IO_SIZE]; + IpcIoInit(&ipcIo, data, MAX_IO_SIZE, OBJECT_NUMBER_IN_WANT); if (!SerializeWant(&ipcIo, want)) { return ERR_APPEXECFWK_SERIALIZATION_FAILED; } - if (!IpcIoAvailable(&ipcIo)) { - HILOG_ERROR(HILOG_MODULE_APP, "BundleManager QueryAbilityInfo ipc failed"); - return ERR_APPEXECFWK_SERIALIZATION_FAILED; - } ResultOfQueryAbilityInfo resultOfQueryAbilityInfo = { 0, nullptr }; int32_t ret = bmsClient->Invoke(bmsClient, QUERY_ABILITY_INFO, &ipcIo, &resultOfQueryAbilityInfo, Notify); @@ -526,14 +483,10 @@ uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo *bundleI } IpcIo ipcIo; - char data[IPC_IO_DATA_MAX]; - IpcIoInit(&ipcIo, data, IPC_IO_DATA_MAX, 0); - IpcIoPushString(&ipcIo, bundleName); - IpcIoPushInt32(&ipcIo, flags); - if (!IpcIoAvailable(&ipcIo)) { - HILOG_ERROR(HILOG_MODULE_APP, "BundleManager GetBundleInfo ipc failed"); - return ERR_APPEXECFWK_SERIALIZATION_FAILED; - } + char data[MAX_IO_SIZE]; + IpcIoInit(&ipcIo, data, MAX_IO_SIZE, 0); + WriteString(&ipcIo, bundleName); + WriteInt32(&ipcIo, flags); ResultOfGetBundleInfo resultOfGetBundleInfo; resultOfGetBundleInfo.bundleInfo = nullptr; int32_t ret = bmsClient->Invoke(bmsClient, GET_BUNDLE_INFO, &ipcIo, &resultOfGetBundleInfo, Notify); @@ -570,10 +523,6 @@ static uint8_t ObtainInnerBundleInfos(const int flags, BundleInfo **bundleInfos, return ERR_APPEXECFWK_OBJECT_NULL; } - if (!IpcIoAvailable(ipcIo)) { - HILOG_ERROR(HILOG_MODULE_APP, "BundleManager GetBundleInfos ipc failed"); - return ERR_APPEXECFWK_SERIALIZATION_FAILED; - } ResultOfGetBundleInfos resultOfGetBundleInfos; resultOfGetBundleInfos.length = 0; resultOfGetBundleInfos.bundleInfo = nullptr; @@ -618,9 +567,9 @@ uint8_t GetBundleInfos(const int flags, BundleInfo **bundleInfos, int32_t *len) return ERR_APPEXECFWK_QUERY_PARAMETER_ERROR; } IpcIo ipcIo; - char data[IPC_IO_DATA_MAX]; - IpcIoInit(&ipcIo, data, IPC_IO_DATA_MAX, 0); - IpcIoPushInt32(&ipcIo, flags); + char data[MAX_IO_SIZE]; + IpcIoInit(&ipcIo, data, MAX_IO_SIZE, 0); + WriteInt32(&ipcIo, flags); return ObtainInnerBundleInfos(flags, bundleInfos, len, GET_BUNDLE_INFOS, &ipcIo); } @@ -643,13 +592,9 @@ uint32_t GetBundleSize(const char *bundleName) } IpcIo ipcIo; - char data[IPC_IO_DATA_MAX]; - IpcIoInit(&ipcIo, data, IPC_IO_DATA_MAX, 0); - IpcIoPushString(&ipcIo, bundleName); - if (!IpcIoAvailable(&ipcIo)) { - HILOG_ERROR(HILOG_MODULE_APP, "BundleManager GetBundleSize ipc failed"); - return 0; - } + char data[MAX_IO_SIZE]; + IpcIoInit(&ipcIo, data, MAX_IO_SIZE, 0); + WriteString(&ipcIo, bundleName); ResultOfGetBundleSize resultOfGetBundleSize; int32_t ret = bmsClient->Invoke(bmsClient, GET_BUNDLE_SIZE, &ipcIo, &resultOfGetBundleSize, Notify); @@ -667,8 +612,8 @@ uint8_t QueryKeepAliveBundleInfos(BundleInfo **bundleInfos, int32_t *len) return ERR_APPEXECFWK_OBJECT_NULL; } IpcIo ipcIo; - char data[IPC_IO_DATA_MAX]; - IpcIoInit(&ipcIo, data, IPC_IO_DATA_MAX, 0); + char data[MAX_IO_SIZE]; + IpcIoInit(&ipcIo, data, MAX_IO_SIZE, 0); return ObtainInnerBundleInfos(0, bundleInfos, len, QUERY_KEEPALIVE_BUNDLE_INFOS, &ipcIo); } @@ -678,9 +623,9 @@ uint8_t GetBundleInfosByMetaData(const char *metaDataKey, BundleInfo **bundleInf return ERR_APPEXECFWK_OBJECT_NULL; } IpcIo ipcIo; - char data[IPC_IO_DATA_MAX]; - IpcIoInit(&ipcIo, data, IPC_IO_DATA_MAX, 0); - IpcIoPushString(&ipcIo, metaDataKey); + char data[MAX_IO_SIZE]; + IpcIoInit(&ipcIo, data, MAX_IO_SIZE, 0); + WriteString(&ipcIo, metaDataKey); return ObtainInnerBundleInfos(0, bundleInfos, len, GET_BUNDLE_INFOS_BY_METADATA, &ipcIo); } @@ -700,9 +645,9 @@ uint8_t GetBundleNameForUid(int32_t uid, char **bundleName) } IpcIo ipcIo; - char data[IPC_IO_DATA_MAX]; - IpcIoInit(&ipcIo, data, IPC_IO_DATA_MAX, 0); - IpcIoPushInt32(&ipcIo, uid); + char data[MAX_IO_SIZE]; + IpcIoInit(&ipcIo, data, MAX_IO_SIZE, 0); + WriteInt32(&ipcIo, uid); ResultOfGetBundleNameForUid resultOfGetBundleNameForUid; resultOfGetBundleNameForUid.length = 0; @@ -744,13 +689,9 @@ bool HasSystemCapability(const char *sysCapName) return false; } IpcIo ipcIo; - char data[IPC_IO_DATA_MAX]; - IpcIoInit(&ipcIo, data, IPC_IO_DATA_MAX, 0); - IpcIoPushString(&ipcIo, sysCapName); - if (!IpcIoAvailable(&ipcIo)) { - HILOG_ERROR(HILOG_MODULE_APP, "BundleManager HasSystemCapability ipc failed"); - return false; - } + char data[MAX_IO_SIZE]; + IpcIoInit(&ipcIo, data, MAX_IO_SIZE, 0); + WriteString(&ipcIo, sysCapName); uint8_t result = 0; int32_t ret = bmsClient->Invoke(bmsClient, CHECK_SYS_CAP, &ipcIo, &result, Notify); if (ret != OHOS_SUCCESS) { @@ -768,12 +709,8 @@ SystemCapability *GetSystemAvailableCapabilities() return nullptr; } IpcIo ipcIo; - char data[IPC_IO_DATA_MAX]; - IpcIoInit(&ipcIo, data, IPC_IO_DATA_MAX, 0); - if (!IpcIoAvailable(&ipcIo)) { - HILOG_ERROR(HILOG_MODULE_APP, "BundleManager GetSystemAvailableCapabilities ipc failed"); - return nullptr; - } + char data[MAX_IO_SIZE]; + IpcIoInit(&ipcIo, data, MAX_IO_SIZE, 0); ResultOfGetSysCap resultOfGetSysCap; resultOfGetSysCap.systemCap.systemCapNum = 0; resultOfGetSysCap.systemCap.systemCapName = nullptr; diff --git a/frameworks/bundle_lite/src/bundle_self_callback.cpp b/frameworks/bundle_lite/src/bundle_self_callback.cpp old mode 100755 new mode 100644 index 0fd6c9334856642d7f7998dbe68b1075495f067b..6311788094c7c538d4b693feb27cffe09fd26bc8 --- a/frameworks/bundle_lite/src/bundle_self_callback.cpp +++ b/frameworks/bundle_lite/src/bundle_self_callback.cpp @@ -21,12 +21,12 @@ #include "iproxy_client.h" #include "log.h" #include "samgr_lite.h" +#include "rpc_errno.h" namespace OHOS { BundleSelfCallback::~BundleSelfCallback() { if (svcIdentity_ != nullptr) { - (void) UnregisterIpcCallback(*svcIdentity_); AdapterFree(svcIdentity_); } } @@ -44,36 +44,23 @@ int32_t InnerCallback(const char *resultMessage, uint8_t resultCode, const Insta return ERR_OK; } -int32_t BundleSelfCallback::Callback(const IpcContext* context, void *ipcMsg, IpcIo *io, void *arg) +int32_t BundleSelfCallback::Callback(uint32_t code, IpcIo* data, IpcIo* reply, MessageOption option) { - if (ipcMsg == nullptr) { - HILOG_ERROR(HILOG_MODULE_APP, "BundleSelfCallback ipcMsg is nullptr"); - return ERR_APPEXECFWK_OBJECT_NULL; - } - - if (io == nullptr) { - HILOG_ERROR(HILOG_MODULE_APP, "BundleSelfCallback io is nullptr"); - FreeBuffer(NULL, ipcMsg); + if (data == nullptr) { + HILOG_ERROR(HILOG_MODULE_APP, "BundleSelfCallback data is nullptr"); return ERR_APPEXECFWK_OBJECT_NULL; } InstallerCallback installerCallback = GetInstance().GetCallback(); if (installerCallback == nullptr) { - FreeBuffer(NULL, ipcMsg); return ERR_APPEXECFWK_OBJECT_NULL; } - uint32_t installType = 0; - int32_t ret = GetCode(ipcMsg, &installType); - if (ret != LITEIPC_OK) { - FreeBuffer(NULL, ipcMsg); - HILOG_ERROR(HILOG_MODULE_APP, "BundleSelfCallback Get install type failed"); - return ERR_APPEXECFWK_CALLBACK_GET_INSTALLTYPE_FAILED; - } - auto resultCode = static_cast(IpcIoPopInt32(io)); - FreeBuffer(NULL, ipcMsg); - if (installType == INSTALL_CALLBACK) { + int32_t readCode; + ReadInt32(data, &readCode); + auto resultCode = static_cast(readCode); + if (code == INSTALL_CALLBACK) { return InnerCallback(INSTALL_SUCCESS, resultCode, installerCallback); } - if (installType == UNINSTALL_CALLBACK) { + if (code == UNINSTALL_CALLBACK) { return InnerCallback(UNINSTALL_SUCCESS, resultCode, installerCallback); } HILOG_ERROR(HILOG_MODULE_APP, "BundleSelfCallback get error install type"); @@ -87,12 +74,13 @@ int32 BundleSelfCallback::GenerateLocalServiceId() return ERR_APPEXECFWK_CALLBACK_GENERATE_LOCAL_SERVICEID_FAILED; } - int32_t ret = RegisterIpcCallback(Callback, 0, IPC_WAIT_FOREVER, svcIdentity_, NULL); - if ((ret != LITEIPC_OK)) { - AdapterFree(svcIdentity_); - svcIdentity_ = nullptr; - return ERR_APPEXECFWK_CALLBACK_GENERATE_LOCAL_SERVICEID_FAILED; - } + objectStub_.func = BundleSelfCallback::Callback; + objectStub_.args = nullptr; + objectStub_.isRemote = false; + + svcIdentity_->handle = IPC_INVALID_HANDLE; + svcIdentity_->token = SERVICE_TYPE_ANONYMOUS; + svcIdentity_->cookie = (uintptr_t)&objectStub_; return ERR_OK; } diff --git a/frameworks/bundle_lite/src/element_name.cpp b/frameworks/bundle_lite/src/element_name.cpp index 8c89e9c6d40267de641e754797dc4a39482bacd9..e4bff9bf02b317dc9ff0825304174e6023e07095 100644 --- a/frameworks/bundle_lite/src/element_name.cpp +++ b/frameworks/bundle_lite/src/element_name.cpp @@ -81,28 +81,28 @@ bool SerializeElement(IpcIo *io, const ElementName *element) } if (element->deviceId == nullptr || strlen(element->deviceId) == 0) { - IpcIoPushInt32(io, VALUE_NULL); + WriteInt32(io, VALUE_NULL); } else if (strlen(element->deviceId) > MAX_DEVICE_ID) { return false; } else { - IpcIoPushInt32(io, VALUE_OBJECT); - IpcIoPushString(io, element->deviceId); + WriteInt32(io, VALUE_OBJECT); + WriteString(io, element->deviceId); } if (element->bundleName == nullptr || strlen(element->bundleName) == 0) { - IpcIoPushInt32(io, VALUE_NULL); + WriteInt32(io, VALUE_NULL); } else if (strlen(element->bundleName) > MAX_BUNDLE_NAME) { return false; } else { - IpcIoPushInt32(io, VALUE_OBJECT); - IpcIoPushString(io, element->bundleName); + WriteInt32(io, VALUE_OBJECT); + WriteString(io, element->bundleName); } if (element->abilityName == nullptr || strlen(element->abilityName) == 0) { - IpcIoPushInt32(io, VALUE_NULL); + WriteInt32(io, VALUE_NULL); } else if (strlen(element->abilityName) > MAX_ABILITY_NAME) { return false; } else { - IpcIoPushInt32(io, VALUE_OBJECT); - IpcIoPushString(io, element->abilityName); + WriteInt32(io, VALUE_OBJECT); + WriteString(io, element->abilityName); } return true; } @@ -113,17 +113,21 @@ bool DeserializeElement(ElementName *element, IpcIo *io) return false; } - if (IpcIoPopInt32(io) == VALUE_OBJECT && - !SetElementDeviceID(element, reinterpret_cast(IpcIoPopString(io, nullptr)))) { + int32_t naspac; + ReadInt32(io, &naspac); + if (naspac == VALUE_OBJECT && + !SetElementDeviceID(element, reinterpret_cast(ReadString(io, nullptr)))) { return false; } - if (IpcIoPopInt32(io) == VALUE_OBJECT && - !SetElementBundleName(element, reinterpret_cast(IpcIoPopString(io, nullptr)))) { + ReadInt32(io, &naspac); + if (naspac == VALUE_OBJECT && + !SetElementBundleName(element, reinterpret_cast(ReadString(io, nullptr)))) { ClearElement(element); return false; } - if (IpcIoPopInt32(io) == VALUE_OBJECT && - !SetElementAbilityName(element, reinterpret_cast(IpcIoPopString(io, nullptr)))) { + ReadInt32(io, &naspac); + if (naspac == VALUE_OBJECT && + !SetElementAbilityName(element, reinterpret_cast(ReadString(io, nullptr)))) { ClearElement(element); return false; } diff --git a/interfaces/kits/bundle_lite/js/builtin/BUILD.gn b/interfaces/kits/bundle_lite/js/builtin/BUILD.gn old mode 100755 new mode 100644 index 3a2ebf512a0258e768a784539b76e9cb3432f43e..e0a252a075857b76cd94f4684b58b9870458982e --- a/interfaces/kits/bundle_lite/js/builtin/BUILD.gn +++ b/interfaces/kits/bundle_lite/js/builtin/BUILD.gn @@ -21,7 +21,7 @@ static_library("capability_api_simulator") { "//foundation/arkui/ace_engine_lite/interfaces/inner_api/builtin/base", "//foundation/arkui/ace_engine_lite/interfaces/inner_api/builtin/jsi", "${appexecfwk_lite_path}/interfaces/kits/bundle_lite/js/builtin/include", - "//foundation/communication/ipc_lite/interfaces/kits", + "//foundation/communication/ipc/interfaces/innerkits/c/ipc/include", "${aafwk_lite_path}/interfaces/kits/want_lite", "${appexecfwk_lite_path}/interfaces/kits/bundle_lite", ] @@ -39,7 +39,7 @@ shared_library("capability_api") { "//foundation/arkui/ace_engine_lite/interfaces/inner_api/builtin/base", "//foundation/arkui/ace_engine_lite/interfaces/inner_api/builtin/jsi", "${appexecfwk_lite_path}/interfaces/kits/bundle_lite/js/builtin/include", - "//foundation/communication/ipc_lite/interfaces/kits", + "//foundation/communication/ipc/interfaces/innerkits/c/ipc/include", "${aafwk_lite_path}/interfaces/kits/want_lite", "${appexecfwk_lite_path}/interfaces/kits/bundle_lite", ] diff --git a/services/bundlemgr_lite/BUILD.gn b/services/bundlemgr_lite/BUILD.gn index b2b7adca2ed07a33067489569d48fb9d0db3eee5..9632fe9d52f75f99e25bb9231db04e758e703a35 100644 --- a/services/bundlemgr_lite/BUILD.gn +++ b/services/bundlemgr_lite/BUILD.gn @@ -55,6 +55,7 @@ if (ohos_kernel_type == "liteos_m") { "//base/global/resource_management_lite/interfaces/inner_api/include", "//foundation/distributedschedule/samgr_lite/interfaces/kits/registry", "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", + "//foundation/communication/ipc/interfaces/innerkits/c/ipc/include", "//third_party/jerryscript/jerry-core/api", "//third_party/jerryscript/jerry-core/include", "//third_party/cJSON", diff --git a/services/bundlemgr_lite/bundle_daemon/include/bundlems_client.h b/services/bundlemgr_lite/bundle_daemon/include/bundlems_client.h index 1b2985e388c2f3bc1667be8adfdc91d6d94ecec3..c0a7ea5b0682b4f8ede2389f33d2f2886e7eec05 100644 --- a/services/bundlemgr_lite/bundle_daemon/include/bundlems_client.h +++ b/services/bundlemgr_lite/bundle_daemon/include/bundlems_client.h @@ -16,7 +16,7 @@ #ifndef OHOS_BUNDLEMS_CLIENT_H #define OHOS_BUNDLEMS_CLIENT_H -#include "liteipc_adapter.h" +#include "ipc_skeleton.h" #include "nocopyable.h" #include "ohos_types.h" diff --git a/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon.cpp b/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon.cpp index 3d4c436ad283952d9ac83a7bb84fae726a157c66..3e6b6f7803dcb0b4bd4bd102bf72b7bced1e70f8 100644 --- a/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon.cpp +++ b/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon.cpp @@ -18,11 +18,10 @@ #include #include "bundle_daemon_log.h" -#include "liteipc_adapter.h" +#include "ipc_skeleton.h" #include "ohos_errno.h" #include "ohos_init.h" #include "samgr_lite.h" -#include "serializer.h" namespace OHOS { namespace { @@ -102,12 +101,12 @@ BOOL BundleDaemon::ServiceMessageHandle(Service *service, Request *request) int32_t BundleDaemon::Invoke(IServerProxy *iProxy, int32_t funcId, void *origin, IpcIo *req, IpcIo *reply) { PRINTI("BundleDaemon", "bundle_daemon invoke start %{public}d", funcId); - if (origin == nullptr || req == nullptr) { + if (req == nullptr) { PRINTE("BundleDaemon", "invalid param"); return EC_INVALID; } // check permission - pid_t uid = GetCallingUid(origin); + pid_t uid = GetCallingUid(); if (uid != BMS_UID) { PRINTE("BundleDaemon", "permission denied"); return EC_PERMISSION; @@ -130,7 +129,7 @@ int32_t BundleDaemon::Invoke(IServerProxy *iProxy, int32_t funcId, void *origin, ret = (BundleDaemon::invokeFuncs[funcId])(req); } #ifdef __LINUX__ - IpcIoPushInt32(reply, ret); + WriteInt32(reply, ret); return ret; #else return BundleDaemon::GetInstance().bundleMsClient_->SendReply(ret); @@ -139,38 +138,25 @@ int32_t BundleDaemon::Invoke(IServerProxy *iProxy, int32_t funcId, void *origin, int32_t BundleDaemon::RegisterCallbackInvoke(IpcIo *req) { - SvcIdentity *svcIdentity = IpcIoPopSvc(req); - if (svcIdentity == nullptr) { + SvcIdentity svcIdentity; + if (!(ReadRemoteObject(req, &svcIdentity))) { return EC_INVALID; } - BundleDaemon::GetInstance().bundleMsClient_ = new BundleMsClient(*svcIdentity); + BundleDaemon::GetInstance().bundleMsClient_ = new BundleMsClient(svcIdentity); return BundleDaemon::GetInstance().bundleMsClient_->SendReply(EC_SUCCESS); } static int32_t ObtainStringFromIpc(IpcIo *req, std::string &firstStr, std::string &secondStr) { -#ifdef __LINUX__ size_t length = 0; - std::string innerStr = reinterpret_cast(IpcIoPopString(req, &length)); -#else - BuffPtr *buff = IpcIoPopDataBuff(req); - if (buff == nullptr || buff->buffSz == 0) { - return EC_INVALID; - } - std::string innerStr = reinterpret_cast(buff->buff); -#endif - uint32_t len = IpcIoPopUint16(req); + std::string innerStr = reinterpret_cast(ReadString(req, &length)); + uint16_t len; + ReadUint16(req, &len); if (innerStr.length() <= len) { -#ifndef __LINUX__ - FreeBuffer(nullptr, buff->buff); -#endif return EC_INVALID; } firstStr = innerStr.substr(0, len); secondStr = innerStr.substr(len); -#ifndef __LINUX__ - FreeBuffer(nullptr, buff->buff); -#endif return EC_SUCCESS; } @@ -204,13 +190,16 @@ int32_t BundleDaemon::CreatePermissionInvoke(IpcIo *req) int32_t BundleDaemon::CreateDataDirectoryInvoke(IpcIo *req) { size_t len = 0; - const char *dataPath = reinterpret_cast(IpcIoPopString(req, &len)); + const char *dataPath = reinterpret_cast(ReadString(req, &len)); if (dataPath == nullptr || len == 0) { return EC_INVALID; } - int32_t uid = IpcIoPopInt32(req); - int32_t gid = IpcIoPopInt32(req); - bool isChown = IpcIoPopBool(req); + int32_t uid; + ReadInt32(req, &uid); + int32_t gid; + ReadInt32(req, &gid); + bool isChown; + ReadBool(req, &isChown); return BundleDaemon::GetInstance().handler_.CreateDataDirectory(dataPath, uid, gid, isChown); } @@ -218,41 +207,27 @@ int32_t BundleDaemon::CreateDataDirectoryInvoke(IpcIo *req) int32_t BundleDaemon::StoreContentToFileInvoke(IpcIo *req) { size_t len = 0; - const char *path = reinterpret_cast(IpcIoPopString(req, &len)); + const char *path = reinterpret_cast(ReadString(req, &len)); if (path == nullptr || len == 0) { return EC_INVALID; } -#ifdef __LINUX__ size_t buffLen = 0; - const char *buff = reinterpret_cast(IpcIoPopString(req, &buffLen)); + const char *buff = reinterpret_cast(ReadString(req, &buffLen)); if (buff == nullptr || buffLen == 0) { return EC_INVALID; } int32_t ret = BundleDaemon::GetInstance().handler_.StoreContentToFile(path, buff, buffLen); -#else - BuffPtr *buffPtr = IpcIoPopDataBuff(req); - if (buffPtr == nullptr || buffPtr->buffSz == 0) { - return EC_INVALID; - } - char *buff = reinterpret_cast(buffPtr->buff); - if (buff == nullptr) { - return EC_INVALID; - } - - int32_t ret = BundleDaemon::GetInstance().handler_.StoreContentToFile(path, buff, buffPtr->buffSz); - FreeBuffer(nullptr, buffPtr->buff); -#endif return ret; } int32_t BundleDaemon::MoveFileInvoke(IpcIo *req) { size_t len = 0; - const char *oldFile = reinterpret_cast(IpcIoPopString(req, &len)); + const char *oldFile = reinterpret_cast(ReadString(req, &len)); if (oldFile == nullptr || len == 0) { return EC_INVALID; } - const char *newFile = reinterpret_cast(IpcIoPopString(req, &len)); + const char *newFile = reinterpret_cast(ReadString(req, &len)); if (newFile == nullptr || len == 0) { return EC_INVALID; } @@ -262,7 +237,7 @@ int32_t BundleDaemon::MoveFileInvoke(IpcIo *req) int32_t BundleDaemon::RemoveFileInvoke(IpcIo *req) { size_t len = 0; - const char *path = reinterpret_cast(IpcIoPopString(req, &len)); + const char *path = reinterpret_cast(ReadString(req, &len)); if (path == nullptr || len == 0) { return EC_INVALID; } @@ -277,7 +252,8 @@ int32_t BundleDaemon::RemoveInstallDirectoryInvoke(IpcIo *req) if (ret != EC_SUCCESS) { return ret; } - bool keepData = IpcIoPopBool(req); + bool keepData; + ReadBool(req, &keepData); return BundleDaemon::GetInstance().handler_.RemoveInstallDirectory(codePath.c_str(), dataPath.c_str(), keepData); } } // OHOS diff --git a/services/bundlemgr_lite/bundle_daemon/src/bundlems_client.cpp b/services/bundlemgr_lite/bundle_daemon/src/bundlems_client.cpp index 83ee0e73b661d62f23c727e5263b3b5ec58caa8a..69b995e974d941e1514af117cd647185a0c31c34 100644 --- a/services/bundlemgr_lite/bundle_daemon/src/bundlems_client.cpp +++ b/services/bundlemgr_lite/bundle_daemon/src/bundlems_client.cpp @@ -26,9 +26,12 @@ BundleMsClient::BundleMsClient(const SvcIdentity &svcIdentity) int32 BundleMsClient::SendReply(int32 result) { IpcIo request; - char data[IPC_IO_DATA_MAX]; - IpcIoInit(&request, data, IPC_IO_DATA_MAX, 0); - IpcIoPushInt32(&request, result); - return Transact(nullptr, svcIdentity_, BDS_CALLBACK, &request, nullptr, LITEIPC_FLAG_ONEWAY, nullptr); + char data[MAX_IO_SIZE]; + IpcIoInit(&request, data, MAX_IO_SIZE, 0); + WriteInt32(&request, result); + MessageOption option; + MessageOptionInit(&option); + option.flags = TF_OP_ASYNC; + return SendRequest(svcIdentity_, BDS_CALLBACK, &request, nullptr, option, nullptr); } } // OHOS diff --git a/services/bundlemgr_lite/include/bundle_daemon_client.h b/services/bundlemgr_lite/include/bundle_daemon_client.h index 57d5730d3c3473092203fab117794f1efc7b479e..0387d47f8bc6bacbdee9f7a7d205c4a7c65ce57f 100644 --- a/services/bundlemgr_lite/include/bundle_daemon_client.h +++ b/services/bundlemgr_lite/include/bundle_daemon_client.h @@ -20,7 +20,7 @@ #include "ohos_errno.h" #include "iproxy_client.h" -#include "liteipc_adapter.h" +#include "ipc_skeleton.h" #include "mutex_lock.h" #include "nocopyable.h" @@ -42,8 +42,8 @@ public: int32_t RemoveFile(const char *file); int32_t RemoveInstallDirectory(const char *codePath, const char *dataPath, bool keepData); int32_t CallClientInvoke(int32_t funcId, const char *firstPath, const char *secondPath); - static int32_t BundleDaemonCallback(const IpcContext* context, void *ipcMsg, IpcIo *io, void *arg); - static int32_t DeathCallback(const IpcContext* context, void* ipcMsg, IpcIo* data, void* arg); + static int32_t BundleDaemonCallback(uint32_t code, IpcIo* data, IpcIo* reply, MessageOption option); + static void DeathCallback(void* arg); static int Notify(IOwner owner, int code, IpcIo *reply); private: @@ -53,6 +53,7 @@ private: IClientProxy *bdsClient_ { nullptr }; SvcIdentity svcIdentity_ {}; SvcIdentity bdsSvcIdentity_ {}; + IpcObjectStub objectStub_ {}; uint32_t cbid_ = INVALID_INDEX; sem_t sem_; Mutex mutex_; diff --git a/services/bundlemgr_lite/src/bundle_daemon_client.cpp b/services/bundlemgr_lite/src/bundle_daemon_client.cpp old mode 100755 new mode 100644 index b2367a075d3b1938180e1c13f97c9e34a6559277..f4a405a88e9f037502b661e37bee71262a85dd6e --- a/services/bundlemgr_lite/src/bundle_daemon_client.cpp +++ b/services/bundlemgr_lite/src/bundle_daemon_client.cpp @@ -25,6 +25,7 @@ #include "ohos_errno.h" #include "samgr_lite.h" #include "utils.h" +#include "rpc_errno.h" namespace OHOS { namespace { @@ -41,7 +42,7 @@ int BundleDaemonClient::Notify(IOwner owner, int code, IpcIo *reply) if (client == nullptr) { return EC_INVALID; } - client->result_ = IpcIoPopInt32(reply); + ReadInt32(reply, &(client->result_)); int value; sem_getvalue(&client->sem_, &value); if (value <= 0) { @@ -50,20 +51,14 @@ int BundleDaemonClient::Notify(IOwner owner, int code, IpcIo *reply) return EC_SUCCESS; } #else -int32_t BundleDaemonClient::BundleDaemonCallback(const IpcContext* context, void *ipcMsg, IpcIo *io, void *arg) +int32_t BundleDaemonClient::BundleDaemonCallback(uint32_t code, IpcIo* data, IpcIo* reply, MessageOption option) { - BundleDaemonClient *client = reinterpret_cast(arg); + BundleDaemonClient *client = reinterpret_cast(option.args); if (client == nullptr) { - if (ipcMsg != nullptr) { - FreeBuffer(nullptr, ipcMsg); - } return EC_INVALID; } - client->result_ = IpcIoPopInt32(io); - if (ipcMsg != nullptr) { - FreeBuffer(nullptr, ipcMsg); - } + ReadInt32(data, &(client->result_)); int value; sem_getvalue(&client->sem_, &value); if (value <= 0) { @@ -73,33 +68,27 @@ int32_t BundleDaemonClient::BundleDaemonCallback(const IpcContext* context, void } #endif -int32_t BundleDaemonClient::DeathCallback(const IpcContext* context, void* ipcMsg, IpcIo* data, void* arg) +void BundleDaemonClient::DeathCallback(void* arg) { - if (ipcMsg != nullptr) { - FreeBuffer(nullptr, ipcMsg); - } pthread_t pid; - if (pthread_create(&pid, nullptr, RegisterDeathCallback, arg) == 0) { - return EC_SUCCESS; - } - BundleDaemonClient *client = reinterpret_cast(arg); - if (client != nullptr) { - client->result_ = EC_CANCELED; - int value; - sem_getvalue(&client->sem_, &value); - if (value <= 0) { - sem_post(&client->sem_); + if (pthread_create(&pid, nullptr, RegisterDeathCallback, arg) != 0) { + BundleDaemonClient *client = reinterpret_cast(arg); + if (client != nullptr) { + client->result_ = EC_CANCELED; + int value; + sem_getvalue(&client->sem_, &value); + if (value <= 0) { + sem_post(&client->sem_); + } } } - return EC_INVALID; } BundleDaemonClient::~BundleDaemonClient() { if (initialized_) { - UnregisterIpcCallback(svcIdentity_); - UnregisterDeathCallback(bdsSvcIdentity_, cbid_); + RemoveDeathRecipient(bdsSvcIdentity_, cbid_); bdsClient_->Release(reinterpret_cast(bdsClient_)); bdsClient_ = nullptr; sem_destroy(&sem_); @@ -129,15 +118,15 @@ bool BundleDaemonClient::Initialize() // register bundle_daemon callback #ifndef __LINUX__ - int32_t ret = RegisterIpcCallback( - BundleDaemonClient::BundleDaemonCallback, 0, IPC_WAIT_FOREVER, &svcIdentity_, this); - if (ret != EC_SUCCESS) { - PRINTE("BundleDaemonClient", "register bundle_daemon RegisterIpcCallback fail"); - sem_destroy(&sem_); - return false; - } + objectStub_.func = BundleDaemonClient::BundleDaemonCallback; + objectStub_.args = this; + objectStub_.isRemote = false; + + svcIdentity_.handle = IPC_INVALID_HANDLE; + svcIdentity_.token = SERVICE_TYPE_ANONYMOUS; + svcIdentity_.cookie = (uintptr_t)&objectStub_; #endif - if (RegisterCallback() != LITEIPC_OK) { + if (RegisterCallback() != ERR_NONE) { PRINTE("BundleDaemonClient", "register bundle_daemon callback fail"); sem_destroy(&sem_); return false; @@ -145,8 +134,7 @@ bool BundleDaemonClient::Initialize() // register bundle_daemon death callback bdsSvcIdentity_ = SAMGR_GetRemoteIdentity(BDS_SERVICE, nullptr); - if (::RegisterDeathCallback(nullptr, bdsSvcIdentity_, &BundleDaemonClient::DeathCallback, this, &cbid_) != - LITEIPC_OK) { + if (::AddDeathRecipient(bdsSvcIdentity_, &BundleDaemonClient::DeathCallback, this, &cbid_) != ERR_NONE) { PRINTW("BundleDaemonClient", "register bundle_daemon death callback fail"); // Keep running if register death callback fail } @@ -170,15 +158,15 @@ void *BundleDaemonClient::RegisterDeathCallback(void *arg) // Register invoke callback and death callback again Lock lock(client->mutex_); client->RegisterCallback(); + RemoveDeathRecipient(client->bdsSvcIdentity_, client->cbid_); - UnregisterDeathCallback(client->bdsSvcIdentity_, client->cbid_); client->cbid_ = INVALID_INDEX; client->bdsSvcIdentity_.handle = INVALID_INDEX; client->bdsSvcIdentity_.token = INVALID_INDEX; client->bdsSvcIdentity_ = SAMGR_GetRemoteIdentity(BDS_SERVICE, nullptr); - if (::RegisterDeathCallback(nullptr, client->bdsSvcIdentity_, &BundleDaemonClient::DeathCallback, - client, &client->cbid_) != LITEIPC_OK) { + if (::AddDeathRecipient(client->bdsSvcIdentity_, &BundleDaemonClient::DeathCallback, + client, &client->cbid_) != ERR_NONE) { PRINTW("BundleDeamonClient", "register death callback fail"); // Keep running if register death callback fail } @@ -199,9 +187,12 @@ int32_t BundleDaemonClient::WaitResultSync(int32_t result) int32_t BundleDaemonClient::RegisterCallback() { IpcIo request; - char data[IPC_IO_DATA_MAX]; - IpcIoInit(&request, data, IPC_IO_DATA_MAX, 1); - IpcIoPushSvc(&request, &svcIdentity_); + char data[MAX_IO_SIZE]; + IpcIoInit(&request, data, MAX_IO_SIZE, 1); + bool writeRemote = WriteRemoteObject(&request, &svcIdentity_); + if (!writeRemote) { + return EC_FAILURE; + } #ifdef __LINUX__ while (bdsClient_->Invoke(bdsClient_, REGISTER_CALLBACK, &request, this, Notify) != EC_SUCCESS) { #else @@ -216,28 +207,13 @@ int32_t BundleDaemonClient::RegisterCallback() int32_t BundleDaemonClient::CallClientInvoke(int32_t funcId, const char *firstPath, const char *secondPath) { IpcIo request; - char data[IPC_IO_DATA_MAX]; -#ifdef __LINUX__ - IpcIoInit(&request, data, IPC_IO_DATA_MAX, 0); -#else - IpcIoInit(&request, data, IPC_IO_DATA_MAX, 1); -#endif + char data[MAX_IO_SIZE]; + IpcIoInit(&request, data, MAX_IO_SIZE, 0); std::string innerStr = firstPath; innerStr += secondPath; -#ifdef __LINUX__ - IpcIoPushString(&request, innerStr.c_str()); -#else - BuffPtr dataBuff = { - .buffSz = innerStr.length() + 1, - .buff = const_cast(innerStr.c_str()) - }; - IpcIoPushDataBuff(&request, &dataBuff); -#endif - IpcIoPushUint16(&request, strlen(firstPath)); - if (!IpcIoAvailable(&request)) { - PRINTE("BundleDaemonClient", "BundleDaemonClient GenerateRequest ipc failed"); - return EC_FAILURE; - } + WriteString(&request, innerStr.c_str()); + + WriteUint16(&request, strlen(firstPath)); Lock lock(mutex_); #ifdef __LINUX__ @@ -296,12 +272,12 @@ int32_t BundleDaemonClient::CreateDataDirectory(const char *dataPath, int32_t ui return EC_INVALID; } IpcIo request; - char data[IPC_IO_DATA_MAX]; - IpcIoInit(&request, data, IPC_IO_DATA_MAX, 0); - IpcIoPushString(&request, dataPath); - IpcIoPushInt32(&request, uid); - IpcIoPushInt32(&request, gid); - IpcIoPushBool(&request, isChown); + char data[MAX_IO_SIZE]; + IpcIoInit(&request, data, MAX_IO_SIZE, 0); + WriteString(&request, dataPath); + WriteInt32(&request, uid); + WriteInt32(&request, gid); + WriteBool(&request, isChown); Lock lock(mutex_); #ifdef __LINUX__ @@ -321,22 +297,12 @@ int32_t BundleDaemonClient::StoreContentToFile(const char *file, const void *buf return EC_INVALID; } IpcIo request; - char data[IPC_IO_DATA_MAX]; -#ifdef __LINUX__ - IpcIoInit(&request, data, IPC_IO_DATA_MAX, 0); -#else - IpcIoInit(&request, data, IPC_IO_DATA_MAX, 1); -#endif - IpcIoPushString(&request, file); -#ifdef __LINUX__ - IpcIoPushString(&request, static_cast(buffer)); -#else - BuffPtr dataBuff = { - .buffSz = size, // include \0 - .buff = const_cast(buffer) - }; - IpcIoPushDataBuff(&request, &dataBuff); -#endif + char data[MAX_IO_SIZE]; + + IpcIoInit(&request, data, MAX_IO_SIZE, 0); + + WriteString(&request, file); + WriteString(&request, static_cast(buffer)); Lock lock(mutex_); #ifdef __LINUX__ return WaitResultSync(bdsClient_->Invoke(bdsClient_, STORE_CONTENT_TO_FILE, &request, this, Notify)); @@ -355,10 +321,10 @@ int32_t BundleDaemonClient::MoveFile(const char *oldFile, const char *newFile) return EC_INVALID; } IpcIo request; - char data[IPC_IO_DATA_MAX]; - IpcIoInit(&request, data, IPC_IO_DATA_MAX, 0); - IpcIoPushString(&request, oldFile); - IpcIoPushString(&request, newFile); + char data[MAX_IO_SIZE]; + IpcIoInit(&request, data, MAX_IO_SIZE, 0); + WriteString(&request, oldFile); + WriteString(&request, newFile); Lock lock(mutex_); #ifdef __LINUX__ @@ -378,9 +344,9 @@ int32_t BundleDaemonClient::RemoveFile(const char *file) return EC_INVALID; } IpcIo request; - char data[IPC_IO_DATA_MAX]; - IpcIoInit(&request, data, IPC_IO_DATA_MAX, 0); - IpcIoPushString(&request, file); + char data[MAX_IO_SIZE]; + IpcIoInit(&request, data, MAX_IO_SIZE, 0); + WriteString(&request, file); Lock lock(mutex_); #ifdef __LINUX__ diff --git a/services/bundlemgr_lite/src/bundle_inner_feature.cpp b/services/bundlemgr_lite/src/bundle_inner_feature.cpp old mode 100755 new mode 100644 index b64ca40a29d4edeec6fdebc7a38b935353738aa0..878c1ee60ad5908a36d51a18132e4de6ef15510c --- a/services/bundlemgr_lite/src/bundle_inner_feature.cpp +++ b/services/bundlemgr_lite/src/bundle_inner_feature.cpp @@ -22,7 +22,7 @@ #include "bundle_manager_service.h" #include "bundle_message_id.h" #include "convert_utils.h" -#include "liteipc_adapter.h" +#include "ipc_skeleton.h" #include "log.h" #include "message.h" #include "ohos_init.h" @@ -113,42 +113,20 @@ uint8_t BundleInnerFeature::InstallInnerBundle(const uint8_t funcId, IpcIo *req, HILOG_ERROR(HILOG_MODULE_APP, "BundleMS InstallInnerBundle, request or reply is null"); return ERR_APPEXECFWK_OBJECT_NULL; } -#ifdef __LINUX__ size_t length = 0; - char *reqPath = reinterpret_cast(IpcIoPopString(req, &length)); -#else - BuffPtr *buff = IpcIoPopDataBuff(req); - if (buff == nullptr) { - HILOG_ERROR(HILOG_MODULE_APP, "BundleMS inner feature deserialize req data failed"); - return ERR_APPEXECFWK_DESERIALIZATION_FAILED; - } - char *reqPath = reinterpret_cast(buff->buff); - if ((reqPath == nullptr) || (buff->buffSz == 0)) { - HILOG_ERROR(HILOG_MODULE_APP, "BundleMS inner feature deserialize install path failed"); - return ERR_APPEXECFWK_DESERIALIZATION_FAILED; - } -#endif - SvcIdentity *svc = IpcIoPopSvc(req); - if (svc == nullptr) { + char *reqPath = reinterpret_cast(ReadString(req, &length)); + SvcIdentity svc; + if (!(ReadRemoteObject(req, &svc))) { HILOG_ERROR(HILOG_MODULE_APP, "BundleMS inner feature deserialize serviceId failed"); return ERR_APPEXECFWK_DESERIALIZATION_FAILED; } SvcIdentityInfo *info = reinterpret_cast(AdapterMalloc(sizeof(SvcIdentityInfo))); if (info == nullptr) { -#ifdef __LINUX__ - AdapterFree(svc); - svc = nullptr; -#endif HILOG_ERROR(HILOG_MODULE_APP, "BundleMS inner feature malloc service info info failed"); return ERR_APPEXECFWK_SYSTEM_INTERNAL_ERROR; } - uint8_t svcIdentityInfoRsp = GetSvcIdentityInfo(info, svc, reqPath, req); -#ifdef __LINUX__ - BinderAcquire(svc->ipcContext, svc->handle); - AdapterFree(svc); - svc = nullptr; -#endif + uint8_t svcIdentityInfoRsp = GetSvcIdentityInfo(info, &svc, reqPath, req); if (svcIdentityInfoRsp != ERR_OK) { return svcIdentityInfoRsp; } @@ -190,7 +168,7 @@ uint8_t BundleInnerFeature::GetSvcIdentityInfo(SvcIdentityInfo *info, const SvcI return ERR_APPEXECFWK_SYSTEM_INTERNAL_ERROR; } *(info->svc) = *svc; - info->installLocation = IpcIoPopInt32(req); + ReadInt32(req, &(info->installLocation)); info->keepData = false; return ERR_OK; @@ -203,22 +181,18 @@ uint8_t BundleInnerFeature::UninstallInnerBundle(const uint8_t funcId, IpcIo *re return ERR_APPEXECFWK_OBJECT_NULL; } size_t length = 0; - char *bundleName = reinterpret_cast(IpcIoPopString(req, &length)); + char *bundleName = reinterpret_cast(ReadString(req, &length)); if (bundleName == nullptr) { HILOG_ERROR(HILOG_MODULE_APP, "BundleMS inner feature deserialize bundle name failed"); return ERR_APPEXECFWK_DESERIALIZATION_FAILED; } - SvcIdentity *svc = IpcIoPopSvc(req); - if (svc == nullptr) { + SvcIdentity svc; + if (!(ReadRemoteObject(req, &svc))) { HILOG_ERROR(HILOG_MODULE_APP, "BundleMS inner feature deserialize serviceId failed"); return ERR_APPEXECFWK_DESERIALIZATION_FAILED; } SvcIdentityInfo *info = reinterpret_cast(AdapterMalloc(sizeof(SvcIdentityInfo))); if (info == nullptr) { -#ifdef __LINUX__ - AdapterFree(svc); - svc = nullptr; -#endif HILOG_ERROR(HILOG_MODULE_APP, "BundleMS inner feature malloc service info failed"); return ERR_APPEXECFWK_SYSTEM_INTERNAL_ERROR; } @@ -228,21 +202,12 @@ uint8_t BundleInnerFeature::UninstallInnerBundle(const uint8_t funcId, IpcIo *re if (info->svc == nullptr) { AdapterFree(info->bundleName); AdapterFree(info); -#ifdef __LINUX__ - AdapterFree(svc); - svc = nullptr; -#endif HILOG_ERROR(HILOG_MODULE_APP, "BundleMS inner feature malloc serviceId failed"); return ERR_APPEXECFWK_SYSTEM_INTERNAL_ERROR; } - *(info->svc) = *svc; -#ifdef __LINUX__ - BinderAcquire(svc->ipcContext, svc->handle); - AdapterFree(svc); - svc = nullptr; -#endif + *(info->svc) = svc; info->installLocation = 0; - info->keepData = IpcIoPopBool(req); + ReadBool(req, &(info->keepData)); Request request = { .msgId = BUNDLE_UNINSTALLED, .len = static_cast(sizeof(SvcIdentityInfo)), @@ -265,9 +230,11 @@ uint8_t BundleInnerFeature::SetExternalInstallMode(const uint8_t funcId, IpcIo * if ((req == nullptr) || (reply == nullptr)) { return ERR_APPEXECFWK_OBJECT_NULL; } - uint8_t errorCode = OHOS::ManagerService::GetInstance().SetExternalInstallMode(IpcIoPopBool(req)); + bool mode; + ReadBool(req, &mode); + uint8_t errorCode = OHOS::ManagerService::GetInstance().SetExternalInstallMode(mode); if (errorCode == OHOS_SUCCESS) { - IpcIoPushUint8(reply, static_cast(OHOS_SUCCESS)); + WriteUint8(reply, static_cast(OHOS_SUCCESS)); } return errorCode; } @@ -277,9 +244,11 @@ uint8_t BundleInnerFeature::SetInnerDebugMode(const uint8_t funcId, IpcIo *req, if ((req == nullptr) || (reply == nullptr)) { return ERR_APPEXECFWK_OBJECT_NULL; } - uint8_t errorCode = OHOS::ManagerService::GetInstance().SetDebugMode(IpcIoPopBool(req)); + bool mode; + ReadBool(req, &mode); + uint8_t errorCode = OHOS::ManagerService::GetInstance().SetDebugMode(mode); if (errorCode == OHOS_SUCCESS) { - IpcIoPushUint8(reply, static_cast(OHOS_SUCCESS)); + WriteUint8(reply, static_cast(OHOS_SUCCESS)); } return errorCode; } @@ -289,9 +258,11 @@ uint8_t BundleInnerFeature::SetInnerSignMode(const uint8_t funcId, IpcIo *req, I if ((req == nullptr) || (reply == nullptr)) { return ERR_APPEXECFWK_OBJECT_NULL; } - uint8_t errorCode = OHOS::ManagerService::GetInstance().SetSignMode(IpcIoPopBool(req)); + bool mode; + ReadBool(req, &mode); + uint8_t errorCode = OHOS::ManagerService::GetInstance().SetSignMode(mode); if (errorCode == OHOS_SUCCESS) { - IpcIoPushUint8(reply, static_cast(OHOS_SUCCESS)); + WriteUint8(reply, static_cast(OHOS_SUCCESS)); } return errorCode; } @@ -302,7 +273,7 @@ int32 BundleInnerFeature::Invoke(IServerProxy *iProxy, int funcId, void *origin, if (req == nullptr) { return ERR_APPEXECFWK_OBJECT_NULL; } - IpcIoPushUint8(reply, static_cast(funcId)); + WriteUint8(reply, static_cast(funcId)); uint8_t ret = OHOS_SUCCESS; #ifdef OHOS_DEBUG if ((funcId >= BMS_INNER_BEGIN) && (funcId < BMS_CMD_END)) { @@ -315,7 +286,7 @@ int32 BundleInnerFeature::Invoke(IServerProxy *iProxy, int funcId, void *origin, } if (ret != OHOS_SUCCESS) { - IpcIoPushUint8(reply, ret); + WriteUint8(reply, ret); } return ret; } diff --git a/services/bundlemgr_lite/src/bundle_manager_service.cpp b/services/bundlemgr_lite/src/bundle_manager_service.cpp old mode 100755 new mode 100644 index b4e28ab037b39e41623c8553d917b1670410674f..77007b7f3ad48cfe29fcc487043bb8087be86212 --- a/services/bundlemgr_lite/src/bundle_manager_service.cpp +++ b/services/bundlemgr_lite/src/bundle_manager_service.cpp @@ -39,7 +39,8 @@ extern "C" { #include "bundle_message_id.h" #include "bundle_parser.h" #include "bundle_util.h" -#include "liteipc_adapter.h" +#include "ipc_skeleton.h" +#include "rpc_errno.h" #include "log.h" #include "samgr_lite.h" #include "utils.h" @@ -69,23 +70,22 @@ static void InnerTransact(uint32_t code, uint8_t resultCode, const char *bundleN return; } IpcIo io; - char data[IPC_IO_DATA_MAX]; + char data[MAX_IO_SIZE]; IpcIo reply; uintptr_t ptr; - IpcIoInit(&io, data, IPC_IO_DATA_MAX, 0); - IpcIoPushInt32(&io, static_cast(resultCode)); - IpcIoPushString(&io, bundleName); - if (!IpcIoAvailable(&io)) { - HILOG_ERROR(HILOG_MODULE_APP, "BundleMS InnerTransact ipc failed"); - return; - } + IpcIoInit(&io, data, MAX_IO_SIZE, 0); + WriteInt32(&io, static_cast(resultCode)); + WriteString(&io, bundleName); std::vector svcIdentity = ManagerService::GetInstance().GetServiceId(); if (svcIdentity.empty()) { return; } + MessageOption option; + MessageOptionInit(&option); + option.flags = TF_OP_ASYNC; for (const auto& svc : svcIdentity) { - int32_t ret = Transact(NULL, svc, code, &io, &reply, LITEIPC_FLAG_ONEWAY, &ptr); - if (ret != LITEIPC_OK) { + int32_t ret = SendRequest(svc, code, &io, &reply, option, &ptr); + if (ret != ERR_NONE) { HILOG_ERROR(HILOG_MODULE_APP, "BundleMS InnerTransact failed %{public}d\n", ret); return; } @@ -95,17 +95,19 @@ static void InnerTransact(uint32_t code, uint8_t resultCode, const char *bundleN static void InnerSelfTransact(uint32_t code, uint8_t resultCode, const SvcIdentity &svc) { IpcIo io; - char data[IPC_IO_DATA_MAX]; + char data[MAX_IO_SIZE]; IpcIo reply; - IpcIoInit(&io, data, IPC_IO_DATA_MAX, 0); - IpcIoPushInt32(&io, static_cast(resultCode)); - int32_t ret = Transact(NULL, svc, code, &io, &reply, LITEIPC_FLAG_ONEWAY, NULL); - if (ret != LITEIPC_OK) { + IpcIoInit(&io, data, MAX_IO_SIZE, 0); + WriteInt32(&io, static_cast(resultCode)); + + MessageOption option; + MessageOptionInit(&option); + option.flags = TF_OP_ASYNC; + int32_t ret = SendRequest(svc, code, &io, &reply, option, NULL); + if (ret != ERR_NONE) { HILOG_ERROR(HILOG_MODULE_APP, "BundleMS InnerSelfTransact failed %{public}d\n", ret); } -#ifdef __LINUX__ - BinderRelease(svc.ipcContext, svc.handle); -#endif + ReleaseSvc(svc); } std::vector ManagerService::GetServiceId() const @@ -275,9 +277,7 @@ void ManagerService::AddCallbackServiceId(const SvcIdentity &svc) void ManagerService::RemoveCallbackServiceId(const SvcIdentity &svc) { -#ifdef __LINUX__ - BinderRelease(svc.ipcContext, svc.handle); -#endif + ReleaseSvc(svc); for (auto it = svcIdentity_.begin(); it != svcIdentity_.end(); ++it) { if (CompareServiceId(*it, svc)) { svcIdentity_.erase(it); diff --git a/services/bundlemgr_lite/src/bundle_ms_feature.cpp b/services/bundlemgr_lite/src/bundle_ms_feature.cpp old mode 100755 new mode 100644 index 785545f9a1cf395cc3efee3a9acd0099a70bf0fe..6d6b10bce7601c63c9419a47264cbe854011b073 --- a/services/bundlemgr_lite/src/bundle_ms_feature.cpp +++ b/services/bundlemgr_lite/src/bundle_ms_feature.cpp @@ -22,13 +22,12 @@ #include "bundle_manager_service.h" #include "bundle_message_id.h" #include "convert_utils.h" -#include "liteipc_adapter.h" +#include "ipc_skeleton.h" #include "log.h" #include "message.h" #include "ohos_init.h" #include "samgr_lite.h" #include "securec.h" -#include "serializer.h" #include "utils.h" #include "want_utils.h" @@ -134,13 +133,13 @@ uint8_t BundleMsFeature::HasSystemCapability(const uint8_t funcId, IpcIo *req, I return ERR_APPEXECFWK_OBJECT_NULL; } size_t size = 0; - char *sysCapName = reinterpret_cast(IpcIoPopString(req, &size)); + char *sysCapName = reinterpret_cast(ReadString(req, &size)); if (sysCapName == nullptr) { return ERR_APPEXECFWK_DESERIALIZATION_FAILED; } bool hasSysCap = OHOS::ManagerService::GetInstance().HasSystemCapability(sysCapName); if (hasSysCap) { - IpcIoPushUint8(reply, static_cast(OHOS_SUCCESS)); + WriteUint8(reply, static_cast(OHOS_SUCCESS)); return OHOS_SUCCESS; } return ERR_APPEXECFWK_OBJECT_NULL; @@ -158,10 +157,10 @@ uint8_t BundleMsFeature::GetSystemAvailableCapabilities(const uint8_t funcId, Ip if (errorCode != OHOS_SUCCESS) { return errorCode; } - IpcIoPushUint8(reply, static_cast(OHOS_SUCCESS)); - IpcIoPushInt32(reply, len); + WriteUint8(reply, static_cast(OHOS_SUCCESS)); + WriteInt32(reply, len); for (int32_t index = 0; index < len; index++) { - IpcIoPushString(reply, sysCaps[index]); + WriteString(reply, sysCaps[index]); } return errorCode; } @@ -203,13 +202,8 @@ uint8_t BundleMsFeature::QueryInnerAbilityInfo(const uint8_t funcId, IpcIo *req, return ERR_APPEXECFWK_SERIALIZATION_FAILED; } #endif - IpcIoPushUint8(reply, static_cast(OHOS_SUCCESS)); -#ifdef __LINUX__ - IpcIoPushString(reply, str); -#else - BuffPtr dataBuff = {.buffSz = strlen(str) + 1, .buff = str}; - IpcIoPushDataBuffWithFree(reply, &dataBuff, InnerFreeDataBuff); -#endif + WriteUint8(reply, static_cast(OHOS_SUCCESS)); + WriteString(reply, str); ClearAbilityInfo(&abilityInfo); return OHOS_SUCCESS; } @@ -220,7 +214,7 @@ uint8_t BundleMsFeature::GetInnerBundleInfo(const uint8_t funcId, IpcIo *req, Ip return ERR_APPEXECFWK_OBJECT_NULL; } size_t size = 0; - char *bundleName = reinterpret_cast(IpcIoPopString(req, &size)); + char *bundleName = reinterpret_cast(ReadString(req, &size)); if (bundleName == nullptr) { return ERR_APPEXECFWK_DESERIALIZATION_FAILED; } @@ -228,7 +222,9 @@ uint8_t BundleMsFeature::GetInnerBundleInfo(const uint8_t funcId, IpcIo *req, Ip if (memset_s(&bundleInfo, sizeof(BundleInfo), 0, sizeof(BundleInfo)) != EOK) { return ERR_APPEXECFWK_SYSTEM_INTERNAL_ERROR; } - uint8_t errorCode = GetBundleInfo(bundleName, IpcIoPopInt32(req), &bundleInfo); + int32_t flag; + ReadInt32(req, &flag); + uint8_t errorCode = GetBundleInfo(bundleName, flag, &bundleInfo); if (errorCode != OHOS_SUCCESS) { HILOG_ERROR(HILOG_MODULE_APP, "BundleMS GET_BUNDLE_INFO errorcode: %{public}d\n", errorCode); return errorCode; @@ -242,13 +238,8 @@ uint8_t BundleMsFeature::GetInnerBundleInfo(const uint8_t funcId, IpcIo *req, Ip return ERR_APPEXECFWK_SERIALIZATION_FAILED; } #endif - IpcIoPushUint8(reply, static_cast(OHOS_SUCCESS)); -#ifdef __LINUX__ - IpcIoPushString(reply, str); -#else - BuffPtr dataBuff = {.buffSz = strlen(str) + 1, .buff = str}; - IpcIoPushDataBuffWithFree(reply, &dataBuff, InnerFreeDataBuff); -#endif + WriteUint8(reply, static_cast(OHOS_SUCCESS)); + WriteString(reply, str); return OHOS_SUCCESS; } @@ -259,15 +250,15 @@ uint8_t BundleMsFeature::GetInnerBundleSize(const uint8_t funcId, IpcIo *req, Ip } size_t size = 0; uint32_t bundleSize = 0; - char *bundleName = reinterpret_cast(IpcIoPopString(req, &size)); + char *bundleName = reinterpret_cast(ReadString(req, &size)); if (bundleName == nullptr) { - IpcIoPushUint8(reply, static_cast(OHOS_SUCCESS)); - IpcIoPushUint32(reply, bundleSize); + WriteUint8(reply, static_cast(OHOS_SUCCESS)); + WriteUint32(reply, bundleSize); return OHOS_SUCCESS; } bundleSize = GetBundleSize(bundleName); - IpcIoPushUint8(reply, static_cast(OHOS_SUCCESS)); - IpcIoPushUint32(reply, bundleSize); + WriteUint8(reply, static_cast(OHOS_SUCCESS)); + WriteUint32(reply, bundleSize); return OHOS_SUCCESS; } @@ -282,11 +273,13 @@ uint8_t BundleMsFeature::HandleGetBundleInfos(const uint8_t funcId, IpcIo *req, uint8_t errorCode = 0; size_t length = 0; if (funcId == GET_BUNDLE_INFOS) { - errorCode = GetBundleInfos(IpcIoPopInt32(req), &bundleInfos, &lengthOfBundleInfo); + int32_t flag; + ReadInt32(req, &flag); + errorCode = GetBundleInfos(flag, &bundleInfos, &lengthOfBundleInfo); } else if (funcId == QUERY_KEEPALIVE_BUNDLE_INFOS) { errorCode = QueryKeepAliveBundleInfos(&bundleInfos, &lengthOfBundleInfo); } else if (funcId == GET_BUNDLE_INFOS_BY_METADATA) { - metaDataKey = reinterpret_cast(IpcIoPopString(req, &length)); + metaDataKey = reinterpret_cast(ReadString(req, &length)); if (metaDataKey == nullptr) { return ERR_APPEXECFWK_DESERIALIZATION_FAILED; } @@ -309,14 +302,9 @@ uint8_t BundleMsFeature::HandleGetBundleInfos(const uint8_t funcId, IpcIo *req, return ERR_APPEXECFWK_SERIALIZATION_FAILED; } #endif - IpcIoPushUint8(reply, static_cast(OHOS_SUCCESS)); - IpcIoPushInt32(reply, lengthOfBundleInfo); -#ifdef __LINUX__ - IpcIoPushString(reply, strs); -#else - BuffPtr dataBuff = {.buffSz = strlen(strs) + 1, .buff = strs}; - IpcIoPushDataBuffWithFree(reply, &dataBuff, InnerFreeDataBuff); -#endif + WriteUint8(reply, static_cast(OHOS_SUCCESS)); + WriteInt32(reply, lengthOfBundleInfo); + WriteString(reply, strs); BundleInfoUtils::FreeBundleInfos(bundleInfos, lengthOfBundleInfo); return OHOS_SUCCESS; } @@ -327,13 +315,15 @@ uint8_t BundleMsFeature::GetInnerBundleNameForUid(const uint8_t funcId, IpcIo *r return ERR_APPEXECFWK_OBJECT_NULL; } char *bundleName = nullptr; - uint8_t errorCode = GetBundleNameForUid(IpcIoPopInt32(req), &bundleName); + int32_t readUid; + ReadInt32(req, &readUid); + uint8_t errorCode = GetBundleNameForUid(readUid, &bundleName); if (errorCode != OHOS_SUCCESS) { AdapterFree(bundleName); return errorCode; } - IpcIoPushUint8(reply, static_cast(OHOS_SUCCESS)); - IpcIoPushString(reply, bundleName); + WriteUint8(reply, static_cast(OHOS_SUCCESS)); + WriteString(reply, bundleName); AdapterFree(bundleName); return errorCode; } @@ -343,26 +333,18 @@ uint8_t BundleMsFeature::ChangeInnerCallbackServiceId(const uint8_t funcId, IpcI if ((req == nullptr) || (reply == nullptr)) { return ERR_APPEXECFWK_OBJECT_NULL; } - bool flag = IpcIoPopBool(req); - SvcIdentity *svc = IpcIoPopSvc(req); - if (svc == nullptr) { + bool flag; + ReadBool(req, &flag); + SvcIdentity svc; + if (!(ReadRemoteObject(req, &svc))) { return ERR_APPEXECFWK_DESERIALIZATION_FAILED; } auto svcIdentity = reinterpret_cast(AdapterMalloc(sizeof(SvcIdentity))); if (svcIdentity == nullptr) { -#ifdef __LINUX__ - AdapterFree(svc); - svc = nullptr; -#endif return ERR_APPEXECFWK_SYSTEM_INTERNAL_ERROR; } - *svcIdentity = *svc; -#ifdef __LINUX__ - BinderAcquire(svc->ipcContext, svc->handle); - AdapterFree(svc); - svc = nullptr; -#endif + *svcIdentity = svc; Request request = { .msgId = BUNDLE_CHANGE_CALLBACK, .len = static_cast(sizeof(SvcIdentity)), @@ -382,7 +364,7 @@ int32 BundleMsFeature::Invoke(IServerProxy *iProxy, int funcId, void *origin, Ip if (req == nullptr) { return ERR_APPEXECFWK_OBJECT_NULL; } - IpcIoPushUint8(reply, static_cast(funcId)); + WriteUint8(reply, static_cast(funcId)); uint8_t ret = OHOS_SUCCESS; if (funcId >= GET_BUNDLE_INFOS && funcId <= GET_BUNDLE_INFOS_BY_METADATA) { ret = BundleMsInvokeFuc[GET_BUNDLE_INFOS](funcId, req, reply); @@ -395,7 +377,7 @@ int32 BundleMsFeature::Invoke(IServerProxy *iProxy, int funcId, void *origin, Ip } if (ret != OHOS_SUCCESS) { - IpcIoPushUint8(reply, ret); + WriteUint8(reply, ret); } return ret; } diff --git a/services/bundlemgr_lite/tools/BUILD.gn b/services/bundlemgr_lite/tools/BUILD.gn index 4c9d99af546894bcfb343aeba0ae6afaa6fb20d9..a0a33ed0a9006aa8488580466384f27bfdc0b379 100644 --- a/services/bundlemgr_lite/tools/BUILD.gn +++ b/services/bundlemgr_lite/tools/BUILD.gn @@ -38,10 +38,10 @@ executable("bm") { deps = [ "${appexecfwk_lite_path}/frameworks/bundle_lite:bundle", "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", - "//base/startup/syspara_lite/frameworks/parameter:parameter", "//base/security/permission/services/permission_lite/pms_client:pms_client", + "//base/startup/syspara_lite/frameworks/parameter:parameter", "//build/lite/config/component/cJSON:cjson_shared", - "//foundation/communication/ipc_lite:liteipc_adapter", + "//foundation/communication/ipc/interfaces/innerkits/c/ipc:ipc_single", "//foundation/distributedschedule/samgr_lite/samgr:samgr", ] @@ -61,6 +61,7 @@ executable("bm") { "//foundation/distributedschedule/samgr_lite/interfaces/kits/registry", "//third_party/cJSON", "//utils/native/lite/include", + "//foundation/communication/ipc/interfaces/innerkits/c/ipc/include", ] defines = [ "OHOS_APPEXECFWK_BMS_BUNDLEMANAGER" ] diff --git a/services/bundlemgr_lite/tools/src/command_parser.cpp b/services/bundlemgr_lite/tools/src/command_parser.cpp index 28f9687a56950a62e524b2ff5a384dab561bb33b..a25255d3c3cd843239ddca7660dc4c0d6ea91b99 100644 --- a/services/bundlemgr_lite/tools/src/command_parser.cpp +++ b/services/bundlemgr_lite/tools/src/command_parser.cpp @@ -29,10 +29,11 @@ #include "bundle_manager.h" #include "convert_utils.h" #include "iproxy_client.h" -#include "liteipc_adapter.h" +#include "ipc_skeleton.h" #include "parameter.h" #include "samgr_lite.h" #include "securec.h" +#include "rpc_errno.h" using namespace std; @@ -157,9 +158,8 @@ static void ReceiveCallback(const uint8_t resultCode, const void *resultMessage) sem_post(&g_sem); } -static int32 BmToolDeathNotify(const IpcContext* context, void *ipcMsg, IpcIo *data, void *arg) +static void BmToolDeathNotify(void *arg) { - FreeBuffer(nullptr, ipcMsg); printf("error message: %s\n", "Bundle Manager Service is dead"); exit(-1); } @@ -193,7 +193,7 @@ void CommandParser::RunAsInstallCommand(int32_t argc, char *argv[]) const printf("error message: %s\n", ERROR_INSTALL_PATH.c_str()); return; } - if (RegisterDeathCallback(nullptr, sid, BmToolDeathNotify, nullptr, &cbId) != LITEIPC_OK) { + if (AddDeathRecipient(sid, BmToolDeathNotify, nullptr, &cbId) != ERR_NONE) { printf("error message: %s\n", "death callback is registered unsuccessfully"); return; } @@ -227,7 +227,7 @@ void CommandParser::RunAsUninstallCommand(int32_t argc, char *argv[]) const printf("error message: %s\n", ERROR_SEM_ERROR.c_str()); return; } - if (RegisterDeathCallback(nullptr, sid, BmToolDeathNotify, nullptr, &cbId) != LITEIPC_OK) { + if (AddDeathRecipient(sid, BmToolDeathNotify, nullptr, &cbId) != ERR_NONE) { printf("error message: %s\n", "death callback is registered unsuccessfully"); return; } @@ -429,12 +429,14 @@ static int BmsToolNotify(IOwner owner, int code, IpcIo *reply) printf("%s\n", "Bm tool Notify ipc is nullptr"); return OHOS_FAILURE; } - switch (IpcIoPopUint8(reply)) { + uint8_t readCode; + ReadUint8(reply, &readCode); + switch (readCode) { case SET_EXTERNAL_INSTALL_MODE: case SET_SIGN_DEBUG_MODE: case SET_SIGN_MODE: { uint8_t *ret = reinterpret_cast(owner); - *ret = IpcIoPopUint8(reply); + ReadUint8(reply, ret); break; } default: { @@ -451,13 +453,9 @@ uint8_t SetMode(int32_t mode, bool enable) return ERR_APPEXECFWK_OBJECT_NULL; } IpcIo ipcIo; - char data[IPC_IO_DATA_MAX]; - IpcIoInit(&ipcIo, data, IPC_IO_DATA_MAX, 0); - IpcIoPushBool(&ipcIo, enable); - if (!IpcIoAvailable(&ipcIo)) { - printf("%s\n", "Bm tool ipc failed"); - return ERR_APPEXECFWK_SERIALIZATION_FAILED; - } + char data[MAX_IO_SIZE]; + IpcIoInit(&ipcIo, data, MAX_IO_SIZE, 0); + WriteBool(&ipcIo, enable); uint8_t setModeResult = 0; int32_t ret = g_bmsInnerClient->Invoke(g_bmsInnerClient, mode, &ipcIo, &setModeResult, BmsToolNotify); if (ret != ERR_OK) {