diff --git a/frameworks/accesstoken/BUILD.gn b/frameworks/accesstoken/BUILD.gn index 195b595be8a786a27e06bfccfa1954ed8b8c2e9c..b05a2c71619d22d4fb37c568c55c2522ff4ac886 100644 --- a/frameworks/accesstoken/BUILD.gn +++ b/frameworks/accesstoken/BUILD.gn @@ -17,6 +17,7 @@ config("accesstoken_communication_adapter_cxx_public_config") { visibility = [ ":*" ] include_dirs = [ "include", + "//base/security/access_token/frameworks/common/include", "//base/security/access_token/interfaces/innerkits/accesstoken/include", ] } diff --git a/frameworks/accesstoken/src/hap_info_parcel.cpp b/frameworks/accesstoken/src/hap_info_parcel.cpp index b7569ca1fe918e169177d5a622ebb57976752f7b..88259f85b0af21f12ef9190795da330791d4dad2 100644 --- a/frameworks/accesstoken/src/hap_info_parcel.cpp +++ b/frameworks/accesstoken/src/hap_info_parcel.cpp @@ -1,57 +1,46 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "hap_info_parcel.h" - -namespace OHOS { -namespace Security { -namespace AccessToken { -#define RETURN_IF_FALSE(expr) \ - if (!(expr)) { \ - return false; \ - } - -#define RELEASE_IF_FALSE(expr, obj) \ - if (!(expr)) { \ - delete (obj); \ - (obj) = nullptr; \ - return (obj); \ - } - -bool HapInfoParcel::Marshalling(Parcel& out) const -{ - RETURN_IF_FALSE(out.WriteInt32(this->hapInfoParameter.userID)); - RETURN_IF_FALSE(out.WriteString(this->hapInfoParameter.bundleName)); - RETURN_IF_FALSE(out.WriteInt32(this->hapInfoParameter.instIndex)); - RETURN_IF_FALSE(out.WriteInt32(this->hapInfoParameter.dlpType)); - RETURN_IF_FALSE(out.WriteString(this->hapInfoParameter.appIDDesc)); - return true; -} - -HapInfoParcel* HapInfoParcel::Unmarshalling(Parcel& in) -{ - auto* hapInfoParcel = new (std::nothrow) HapInfoParcel(); - RELEASE_IF_FALSE(hapInfoParcel != nullptr, hapInfoParcel); - RELEASE_IF_FALSE(in.ReadInt32(hapInfoParcel->hapInfoParameter.userID), hapInfoParcel); - hapInfoParcel->hapInfoParameter.bundleName = in.ReadString(); - RELEASE_IF_FALSE(in.ReadInt32(hapInfoParcel->hapInfoParameter.instIndex), hapInfoParcel); - RELEASE_IF_FALSE(in.ReadInt32(hapInfoParcel->hapInfoParameter.dlpType), hapInfoParcel); - hapInfoParcel->hapInfoParameter.appIDDesc = in.ReadString(); - - return hapInfoParcel; -} -} // namespace AccessToken -} // namespace Security -} // namespace OHOS +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "hap_info_parcel.h" +#include "parcel_utils.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +bool HapInfoParcel::Marshalling(Parcel& out) const +{ + RETURN_IF_FALSE(out.WriteInt32(this->hapInfoParameter.userID)); + RETURN_IF_FALSE(out.WriteString(this->hapInfoParameter.bundleName)); + RETURN_IF_FALSE(out.WriteInt32(this->hapInfoParameter.instIndex)); + RETURN_IF_FALSE(out.WriteInt32(this->hapInfoParameter.dlpType)); + RETURN_IF_FALSE(out.WriteString(this->hapInfoParameter.appIDDesc)); + return true; +} + +HapInfoParcel* HapInfoParcel::Unmarshalling(Parcel& in) +{ + auto* hapInfoParcel = new (std::nothrow) HapInfoParcel(); + RELEASE_IF_FALSE(hapInfoParcel != nullptr, hapInfoParcel); + RELEASE_IF_FALSE(in.ReadInt32(hapInfoParcel->hapInfoParameter.userID), hapInfoParcel); + hapInfoParcel->hapInfoParameter.bundleName = in.ReadString(); + RELEASE_IF_FALSE(in.ReadInt32(hapInfoParcel->hapInfoParameter.instIndex), hapInfoParcel); + RELEASE_IF_FALSE(in.ReadInt32(hapInfoParcel->hapInfoParameter.dlpType), hapInfoParcel); + hapInfoParcel->hapInfoParameter.appIDDesc = in.ReadString(); + + return hapInfoParcel; +} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/frameworks/accesstoken/src/hap_policy_parcel.cpp b/frameworks/accesstoken/src/hap_policy_parcel.cpp index 8ede17163f6a626d930986c33543dcdbfaea2698..7d4ed108c5b2f391937b372bee2cb97daec1a8ef 100644 --- a/frameworks/accesstoken/src/hap_policy_parcel.cpp +++ b/frameworks/accesstoken/src/hap_policy_parcel.cpp @@ -14,22 +14,11 @@ */ #include "hap_policy_parcel.h" +#include "parcel_utils.h" namespace OHOS { namespace Security { namespace AccessToken { -#define RETURN_IF_FALSE(expr) \ - if (!(expr)) { \ - return false; \ - } - -#define RELEASE_IF_FALSE(expr, obj) \ - if (!(expr)) { \ - delete (obj); \ - (obj) = nullptr; \ - return (obj); \ - } - bool HapPolicyParcel::Marshalling(Parcel& out) const { RETURN_IF_FALSE(out.WriteInt32(this->hapPolicyParameter.apl)); diff --git a/frameworks/accesstoken/src/hap_token_info_for_sync_parcel.cpp b/frameworks/accesstoken/src/hap_token_info_for_sync_parcel.cpp index 269ff8de9a859217620f192348e8f8fd84a9f684..89766e8710ea91aff07ed7885a5e1ff45238738d 100644 --- a/frameworks/accesstoken/src/hap_token_info_for_sync_parcel.cpp +++ b/frameworks/accesstoken/src/hap_token_info_for_sync_parcel.cpp @@ -15,23 +15,12 @@ #include "hap_token_info_for_sync_parcel.h" #include "hap_token_info_parcel.h" +#include "parcel_utils.h" #include "permission_state_full_parcel.h" namespace OHOS { namespace Security { namespace AccessToken { -#define RETURN_IF_FALSE(expr) \ - if (!(expr)) { \ - return false; \ - } - -#define RELEASE_IF_FALSE(expr, obj) \ - if (!(expr)) { \ - delete (obj); \ - (obj) = nullptr; \ - return (obj); \ - } - bool HapTokenInfoForSyncParcel::Marshalling(Parcel& out) const { HapTokenInfoParcel baseInfoParcel; diff --git a/frameworks/accesstoken/src/hap_token_info_parcel.cpp b/frameworks/accesstoken/src/hap_token_info_parcel.cpp index 3ff51d4584a7bbd876abfb512b1af79d6a02799a..414587d82cc9b3369627cde7963156ce7fa572d3 100644 --- a/frameworks/accesstoken/src/hap_token_info_parcel.cpp +++ b/frameworks/accesstoken/src/hap_token_info_parcel.cpp @@ -14,22 +14,11 @@ */ #include "hap_token_info_parcel.h" +#include "parcel_utils.h" namespace OHOS { namespace Security { namespace AccessToken { -#define RETURN_IF_FALSE(expr) \ - if (!(expr)) { \ - return false; \ - } - -#define RELEASE_IF_FALSE(expr, obj) \ - if (!(expr)) { \ - delete (obj); \ - (obj) = nullptr; \ - return (obj); \ - } - bool HapTokenInfoParcel::Marshalling(Parcel& out) const { RETURN_IF_FALSE(out.WriteInt32(this->hapTokenInfoParams.apl)); diff --git a/frameworks/accesstoken/src/native_token_info_for_sync_parcel.cpp b/frameworks/accesstoken/src/native_token_info_for_sync_parcel.cpp index ad64e63eb60ba3e143748683763f5943fa924209..541bbea1d858d90fe39cca12f7b394c5a978514d 100644 --- a/frameworks/accesstoken/src/native_token_info_for_sync_parcel.cpp +++ b/frameworks/accesstoken/src/native_token_info_for_sync_parcel.cpp @@ -15,23 +15,12 @@ #include "native_token_info_for_sync_parcel.h" #include "native_token_info_parcel.h" +#include "parcel_utils.h" #include "permission_state_full_parcel.h" namespace OHOS { namespace Security { namespace AccessToken { -#define RETURN_IF_FALSE(expr) \ - if (!(expr)) { \ - return false; \ - } - -#define RELEASE_IF_FALSE(expr, obj) \ - if (!(expr)) { \ - delete (obj); \ - (obj) = nullptr; \ - return (obj); \ - } - bool NativeTokenInfoForSyncParcel::Marshalling(Parcel& out) const { NativeTokenInfoParcel baseInfoParcel; diff --git a/frameworks/accesstoken/src/native_token_info_parcel.cpp b/frameworks/accesstoken/src/native_token_info_parcel.cpp index 0919a8a961458de6cb485c47633534b5b5e3a6aa..ce55f5f57f99e5fef755c01453f78d698921e5b1 100644 --- a/frameworks/accesstoken/src/native_token_info_parcel.cpp +++ b/frameworks/accesstoken/src/native_token_info_parcel.cpp @@ -14,22 +14,11 @@ */ #include "native_token_info_parcel.h" +#include "parcel_utils.h" namespace OHOS { namespace Security { namespace AccessToken { -#define RETURN_IF_FALSE(expr) \ - if (!(expr)) { \ - return false; \ - } - -#define RELEASE_IF_FALSE(expr, obj) \ - if (!(expr)) { \ - delete (obj); \ - (obj) = nullptr; \ - return (obj); \ - } - bool NativeTokenInfoParcel::Marshalling(Parcel& out) const { RETURN_IF_FALSE(out.WriteInt32(this->nativeTokenInfoParams.apl)); diff --git a/frameworks/accesstoken/src/permission_def_parcel.cpp b/frameworks/accesstoken/src/permission_def_parcel.cpp index f87b17cfabc9d88d6db768129bfadbf2208aa799..4ca7b3d2a3d553ed44a550b9515ec78a47129d68 100644 --- a/frameworks/accesstoken/src/permission_def_parcel.cpp +++ b/frameworks/accesstoken/src/permission_def_parcel.cpp @@ -16,22 +16,11 @@ #include "permission_def_parcel.h" #include "access_token.h" +#include "parcel_utils.h" namespace OHOS { namespace Security { namespace AccessToken { -#define RETURN_IF_FALSE(expr) \ - if (!(expr)) { \ - return false; \ - } - -#define RELEASE_IF_FALSE(expr, obj) \ - if (!(expr)) { \ - delete (obj); \ - (obj) = nullptr; \ - return (obj); \ - } - bool PermissionDefParcel::Marshalling(Parcel& out) const { RETURN_IF_FALSE(out.WriteString(this->permissionDef.permissionName)); diff --git a/frameworks/accesstoken/src/permission_list_state_parcel.cpp b/frameworks/accesstoken/src/permission_list_state_parcel.cpp index 96f0d2419a8c0c4594bc1b6c0e9be35c69576e1b..5fe05d917635bb6f3fce2f365712d372a6e8742f 100644 --- a/frameworks/accesstoken/src/permission_list_state_parcel.cpp +++ b/frameworks/accesstoken/src/permission_list_state_parcel.cpp @@ -14,22 +14,11 @@ */ #include "permission_list_state_parcel.h" +#include "parcel_utils.h" namespace OHOS { namespace Security { namespace AccessToken { -#define RETURN_IF_FALSE(expr) \ - if (!(expr)) { \ - return false; \ - } - -#define RELEASE_IF_FALSE(expr, obj) \ - if (!(expr)) { \ - delete (obj); \ - (obj) = nullptr; \ - return (obj); \ - } - bool PermissionListStateParcel::Marshalling(Parcel& out) const { RETURN_IF_FALSE(out.WriteString(this->permsState.permissionName)); diff --git a/frameworks/accesstoken/src/permission_state_full_parcel.cpp b/frameworks/accesstoken/src/permission_state_full_parcel.cpp index 642dbda7b7cb30d08a74b329593eadd8c4cf21c8..1919f9d52de426452fca7f0ba61b5703d39d5de8 100644 --- a/frameworks/accesstoken/src/permission_state_full_parcel.cpp +++ b/frameworks/accesstoken/src/permission_state_full_parcel.cpp @@ -14,22 +14,11 @@ */ #include "permission_state_full_parcel.h" +#include "parcel_utils.h" namespace OHOS { namespace Security { namespace AccessToken { -#define RETURN_IF_FALSE(expr) \ - if (!(expr)) { \ - return false; \ - } - -#define RELEASE_IF_FALSE(expr, obj) \ - if (!(expr)) { \ - delete (obj); \ - (obj) = nullptr; \ - return (obj); \ - } - bool PermissionStateFullParcel::Marshalling(Parcel& out) const { RETURN_IF_FALSE(out.WriteString(this->permStatFull.permissionName)); diff --git a/frameworks/common/include/parcel_utils.h b/frameworks/common/include/parcel_utils.h new file mode 100644 index 0000000000000000000000000000000000000000..ddc87d6884a0999ed97cdef2bd329fb517a354d9 --- /dev/null +++ b/frameworks/common/include/parcel_utils.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PARCEL_UTILS_H +#define PARCEL_UTILS_H +namespace OHOS { +namespace Security { +namespace AccessToken { +#define RETURN_IF_FALSE(expr) \ + if (!(expr)) { \ + return false; \ + } + +#define RELEASE_IF_FALSE(expr, obj) \ + if (!(expr)) { \ + if ((obj) != nullptr) { \ + delete (obj); \ + (obj) = nullptr; \ + } \ + return (obj); \ + } +} // namespace AccessToken +} // namespace Security +} // namespace OHOS +#endif // PARCEL_UTILS_H diff --git a/frameworks/privacy/BUILD.gn b/frameworks/privacy/BUILD.gn index 58c54cd1e42d8174006b9946dff10b40b13909cd..de6e65926f2895ae64f57ed121f145289d4c808f 100644 --- a/frameworks/privacy/BUILD.gn +++ b/frameworks/privacy/BUILD.gn @@ -21,6 +21,7 @@ ohos_shared_library("privacy_communication_adapter_cxx") { "include", "//base/security/access_token/interfaces/innerkits/accesstoken/include", "//base/security/access_token/interfaces/innerkits/privacy/include", + "//base/security/access_token/frameworks/common/include", "//utils/native/base/include", ] diff --git a/frameworks/privacy/src/bundle_used_record_parcel.cpp b/frameworks/privacy/src/bundle_used_record_parcel.cpp index 6eae3df5c4e6ef216182b53f255b4d8219dea3eb..f817e1feff9c10d2566183863aecc5af52bc2592 100644 --- a/frameworks/privacy/src/bundle_used_record_parcel.cpp +++ b/frameworks/privacy/src/bundle_used_record_parcel.cpp @@ -14,25 +14,12 @@ */ #include "bundle_used_record_parcel.h" +#include "parcel_utils.h" #include "permission_used_record_parcel.h" namespace OHOS { namespace Security { namespace AccessToken { -#define RETURN_IF_FALSE(expr) \ - if (!(expr)) { \ - return false; \ - } - -#define RELEASE_IF_FALSE(expr, obj) \ - if (!(expr)) { \ - if ((obj) != nullptr) { \ - delete (obj); \ - (obj) = nullptr; \ - } \ - return (obj); \ - } - bool BundleUsedRecordParcel::Marshalling(Parcel& out) const { RETURN_IF_FALSE(out.WriteUint32(this->bundleRecord.tokenId)); diff --git a/frameworks/privacy/src/permission_used_record_parcel.cpp b/frameworks/privacy/src/permission_used_record_parcel.cpp index 657babba63370960aa3538737821b240d7919f02..021b1435e40afe36bfcdb73727578bcdbfdcf974 100644 --- a/frameworks/privacy/src/permission_used_record_parcel.cpp +++ b/frameworks/privacy/src/permission_used_record_parcel.cpp @@ -14,25 +14,12 @@ */ #include "permission_used_record_parcel.h" +#include "parcel_utils.h" #include "used_record_detail_parcel.h" namespace OHOS { namespace Security { namespace AccessToken { -#define RETURN_IF_FALSE(expr) \ - if (!(expr)) { \ - return false; \ - } - -#define RELEASE_IF_FALSE(expr, obj) \ - if (!(expr)) { \ - if ((obj) != nullptr) { \ - delete (obj); \ - (obj) = nullptr; \ - } \ - return (obj); \ - } - bool PermissionUsedRecordParcel::Marshalling(Parcel& out) const { RETURN_IF_FALSE(out.WriteString(this->permissionRecord.permissionName)); diff --git a/frameworks/privacy/src/permission_used_request_parcel.cpp b/frameworks/privacy/src/permission_used_request_parcel.cpp index dfc8415303f68ecc23105911deecc241eaa4cfb9..96915ff03d9804a8ebb4ce354c79e2c09c5621b2 100644 --- a/frameworks/privacy/src/permission_used_request_parcel.cpp +++ b/frameworks/privacy/src/permission_used_request_parcel.cpp @@ -14,24 +14,11 @@ */ #include "permission_used_request_parcel.h" +#include "parcel_utils.h" namespace OHOS { namespace Security { namespace AccessToken { -#define RETURN_IF_FALSE(expr) \ - if (!(expr)) { \ - return false; \ - } - -#define RELEASE_IF_FALSE(expr, obj) \ - if (!(expr)) { \ - if ((obj) != nullptr) { \ - delete (obj); \ - (obj) = nullptr; \ - } \ - return (obj); \ - } - bool PermissionUsedRequestParcel::Marshalling(Parcel& out) const { RETURN_IF_FALSE(out.WriteUint32(this->request.tokenId)); diff --git a/frameworks/privacy/src/permission_used_result_parcel.cpp b/frameworks/privacy/src/permission_used_result_parcel.cpp index a8655ff69fa997199ab98fb48b0b1ad5d73e11d4..0ca67c4b14d2c263e50c00ecb7becc72a3f6260c 100644 --- a/frameworks/privacy/src/permission_used_result_parcel.cpp +++ b/frameworks/privacy/src/permission_used_result_parcel.cpp @@ -15,24 +15,11 @@ #include "permission_used_result_parcel.h" #include "bundle_used_record_parcel.h" +#include "parcel_utils.h" namespace OHOS { namespace Security { namespace AccessToken { -#define RETURN_IF_FALSE(expr) \ - if (!(expr)) { \ - return false; \ - } - -#define RELEASE_IF_FALSE(expr, obj) \ - if (!(expr)) { \ - if ((obj) != nullptr) { \ - delete (obj); \ - (obj) = nullptr; \ - } \ - return (obj); \ - } - bool PermissionUsedResultParcel::Marshalling(Parcel& out) const { RETURN_IF_FALSE(out.WriteInt64(this->result.beginTimeMillis)); diff --git a/frameworks/privacy/src/used_record_detail_parcel.cpp b/frameworks/privacy/src/used_record_detail_parcel.cpp index d8ffc292767a237f83acd8c77165b6995ab6a073..9785cf45b7ca0a90b6e268e2d7218abda94322c8 100644 --- a/frameworks/privacy/src/used_record_detail_parcel.cpp +++ b/frameworks/privacy/src/used_record_detail_parcel.cpp @@ -14,24 +14,11 @@ */ #include "used_record_detail_parcel.h" +#include "parcel_utils.h" namespace OHOS { namespace Security { namespace AccessToken { -#define RETURN_IF_FALSE(expr) \ - if (!(expr)) { \ - return false; \ - } - -#define RELEASE_IF_FALSE(expr, obj) \ - if (!(expr)) { \ - if ((obj) != nullptr) { \ - delete (obj); \ - (obj) = nullptr; \ - } \ - return (obj); \ - } - bool UsedRecordDetailParcel::Marshalling(Parcel& out) const { RETURN_IF_FALSE(out.WriteInt32(this->detail.status));