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 0000000000000000000000000000000000000000..05733d8510b412d9189983561b20f1e26e3e790c --- /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 0000000000000000000000000000000000000000..159df7db29eb12a2b3e425f131ca944bbe8c8577 --- /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 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 7d0086efbb6f6bde656e59d58858e05602d2ac90..c2e13cb184c18618f8a04d1a48918ee4895937ec 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 1f3e1ea26b830db8b011fa49bdeec7f97bb9dba5..b8845e58e7628c0abfc342a9968e2a5e9928df98 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)