diff --git a/common/native/include/edm_permission.h b/common/native/include/edm_permission.h index 910890730a6045f60983065d8382ba0e53595200..2c1571911e3469901a662e67fd586977693fae88 100644 --- a/common/native/include/edm_permission.h +++ b/common/native/include/edm_permission.h @@ -34,7 +34,7 @@ public: virtual bool Marshalling(Parcel &parcel) const override; - static EdmPermission *Unmarshalling(Parcel &parcel); + static bool Unmarshalling(Parcel &parcel, EdmPermission &edmPermission); const std::string &getPermissionName() const; diff --git a/common/native/src/edm_permission.cpp b/common/native/src/edm_permission.cpp index 701e55d8776de46abae201a0516cd3f222467731..e5aadbd7dc73c123449b2726d43dca1c42e3e6df 100644 --- a/common/native/src/edm_permission.cpp +++ b/common/native/src/edm_permission.cpp @@ -68,11 +68,9 @@ bool EdmPermission::Marshalling(Parcel &parcel) const return true; } -EdmPermission *EdmPermission::Unmarshalling(Parcel &parcel) +bool EdmPermission::Unmarshalling(Parcel &parcel, EdmPermission &edmPermission) { - auto *permission = new (std::nothrow)EdmPermission(); - permission->ReadFromParcel(parcel); - return permission; + return edmPermission.ReadFromParcel(parcel); } } // namespace EDM } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_api/common/include/ent_info.h b/interfaces/inner_api/common/include/ent_info.h index a3d55356938eb18c41e828f4794a02dbee94d52a..59a58abc72c2db7a62d201af7d3ccede21bfb2ed 100644 --- a/interfaces/inner_api/common/include/ent_info.h +++ b/interfaces/inner_api/common/include/ent_info.h @@ -30,7 +30,7 @@ struct EntInfo : public Parcelable { std::string description; bool ReadFromParcel(Parcel &parcel); virtual bool Marshalling(Parcel &parcel) const override; - static EntInfo *Unmarshalling(Parcel &parcel); + static bool Unmarshalling(Parcel &parcel, EntInfo &entInfo); }; } // namespace EDM } // namespace OHOS diff --git a/interfaces/inner_api/common/src/ent_info.cpp b/interfaces/inner_api/common/src/ent_info.cpp index a07a1d8544ca63198e4228425a6db044980a9371..b1b1e3e69090eea0b57227650a6a8f10d5b365e5 100644 --- a/interfaces/inner_api/common/src/ent_info.cpp +++ b/interfaces/inner_api/common/src/ent_info.cpp @@ -43,15 +43,9 @@ bool EntInfo::Marshalling(Parcel &parcel) const return true; } -EntInfo *EntInfo::Unmarshalling(Parcel &parcel) +bool EntInfo::Unmarshalling(Parcel &parcel, EntInfo &entInfo) { - auto *info = new (std::nothrow) EntInfo(); - if (info && !info->ReadFromParcel(parcel)) { - EDMLOGW("read from parcel failed"); - delete info; - info = nullptr; - } - return info; + return entInfo.ReadFromParcel(parcel); } bool EntInfo::ReadFromParcel(Parcel &parcel) diff --git a/interfaces/inner_api/common/src/enterprise_device_mgr_proxy.cpp b/interfaces/inner_api/common/src/enterprise_device_mgr_proxy.cpp index 45cd23da98de87ab9264e5f80951bfb7494b0460..76ca21f44a10df93914182377482782422c99312 100644 --- a/interfaces/inner_api/common/src/enterprise_device_mgr_proxy.cpp +++ b/interfaces/inner_api/common/src/enterprise_device_mgr_proxy.cpp @@ -202,12 +202,10 @@ ErrCode EnterpriseDeviceMgrProxy::GetEnterpriseInfo(AppExecFwk::ElementName &adm EDMLOGW("EnterpriseDeviceMgrProxy:GetEnterpriseInfo get result code fail. %{public}d", resCode); return resCode; } - std::unique_ptr info(reply.ReadParcelable()); - if (!info) { + if (!EntInfo::Unmarshalling(reply, entInfo)) { EDMLOGE("EnterpriseDeviceMgrProxy::GetEnterpriseInfo read parcel fail"); return EdmReturnErrCode::SYSTEM_ABNORMALLY; } - entInfo = *info; return ERR_OK; } diff --git a/services/edm/src/enterprise_device_mgr_stub.cpp b/services/edm/src/enterprise_device_mgr_stub.cpp index 153025c9e36eb89ccccac44bb2340ce1e8205fff..7130d263270670ee25ece449abe1b48bcf5fd829 100644 --- a/services/edm/src/enterprise_device_mgr_stub.cpp +++ b/services/edm/src/enterprise_device_mgr_stub.cpp @@ -112,8 +112,8 @@ ErrCode EnterpriseDeviceMgrStub::EnableAdminInner(MessageParcel &data, MessagePa } EDMLOGD("EnableAdminInner bundleName:: %{public}s : abilityName : %{public}s ", admin->GetBundleName().c_str(), admin->GetAbilityName().c_str()); - std::unique_ptr entInfo(data.ReadParcelable()); - if (!entInfo) { + EntInfo entInfo; + if (!EntInfo::Unmarshalling(data, entInfo)) { EDMLOGE("EnterpriseDeviceMgrStub::EnableAdminInner read parcel fail"); reply.WriteInt32(EdmReturnErrCode::PARAM_ERROR); return EdmReturnErrCode::PARAM_ERROR; @@ -124,7 +124,7 @@ ErrCode EnterpriseDeviceMgrStub::EnableAdminInner(MessageParcel &data, MessagePa if (type == static_cast(AdminType::NORMAL) || type == static_cast(AdminType::ENT)) { adminType = static_cast(type); } - ErrCode retCode = EnableAdmin(*admin, *entInfo, adminType, userId); + ErrCode retCode = EnableAdmin(*admin, entInfo, adminType, userId); reply.WriteInt32(retCode); return ERR_OK; } @@ -241,12 +241,12 @@ ErrCode EnterpriseDeviceMgrStub::SetEnterpriseInfoInner(MessageParcel &data, Mes reply.WriteInt32(EdmReturnErrCode::PARAM_ERROR); return EdmReturnErrCode::PARAM_ERROR; } - std::unique_ptr entInfo(data.ReadParcelable()); - if (!entInfo) { + EntInfo entInfo; + if (!EntInfo::Unmarshalling(data, entInfo)) { reply.WriteInt32(EdmReturnErrCode::PARAM_ERROR); return EdmReturnErrCode::PARAM_ERROR; } - ErrCode ret = SetEnterpriseInfo(*admin, *entInfo); + ErrCode ret = SetEnterpriseInfo(*admin, entInfo); reply.WriteInt32(ret); return ERR_OK; } diff --git a/test/fuzztest/entinfo_fuzzer/entinfo_fuzzer.cpp b/test/fuzztest/entinfo_fuzzer/entinfo_fuzzer.cpp index b1ce9b79b97ee7d08e21b6f869e997eb8b419165..e26bbd6b26a0ff80cfd40577d5a87c45f3f0f67a 100644 --- a/test/fuzztest/entinfo_fuzzer/entinfo_fuzzer.cpp +++ b/test/fuzztest/entinfo_fuzzer/entinfo_fuzzer.cpp @@ -28,8 +28,7 @@ namespace OHOS { EntInfo entInfo; std::string entName(reinterpret_cast(data), size); entInfo.enterpriseName = entName; - std::unique_ptr entInfoPtr(EntInfo::Unmarshalling(dataMessageParcel)); - return entInfoPtr != nullptr; + return EntInfo::Unmarshalling(dataMessageParcel, entInfo); } } diff --git a/test/unittest/src/edm_permission_test.cpp b/test/unittest/src/edm_permission_test.cpp index 4cc873e3054d141de404d23c04907c7a22ca469e..01ec6c213f235cbd101184d511f9819cdda5b3f0 100644 --- a/test/unittest/src/edm_permission_test.cpp +++ b/test/unittest/src/edm_permission_test.cpp @@ -60,12 +60,9 @@ HWTEST_F(EdmPermissionTest, TestMarshalling, TestSize.Level1) EdmPermission permission1("ohos.permission.EDM_TEST_PERMISSION", AdminType::NORMAL); Parcel parcel; permission1.Marshalling(parcel); - EdmPermission *permission2 = permission1.Unmarshalling(parcel); - EXPECT_TRUE(permission2 != nullptr); - EXPECT_TRUE(permission1 == *permission2); - if (permission2) { - delete permission2; - } + EdmPermission permission2; + EXPECT_TRUE(EdmPermission::Unmarshalling(parcel, permission2)); + EXPECT_TRUE(permission1 == permission2); } } // namespace TEST } // namespace EDM diff --git a/test/unittest/src/ent_info_test.cpp b/test/unittest/src/ent_info_test.cpp index 39112e24fb91ec017f6423b0a88993103318fddf..f560a6db7a847df4eebd2b6ae1d532938a28af46 100644 --- a/test/unittest/src/ent_info_test.cpp +++ b/test/unittest/src/ent_info_test.cpp @@ -58,18 +58,12 @@ HWTEST_F(EntInfoTest, TestMarshalling, TestSize.Level1) EXPECT_TRUE(ret); EntInfo entinfo; - EntInfo *entinfo1 = entinfo.Unmarshalling(parcel); - EXPECT_TRUE(entinfo1 != nullptr); + EXPECT_TRUE(EntInfo::Unmarshalling(parcel, entinfo)); - EXPECT_STREQ((entinfo1->enterpriseName).c_str(), NAME.c_str()); - EXPECT_STREQ((entinfo1->description).c_str(), DESCRIPTION.c_str()); - EXPECT_STREQ((entInfoTest->enterpriseName).c_str(), (entinfo1->enterpriseName).c_str()); - EXPECT_STREQ((entInfoTest->description).c_str(), (entinfo1->description).c_str()); - - if (entinfo1) { - delete entinfo1; - entinfo1 = nullptr; - } + EXPECT_STREQ(entinfo.enterpriseName.c_str(), NAME.c_str()); + EXPECT_STREQ(entinfo.description.c_str(), DESCRIPTION.c_str()); + EXPECT_STREQ((entInfoTest->enterpriseName).c_str(), entinfo.enterpriseName.c_str()); + EXPECT_STREQ((entInfoTest->description).c_str(), entinfo.description.c_str()); } } // namespace TEST } // namespace EDM diff --git a/test/unittest/test_bundle/ohos_test/BUILD.gn b/test/unittest/test_bundle/ohos_test/BUILD.gn index 572c0cd58bf0749952e2f7a019c261b53cdea99a..15bc3e34792fd9195c9362220e53b395a5c8fc59 100644 --- a/test/unittest/test_bundle/ohos_test/BUILD.gn +++ b/test/unittest/test_bundle/ohos_test/BUILD.gn @@ -15,7 +15,7 @@ import("//build/ohos.gni") ohos_copy("copy_ohos_test") { sources = [ "./ohos_test.xml" ] - outputs = [ "$root_out_dir/tests/unittest/enterprise_device_management/services/resource/ohos_test.xml" ] + outputs = [ "$root_out_dir/tests/unittest/enterprise_device_management/enterprise_device_management/resource/ohos_test.xml" ] subsystem_name = "customization" part_name = "enterprise_device_management" } diff --git a/test/unittest/test_bundle/right_hap/BUILD.gn b/test/unittest/test_bundle/right_hap/BUILD.gn index b0cf8c3234b0765ddf681515c491c4338927c87c..bef1bb33f68e5d47e8dd95e523cb047a89625dfb 100644 --- a/test/unittest/test_bundle/right_hap/BUILD.gn +++ b/test/unittest/test_bundle/right_hap/BUILD.gn @@ -18,7 +18,7 @@ ohos_hap("right") { hap_name = "right" subsystem_name = "customization" part_name = "enterprise_device_management" - final_hap_path = "$root_out_dir/tests/unittest/enterprise_device_management/services/resource/test_bundle/${hap_name}.hap" + final_hap_path = "$root_out_dir/tests/unittest/enterprise_device_management/enterprise_device_management/resource/test_bundle/${hap_name}.hap" testonly = true deps = [ ":hjs_demo_js_assets",