diff --git a/frameworks/privacy/BUILD.gn b/frameworks/privacy/BUILD.gn index e0106a79d2849a5394bd962dd8c177b0bba4b6f4..8b434daf15e1af89f1fc6844e3568b34ca2ba87a 100644 --- a/frameworks/privacy/BUILD.gn +++ b/frameworks/privacy/BUILD.gn @@ -30,6 +30,7 @@ ohos_shared_library("privacy_communication_adapter_cxx") { "src/permission_used_record_parcel.cpp", "src/permission_used_request_parcel.cpp", "src/permission_used_result_parcel.cpp", + "src/perm_active_response_parcel.cpp", "src/used_record_detail_parcel.cpp", ] diff --git a/frameworks/privacy/include/i_perm_active_status_callback.h b/frameworks/privacy/include/i_perm_active_status_callback.h new file mode 100755 index 0000000000000000000000000000000000000000..8d164cad031969810cf9ad2ecab3763824f10694 --- /dev/null +++ b/frameworks/privacy/include/i_perm_active_status_callback.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 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 I_PERMI_ACTIVE_STATUS_CALLBACK_H +#define I_PERMI_ACTIVE_STATUS_CALLBACK_H + +#include + +#include "access_token.h" +#include "active_change_response_info.h" +#include "iremote_broker.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +class IPermActiveStatusChangeCbk : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.security.accesstoken.IPermActiveStatusChangeCbk"); + + virtual void ActiveStatusChangeCallback(ActiveChangeResponse& result) = 0; + + enum { + PERM_ACTIVE_STATUS_CHANGE = 0, + }; +}; +} // namespace AccessToken +} // namespace Security +} // namespace OHOS + +#endif // PERMI_ACTIVE_STATUS_CALLBACK_H \ No newline at end of file diff --git a/frameworks/privacy/include/i_privacy_manager.h b/frameworks/privacy/include/i_privacy_manager.h index 8ee5f3fbad385dbff6785acfa5c3531949dea670..137f5886406aaf77e073d446879683e823247240 100644 --- a/frameworks/privacy/include/i_privacy_manager.h +++ b/frameworks/privacy/include/i_privacy_manager.h @@ -45,7 +45,9 @@ public: virtual int32_t GetPermissionUsedRecords( const PermissionUsedRequestParcel& request, const sptr& callback) = 0; virtual std::string DumpRecordInfo(const std::string& bundleName, const std::string& permissionName) = 0; - + virtual int32_t RegisterPermActiveStatusCallback( + std::vector& permList, const sptr& callback) = 0; + virtual int32_t UnRegisterPermActiveStatusCallback(const sptr& callback) = 0; enum class InterfaceCode { ADD_PERMISSION_USED_RECORD = 0xf001, START_USING_PERMISSION = 0xf002, @@ -53,7 +55,9 @@ public: DELETE_PERMISSION_USED_RECORDS = 0xf004, GET_PERMISSION_USED_RECORDS = 0xf005, GET_PERMISSION_USED_RECORDS_ASYNC = 0xf006, - DUMP_RECORD_INFO = 0xf007 + DUMP_RECORD_INFO = 0xf007, + REGISTER_PERM_ACTIVE_STATUS_CHANGE_CALLBACK = 0xf008, + UNREGISTER_PERM_ACTIVE_STATUS_CHANGE_CALLBACK = 0xf009, }; }; } // namespace AccessToken diff --git a/frameworks/privacy/include/perm_active_response_parcel.h b/frameworks/privacy/include/perm_active_response_parcel.h new file mode 100755 index 0000000000000000000000000000000000000000..b870dd23d287ee3b7fd100a3f93123f25f9ef772 --- /dev/null +++ b/frameworks/privacy/include/perm_active_response_parcel.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 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 PERMISSION_USED_RECORD_PRACEL_H +#define PERMISSION_USED_RECORD_PRACEL_H + +#include "parcel.h" +#include "active_change_response_info.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +struct ActiveChangeResponseParcel final : public Parcelable { + ActiveChangeResponseParcel() = default; + + ~ActiveChangeResponseParcel() override = default; + + bool Marshalling(Parcel& out) const override; + + static ActiveChangeResponseParcel* Unmarshalling(Parcel& in); + + ActiveChangeResponse changeResponse; +}; +} // namespace AccessToken +} // namespace Security +} // namespace OHOS + +#endif // PERMISSION_USED_RECORD_PRACEL_H diff --git a/frameworks/privacy/src/perm_active_response_parcel.cpp b/frameworks/privacy/src/perm_active_response_parcel.cpp new file mode 100755 index 0000000000000000000000000000000000000000..9a475dd857b6343fd9a1529f0fbfa23beb136015 --- /dev/null +++ b/frameworks/privacy/src/perm_active_response_parcel.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 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 "perm_active_response_parcel.h" +#include "parcel_utils.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +bool ActiveChangeResponseParcel::Marshalling(Parcel& out) const +{ + RETURN_IF_FALSE(out.WriteUint32(this->changeResponse.tokenID)); + RETURN_IF_FALSE(out.WriteString(this->changeResponse.permissionName)); + RETURN_IF_FALSE(out.WriteString(this->changeResponse.deviceId)); + RETURN_IF_FALSE(out.WriteInt32(this->changeResponse.type)); + return true; +} + +ActiveChangeResponseParcel* ActiveChangeResponseParcel::Unmarshalling(Parcel& in) +{ + auto* activeChangeResponseParcel = new (std::nothrow) ActiveChangeResponseParcel(); + if (activeChangeResponseParcel == nullptr) { + return nullptr; + } + + RELEASE_IF_FALSE(in.ReadUint32(activeChangeResponseParcel->changeResponse.tokenID), activeChangeResponseParcel); + RELEASE_IF_FALSE(in.ReadString(activeChangeResponseParcel->changeResponse.permissionName), + activeChangeResponseParcel); + RELEASE_IF_FALSE(in.ReadString(activeChangeResponseParcel->changeResponse.deviceId), activeChangeResponseParcel); + + int32_t type; + RELEASE_IF_FALSE(in.ReadInt32(type), activeChangeResponseParcel); + activeChangeResponseParcel->changeResponse.type = static_cast(type); + return activeChangeResponseParcel; +} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/interfaces/innerkits/accesstoken/include/access_token.h b/interfaces/innerkits/accesstoken/include/access_token.h index ef3aab948606682cdfed85d5fccec0787b818f77..a56b4c16ff76ddb481fc9a1b9f73a428a685329a 100644 --- a/interfaces/innerkits/accesstoken/include/access_token.h +++ b/interfaces/innerkits/accesstoken/include/access_token.h @@ -43,6 +43,7 @@ typedef enum TypeATokenTypeEnum { TOKEN_INVALID = -1, TOKEN_HAP = 0, TOKEN_NATIVE, + TOKEN_SHELL, } ATokenTypeEnum; typedef enum TypeATokenAplEnum { diff --git a/interfaces/innerkits/privacy/BUILD.gn b/interfaces/innerkits/privacy/BUILD.gn index 044a1a6803c2473024879dd8e9e93a66d45aadf5..7c6c33d75de309f5e82879e5330a2e8312005876 100644 --- a/interfaces/innerkits/privacy/BUILD.gn +++ b/interfaces/innerkits/privacy/BUILD.gn @@ -41,6 +41,9 @@ ohos_shared_library("libprivacy_sdk") { "src/privacy_kit.cpp", "src/privacy_manager_client.cpp", "src/privacy_manager_proxy.cpp", + "src/perm_active_status_change_callback_stub.cpp", + "src/perm_active_status_change_callback.cpp", + "src/perm_active_status_change_customized_cbk.cpp", ] deps = [ diff --git a/interfaces/innerkits/privacy/include/active_change_response_info.h b/interfaces/innerkits/privacy/include/active_change_response_info.h new file mode 100755 index 0000000000000000000000000000000000000000..71f73446229551d4471d16ba135f7340a13505dc --- /dev/null +++ b/interfaces/innerkits/privacy/include/active_change_response_info.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 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 ACTIVE_CHANGE_RESPONSE_INFO_H +#define ACTIVE_CHANGE_RESPONSE_INFO_H + +#include +#include + +#include "access_token.h" + +namespace OHOS { +namespace Security { +namespace AccessToken{ +#define TOKENID_LIST_SIZE_MAX 1024 +#define PERM_LIST_SIZE_MAX 1024 + +enum ActiveChangeType { + PERM_INACTIVE = 0, + PERM_ACTIVE_IN_FOREGROUND = 1, + PERM_ACTIVE_IN_BACKGRONGD = 2, +}; + +struct ActiveChangeResponse { + AccessTokenID tokenID; + std::string permissionName; + std::string deviceId; + ActiveChangeType type; +}; + +} // namespace AccessToken +} // namespace Security +} // namespace OHOS + +#endif // ACTIVE_CHANGE_RESPONSE_INFO_H \ No newline at end of file diff --git a/interfaces/innerkits/privacy/include/perm_active_status_change_callback.h b/interfaces/innerkits/privacy/include/perm_active_status_change_callback.h new file mode 100755 index 0000000000000000000000000000000000000000..02ddc121fdda24266c69e2ccf8ddfe3779c38354 --- /dev/null +++ b/interfaces/innerkits/privacy/include/perm_active_status_change_callback.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 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 PERM_ACTIVE_STATUS_CHANGE_CALLBACK_H +#define PERM_ACTIVE_STATUS_CHANGE_CALLBACK_H + +#include +#include + +#include "active_change_response_info.h" +#include "perm_active_status_change_callback_stub.h" +#include "perm_active_status_change_customized_cbk.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +class PermActiveStatusChangeCallback : public PermActiveStatusChangeCallbackStub { +public: + explicit PermActiveStatusChangeCallback(const std::shared_ptr &subscriber); + ~PermActiveStatusChangeCallback() override; + + void ActiveStatusChangeCallback(ActiveChangeResponse& result) override; + + void Stop(); + +private: + std::shared_ptr customizedCallback_; +}; +} // namespace AccessToken +} // namespace Security +} // namespace OHOS + +#endif // PERM_ACTIVE_STATUS_CHANGE_CALLBACK_H \ No newline at end of file diff --git a/interfaces/innerkits/privacy/include/perm_active_status_change_callback_stub.h b/interfaces/innerkits/privacy/include/perm_active_status_change_callback_stub.h new file mode 100755 index 0000000000000000000000000000000000000000..71838bd3a47d324d9d1e5143f7442859dc3880f6 --- /dev/null +++ b/interfaces/innerkits/privacy/include/perm_active_status_change_callback_stub.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 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 PERM_ACTIVE_STATUS_CHANGE_CALLBACK_STUB_H +#define PERM_ACTIVE_STATUS_CHANGE_CALLBACK_STUB_H + + +#include "i_perm_active_status_callback.h" + +#include "iremote_stub.h" +#include "nocopyable.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +class PermActiveStatusChangeCallbackStub : public IRemoteStub { +public: + PermActiveStatusChangeCallbackStub() = default; + virtual ~PermActiveStatusChangeCallbackStub() = default; + + int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; +}; +} // namespace AccessToken +} // namespace Security +} // namespace OHOS +#endif // PERM_ACTIVE_STATUS_CHANGE_CALLBACK_STUB_H diff --git a/interfaces/innerkits/privacy/include/perm_active_status_change_customized_cbk.h b/interfaces/innerkits/privacy/include/perm_active_status_change_customized_cbk.h new file mode 100755 index 0000000000000000000000000000000000000000..e5a7654760b384b50cf9e45293f4bd1b29316514 --- /dev/null +++ b/interfaces/innerkits/privacy/include/perm_active_status_change_customized_cbk.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 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 PERM_ACTIVE_STATUS_CHANGE_CUSTOMIZED_CBK_H +#define PERM_ACTIVE_STATUS_CHANGE_CUSTOMIZED_CBK_H + +#include +#include + +#include "access_token.h" +#include "active_change_response_info.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +class PermActiveStatusCustomizedCbk { +public: + PermActiveStatusCustomizedCbk(); + explicit PermActiveStatusCustomizedCbk(const std::vector& permList); + virtual ~PermActiveStatusCustomizedCbk(); + + virtual void ActiveStatusChangeCallback(ActiveChangeResponse& result) = 0; + + void GetPermList(std::vector& permList) const; + +private: + std::vector permList_; +}; +} // namespace AccessToken +} // namespace Security +} // namespace OHOS + +#endif // PERM_ACTIVE_STATUS_CHANGE_CUSTOMIZED_CBK_H \ No newline at end of file diff --git a/interfaces/innerkits/privacy/include/privacy_kit.h b/interfaces/innerkits/privacy/include/privacy_kit.h index b3fb9a4d1e58d5bb63f9857dbc9a35428c29f6f0..3c7e34cc7129764d03c4e271f9e71aaeb3fbb4cc 100644 --- a/interfaces/innerkits/privacy/include/privacy_kit.h +++ b/interfaces/innerkits/privacy/include/privacy_kit.h @@ -22,6 +22,7 @@ #include "on_permission_used_record_callback.h" #include "permission_used_request.h" #include "permission_used_result.h" +#include "perm_active_status_change_customized_cbk.h" namespace OHOS { namespace Security { @@ -37,6 +38,8 @@ public: static int32_t GetPermissionUsedRecords( const PermissionUsedRequest& request, const sptr& callback); static std::string DumpRecordInfo(const std::string& bundleName, const std::string& permissionName); + static int32_t RegisterPermActiveStatusCallback(const std::shared_ptr& callback); + static int32_t UnRegisterPermActiveStatusCallback(const std::shared_ptr& callback); }; } // namespace AccessToken } // namespace Security diff --git a/interfaces/innerkits/privacy/src/perm_active_status_change_callback.cpp b/interfaces/innerkits/privacy/src/perm_active_status_change_callback.cpp new file mode 100755 index 0000000000000000000000000000000000000000..633a2e37a61838839423fdc0c66699d09f2ffd0c --- /dev/null +++ b/interfaces/innerkits/privacy/src/perm_active_status_change_callback.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 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 "perm_active_status_change_callback.h" + +#include "access_token.h" +#include "accesstoken_log.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { + LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "PermissionActiveStatusChangeCallback" +}; +PermActiveStatusChangeCallback::PermActiveStatusChangeCallback( + const std::shared_ptr &customizedCallback) + : customizedCallback_(customizedCallback) +{} + +PermActiveStatusChangeCallback::~PermActiveStatusChangeCallback() +{} + +void PermActiveStatusChangeCallback::ActiveStatusChangeCallback(ActiveChangeResponse& result) +{ + if (customizedCallback_ == nullptr) { + ACCESSTOKEN_LOG_ERROR(LABEL, "customizedCallback_ is nullptr"); + return; + } + + customizedCallback_->ActiveStatusChangeCallback(result); +} + +void PermActiveStatusChangeCallback::Stop() +{} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/interfaces/innerkits/privacy/src/perm_active_status_change_callback_stub.cpp b/interfaces/innerkits/privacy/src/perm_active_status_change_callback_stub.cpp new file mode 100755 index 0000000000000000000000000000000000000000..3fcfcb3ecc473190ffb201ac2bc9e1cd7420d973 --- /dev/null +++ b/interfaces/innerkits/privacy/src/perm_active_status_change_callback_stub.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 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 "perm_active_status_change_callback_stub.h" + +#include "accesstoken_log.h" +#include "perm_active_response_parcel.h" +#include "string_ex.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +namespace { +static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { + LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PermActiveStatusChangeCallbackStub" +}; +} + +int32_t PermActiveStatusChangeCallbackStub::OnRemoteRequest( + uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) +{ + ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry, code: 0x%{public}x", code); + std::u16string descriptor = data.ReadInterfaceToken(); + if (descriptor != IPermActiveStatusChangeCbk::GetDescriptor()) { + ACCESSTOKEN_LOG_ERROR(LABEL, "get unexpect descriptor: %{public}s", Str16ToStr8(descriptor).c_str()); + return RET_FAILED; + } + + int32_t msgCode = static_cast(code); + if (msgCode == IPermActiveStatusChangeCbk::PERM_ACTIVE_STATUS_CHANGE) { + sptr resultSptr = data.ReadParcelable(); + if (resultSptr == nullptr) { + ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable fail"); + return RET_FAILED; + } + + ActiveStatusChangeCallback(resultSptr->changeResponse); + } else { + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + return RET_SUCCESS; +} + +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/interfaces/innerkits/privacy/src/perm_active_status_change_customized_cbk.cpp b/interfaces/innerkits/privacy/src/perm_active_status_change_customized_cbk.cpp new file mode 100755 index 0000000000000000000000000000000000000000..a87e154868f1e2a0cc3a45cba2f14a953155dc51 --- /dev/null +++ b/interfaces/innerkits/privacy/src/perm_active_status_change_customized_cbk.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 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 "perm_active_status_change_customized_cbk.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +PermActiveStatusCustomizedCbk::PermActiveStatusCustomizedCbk() +{} + +PermActiveStatusCustomizedCbk::PermActiveStatusCustomizedCbk( + const std::vector& permList) : permList_(permList) // 此处是否有问题 +{} + +PermActiveStatusCustomizedCbk::~PermActiveStatusCustomizedCbk() +{} + +void PermActiveStatusCustomizedCbk::GetPermList(std::vector& permList) const +{ + permList = permList_; +} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/interfaces/innerkits/privacy/src/privacy_kit.cpp b/interfaces/innerkits/privacy/src/privacy_kit.cpp index 0b9557bdd38c5d61acc97c2fb206349b3b8894fc..2e91a684dea85272c6f9471c79359c86366d9949 100644 --- a/interfaces/innerkits/privacy/src/privacy_kit.cpp +++ b/interfaces/innerkits/privacy/src/privacy_kit.cpp @@ -78,6 +78,18 @@ std::string PrivacyKit::DumpRecordInfo(const std::string& bundleName, const std: bundleName.c_str(), permissionName.c_str()); return PrivacyManagerClient::GetInstance().DumpRecordInfo(bundleName, permissionName); } + +int32_t PrivacyKit::RegisterPermActiveStatusCallback(const std::shared_ptr& callback) +{ + ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry"); + return PrivacyManagerClient::GetInstance().RegisterPermActiveStatusCallback(callback); +} + +int32_t PrivacyKit::UnRegisterPermActiveStatusCallback(const std::shared_ptr& callback) +{ + ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry"); + return PrivacyManagerClient::GetInstance().UnRegisterPermActiveStatusCallback(callback); +} } // namespace AccessToken } // namespace Security } // namespace OHOS diff --git a/interfaces/innerkits/privacy/src/privacy_manager_client.cpp b/interfaces/innerkits/privacy/src/privacy_manager_client.cpp index 495f5b42a47dbb4a65ca5e769bd7452f84318c77..f46fb627aaa1b621be1576d8b57adeca98d8cdbf 100644 --- a/interfaces/innerkits/privacy/src/privacy_manager_client.cpp +++ b/interfaces/innerkits/privacy/src/privacy_manager_client.cpp @@ -14,6 +14,7 @@ */ #include "privacy_manager_client.h" +#include #include "accesstoken_log.h" #include "data_validator.h" #include "iservice_registry.h" @@ -142,6 +143,83 @@ std::string PrivacyManagerClient::DumpRecordInfo(const std::string& bundleName, return proxy->DumpRecordInfo(bundleName, permissionName); } +int32_t PrivacyManagerClient::CreateActiveStatusChangeCbk( + const std::shared_ptr& callback, sptr& callbackObject) +{ + std::lock_guard lock(activeCbkMutex_); + + auto goalCallback = activeCbkMap_.find(callback); + if (goalCallback != activeCbkMap_.end()) { + callbackObject = goalCallback->second->AsObject(); + ACCESSTOKEN_LOG_ERROR(LABEL, "activeCbkMap_ already has such callback"); + return ERROR; + } else { + if (activeCbkMap_.size() == 200) { + ACCESSTOKEN_LOG_ERROR(LABEL, "the maximum number of subscribers has been reached"); + return ERROR; + } + sptr callbackWraped = + new (std::nothrow) PermActiveStatusChangeCallback(callback); + if (!callbackWraped) { + ACCESSTOKEN_LOG_ERROR(LABEL, "memory allocation for callbackWraped failed!"); + return ERROR; + } + ACCESSTOKEN_LOG_INFO(LABEL, "callbackObject added"); + callbackObject = callbackWraped->AsObject(); + activeCbkMap_[callback] = callbackWraped; + } + return RET_SUCCESS; +} + +int32_t PrivacyManagerClient::RegisterPermActiveStatusCallback( + const std::shared_ptr& callback) +{ + ACCESSTOKEN_LOG_INFO(LABEL, "called!"); + if (callback == nullptr) { + ACCESSTOKEN_LOG_ERROR(LABEL, "customizedCb is nullptr"); + return ERROR; + } + + sptr callbackObject = nullptr; + int32_t result = CreateActiveStatusChangeCbk(callback, callbackObject); + if (result != RET_SUCCESS) { + return result; + } + + auto proxy = GetProxy(); + if (proxy == nullptr) { + ACCESSTOKEN_LOG_ERROR(LABEL, "proxy is null"); + return ERROR; + } + std::vector permList; + callback->GetPermList(permList); + + return proxy->RegisterPermActiveStatusCallback(permList, callbackObject); +} + +int32_t PrivacyManagerClient::UnRegisterPermActiveStatusCallback( + const std::shared_ptr& callback) +{ + ACCESSTOKEN_LOG_INFO(LABEL, "%{public}s: called!", __func__); + + std::lock_guard lock(activeCbkMutex_); + auto goalCallback = activeCbkMap_.find(callback); + if (goalCallback == activeCbkMap_.end()) { + ACCESSTOKEN_LOG_ERROR(LABEL, "goalCallback already is not exist"); + return ERROR; + } + + auto proxy = GetProxy(); + if (proxy == nullptr) { + ACCESSTOKEN_LOG_ERROR(LABEL, "proxy is null"); + return ERROR; + } + + int32_t result = proxy->UnRegisterPermActiveStatusCallback(goalCallback->second->AsObject()); + activeCbkMap_.erase(goalCallback); + return result; +} + void PrivacyManagerClient::InitProxy() { std::lock_guard lock(proxyMutex_); diff --git a/interfaces/innerkits/privacy/src/privacy_manager_client.h b/interfaces/innerkits/privacy/src/privacy_manager_client.h index c43bd9dd1fc9bf60b36c6ec648285fa12ff97650..28b4995ee1507411f2b01ad2f879a85b445bcb58 100644 --- a/interfaces/innerkits/privacy/src/privacy_manager_client.h +++ b/interfaces/innerkits/privacy/src/privacy_manager_client.h @@ -16,11 +16,14 @@ #ifndef PRIVACY_MANAGER_CLIENT_H #define PRIVACY_MANAGER_CLIENT_H +#include #include #include #include #include "i_privacy_manager.h" +#include "perm_active_status_change_callback.h" +#include "perm_active_status_change_customized_cbk.h" #include "privacy_death_recipient.h" namespace OHOS { @@ -41,6 +44,10 @@ public: int32_t GetPermissionUsedRecords( const PermissionUsedRequest& request, const sptr& callback); std::string DumpRecordInfo(const std::string& bundleName, const std::string& permissionName); + int32_t RegisterPermActiveStatusCallback(const std::shared_ptr& callback); + int32_t UnRegisterPermActiveStatusCallback(const std::shared_ptr& callback); + int32_t CreateActiveStatusChangeCbk( + const std::shared_ptr& callback, sptr& callbackObject); void OnRemoteDiedHandle(); private: @@ -52,6 +59,10 @@ private: sptr serviceDeathObserver_ = nullptr; void InitProxy(); sptr GetProxy(); + +private: + std::mutex activeCbkMutex_; + std::map, sptr> activeCbkMap_; }; } // namespace AccessToken } // namespace Security diff --git a/interfaces/innerkits/privacy/src/privacy_manager_proxy.cpp b/interfaces/innerkits/privacy/src/privacy_manager_proxy.cpp index b8224d258bd3a7eca109c6cb1332b871342b6bea..38cef84015fd075b9f08c86e7843f6efda21d55e 100644 --- a/interfaces/innerkits/privacy/src/privacy_manager_proxy.cpp +++ b/interfaces/innerkits/privacy/src/privacy_manager_proxy.cpp @@ -211,6 +211,77 @@ std::string PrivacyManagerProxy::DumpRecordInfo(const std::string& bundleName, c return dumpInfo; } +int32_t PrivacyManagerProxy::RegisterPermActiveStatusCallback( + std::vector& permList, const sptr& callback) +{ + ACCESSTOKEN_LOG_INFO(LABEL, "called."); + MessageParcel data; + data.WriteInterfaceToken(IPrivacyManager::GetDescriptor()); + + uint32_t listSize = permList.size(); + if (!data.WriteUint32(listSize)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write listSize"); + return ERROR; + } + for (int i = 0; i < listSize; i++) { + if (!data.WriteString(permList[i])) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write permList[%{public}d], %{public}s", i, permList[i].c_str()); + return ERROR; + } + } + + if (!data.WriteRemoteObject(callback)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write remote object."); + return ERROR; + } + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + sptr remote = Remote(); + if (remote == nullptr) { + ACCESSTOKEN_LOG_ERROR(LABEL, "remote service null."); + return ERROR; + } + int32_t requestResult = remote->SendRequest( + static_cast(IPrivacyManager::InterfaceCode::REGISTER_PERM_ACTIVE_STATUS_CHANGE_CALLBACK), + data, reply, option); + if (requestResult != NO_ERROR) { + ACCESSTOKEN_LOG_ERROR(LABEL, "request fail, result: %{public}d.", requestResult); + return ERROR; + } + + int32_t result = reply.ReadInt32(); + return result; +} + +int32_t PrivacyManagerProxy::UnRegisterPermActiveStatusCallback(const sptr& callback) +{ + ACCESSTOKEN_LOG_INFO(LABEL, "called."); + MessageParcel data; + data.WriteInterfaceToken(IPrivacyManager::GetDescriptor()); + + if (!data.WriteRemoteObject(callback)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to write remote object."); + return ERROR; + } + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + sptr remote = Remote(); + if (remote == nullptr) { + ACCESSTOKEN_LOG_ERROR(LABEL, "remote service null."); + return ERROR; + } + int32_t requestResult = remote->SendRequest( + static_cast(IPrivacyManager::InterfaceCode::UNREGISTER_PERM_ACTIVE_STATUS_CHANGE_CALLBACK), + data, reply, option); + if (requestResult != NO_ERROR) { + ACCESSTOKEN_LOG_ERROR(LABEL, "request fail, result: %{public}d.", requestResult); + return ERROR; + } + + int32_t result = reply.ReadInt32(); + return result; +} + bool PrivacyManagerProxy::SendRequest( IPrivacyManager::InterfaceCode code, MessageParcel& data, MessageParcel& reply) { diff --git a/interfaces/innerkits/privacy/src/privacy_manager_proxy.h b/interfaces/innerkits/privacy/src/privacy_manager_proxy.h index 1ed65c1283edd58e8bb5e56df0e40ee619675b1c..c3c2ef1a92924a01ae0eb46566c0a2522ca1ccab 100644 --- a/interfaces/innerkits/privacy/src/privacy_manager_proxy.h +++ b/interfaces/innerkits/privacy/src/privacy_manager_proxy.h @@ -39,6 +39,8 @@ public: int32_t GetPermissionUsedRecords(const PermissionUsedRequestParcel& request, const sptr& callback) override; std::string DumpRecordInfo(const std::string& bundleName, const std::string& permissionName) override; + int32_t RegisterPermActiveStatusCallback(std::vector& permList, const sptr& callback) override; + int32_t UnRegisterPermActiveStatusCallback(const sptr& callback) override; private: bool SendRequest(IPrivacyManager::InterfaceCode code, MessageParcel& data, MessageParcel& reply); diff --git a/interfaces/innerkits/privacy/test/unittest/src/privacy_kit_test.cpp b/interfaces/innerkits/privacy/test/unittest/src/privacy_kit_test.cpp index 4c5b9de0288e90d9b8a081c8670d51cb127fce48..97edbdd9fca0f88291c9e4f5ce71e0a1f4e8f3c0 100644 --- a/interfaces/innerkits/privacy/test/unittest/src/privacy_kit_test.cpp +++ b/interfaces/innerkits/privacy/test/unittest/src/privacy_kit_test.cpp @@ -51,6 +51,13 @@ static HapInfoParams g_InfoParmsB = { .appIDDesc = "privacy_test.bundleB" }; +static HapInfoParams g_InfoParmsE = { + .userID = 1, + .bundleName = "ohos.privacy_test.bundleE", + .instIndex = 0, + .appIDDesc = "privacy_test.bundleE" +}; + static AccessTokenID g_selfTokenId = 0; static AccessTokenID g_TokenId_A = 0; static AccessTokenID g_TokenId_B = 0; @@ -75,8 +82,12 @@ void PrivacyKitTest::SetUp() g_TokenId_B = AccessTokenKit::GetHapTokenID(g_InfoParmsB.userID, g_InfoParmsB.bundleName, g_InfoParmsB.instIndex); + AccessTokenID tokenId = AccessTokenKit::GetHapTokenID(g_InfoParmsE.userID, + g_InfoParmsE.bundleName, + g_InfoParmsE.instIndex); + AccessTokenKit::DeleteToken(tokenId); - AccessTokenID tokenId = AccessTokenKit::GetHapTokenID(100, "com.ohos.permissionmanager", 0); + tokenId = AccessTokenKit::GetHapTokenID(100, "com.ohos.permissionmanager", 0); SetSelfTokenID(tokenId); } @@ -92,6 +103,11 @@ void PrivacyKitTest::TearDown() g_InfoParmsB.bundleName, g_InfoParmsB.instIndex); AccessTokenKit::DeleteToken(tokenId); + + tokenId = AccessTokenKit::GetHapTokenID(g_InfoParmsE.userID, + g_InfoParmsE.bundleName, + g_InfoParmsE.instIndex); + AccessTokenKit::DeleteToken(tokenId); } std::string PrivacyKitTest::GetLocalDeviceUdid() @@ -536,4 +552,188 @@ HWTEST_F(PrivacyKitTest, GetPermissionUsedRecordsAsync002, TestSize.Level1) BuildQueryRequest(g_TokenId_A, GetLocalDeviceUdid(), "", permissionList, request); OHOS::sptr callback(new TestCallBack()); ASSERT_EQ(RET_NO_ERROR, PrivacyKit::GetPermissionUsedRecords(request, callback)); +} + +class CbCustomizeTest1 : public PermActiveStatusCustomizedCbk { +public: + explicit CbCustomizeTest1(const std::vector &permList) + : PermActiveStatusCustomizedCbk(permList) + { + GTEST_LOG_(INFO) << "CbCustomizeTest1 create"; + } + + ~CbCustomizeTest1() + {} + + virtual void ActiveStatusChangeCallback(ActiveChangeResponse& result) + { + type_ = result.type; + GTEST_LOG_(INFO) << "CbCustomizeTest1 ActiveChangeResponse"; + GTEST_LOG_(INFO) << "tokenid " << result.tokenID; + GTEST_LOG_(INFO) << "permissionName " << result.permissionName; + GTEST_LOG_(INFO) << "deviceId " << result.deviceId; + GTEST_LOG_(INFO) << "type " << result.type; + } + + ActiveChangeType type_ = PERM_INACTIVE; +}; + +class CbCustomizeTest2 : public PermActiveStatusCustomizedCbk { +public: + explicit CbCustomizeTest2(const std::vector &permList) + : PermActiveStatusCustomizedCbk(permList) + { + GTEST_LOG_(INFO) << "CbCustomizeTest2 create"; + } + + ~CbCustomizeTest2() + {} + + virtual void ActiveStatusChangeCallback(ActiveChangeResponse& result) + { + type_ = result.type; + GTEST_LOG_(INFO) << "CbCustomizeTest2 ActiveChangeResponse"; + GTEST_LOG_(INFO) << "tokenid " << result.tokenID; + GTEST_LOG_(INFO) << "permissionName " << result.permissionName; + GTEST_LOG_(INFO) << "deviceId " << result.deviceId; + GTEST_LOG_(INFO) << "type " << result.type; + } + + ActiveChangeType type_; +}; + +/** + * @tc.name: RegisterPermActiveStatusCallback001 + * @tc.desc: RegisterPermActiveStatusCallback with valid permission. + * @tc.type: FUNC + * @tc.require:Issue Number + */ +HWTEST_F(PrivacyKitTest, RegisterPermActiveStatusCallback001, TestSize.Level1) +{ + std::vector permList = {"ohos.permission.CAMERA"}; + + auto callbackPtr = std::make_shared(permList); + callbackPtr->type_ = PERM_INACTIVE; + + int32_t res = PrivacyKit::RegisterPermActiveStatusCallback(callbackPtr); + + static PermissionStateFull infoManagerTestStateA = { + .permissionName = "ohos.permission.CAMERA", + .grantFlags = {1}, + .grantStatus = {PERMISSION_GRANTED}, + .isGeneral = true, + .resDeviceID = {"local"} + }; + static HapPolicyParams infoManagerTestPolicyPrams = { + .apl = APL_NORMAL, + .domain = "test.domain", + .permList = {}, + .permStateList = {infoManagerTestStateA} + }; + + AccessTokenIDEx tokenIdEx = {0}; + AccessTokenID tokenID; + tokenIdEx = AccessTokenKit::AllocHapToken(g_InfoParmsE, infoManagerTestPolicyPrams); + + tokenID = tokenIdEx.tokenIdExStruct.tokenID; + ASSERT_NE(0, tokenID); + + ATokenTypeEnum ret = AccessTokenKit::GetTokenTypeFlag(tokenID); + ASSERT_EQ(ret, TOKEN_HAP); + + res = PrivacyKit::StartUsingPermission(tokenID, "ohos.permission.CAMERA"); + ASSERT_EQ(RET_SUCCESS, res); + + ASSERT_EQ(PERM_ACTIVE_IN_FOREGROUND, callbackPtr->type_); + + res = PrivacyKit::StopUsingPermission(tokenID, "ohos.permission.CAMERA"); + ASSERT_EQ(RET_SUCCESS, res); + ASSERT_EQ(PERM_INACTIVE, callbackPtr->type_); + + res = PrivacyKit::UnRegisterPermActiveStatusCallback(callbackPtr); + ASSERT_EQ(RET_SUCCESS, res); + callbackPtr->type_ = PERM_INACTIVE; + + res = PrivacyKit::StartUsingPermission(tokenID, "ohos.permission.CAMERA"); + ASSERT_EQ(RET_SUCCESS, res); + ASSERT_EQ(PERM_INACTIVE, callbackPtr->type_); + + res = PrivacyKit::StopUsingPermission(tokenID, "ohos.permission.CAMERA"); + ASSERT_EQ(RET_SUCCESS, res); + ASSERT_EQ(PERM_INACTIVE, callbackPtr->type_); + + res = AccessTokenKit::DeleteToken(tokenID); + ASSERT_EQ(RET_SUCCESS, res); +} + + +/** + * @tc.name: RegisterPermActiveStatusCallback002 + * @tc.desc: RegisterPermActiveStatusCallback with valid permission. + * @tc.type: FUNC + * @tc.require:Issue Number + */ + +HWTEST_F(PrivacyKitTest, RegisterPermActiveStatusCallback002, TestSize.Level1) +{ + std::vector permList1 = {"ohos.permission.CAMERA"}; + auto callbackPtr1 = std::make_shared(permList1); + callbackPtr1->type_ = PERM_INACTIVE; + + std::vector permList2 = {"ohos.permission.GET_BUNDLE_INFO"}; + auto callbackPtr2 = std::make_shared(permList2); + callbackPtr2->type_ = PERM_INACTIVE; + + int32_t res = PrivacyKit::RegisterPermActiveStatusCallback(callbackPtr1); + res = PrivacyKit::RegisterPermActiveStatusCallback(callbackPtr2); + + static PermissionStateFull infoManagerTestStateA = { + .permissionName = "ohos.permission.CAMERA", + .grantFlags = {1}, + .grantStatus = {PERMISSION_GRANTED}, + .isGeneral = true, + .resDeviceID = {"local"} + }; + static PermissionStateFull infoManagerTestStateB = { + .permissionName = "ohos.permission.GET_BUNDLE_INFO", + .grantFlags = {1}, + .grantStatus = {PERMISSION_GRANTED}, + .isGeneral = true, + .resDeviceID = {"local"} + }; + static HapPolicyParams infoManagerTestPolicyPrams = { + .apl = APL_NORMAL, + .domain = "test.domain", + .permList = {}, + .permStateList = {infoManagerTestStateA, infoManagerTestStateB} + }; + + AccessTokenIDEx tokenIdEx = {0}; + AccessTokenID tokenID; + tokenIdEx = AccessTokenKit::AllocHapToken(g_InfoParmsE, infoManagerTestPolicyPrams); + + tokenID = tokenIdEx.tokenIdExStruct.tokenID; + ASSERT_NE(0, tokenID); + + res = PrivacyKit::StartUsingPermission(tokenID, "ohos.permission.CAMERA"); + ASSERT_EQ(RET_SUCCESS, res); + + ASSERT_EQ(PERM_ACTIVE_IN_FOREGROUND, callbackPtr1->type_); + ASSERT_EQ(PERM_INACTIVE, callbackPtr2->type_); + + res = PrivacyKit::StopUsingPermission(tokenID, "ohos.permission.CAMERA"); + ASSERT_EQ(RET_SUCCESS, res); + ASSERT_EQ(PERM_INACTIVE, callbackPtr1->type_); + + res = PrivacyKit::StartUsingPermission(tokenID, "ohos.permission.GET_BUNDLE_INFO"); + ASSERT_EQ(RET_SUCCESS, res); + ASSERT_EQ(PERM_INACTIVE, callbackPtr1->type_); + ASSERT_EQ(PERM_ACTIVE_IN_FOREGROUND, callbackPtr2->type_); + + res = PrivacyKit::StopUsingPermission(tokenID, "ohos.permission.GET_BUNDLE_INFO"); + ASSERT_EQ(RET_SUCCESS, res); + ASSERT_EQ(PERM_INACTIVE, callbackPtr2->type_); + + res = AccessTokenKit::DeleteToken(tokenID); + ASSERT_EQ(RET_SUCCESS, res); } \ No newline at end of file diff --git a/services/privacymanager/BUILD.gn b/services/privacymanager/BUILD.gn index 5a98012890bd6944f6f56f046038ce0e0e432b02..9ba1d8762912b89a94f49e906e426d268d183e42 100644 --- a/services/privacymanager/BUILD.gn +++ b/services/privacymanager/BUILD.gn @@ -25,6 +25,7 @@ ohos_shared_library("privacy_manager_service") { part_name = "access_token" include_dirs = [ + "include/active", "include/common", "include/database", "include/record", @@ -38,6 +39,9 @@ ohos_shared_library("privacy_manager_service") { ] sources = [ + "src/active/perm_active_status_callback_death_recipient.cpp", + "src/active/perm_active_status_change_callback_manage.cpp", + "src/active/perm_active_status_change_callback_proxy.cpp", "src/common/constant.cpp", "src/common/time_util.cpp", "src/common/to_string.cpp", diff --git a/services/privacymanager/include/active/perm_active_status_callback_death_recipient.h b/services/privacymanager/include/active/perm_active_status_callback_death_recipient.h new file mode 100644 index 0000000000000000000000000000000000000000..48a56a61fca685dad4d79d3458fd7b1745ae2efb --- /dev/null +++ b/services/privacymanager/include/active/perm_active_status_callback_death_recipient.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 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 PERM_ACTIVE_STATUS_CALLBACK_DEATH_RECIPIENT_H +#define PERM_ACTIVE_STATUS_CALLBACK_DEATH_RECIPIENT_H + + +#include "iremote_object.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +class PermActiveCallbackDeathRecipient : public IRemoteObject::DeathRecipient { +public: + PermActiveCallbackDeathRecipient() = default; + virtual ~PermActiveCallbackDeathRecipient() = default; + + virtual void OnRemoteDied(const wptr &remote); +}; +} // namespace AccessToken +} // namespace Security +} // namespace OHOS +#endif // PERM_ACTIVE_STATUS_CALLBACK_DEATH_RECIPIENT_H diff --git a/services/privacymanager/include/active/perm_active_status_change_callback_manage.h b/services/privacymanager/include/active/perm_active_status_change_callback_manage.h new file mode 100755 index 0000000000000000000000000000000000000000..0dd95a85f7884ef547f71e0702a9aabc394c0a4b --- /dev/null +++ b/services/privacymanager/include/active/perm_active_status_change_callback_manage.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 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 PERM_ACTIVE_STATUS_CHANGE_CALLBACK_MANAGE_H +#define PERM_ACTIVE_STATUS_CHANGE_CALLBACK_MANAGE_H + +#include +#include + +#include "access_token.h" +#include "accesstoken_log.h" +#include "perm_active_status_callback_death_recipient.h" +#include "perm_active_status_change_callback_proxy.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { + +struct CallbackData { + CallbackData() : permList_(), callbackObject_(nullptr) + {} + CallbackData(const std::vector& permList, sptr callback) + : permList_(permList), callbackObject_(callback) + {} + + std::vector permList_; + sptr callbackObject_; +}; + +class ActiveStatusCallbackManager { +public: + virtual ~ActiveStatusCallbackManager(); + ActiveStatusCallbackManager(); + static ActiveStatusCallbackManager& GetInstance(); + + int32_t AddCallback( + const std::vector& permList, const sptr& callback); + int32_t RemoveCallback(const sptr& callback); + bool NeedCalled(const std::vector& permList, const std::string& permName); + void ExcuteCallbackAsync( + AccessTokenID tokenID, const std::string& permName, const std::string& deviceId, ActiveChangeType changeType); + +private: + std::mutex mutex_; + std::vector callbackDataList_; + sptr callbackDeathRecipient_; +}; +} // namespace AccessToken +} // namespace Security +} // namespace OHOS +#endif // PERM_ACTIVE_STATUS_CHANGE_CALLBACK_MANAGE_H diff --git a/services/privacymanager/include/active/perm_active_status_change_callback_proxy.h b/services/privacymanager/include/active/perm_active_status_change_callback_proxy.h new file mode 100755 index 0000000000000000000000000000000000000000..61695aac0916cd377629ba100934b565893e85e3 --- /dev/null +++ b/services/privacymanager/include/active/perm_active_status_change_callback_proxy.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 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 PERM_ACTIVE_STATUS_CHANGE_CALLBACK_PROXY_H +#define PERM_ACTIVE_STATUS_CHANGE_CALLBACK_PROXY_H + + +#include "i_perm_active_status_callback.h" + +#include "iremote_proxy.h" +#include "nocopyable.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +class PermActiveStatusChangeCallbackProxy : public IRemoteProxy { +public: + explicit PermActiveStatusChangeCallbackProxy(const sptr& impl); + ~PermActiveStatusChangeCallbackProxy() override; + + virtual void ActiveStatusChangeCallback(ActiveChangeResponse& result) override; +private: + static inline BrokerDelegator delegator_; +}; +} // namespace AccessToken +} // namespace Security +} // namespace OHOS +#endif // PERM_ACTIVE_STATUS_CHANGE_CALLBACK_PROXY_H diff --git a/services/privacymanager/include/record/permission_record_manager.h b/services/privacymanager/include/record/permission_record_manager.h index 727599d119badad5f773cf53de783e45b9cf33d6..bc8b417b278e29f23114e188d2935cdcfeb56921 100644 --- a/services/privacymanager/include/record/permission_record_manager.h +++ b/services/privacymanager/include/record/permission_record_manager.h @@ -46,13 +46,18 @@ public: int32_t GetPermissionUsedRecordsAsync( const PermissionUsedRequest& request, const sptr& callback); std::string DumpRecordInfo(const std::string& bundleName, const std::string& permissionName); + int32_t StartUsingPermission(AccessTokenID tokenID, const std::string& permissionName); + int32_t StopUsingPermission(AccessTokenID tokenID, const std::string& permissionName); + int32_t RegisterPermActiveStatusCallback( + std::vector& permList, const sptr& callback); + int32_t UnRegisterPermActiveStatusCallback(const sptr& callback); + bool GetPermissionVisitor(AccessTokenID tokenID, PermissionVisitor& visitor); private: PermissionRecordManager(); DISALLOW_COPY_AND_MOVE(PermissionRecordManager); bool AddVisitor(AccessTokenID tokenID, int32_t& visitorId); - bool GetPermissionVisitor(AccessTokenID tokenID, PermissionVisitor& visitor); bool AddRecord(int32_t visitorId, const std::string& permissionName, int32_t successCount, int32_t failCount); bool GetPermissionsRecord(int32_t visitorId, const std::string& permissionName, int32_t successCount, int32_t failCount, PermissionRecord& record); diff --git a/services/privacymanager/include/service/privacy_manager_service.h b/services/privacymanager/include/service/privacy_manager_service.h index d2c89b6cedfecd4194ed0e6e61a8b733eea44cdd..116249c7fb4b76e13dea65d9f943ed16bb40d170 100644 --- a/services/privacymanager/include/service/privacy_manager_service.h +++ b/services/privacymanager/include/service/privacy_manager_service.h @@ -46,6 +46,9 @@ public: int32_t GetPermissionUsedRecords( const PermissionUsedRequestParcel& request, const sptr& callback) override; std::string DumpRecordInfo(const std::string& bundleName, const std::string& permissionName) override; + int32_t RegisterPermActiveStatusCallback( + std::vector& permList, const sptr& callback) override; + int32_t UnRegisterPermActiveStatusCallback(const sptr& callback) override; private: bool Initialize() const; diff --git a/services/privacymanager/include/service/privacy_manager_stub.h b/services/privacymanager/include/service/privacy_manager_stub.h index 1a8ce60baef75b5b0ae1ddb8ec81cd936a2d7ced..17f592436b386e52ffd31ebc9528acb30db5edb4 100644 --- a/services/privacymanager/include/service/privacy_manager_stub.h +++ b/services/privacymanager/include/service/privacy_manager_stub.h @@ -39,7 +39,8 @@ private: void GetPermissionUsedRecordsInner(MessageParcel& data, MessageParcel& reply); void GetPermissionUsedRecordsAsyncInner(MessageParcel& data, MessageParcel& reply); void DumpRecordInfoInner(MessageParcel& data, MessageParcel& reply); - + void RegisterPermActiveStatusCallbackInner(MessageParcel& data, MessageParcel& reply); + void UnRegisterPermActiveStatusCallbackInner(MessageParcel& data, MessageParcel& reply); bool IsAccessTokenCalling() const; static const int32_t ACCESSTOKEN_UID = 3020; }; diff --git a/services/privacymanager/src/active/perm_active_status_callback_death_recipient.cpp b/services/privacymanager/src/active/perm_active_status_callback_death_recipient.cpp new file mode 100644 index 0000000000000000000000000000000000000000..773dcc6a52301d8fa521cd471904293ce8a22e51 --- /dev/null +++ b/services/privacymanager/src/active/perm_active_status_callback_death_recipient.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 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 "perm_active_status_callback_death_recipient.h" + +#include "access_token.h" +#include "perm_active_status_change_callback_manage.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +namespace { +static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { + LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "PermActiveCallbackDeathRecipient" +}; +} +void PermActiveCallbackDeathRecipient::OnRemoteDied(const wptr &remote) +{ + ACCESSTOKEN_LOG_INFO(LABEL, "enter"); + if (remote == nullptr) { + ACCESSTOKEN_LOG_ERROR(LABEL, "remote object is nullptr"); + return; + } + + sptr object = remote.promote(); + if (object == nullptr) { + ACCESSTOKEN_LOG_ERROR(LABEL, "object is nullptr"); + return; + } + ActiveStatusCallbackManager::GetInstance().RemoveCallback(object); + ACCESSTOKEN_LOG_ERROR(LABEL, "end"); +} + +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/services/privacymanager/src/active/perm_active_status_change_callback_manage.cpp b/services/privacymanager/src/active/perm_active_status_change_callback_manage.cpp new file mode 100755 index 0000000000000000000000000000000000000000..c8b8734558009c8e6339ac8d300291fc8c4228bc --- /dev/null +++ b/services/privacymanager/src/active/perm_active_status_change_callback_manage.cpp @@ -0,0 +1,149 @@ +/* + * Copyright (c) 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 "perm_active_status_change_callback_manage.h" + +#include +#include +#include + +#include "accesstoken_log.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +namespace { +static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { + LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PermActiveStatusChangeCallbackManage" +}; +const time_t MAX_TIMEOUT_SEC = 30; +} + +ActiveStatusCallbackManager& ActiveStatusCallbackManager::GetInstance() +{ + static ActiveStatusCallbackManager instance; + return instance; +} + +ActiveStatusCallbackManager::ActiveStatusCallbackManager() : + callbackDeathRecipient_(sptr(new (std::nothrow) PermActiveCallbackDeathRecipient())) +{ +} + +ActiveStatusCallbackManager::~ActiveStatusCallbackManager() +{ +} + +int32_t ActiveStatusCallbackManager::AddCallback( + const std::vector& permList, const sptr& callback) +{ + ACCESSTOKEN_LOG_INFO(LABEL, "callback %{public}p ", (IRemoteObject *)callback); + if (callback == nullptr) { + ACCESSTOKEN_LOG_ERROR(LABEL, "input is nullptr"); + return RET_FAILED; + } + + callback->AddDeathRecipient(callbackDeathRecipient_); + + CallbackData recordInstance; + recordInstance.callbackObject_ = callback; + recordInstance.permList_ = permList; + + std::lock_guard lock(mutex_); + callbackDataList_.emplace_back(recordInstance); + + ACCESSTOKEN_LOG_INFO(LABEL, "recordInstance is added"); + return RET_SUCCESS; +} + +int32_t ActiveStatusCallbackManager::RemoveCallback(const sptr& callback) +{ + ACCESSTOKEN_LOG_INFO(LABEL, "called"); + if (callback == nullptr) { + ACCESSTOKEN_LOG_ERROR(LABEL, "callback is nullptr"); + return RET_FAILED; + } + + std::lock_guard lock(mutex_); + + for (auto it = callbackDataList_.begin(); it != callbackDataList_.end(); ++it) { + if (callback == (*it).callbackObject_) { + ACCESSTOKEN_LOG_INFO(LABEL, "find callback"); + if (callbackDeathRecipient_ != nullptr) { + callback->RemoveDeathRecipient(callbackDeathRecipient_); + } + (*it).callbackObject_ = nullptr; + callbackDataList_.erase(it); + break; + } + } + return RET_SUCCESS; +} + +bool ActiveStatusCallbackManager::NeedCalled(const std::vector& permList, const std::string& permName) +{ + if (permList.empty()) { + return true; + } + for (const auto& perm : permList) { + if (perm == permName) { + return true; + } + } + return false; +} + +void ActiveStatusCallbackManager::ExcuteCallbackAsync( + AccessTokenID tokenID, const std::string& permName, const std::string& deviceId, ActiveChangeType changeType) +{ + ACCESSTOKEN_LOG_INFO(LABEL, "entry"); + + auto callbackFunc = [&]() { + ACCESSTOKEN_LOG_INFO(LABEL, "callbackStart"); + std::lock_guard lock(mutex_); + for (auto it = callbackDataList_.begin(); it != callbackDataList_.end(); ++it) { + std::vector permList = (*it).permList_; + if (!NeedCalled(permList, permName)) { + ACCESSTOKEN_LOG_INFO(LABEL, "tokenID is %{public}u, permName is %{public}s", tokenID, permName.c_str()); + continue; + } + auto callback = iface_cast((*it).callbackObject_); + if (callback != nullptr) { + ActiveChangeResponse resInfo; + resInfo.type = changeType; + resInfo.permissionName = permName; + resInfo.tokenID = tokenID; + resInfo.deviceId = deviceId; + ACCESSTOKEN_LOG_INFO(LABEL, "callback excute changeType %{public}d", changeType); + callback->ActiveStatusChangeCallback(resInfo); + } + } + }; + + std::packaged_task callbackTask(callbackFunc); + std::future fut = callbackTask.get_future(); + std::make_unique(std::move(callbackTask))->detach(); + + ACCESSTOKEN_LOG_INFO(LABEL, "Waiting for the callback execution complete..."); + std::future_status status = fut.wait_for(std::chrono::seconds(MAX_TIMEOUT_SEC)); + if (status == std::future_status::timeout) { + ACCESSTOKEN_LOG_WARN(LABEL, "callbackTask callback execution timeout"); + } + ACCESSTOKEN_LOG_INFO(LABEL, "The callback execution is complete"); + +} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/services/privacymanager/src/active/perm_active_status_change_callback_proxy.cpp b/services/privacymanager/src/active/perm_active_status_change_callback_proxy.cpp new file mode 100755 index 0000000000000000000000000000000000000000..eac34f1b623951ecd561160c7f9c35f702dc7d0f --- /dev/null +++ b/services/privacymanager/src/active/perm_active_status_change_callback_proxy.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 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 "perm_active_status_change_callback_proxy.h" + +#include "accesstoken_log.h" +#include "perm_active_response_parcel.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +namespace { +static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { + LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PermActiveStatusChangeCallbackProxy" +}; +} + +PermActiveStatusChangeCallbackProxy::PermActiveStatusChangeCallbackProxy(const sptr& impl) + : IRemoteProxy(impl) { +} + +PermActiveStatusChangeCallbackProxy::~PermActiveStatusChangeCallbackProxy() +{} + +void PermActiveStatusChangeCallbackProxy::ActiveStatusChangeCallback(ActiveChangeResponse& result) +{ + MessageParcel data; + data.WriteInterfaceToken(IPermActiveStatusChangeCbk::GetDescriptor()); + + ActiveChangeResponseParcel resultParcel; + resultParcel.changeResponse = result; + if (!data.WriteParcelable(&resultParcel)) { + ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteParcelable"); + return; + } + + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + sptr remote = Remote(); + if (remote == nullptr) { + ACCESSTOKEN_LOG_ERROR(LABEL, "remote service null."); + return; + } + int32_t requestResult = remote->SendRequest( + static_cast(IPermActiveStatusChangeCbk::PERM_ACTIVE_STATUS_CHANGE), data, reply, option); + if (requestResult != NO_ERROR) { + ACCESSTOKEN_LOG_ERROR(LABEL, "send request fail, result: %{public}d", requestResult); + return; + } + + ACCESSTOKEN_LOG_INFO(LABEL, "SendRequest success"); +} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/services/privacymanager/src/record/permission_record_manager.cpp b/services/privacymanager/src/record/permission_record_manager.cpp index 024790c7d1f230b01a13fe4c1ca016359d66253c..cba2f296c49a72afd93791700fb0b86674369b1e 100644 --- a/services/privacymanager/src/record/permission_record_manager.cpp +++ b/services/privacymanager/src/record/permission_record_manager.cpp @@ -23,6 +23,7 @@ #include "field_const.h" #include "permission_record_repository.h" #include "permission_visitor_repository.h" +#include "perm_active_status_change_callback_manage.h" #include "time_util.h" #include "to_string.h" @@ -422,6 +423,82 @@ std::string PermissionRecordManager::DumpRecordInfo(const std::string& bundleNam return dumpInfo; } +static void RegisterFrontAndBackGroundlistener() +{ + // 给注册前后台监听打桩 + // 此处需要实现一个callback函数用于被注册 +} + +static void UnRegisterFrontAndBackGroundlistener() +{ + +} + +// 被注册的函数 +int32_t FrontAndBackGroundlistener( + AccessTokenID tokenID, const std::string& permissionName, int32_t statusType) +{ + PermissionVisitor visitor; + bool res = PermissionRecordManager::GetInstance().GetPermissionVisitor(tokenID, visitor); + if (!res) { + return Constant::FAILURE; + } + ActiveStatusCallbackManager::GetInstance().ExcuteCallbackAsync( + tokenID, permissionName, visitor.deviceId, static_cast(statusType)); + return Constant::SUCCESS; +} + +int32_t PermissionRecordManager::StartUsingPermission(AccessTokenID tokenID, const std::string& permissionName) +{ + // 记录开始使用 + + // 此处是否结合全局变量的使用来判断是否开始记录 + + // 注册前后台监听 + RegisterFrontAndBackGroundlistener(); + + // 触发给systemUi当前的权限在前台使用 + PermissionVisitor visitor; + bool res = GetPermissionVisitor(tokenID, visitor); + if (!res) { + return Constant::FAILURE; + } + + ActiveStatusCallbackManager::GetInstance().ExcuteCallbackAsync( + tokenID, permissionName, visitor.deviceId, PERM_ACTIVE_IN_FOREGROUND); + return Constant::SUCCESS; +} + +int32_t PermissionRecordManager::StopUsingPermission(AccessTokenID tokenID, const std::string& permissionName) +{ + // 记录结束使用 + + // 注册前后台监听 + UnRegisterFrontAndBackGroundlistener(); + + // 触发给systemUi当前的权限在前台使用 + PermissionVisitor visitor; + bool res = GetPermissionVisitor(tokenID, visitor); + if (!res) { + return Constant::FAILURE; + } + + ActiveStatusCallbackManager::GetInstance().ExcuteCallbackAsync( + tokenID, permissionName, visitor.deviceId, PERM_INACTIVE); + return Constant::SUCCESS; +} + +int32_t PermissionRecordManager::RegisterPermActiveStatusCallback( + std::vector& permList, const sptr& callback) +{ + return ActiveStatusCallbackManager::GetInstance().AddCallback(permList, callback); +} + +int32_t PermissionRecordManager::UnRegisterPermActiveStatusCallback(const sptr& callback) +{ + return ActiveStatusCallbackManager::GetInstance().RemoveCallback(callback); +} + bool PermissionRecordManager::IsLocalDevice(const std::string& deviceId) { if (deviceId == "0") { // local diff --git a/services/privacymanager/src/service/privacy_manager_service.cpp b/services/privacymanager/src/service/privacy_manager_service.cpp index 1f9cecd49093288fff571c590dc68b9b9acf3184..92e690931b13fa823fba36d359ba1453e58ae60c 100644 --- a/services/privacymanager/src/service/privacy_manager_service.cpp +++ b/services/privacymanager/src/service/privacy_manager_service.cpp @@ -83,14 +83,14 @@ int32_t PrivacyManagerService::StartUsingPermission(AccessTokenID tokenID, const { ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry, tokenID: 0x%{public}x, permission: %{public}s", tokenID, permissionName.c_str()); - return Constant::SUCCESS; + return PermissionRecordManager::GetInstance().StartUsingPermission(tokenID, permissionName); } int32_t PrivacyManagerService::StopUsingPermission(AccessTokenID tokenID, const std::string& permissionName) { ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry, tokenID: 0x%{public}x, permission: %{public}s", tokenID, permissionName.c_str()); - return Constant::SUCCESS; + return PermissionRecordManager::GetInstance().StopUsingPermission(tokenID, permissionName); } int32_t PrivacyManagerService::RemovePermissionUsedRecords(AccessTokenID tokenID, const std::string& deviceID) @@ -125,6 +125,17 @@ std::string PrivacyManagerService::DumpRecordInfo(const std::string& bundleName, return PermissionRecordManager::GetInstance().DumpRecordInfo(bundleName, permissionName); } +int32_t PrivacyManagerService::RegisterPermActiveStatusCallback( + std::vector& permList, const sptr& callback) +{ + return PermissionRecordManager::GetInstance().RegisterPermActiveStatusCallback(permList, callback); +} + +int32_t PrivacyManagerService::UnRegisterPermActiveStatusCallback(const sptr& callback) +{ + return PermissionRecordManager::GetInstance().UnRegisterPermActiveStatusCallback(callback); +} + bool PrivacyManagerService::Initialize() const { PermissionRecordManager::GetInstance().Init(); diff --git a/services/privacymanager/src/service/privacy_manager_stub.cpp b/services/privacymanager/src/service/privacy_manager_stub.cpp index bd1dd4fe72a035c93122eca81bc5d2435cfe3b14..37c1ded5c8037572e7fde64fa34e301bb9afbed0 100644 --- a/services/privacymanager/src/service/privacy_manager_stub.cpp +++ b/services/privacymanager/src/service/privacy_manager_stub.cpp @@ -60,6 +60,12 @@ int32_t PrivacyManagerStub::OnRemoteRequest( case static_cast(IPrivacyManager::InterfaceCode::DUMP_RECORD_INFO): DumpRecordInfoInner(data, reply); break; + case static_cast(IPrivacyManager::InterfaceCode::REGISTER_PERM_ACTIVE_STATUS_CHANGE_CALLBACK): + RegisterPermActiveStatusCallbackInner(data, reply); + break; + case static_cast(IPrivacyManager::InterfaceCode::UNREGISTER_PERM_ACTIVE_STATUS_CHANGE_CALLBACK): + UnRegisterPermActiveStatusCallbackInner(data, reply); + break; default: return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } @@ -158,6 +164,43 @@ void PrivacyManagerStub::DumpRecordInfoInner(MessageParcel& data, MessageParcel& reply.WriteString(dumpInfo); } +void PrivacyManagerStub::RegisterPermActiveStatusCallbackInner(MessageParcel& data, MessageParcel& reply) +{ + uint32_t permListSize = data.ReadUint32(); + if (permListSize > 200) { + ACCESSTOKEN_LOG_ERROR(LABEL, "read permListSize fail"); + reply.WriteInt32(RET_FAILED); + return; + } + std::vector permList; + for (uint32_t i = 0; i < permListSize; i++) { + std::string perm = data.ReadString(); + permList.emplace_back(perm); + } + sptr callback = data.ReadRemoteObject(); + if (callback == nullptr) { + ACCESSTOKEN_LOG_ERROR(LABEL, "read ReadRemoteObject fail"); + reply.WriteInt32(RET_FAILED); + return; + } + ACCESSTOKEN_LOG_INFO(LABEL, "callback %{public}p ", (IRemoteObject *)callback); + int32_t result = this->RegisterPermActiveStatusCallback(permList, callback); + reply.WriteInt32(result); +} + +void PrivacyManagerStub::UnRegisterPermActiveStatusCallbackInner(MessageParcel& data, MessageParcel& reply) +{ + sptr callback = data.ReadRemoteObject(); + if (callback == nullptr) { + ACCESSTOKEN_LOG_ERROR(LABEL, "read scopeParcel fail"); + reply.WriteInt32(RET_FAILED); + return; + } + ACCESSTOKEN_LOG_INFO(LABEL, "callback %{public}p ", (IRemoteObject *)callback); + int32_t result = this->UnRegisterPermActiveStatusCallback(callback); + reply.WriteInt32(result); +} + bool PrivacyManagerStub::IsAccessTokenCalling() const { int32_t callingUid = IPCSkeleton::GetCallingUid();