From 9c8c435ef9000897a0ff1f42a76d60d5d72120ec Mon Sep 17 00:00:00 2001 From: lsq Date: Fri, 22 Jul 2022 16:15:12 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lsq Change-Id: Ia945d60fab37359d746d87571b4ffca2beeace7b --- .../soft_bus_device_connection_listener.h | 4 ++ .../soft_bus_device_connection_listener.cpp | 60 ++++++++++--------- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/services/tokensyncmanager/include/remote/soft_bus_device_connection_listener.h b/services/tokensyncmanager/include/remote/soft_bus_device_connection_listener.h index 7d0086efb..c2e13cb18 100644 --- a/services/tokensyncmanager/include/remote/soft_bus_device_connection_listener.h +++ b/services/tokensyncmanager/include/remote/soft_bus_device_connection_listener.h @@ -18,6 +18,7 @@ #include #include +#include #include #include "accesstoken_log.h" @@ -64,6 +65,9 @@ public: * @param deviceInfo node info */ void OnDeviceChanged(const DistributedHardware::DmDeviceInfo &deviceInfo) override; + +private: + std::mutex exitMutex_; }; } // namespace AccessToken } // namespace Security diff --git a/services/tokensyncmanager/src/remote/soft_bus_device_connection_listener.cpp b/services/tokensyncmanager/src/remote/soft_bus_device_connection_listener.cpp index 1f3e1ea26..b8845e58e 100644 --- a/services/tokensyncmanager/src/remote/soft_bus_device_connection_listener.cpp +++ b/services/tokensyncmanager/src/remote/soft_bus_device_connection_listener.cpp @@ -14,6 +14,9 @@ */ #include "soft_bus_device_connection_listener.h" + +#include + #include "remote_command_manager.h" #include "soft_bus_manager.h" #include "device_info_manager.h" @@ -21,6 +24,8 @@ #include "constant_common.h" #include "device_manager.h" #include "dm_device_info.h" +#include "token_sync_event_handler.h" +#include "token_sync_manager_service.h" namespace OHOS { namespace Security { @@ -73,36 +78,37 @@ void SoftBusDeviceConnectionListener::OnDeviceOffline(const DmDeviceInfo &info) std::string uuid = DeviceInfoManager::GetInstance().ConvertToUniversallyUniqueIdOrFetch(networkId); std::string udid = DeviceInfoManager::GetInstance().ConvertToUniqueDeviceIdOrFetch(networkId); - ACCESSTOKEN_LOG_INFO(LABEL, - "networkId: %{public}s, uuid: %{public}s, udid: %{public}s", - networkId.c_str(), - uuid.c_str(), - ConstantCommon::EncryptDevId(udid).c_str()); + ACCESSTOKEN_LOG_INFO(LABEL, "networkId: %{public}s, uuid: %{public}s, udid: %{public}s", networkId.c_str(), + uuid.c_str(), ConstantCommon::EncryptDevId(udid).c_str()); - if (uuid != "" && udid != "") { - RemoteCommandManager::GetInstance().NotifyDeviceOffline(uuid); - RemoteCommandManager::GetInstance().NotifyDeviceOffline(udid); - DeviceInfoManager::GetInstance().RemoveRemoteDeviceInfo(networkId, DeviceIdType::NETWORK_ID); - - std::string packageName = ACCESSTOKEN_PACKAGE_NAME; - std::string extra = ""; - std::vector deviceList; - - int32_t ret = DistributedHardware::DeviceManager::GetInstance().GetTrustedDeviceList(packageName, - extra, deviceList); - if (ret != Constant::SUCCESS) { - ACCESSTOKEN_LOG_ERROR(LABEL, "GetTrustedDeviceList error, result: %{public}d", ret); - return; - } - - if (deviceList.empty()) { - ACCESSTOKEN_LOG_INFO(LABEL, "there is no remote decice online, exit tokensync process"); - - exit(0); - } - } else { + if (uuid == "" || udid == "") { ACCESSTOKEN_LOG_ERROR(LABEL, "uuid or udid is empty, offline failed."); + return; + } + + RemoteCommandManager::GetInstance().NotifyDeviceOffline(uuid); + RemoteCommandManager::GetInstance().NotifyDeviceOffline(udid); + DeviceInfoManager::GetInstance().RemoveRemoteDeviceInfo(networkId, DeviceIdType::NETWORK_ID); + std::vector deviceList; + std::string packageName = ACCESSTOKEN_PACKAGE_NAME; + std::string extra = ""; + + int32_t ret = DistributedHardware::DeviceManager::GetInstance().GetTrustedDeviceList(packageName, + extra, deviceList); + if (ret != Constant::SUCCESS) { + ACCESSTOKEN_LOG_ERROR(LABEL, "GetTrustedDeviceList error, result: %{public}d", ret); + return; + } + if (!deviceList.empty()) { + return; + } + std::shared_ptr handler = + DelayedSingleton::GetInstance()->GetSendEventHandler(); + while ((handler != nullptr) && (!handler->IsIdle())) { + ACCESSTOKEN_LOG_INFO(LABEL, "handler->IsIdle is false."); + usleep(10); } + exit(0); } void SoftBusDeviceConnectionListener::OnDeviceReady(const DmDeviceInfo &info) -- Gitee From c1757775de2d8f4701b5093ab780327d4f240728 Mon Sep 17 00:00:00 2001 From: lsq Date: Tue, 26 Jul 2022 22:23:11 +0800 Subject: [PATCH 2/2] Signed-off-by: lsq Change-Id: I14600c3dff2b8eb47fe3fd538868fcb551e7f5c1 --- .../permission_state_change_scope_parcel.cpp | 63 +++++++++++++++++++ .../include/permission_state_change_info.h | 44 +++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 frameworks/accesstoken/src/permission_state_change_scope_parcel.cpp create mode 100644 interfaces/innerkits/accesstoken/include/permission_state_change_info.h diff --git a/frameworks/accesstoken/src/permission_state_change_scope_parcel.cpp b/frameworks/accesstoken/src/permission_state_change_scope_parcel.cpp new file mode 100644 index 000000000..05733d851 --- /dev/null +++ b/frameworks/accesstoken/src/permission_state_change_scope_parcel.cpp @@ -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. + */ + +#include "permission_state_change_scope_parcel.h" +#include "parcel_utils.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +bool PermStateChangeScopeParcel::Marshalling(Parcel& out) const +{ + RETURN_IF_FALSE(out.WriteUint32((this->scope.tokenIDs.size()))); + for (auto& tokenID : this->scope.tokenIDs) { + RETURN_IF_FALSE(out.WriteUint32(tokenID)); + } + + RETURN_IF_FALSE(out.WriteUint32((this->scope.permList.size()))); + for (const auto& permissionName : this->scope.permList) { + RETURN_IF_FALSE(out.WriteString(permissionName)); + } + return true; +} + +PermStateChangeScopeParcel* PermStateChangeScopeParcel::Unmarshalling(Parcel& in) +{ + auto* permStateChangeScopeParcel = new (std::nothrow) PermStateChangeScopeParcel(); + if (permStateChangeScopeParcel == nullptr) { + return nullptr; + } + uint32_t tokenIdListSize = 0; + RELEASE_IF_FALSE(in.ReadUint32(tokenIdListSize), permStateChangeScopeParcel); + RELEASE_IF_FALSE(tokenIdListSize <= MAX_TOKENID_LIST_SIZE, permStateChangeScopeParcel); + for (uint32_t i = 0; i < tokenIdListSize; i++) { + AccessTokenID tokenID; + RELEASE_IF_FALSE(in.ReadUint32(tokenID), permStateChangeScopeParcel); + permStateChangeScopeParcel->scope.tokenIDs.emplace_back(tokenID); + } + + uint32_t permListSize = 0; + RELEASE_IF_FALSE(in.ReadUint32(permListSize), permStateChangeScopeParcel); + RELEASE_IF_FALSE(permListSize <= MAX_PERM_LIST_SIZE, permStateChangeScopeParcel); + for (uint32_t i = 0; i < permListSize; i++) { + std::string permName; + RELEASE_IF_FALSE(in.ReadString(permName), permStateChangeScopeParcel); + permStateChangeScopeParcel->scope.permList.emplace_back(permName); + } + return permStateChangeScopeParcel; +} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/interfaces/innerkits/accesstoken/include/permission_state_change_info.h b/interfaces/innerkits/accesstoken/include/permission_state_change_info.h new file mode 100644 index 000000000..159df7db2 --- /dev/null +++ b/interfaces/innerkits/accesstoken/include/permission_state_change_info.h @@ -0,0 +1,44 @@ +/* + * 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 INTERFACES_INNER_KITS_PERMISSION_STATE_CHANGE_INFO_H +#define INTERFACES_INNER_KITS_PERMISSION_STATE_CHANGE_INFO_H + +#include +#include + +#include "access_token.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +#define MAX_TOKENID_LIST_SIZE 1024 +#define MAX_PERM_LIST_SIZE 1024 + +struct PermStateChangeInfo { + int32_t PermStateChangeType; + AccessTokenID tokenID; + std::string permissionName; +}; + +struct PermStateChangeScope { + std::vector tokenIDs; + std::vector permList; +}; +} // namespace AccessToken +} // namespace Security +} // namespace OHOS + +#endif // INTERFACES_INNER_KITS_PERMISSION_STATE_CHANGE_INFO_H -- Gitee