diff --git a/common/include/device_manager_ipc_interface_code.h b/common/include/device_manager_ipc_interface_code.h index 418684851ef4e18d1ffd2b47eeff7818525a521e..1461de6a0abdff87ffec69db9c04ecf838a388fb 100644 --- a/common/include/device_manager_ipc_interface_code.h +++ b/common/include/device_manager_ipc_interface_code.h @@ -94,8 +94,8 @@ enum DMIpcCmdInterfaceCode { GET_DEVICE_SCREEN_STATUS, GET_NETWORKID_BY_UDID, SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, - SINK_BIND_TARGET_RESULT, SYNC_CALLBACK, + SINK_BIND_TARGET_RESULT, GET_ANONY_LOCAL_UDID, REG_AUTHENTICATION_TYPE, GET_DEVICE_PROFILE_INFO_LIST, @@ -109,12 +109,12 @@ enum DMIpcCmdInterfaceCode { SET_LOCAL_DEVICE_NAME, SET_LOCAL_DEVICE_NAME_RESULT, GET_ALL_TRUST_DEVICE_LIST, + GET_DEVICE_NETWORK_ID_LIST, + RESTORE_LOCAL_DEVICE_NAME, REG_LOCALSERVICE_INFO, UNREG_LOCALSERVICE_INFO, UPDATE_LOCALSERVICE_INFO, GET_SERVICEINFO_BYBUNDLENAME_PINEXCHANGETYPE, - RESTORE_LOCAL_DEVICE_NAME, - GET_DEVICE_NETWORK_ID_LIST, UNREGISTER_PIN_HOLDER_CALLBACK, GET_LOCAL_DEVICE_NAME, GET_LOCAL_DEVICE_NAME_OLD, diff --git a/common/include/dm_error_type.h b/common/include/dm_error_type.h index 753c754f23597329907bfd04f835913e3d8dc16c..0bca1de1bbf53d8f18f418ade87cc96e8c8fb410 100644 --- a/common/include/dm_error_type.h +++ b/common/include/dm_error_type.h @@ -144,6 +144,7 @@ enum { ERR_DM_DEVICE_FROZEN = 969298355, ERR_DM_SOCKET_IN_USED = 969298356, ERR_DM_ANTI_DISTURB_MODE = 969298357, + ERR_DM_SKIP_AUTHENTICATE = 969298358, }; } // namespace DistributedHardware } // namespace OHOS diff --git a/common/include/ipc/standard/ipc_model_codec.h b/common/include/ipc/standard/ipc_model_codec.h index e06af83a94477da5100f2039832ccb033d070f7d..e2d5bd353d2e063c2c502e96bc17eca30a6f65d5 100644 --- a/common/include/ipc/standard/ipc_model_codec.h +++ b/common/include/ipc/standard/ipc_model_codec.h @@ -48,14 +48,14 @@ public: static bool EncodeDmDeviceIconInfoFilterOptions(const DmDeviceIconInfoFilterOptions &filterOptions, MessageParcel &parcel); static void DecodeDmDeviceInfo(MessageParcel &parcel, DmDeviceInfo &devInfo); - static bool EncodeLocalServiceInfo(const DMLocalServiceInfo &serviceInfo, MessageParcel &parcel); - static bool EncodeLocalServiceInfos(const std::vector &serviceInfos, MessageParcel &parcel); - static bool DecodeLocalServiceInfo(MessageParcel &parcel, DMLocalServiceInfo &serviceInfo); - static bool DecodeLocalServiceInfos(MessageParcel &parcel, std::vector &serviceInfos); static bool EncodeNetworkIdQueryFilter(const NetworkIdQueryFilter &queryFilter, MessageParcel &parcel); static bool DecodeNetworkIdQueryFilter(MessageParcel &parcel, NetworkIdQueryFilter &queryFilter); static bool EncodeStringVector(const std::vector &vec, MessageParcel &parcel); static bool DecodeStringVector(MessageParcel &parcel, std::vector &vec); + static bool EncodeLocalServiceInfo(const DMLocalServiceInfo &serviceInfo, MessageParcel &parcel); + static bool EncodeLocalServiceInfos(const std::vector &serviceInfos, MessageParcel &parcel); + static bool DecodeLocalServiceInfo(MessageParcel &parcel, DMLocalServiceInfo &serviceInfo); + static bool DecodeLocalServiceInfos(MessageParcel &parcel, std::vector &serviceInfos); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/common/include/show_confirm_dialog/dialog_ui/js/BUILD.gn b/common/include/show_confirm_dialog/dialog_ui/js/BUILD.gn index 4c6953fc4447e324359368c2b4821bf953367087..7ce4ea8bbcaae1c1df0b9ae44e619c27664f6546 100644 --- a/common/include/show_confirm_dialog/dialog_ui/js/BUILD.gn +++ b/common/include/show_confirm_dialog/dialog_ui/js/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 -2024 Huawei Device Co., Ltd. +# Copyright (c) 2022 -2023 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 diff --git a/common/src/dm_anonymous.cpp b/common/src/dm_anonymous.cpp index 43a0ecfed58b75fd2d1ae7fbe42ed2c032afe5d0..d9a4eef831a8a00525f0ec3d914ba7a592d11e1b 100644 --- a/common/src/dm_anonymous.cpp +++ b/common/src/dm_anonymous.cpp @@ -438,21 +438,23 @@ bool IsJsonValIntegerString(const JsonItemObject &jsonObj, const std::string &ke std::string GetAnonyJsonString(const std::string &value) { if (value.empty()) { + LOGE("Str is empty."); return ""; } JsonObject paramJson(value); if (paramJson.IsDiscarded()) { + LOGE("Str is not json string."); return ""; } const std::set sensitiveKey = { "LOCALDEVICEID", "localAccountId", "networkId", "lnnPublicKey", "transmitPublicKey", "DEVICEID", "deviceId", "keyValue", "deviceName", "REMOTE_DEVICE_NAME", "data" }; - - for (auto &element : paramJson.Items()) { + std::vector paramJsonVec = paramJson.Items(); + for (auto &element : paramJsonVec) { if (element.IsString() && sensitiveKey.find(element.Key()) != sensitiveKey.end()) { paramJson[element.Key()] = GetAnonyString(element.Get()); } } - return paramJson.Dump(); + return paramJson.DumpFormated(); } int64_t GetCurrentTimestamp() diff --git a/common/src/dm_constants.cpp b/common/src/dm_constants.cpp index 73ed7a13ca8ec73532b3cacbdf1ef36d8955ddaf..43ca3ec02efbcacefbdfaf6ffa584f15ca31ef32 100644 --- a/common/src/dm_constants.cpp +++ b/common/src/dm_constants.cpp @@ -145,7 +145,6 @@ const char* PARAM_CLOSE_SESSION_DELAY_SECONDS = "DM_CLOSE_SESSION_DELAY_SECONDS" const char* DM_AUTHENTICATION_TYPE = "DM_AUTHENTICATION_TYPE"; const char* PARAM_KEY_CONN_SESSIONTYPE = "connSessionType"; -const char* PARAM_KEY_HML_RELEASETIME = "hmlReleaseTime"; const char* PARAM_KEY_HML_ENABLE_160M = "hmlEnable160M"; const char* PARAM_KEY_HML_ACTIONID = "hmlActionId"; diff --git a/common/src/ipc/standard/ipc_model_codec.cpp b/common/src/ipc/standard/ipc_model_codec.cpp index bd0573e02cefa199a1faca8163f529a730159b8c..b8ab7d884d24d17149ff657a9f6b7badbf77281e 100644 --- a/common/src/ipc/standard/ipc_model_codec.cpp +++ b/common/src/ipc/standard/ipc_model_codec.cpp @@ -23,7 +23,7 @@ namespace DistributedHardware { namespace { constexpr const char* UK_SEPARATOR = "#"; constexpr int32_t MAX_ICON_SIZE = 4 * 1024 * 1024; -constexpr uint32_t IPC_VECTOR_MAX_SIZE = 1000; +constexpr uint32_t IPC_VECTOR_MAX_SIZE = 1000; } #define READ_HELPER_RET(parcel, type, out, failRet) \ @@ -35,7 +35,7 @@ constexpr uint32_t IPC_VECTOR_MAX_SIZE = 1000; } \ } while (0) - #define CHECK_CPY_SIZE_RETURN(destSize, srcSize) \ +#define CHECK_CPY_SIZE_RETURN(destSize, srcSize) \ do { \ if ((destSize) <= (srcSize)) { \ LOGE("params size invalid"); \ diff --git a/commondependency/BUILD.gn b/commondependency/BUILD.gn index db0d575ddf1a628205d04c6b321db99f80f3fac6..fe7d549456bbdb4224eb3c32870b69e28df36278 100644 --- a/commondependency/BUILD.gn +++ b/commondependency/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023-2024 Huawei Device Co., Ltd. +# Copyright (c) 2023 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 @@ -55,6 +55,7 @@ ohos_shared_library("devicemanagerdependency") { "include", "${common_path}/include", "${innerkits_path}/native_cpp/include", + "${utils_path}/include/appInfo", "${servicesimpl_path}/include/cryptomgr", "${utils_path}/include/crypto", ] @@ -126,6 +127,7 @@ ohos_shared_library("devicemanagerdependencytest") { "include", "${common_path}/include", "${innerkits_path}/native_cpp/include", + "${utils_path}/include/appInfo", "${servicesimpl_path}/include/cryptomgr", "${utils_path}/include/crypto", ] @@ -168,4 +170,4 @@ ohos_shared_library("devicemanagerdependencytest") { subsystem_name = "distributedhardware" part_name = "device_manager" -} +} \ No newline at end of file diff --git a/display/entry/src/main/ets/pages/ConfirmDialog.ets b/display/entry/src/main/ets/pages/ConfirmDialog.ets index 19f1a102c8b717da714abaa05a5d2742e93d2221..ef97c0b6a60c2d3961a9ac2596c879f97bc32ab5 100644 --- a/display/entry/src/main/ets/pages/ConfirmDialog.ets +++ b/display/entry/src/main/ets/pages/ConfirmDialog.ets @@ -234,7 +234,6 @@ struct ConfirmCustomDialog { }; const jsonStr = JSON.stringify(param); console.log('allow once' + ACTION_ALLOW_AUTH_ONCE) - console.log('param:' + jsonStr) this.setUserAuthorization(ACTION_ALLOW_AUTH_ONCE, jsonStr) this.destruction() } @@ -250,7 +249,6 @@ struct ConfirmCustomDialog { }; const jsonStr = JSON.stringify(param); console.log('allow always' + ACTION_ALLOW_AUTH_ALWAYS) - console.log('param:' + jsonStr) this.setUserAuthorization(ACTION_ALLOW_AUTH_ALWAYS, jsonStr) this.destruction() } diff --git a/display/entry/src/main/ets/pages/ConfirmDialogTv.ets b/display/entry/src/main/ets/pages/ConfirmDialogTv.ets index 49f3ce1e40e23585ac551311794d6886cc2ff004..828314d573ac149cd703d0a91d2beece606780d8 100644 --- a/display/entry/src/main/ets/pages/ConfirmDialogTv.ets +++ b/display/entry/src/main/ets/pages/ConfirmDialogTv.ets @@ -49,7 +49,7 @@ struct ConfirmCustomDialog { @State isAvailableType: boolean = false; @State btnColor: ResourceColor = Color.Transparent; @State title: string = ''; - @State mLocalWidth: number = 0; + @State mLocalWidth: number = 1; controller?: CustomDialogController; isPC: boolean = false; aboutToAppear() { @@ -59,7 +59,7 @@ struct ConfirmCustomDialog { this.mLocalWidth = display.getDefaultDisplaySync().width; } catch (err) { console.error('Failed to get display width:', err); - this.mLocalWidth = 0; + this.mLocalWidth = 1; } let context = getContext() as common.UIAbilityContext; diff --git a/display/entry/src/main/ets/pages/InputPinDialog.ets b/display/entry/src/main/ets/pages/InputPinDialog.ets index 1c6949c5708927f330bb2f05903c660a324a9857..67d95038d9b73e4a88a6d9217b7d08e06345a93e 100644 --- a/display/entry/src/main/ets/pages/InputPinDialog.ets +++ b/display/entry/src/main/ets/pages/InputPinDialog.ets @@ -46,7 +46,7 @@ struct InputCustomDialog { @State isPC: boolean = false; @State isPhone: boolean = false; @State btnColor: ResourceColor = Color.Transparent; - @State mLocalHeight: number = 0; + @State mLocalHeight: number = 1; listener: mediaquery.MediaQueryListener = mediaquery.matchMediaSync('(orientation: landscape)'); controller?: CustomDialogController; private scroller: Scroller = new Scroller(); @@ -56,7 +56,7 @@ struct InputCustomDialog { this.mLocalHeight = display.getDefaultDisplaySync().height; } catch (e) { console.error('Failed to get display height:', e); - this.mLocalHeight = 0; + this.mLocalHeight = 1; } let heightRatio = px2vp(this.mLocalHeight) * 0.2; @@ -99,7 +99,7 @@ struct InputCustomDialog { this.mLocalHeight = display.getDefaultDisplaySync().height; } catch (err) { console.error('Failed to get display height:', err); - this.mLocalHeight = 0; + this.mLocalHeight = 1; } this.isPC = Constant.isPC(); this.isPhone = Constant.isPhone(); diff --git a/display/entry/src/main/ets/pages/PinDialogTv.ets b/display/entry/src/main/ets/pages/PinDialogTv.ets index 4d93d460bea2fc4bb7eff82769839dfc0df9291e..dc671b93ab37be2f8b6628a5c0b1fa250e894e39 100644 --- a/display/entry/src/main/ets/pages/PinDialogTv.ets +++ b/display/entry/src/main/ets/pages/PinDialogTv.ets @@ -35,7 +35,7 @@ struct PinCustomDialog { @State pinCodeArr: Array = []; @State btnColor: ResourceColor = Color.Transparent; @State isPC: boolean = false; - @State mLocalWidth: number = 0; + @State mLocalWidth: number = 1; controller?: CustomDialogController cancel() { @@ -57,7 +57,7 @@ struct PinCustomDialog { this.mLocalWidth = display.getDefaultDisplaySync().width; } catch (err) { console.error('Failed to get display width:', err); - this.mLocalWidth = 0; + this.mLocalWidth = 1; } this.isPC = Constant.isPC(); this.pinCode = AppStorage.get('pinCode') as string; diff --git a/display/entry/src/main/resources/en_GB/element/string.json b/display/entry/src/main/resources/en_GB/element/string.json index baa3bb587bcc7e373feb47d6a518b9ae3d6c3785..4a8c6fe8df8892d91e22df19bf6f7bfbb998bc94 100644 --- a/display/entry/src/main/resources/en_GB/element/string.json +++ b/display/entry/src/main/resources/en_GB/element/string.json @@ -58,7 +58,7 @@ }, { "name":"dm_confirm_proxy", - "value":"%s requests to connect to this device. Please select the authorized service:", + "value":"%s would like to connect to this device. Please select which services it can access:", "attr":{ "priority":"translate" } diff --git a/ext/pin_auth/BUILD.gn b/ext/pin_auth/BUILD.gn index 728a937de9a01697abb9bd2695007fe80fa0a837..bf7555a2035a6e0bce3045f75c8bcd3f0ab7df6b 100644 --- a/ext/pin_auth/BUILD.gn +++ b/ext/pin_auth/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2024 Huawei Device Co., Ltd. +# Copyright (c) 2022-2023 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 @@ -82,6 +82,7 @@ ohos_shared_library("devicemanagerext_pin_auth") { "ability_base:session_info", "ability_base:want", "ability_runtime:ability_manager", + "cJSON:cjson", "c_utils:utils", "device_auth:deviceauth_sdk", "device_info_manager:distributed_device_profile_common", diff --git a/ext/pin_auth/src/ability/standard/dm_ability_manager.cpp b/ext/pin_auth/src/ability/standard/dm_ability_manager.cpp index 299e1148fc0449dd5bbd8f4163b0d531f1a445b2..b85e33d85d65fabe61ff383639c1cf65413bf1ff 100644 --- a/ext/pin_auth/src/ability/standard/dm_ability_manager.cpp +++ b/ext/pin_auth/src/ability/standard/dm_ability_manager.cpp @@ -24,12 +24,12 @@ AbilityStatus DmAbilityManager::StartAbility(AAFwk::Want &want) { ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->Connect(); if (ret != 0) { - LOGE("Connect Ability failed, error value = %{public}d", (int32_t)ret); + LOGE("Connect Ability failed, error value = %{public}d", static_cast(ret)); return AbilityStatus::ABILITY_STATUS_FAILED; } ErrCode result = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want); if (result != 0) { - LOGE("Start Ability failed, error value = %{public}d", (int32_t)result); + LOGE("Start Ability failed, error value = %{public}d", static_cast(result)); return AbilityStatus::ABILITY_STATUS_FAILED; } return AbilityStatus::ABILITY_STATUS_SUCCESS; diff --git a/interfaces/cj/kits/BUILD.gn b/interfaces/cj/kits/BUILD.gn index 1155e845dded3e4163623b00e2dd01a9e9e2167b..4518b451146ed5cb3aba5eddb3b7609c80b5949d 100644 --- a/interfaces/cj/kits/BUILD.gn +++ b/interfaces/cj/kits/BUILD.gn @@ -70,6 +70,7 @@ ohos_shared_library("cj_distributed_device_manager_ffi") { external_deps = [ "access_token:libtokenid_sdk", "bounds_checking_function:libsec_shared", + "cJSON:cjson", "c_utils:utils", "hilog:libhilog", "ipc:ipc_core", diff --git a/interfaces/inner_kits/native_cpp/BUILD.gn b/interfaces/inner_kits/native_cpp/BUILD.gn index 2068a5585b19c581039241a6e5110ae529ed7035..ecb70b0c2777d458dab36dbcce0138c730e78b2f 100644 --- a/interfaces/inner_kits/native_cpp/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/BUILD.gn @@ -23,6 +23,7 @@ if (defined(ohos_lite)) { static_library("devicemanagersdk") { include_dirs = [ "${innerkits_path}/native_cpp/include/mini", + "//third_party/cJSON", "//kernel/liteos_m/kal/cmsis", "//utils/native/lite/include", "//kernel/liteos_m/kal/posix/include", @@ -50,7 +51,6 @@ if (defined(ohos_lite)) { "//commonlibrary/utils_lite:utils", "//foundation/systemabilitymgr/samgr_lite/samgr", "//third_party/bounds_checking_function:libsec_static", - "//third_party/cJSON:cjson", ] cflags = [ @@ -220,6 +220,8 @@ if (defined(ohos_lite)) { "samgr:samgr_proxy", ] + public_external_deps = [ "cJSON:cjson" ] + subsystem_name = "distributedhardware" part_name = "device_manager" diff --git a/interfaces/inner_kits/native_cpp/include/device_manager.h b/interfaces/inner_kits/native_cpp/include/device_manager.h index da0db3936076c2cece54906b35ba28a0a818fe77..a5c5f66a1e2be40b60fdfce1f8bf88ec8a72b753 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager.h @@ -344,7 +344,8 @@ public: /** * @brief Get local device name. - * @return Returns device name. + * @param deviceName device name. + * @return Returns 0 if success. */ virtual int32_t GetLocalDeviceName(std::string &deviceName) = 0; @@ -607,6 +608,7 @@ public: virtual bool CheckIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee) = 0; virtual int32_t GetErrCode(int32_t errCode) = 0; virtual int32_t ShiftLNNGear(const std::string &pkgName) = 0; + virtual int32_t SetDnPolicy(const std::string &pkgName, std::map &policy) = 0; virtual int32_t RegDevTrustChangeCallback(const std::string &pkgName, std::shared_ptr callback) = 0; virtual int32_t RegisterDeviceScreenStatusCallback(const std::string &pkgName, @@ -614,7 +616,6 @@ public: virtual int32_t UnRegisterDeviceScreenStatusCallback(const std::string &pkgName) = 0; virtual int32_t GetDeviceScreenStatus(const std::string &pkgName, const std::string &networkId, int32_t &screenStatus) = 0; - virtual int32_t SetDnPolicy(const std::string &pkgName, std::map &policy) = 0; virtual int32_t StopAuthenticateDevice(const std::string &pkgName) = 0; virtual int32_t GetNetworkIdByUdid(const std::string &pkgName, const std::string &udid, std::string &networkId) = 0; virtual int32_t RegisterCredentialAuthStatusCallback(const std::string &pkgName, @@ -636,18 +637,18 @@ public: const std::vector &deviceProfileInfoList) = 0; virtual int32_t GetLocalDisplayDeviceName(const std::string &pkgName, int32_t maxNameLength, std::string &displayName) = 0; - virtual int32_t RegisterLocalServiceInfo(const DMLocalServiceInfo &info) = 0; - virtual int32_t UnRegisterLocalServiceInfo(const std::string &bundleName, int32_t pinExchangeType) = 0; - virtual int32_t UpdateLocalServiceInfo(const DMLocalServiceInfo &info) = 0; - virtual int32_t GetLocalServiceInfoByBundleNameAndPinExchangeType(const std::string &bundleName, - int32_t pinExchangeType, DMLocalServiceInfo &info) = 0; + virtual int32_t GetDeviceNetworkIdList(const std::string &bundleName, const NetworkIdQueryFilter &queryFilter, + std::vector &networkIds) = 0; virtual int32_t SetLocalDeviceName(const std::string &pkgName, const std::string &deviceName, std::shared_ptr callback) = 0; virtual int32_t SetRemoteDeviceName(const std::string &pkgName, const std::string &deviceId, const std::string &deviceName, std::shared_ptr callback) = 0; virtual int32_t RestoreLocalDeviceName(const std::string &pkgName) = 0; - virtual int32_t GetDeviceNetworkIdList(const std::string &bundleName, const NetworkIdQueryFilter &queryFilter, - std::vector &networkIds) = 0; + virtual int32_t RegisterLocalServiceInfo(const DMLocalServiceInfo &info) = 0; + virtual int32_t UnRegisterLocalServiceInfo(const std::string &bundleName, int32_t pinExchangeType) = 0; + virtual int32_t UpdateLocalServiceInfo(const DMLocalServiceInfo &info) = 0; + virtual int32_t GetLocalServiceInfoByBundleNameAndPinExchangeType(const std::string &bundleName, + int32_t pinExchangeType, DMLocalServiceInfo &info) = 0; virtual int32_t UnRegisterPinHolderCallback(const std::string &pkgName) = 0; virtual bool CheckSrcAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee) = 0; virtual bool CheckSinkAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee) = 0; @@ -656,4 +657,4 @@ public: }; } // namespace DistributedHardware } // namespace OHOS -#endif // DEVICE_MANAGER_H +#endif // DEVICE_MANAGER_H \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h index 863626aef135a41ee472de50ce98df36a35c596b..7dcf251facf306d3fa4309022c7da86f2d731b15 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -403,12 +403,12 @@ public: virtual int32_t RegisterCredentialAuthStatusCallback(const std::string &pkgName, std::shared_ptr callback) override; virtual int32_t UnRegisterCredentialAuthStatusCallback(const std::string &pkgName) override; + void SyncCallbacksToService(std::map> &callbackMap); virtual int32_t RegisterSinkBindCallback(const std::string &pkgName, std::shared_ptr callback) override; virtual int32_t UnRegisterSinkBindCallback(const std::string &pkgName) override; virtual int32_t GetAllTrustedDeviceList(const std::string &pkgName, const std::string &extra, std::vector &deviceList) override; - void SyncCallbacksToService(std::map> &callbackMap); virtual int32_t RegisterAuthenticationType(const std::string &pkgName, const std::map &authParam) override; @@ -422,18 +422,18 @@ public: const std::vector &deviceProfileInfoList) override; virtual int32_t GetLocalDisplayDeviceName(const std::string &pkgName, int32_t maxNameLength, std::string &displayName) override; - virtual int32_t RegisterLocalServiceInfo(const DMLocalServiceInfo &info) override; - virtual int32_t UnRegisterLocalServiceInfo(const std::string &bundleName, int32_t pinExchangeType) override; - virtual int32_t UpdateLocalServiceInfo(const DMLocalServiceInfo &info) override; - virtual int32_t GetLocalServiceInfoByBundleNameAndPinExchangeType(const std::string &bundleName, - int32_t pinExchangeType, DMLocalServiceInfo &info) override; + virtual int32_t GetDeviceNetworkIdList(const std::string &bundleName, const NetworkIdQueryFilter &queryFilter, + std::vector &networkIds) override; virtual int32_t SetLocalDeviceName(const std::string &pkgName, const std::string &deviceName, std::shared_ptr callback) override; virtual int32_t SetRemoteDeviceName(const std::string &pkgName, const std::string &deviceId, const std::string &deviceName, std::shared_ptr callback) override; virtual int32_t RestoreLocalDeviceName(const std::string &pkgName) override; - virtual int32_t GetDeviceNetworkIdList(const std::string &bundleName, const NetworkIdQueryFilter &queryFilter, - std::vector &networkIds) override; + virtual int32_t RegisterLocalServiceInfo(const DMLocalServiceInfo &info) override; + virtual int32_t UnRegisterLocalServiceInfo(const std::string &bundleName, int32_t pinExchangeType) override; + virtual int32_t UpdateLocalServiceInfo(const DMLocalServiceInfo &info) override; + virtual int32_t GetLocalServiceInfoByBundleNameAndPinExchangeType(const std::string &bundleName, + int32_t pinExchangeType, DMLocalServiceInfo &info) override; virtual int32_t UnRegisterPinHolderCallback(const std::string &pkgName) override; virtual bool CheckSrcAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee) override; virtual bool CheckSinkAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee) override; diff --git a/interfaces/inner_kits/native_cpp/include/dm_device_info.h b/interfaces/inner_kits/native_cpp/include/dm_device_info.h index b7704d94df412168e0e12abc80305242450246e6..ff8a313daacb1a4aa5c806bee9c764367c9fa233 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -150,7 +150,7 @@ typedef enum DmAuthForm { */ ACROSS_ACCOUNT = 2, /** - * Share + * Share. */ SHARE = 3, } DmAuthForm; diff --git a/interfaces/inner_kits/native_cpp/include/dm_subscribe_info.h b/interfaces/inner_kits/native_cpp/include/dm_subscribe_info.h index d39b30365aeeea6226c2d6add0cc8598b02e0975..83208d95ee7237393e528894867924a3f9f0f9f9 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_subscribe_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_subscribe_info.h @@ -81,10 +81,6 @@ typedef enum DmExchangeFreq { * Super-high */ DM_SUPER_HIGH = 3, - /** - * Extreme-high - */ - DM_EXTREME_HIGH = 4, DM_FREQ_BUTT } DmExchangeFreq; diff --git a/interfaces/inner_kits/native_cpp/include/i_dm_bind_manager_ext_resident.h b/interfaces/inner_kits/native_cpp/include/i_dm_bind_manager_ext_resident.h index 0302487105f9fb987c8b2ceec1f598870d9d9015..bfb8180ea85a1aafa2311261a815c12d7b346a4d 100644 --- a/interfaces/inner_kits/native_cpp/include/i_dm_bind_manager_ext_resident.h +++ b/interfaces/inner_kits/native_cpp/include/i_dm_bind_manager_ext_resident.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 diff --git a/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h b/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h index cb4bb85bc260c8e3638704898fe98dfe3c505d4a..db20a207b0429ccaf9ddc68397914eb5e881ee10 100644 --- a/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h +++ b/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h @@ -17,6 +17,7 @@ #define OHOS_I_DM_SERVICE_IMPL_EXT_H #include "dm_device_info.h" +#include "dm_device_profile_info.h" #include "idevice_manager_service_listener.h" #include "i_dm_bind_manager_ext_resident.h" @@ -99,10 +100,10 @@ public: * @tc.type: FUNC */ virtual int32_t AccountUserSwitched(int32_t userId, const std::string &accountId) = 0; + virtual int32_t InitResident(std::shared_ptr residentCallback, const std::shared_ptr &listener) = 0; virtual void OnResidentBytesReceived(const int32_t sessionId, const std::string &message) = 0; - virtual void OnSessionOpened(int32_t sessionId, int32_t sessionSide, int32_t result) = 0; virtual void OnSessionClosed(const int32_t sessionId) = 0; virtual void OnBytesReceived(const int32_t sessionId, const std::string message) = 0; diff --git a/interfaces/inner_kits/native_cpp/include/idevice_manager_service_listener.h b/interfaces/inner_kits/native_cpp/include/idevice_manager_service_listener.h index 336c5b631bd1e523058e86a725f72225b2997688..e6fe7d298e1f137fc9af274f35c01d726b9b9428 100644 --- a/interfaces/inner_kits/native_cpp/include/idevice_manager_service_listener.h +++ b/interfaces/inner_kits/native_cpp/include/idevice_manager_service_listener.h @@ -160,11 +160,11 @@ public: virtual void OnCredentialAuthStatus(const ProcessInfo &processInfo, const std::string &deviceList, uint16_t deviceTypeId, int32_t errcode) = 0; virtual void OnAppUnintall(const std::string &pkgName) = 0; - virtual void OnSinkBindResult(const ProcessInfo &processInfo, const PeerTargetId &targetId, int32_t result, - int32_t status, std::string content) = 0; virtual void OnProcessRemove(const ProcessInfo &processInfo) = 0; virtual void OnDevStateCallbackAdd(const ProcessInfo &processInfo, const std::vector &deviceList) = 0; + virtual void OnSinkBindResult(const ProcessInfo &processInfo, const PeerTargetId &targetId, int32_t result, + int32_t status, std::string content) = 0; virtual void OnGetDeviceProfileInfoListResult(const ProcessInfo &processInfo, const std::vector &deviceProfileInfos, int32_t code) = 0; virtual void OnGetDeviceIconInfoResult(const ProcessInfo &processInfo, diff --git a/interfaces/inner_kits/native_cpp/src/dm_device_info.cpp b/interfaces/inner_kits/native_cpp/src/dm_device_info.cpp index c80cbb4a4b72f9f5ce1096228e4d3b16335f732d..090c815a8ec0ed173ea9398df74b2262a872aaed 100644 --- a/interfaces/inner_kits/native_cpp/src/dm_device_info.cpp +++ b/interfaces/inner_kits/native_cpp/src/dm_device_info.cpp @@ -13,6 +13,8 @@ * limitations under the License. */ +#include "dm_device_info.h" + namespace OHOS { namespace DistributedHardware { const char* DEVICE_TYPE_UNKNOWN_STRING = "UNKNOWN"; diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp index 14d6c0d2a87873f141acf30b26a44abe5d18a493..049b3d1920a92f1294d989b5fc522d93e66ef895 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp @@ -90,7 +90,6 @@ int32_t IpcClientManager::SendRequest(int32_t cmdCode, std::shared_ptr r CHECK_NULL_RETURN(rsp, ERR_DM_POINT_NULL); std::string pkgName = req->GetPkgName(); if (!IsInit(pkgName)) { - LOGE("PkgName: %s is not init.", pkgName.c_str()); return ERR_DM_INIT_FAILED; } return serverProxy_.SendCmd(cmdCode, req, rsp); @@ -99,17 +98,7 @@ int32_t IpcClientManager::SendRequest(int32_t cmdCode, std::shared_ptr r bool IpcClientManager::IsInit(const std::string &pkgName) { std::lock_guard autoLock(packageInitSetLock_); - for (auto &iter : packageInitSet_) { - size_t len = iter.size(); - if (len > pkgName.size()) { - continue; - } - std::string tmp = pkgName.substr(0, len); - if (tmp == iter) { - return true; - } - } - return false; + return (packageInitSet_.count(pkgName) > 0); } int32_t IpcClientManager::OnDmServiceDied() diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index f24244d23639cf6b4597e920a5ed491feb58cdae..999508c4786903f09c2baa92dd5541c78721a560 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2024 Huawei Device Co., Ltd. +# Copyright (c) 2022-2023 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 @@ -65,6 +65,7 @@ ohos_shared_library("devicemanager") { external_deps = [ "access_token:libtokenid_sdk", "bounds_checking_function:libsec_shared", + "cJSON:cjson", "c_utils:utils", "hilog:libhilog", "ipc:ipc_core", diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index f7a1825bd8bb91fffeca56ce41c040227110bbd1..5e48da4e7adb7bf3a3baa01087c67832824c1910 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -14,7 +14,11 @@ */ #include "native_devicemanager_js.h" + +#include #include +#include + #include "device_manager.h" #include "dm_constants.h" #include "dm_device_info.h" @@ -97,14 +101,16 @@ enum class DMBussinessErrorCode : int32_t { DM_ERR_PUBLISH_INVALID = 11600105, }; -const std::string ERR_MESSAGE_NO_PERMISSION = "Permission verify failed."; -const std::string ERR_MESSAGE_NOT_SYSTEM_APP = "The caller is not a system application."; -const std::string ERR_MESSAGE_INVALID_PARAMS = "Input parameter error."; +const std::string ERR_MESSAGE_NO_PERMISSION = + "Permission verification failed. The application does not have the permission required to call the API."; +const std::string ERR_MESSAGE_NOT_SYSTEM_APP = + "Permission verification failed. A non-system application calls a system API."; +const std::string ERR_MESSAGE_INVALID_PARAMS = "Parameter error."; const std::string ERR_MESSAGE_FAILED = "Failed to execute the function."; const std::string ERR_MESSAGE_OBTAIN_SERVICE = "Failed to obtain the service."; -const std::string ERR_MESSAGE_AUTHENTICALTION_INVALID = "Authentication invalid."; -const std::string ERR_MESSAGE_DISCOVERY_INVALID = "Discovery invalid."; -const std::string ERR_MESSAGE_PUBLISH_INVALID = "Publish invalid."; +const std::string ERR_MESSAGE_AUTHENTICALTION_INVALID = "Authentication unavailable."; +const std::string ERR_MESSAGE_DISCOVERY_INVALID = "Discovery unavailable."; +const std::string ERR_MESSAGE_PUBLISH_INVALID = "Publish unavailable."; napi_value GenerateBusinessError(napi_env env, int32_t err, const std::string &msg) { @@ -915,7 +921,6 @@ void DeviceManagerNapi::OnAuthResult(const std::string &deviceId, const std::str } else { napi_call_function(env_, nullptr, handler, DM_NAPI_ARGS_TWO, &result[0], &callResult); napi_delete_reference(env_, authAsyncCallbackInfo_.callback); - authAsyncCallbackInfo_.callback = nullptr; } } else { LOGE("handler is nullptr"); @@ -1693,7 +1698,6 @@ void DeviceManagerNapi::CallGetTrustedDeviceListStatus(napi_env env, napi_status if (handler != nullptr) { NAPI_CALL_RETURN_VOID(env, napi_call_function(env, nullptr, handler, DM_NAPI_ARGS_TWO, &array[0], &callResult)); NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, deviceInfoListAsyncCallbackInfo->callback)); - deviceInfoListAsyncCallbackInfo->callback = nullptr; } else { LOGE("handler is nullptr"); } @@ -1721,7 +1725,6 @@ void DeviceManagerNapi::CallRequestCreInfoStatus(napi_env env, napi_status &stat if (handler != nullptr) { napi_call_function(env, nullptr, handler, DM_NAPI_ARGS_ONE, &result, &callResult); napi_delete_reference(env, creAsyncCallbackInfo->callback); - creAsyncCallbackInfo->callback = nullptr; } else { LOGE("handler is nullptr"); } @@ -1768,7 +1771,6 @@ void DeviceManagerNapi::CallGetLocalDeviceInfo(napi_env env, napi_status &status NAPI_CALL_RETURN_VOID(env, napi_call_function(env, nullptr, handler, DM_NAPI_ARGS_TWO, &result[0], &callResult)); NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, deviceInfoAsyncCallbackInfo->callback)); - deviceInfoAsyncCallbackInfo->callback = nullptr; } else { LOGE("handler is nullptr"); } @@ -1848,7 +1850,7 @@ void DeviceManagerNapi::CallAsyncWorkSync(napi_env env, { napi_value resourceName; napi_create_string_latin1(env, "GetTrustListInfo", NAPI_AUTO_LENGTH, &resourceName); - napi_create_async_work( + napi_status result = napi_create_async_work( env, nullptr, resourceName, [](napi_env env, void *data) { (void)env; @@ -1874,17 +1876,21 @@ void DeviceManagerNapi::CallAsyncWorkSync(napi_env env, reinterpret_cast(data); CallGetTrustedDeviceListStatusSync(env, status, dInfoListAsyncCallbackInfo); napi_delete_async_work(env, dInfoListAsyncCallbackInfo->asyncWork); - delete dInfoListAsyncCallbackInfo; + DeleteAsyncCallbackInfo(dInfoListAsyncCallbackInfo); }, (void *)deviceInfoListAsyncCallbackInfo, &deviceInfoListAsyncCallbackInfo->asyncWork); napi_queue_async_work_with_qos(env, deviceInfoListAsyncCallbackInfo->asyncWork, napi_qos_user_initiated); + if (result != napi_ok) { + LOGE("CallAsyncWorkSync failed result %{public}d", result); + DeleteAsyncCallbackInfo(deviceInfoListAsyncCallbackInfo); + } } void DeviceManagerNapi::CallAsyncWork(napi_env env, DeviceInfoListAsyncCallbackInfo *deviceInfoListAsyncCallbackInfo) { napi_value resourceName; napi_create_string_latin1(env, "GetTrustListInfo", NAPI_AUTO_LENGTH, &resourceName); - napi_create_async_work( + napi_status result = napi_create_async_work( env, nullptr, resourceName, [](napi_env env, void *data) { DeviceInfoListAsyncCallbackInfo *devInfoListAsyncCallbackInfo = @@ -1909,11 +1915,14 @@ void DeviceManagerNapi::CallAsyncWork(napi_env env, DeviceInfoListAsyncCallbackI reinterpret_cast(data); CallGetTrustedDeviceListStatus(env, status, dInfoListAsyncCallbackInfo); napi_delete_async_work(env, dInfoListAsyncCallbackInfo->asyncWork); - delete dInfoListAsyncCallbackInfo; - dInfoListAsyncCallbackInfo = nullptr; + DeleteAsyncCallbackInfo(dInfoListAsyncCallbackInfo); }, (void *)deviceInfoListAsyncCallbackInfo, &deviceInfoListAsyncCallbackInfo->asyncWork); napi_queue_async_work_with_qos(env, deviceInfoListAsyncCallbackInfo->asyncWork, napi_qos_user_initiated); + if (result != napi_ok) { + LOGE("CallAsyncWork failed result %{public}d", result); + DeleteAsyncCallbackInfo(deviceInfoListAsyncCallbackInfo); + } } void DeviceManagerNapi::AsyncTaskCallback(napi_env env, void *data) @@ -3109,7 +3118,6 @@ void DeviceManagerNapi::CallGetDeviceInfoCB(napi_env env, napi_status &status, if (handler != nullptr) { napi_call_function(env, nullptr, handler, DM_NAPI_ARGS_TWO, &result[0], &callResult); napi_delete_reference(env, networkIdAsyncCallbackInfo->callback); - networkIdAsyncCallbackInfo->callback = nullptr; } else { LOGE("handler is nullptr"); } diff --git a/interfaces/kits/js4.0/BUILD.gn b/interfaces/kits/js4.0/BUILD.gn index d7bfd367bdbef51e1a915116e894d7925375456d..f5c1249b5fc7adbcbfb338c605204cf0b15bcec5 100644 --- a/interfaces/kits/js4.0/BUILD.gn +++ b/interfaces/kits/js4.0/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2024 Huawei Device Co., Ltd. +# Copyright (c) 2022-2023 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 @@ -67,6 +67,7 @@ ohos_shared_library("distributeddevicemanager") { external_deps = [ "access_token:libtokenid_sdk", "bounds_checking_function:libsec_shared", + "cJSON:cjson", "c_utils:utils", "hilog:libhilog", "ipc:ipc_core", diff --git a/interfaces/kits/js4.0/include/dm_native_util.h b/interfaces/kits/js4.0/include/dm_native_util.h index f41bafde5b44c551865aad3166bea39506432df6..fb8bf8a5bbbbc597ffcf4ec28bd010055c5dbb91 100644 --- a/interfaces/kits/js4.0/include/dm_native_util.h +++ b/interfaces/kits/js4.0/include/dm_native_util.h @@ -88,10 +88,10 @@ void DmDeviceIconInfoToJs(const napi_env &env, const DmDeviceIconInfo &deviceIco void DmDeviceProfileInfoToJsArray(const napi_env &env, const std::vector &devInfos, napi_value &arrayResult); bool JsToDmDeviceProfileInfos(const napi_env &env, const napi_value &jsObj, std::vector &devInfos); -void JsToDiscoveryParam(const napi_env &env, const napi_value &object, - std::map &discParam); void JsToDmDeviceNetworkIdFilterOptions(const napi_env &env, const napi_value &object, NetworkIdQueryFilter &info); +void JsToDiscoveryParam(const napi_env &env, const napi_value &object, + std::map &discParam); } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_NATIVE_UTIL_H diff --git a/interfaces/kits/js4.0/include/native_devicemanager_js.h b/interfaces/kits/js4.0/include/native_devicemanager_js.h index a26bd243797ed28e6e86d616796f3d376807ff1d..4d037097112bb174df32839c69106d72158ba671 100644 --- a/interfaces/kits/js4.0/include/native_devicemanager_js.h +++ b/interfaces/kits/js4.0/include/native_devicemanager_js.h @@ -374,10 +374,10 @@ public: static napi_value JsGetDeviceIconInfo(napi_env env, napi_callback_info info); static napi_value JsPutDeviceProfileInfoList(napi_env env, napi_callback_info info); static napi_value JsGetLocalDisplayDeviceName(napi_env env, napi_callback_info info); + static napi_value JsGetDeviceNetworkIdList(napi_env env, napi_callback_info info); static napi_value JsSetLocalDeviceName(napi_env env, napi_callback_info info); static napi_value JsSetRemoteDeviceName(napi_env env, napi_callback_info info); static napi_value JsRestoreLocalDeviceName(napi_env env, napi_callback_info info); - static napi_value JsGetDeviceNetworkIdList(napi_env env, napi_callback_info info); static DeviceManagerNapi *GetDeviceManagerNapi(std::string &bundleName); static void CreateDmCallback(napi_env env, std::string &bundleName, std::string &eventType); static void CreateDmCallback(napi_env env, std::string &bundleName, std::string &eventType, std::string &extra); @@ -423,10 +423,11 @@ private: PutDeviceProfileInfoListAsyncCallbackInfo *jsCallback); static napi_value GetLocalDisplayDeviceNamePromise(napi_env env, GetLocalDisplayDeviceNameAsyncCallbackInfo *jsCallback); - static napi_value SetLocalDeviceNamePromise(napi_env env, SetLocalDeviceNameAsyncCallbackInfo *jsCallback); - static napi_value SetRemoteDeviceNamePromise(napi_env env, SetRemoteDeviceNameAsyncCallbackInfo *jsCallback); static napi_value GetDeviceNetworkIdListPromise(napi_env env, GetDeviceNetworkIdListAsyncCallbackInfo *jsCallback); + static napi_value SetLocalDeviceNamePromise(napi_env env, SetLocalDeviceNameAsyncCallbackInfo *jsCallback); + static napi_value SetRemoteDeviceNamePromise(napi_env env, SetRemoteDeviceNameAsyncCallbackInfo *jsCallback); + private: napi_env env_; static thread_local napi_ref sConstructor_; diff --git a/interfaces/kits/js4.0/src/dm_native_util.cpp b/interfaces/kits/js4.0/src/dm_native_util.cpp index 60a8e66d8961bb36eefe820ee606de9b2a560388..638ac7def3b25c2bb447e33904fd8f4bb879c5e1 100644 --- a/interfaces/kits/js4.0/src/dm_native_util.cpp +++ b/interfaces/kits/js4.0/src/dm_native_util.cpp @@ -27,14 +27,16 @@ using namespace OHOS::Security::AccessToken; namespace OHOS { namespace DistributedHardware { namespace { -const std::string ERR_MESSAGE_NO_PERMISSION = "Permission verify failed."; -const std::string ERR_MESSAGE_NOT_SYSTEM_APP = "The caller is not a system application."; -const std::string ERR_MESSAGE_INVALID_PARAMS = "Input parameter error."; +const std::string ERR_MESSAGE_NO_PERMISSION = + "Permission verification failed. The application does not have the permission required to call the API."; +const std::string ERR_MESSAGE_NOT_SYSTEM_APP = + "Permission verification failed. A non-system application calls a system API."; +const std::string ERR_MESSAGE_INVALID_PARAMS = "Parameter error."; const std::string ERR_MESSAGE_FAILED = "Failed to execute the function."; const std::string ERR_MESSAGE_OBTAIN_SERVICE = "Failed to obtain the service."; -const std::string ERR_MESSAGE_AUTHENTICALTION_INVALID = "Authentication invalid."; -const std::string ERR_MESSAGE_DISCOVERY_INVALID = "Discovery invalid."; -const std::string ERR_MESSAGE_PUBLISH_INVALID = "Publish invalid."; +const std::string ERR_MESSAGE_AUTHENTICALTION_INVALID = "Authentication unavailable."; +const std::string ERR_MESSAGE_DISCOVERY_INVALID = "Discovery unavailable."; +const std::string ERR_MESSAGE_PUBLISH_INVALID = "Publish unavailable."; const std::string ERR_MESSAGE_FROM_CLOUD_FAILED = "Get data from cloud failed."; const std::string ERR_MESSAGE_NEED_LOGIN = "A login account is required."; const std::string ERR_MESSAGE_SCAS_CHECK_FAILED = "The device name contains non-compliant content."; diff --git a/interfaces/mini_tools_kits/native_cpp/src/device_manager_impl_mini.cpp b/interfaces/mini_tools_kits/native_cpp/src/device_manager_impl_mini.cpp index ff35fd1066affd3410769ccc58ebfe0e2a41e2ff..ca772d6ea98df92a04c465990e63fa8f57396b24 100644 --- a/interfaces/mini_tools_kits/native_cpp/src/device_manager_impl_mini.cpp +++ b/interfaces/mini_tools_kits/native_cpp/src/device_manager_impl_mini.cpp @@ -99,8 +99,8 @@ int32_t DeviceManagerImplMini::GetLocalDisplayDeviceName(const std::string &pkgN req->SetMaxNameLength(maxNameLength); int32_t ret = ipcClientProxy_->SendRequest(GET_LOCAL_DISPLAY_DEVICE_NAME, req, rsp); if (ret != DM_OK) { - return ERR_DM_IPC_SEND_REQUEST_FAILED; LOGE("error: Send Request failed ret: %{public}d", ret); + return ERR_DM_IPC_SEND_REQUEST_FAILED; } ret = rsp->GetErrCode(); if (ret != DM_OK) { diff --git a/json/src/json_object_cjson.cpp b/json/src/json_object_cjson.cpp index 32fed83ebe4701dc9e094d8ecef6d4d550abec6b..a27b2762838cc01bcad20e22813ab178dba01dee 100644 --- a/json/src/json_object_cjson.cpp +++ b/json/src/json_object_cjson.cpp @@ -156,6 +156,7 @@ void ToJson(JsonItemObject &itemObject, const uint64_t &value) #endif } +//LCOV_EXCL_START void FromJson(const JsonItemObject &itemObject, std::string &value) { itemObject.GetTo(value); @@ -307,6 +308,7 @@ bool JsonItemObject::IsObject() const } return cJSON_IsObject(GetCJsonPointer(item_)); } +//LCOV_EXCL_STOP void JsonItemObject::Insert(const std::string &key, const JsonItemObject &object) { diff --git a/sa_profile/device_manager.cfg b/sa_profile/device_manager.cfg index 0110d5f331b36eccb9d357a28dbbe54d1244eeaf..5728fa975da9eae0e4411a80efe364212484e792 100644 --- a/sa_profile/device_manager.cfg +++ b/sa_profile/device_manager.cfg @@ -26,9 +26,9 @@ "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", "ohos.permission.ENABLE_DISTRIBUTED_HARDWARE", "ohos.permission.MANAGE_LOCAL_ACCOUNTS", - "ohos.permission.MANAGE_SECURE_SETTINGS", "ohos.permission.ACCESS_BLUETOOTH", "ohos.permission.MANAGE_BLUETOOTH", + "ohos.permission.MANAGE_SECURE_SETTINGS", "ohos.permission.MANAGE_SETTINGS", "ohos.permission.MANAGE_SOFTBUS_NETWORK", "ohos.permission.START_SYSTEM_DIALOG", diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 1d3f72374390458c1220ef8545088d5a13c16dc0..e7de7e5f06f25d491ff6133ab68e56057d90fce9 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -114,8 +114,8 @@ typedef struct DmAuthRequestContext { std::string cryptoVer; std::string hostPkgName; std::string targetPkgName; - std::string bundleName; std::string peerBundleName; + std::string bundleName; std::string appOperation; std::string appDesc; std::string appName; @@ -235,6 +235,7 @@ public: * @param deviceId device id. * @return Return 0 if success. */ + int32_t UnBindDevice(const std::string &pkgName, const std::string &udid, int32_t bindLevel); int32_t UnBindDevice(const std::string &pkgName, const std::string &udid, int32_t bindLevel, const std::string &extra); @@ -497,6 +498,10 @@ public: private: bool IsHmlSessionType(); + void JoinLnn(const std::string &deviceId, bool isForceJoin = false); + int32_t CheckAuthParamVaild(const std::string &pkgName, int32_t authType, const std::string &deviceId, + const std::string &extra); + int32_t CheckAuthParamVaildExtra(const std::string &extra, const std::string &deviceId); bool CanUsePincodeFromDp(); bool IsServiceInfoAuthTypeValid(int32_t authType); bool IsServiceInfoAuthBoxTypeValid(int32_t authBoxType); @@ -505,10 +510,6 @@ private: void GetLocalServiceInfoInDp(); bool CheckNeedShowAuthInfoDialog(int32_t errorCode); void UpdateInputPincodeDialog(int32_t errorCode); - void JoinLnn(const std::string &deviceId, bool isForceJoin = false); - int32_t CheckAuthParamVaild(const std::string &pkgName, int32_t authType, const std::string &deviceId, - const std::string &extra); - int32_t CheckAuthParamVaildExtra(const std::string &extra, const std::string &deviceId); bool CheckHmlParamValid(JsonObject &jsonObject); void ProcessSourceMsg(); void ProcessSinkMsg(); @@ -586,13 +587,16 @@ private: int32_t GetTaskTimeout(const char* taskName, int32_t taskTimeOut); void GetPeerUdidHash(int32_t sessionId, std::string &peerUdidHash); void DeleteOffLineTimer(int32_t sessionId); - int32_t GetBinderInfo(); - void SetProcessInfo(); + void ProcessTerminateMsg(int32_t sessionId, int32_t reply); int32_t GetCloseSessionDelaySeconds(std::string &delaySecondsStr); void ConverToFinish(); + void HandleDeviceOnline(); + int32_t GetBinderInfo(); + void SetProcessInfo(); bool IsSinkMsgValid(); bool IsSourceMsgValid(); void ProcessReqPublicKey(); + bool CheckBindLevel(const JsonObject &jsonObj, const std::string &key, int32_t &bindLevel); void RegisterCleanNotifyCallback(CleanNotifyCallback cleanNotifyCallback); void GetBindCallerInfo(); void ProcessReqAuthTerminate(); @@ -636,14 +640,14 @@ private: std::mutex srcReqMsgLock_; bool isNeedProcCachedSrcReqMsg_ = false; std::string srcReqMsg_ = ""; + std::string bundleName_ = ""; int32_t authenticationType_ = USER_OPERATION_TYPE_ALLOW_AUTH; + bool isWaitingJoinLnnCallback_ = false; DistributedDeviceProfile::LocalServiceInfo serviceInfoProfile_; bool pincodeDialogEverShown_ = false; - std::string bundleName_ = ""; std::mutex sessionKeyIdMutex_; std::condition_variable sessionKeyIdCondition_; std::map> sessionKeyIdAsyncResult_; - bool isWaitingJoinLnnCallback_ = false; CleanNotifyCallback cleanNotifyCallback_{nullptr}; std::mutex bindParamMutex_; std::map bindParam_; diff --git a/services/implementation/include/authentication_v2/auth_manager.h b/services/implementation/include/authentication_v2/auth_manager.h index 02deef3fe7ca1f8f8b1fec0005eccb180e1578b2..9eb05ec58d8386b783ffc5d9ec11c97651d1326b 100644 --- a/services/implementation/include/authentication_v2/auth_manager.h +++ b/services/implementation/include/authentication_v2/auth_manager.h @@ -139,7 +139,6 @@ private: void ParseJsonObject(const JsonObject &jsonObject); void GetAuthParam(const std::string &sessionName, int32_t authType, const std::string &deviceId, const std::string &extra); - std::string GetBundleName(const JsonObject &jsonObject); void SetAuthType(int32_t authType); bool IsAuthTypeSupported(const int32_t &authType); bool IsAuthCodeReady(const std::string &sessionName); diff --git a/services/implementation/include/authentication_v2/dm_auth_context.h b/services/implementation/include/authentication_v2/dm_auth_context.h index e60adda5c2876c443aa42a3f23cb2ea0034c5cdb..dd511bd12a059972a09cd8dda78a85e605473ca1 100644 --- a/services/implementation/include/authentication_v2/dm_auth_context.h +++ b/services/implementation/include/authentication_v2/dm_auth_context.h @@ -200,7 +200,7 @@ struct DmAccess { int64_t transmitSkTimeStamp; // Used for aging, time is 2 days, application-level credential timestamp int64_t lnnSkTimeStamp{0}; // Used for aging, time is 2 days, user-level credential timestamp int64_t skTimeStamp; // Used for aging, time is 2 days - uint64_t certRandom{0}; // Used for cert generate + uint64_t certRandom{0}; bool isAuthed; bool isUserLevelAuthed; bool isOnline; @@ -278,7 +278,7 @@ struct DmAuthContext { bool IsProxyBind{false}; bool IsCallingProxyAsSubject{true}; bool IsNeedSetProxy{false}; - bool isNeedAuthorize{false}; + bool isNeedAuthenticate{true}; // apply for skip authenticate std::vector subjectProxyOnes; std::string reUseCreId; std::string title; diff --git a/services/implementation/include/authentication_v2/dm_auth_manager_base.h b/services/implementation/include/authentication_v2/dm_auth_manager_base.h index d3a4fa411a7e520369591f4097a9e2d9702390fe..c03932d094c3001f8781b7b4a2e9141e14ea9cb9 100644 --- a/services/implementation/include/authentication_v2/dm_auth_manager_base.h +++ b/services/implementation/include/authentication_v2/dm_auth_manager_base.h @@ -57,7 +57,7 @@ extern const char* TAG_HOST_PKGLABEL; extern const char* TAG_REMOTE_DEVICE_NAME; extern const char* TAG_HOST; extern const char* TAG_PROXY_CONTEXT_ID; - +extern const char* TAG_IS_NEED_AUTHENTICATE; extern const char* APP_OPERATION_KEY; extern const char* TARGET_PKG_NAME_KEY; extern const char* CUSTOM_DESCRIPTION_KEY; diff --git a/services/implementation/include/authentication_v2/dm_auth_state.h b/services/implementation/include/authentication_v2/dm_auth_state.h index f1857b8f1698cd3aed6b0b43f33843aedba4f2d4..0007141625ef61add3996f146991c892df20df69 100644 --- a/services/implementation/include/authentication_v2/dm_auth_state.h +++ b/services/implementation/include/authentication_v2/dm_auth_state.h @@ -169,13 +169,13 @@ public: static uint64_t GetSysTimeMs(); static void DeleteAcl(std::shared_ptr context, const DistributedDeviceProfile::AccessControlProfile &profile); + void GetPeerDeviceId(std::shared_ptr context, std::string &peerDeviceId); static void DeleteCredential(std::shared_ptr context, int32_t userId, const JsonItemObject &credInfo, const DistributedDeviceProfile::AccessControlProfile &profile); static void DirectlyDeleteCredential(std::shared_ptr context, int32_t userId, const JsonItemObject &credInfo); static void DeleteAclAndSk(std::shared_ptr context, const DistributedDeviceProfile::AccessControlProfile &profile); - void GetPeerDeviceId(std::shared_ptr context, std::string &peerDeviceId); void JoinLnn(std::shared_ptr context); protected: bool NeedReqUserConfirm(std::shared_ptr context); @@ -570,6 +570,7 @@ public: virtual ~AuthSrcDataSyncState() {}; DmAuthStateType GetStateType() override; int32_t Action(std::shared_ptr context) override; + void GetPeerDeviceId(std::shared_ptr context, std::string &peerDeviceId); }; class AuthSinkFinishState : public DmAuthState { diff --git a/services/implementation/include/dependency/softbus/softbus_connector.h b/services/implementation/include/dependency/softbus/softbus_connector.h index 3f3a102941875631243bd20cab736b30a8198d01..221d2f58791a0af5e67746dd4a28fe66d16d467b 100644 --- a/services/implementation/include/dependency/softbus/softbus_connector.h +++ b/services/implementation/include/dependency/softbus/softbus_connector.h @@ -107,7 +107,6 @@ public: * @tc.type: FUNC */ int32_t UnRegisterConnectorCallback(); - public: SoftbusConnector(); ~SoftbusConnector(); @@ -162,6 +161,7 @@ private: int32_t GetLocalVersion(const std::string localUdid, const std::string remoteUdid, std::string &localVersion, DistributedDeviceProfile::AccessControlProfile &localAcl); #endif + private: static std::string remoteUdidHash_; #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) @@ -176,6 +176,7 @@ private: static std::mutex discoveryDeviceInfoMutex_; static std::mutex deviceUdidLocks_; static std::mutex processInfoVecMutex_; + static std::mutex registerCallback_; static std::mutex processChangeInfoVecMutex_; static std::shared_ptr connectorCallback_; }; diff --git a/services/implementation/src/authentication/auth_message_processor.cpp b/services/implementation/src/authentication/auth_message_processor.cpp index 5d4458025323d06c424bdd0da3acedc8732bee30..47c0318531262261f7ec0f4745d253bbb4fae755 100644 --- a/services/implementation/src/authentication/auth_message_processor.cpp +++ b/services/implementation/src/authentication/auth_message_processor.cpp @@ -113,6 +113,7 @@ void AuthMessageProcessor::GetJsonObj(JsonObject &jsonObj) } } +//LCOV_EXCL_START bool AuthMessageProcessor::IsPincodeImported() { auto sptrAuthMgr = authMgr_.lock(); @@ -124,7 +125,7 @@ bool AuthMessageProcessor::IsPincodeImported() std::vector AuthMessageProcessor::CreateAuthRequestMessage() { - LOGI("start."); + LOGI("AuthMessageProcessor::CreateAuthRequestMessage start."); std::vector jsonStrVec; if (authRequestContext_ == nullptr) { LOGE("AuthMessageProcessor::CreateAuthRequestMessage authRequestContext_ is nullptr."); @@ -147,15 +148,18 @@ std::vector AuthMessageProcessor::CreateAuthRequestMessage() jsonThumbnailObj[TAG_THUMBNAIL_SIZE] = thumbnailSize; int32_t leftLen = thumbnailSize - idx * MSG_MAX_SIZE; int32_t sliceLen = (leftLen > MSG_MAX_SIZE) ? MSG_MAX_SIZE : leftLen; + LOGI("TAG_APP_THUMBNAIL encode, idx %{public}d, sliceLen %{public}d, thumbnailSize %{public}d", idx, + (uint32_t)sliceLen, thumbnailSize); jsonObj[TAG_APP_THUMBNAIL] = authRequestContext_->appThumbnail.substr(idx * MSG_MAX_SIZE, sliceLen); jsonStrVec.push_back(jsonThumbnailObj.Dump()); } return jsonStrVec; } +//LCOV_EXCL_STOP std::string AuthMessageProcessor::CreateSimpleMessage(int32_t msgType) { - LOGI("start. msgType is %{public}d", msgType); + LOGI("AuthMessageProcessor::CreateSimpleMessage start. msgType is %{public}d", msgType); JsonObject jsonObj; jsonObj[TAG_VER] = DM_ITF_VER; jsonObj[TAG_MSG_TYPE] = msgType; @@ -310,7 +314,7 @@ void AuthMessageProcessor::CreateResponseAuthMessage(JsonObject &json) json[TAG_TOKEN] = authResponseContext_->token; if (authResponseContext_->reply == 0) { std::string groupId = authResponseContext_->groupId; - LOGI("groupId %{public}s", GetAnonyString(groupId).c_str()); + LOGI("AuthMessageProcessor::CreateResponseAuthMessage groupId %{public}s", GetAnonyString(groupId).c_str()); JsonObject jsonObject(groupId); if (jsonObject.IsDiscarded()) { LOGE("DecodeRequestAuth jsonStr error"); @@ -350,7 +354,7 @@ int32_t AuthMessageProcessor::ParseMessage(const std::string &message) } int32_t msgType = jsonObject[TAG_MSG_TYPE].Get(); authResponseContext_->msgType = msgType; - LOGI("message type %{public}d", authResponseContext_->msgType); + LOGI("AuthMessageProcessor::ParseMessage message type %{public}d", authResponseContext_->msgType); switch (msgType) { case MSG_TYPE_NEGOTIATE: ParseNegotiateMessage(jsonObject); @@ -414,6 +418,7 @@ void AuthMessageProcessor::ParsePublicKeyMessageExt(JsonObject &json) } if (IsInt32(jsonObject, TAG_SESSIONKEY_ID)) { authResponseContext_->remoteSessionKeyId = jsonObject[TAG_SESSIONKEY_ID].Get(); + LOGI("get remoteSessionKeyId"); } return; } @@ -421,7 +426,7 @@ void AuthMessageProcessor::ParsePublicKeyMessageExt(JsonObject &json) void AuthMessageProcessor::ParseAuthResponseMessageExt(JsonObject &json) { - LOGI("start"); + LOGI("start ParseAuthResponseMessageExt"); if (IsInt32(json, TAG_REPLY)) { authResponseContext_->reply = json[TAG_REPLY].Get(); } @@ -483,7 +488,7 @@ void AuthMessageProcessor::GetAuthReqMessage(JsonObject &json) int32_t AuthMessageProcessor::ParseAuthRequestMessage(JsonObject &json) { - LOGI("start"); + LOGI("start ParseAuthRequestMessage"); int32_t sliceNum = 0; int32_t idx = 0; if (!IsInt32(json, TAG_INDEX) || !IsInt32(json, TAG_SLICE_NUM)) { @@ -525,7 +530,7 @@ int32_t AuthMessageProcessor::ParseAuthRequestMessage(JsonObject &json) void AuthMessageProcessor::ParseAuthResponseMessage(JsonObject &json) { - LOGI("start"); + LOGI("start ParseAuthResponseMessage"); if (!IsInt32(json, TAG_REPLY)) { LOGE("AuthMessageProcessor::ParseAuthResponseMessage err json string, first time."); return; @@ -631,8 +636,6 @@ void AuthMessageProcessor::ParseNegotiateMessage(const JsonObject &json) } if (IsString(json, TAG_ACCOUNT_GROUPID)) { authResponseContext_->accountGroupIdHash = json[TAG_ACCOUNT_GROUPID].Get(); - } else { - authResponseContext_->accountGroupIdHash = OLD_VERSION_ACCOUNT; } if (IsString(json, TAG_HOST)) { authResponseContext_->hostPkgName = json[TAG_HOST].Get(); @@ -670,8 +673,6 @@ void AuthMessageProcessor::ParseRespNegotiateMessage(const JsonObject &json) } if (IsString(json, TAG_ACCOUNT_GROUPID)) { authResponseContext_->accountGroupIdHash = json[TAG_ACCOUNT_GROUPID].Get(); - } else { - authResponseContext_->accountGroupIdHash = OLD_VERSION_ACCOUNT; } if (IsString(json, TAG_NET_ID)) { authResponseContext_->networkId = json[TAG_NET_ID].Get(); @@ -708,7 +709,7 @@ std::shared_ptr AuthMessageProcessor::GetRequestContext() std::string AuthMessageProcessor::CreateDeviceAuthMessage(int32_t msgType, const uint8_t *data, uint32_t dataLen) { - LOGI("start, msgType %{public}d.", msgType); + LOGI("CreateDeviceAuthMessage start, msgType %{public}d.", msgType); JsonObject jsonObj; jsonObj[TAG_MSG_TYPE] = msgType; std::string authDataStr = std::string(reinterpret_cast(data), dataLen); diff --git a/services/implementation/src/authentication/auth_request_state.cpp b/services/implementation/src/authentication/auth_request_state.cpp index 6b086fef485083c13fb1ca308fb479d1bade5ccc..ff8c4120e541ced6d6234e35ffd5bc8a5a6d2fe8 100644 --- a/services/implementation/src/authentication/auth_request_state.cpp +++ b/services/implementation/src/authentication/auth_request_state.cpp @@ -25,6 +25,7 @@ int32_t AuthRequestState::Leave() return DM_OK; } +//LCOV_EXCL_START int32_t AuthRequestState::SetAuthManager(std::shared_ptr authManager) { authManager_ = std::move(authManager); @@ -246,5 +247,6 @@ int32_t AuthRequestReCheckMsgDone::Enter() stateAuthManager->RequestReCheckMsgDone(); return DM_OK; } +//LCOV_EXCL_STOP } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/implementation/src/authentication/auth_response_state.cpp b/services/implementation/src/authentication/auth_response_state.cpp index f076e5e70b657e1fffb1af487d86ba83701af349..38dae0cccfa8727a0caafbc580485e097e26345c 100644 --- a/services/implementation/src/authentication/auth_response_state.cpp +++ b/services/implementation/src/authentication/auth_response_state.cpp @@ -60,6 +60,7 @@ int32_t AuthResponseState::TransitionTo(std::shared_ptr state return DM_OK; } +//LCOV_EXCL_START int32_t AuthResponseInitState::GetStateType() { return AuthState::AUTH_RESPONSE_INIT; @@ -194,5 +195,6 @@ int32_t AuthResponseReCheckMsg::Enter() stateAuthManager->ResponseReCheckMsg(); return DM_OK; } +//LCOV_EXCL_STOP } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index e237a3678578b0d7485252b70826ec244ceb0fa1..1e839979ca07122fe5837d6a5e1e1f78d430a7c2 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -132,7 +132,7 @@ bool DmAuthManager::IsHmlSessionType() int32_t DmAuthManager::CheckAuthParamVaild(const std::string &pkgName, int32_t authType, const std::string &deviceId, const std::string &extra) { - LOGI("start."); + LOGI("DmAuthManager::CheckAuthParamVaild start."); if (authType < DM_AUTH_TYPE_MIN || authType > DM_AUTH_TYPE_MAX) { LOGE("CheckAuthParamVaild failed, authType is illegal."); return ERR_DM_AUTH_FAILED; @@ -275,7 +275,6 @@ void DmAuthManager::ParseJsonObject(JsonObject &jsonObject) if (authRequestContext_->peerBundleName == "") { authRequestContext_->peerBundleName = authRequestContext_->hostPkgName; } - LOGI("ParseJsonObject peerBundleName = %{public}s", authRequestContext_->peerBundleName.c_str()); } else { authRequestContext_->peerBundleName = authRequestContext_->hostPkgName; } @@ -343,7 +342,6 @@ void DmAuthManager::InitAuthState(const std::string &pkgName, int32_t authType, LOGE("extra string not a json type."); return; } - GetAuthParam(pkgName, authType, deviceId, extra); authMessageProcessor_->SetRequestContext(authRequestContext_); authRequestState_ = std::make_shared(); @@ -360,7 +358,7 @@ void DmAuthManager::InitAuthState(const std::string &pkgName, int32_t authType, int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t authType, const std::string &deviceId, const std::string &extra) { - LOGI("start auth type %{public}d.", authType); + LOGI("DmAuthManager::AuthenticateDevice start auth type %{public}d.", authType); processInfo_.pkgName = pkgName; { std::lock_guard lock(bindParamMutex_); diff --git a/services/implementation/src/authentication_v2/auth_manager.cpp b/services/implementation/src/authentication_v2/auth_manager.cpp index b38dc56227044113042fabda12f6346b33bb7ee3..34121d4cc28029a5d8c27d3f311789a8e406f11f 100644 --- a/services/implementation/src/authentication_v2/auth_manager.cpp +++ b/services/implementation/src/authentication_v2/auth_manager.cpp @@ -418,17 +418,6 @@ void AuthManager::ParseHmlInfoInJsonObject(const JsonObject &jsonObject) return; } -std::string AuthManager::GetBundleName(const JsonObject &jsonObject) -{ - if (!jsonObject.IsDiscarded() && jsonObject[BUNDLE_NAME_KEY].IsString()) { - return jsonObject[BUNDLE_NAME_KEY].Get(); - } - bool isSystemSA = false; - std::string bundleName; - AppManager::GetInstance().GetCallerName(isSystemSA, bundleName); - return bundleName; -} - void AuthManager::ParseJsonObject(const JsonObject &jsonObject) { if (IsString(jsonObject, DM_BUSINESS_ID)) { @@ -448,7 +437,6 @@ void AuthManager::ParseJsonObject(const JsonObject &jsonObject) std::string delaySecondsStr = jsonObject[PARAM_CLOSE_SESSION_DELAY_SECONDS].Get(); context_->connDelayCloseTime = GetCloseSessionDelaySeconds(delaySecondsStr); } - context_->accessee.bundleName = context_->accesser.bundleName; if (jsonObject[TAG_PEER_BUNDLE_NAME].IsString() && !jsonObject[TAG_PEER_BUNDLE_NAME].Get().empty()) { context_->accessee.bundleName = jsonObject[TAG_PEER_BUNDLE_NAME].Get(); @@ -456,14 +444,11 @@ void AuthManager::ParseJsonObject(const JsonObject &jsonObject) } else { context_->accessee.oldBundleName = context_->pkgName; } - context_->accesser.pkgName = context_->pkgName; context_->accessee.pkgName = context_->accesser.pkgName; - if (jsonObject[TAG_PEER_PKG_NAME].IsString()) { context_->accessee.pkgName = jsonObject[TAG_PEER_PKG_NAME].Get(); } - if (jsonObject[TAG_PEER_DISPLAY_ID].IsNumberInteger()) { context_->accessee.displayId = jsonObject[TAG_PEER_DISPLAY_ID].Get(); } @@ -472,11 +457,13 @@ void AuthManager::ParseJsonObject(const JsonObject &jsonObject) } else { context_->accesser.userId = MultipleUserConnector::GetFirstForegroundUserId(); } - + if (jsonObject[TAG_IS_NEED_AUTHENTICATE].IsString()) { + context_->isNeedAuthenticate = std::atoi(jsonObject[TAG_IS_NEED_AUTHENTICATE].Get().c_str()); + LOGI("isNeedAuthenticate: %{public}d.", context_->isNeedAuthenticate); + } if (context_->authType == AUTH_TYPE_PIN_ULTRASONIC) { ParseUltrasonicSide(jsonObject); } - ParseHmlInfoInJsonObject(jsonObject); ParseProxyJsonObject(jsonObject); return; @@ -581,6 +568,7 @@ void AuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, LOGE("extra string not a json type."); return; } + ParseJsonObject(jsonObject); context_->accesser.accountId = MultipleUserConnector::GetOhosAccountIdByUserId(context_->accesser.userId); @@ -969,8 +957,14 @@ void AuthSrcManager::AuthDeviceFinish(int64_t requestId) DmAuthStateType curState = context_->authStateMachine->GetCurState(); switch (curState) { case DmAuthStateType::AUTH_SRC_PIN_AUTH_DONE_STATE: - // ON_FINISH event occurs, start credential exchange - context_->authStateMachine->TransitionTo(std::make_shared()); + if (!context_->isNeedAuthenticate) { + LOGI("skip authenticate."); + context_->reason = ERR_DM_SKIP_AUTHENTICATE; + context_->authStateMachine->TransitionTo(std::make_shared()); + } else { + // ON_FINISH event occurs, start credential exchange + context_->authStateMachine->TransitionTo(std::make_shared()); + } break; default: break; diff --git a/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp b/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp index d6d13bfc97b5c14cbd15aa17988e683cba51a894..eeec84f29a86b364986b0004a39d7c263c8078d8 100644 --- a/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp +++ b/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp @@ -194,6 +194,50 @@ DmAuthStateType AuthSrcDataSyncState::GetStateType() return DmAuthStateType::AUTH_SRC_DATA_SYNC_STATE; } +void AuthSrcDataSyncState::GetPeerDeviceId(std::shared_ptr context, std::string &peerDeviceId) +{ + CHECK_NULL_VOID(context); + if (context->accesser.aclProfiles.find(DM_IDENTICAL_ACCOUNT) != context->accesser.aclProfiles.end()) { + peerDeviceId = context->accesser.aclProfiles[DM_IDENTICAL_ACCOUNT].GetAccessee().GetAccesseeDeviceId(); + if (!peerDeviceId.empty()) { + return; + } + } + if (context->accesser.aclProfiles.find(DM_SHARE) != context->accesser.aclProfiles.end()) { + peerDeviceId = context->accesser.aclProfiles[DM_SHARE].GetAccessee().GetAccesseeDeviceId(); + if (peerDeviceId == context->accesser.deviceId) { + peerDeviceId = context->accesser.aclProfiles[DM_SHARE].GetAccesser().GetAccesserDeviceId(); + } + if (!peerDeviceId.empty()) { + return; + } + } + if (context->accesser.aclProfiles.find(DM_POINT_TO_POINT) != context->accesser.aclProfiles.end()) { + peerDeviceId = context->accesser.aclProfiles[DM_POINT_TO_POINT].GetAccessee().GetAccesseeDeviceId(); + if (peerDeviceId == context->accesser.deviceId) { + peerDeviceId = context->accesser.aclProfiles[DM_POINT_TO_POINT].GetAccesser().GetAccesserDeviceId(); + } + if (!peerDeviceId.empty()) { + return; + } + } + if (!context->IsProxyBind || context->subjectProxyOnes.empty()) { + return; + } + for (auto &app : context->subjectProxyOnes) { + if (app.proxyAccesser.aclProfiles.find(DM_POINT_TO_POINT) != app.proxyAccesser.aclProfiles.end()) { + peerDeviceId = app.proxyAccesser.aclProfiles[DM_POINT_TO_POINT].GetAccessee().GetAccesseeDeviceId(); + if (peerDeviceId == context->accesser.deviceId) { + peerDeviceId = app.proxyAccesser.aclProfiles[DM_POINT_TO_POINT].GetAccesser().GetAccesserDeviceId(); + } + if (!peerDeviceId.empty()) { + return; + } + } + } + LOGE("failed"); +} + // Received 200 end message, send 201 int32_t AuthSinkFinishState::Action(std::shared_ptr context) { @@ -231,7 +275,10 @@ DmAuthStateType AuthSinkFinishState::GetStateType() int32_t AuthSrcFinishState::Action(std::shared_ptr context) { LOGI("AuthSrcFinishState::Action start"); - if (context->reason != DM_OK && context->reason != DM_BIND_TRUST_TARGET) { + if (context->reason == ERR_DM_SKIP_AUTHENTICATE && !context->isNeedAuthenticate) { + context->authMessageProcessor->CreateAndSendMsg(MSG_TYPE_AUTH_REQ_FINISH, context); + context->state = static_cast(GetStateType()); + } else if (context->reason != DM_OK && context->reason != DM_BIND_TRUST_TARGET) { context->authMessageProcessor->CreateAndSendMsg(MSG_TYPE_AUTH_REQ_FINISH, context); } else { context->state = static_cast(GetStateType()); diff --git a/services/implementation/src/authentication_v2/auth_stages/auth_negotiate.cpp b/services/implementation/src/authentication_v2/auth_stages/auth_negotiate.cpp index c674341998405dd3c00a5d20463389133a8212ff..19e9c2261cc1046f71f35c1aa2674aff43f5cdc0 100644 --- a/services/implementation/src/authentication_v2/auth_stages/auth_negotiate.cpp +++ b/services/implementation/src/authentication_v2/auth_stages/auth_negotiate.cpp @@ -24,6 +24,8 @@ #include "app_manager.h" #include "business_event.h" #include "distributed_device_profile_client.h" +#include "dm_auth_cert.h" +#include "dm_auth_attest_common.h" #include "dm_crypto.h" #include "dm_log.h" #include "dm_timer.h" @@ -234,6 +236,7 @@ int32_t AuthSinkNegotiateStateMachine::Action(std::shared_ptr con DmAuthState::HandleAuthenticateTimeout(context, name); }); } + // To be compatible with historical versions, use ConvertSrcVersion to get the actual version on the source side. std::string preVersion = std::string(DM_VERSION_5_0_OLD_MAX); LOGI("AuthSinkNegotiateStateMachine::Action start version compare %{public}s to %{public}s", diff --git a/services/implementation/src/authentication_v2/dm_auth_manager_base.cpp b/services/implementation/src/authentication_v2/dm_auth_manager_base.cpp index f5ec91846baf9fd921a0d78a17e69238a1c2bafe..82b760096dfd77894efeaaadca8b70164579d056 100644 --- a/services/implementation/src/authentication_v2/dm_auth_manager_base.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_manager_base.cpp @@ -58,7 +58,7 @@ const char* TAG_HOST_PKGLABEL = "hostPkgLabel"; const char* TAG_REMOTE_DEVICE_NAME = "REMOTE_DEVICE_NAME"; const char* TAG_HOST = "HOST"; const char* TAG_PROXY_CONTEXT_ID = "proxyContextId"; - +const char* TAG_IS_NEED_AUTHENTICATE = "isNeedAuthenticate"; const char* APP_OPERATION_KEY = "appOperation"; const char* TARGET_PKG_NAME_KEY = "targetPkgName"; const char* CUSTOM_DESCRIPTION_KEY = "customDescription"; @@ -541,7 +541,7 @@ int32_t AuthManagerBase::EndDream() bool AuthManagerBase::CheckProcessNameInWhiteList(const std::string &processName) { - LOGI("AuthManagerBase::CheckProcessNameInWhiteList start"); + LOGI("DmAuthState::CheckProcessNameInWhiteList start"); if (processName.empty()) { LOGE("processName is empty"); return false; diff --git a/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp b/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp index 43f367ea373d73d62bd35b0dd2f81116ac354050..f8501377ae890812679aaf75707e8ebdf1b11751 100644 --- a/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp @@ -837,8 +837,9 @@ std::string DmAuthMessageProcessor::CreateMessage(DmMessageType msgType, std::sh return ""; } int32_t ret = (this->*(itr->second))(context, jsonObj); - LOGI("start. message is %{public}s", GetAnonyJsonString(jsonObj.Dump()).c_str()); - return (ret == DM_OK) ? jsonObj.Dump() : ""; + std::string strMsg = jsonObj.Dump(); + LOGI("start. message is %{public}s", GetAnonyJsonString(strMsg).c_str()); + return (ret == DM_OK) ? strMsg : ""; } int32_t DmAuthMessageProcessor::CreateCredentialNegotiateMessage(std::shared_ptr context, diff --git a/services/implementation/src/authentication_v2/dm_auth_state.cpp b/services/implementation/src/authentication_v2/dm_auth_state.cpp index a8da668324b9563fbbd500f756a8933fbf9f05ef..72ce91c02cc6d6cd3ce4c0d07c1a619fd1099106 100644 --- a/services/implementation/src/authentication_v2/dm_auth_state.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_state.cpp @@ -52,6 +52,7 @@ constexpr const static char* ONBINDRESULT_MAPPING_LIST[ONBINDRESULT_MAPPING_NUM] "cast_engine_service", }; + const std::map NEW_AND_OLD_STATE_MAPPING = { { DmAuthStateType::AUTH_SRC_FINISH_STATE, DmAuthStatus::STATUS_DM_AUTH_FINISH }, { DmAuthStateType::AUTH_SINK_FINISH_STATE, DmAuthStatus::STATUS_DM_SINK_AUTH_FINISH }, @@ -76,7 +77,8 @@ const std::map NEW_AND_OLD_STATE_MAPPING = { const std::map NEW_AND_OLD_REPLAY_MAPPING = { { DM_ALREADY_AUTHED, SOFTBUS_OK }, { SOFTBUS_OK, SOFTBUS_OK }, - { DM_BIND_TRUST_TARGET, DM_OK } + { DM_BIND_TRUST_TARGET, DM_OK }, + { ERR_DM_SKIP_AUTHENTICATE, DM_OK }, }; int32_t DmAuthState::GetTaskTimeout(std::shared_ptr context, const char* taskName, int32_t taskTimeOut) @@ -130,7 +132,6 @@ void DmAuthState::SourceFinish(std::shared_ptr context) GetOutputReplay(context->accesser.bundleName, context->reason), GetOutputState(context->state), GenerateBindResultContent(context)); context->successFinished = true; - if (context->reason != DM_OK && context->reason != DM_ALREADY_AUTHED && context->reason != DM_BIND_TRUST_TARGET) { BindFail(context); } @@ -625,6 +626,18 @@ void DmAuthState::FilterProfilesByContext( profiles.assign(aclProfilesVec.begin(), aclProfilesVec.end()); } +void DmAuthState::GetPeerDeviceId(std::shared_ptr context, std::string &peerDeviceId) +{ + CHECK_NULL_VOID(context); + peerDeviceId = context->accesser.aclProfiles[DM_IDENTICAL_ACCOUNT].GetAccessee().GetAccesseeDeviceId(); + if (peerDeviceId.empty()) { + peerDeviceId = context->accesser.aclProfiles[DM_SHARE].GetAccessee().GetAccesseeDeviceId(); + } + if (peerDeviceId.empty()) { + peerDeviceId = context->accesser.aclProfiles[DM_POINT_TO_POINT].GetAccessee().GetAccesseeDeviceId(); + } +} + bool DmAuthState::GetSessionKey(std::shared_ptr context) { int32_t skId = 0; @@ -801,50 +814,6 @@ void DmAuthState::DeleteAclAndSk(std::shared_ptr context, DeviceProfileConnector::GetInstance().DeleteAccessControlById(profile.GetAccessControlId()); } -void DmAuthState::GetPeerDeviceId(std::shared_ptr context, std::string &peerDeviceId) -{ - CHECK_NULL_VOID(context); - if (context->accesser.aclProfiles.find(DM_IDENTICAL_ACCOUNT) != context->accesser.aclProfiles.end()) { - peerDeviceId = context->accesser.aclProfiles[DM_IDENTICAL_ACCOUNT].GetAccessee().GetAccesseeDeviceId(); - if (!peerDeviceId.empty()) { - return; - } - } - if (context->accesser.aclProfiles.find(DM_SHARE) != context->accesser.aclProfiles.end()) { - peerDeviceId = context->accesser.aclProfiles[DM_SHARE].GetAccessee().GetAccesseeDeviceId(); - if (peerDeviceId == context->accesser.deviceId) { - peerDeviceId = context->accesser.aclProfiles[DM_SHARE].GetAccesser().GetAccesserDeviceId(); - } - if (!peerDeviceId.empty()) { - return; - } - } - if (context->accesser.aclProfiles.find(DM_POINT_TO_POINT) != context->accesser.aclProfiles.end()) { - peerDeviceId = context->accesser.aclProfiles[DM_POINT_TO_POINT].GetAccessee().GetAccesseeDeviceId(); - if (peerDeviceId == context->accesser.deviceId) { - peerDeviceId = context->accesser.aclProfiles[DM_POINT_TO_POINT].GetAccesser().GetAccesserDeviceId(); - } - if (!peerDeviceId.empty()) { - return; - } - } - if (!context->IsProxyBind || context->subjectProxyOnes.empty()) { - return; - } - for (auto &app : context->subjectProxyOnes) { - if (app.proxyAccesser.aclProfiles.find(DM_POINT_TO_POINT) != app.proxyAccesser.aclProfiles.end()) { - peerDeviceId = app.proxyAccesser.aclProfiles[DM_POINT_TO_POINT].GetAccessee().GetAccesseeDeviceId(); - if (peerDeviceId == context->accesser.deviceId) { - peerDeviceId = app.proxyAccesser.aclProfiles[DM_POINT_TO_POINT].GetAccesser().GetAccesserDeviceId(); - } - if (!peerDeviceId.empty()) { - return; - } - } - } - LOGE("failed"); -} - bool DmAuthState::IsMatchCredentialAndP2pACL(JsonObject &credInfo, std::string &credId, const DistributedDeviceProfile::AccessControlProfile &profile) { diff --git a/services/implementation/src/credential/dm_credential_manager.cpp b/services/implementation/src/credential/dm_credential_manager.cpp index a41f67390a101c4709804e0c99c4a1bf691ef63b..1ea8e7eaaea7ff0d218435b867fd951f7a170c45 100644 --- a/services/implementation/src/credential/dm_credential_manager.cpp +++ b/services/implementation/src/credential/dm_credential_manager.cpp @@ -97,7 +97,7 @@ DmCredentialManager::~DmCredentialManager() int32_t DmCredentialManager::RequestCredential(const std::string &reqJsonStr, std::string &returnJsonStr) { - LOGI("start."); + LOGI("start to request credential."); char localDeviceId[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); JsonObject jsonObject(reqJsonStr); @@ -158,7 +158,7 @@ int32_t DmCredentialManager::ImportCredential(const std::string &pkgName, const int32_t DmCredentialManager::ImportRemoteCredentialExt(const std::string &credentialInfo) { - LOGI("start."); + LOGI("ImportRemoteCredentialExt start."); if (hiChainConnector_->addMultiMembersExt(credentialInfo) != DM_OK) { LOGE("Failed to add member to group."); return ERR_DM_FAILED; @@ -168,7 +168,7 @@ int32_t DmCredentialManager::ImportRemoteCredentialExt(const std::string &creden int32_t DmCredentialManager::ImportLocalCredential(const std::string &credentialInfo) { - LOGI(" start"); + LOGI("ImportLocalCredential start"); JsonObject jsonObject(credentialInfo); if (jsonObject.IsDiscarded()) { LOGE("credentialInfo string not a json type."); @@ -195,7 +195,7 @@ int32_t DmCredentialManager::ImportLocalCredential(const std::string &credential LOGI("ImportLocalCredential credentialData err"); return ERR_DM_FAILED; } - LOGI("get credentialData success!"); + LOGI("ImportLocalCredential get credentialData success!"); JsonObject jsonOutObj; if (GetCredentialData(credentialInfo, vecCredentialData[0], jsonOutObj) != DM_OK) { LOGE("failed to get credentialData field from input credential."); @@ -254,7 +254,7 @@ int32_t DmCredentialManager::DeleteCredential(const std::string &pkgName, const void DmCredentialManager::OnGroupResultExt(int32_t action, const std::string &resultInfo) { - LOGI("action %{public}d, resultInfo %{public}s.", action, resultInfo.c_str()); + LOGI("DmCredentialManager::OnGroupResultExt action %{public}d, resultInfo %{public}s.", action, resultInfo.c_str()); CHECK_NULL_VOID(listener_); listener_->OnCredentialResult(processInfo_, action, resultInfo); } @@ -262,7 +262,7 @@ void DmCredentialManager::OnGroupResultExt(int32_t action, const std::string &re void DmCredentialManager::OnGroupResult(int64_t requestId, int32_t action, const std::string &resultInfo) { - LOGI("OnGroupResult"); + LOGI("DmCredentialManager::OnImportResult"); if (requestId_ != requestId) { return; } @@ -280,7 +280,7 @@ int32_t DmCredentialManager::RegisterCredentialCallback(const std::string &pkgNa #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) MultipleUserConnector::GetCallerUserId(userId); #endif - LOGI("pkgName = %{public}s", GetAnonyString(pkgName).c_str()); + LOGI("DmCredentialManager::RegisterCredentialCallback pkgName = %{public}s", GetAnonyString(pkgName).c_str()); { std::lock_guard autoLock(locks_); processInfo_.pkgName = pkgName; @@ -296,7 +296,7 @@ int32_t DmCredentialManager::UnRegisterCredentialCallback(const std::string &pkg LOGE("DmCredentialManager::UnRegisterCredentialStateCallback input param is empty"); return ERR_DM_FAILED; } - LOGI("pkgName = %{public}s", + LOGI("DmCredentialManager::UnRegisterCredentialStateCallback pkgName = %{public}s", GetAnonyString(pkgName).c_str()); { std::lock_guard autoLock(locks_); diff --git a/services/implementation/src/dependency/MSDP/spatial_location_callback_impl.cpp b/services/implementation/src/dependency/MSDP/spatial_location_callback_impl.cpp index 43a8682b727296fe90310d5f8461ca68fedc5574..6de474673870e6a75f047c73c541212265d5a82c 100644 --- a/services/implementation/src/dependency/MSDP/spatial_location_callback_impl.cpp +++ b/services/implementation/src/dependency/MSDP/spatial_location_callback_impl.cpp @@ -35,7 +35,7 @@ SpatialLocationCallbackImpl::~SpatialLocationCallbackImpl() void SpatialLocationCallbackImpl::OnPinCodeChanged(const Msdp::PinCodeResponse &pinCodeResponse) { - LOGI("Start."); + LOGI("SpatialLocationCallbackImpl::OnPinCodeChanged Start."); if (pinCodeResponse.pincode.length() != pinCodeLength) { LOGE("OnPinCodeChanged pincode length error."); return; diff --git a/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp b/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp index 23756a20f80569f0f46a5a4dddf95d24d07ac51a..5ee041f79a3dbe82dc407234eb3c5188fa838178 100644 --- a/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp +++ b/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp @@ -27,6 +27,12 @@ namespace OHOS { namespace DistributedHardware { +namespace { + +constexpr int32_t HICHAIN_DATA_SIZE = 10240; + +} + std::shared_ptr HiChainAuthConnector::dmDeviceAuthCallback_ = nullptr; std::map> HiChainAuthConnector::dmDeviceAuthCallbackMap_; std::mutex HiChainAuthConnector::dmDeviceAuthCallbackMutex_; @@ -283,6 +289,11 @@ int32_t HiChainAuthConnector::AuthCredentialPinCode(int32_t osAccountId, int64_t bool HiChainAuthConnector::onTransmit(int64_t requestId, const uint8_t *data, uint32_t dataLen) { LOGI("AuthDevice onTransmit, requestId %{public}" PRId64, requestId); + if (dataLen > HICHAIN_DATA_SIZE) { + LOGE("dataLen = %{public}u is invalid.", dataLen); + return false; + } + CHECK_NULL_RETURN(data, false); auto dmDeviceAuthCallback = GetDeviceAuthCallback(requestId); if (dmDeviceAuthCallback == nullptr) { LOGE("HiChainAuthConnector::onTransmit dmDeviceAuthCallback_ is nullptr."); @@ -336,6 +347,11 @@ void HiChainAuthConnector::onError(int64_t requestId, int operationCode, int err void HiChainAuthConnector::onSessionKeyReturned(int64_t requestId, const uint8_t *sessionKey, uint32_t sessionKeyLen) { LOGI("start."); + if (sessionKeyLen > HICHAIN_DATA_SIZE) { + LOGE("sessionKeyLen = %{public}u is invalid.", sessionKeyLen); + return; + } + CHECK_NULL_VOID(sessionKey); auto dmDeviceAuthCallback = GetDeviceAuthCallback(requestId); if (dmDeviceAuthCallback == nullptr) { LOGE("HiChainAuthConnector::onSessionKeyReturned dmDeviceAuthCallback_ is nullptr."); diff --git a/services/implementation/src/dependency/hichain/hichain_connector.cpp b/services/implementation/src/dependency/hichain/hichain_connector.cpp index ea4ddd7b2d72325fe39e3fa3f42fc89581b5e26a..203201fad8ddfc9eb4d890509d78482e1b5f08d8 100644 --- a/services/implementation/src/dependency/hichain/hichain_connector.cpp +++ b/services/implementation/src/dependency/hichain/hichain_connector.cpp @@ -29,6 +29,7 @@ #include "dm_random.h" #include "dm_radar_helper.h" #include "hichain_connector_callback.h" +#include "json_object.h" #include "multiple_user_connector.h" #include "json_object.h" #include "parameter.h" diff --git a/services/implementation/src/dependency/softbus/softbus_connector.cpp b/services/implementation/src/dependency/softbus/softbus_connector.cpp index ea2ddcb5cf19af81908d75871e33f114d3a6b43a..f171d4593bdd96cab5802b9ea6140f5679513c71 100644 --- a/services/implementation/src/dependency/softbus/softbus_connector.cpp +++ b/services/implementation/src/dependency/softbus/softbus_connector.cpp @@ -78,7 +78,7 @@ SoftbusConnector::~SoftbusConnector() void SoftbusConnector::SyncAclList(int32_t userId, std::string credId, int32_t sessionKeyId, int32_t aclId) { - LOGI("userId:%{public}d, credId:%{public}s, sessionKeyId:%{public}d, aclId:%{public}d", + LOGI("SyncAclList userId:%{public}d, credId:%{public}s, sessionKeyId:%{public}d, aclId:%{public}d", userId, credId.c_str(), sessionKeyId, aclId); #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) // 根据skid删除sk,删除skid @@ -98,7 +98,6 @@ void SoftbusConnector::SyncAclList(int32_t userId, std::string credId, #endif } - #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) int32_t SoftbusConnector::SyncLocalAclList5_1_0(const std::string localUdid, const std::string remoteUdid, DistributedDeviceProfile::AccessControlProfile &localAcl, std::vector &acLStrList) @@ -540,7 +539,7 @@ void SoftbusConnector::OnSoftbusJoinLNNResult(ConnectionAddr *addr, const char * LOGE("addr is null."); return; } - if (addr->type != CONNECTION_ADDR_SESSION_WITH_KEY) { + if (addr->type != CONNECTION_ADDR_SESSION) { LOGI("addr type is not session."); return; } @@ -562,7 +561,7 @@ std::string SoftbusConnector::GetDeviceUdidByUdidHash(const std::string &udidHas return iter.first; } } - LOGE("failed, udidHash: %{public}s", GetAnonyString(udidHash).c_str()); + LOGE("fail to GetUdidByUdidHash, udidHash: %{public}s", GetAnonyString(udidHash).c_str()); return udidHash; } @@ -648,7 +647,7 @@ int32_t SoftbusConnector::AddMemberToDiscoverMap(const std::string &deviceId, st std::string SoftbusConnector::GetNetworkIdByDeviceId(const std::string &deviceId) { - LOGI("start"); + LOGI("SoftbusConnector::GetNetworkIdByDeviceId"); int32_t deviceCount = 0; NodeBasicInfo *nodeInfo = nullptr; if (GetAllNodeDeviceInfo(DM_PKG_NAME, &nodeInfo, &deviceCount) != DM_OK) { @@ -673,70 +672,70 @@ std::string SoftbusConnector::GetNetworkIdByDeviceId(const std::string &deviceId void SoftbusConnector::SetProcessInfo(ProcessInfo processInfo) { - LOGI("start"); + LOGI("SoftbusConnector::SetProcessInfo"); std::lock_guard lock(processInfoVecMutex_); processInfoVec_.push_back(processInfo); } void SoftbusConnector::SetProcessInfoVec(std::vector processInfoVec) { - LOGI("start"); + LOGI("SoftbusConnector::SetProcessInfoVec"); std::lock_guard lock(processInfoVecMutex_); processInfoVec_ = processInfoVec; } std::vector SoftbusConnector::GetProcessInfo() { - LOGI("start"); + LOGI("SoftbusConnector::GetProcessInfo"); std::lock_guard lock(processInfoVecMutex_); return processInfoVec_; } void SoftbusConnector::ClearProcessInfo() { - LOGI("start"); + LOGI("SoftbusConnector::ClearProcessInfo"); std::lock_guard lock(processInfoVecMutex_); processInfoVec_.clear(); } void SoftbusConnector::SetChangeProcessInfo(ProcessInfo processInfo) { - LOGI("start"); + LOGI("SoftbusConnector::SetChangeProcessInfo"); std::lock_guard lock(processChangeInfoVecMutex_); processChangeInfoVec_.push_back(processInfo); } std::vector SoftbusConnector::GetChangeProcessInfo() { - LOGI("start"); + LOGI("SoftbusConnector::GetChangeProcessInfo"); std::lock_guard lock(processChangeInfoVecMutex_); return processChangeInfoVec_; } void SoftbusConnector::ClearChangeProcessInfo() { - LOGI("start"); + LOGI("SoftbusConnector::ClearChangeProcessInfo"); std::lock_guard lock(processChangeInfoVecMutex_); processChangeInfoVec_.clear(); } void SoftbusConnector::HandleDeviceOnline(std::string deviceId, int32_t authForm) { - LOGI("start"); + LOGI("SoftbusConnector::HandleDeviceOnline"); deviceStateManagerCallback_->OnDeviceOnline(deviceId, authForm); return; } void SoftbusConnector::HandleDeviceOffline(std::string deviceId) { - LOGI("start"); + LOGI("SoftbusConnector::HandleDeviceOffline"); deviceStateManagerCallback_->OnDeviceOffline(deviceId); return; } void SoftbusConnector::DeleteOffLineTimer(std::string &udidHash) { - LOGI("start"); + LOGI("SoftbusConnector::DeleteOffLineTimer"); remoteUdidHash_ = udidHash; if (deviceStateManagerCallback_ != nullptr) { deviceStateManagerCallback_->DeleteOffLineTimer(udidHash); @@ -829,7 +828,7 @@ bool SoftbusConnector::CheckIsOnline(const std::string &targetDeviceId) DmDeviceInfo SoftbusConnector::GetDeviceInfoByDeviceId(const std::string &deviceId) { - LOGI("start"); + LOGI("SoftbusConnector::GetDeviceInfoBydeviceId"); DmDeviceInfo info; int32_t deviceCount = 0; NodeBasicInfo *nodeInfo = nullptr; diff --git a/services/implementation/src/dependency/softbus/softbus_session.cpp b/services/implementation/src/dependency/softbus/softbus_session.cpp index 1563f8b861969b505a82fda35348ba07a38436ca..db16ac673e1ea949e2744f400b3960d85f3011be 100644 --- a/services/implementation/src/dependency/softbus/softbus_session.cpp +++ b/services/implementation/src/dependency/softbus/softbus_session.cpp @@ -20,10 +20,11 @@ #include "dm_dfx_constants.h" #include "dm_hitrace.h" #include "dm_log.h" +#include "dm_softbus_cache.h" +#include "multiple_user_connector.h" #include "json_object.h" #include "softbus_connector.h" #include "softbus_error_code.h" - namespace OHOS { namespace DistributedHardware { std::shared_ptr SoftbusSession::sessionCallback_ = nullptr; @@ -122,6 +123,7 @@ int SoftbusSession::OnSessionOpened(int sessionId, int result) return DM_OK; } int32_t sessionSide = GetSessionSide(sessionId); + CHECK_NULL_RETURN(sessionCallback_, ERR_DM_POINT_NULL); sessionCallback_->OnSessionOpened(sessionId, sessionSide, result); return DM_OK; } diff --git a/services/implementation/src/devicestate/dm_device_state_manager.cpp b/services/implementation/src/devicestate/dm_device_state_manager.cpp index e77e579b7fd319f9819489bac22c05e69606b21f..5122b7d61c2279bf6f9183df2ec6c5d451cb077f 100644 --- a/services/implementation/src/devicestate/dm_device_state_manager.cpp +++ b/services/implementation/src/devicestate/dm_device_state_manager.cpp @@ -62,7 +62,7 @@ int32_t DmDeviceStateManager::RegisterSoftbusStateCallback() void DmDeviceStateManager::SaveOnlineDeviceInfo(const DmDeviceInfo &info) { - LOGI("begin, deviceId = %{public}s", GetAnonyString(std::string(info.deviceId)).c_str()); + LOGI("SaveOnlineDeviceInfo begin, deviceId = %{public}s", GetAnonyString(std::string(info.deviceId)).c_str()); std::string udid; if (SoftbusConnector::GetUdidByNetworkId(info.networkId, udid) == DM_OK) { std::string uuid; @@ -73,7 +73,7 @@ void DmDeviceStateManager::SaveOnlineDeviceInfo(const DmDeviceInfo &info) remoteDeviceInfos_[uuid] = saveInfo; stateDeviceInfos_[udid] = saveInfo; } - LOGI("complete, networkId = %{public}s, udid = %{public}s, uuid = %{public}s", + LOGI("SaveOnlineDeviceInfo complete, networkId = %{public}s, udid = %{public}s, uuid = %{public}s", GetAnonyString(std::string(info.networkId)).c_str(), GetAnonyString(udid).c_str(), GetAnonyString(uuid).c_str()); } @@ -81,7 +81,7 @@ void DmDeviceStateManager::SaveOnlineDeviceInfo(const DmDeviceInfo &info) void DmDeviceStateManager::DeleteOfflineDeviceInfo(const DmDeviceInfo &info) { - LOGI("begin, deviceId = %{public}s", GetAnonyString(std::string(info.deviceId)).c_str()); + LOGI("DeleteOfflineDeviceInfo begin, deviceId = %{public}s", GetAnonyString(std::string(info.deviceId)).c_str()); std::lock_guard mutexLock(remoteDeviceInfosMutex_); std::string deviceId = std::string(info.deviceId); for (auto iter: remoteDeviceInfos_) { @@ -102,7 +102,7 @@ void DmDeviceStateManager::DeleteOfflineDeviceInfo(const DmDeviceInfo &info) void DmDeviceStateManager::OnDeviceOnline(std::string deviceId, int32_t authForm) { - LOGI("OnDeviceOnline, deviceId = %{public}s", GetAnonyString(deviceId).c_str()); + LOGI("DmDeviceStateManager::OnDeviceOnline, deviceId = %{public}s", GetAnonyString(deviceId).c_str()); DmDeviceInfo devInfo = softbusConnector_->GetDeviceInfoByDeviceId(deviceId); if (devInfo.deviceId[0] == '\0') { LOGE("deviceId is empty."); @@ -122,7 +122,7 @@ void DmDeviceStateManager::OnDeviceOnline(std::string deviceId, int32_t authForm void DmDeviceStateManager::OnDeviceOffline(std::string deviceId) { - LOGI("OnDeviceOffline, deviceId = %{public}s", GetAnonyString(deviceId).c_str()); + LOGI("DmDeviceStateManager::OnDeviceOffline, deviceId = %{public}s", GetAnonyString(deviceId).c_str()); DmDeviceInfo devInfo; { std::lock_guard mutexLock(remoteDeviceInfosMutex_); @@ -177,7 +177,6 @@ void DmDeviceStateManager::ProcessDeviceStateChange(const DmDeviceState devState CHECK_NULL_VOID(listener_); for (const auto &item : processInfoVec) { if (!item.pkgName.empty()) { - LOGI("ProcessDeviceStateChange, pkgName = %{public}s", item.pkgName.c_str()); listener_->OnDeviceStateChange(item, devState, devInfo); } } @@ -356,27 +355,27 @@ int32_t DmDeviceStateManager::DeleteSkCredAndAcl(const std::vector void DmDeviceStateManager::StartEventThread() { - LOGD("StartEventThread begin"); + LOGI("StartEventThread begin"); eventTask_.threadRunning_ = true; eventTask_.queueThread_ = std::thread([this]() { this->ThreadLoop(); }); - LOGD("StartEventThread complete"); + LOGI("StartEventThread complete"); } void DmDeviceStateManager::StopEventThread() { - LOGD("StopEventThread begin"); + LOGI("StopEventThread begin"); eventTask_.threadRunning_ = false; eventTask_.queueCond_.notify_all(); eventTask_.queueFullCond_.notify_all(); if (eventTask_.queueThread_.joinable()) { eventTask_.queueThread_.join(); } - LOGD("StopEventThread complete"); + LOGI("StopEventThread complete"); } int32_t DmDeviceStateManager::AddTask(const std::shared_ptr &task) { - LOGD("AddTask begin, eventId: %{public}d", task->GetEventId()); + LOGI("AddTask begin, eventId: %{public}d", task->GetEventId()); { std::unique_lock lock(eventTask_.queueMtx_); while (eventTask_.queue_.size() >= DM_EVENT_QUEUE_CAPACITY) { @@ -385,13 +384,13 @@ int32_t DmDeviceStateManager::AddTask(const std::shared_ptr &task) eventTask_.queue_.push(task); } eventTask_.queueCond_.notify_one(); - LOGD("AddTask complete"); + LOGI("AddTask complete"); return DM_OK; } void DmDeviceStateManager::ThreadLoop() { - LOGD("ThreadLoop begin"); + LOGI("ThreadLoop begin"); int32_t ret = pthread_setname_np(pthread_self(), THREAD_LOOP); if (ret != DM_OK) { LOGE("ThreadLoop setname failed."); @@ -413,16 +412,16 @@ void DmDeviceStateManager::ThreadLoop() RunTask(task); } } - LOGD("ThreadLoop end"); + LOGI("ThreadLoop end"); } void DmDeviceStateManager::RunTask(const std::shared_ptr &task) { - LOGD("RunTask begin, eventId: %{public}d", task->GetEventId()); + LOGI("RunTask begin, eventId: %{public}d", task->GetEventId()); if (task->GetEventId() == DM_NOTIFY_EVENT_ONDEVICEREADY) { OnDbReady(std::string(DM_PKG_NAME), task->GetDeviceId()); } - LOGD("RunTask complete"); + LOGI("RunTask complete"); } DmAuthForm DmDeviceStateManager::GetAuthForm(const std::string &networkId) @@ -448,7 +447,7 @@ DmAuthForm DmDeviceStateManager::GetAuthForm(const std::string &networkId) int32_t DmDeviceStateManager::ProcNotifyEvent(const int32_t eventId, const std::string &deviceId) { - LOGD("ProcNotifyEvent in, eventId: %{public}d", eventId); + LOGI("ProcNotifyEvent in, eventId: %{public}d", eventId); return AddTask(std::make_shared(eventId, deviceId)); } @@ -493,7 +492,7 @@ void DmDeviceStateManager::ChangeDeviceInfo(const DmDeviceInfo &info) std::string DmDeviceStateManager::GetUdidByNetWorkId(std::string networkId) { - LOGI("networkId %{public}s", GetAnonyString(networkId).c_str()); + LOGI("DmDeviceStateManager::GetUdidByNetWorkId networkId %{public}s", GetAnonyString(networkId).c_str()); { std::lock_guard mutexLock(remoteDeviceInfosMutex_); for (auto &iter : stateDeviceInfos_) { @@ -511,7 +510,7 @@ int32_t DmDeviceStateManager::DeleteGroupByDP(const std::string &deviceId) { std::vector profiles = DeviceProfileConnector::GetInstance().GetAccessControlProfile(); - LOGI("AccessControlProfile size is %{public}zu", profiles.size()); + LOGI("DeleteGroupByDP, AccessControlProfile size is %{public}zu", profiles.size()); std::vector delPkgNameVec; for (auto &item : profiles) { std::string trustDeviceId = item.GetTrustDeviceId(); diff --git a/services/service/include/device_manager_service_listener.h b/services/service/include/device_manager_service_listener.h index 216835016a96327f3e1961ba1e80cab2facb1e72..85b1b8464f4e283dade1a12a9ae69bc462632de9 100644 --- a/services/service/include/device_manager_service_listener.h +++ b/services/service/include/device_manager_service_listener.h @@ -77,10 +77,10 @@ public: void OnCredentialAuthStatus(const ProcessInfo &processInfo, const std::string &deviceList, uint16_t deviceTypeId, int32_t errcode) override; void OnAppUnintall(const std::string &pkgName) override; - void OnSinkBindResult(const ProcessInfo &processInfo, const PeerTargetId &targetId, int32_t result, - int32_t status, std::string content) override; void OnProcessRemove(const ProcessInfo &processInfo) override; void OnDevStateCallbackAdd(const ProcessInfo &processInfo, const std::vector &deviceList) override; + void OnSinkBindResult(const ProcessInfo &processInfo, const PeerTargetId &targetId, int32_t result, + int32_t status, std::string content) override; void OnGetDeviceProfileInfoListResult(const ProcessInfo &processInfo, const std::vector &deviceProfileInfos, int32_t code) override; void OnGetDeviceIconInfoResult(const ProcessInfo &processInfo, diff --git a/services/service/include/discovery/discovery_manager.h b/services/service/include/discovery/discovery_manager.h index a4c6ebc4cc789ee2bdadd7bbf07035a0989df96f..aef045a02b610f673981d5413fdedba5df720240 100644 --- a/services/service/include/discovery/discovery_manager.h +++ b/services/service/include/discovery/discovery_manager.h @@ -96,10 +96,10 @@ private: void OnDeviceFound(const std::string &pkgName, const uint32_t capabilityType, const DmDeviceInfo &info, const DeviceFilterPara &filterPara); void UpdateInfoFreq(const std::map &discoverParam, DmSubscribeInfo &dmSubInfo); - void UpdateInfoMedium(const std::map &discoverParam, DmSubscribeInfo &dmSubInfo); std::string AddMultiUserIdentify(const std::string &pkgName); std::string RemoveMultiUserIdentify(const std::string &pkgName); void GetPkgNameAndUserId(const std::string &pkgName, std::string &callerPkgName, int32_t &userId); + void UpdateInfoMedium(const std::map &discoverParam, DmSubscribeInfo &dmSubInfo); int32_t GenInnerSubId(const std::string &pkgName, uint16_t subId); int32_t GetAndRemoveInnerSubId(const std::string &pkgName, uint16_t subId); int32_t StopDiscoveringByInnerSubId(const std::string &pkgName, uint16_t subscribeId); diff --git a/services/service/include/idevice_manager_service_impl.h b/services/service/include/idevice_manager_service_impl.h index 949542bedeb80a1f942cc5aecc0edaf66183fd77..9b09957eeb1a111e195f79d06d5247319c6c81ea 100644 --- a/services/service/include/idevice_manager_service_impl.h +++ b/services/service/include/idevice_manager_service_impl.h @@ -220,6 +220,8 @@ public: virtual std::unordered_map GetAppTrustDeviceIdList(std::string pkgname) = 0; virtual int32_t DpAclAdd(const std::string &udid) = 0; + virtual void DeleteAlwaysAllowTimeOut() = 0; + virtual void CheckDeleteCredential(const std::string &remoteUdid, int32_t remoteUserId) = 0; virtual int32_t IsSameAccount(const std::string &udid) = 0; virtual uint64_t GetTokenIdByNameAndDeviceId(std::string extra, std::string requestDeviceId) = 0; virtual void ScreenCommonEventCallback(std::string commonEventType) = 0; @@ -265,8 +267,6 @@ public: virtual void HandleDeviceUnBind(int32_t bindType, const std::string &peerUdid, const std::string &localUdid, int32_t localUserId, const std::string &localAccountId) = 0; virtual int32_t RegisterAuthenticationType(int32_t authenticationType) = 0; - virtual void DeleteAlwaysAllowTimeOut() = 0; - virtual void CheckDeleteCredential(const std::string &remoteUdid, int32_t remoteUserId) = 0; virtual void HandleCredentialDeleted(const char *credId, const char *credInfo, const std::string &localUdid, std::string &remoteUdid, bool &isSendBroadCast) = 0; virtual void HandleShareUnbindBroadCast(const std::string &credId, const int32_t &userId, diff --git a/services/service/src/advertise/advertise_manager.cpp b/services/service/src/advertise/advertise_manager.cpp index 5acf52a6def9f1306aa13299f246636449420a7b..0f481a4314c10246cd67d1d283ad5d7f4b0ffbec 100644 --- a/services/service/src/advertise/advertise_manager.cpp +++ b/services/service/src/advertise/advertise_manager.cpp @@ -42,11 +42,11 @@ AdvertiseManager::~AdvertiseManager() int32_t AdvertiseManager::StartAdvertising(const std::string &pkgName, const std::map &advertiseParam) { + LOGI("AdvertiseManager::StartAdvertising begin for pkgName = %{public}s.", pkgName.c_str()); if (pkgName.empty()) { LOGE("Invalid parameter, pkgName is empty."); return ERR_DM_INPUT_PARA_INVALID; } - LOGI("begin for pkgName = %{public}s.", pkgName.c_str()); DmPublishInfo dmPubInfo; ConfigAdvParam(advertiseParam, &dmPubInfo, pkgName); std::string capability = DM_CAPABILITY_OSD; @@ -66,7 +66,7 @@ int32_t AdvertiseManager::StartAdvertising(const std::string &pkgName, int32_t ret = softbusListener_->PublishSoftbusLNN(dmPubInfo, capability, customData); if (ret != DM_OK) { - LOGE("failed, softbus publish lnn ret: %{public}d", ret); + LOGE("StartAdvertising failed, softbus publish lnn ret: %{public}d", ret); return ret; } @@ -128,11 +128,12 @@ void AdvertiseManager::ConfigAdvParam(const std::map & int32_t AdvertiseManager::StopAdvertising(const std::string &pkgName, int32_t publishId) { + LOGI("AdvertiseManager::StopDiscovering begin for pkgName = %{public}s, publishId = %{public}d.", pkgName.c_str(), + publishId); if (pkgName.empty()) { LOGE("Invalid parameter, pkgName is empty."); return ERR_DM_INPUT_PARA_INVALID; } - LOGI("begin for pkgName = %{public}s, publishId = %{public}d.", pkgName.c_str(), publishId); int32_t innerPublishId = GetAndRemoveInnerPublishId(pkgName, publishId); if (innerPublishId == DM_INVALID_FLAG_ID) { LOGE("Failed: cannot find pkgName in cache map."); @@ -144,7 +145,7 @@ int32_t AdvertiseManager::StopAdvertising(const std::string &pkgName, int32_t pu void AdvertiseManager::HandleAutoStopAdvertise(const std::string &timerName, const std::string &pkgName, int32_t publishId) { - LOGI("auto stop advertise task timeout, timerName=%{public}s", timerName.c_str()); + LOGI("HandleAutoStopAdvertise, auto stop advertise task timeout, timerName=%{public}s", timerName.c_str()); StopAdvertising(pkgName, publishId); } @@ -155,9 +156,14 @@ int32_t AdvertiseManager::GenInnerPublishId(const std::string &pkgName, int32_t std::lock_guard autoLock(pubMapLock_); CHECK_SIZE_RETURN(pkgName2PubIdMap_, DM_INVALID_FLAG_ID); CHECK_SIZE_RETURN(publishIdSet_, DM_INVALID_FLAG_ID); - if (pkgName2PubIdMap_[pkgName].find(publishId) != pkgName2PubIdMap_[pkgName].end()) { + if (pkgName2PubIdMap_.find(pkgName) != pkgName2PubIdMap_.end() && + pkgName2PubIdMap_[pkgName].find(publishId) != pkgName2PubIdMap_[pkgName].end()) { return pkgName2PubIdMap_[pkgName][publishId]; } + if (publishIdSet_.size() >= (DM_MAX_RANDOM - 1)) { + LOGE("The publishIdSet_ cache size exceed the limit."); + return tempPublishId; + } if (pkgName2PubIdMap_.find(pkgName) == pkgName2PubIdMap_.end()) { pkgName2PubIdMap_[pkgName] = std::map(); } @@ -198,15 +204,17 @@ int32_t AdvertiseManager::GetAndRemoveInnerPublishId(const std::string &pkgName, void AdvertiseManager::ClearPublishIdCache(const std::string &pkgName) { + LOGI("Begin for pkgName = %{public}s.", pkgName.c_str()); if (pkgName.empty()) { LOGE("Invalid parameter, pkgName is empty."); return; } - LOGI("Begin for pkgName = %{public}s.", pkgName.c_str()); std::lock_guard autoLock(pubMapLock_); - for (auto iter : pkgName2PubIdMap_[pkgName]) { - softbusListener_->StopPublishSoftbusLNN(iter.second); - publishIdSet_.erase(iter.second); + if (pkgName2PubIdMap_.find(pkgName) != pkgName2PubIdMap_.end()) { + for (auto iter : pkgName2PubIdMap_[pkgName]) { + softbusListener_->StopPublishSoftbusLNN(iter.second); + publishIdSet_.erase(iter.second); + } } pkgName2PubIdMap_.erase(pkgName); } diff --git a/services/service/src/discovery/discovery_manager.cpp b/services/service/src/discovery/discovery_manager.cpp index c349189fc235d770c85c667eede469e11d730ef0..186a53c2f66c7a626e71a468aa7511c8ccf0d09e 100644 --- a/services/service/src/discovery/discovery_manager.cpp +++ b/services/service/src/discovery/discovery_manager.cpp @@ -59,11 +59,11 @@ DiscoveryManager::~DiscoveryManager() int32_t DiscoveryManager::EnableDiscoveryListener(const std::string &pkgName, const std::map &discoverParam, const std::map &filterOptions) { + LOGI("DiscoveryManager::EnableDiscoveryListener begin for pkgName = %{public}s.", pkgName.c_str()); if (pkgName.empty()) { LOGE("Invalid parameter, pkgName is empty."); return ERR_DM_INPUT_PARA_INVALID; } - LOGI("begin for pkgName = %{public}s.", pkgName.c_str()); std::string pkgNameTemp = AddMultiUserIdentify(pkgName); DmSubscribeInfo dmSubInfo; dmSubInfo.subscribeId = DM_INVALID_FLAG_ID; @@ -78,7 +78,7 @@ int32_t DiscoveryManager::EnableDiscoveryListener(const std::string &pkgName, UpdateInfoFreq(discoverParam, dmSubInfo); if (discoverParam.find(PARAM_KEY_META_TYPE) != discoverParam.end()) { std::string metaType = discoverParam.find(PARAM_KEY_META_TYPE)->second; - LOGI("input MetaType = %{public}s.", metaType.c_str()); + LOGI("EnableDiscoveryListener, input MetaType = %{public}s in discoverParam map.", metaType.c_str()); } if (discoverParam.find(PARAM_KEY_SUBSCRIBE_ID) != discoverParam.end() && IsNumberString((discoverParam.find(PARAM_KEY_SUBSCRIBE_ID)->second))) { @@ -89,11 +89,11 @@ int32_t DiscoveryManager::EnableDiscoveryListener(const std::string &pkgName, if (discoverParam.find(PARAM_KEY_DISC_CAPABILITY) != discoverParam.end()) { std::string capability = discoverParam.find(PARAM_KEY_DISC_CAPABILITY)->second; if (strcpy_s(dmSubInfo.capability, DM_MAX_DEVICE_CAPABILITY_LEN, capability.c_str()) != EOK) { - LOGE("failed, capability copy err."); + LOGI("EnableDiscoveryListener failed, capability copy err."); return ERR_DM_ENABLE_DISCOVERY_LISTENER_FAILED; } } - LOGI("capability = %{public}s,", std::string(dmSubInfo.capability).c_str()); + LOGI("EnableDiscoveryListener capability = %{public}s,", std::string(dmSubInfo.capability).c_str()); { std::lock_guard capLock(capabilityMapLocks_); capabilityMap_[pkgNameTemp] = std::string(dmSubInfo.capability); @@ -101,7 +101,7 @@ int32_t DiscoveryManager::EnableDiscoveryListener(const std::string &pkgName, UpdateInfoMedium(discoverParam, dmSubInfo); int32_t ret = softbusListener_->RefreshSoftbusLNN(DM_PKG_NAME, dmSubInfo, LNN_DISC_CAPABILITY); if (ret != DM_OK) { - LOGE("failed, softbus refresh lnn ret: %{public}d.", ret); + LOGE("EnableDiscoveryListener failed, softbus refresh lnn ret: %{public}d.", ret); return ret; } softbusListener_->RegisterSoftbusLnnOpsCbk(pkgNameTemp, shared_from_this()); @@ -111,11 +111,11 @@ int32_t DiscoveryManager::EnableDiscoveryListener(const std::string &pkgName, int32_t DiscoveryManager::DisableDiscoveryListener(const std::string &pkgName, const std::map &extraParam) { + LOGI("DiscoveryManager::DisableDiscoveryListener begin for pkgName = %{public}s.", pkgName.c_str()); if (pkgName.empty()) { LOGE("Invalid parameter, pkgName is empty."); return ERR_DM_INPUT_PARA_INVALID; } - LOGI("begin for pkgName = %{public}s.", pkgName.c_str()); std::string pkgNameTemp = RemoveMultiUserIdentify(pkgName); if (extraParam.find(PARAM_KEY_META_TYPE) != extraParam.end()) { LOGI("DisableDiscoveryListener, input MetaType = %{public}s", @@ -128,6 +128,10 @@ int32_t DiscoveryManager::DisableDiscoveryListener(const std::string &pkgName, static_cast(std::atoi((extraParam.find(PARAM_KEY_SUBSCRIBE_ID)->second).c_str())); innerSubId = GetAndRemoveInnerSubId(pkgNameTemp, externalSubId); } + if (innerSubId == DM_INVALID_FLAG_ID) { + LOGE("Invalid parameter, cannot find subscribeId in cache map."); + return ERR_DM_INPUT_PARA_INVALID; + } { std::lock_guard capLock(capabilityMapLocks_); if (capabilityMap_.find(pkgNameTemp) != capabilityMap_.end()) { @@ -135,21 +139,17 @@ int32_t DiscoveryManager::DisableDiscoveryListener(const std::string &pkgName, } } softbusListener_->UnRegisterSoftbusLnnOpsCbk(pkgNameTemp); - if (innerSubId == DM_INVALID_FLAG_ID) { - LOGE("Invalid parameter, cannot find subscribeId in cache map."); - return ERR_DM_INPUT_PARA_INVALID; - } return softbusListener_->StopRefreshSoftbusLNN(innerSubId); } int32_t DiscoveryManager::StartDiscovering(const std::string &pkgName, const std::map &discoverParam, const std::map &filterOptions) { + LOGI("DiscoveryManager::StartDiscovering begin for pkgName = %{public}s.", pkgName.c_str()); if (pkgName.empty()) { LOGE("Invalid parameter, pkgName is empty."); return ERR_DM_INPUT_PARA_INVALID; } - LOGI("begin for pkgName = %{public}s.", pkgName.c_str()); std::string pkgNameTemp = AddMultiUserIdentify(pkgName); DmSubscribeInfo dmSubInfo; ConfigDiscParam(discoverParam, &dmSubInfo); @@ -187,6 +187,7 @@ int32_t DiscoveryManager::StartDiscovering(const std::string &pkgName, void DiscoveryManager::ConfigDiscParam(const std::map &discoverParam, DmSubscribeInfo *dmSubInfo) { + LOGI("DiscoveryManager::ConfigDiscParam"); if (dmSubInfo == nullptr) { LOGE("ConfigDiscParam failed, dmSubInfo is nullptr."); return; @@ -221,7 +222,7 @@ int32_t DiscoveryManager::StartDiscovering4MineLibary(const std::string &pkgName LOGE("capability copy err."); return ERR_DM_START_DISCOVERING_FAILED; } - LOGI("mine meta node process, pkgName = %{public}s, capability = %{public}s", + LOGI("StartDiscovering for mine meta node process, pkgName = %{public}s, capability = %{public}s", pkgName.c_str(), std::string(dmSubInfo.capability).c_str()); { std::lock_guard capLock(capabilityMapLocks_); @@ -250,7 +251,7 @@ int32_t DiscoveryManager::StartDiscoveringNoMetaType(const std::string &pkgName, LOGE("capability copy err."); return ERR_DM_START_DISCOVERING_FAILED; } - LOGI("standard meta node process, pkgName = %{public}s, capability = %{public}s", + LOGI("StartDiscovering for standard meta node process, pkgName = %{public}s, capability = %{public}s", pkgName.c_str(), std::string(dmSubInfo.capability).c_str()); { @@ -280,24 +281,28 @@ int32_t DiscoveryManager::StartDiscovering4MetaType(const std::string &pkgName, } switch (metaType) { case MetaNodeType::PROXY_SHARE: + LOGI("StartDiscovering4MetaType for share meta node process."); if (strcpy_s(dmSubInfo.capability, DM_MAX_DEVICE_CAPABILITY_LEN, DM_CAPABILITY_SHARE) != EOK) { LOGE("capability copy error."); return ERR_DM_FAILED; } break; case MetaNodeType::PROXY_WEAR: + LOGI("StartDiscovering4MetaType for wear meta node process."); if (strcpy_s(dmSubInfo.capability, DM_MAX_DEVICE_CAPABILITY_LEN, DM_CAPABILITY_WEAR) != EOK) { LOGE("capability copy error."); return ERR_DM_FAILED; } break; case MetaNodeType::PROXY_CASTPLUS: + LOGI("StartDiscovering4MetaType for cast_plus meta node process."); if (strcpy_s(dmSubInfo.capability, DM_MAX_DEVICE_CAPABILITY_LEN, DM_CAPABILITY_CASTPLUS) != EOK) { LOGE("capability copy error."); return ERR_DM_FAILED; } break; default: + LOGE("StartDiscovering4MetaType failed, unsupport meta type : %{public}d.", metaType); return ERR_DM_UNSUPPORTED_METHOD; } @@ -305,7 +310,7 @@ int32_t DiscoveryManager::StartDiscovering4MetaType(const std::string &pkgName, if (param.find(PARAM_KEY_CUSTOM_DATA) != param.end()) { customData = param.find(PARAM_KEY_CUSTOM_DATA)->second; } - LOGI("capability = %{public}s,", std::string(dmSubInfo.capability).c_str()); + LOGI("StartDiscovering4MetaType capability = %{public}s,", std::string(dmSubInfo.capability).c_str()); { std::lock_guard capLock(capabilityMapLocks_); CHECK_SIZE_RETURN(capabilityMap_, ERR_DM_START_DISCOVERING_FAILED); @@ -321,22 +326,22 @@ int32_t DiscoveryManager::StartDiscovering4MetaType(const std::string &pkgName, int32_t DiscoveryManager::StopDiscovering(const std::string &pkgName, uint16_t subscribeId) { + LOGI("DiscoveryManager::StopDiscovering begin for pkgName = %{public}s.", pkgName.c_str()); if (pkgName.empty()) { LOGE("Invalid parameter, pkgName is empty."); return ERR_DM_INPUT_PARA_INVALID; } - LOGI("begin for pkgName = %{public}s.", pkgName.c_str()); std::string pkgNameTemp = RemoveMultiUserIdentify(pkgName); return StopDiscoveringByInnerSubId(pkgNameTemp, subscribeId); } int32_t DiscoveryManager::StopDiscoveringByInnerSubId(const std::string &pkgName, uint16_t subscribeId) { + LOGI("DiscoveryManager::StopDiscovering begin for pkgName = %{public}s.", pkgName.c_str()); if (pkgName.empty()) { LOGE("Invalid parameter, pkgName is empty."); return ERR_DM_INPUT_PARA_INVALID; } - LOGI("begin for pkgName = %{public}s.", pkgName.c_str()); uint16_t innerSubId = static_cast(GetAndRemoveInnerSubId(pkgName, subscribeId)); if (innerSubId == DM_INVALID_FLAG_ID) { LOGE("Invalid parameter, cannot find subscribeId in cache map."); @@ -551,7 +556,7 @@ int32_t DiscoveryManager::HandleDiscoveryQueue(const std::string &pkgName, uint1 void DiscoveryManager::HandleDiscoveryTimeout(const std::string &pkgName) { - LOGI("pkgName: %{public}s.", pkgName.c_str()); + LOGI("DiscoveryManager::HandleDiscoveryTimeout, pkgName: %{public}s.", pkgName.c_str()); uint16_t subscribeId = 0; { std::lock_guard autoLock(locks_); @@ -648,12 +653,13 @@ bool DiscoveryManager::IsCommonDependencyReady() } dpConnector_ = func(); isSoLoaded_ = true; + LOGI("IsCommonDependencyReady success."); return true; } bool DiscoveryManager::CloseCommonDependencyObj() { - LOGI("start."); + LOGI("DiscoveryManager::CloseCommonDependencyObj start."); std::lock_guard lock(comDependencyLoadLock); if (!isSoLoaded_ && (dpConnector_ == nullptr) && (dpConnectorHandle_ == nullptr)) { return true; @@ -667,6 +673,7 @@ bool DiscoveryManager::CloseCommonDependencyObj() isSoLoaded_ = false; dpConnector_ = nullptr; dpConnectorHandle_ = nullptr; + LOGI("close libdevicemanagerdependency so success."); return true; } #endif diff --git a/services/service/src/hichain/hichain_listener.cpp b/services/service/src/hichain/hichain_listener.cpp index 278b00e46ca68e504069d7418a79c2b93e388250..10dff7a023f5ced86727603fd83ca9690aefaa54 100644 --- a/services/service/src/hichain/hichain_listener.cpp +++ b/services/service/src/hichain/hichain_listener.cpp @@ -16,7 +16,9 @@ #include "hichain_listener.h" #include "device_manager_service.h" +#include "dm_anonymous.h" #include "dm_constants.h" +#include "dm_log.h" #include "dm_random.h" #include "multiple_user_connector.h" @@ -108,7 +110,7 @@ HichainListener::~HichainListener() //LCOV_EXCL_START void HichainListener::RegisterDataChangeCb() { - LOGI("start"); + LOGI("HichainListener::RegisterDataChangeCb start"); if (deviceGroupManager_ == nullptr) { LOGE("deviceGroupManager_ is null!"); return; @@ -118,12 +120,12 @@ void HichainListener::RegisterDataChangeCb() LOGE("[HICHAIN]regDataChangeListener failed with ret: %{public}d.", ret); return; } - LOGI("success!"); + LOGI("RegisterDataChangeCb success!"); } void HichainListener::RegisterCredentialCb() { - LOGI("start"); + LOGI("HichainListener::RegisterCredentialCb start"); if (credManager_ == nullptr) { LOGE("credManager_ is null!"); return; @@ -133,13 +135,13 @@ void HichainListener::RegisterCredentialCb() LOGE("[HICHAIN]registerChangeListener failed with ret: %{public}d.", ret); return; } - LOGI("success!"); + LOGI("RegisterCredentialCb success!"); } //LCOV_EXCL_STOP void HichainListener::OnHichainDeviceUnBound(const char *peerUdid, const char *groupInfo) { - LOGI("start"); + LOGI("HichainListener::onDeviceUnBound start"); if (peerUdid == nullptr || groupInfo == nullptr) { LOGE("peerUdid or groupInfo is null!"); return; @@ -178,7 +180,7 @@ void HichainListener::OnCredentialDeleted(const char *credId, const char *credIn LOGE("credId or credInfo is invalid"); return; } - LOGI("start, credId: %{public}s.", GetAnonyString(credId).c_str()); + LOGI("HichainListener::OnCredentialDeleted start, credId: %{public}s.", GetAnonyString(credId).c_str()); JsonObject jsonObject; jsonObject.Parse(std::string(credInfo)); if (jsonObject.IsDiscarded()) { @@ -191,7 +193,7 @@ void HichainListener::OnCredentialDeleted(const char *credId, const char *credIn credType = static_cast(jsonObject[credTypeTag].Get()); } if (credType != ACCOUNT_SHARED) { - LOGE("credType %{public}d is invalid.", credType); + LOGE("credType: %{public}d is invalid.", credType); return; } DeviceManagerService::GetInstance().HandleCredentialDeleted(credId, credInfo); @@ -200,7 +202,7 @@ void HichainListener::OnCredentialDeleted(const char *credId, const char *credIn void HichainListener::DeleteAllGroup(const std::string &localUdid, const std::vector &backgroundUserIds) { - LOGI("start"); + LOGI("OnStart HichainListener::DeleteAllGroup"); for (auto &userId : backgroundUserIds) { std::vector groupList; GetRelatedGroups(userId, localUdid, groupList); @@ -240,11 +242,11 @@ int32_t HichainListener::GetRelatedGroupsExt(int32_t userId, const std::string & int32_t HichainListener::GetRelatedGroupsCommon(int32_t userId, const std::string &deviceId, const char* pkgName, std::vector &groupList) { + LOGI("Start to get related groups."); if (userId < 0) { LOGE("user id failed"); return ERR_DM_FAILED; } - LOGI("Start."); uint32_t groupNum = 0; char *returnGroups = nullptr; int32_t ret = diff --git a/services/service/src/ipc/lite/ipc_cmd_parser.cpp b/services/service/src/ipc/lite/ipc_cmd_parser.cpp index 00d71d515835952432481037fa2937cea161cb35..37bec133e610254c2a34d144830565b3639e44ea 100644 --- a/services/service/src/ipc/lite/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/lite/ipc_cmd_parser.cpp @@ -251,39 +251,5 @@ ON_IPC_SERVER_CMD(SYNC_CALLBACK, IpcIo &req, IpcIo &reply) int32_t ret = DeviceManagerServiceNotify::GetInstance().RegisterCallBack(dmCommonNotifyEvent, processInfo); WriteInt32(&reply, ret); } - -ON_IPC_SERVER_CMD(START_DISCOVERING, IpcIo &req, IpcIo &reply) -{ - LOGI("start."); - std::string pkgName = (const char *)ReadString(&req, nullptr); - std::string discParaStr = (const char *)ReadString(&req, nullptr); - std::string filterOpStr = (const char *)ReadString(&req, nullptr); - std::map discoverParam; - ParseMapFromJsonString(discParaStr, discoverParam); - std::map filterOptions; - ParseMapFromJsonString(filterOpStr, filterOptions); - int32_t result = DeviceManagerService::GetInstance().StartDiscovering(pkgName, discoverParam, filterOptions); - WriteInt32(&reply, result); -} - -ON_IPC_SERVER_CMD(STOP_DISCOVERING, IpcIo &req, IpcIo &reply) -{ - LOGI("start."); - std::string pkgName = (const char *)ReadString(&req, nullptr); - std::string discParaStr = (const char *)ReadString(&req, nullptr); - std::map discoverParam; - ParseMapFromJsonString(discParaStr, discoverParam); - int32_t result = DeviceManagerService::GetInstance().StopDiscovering(pkgName, discoverParam); - WriteInt32(&reply, result); -} - -ON_IPC_SERVER_CMD(GET_LOCAL_DEVICE_INFO, IpcIo &req, IpcIo &reply) -{ - LOGI("start."); - DmDeviceInfo localDeviceInfo; - int32_t result = DeviceManagerService::GetInstance().GetLocalDeviceInfo(localDeviceInfo); - EncodeDmDeviceInfo(localDeviceInfo, reply); - WriteInt32(&reply, result); -} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/src/ipc/standard/ipc_server_stub.cpp b/services/service/src/ipc/standard/ipc_server_stub.cpp index acc8499e74fc3f0e1a283b0c4a5e5c60f9b88311..1d618481ffa1a658c482b83b659f3427c88d29a8 100644 --- a/services/service/src/ipc/standard/ipc_server_stub.cpp +++ b/services/service/src/ipc/standard/ipc_server_stub.cpp @@ -18,6 +18,10 @@ #include #include +#include "device_manager_ipc_interface_code.h" +#include "device_manager_service.h" +#include "dm_log.h" +#include "if_system_ability_manager.h" #include "ipc_cmd_register.h" #include "ipc_skeleton.h" #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) @@ -27,6 +31,7 @@ #include "mem_mgr_client.h" #include "mem_mgr_proxy.h" #endif // SUPPORT_MEMMGR +#include "string_ex.h" #include "system_ability_definition.h" #include "datetime_ex.h" #include "device_manager_service.h" @@ -302,15 +307,16 @@ ServiceRunningState IpcServerStub::QueryServiceState() const int32_t IpcServerStub::RegisterDeviceManagerListener(const ProcessInfo &processInfo, sptr listener) { + LOGI("RegisterDeviceManagerListener start"); if (processInfo.pkgName.empty() || listener == nullptr) { LOGE("RegisterDeviceManagerListener error: input parameter invalid."); return ERR_DM_POINT_NULL; } - LOGI("pkgName: %{public}s", processInfo.pkgName.c_str()); #ifdef SUPPORT_MEMMGR int pid = getpid(); Memory::MemMgrClient::GetInstance().SetCritical(pid, true, DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID); #endif // SUPPORT_MEMMGR + LOGI("Register device manager listener for package name: %{public}s", processInfo.pkgName.c_str()); std::lock_guard autoLock(listenerLock_); auto iter = dmListener_.find(processInfo); if (iter != dmListener_.end()) { @@ -332,14 +338,16 @@ int32_t IpcServerStub::RegisterDeviceManagerListener(const ProcessInfo &processI if (!listener->AsObject()->AddDeathRecipient(appRecipient)) { LOGE("AddDeathRecipient Failed"); } + LOGI("Checking the number of listeners."); if (dmListener_.size() > MAX_CALLBACK_NUM || appRecipient_.size() > MAX_CALLBACK_NUM) { LOGE("dmListener_ or appRecipient_ size exceed the limit!"); return ERR_DM_FAILED; } dmListener_[processInfo] = listener; appRecipient_[processInfo] = appRecipient; + LOGI("Add system sa."); AddSystemSA(processInfo.pkgName); - LOGI("complete."); + LOGI("Register listener complete."); return DM_OK; } @@ -349,7 +357,7 @@ int32_t IpcServerStub::UnRegisterDeviceManagerListener(const ProcessInfo &proces LOGE("Invalid parameter, pkgName is empty."); return ERR_DM_INPUT_PARA_INVALID; } - LOGI("In, pkgName: %{public}s", processInfo.pkgName.c_str()); + LOGI("IpcServerStub::UnRegisterDeviceManagerListener In, pkgName: %{public}s", processInfo.pkgName.c_str()); std::lock_guard autoLock(listenerLock_); auto listenerIter = dmListener_.find(processInfo); if (listenerIter == dmListener_.end()) { @@ -417,7 +425,7 @@ const ProcessInfo IpcServerStub::GetDmListenerPkgName(const wptr int32_t IpcServerStub::Dump(int32_t fd, const std::vector& args) { - LOGI("start."); + LOGI("DistributedHardwareService Dump."); std::vector argsStr {}; for (auto item : args) { argsStr.emplace_back(Str16ToStr8(item)); diff --git a/services/service/src/pinholder/pin_holder_session.cpp b/services/service/src/pinholder/pin_holder_session.cpp index 44b8a3b8de30bb9eb9e4c1f01e25dd5fb743d681..1b1e45013f79275473f72255b1a4553f22b847fa 100644 --- a/services/service/src/pinholder/pin_holder_session.cpp +++ b/services/service/src/pinholder/pin_holder_session.cpp @@ -38,6 +38,7 @@ int32_t PinHolderSession::RegisterSessionCallback(std::shared_ptr autoLock(pinHolderSessionLock_); pinholderSessionCallback_ = callback; + LOGI("end."); return DM_OK; } @@ -45,6 +46,7 @@ int32_t PinHolderSession::UnRegisterSessionCallback() { std::lock_guard autoLock(pinHolderSessionLock_); pinholderSessionCallback_ = nullptr; + LOGI("end."); return DM_OK; } @@ -62,7 +64,7 @@ int32_t PinHolderSession::OpenSessionServer(const PeerTargetId &targetId) LOGE("[SOFTBUS]open session error, sessionId: %{public}d.", sessionId); return sessionId; } - LOGI("success. sessionId: %{public}d.", sessionId); + LOGI("OpenAuthSession success. sessionId: %{public}d.", sessionId); return sessionId; } @@ -80,7 +82,7 @@ int PinHolderSession::OnSessionOpened(int sessionId, int result) std::lock_guard autoLock(pinHolderSessionLock_); tempCbk = pinholderSessionCallback_; } - LOGI("[SOFTBUS]OnSessionOpened sessionId: %{public}d", sessionId); + LOGI("[SOFTBUS]OnBytesReceived sessionId: %{public}d", sessionId); if (tempCbk == nullptr) { LOGE("OnSessionOpened error, pinholderSessionCallback_ is nullptr."); return ERR_DM_FAILED; diff --git a/services/service/src/softbus/mine_softbus_listener.cpp b/services/service/src/softbus/mine_softbus_listener.cpp index f476a967c4fc199a9b05a67f3053126a8876ecc3..47dee89eae7ba2e4fa0f0965cb2adaba3605b126 100644 --- a/services/service/src/softbus/mine_softbus_listener.cpp +++ b/services/service/src/softbus/mine_softbus_listener.cpp @@ -526,13 +526,13 @@ int32_t MineSoftbusListener::SendBroadcastInfo(const string &pkgName, SubscribeI #if (defined(MINE_HARMONY)) subscribeInfo.custData = base64Out; subscribeInfo.custDataLen = base64OutLen; +#endif IRefreshCallback softbusRefreshCallback_ = SoftbusListener::GetSoftbusRefreshCb(); retValue = RefreshLNN(DM_PKG_NAME, &subscribeInfo, &softbusRefreshCallback_); if (retValue != SOFTBUS_OK) { LOGE("failed to start to refresh quick discovery with ret: %{public}d.", retValue); return ERR_DM_FAILED; } -#endif LOGI("send search broadcast info by softbus successfully with dataLen: %{public}zu, pkgName: %{public}s.", base64OutLen, pkgName.c_str()); return DM_OK; diff --git a/services/service/src/softbus/softbus_listener.cpp b/services/service/src/softbus/softbus_listener.cpp index e57d4338dd199ac80ea1dbe8fa8bfe94b3fd8ac9..2568637f08a0c661d3aff6b9f2032f690c59b440 100644 --- a/services/service/src/softbus/softbus_listener.cpp +++ b/services/service/src/softbus/softbus_listener.cpp @@ -732,7 +732,7 @@ int32_t SoftbusListener::InitSoftPublishLNN() int32_t SoftbusListener::RefreshSoftbusLNN(const char *pkgName, const DmSubscribeInfo &dmSubInfo, const std::string &customData) { - LOGI("begin, subscribeId: %{public}d.", dmSubInfo.subscribeId); + LOGI("RefreshSoftbusLNN begin, subscribeId: %{public}d.", dmSubInfo.subscribeId); SubscribeInfo subscribeInfo; if (memset_s(&subscribeInfo, sizeof(SubscribeInfo), 0, sizeof(SubscribeInfo)) != DM_OK) { LOGE("RefreshSoftbusLNN memset_s failed."); @@ -778,7 +778,7 @@ int32_t SoftbusListener::RefreshSoftbusLNN(const char *pkgName, const DmSubscrib int32_t SoftbusListener::StopRefreshSoftbusLNN(uint16_t subscribeId) { - LOGI("begin, subscribeId: %{public}d.", (int32_t)subscribeId); + LOGI("StopRefreshSoftbusLNN begin, subscribeId: %{public}d.", (int32_t)subscribeId); { std::lock_guard lock(g_lockDeviceIdSet); deviceIdSet.clear(); @@ -874,7 +874,7 @@ int32_t SoftbusListener::GetTrustedDeviceList(std::vector &deviceI { int32_t ret = SoftbusCache::GetInstance().GetDeviceInfoFromCache(deviceInfoList); size_t deviceCount = deviceInfoList.size(); - LOGI("size is %{public}zu.", deviceCount); + LOGI("Success from cache deviceInfoList size is %{public}zu.", deviceCount); return ret; } @@ -1115,7 +1115,7 @@ int32_t SoftbusListener::GetNetworkTypeByNetworkId(const char *networkId, int32_ return ret; } networkType = tempNetworkType; - LOGI("networkType %{public}d.", tempNetworkType); + LOGI("GetNetworkTypeByNetworkId networkType %{public}d.", tempNetworkType); return DM_OK; } @@ -1224,6 +1224,7 @@ bool SoftbusListener::IsDmRadarHelperReady() bool SoftbusListener::CloseDmRadarHelperObj(std::string name) { (void)name; + LOGI("SoftbusListener::CloseDmRadarHelperObj start."); std::lock_guard lock(g_radarLoadLock); if (!isRadarSoLoad_ && (dmRadarHelper_ == nullptr) && (radarHandle_ == nullptr)) { return true; @@ -1237,7 +1238,7 @@ bool SoftbusListener::CloseDmRadarHelperObj(std::string name) isRadarSoLoad_ = false; dmRadarHelper_ = nullptr; radarHandle_ = nullptr; - LOGI("success."); + LOGI("close libdevicemanagerradar so success."); return true; } @@ -1322,7 +1323,7 @@ std::string SoftbusListener::GetHostPkgName() void SoftbusListener::SendAclChangedBroadcast(const std::string &msg) { - LOGI("start"); + LOGI("SendAclChangedBroadcast"); if (SyncTrustedRelationShip(DM_PKG_NAME, msg.c_str(), msg.length()) != DM_OK) { LOGE("SyncTrustedRelationShip failed."); } @@ -1343,7 +1344,7 @@ int32_t SoftbusListener::GetDeviceScreenStatus(const char *networkId, int32_t &s return ret; } screenStatus = devScreenStatus; - LOGI("screenStatus: %{public}d.", devScreenStatus); + LOGI("GetDeviceScreenStatus screenStatus: %{public}d.", devScreenStatus); return DM_OK; } @@ -1353,6 +1354,7 @@ int32_t SoftbusListener::SetForegroundUserIdsToDSoftBus(const std::string &remot #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) NotifyUserIds notifyUserIds(remoteUdid, userIds); std::string msg = notifyUserIds.ToString(); + LOGI("Notify remote userid to dsoftbus, msg: %{public}s", GetAnonyString(msg).c_str()); return DM_OK; #else (void)remoteUdid; @@ -1364,7 +1366,7 @@ int32_t SoftbusListener::SetForegroundUserIdsToDSoftBus(const std::string &remot //LCOV_EXCL_START void SoftbusListener::DeleteCacheDeviceInfo() { - LOGI("start."); + LOGI("DeleteCacheDeviceInfo start."); SoftbusCache::GetInstance().DeleteLocalDeviceInfo(); std::vector onlineDevInfoVec; SoftbusCache::GetInstance().GetDeviceInfoFromCache(onlineDevInfoVec); @@ -1382,11 +1384,12 @@ void SoftbusListener::DeleteCacheDeviceInfo() int32_t SoftbusListener::SetLocalDisplayName(const std::string &displayName) { - LOGI("start"); + LOGI("SoftbusListener Start SetLocalDisplayName!"); uint32_t len = static_cast(displayName.size()); int32_t ret = ::SetDisplayName(DM_PKG_NAME, displayName.c_str(), len); if (ret != DM_OK) { LOGE("SoftbusListener SetLocalDisplayName failed!"); + return ret; } return DM_OK; } diff --git a/services/softbuscache/BUILD.gn b/services/softbuscache/BUILD.gn index 49a243c36afd9896067c0f8e8a4bcd6b9336462e..a53c02045fae88400ae3ed17db4c765789f8bf13 100644 --- a/services/softbuscache/BUILD.gn +++ b/services/softbuscache/BUILD.gn @@ -26,6 +26,7 @@ if (defined(ohos_lite)) { "${innerkits_path}/native_cpp/include", "${utils_path}/include/crypto", "${json_path}/include", + "//third_party/cJSON", ] sources = [ @@ -42,8 +43,8 @@ if (defined(ohos_lite)) { deps = [ "${dsoftbussdk_path}:softbus_client", "${hilog_path}:hilog_shared", - "${json_path}:devicemanagerjson", "${third_path}:libsec_shared", + "${json_path}:devicemanagerjson", "${utils_path}:devicemanagerutils", ] } diff --git a/test/commonfuzztest/hichainconnector_fuzzer/hichain_connector_fuzzer.cpp b/test/commonfuzztest/hichainconnector_fuzzer/hichain_connector_fuzzer.cpp index da7ec23e639fa1fce62b00c565bd3562b9280514..c9eec26f742df3fc790232a7eb9d382d6ff0ef90 100644 --- a/test/commonfuzztest/hichainconnector_fuzzer/hichain_connector_fuzzer.cpp +++ b/test/commonfuzztest/hichainconnector_fuzzer/hichain_connector_fuzzer.cpp @@ -47,7 +47,6 @@ public: { (void)requestId; (void)status; - (void)operationCode; } std::string GetConnectAddr(std::string deviceId) override { diff --git a/test/commonfuzztest/onerror_fuzzer/on_error_fuzzer.cpp b/test/commonfuzztest/onerror_fuzzer/on_error_fuzzer.cpp index afc699f1848539e5a7e06f7fa7325c8e7c902c1c..2d770846aab3a087396bc2022844a131bc7cc979 100644 --- a/test/commonfuzztest/onerror_fuzzer/on_error_fuzzer.cpp +++ b/test/commonfuzztest/onerror_fuzzer/on_error_fuzzer.cpp @@ -17,11 +17,11 @@ #include #include #include +#include #include "device_manager_service_listener.h" #include "dm_auth_manager.h" #include "hichain_connector.h" -#include #include "on_error_fuzzer.h" diff --git a/test/commonfuzztest/onfinish_fuzzer/on_finish_fuzzer.cpp b/test/commonfuzztest/onfinish_fuzzer/on_finish_fuzzer.cpp index f27b4ae57adf2266dcb4ca392e4bb728ba8f3765..ef94b9dc9138b8382463a7c33e966c57d425f84b 100644 --- a/test/commonfuzztest/onfinish_fuzzer/on_finish_fuzzer.cpp +++ b/test/commonfuzztest/onfinish_fuzzer/on_finish_fuzzer.cpp @@ -57,7 +57,7 @@ public: void OnFinishFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size < sizeof(int64_t) + sizeof(int32_t))) { + if ((data == nullptr) || (size < sizeof(int64_t) + sizeof(int))) { return; } @@ -66,7 +66,7 @@ void OnFinishFuzzTest(const uint8_t* data, size_t size) FuzzedDataProvider fdp(data, size); int64_t requestId = fdp.ConsumeIntegral(); - int operationCode = fdp.ConsumeIntegral(); + int operationCode = fdp.ConsumeIntegral(); std::string str(reinterpret_cast(data), size); const char *returnData = str.data(); hichainConnector->onFinish(requestId, operationCode, returnData); diff --git a/test/commonfuzztest/onrequest_fuzzer/on_request_fuzzer.cpp b/test/commonfuzztest/onrequest_fuzzer/on_request_fuzzer.cpp index 7399f8507fa5fe3b29e82a1a299f50b774dfdae1..82aa2d88190099591e9443ead14a2da3d25b931f 100644 --- a/test/commonfuzztest/onrequest_fuzzer/on_request_fuzzer.cpp +++ b/test/commonfuzztest/onrequest_fuzzer/on_request_fuzzer.cpp @@ -56,15 +56,14 @@ public: void OnRequestFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size < sizeof(int64_t) + sizeof(int32_t))) { + if ((data == nullptr) || (size < sizeof(int64_t) + sizeof(int))) { return; } FuzzedDataProvider fdp(data, size); int64_t requestId = fdp.ConsumeIntegral(); - int operationCode = fdp.ConsumeIntegral(); + int operationCode = fdp.ConsumeIntegral(); const char *reqParams = reinterpret_cast(data); - std::shared_ptr hichainConnector = std::make_shared(); hichainConnector->RegisterHiChainCallback(std::make_shared()); char *ret = hichainConnector->onRequest(requestId, operationCode, reqParams); diff --git a/test/commonunittest/UTTest_hichain_auth_connector.cpp b/test/commonunittest/UTTest_hichain_auth_connector.cpp index fe744fcccb7eb713282950b54c610d72f08ad623..50bcad8ccd10933aab60a9c52e67bb16c5750ecd 100644 --- a/test/commonunittest/UTTest_hichain_auth_connector.cpp +++ b/test/commonunittest/UTTest_hichain_auth_connector.cpp @@ -121,7 +121,7 @@ HWTEST_F(HiChainAuthConnectorTest, onTransmit_002, testing::ext::TestSize.Level1 uint32_t dataLen = 0; hiChain_->dmDeviceAuthCallback_ = std::make_shared(); bool ret = hiChain_->onTransmit(requestId, data, dataLen); - EXPECT_EQ(ret, true); + EXPECT_EQ(ret, false); } HWTEST_F(HiChainAuthConnectorTest, onRequest_001, testing::ext::TestSize.Level1) diff --git a/test/softbusfuzztest/publishsoftbuslnn_fuzzer/publish_softbus_lnn_fuzzer.cpp b/test/softbusfuzztest/publishsoftbuslnn_fuzzer/publish_softbus_lnn_fuzzer.cpp index 77dbbd86b2ff1add6a2cab966950dcd7a74b9154..e32366b9949d1e02a35ab1f42e96a1aba93c4ffe 100644 --- a/test/softbusfuzztest/publishsoftbuslnn_fuzzer/publish_softbus_lnn_fuzzer.cpp +++ b/test/softbusfuzztest/publishsoftbuslnn_fuzzer/publish_softbus_lnn_fuzzer.cpp @@ -33,7 +33,6 @@ void PublishSoftbusLNNFuzzTest(const uint8_t* data, size_t size) FuzzedDataProvider fdp(data, size); DmPublishInfo dmPublishInfo; dmPublishInfo.publishId = fdp.ConsumeIntegral(); - dmPublishInfo.publishId = *(reinterpret_cast(data)); std::string capability(reinterpret_cast(data), size); std::string customData(reinterpret_cast(data), size); diff --git a/test/softbusunittest/UTTest_softbus_listener.cpp b/test/softbusunittest/UTTest_softbus_listener.cpp index b68adb9009a20b6800cabcdacb1a2ca4b98e94dc..80637cdc3da837b8ea0ce75ee1dc6a7a8ea53e28 100644 --- a/test/softbusunittest/UTTest_softbus_listener.cpp +++ b/test/softbusunittest/UTTest_softbus_listener.cpp @@ -1303,7 +1303,7 @@ HWTEST_F(SoftbusListenerTest, SetLocalDisplayName_001, testing::ext::TestSize.Le softbusListener = std::make_shared(); } int32_t ret = softbusListener->SetLocalDisplayName(displayName); - EXPECT_EQ(ret, DM_OK); + EXPECT_NE(ret, SOFTBUS_INVALID_PARAM); std::vector onlineDevInfoVec; EXPECT_CALL(*softbusCacheMock_, GetDeviceInfoFromCache(_)).Times(::testing::AtLeast(1)) .WillOnce(DoAll(SetArgReferee<0>(onlineDevInfoVec), Return(DM_OK))); diff --git a/utils/BUILD.gn b/utils/BUILD.gn index c4d1ba8fe5106a23dc36a67e65a175e117e5a6a1..461fa25950ce27cc29c11f16e7bae607c4e30632 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -38,6 +38,7 @@ if (defined(ohos_lite)) { "${innerkits_path}/native_cpp/include", "${interfaces_path}/c/ipc/include", "${json_path}/include", + "//third_party/cJSON", "//third_party/bounds_checking_function/include", ] @@ -67,6 +68,7 @@ if (defined(ohos_lite)) { "${json_path}:devicemanagerjson", "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", ] + external_deps = [ "bounds_checking_function:libsec_shared", "openssl:libcrypto_shared", @@ -250,6 +252,7 @@ if (defined(ohos_lite)) { public_external_deps = [ "bundle_framework:appexecfwk_core", + "cJSON:cjson", "kv_store:distributeddata_inner", ] diff --git a/utils/src/dm_random.cpp b/utils/src/dm_random.cpp index d14c4b73da9c6acd54ae3c71ff98bd6cea19bfd5..db2dd6800ed550ad36b99d873d2137c1c2fba1a9 100644 --- a/utils/src/dm_random.cpp +++ b/utils/src/dm_random.cpp @@ -26,9 +26,9 @@ namespace OHOS { namespace DistributedHardware { namespace { -const int32_t DM_MIN_RANDOM = 1; -const int32_t DM_MAX_RANDOM_UINT16 = INT16_MAX; -const int32_t DM_INVALID_FLAG_ID = 0; +const uint16_t DM_MIN_RANDOM = 1; +const uint16_t DM_MAX_RANDOM_UINT16 = UINT16_MAX; +const uint16_t DM_INVALID_FLAG_ID = 0; } int32_t GenRandInt(int32_t randMin, int32_t randMax) @@ -63,9 +63,13 @@ uint16_t GenRandUint(uint16_t randMin, uint16_t randMax) uint16_t GenUniqueRandUint(std::set &randUint16Set) { uint16_t randUint = DM_INVALID_FLAG_ID; + if (randUint16Set.size() == DM_MAX_RANDOM_UINT16) { + LOGE("The randUint16Set cache size exceed the limit."); + return randUint; + } bool isExist = false; do { - randUint = GenRandInt(DM_MIN_RANDOM, DM_MAX_RANDOM_UINT16); + randUint = GenRandUint(DM_MIN_RANDOM, DM_MAX_RANDOM_UINT16); if (randUint16Set.find(randUint) != randUint16Set.end()) { LOGE("The randUint: %{public}d is exist.", randUint); isExist = true; diff --git a/utils/src/timer/dm_timer.cpp b/utils/src/timer/dm_timer.cpp index 27d1a2777583535af224773a6609dc3b71a3a902..a41c1fdd12e1bf3235e214a650d426fea7699f26 100644 --- a/utils/src/timer/dm_timer.cpp +++ b/utils/src/timer/dm_timer.cpp @@ -49,7 +49,7 @@ int32_t DmTimer::StartTimer(std::string name, int32_t timeOut, TimerCallback cal return ERR_DM_INPUT_PARA_INVALID; } CHECK_NULL_RETURN(queue_, ERR_DM_POINT_NULL); - LOGI("start name: %{public}s", name.c_str()); + LOGI("DmTimer StartTimer start name: %{public}s", name.c_str()); std::lock_guard locker(timerMutex_); auto taskFunc = [callback, name] () { callback(name); }; @@ -68,7 +68,7 @@ int32_t DmTimer::DeleteTimer(std::string timerName) LOGE("DmTimer DeleteTimer timer is null"); return ERR_DM_INPUT_PARA_INVALID; } - LOGI("start name: %{public}s", timerName.c_str()); + LOGI("DmTimer DeleteTimer start name: %{public}s", timerName.c_str()); std::lock_guard locker(timerMutex_); auto item = timerVec_.find(timerName); if (item == timerVec_.end()) { @@ -87,7 +87,7 @@ int32_t DmTimer::DeleteTimer(std::string timerName) DM_EXPORT int32_t DmTimer::DeleteAll() { - LOGI("start"); + LOGI("DmTimer DeleteAll start"); std::lock_guard locker(timerMutex_); for (const auto &name : timerVec_) { if (name.second != nullptr && queue_ != nullptr) {