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)); diff --git a/interfaces/innerkits/privacy/src/privacy_kit.cpp b/interfaces/innerkits/privacy/src/privacy_kit.cpp index 39d3eb03657ceb088e97eeeb5172244506e23795..75ef66a5fd980abf83c36a87c8afaea6e2de4861 100644 --- a/interfaces/innerkits/privacy/src/privacy_kit.cpp +++ b/interfaces/innerkits/privacy/src/privacy_kit.cpp @@ -31,49 +31,50 @@ static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ int32_t PrivacyKit::AddPermissionUsedRecord( AccessTokenID tokenID, const std::string& permissionName, int32_t successCount, int32_t failCount) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s called, tokenID=0x%{public}x, permissionName=%{public}s,", - __func__, tokenID, permissionName.c_str()); + ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry, tokenID=0x%{public}x, permissionName=%{public}s,", + tokenID, permissionName.c_str()); return PrivacyManagerClient::GetInstance().AddPermissionUsedRecord( tokenID, permissionName, successCount, failCount); } int32_t PrivacyKit::StartUsingPermission(AccessTokenID tokenID, const std::string& permissionName) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s called, tokenID=0x%{public}x, permissionName=%{public}s", - __func__, tokenID, permissionName.c_str()); + ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry, tokenID=0x%{public}x, permissionName=%{public}s", + tokenID, permissionName.c_str()); return PrivacyManagerClient::GetInstance().StartUsingPermission(tokenID, permissionName); } int32_t PrivacyKit::StopUsingPermission(AccessTokenID tokenID, const std::string& permissionName) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s called, tokenID=0x%{public}x, permissionName=%{public}s", - __func__, tokenID, permissionName.c_str()); + ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry, tokenID=0x%{public}x, permissionName=%{public}s", + tokenID, permissionName.c_str()); return PrivacyManagerClient::GetInstance().StopUsingPermission(tokenID, permissionName); } int32_t PrivacyKit::RemovePermissionUsedRecords(AccessTokenID tokenID, const std::string& deviceID) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s called", __func__); + ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry, tokenID=0x%{public}x, deviceID=%{private}s", + tokenID, deviceID.c_str()); return PrivacyManagerClient::GetInstance().RemovePermissionUsedRecords(tokenID, deviceID); } int32_t PrivacyKit::GetPermissionUsedRecords(const PermissionUsedRequest& request, PermissionUsedResult& result) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s called", __func__); + ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry"); return PrivacyManagerClient::GetInstance().GetPermissionUsedRecords(request, result); } int32_t PrivacyKit::GetPermissionUsedRecords( const PermissionUsedRequest& request, const sptr& callback) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s called", __func__); + ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry"); return PrivacyManagerClient::GetInstance().GetPermissionUsedRecords(request, callback); } std::string PrivacyKit::DumpRecordInfo(const std::string& bundleName, const std::string& permissionName) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s called, bundleName=%{public}s, permissionName=%{public}s", - __func__, bundleName.c_str(), permissionName.c_str()); + ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry, bundleName=%{public}s, permissionName=%{public}s", + bundleName.c_str(), permissionName.c_str()); return PrivacyManagerClient::GetInstance().DumpRecordInfo(bundleName, permissionName); } } // namespace AccessToken diff --git a/interfaces/kits/privacy/napi/src/permission_record_manager_napi.cpp b/interfaces/kits/privacy/napi/src/permission_record_manager_napi.cpp index 290a4f9f35be82bcded88b601cf347ae5bd8f979..9aeee49110fb3302be4a020d6915fca8ac705b29 100644 --- a/interfaces/kits/privacy/napi/src/permission_record_manager_napi.cpp +++ b/interfaces/kits/privacy/napi/src/permission_record_manager_napi.cpp @@ -370,7 +370,7 @@ napi_value AddPermissionUsedRecord(napi_env env, napi_callback_info cbinfo) { ACCESSTOKEN_LOG_DEBUG(LABEL, "AddPermissionUsedRecord begin."); - auto *asyncContext = new RecordManagerAsyncContext(); + auto *asyncContext = new (std::nothrow) RecordManagerAsyncContext(); if (asyncContext == nullptr) { ACCESSTOKEN_LOG_ERROR(LABEL, "new struct fail."); return nullptr; @@ -379,7 +379,9 @@ napi_value AddPermissionUsedRecord(napi_env env, napi_callback_info cbinfo) napi_value result = nullptr; if (asyncContext->callbackRef == nullptr) { - napi_create_promise(env, &(asyncContext->deferred), &result); + if (napi_create_promise(env, &(asyncContext->deferred), &result) !=napi_ok) { + return nullptr; + } } else { napi_get_undefined(env, &result); } @@ -424,7 +426,7 @@ napi_value StartUsingPermission(napi_env env, napi_callback_info cbinfo) { ACCESSTOKEN_LOG_DEBUG(LABEL, "StartUsingPermission begin."); - auto *asyncContext = new RecordManagerAsyncContext(); + auto *asyncContext = new (std::nothrow) RecordManagerAsyncContext(); if (asyncContext == nullptr) { ACCESSTOKEN_LOG_ERROR(LABEL, "new struct fail."); return nullptr; @@ -433,7 +435,9 @@ napi_value StartUsingPermission(napi_env env, napi_callback_info cbinfo) napi_value result = nullptr; if (asyncContext->callbackRef == nullptr) { - napi_create_promise(env, &(asyncContext->deferred), &result); + if (napi_create_promise(env, &(asyncContext->deferred), &result) !=napi_ok) { + return nullptr; + } } else { napi_get_undefined(env, &result); } @@ -478,7 +482,7 @@ napi_value StopUsingPermission(napi_env env, napi_callback_info cbinfo) { ACCESSTOKEN_LOG_DEBUG(LABEL, "StopUsingPermission begin."); - auto *asyncContext = new RecordManagerAsyncContext(); + auto *asyncContext = new (std::nothrow) RecordManagerAsyncContext(); if (asyncContext == nullptr) { ACCESSTOKEN_LOG_ERROR(LABEL, "new struct fail."); return nullptr; @@ -487,7 +491,9 @@ napi_value StopUsingPermission(napi_env env, napi_callback_info cbinfo) napi_value result = nullptr; if (asyncContext->callbackRef == nullptr) { - napi_create_promise(env, &(asyncContext->deferred), &result); + if (napi_create_promise(env, &(asyncContext->deferred), &result) !=napi_ok) { + return nullptr; + } } else { napi_get_undefined(env, &result); } @@ -531,7 +537,7 @@ napi_value StopUsingPermission(napi_env env, napi_callback_info cbinfo) napi_value GetPermissionUsedRecords(napi_env env, napi_callback_info cbinfo) { ACCESSTOKEN_LOG_DEBUG(LABEL, "GetPermissionUsedRecords begin."); - auto *asyncContext = new RecordManagerAsyncContext(); + auto *asyncContext = new (std::nothrow) RecordManagerAsyncContext(); if (asyncContext == nullptr) { ACCESSTOKEN_LOG_ERROR(LABEL, "new struct fail."); return nullptr; @@ -540,7 +546,9 @@ napi_value GetPermissionUsedRecords(napi_env env, napi_callback_info cbinfo) napi_value result = nullptr; if (asyncContext->callbackRef == nullptr) { - napi_create_promise(env, &(asyncContext->deferred), &result); + if (napi_create_promise(env, &(asyncContext->deferred), &result) !=napi_ok) { + return nullptr; + } } else { napi_get_undefined(env, &result); } diff --git a/services/privacymanager/BUILD.gn b/services/privacymanager/BUILD.gn index 5225ac30ef55a776e9642ed6d872baefc64de8fd..4cd608c62191500d36f95ee30857dbd36d7cb589 100644 --- a/services/privacymanager/BUILD.gn +++ b/services/privacymanager/BUILD.gn @@ -35,7 +35,7 @@ ohos_shared_library("privacy_manager_service") { "src/common/time_util.cpp", "src/common/to_string.cpp", "src/database/data_translator.cpp", - "src/database/sqlite_storage.cpp", + "src/database/permission_used_record_db.cpp", "src/record/on_permission_used_record_callback_proxy.cpp", "src/record/on_permission_used_record_callback_stub.cpp", "src/record/permission_record.cpp", diff --git a/services/privacymanager/include/database/sqlite_storage.h b/services/privacymanager/include/database/permission_used_record_db.h similarity index 89% rename from services/privacymanager/include/database/sqlite_storage.h rename to services/privacymanager/include/database/permission_used_record_db.h index bdd8dbf2a817e35d3625768b9b7770c962e74b96..734e6b7b4e602dceb4a3d137bb6ee497fbe8dc3d 100644 --- a/services/privacymanager/include/database/sqlite_storage.h +++ b/services/privacymanager/include/database/permission_used_record_db.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef SQL_STORAGE_H -#define SQL_STORAGE_H +#ifndef PERMISSION_USED_RECORD_DB_H +#define PERMISSION_USED_RECORD_DB_H #include "generic_values.h" #include "sqlite_helper.h" @@ -30,16 +30,16 @@ public: std::string tableName_; std::vector tableColumnNames_; }; -class SqliteStorage : public SqliteHelper { +class PermissionUsedRecordDb : public SqliteHelper { public: enum DataType { PERMISSION_VISITOR = 0, PERMISSION_RECORD, }; enum ExecuteResult { FAILURE = -1, SUCCESS }; - static SqliteStorage& GetInstance(); + static PermissionUsedRecordDb& GetInstance(); - ~SqliteStorage() override; + ~PermissionUsedRecordDb() override; int32_t Add(const DataType type, const std::vector& values); int32_t Remove(const DataType type, const GenericValues& conditions); @@ -53,8 +53,8 @@ public: void OnUpdate() override; private: - SqliteStorage(); - DISALLOW_COPY_AND_MOVE(SqliteStorage); + PermissionUsedRecordDb(); + DISALLOW_COPY_AND_MOVE(PermissionUsedRecordDb); std::map dataTypeToSqlTable_; OHOS::Utils::RWLock rwLock_; @@ -82,4 +82,4 @@ private: } // namespace Security } // namespace OHOS -#endif // SQL_STORAGE_H +#endif // PERMISSION_USED_RECORD_DB_H diff --git a/services/privacymanager/src/database/sqlite_storage.cpp b/services/privacymanager/src/database/permission_used_record_db.cpp similarity index 86% rename from services/privacymanager/src/database/sqlite_storage.cpp rename to services/privacymanager/src/database/permission_used_record_db.cpp index a14712f040d2efce0697fd72c181977277af47ce..e2f271365ab1638e8ceb4153d5b7a40cc546e5b9 100644 --- a/services/privacymanager/src/database/sqlite_storage.cpp +++ b/services/privacymanager/src/database/permission_used_record_db.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "sqlite_storage.h" +#include "permission_used_record_db.h" #include "accesstoken_log.h" #include "field_const.h" @@ -23,34 +23,34 @@ namespace Security { namespace AccessToken { namespace { static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { - LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PrivacySqliteStorage" + LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PermissionUsedRecordDb" }; } -SqliteStorage& SqliteStorage::GetInstance() +PermissionUsedRecordDb& PermissionUsedRecordDb::GetInstance() { - static SqliteStorage instance; + static PermissionUsedRecordDb instance; return instance; } -SqliteStorage::~SqliteStorage() +PermissionUsedRecordDb::~PermissionUsedRecordDb() { Close(); } -void SqliteStorage::OnCreate() +void PermissionUsedRecordDb::OnCreate() { - ACCESSTOKEN_LOG_INFO(LABEL, "%{public}s called.", __func__); + ACCESSTOKEN_LOG_INFO(LABEL, "Entry"); CreatePermissionVisitorTable(); CreatePermissionRecordTable(); } -void SqliteStorage::OnUpdate() +void PermissionUsedRecordDb::OnUpdate() { - ACCESSTOKEN_LOG_INFO(LABEL, "%{public}s called.", __func__); + ACCESSTOKEN_LOG_INFO(LABEL, "Entry"); } -SqliteStorage::SqliteStorage() : SqliteHelper(DATABASE_NAME, DATABASE_PATH, DATABASE_VERSION) +PermissionUsedRecordDb::PermissionUsedRecordDb() : SqliteHelper(DATABASE_NAME, DATABASE_PATH, DATABASE_VERSION) { SqliteTable permissionVisorTable; permissionVisorTable.tableName_ = PERMISSION_VISITOR_TABLE; @@ -82,7 +82,7 @@ SqliteStorage::SqliteStorage() : SqliteHelper(DATABASE_NAME, DATABASE_PATH, DATA Open(); } -int32_t SqliteStorage::Add(const DataType type, const std::vector& values) +int32_t PermissionUsedRecordDb::Add(const DataType type, const std::vector& values) { OHOS::Utils::UniqueWriteGuard lock(this->rwLock_); std::string prepareSql = CreateInsertPrepareSqlCmd(type); @@ -111,7 +111,7 @@ int32_t SqliteStorage::Add(const DataType type, const std::vector return SUCCESS; } -int32_t SqliteStorage::Remove(const DataType type, const GenericValues& conditions) +int32_t PermissionUsedRecordDb::Remove(const DataType type, const GenericValues& conditions) { OHOS::Utils::UniqueWriteGuard lock(this->rwLock_); std::vector columnNames = conditions.GetAllKeys(); @@ -124,7 +124,8 @@ int32_t SqliteStorage::Remove(const DataType type, const GenericValues& conditio return (ret == Statement::State::DONE) ? SUCCESS : FAILURE; } -int32_t SqliteStorage::Modify(const DataType type, const GenericValues& modifyValues, const GenericValues& conditions) +int32_t PermissionUsedRecordDb::Modify( + const DataType type, const GenericValues& modifyValues, const GenericValues& conditions) { OHOS::Utils::UniqueWriteGuard lock(this->rwLock_); std::vector modifyColumns = modifyValues.GetAllKeys(); @@ -141,7 +142,7 @@ int32_t SqliteStorage::Modify(const DataType type, const GenericValues& modifyVa return (ret == Statement::State::DONE) ? SUCCESS : FAILURE; } -int32_t SqliteStorage::Find(const DataType type, std::vector& results) +int32_t PermissionUsedRecordDb::Find(const DataType type, std::vector& results) { OHOS::Utils::UniqueWriteGuard lock(this->rwLock_); std::string prepareSql = CreateSelectPrepareSqlCmd(type); @@ -161,7 +162,7 @@ int32_t SqliteStorage::Find(const DataType type, std::vector& res return SUCCESS; } -int32_t SqliteStorage::FindByConditions(const DataType type, const GenericValues& andConditions, +int32_t PermissionUsedRecordDb::FindByConditions(const DataType type, const GenericValues& andConditions, const GenericValues& orConditions, std::vector& results) { OHOS::Utils::UniqueWriteGuard lock(this->rwLock_); @@ -192,7 +193,7 @@ int32_t SqliteStorage::FindByConditions(const DataType type, const GenericValues return SUCCESS; } -int32_t SqliteStorage::RefreshAll(const DataType type, const std::vector& values) +int32_t PermissionUsedRecordDb::RefreshAll(const DataType type, const std::vector& values) { OHOS::Utils::UniqueWriteGuard lock(this->rwLock_); std::string deleteSql = CreateDeletePrepareSqlCmd(type); @@ -224,7 +225,7 @@ int32_t SqliteStorage::RefreshAll(const DataType type, const std::vector& columnNames) const { auto it = dataTypeToSqlTable_.find(type); @@ -258,8 +259,8 @@ std::string SqliteStorage::CreateDeletePrepareSqlCmd( return sql; } -std::string SqliteStorage::CreateUpdatePrepareSqlCmd(const DataType type, const std::vector& modifyColumns, - const std::vector& conditionColumns) const +std::string PermissionUsedRecordDb::CreateUpdatePrepareSqlCmd(const DataType type, + const std::vector& modifyColumns, const std::vector& conditionColumns) const { if (modifyColumns.empty()) { return std::string(); @@ -290,7 +291,7 @@ std::string SqliteStorage::CreateUpdatePrepareSqlCmd(const DataType type, const return sql; } -std::string SqliteStorage::CreateSelectPrepareSqlCmd(const DataType type) const +std::string PermissionUsedRecordDb::CreateSelectPrepareSqlCmd(const DataType type) const { auto it = dataTypeToSqlTable_.find(type); if (it == dataTypeToSqlTable_.end()) { @@ -300,7 +301,7 @@ std::string SqliteStorage::CreateSelectPrepareSqlCmd(const DataType type) const return sql; } -std::string SqliteStorage::CreateSelectByConditionPrepareSqlCmd(const DataType type, +std::string PermissionUsedRecordDb::CreateSelectByConditionPrepareSqlCmd(const DataType type, const std::vector& andColumns, const std::vector& orColumns) const { auto it = dataTypeToSqlTable_.find(type); @@ -334,7 +335,7 @@ std::string SqliteStorage::CreateSelectByConditionPrepareSqlCmd(const DataType t return sql; } -int32_t SqliteStorage::CreatePermissionVisitorTable() const +int32_t PermissionUsedRecordDb::CreatePermissionVisitorTable() const { auto it = dataTypeToSqlTable_.find(DataType::PERMISSION_VISITOR); if (it == dataTypeToSqlTable_.end()) { @@ -352,7 +353,7 @@ int32_t SqliteStorage::CreatePermissionVisitorTable() const return ExecuteSql(sql); } -int32_t SqliteStorage::CreatePermissionRecordTable() const +int32_t PermissionUsedRecordDb::CreatePermissionRecordTable() const { auto it = dataTypeToSqlTable_.find(DataType::PERMISSION_RECORD); if (it == dataTypeToSqlTable_.end()) { diff --git a/services/privacymanager/src/record/on_permission_used_record_callback_proxy.cpp b/services/privacymanager/src/record/on_permission_used_record_callback_proxy.cpp index e0974b25dda17162bd566ddb33c5dac6dd31cbbb..f5b9f3a69efe9e2535784b702426f70d2953a30e 100644 --- a/services/privacymanager/src/record/on_permission_used_record_callback_proxy.cpp +++ b/services/privacymanager/src/record/on_permission_used_record_callback_proxy.cpp @@ -64,7 +64,7 @@ void OnPermissionUsedRecordCallbackProxy::OnQueried(ErrCode code, PermissionUsed return; } - ACCESSTOKEN_LOG_INFO(LABEL, "%{public}s SendRequest success", __func__); + ACCESSTOKEN_LOG_INFO(LABEL, "SendRequest success"); } } // namespace AccessToken } // namespace Security diff --git a/services/privacymanager/src/record/on_permission_used_record_callback_stub.cpp b/services/privacymanager/src/record/on_permission_used_record_callback_stub.cpp index a691970ced8ebe87cd25174d33dc931f0125cf4c..1b22bfc6d4a2713c2aa40abf3635ebfbd227db9d 100644 --- a/services/privacymanager/src/record/on_permission_used_record_callback_stub.cpp +++ b/services/privacymanager/src/record/on_permission_used_record_callback_stub.cpp @@ -33,7 +33,7 @@ static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { int32_t OnPermissionUsedRecordCallbackStub::OnRemoteRequest( uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s called, code: 0x%{public}x", __func__, code); + ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry, code: 0x%{public}x", code); std::u16string descriptor = data.ReadInterfaceToken(); if (descriptor != OnPermissionUsedRecordCallback::GetDescriptor()) { ACCESSTOKEN_LOG_ERROR(LABEL, "get unexpect descriptor: %{public}s", Str16ToStr8(descriptor).c_str()); @@ -53,7 +53,7 @@ int32_t OnPermissionUsedRecordCallbackStub::OnRemoteRequest( ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable fail"); return Constant::FAILURE; } - ACCESSTOKEN_LOG_INFO(LABEL, "%{public}s errCode: %{public}d", __func__, errCode); + ACCESSTOKEN_LOG_INFO(LABEL, "errCode: %{public}d", errCode); OnQueried(errCode, resultSptr->result); } else { return IPCObjectStub::OnRemoteRequest(code, data, reply, option); diff --git a/services/privacymanager/src/record/permission_record_manager.cpp b/services/privacymanager/src/record/permission_record_manager.cpp index f24575d646915d56aa9f8f92362b08dccce3dc2d..350c745d103cdd76e72b89433aa71b7fbefbaacb 100644 --- a/services/privacymanager/src/record/permission_record_manager.cpp +++ b/services/privacymanager/src/record/permission_record_manager.cpp @@ -52,7 +52,7 @@ PermissionRecordManager::~PermissionRecordManager() bool PermissionRecordManager::AddVisitor(AccessTokenID tokenID, int32_t& visitorId) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s called", __func__); + ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry"); PermissionVisitor visitor; if (!GetPermissionVisitor(tokenID, visitor)) { return false; @@ -82,7 +82,7 @@ bool PermissionRecordManager::GetPermissionVisitor(AccessTokenID tokenID, Permis { HapTokenInfo tokenInfo; if (AccessTokenKit::GetHapTokenInfo(tokenID, tokenInfo) != Constant::SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "%{public}s GetHapTokenInfo fail", __func__); + ACCESSTOKEN_LOG_ERROR(LABEL, "GetHapTokenInfo fail"); return false; } visitor.isRemoteDevice = true; @@ -99,7 +99,7 @@ bool PermissionRecordManager::GetPermissionVisitor(AccessTokenID tokenID, Permis bool PermissionRecordManager::AddRecord( int32_t visitorId, const std::string& permissionName, int32_t successCount, int32_t failCount) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s called", __func__); + ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry"); PermissionRecord record; if (!GetPermissionsRecord(visitorId, permissionName, successCount, failCount, record)) { return false; @@ -155,11 +155,11 @@ bool PermissionRecordManager::GetPermissionsRecord(int32_t visitorId, const std: { int32_t opCode; if (!Constant::TransferPermissionToOpcode(permissionName, opCode)) { - ACCESSTOKEN_LOG_ERROR(LABEL, "%{public}s TransferPermissionToOpcode fail", __func__); + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to TransferPermissionToOpcode"); return false; } if (successCount == 0 && failCount == 0) { - ACCESSTOKEN_LOG_ERROR(LABEL, "%{public}s successCount and failCount are both zero", __func__); + ACCESSTOKEN_LOG_ERROR(LABEL, "successCount and failCount are both zero"); return false; } record.visitorId = visitorId; @@ -175,12 +175,12 @@ bool PermissionRecordManager::GetPermissionsRecord(int32_t visitorId, const std: int32_t PermissionRecordManager::AddPermissionUsedRecord(AccessTokenID tokenID, const std::string& permissionName, int32_t successCount, int32_t failCount) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s called, tokenId: %{public}x, permissionName: %{public}s", __func__, + ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry, tokenId: %{public}x, permissionName: %{public}s", tokenID, permissionName.c_str()); ExecuteDeletePermissionRecordTask(); if (AccessTokenKit::GetTokenTypeFlag(tokenID) != TOKEN_HAP) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s Invalid token type", __func__); + ACCESSTOKEN_LOG_DEBUG(LABEL, "Invalid token type"); return Constant::SUCCESS; } @@ -197,7 +197,7 @@ int32_t PermissionRecordManager::AddPermissionUsedRecord(AccessTokenID tokenID, void PermissionRecordManager::RemovePermissionUsedRecords(AccessTokenID tokenID, const std::string& deviceID) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s called, tokenId: %{public}x", __func__, tokenID); + ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry, tokenId: %{public}x", tokenID); Utils::UniqueWriteGuard lk(this->rwLock_); PermissionVisitor visitor; @@ -227,7 +227,7 @@ void PermissionRecordManager::RemovePermissionUsedRecords(AccessTokenID tokenID, int32_t PermissionRecordManager::GetPermissionUsedRecords( const PermissionUsedRequest& request, PermissionUsedResult& result) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s called", __func__); + ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry"); ExecuteDeletePermissionRecordTask(); if (!GetRecordsFromDB(request, result)) { @@ -240,7 +240,7 @@ int32_t PermissionRecordManager::GetPermissionUsedRecords( int32_t PermissionRecordManager::GetPermissionUsedRecordsAsync( const PermissionUsedRequest& request, const sptr& callback) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s called", __func__); + ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry"); auto task = [request, callback]() { ACCESSTOKEN_LOG_INFO(LABEL, "GetPermissionUsedRecordsAsync task called"); PermissionUsedResult result; @@ -259,7 +259,7 @@ bool PermissionRecordManager::GetRecordsFromDB(const PermissionUsedRequest& requ GenericValues orConditionValues; if (DataTranslator::TranslationIntoGenericValues(request, visitorValues, andConditionValues, orConditionValues) != Constant::SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "%{public}s: query time is invalid", __func__); + ACCESSTOKEN_LOG_ERROR(LABEL, "query time is invalid"); return false; } @@ -269,7 +269,7 @@ bool PermissionRecordManager::GetRecordsFromDB(const PermissionUsedRequest& requ return false; } if (findVisitorValues.empty()) { - ACCESSTOKEN_LOG_INFO(LABEL, "%{public}s: no visitor", __func__); + ACCESSTOKEN_LOG_INFO(LABEL, "no visitor"); return true; } @@ -315,7 +315,7 @@ bool PermissionRecordManager::GetRecords( record.Put(FIELD_FLAG, flag); if (DataTranslator::TranslationGenericValuesIntoPermissionUsedRecord(record, tmpPermissionRecord) != Constant::SUCCESS) { - ACCESSTOKEN_LOG_INFO(LABEL, "%{public}s: failed to transform permission to opcode", __func__); + ACCESSTOKEN_LOG_INFO(LABEL, "Failed to transform permission to opcode"); continue; } @@ -379,12 +379,17 @@ int32_t PermissionRecordManager::DeletePermissionRecord(int32_t days) return Constant::FAILURE; } - int32_t recordNum = 0; - for (auto record : deleteRecordValues) { - recordNum++; - if ((TimeUtil::GetCurrentTimestamp() - record.GetInt64(FIELD_TIMESTAMP)) > days || - recordNum > Constant::MAX_TOTAL_RECORD) { - PermissionRecordRepository::GetInstance().RemoveRecordValues(record); + size_t deleteSize = 0; + if (deleteRecordValues.size() > Constant::MAX_TOTAL_RECORD) { + deleteSize = deleteRecordValues.size() - Constant::MAX_TOTAL_RECORD; + for (size_t i = 0; i < deleteSize; ++i) { + PermissionRecordRepository::GetInstance().RemoveRecordValues(deleteRecordValues[i]); + } + } + int64_t deleteTimestamp = TimeUtil::GetCurrentTimestamp() - days; + for (size_t i = deleteSize; i < deleteRecordValues.size(); ++i) { + if (deleteRecordValues[i].GetInt64(FIELD_TIMESTAMP) < deleteTimestamp) { + PermissionRecordRepository::GetInstance().RemoveRecordValues(deleteRecordValues[i]); } } return Constant::SUCCESS; @@ -392,8 +397,8 @@ int32_t PermissionRecordManager::DeletePermissionRecord(int32_t days) std::string PermissionRecordManager::DumpRecordInfo(const std::string& bundleName, const std::string& permissionName) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s called, bundleName=%{public}s, permissionName=%{public}s", - __func__, bundleName.c_str(), permissionName.c_str()); + ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry, bundleName=%{public}s, permissionName=%{public}s", + bundleName.c_str(), permissionName.c_str()); PermissionUsedRequest request; request.bundleName = bundleName; request.flag = FLAG_PERMISSION_USAGE_DETAIL; diff --git a/services/privacymanager/src/record/permission_record_repository.cpp b/services/privacymanager/src/record/permission_record_repository.cpp index 61e033fd6f82fc2176857fdf9f2ca7576264fe31..c902bf74f8afe11a38b024aada89d130ea109d5c 100644 --- a/services/privacymanager/src/record/permission_record_repository.cpp +++ b/services/privacymanager/src/record/permission_record_repository.cpp @@ -16,7 +16,7 @@ #include "permission_record_repository.h" #include "accesstoken_log.h" -#include "sqlite_storage.h" +#include "permission_used_record_db.h" namespace OHOS { namespace Security { @@ -43,8 +43,9 @@ PermissionRecordRepository::~PermissionRecordRepository() bool PermissionRecordRepository::AddRecordValues(const std::vector& recordValues) { - if (SqliteStorage::GetInstance().Add(SqliteStorage::PERMISSION_RECORD, recordValues) != SqliteStorage::SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "%{public}s PERMISSION_VISITOR table add fail", __func__); + if (PermissionUsedRecordDb::GetInstance().Add(PermissionUsedRecordDb::PERMISSION_RECORD, recordValues) + != PermissionUsedRecordDb::SUCCESS) { + ACCESSTOKEN_LOG_ERROR(LABEL, "PERMISSION_RECORD table add fail"); return false; } return true; @@ -53,9 +54,9 @@ bool PermissionRecordRepository::AddRecordValues(const std::vector& recordValues) { - if (SqliteStorage::GetInstance().FindByConditions(SqliteStorage::PERMISSION_RECORD, andConditionValues, - orConditionValues, recordValues) != SqliteStorage::SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "%{public}s PERMISSION_VISITOR table find fail", __func__); + if (PermissionUsedRecordDb::GetInstance().FindByConditions(PermissionUsedRecordDb::PERMISSION_RECORD, + andConditionValues, orConditionValues, recordValues) != PermissionUsedRecordDb::SUCCESS) { + ACCESSTOKEN_LOG_ERROR(LABEL, "PERMISSION_RECORD table find fail"); return false; } return true; @@ -63,9 +64,9 @@ bool PermissionRecordRepository::FindRecordValues(const GenericValues& andCondit bool PermissionRecordRepository::RemoveRecordValues(const GenericValues& conditionValues) { - if (SqliteStorage::GetInstance().Remove(SqliteStorage::PERMISSION_RECORD, conditionValues) - != SqliteStorage::SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "%{public}s PERMISSION_VISITOR table add fail", __func__); + if (PermissionUsedRecordDb::GetInstance().Remove(PermissionUsedRecordDb::PERMISSION_RECORD, conditionValues) + != PermissionUsedRecordDb::SUCCESS) { + ACCESSTOKEN_LOG_ERROR(LABEL, "PERMISSION_RECORD table add fail"); return false; } return true; diff --git a/services/privacymanager/src/record/permission_visitor_repository.cpp b/services/privacymanager/src/record/permission_visitor_repository.cpp index 34544eee19feb9d2587a5d242402fbdcaf7516eb..fa237ddfb10cda7de6f4223b690e11ca97cb92e8 100644 --- a/services/privacymanager/src/record/permission_visitor_repository.cpp +++ b/services/privacymanager/src/record/permission_visitor_repository.cpp @@ -16,7 +16,7 @@ #include "permission_visitor_repository.h" #include "accesstoken_log.h" -#include "sqlite_storage.h" +#include "permission_used_record_db.h" namespace OHOS { namespace Security { @@ -46,9 +46,9 @@ bool PermissionVisitorRepository::AddVisitorValues(const GenericValues& visitorV GenericValues nullValues; std::vector insertValues; std::vector resultValues; - if (SqliteStorage::GetInstance().FindByConditions(SqliteStorage::PERMISSION_VISITOR, visitorValues, - nullValues, resultValues) != SqliteStorage::SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "%{public}s PERMISSION_VISITOR table find fail", __func__); + if (PermissionUsedRecordDb::GetInstance().FindByConditions(PermissionUsedRecordDb::PERMISSION_VISITOR, + visitorValues, nullValues, resultValues) != PermissionUsedRecordDb::SUCCESS) { + ACCESSTOKEN_LOG_ERROR(LABEL, "PERMISSION_VISITOR table find fail"); return false; } if (!resultValues.empty()) { @@ -56,8 +56,9 @@ bool PermissionVisitorRepository::AddVisitorValues(const GenericValues& visitorV } insertValues.emplace_back(visitorValues); - if (SqliteStorage::GetInstance().Add(SqliteStorage::PERMISSION_VISITOR, insertValues) != SqliteStorage::SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "%{public}s PERMISSION_VISITOR table add fail", __func__); + if (PermissionUsedRecordDb::GetInstance().Add(PermissionUsedRecordDb::PERMISSION_VISITOR, insertValues) + != PermissionUsedRecordDb::SUCCESS) { + ACCESSTOKEN_LOG_ERROR(LABEL, "PERMISSION_VISITOR table add fail"); return false; } return true; @@ -66,9 +67,9 @@ bool PermissionVisitorRepository::AddVisitorValues(const GenericValues& visitorV bool PermissionVisitorRepository::FindVisitorValues( const GenericValues& andValues, const GenericValues& orValues, std::vector& visitorValues) { - if (SqliteStorage::GetInstance().FindByConditions(SqliteStorage::PERMISSION_VISITOR, andValues, - orValues, visitorValues) != SqliteStorage::SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "%{public}s PERMISSION_VISITOR table find fail", __func__); + if (PermissionUsedRecordDb::GetInstance().FindByConditions(PermissionUsedRecordDb::PERMISSION_VISITOR, andValues, + orValues, visitorValues) != PermissionUsedRecordDb::SUCCESS) { + ACCESSTOKEN_LOG_ERROR(LABEL, "PERMISSION_VISITOR table find fail"); return false; } return true; @@ -76,9 +77,9 @@ bool PermissionVisitorRepository::FindVisitorValues( bool PermissionVisitorRepository::RemoveVisitorValues(const GenericValues& conditionValues) { - if (SqliteStorage::GetInstance().Remove(SqliteStorage::PERMISSION_VISITOR, conditionValues) - != SqliteStorage::SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "%{public}s PERMISSION_VISITOR table remove fail", __func__); + if (PermissionUsedRecordDb::GetInstance().Remove(PermissionUsedRecordDb::PERMISSION_VISITOR, conditionValues) + != PermissionUsedRecordDb::SUCCESS) { + ACCESSTOKEN_LOG_ERROR(LABEL, "PERMISSION_VISITOR table remove fail"); return false; } return true; diff --git a/services/privacymanager/src/service/privacy_manager_service.cpp b/services/privacymanager/src/service/privacy_manager_service.cpp index 0b2e170f22149fbb1465e728c51c13c279f3e207..f9708f5a6e0e5aa1940b2e68c8c123381eea1105 100644 --- a/services/privacymanager/src/service/privacy_manager_service.cpp +++ b/services/privacymanager/src/service/privacy_manager_service.cpp @@ -72,29 +72,29 @@ void PrivacyManagerService::OnStop() int32_t PrivacyManagerService::AddPermissionUsedRecord( AccessTokenID tokenID, const std::string& permissionName, int32_t successCount, int32_t failCount) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s called, tokenID: 0x%{public}x, permission: %{public}s", - __func__, tokenID, permissionName.c_str()); + ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry, tokenID: 0x%{public}x, permission: %{public}s", + tokenID, permissionName.c_str()); return PermissionRecordManager::GetInstance().AddPermissionUsedRecord( tokenID, permissionName, successCount, failCount); } int32_t PrivacyManagerService::StartUsingPermission(AccessTokenID tokenID, const std::string& permissionName) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s called, tokenID: 0x%{public}x, permission: %{public}s", - __func__, tokenID, permissionName.c_str()); + ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry, tokenID: 0x%{public}x, permission: %{public}s", + tokenID, permissionName.c_str()); return Constant::SUCCESS; } int32_t PrivacyManagerService::StopUsingPermission(AccessTokenID tokenID, const std::string& permissionName) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s called, tokenID: 0x%{public}x, permission: %{public}s", - __func__, tokenID, permissionName.c_str()); + ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry, tokenID: 0x%{public}x, permission: %{public}s", + tokenID, permissionName.c_str()); return Constant::SUCCESS; } int32_t PrivacyManagerService::RemovePermissionUsedRecords(AccessTokenID tokenID, const std::string& deviceID) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s called", __func__); + ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry, tokenID: 0x%{public}x, deviceID: %{private}s", tokenID, deviceID.c_str()); PermissionRecordManager::GetInstance().RemovePermissionUsedRecords(tokenID, deviceID); return Constant::SUCCESS; } @@ -102,7 +102,7 @@ int32_t PrivacyManagerService::RemovePermissionUsedRecords(AccessTokenID tokenID int32_t PrivacyManagerService::GetPermissionUsedRecords( const PermissionUsedRequestParcel& request, PermissionUsedResultParcel& result) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s called", __func__); + ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry"); PermissionUsedResult permissionRecord; int32_t ret = PermissionRecordManager::GetInstance().GetPermissionUsedRecords(request.request, permissionRecord); result.result = permissionRecord; @@ -112,13 +112,14 @@ int32_t PrivacyManagerService::GetPermissionUsedRecords( int32_t PrivacyManagerService::GetPermissionUsedRecords( const PermissionUsedRequestParcel& request, const sptr& callback) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s called", __func__); + ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry"); return PermissionRecordManager::GetInstance().GetPermissionUsedRecordsAsync(request.request, callback); } std::string PrivacyManagerService::DumpRecordInfo(const std::string& bundleName, const std::string& permissionName) { - ACCESSTOKEN_LOG_DEBUG(LABEL, "%{public}s called", __func__); + ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry, bundleName: %{public}s, permissionName: %{public}s", + bundleName.c_str(), permissionName.c_str()); return PermissionRecordManager::GetInstance().DumpRecordInfo(bundleName, permissionName); }