From ab0af7bd4e7377968572c60b0cc64fccfd584790 Mon Sep 17 00:00:00 2001 From: cc_ggboy Date: Thu, 23 Jun 2022 10:52:24 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=AD=A6=E5=91=8A=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=8C=91=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cc_ggboy --- frameworks/accesstoken/BUILD.gn | 1 + .../accesstoken/src/hap_info_parcel.cpp | 103 ++++++++---------- .../accesstoken/src/hap_policy_parcel.cpp | 13 +-- .../src/hap_token_info_for_sync_parcel.cpp | 13 +-- .../accesstoken/src/hap_token_info_parcel.cpp | 13 +-- .../src/native_token_info_for_sync_parcel.cpp | 13 +-- .../src/native_token_info_parcel.cpp | 13 +-- .../accesstoken/src/permission_def_parcel.cpp | 13 +-- .../src/permission_list_state_parcel.cpp | 13 +-- .../src/permission_state_full_parcel.cpp | 13 +-- frameworks/common/include/parcel_utils.h | 37 +++++++ frameworks/privacy/BUILD.gn | 1 + .../privacy/src/bundle_used_record_parcel.cpp | 15 +-- .../src/permission_used_record_parcel.cpp | 15 +-- .../src/permission_used_request_parcel.cpp | 15 +-- .../src/permission_used_result_parcel.cpp | 15 +-- .../privacy/src/used_record_detail_parcel.cpp | 15 +-- 17 files changed, 98 insertions(+), 223 deletions(-) create mode 100644 frameworks/common/include/parcel_utils.h diff --git a/frameworks/accesstoken/BUILD.gn b/frameworks/accesstoken/BUILD.gn index 195b595be..b05a2c716 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 b7569ca1f..88259f85b 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 8ede17163..7d4ed108c 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 269ff8de9..89766e871 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 3ff51d458..414587d82 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 ad64e63eb..541bbea1d 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 0919a8a96..ce55f5f57 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 f87b17cfa..4ca7b3d2a 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 96f0d2419..5fe05d917 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 642dbda7b..1919f9d52 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 000000000..ddc87d688 --- /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 58c54cd1e..de6e65926 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 6eae3df5c..f817e1fef 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 657babba6..021b1435e 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 dfc841530..96915ff03 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 a8655ff69..0ca67c4b1 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 d8ffc2927..9785cf45b 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)); -- Gitee From 10ee3ac41d485690da6074478f2b7efae47b41a1 Mon Sep 17 00:00:00 2001 From: cc_ggboy Date: Thu, 23 Jun 2022 14:43:05 +0800 Subject: [PATCH 2/3] 0623cwm Signed-off-by: cc_ggboy --- frameworks/accesstoken/src/hap_info_parcel.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/accesstoken/src/hap_info_parcel.cpp b/frameworks/accesstoken/src/hap_info_parcel.cpp index 88259f85b..034f8d9ec 100644 --- a/frameworks/accesstoken/src/hap_info_parcel.cpp +++ b/frameworks/accesstoken/src/hap_info_parcel.cpp @@ -19,6 +19,7 @@ namespace OHOS { namespace Security { namespace AccessToken { + bool HapInfoParcel::Marshalling(Parcel& out) const { RETURN_IF_FALSE(out.WriteInt32(this->hapInfoParameter.userID)); -- Gitee From d7a795864df3ccd4f665d2b162e2d310b1abdb86 Mon Sep 17 00:00:00 2001 From: cc_ggboy <10017561+cc_ggboy@user.noreply.gitee.com> Date: Thu, 23 Jun 2022 06:54:31 +0000 Subject: [PATCH 3/3] update frameworks/accesstoken/src/hap_info_parcel.cpp. --- frameworks/accesstoken/src/hap_info_parcel.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/frameworks/accesstoken/src/hap_info_parcel.cpp b/frameworks/accesstoken/src/hap_info_parcel.cpp index 034f8d9ec..88259f85b 100644 --- a/frameworks/accesstoken/src/hap_info_parcel.cpp +++ b/frameworks/accesstoken/src/hap_info_parcel.cpp @@ -19,7 +19,6 @@ namespace OHOS { namespace Security { namespace AccessToken { - bool HapInfoParcel::Marshalling(Parcel& out) const { RETURN_IF_FALSE(out.WriteInt32(this->hapInfoParameter.userID)); -- Gitee