diff --git a/BUILD.gn b/BUILD.gn index ae7b066589c7faefea80b41ee16aa025c501f59e..8591cae424aeb4116841e13e518e52af8f3fbdcd 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -56,6 +56,14 @@ if (defined(ohos_lite)) { "services/service:devicemanagerservice", "services/softbuscache:dmdevicecache", ] + if (!is_lite_system && product_name != "qemu-arm-linux-min") { + deps += [ + "commondependency:devicemanagerdependencytest", + "radar:devicemanagerradartest", + "services/service:devicemanagerservicetest", + "utils:devicemanagerutilstest", + ] + } if (product_name != "qemu-arm-linux-min") { deps += [ "display/entry:DeviceManager_UI" ] } diff --git a/common/include/dfx/standard/dm_hisysevent.h b/common/include/dfx/standard/dm_hisysevent.h index 4553087bdacc2ecc43f334a8823cd3492ea06e33..c65b2198252f1f44df5fc1b9bc9d935c9a1062f7 100644 --- a/common/include/dfx/standard/dm_hisysevent.h +++ b/common/include/dfx/standard/dm_hisysevent.h @@ -18,9 +18,14 @@ #include +#ifndef EXPORT +#define EXPORT __attribute__ ((visibility ("default"))) +#endif // EXPORT + namespace OHOS { namespace DistributedHardware { -void SysEventWrite(const std::string &status, int32_t eventType, const std::string &msg); +EXPORT void SysEventWrite( + const std::string &status, int32_t eventType, const std::string &msg); } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DISTRIBUTED_DM_HISYSEVENT_H diff --git a/common/include/dfx/standard/dm_hitrace.h b/common/include/dfx/standard/dm_hitrace.h index f7347c392af955899d2e187fdb436dfac19195e5..4fbae9444cfe6428d456bdccdba30b8f6a0494f8 100644 --- a/common/include/dfx/standard/dm_hitrace.h +++ b/common/include/dfx/standard/dm_hitrace.h @@ -18,10 +18,14 @@ #include +#ifndef EXPORT +#define EXPORT __attribute__ ((visibility ("default"))) +#endif // EXPORT + namespace OHOS { namespace DistributedHardware { -void DmTraceStart(const std::string &msg); -void DmTraceEnd(); +EXPORT void DmTraceStart(const std::string &msg); +EXPORT void DmTraceEnd(); } // namespace DistributedHardware } // namespace OHOS #endif diff --git a/common/include/dm_anonymous.h b/common/include/dm_anonymous.h index 447e310d793acb48ebe953aa981d6d01e2108bd2..aa2c98547fb2fc7efd33c4120b5d67d2f7888092 100644 --- a/common/include/dm_anonymous.h +++ b/common/include/dm_anonymous.h @@ -27,13 +27,13 @@ namespace DistributedHardware { extern const char* PRINT_LIST_SPLIT; extern const int32_t LIST_SPLIT_LEN; -std::string GetAnonyString(const std::string &value); +EXPORT std::string GetAnonyString(const std::string &value); std::string GetAnonyStringList(const std::vector &values); std::string GetAnonyInt32(const int32_t value); std::string GetAnonyInt32List(const std::vector &values); bool IsNumberString(const std::string &inputString); bool IsString(const JsonItemObject &jsonObj, const std::string &key); -bool IsInt32(const JsonItemObject &jsonObj, const std::string &key); +EXPORT bool IsInt32(const JsonItemObject &jsonObj, const std::string &key); bool IsUint32(const JsonItemObject &jsonObj, const std::string &key); bool IsInt64(const JsonItemObject &jsonObj, const std::string &key); bool IsArray(const JsonItemObject &jsonObj, const std::string &key); @@ -101,7 +101,7 @@ bool IsIdLengthValid(const std::string &inputID); bool IsMessageLengthValid(const std::string &inputMessage); bool IsValueExist(const std::multimap unorderedmap, const std::string &udid, int32_t userId); bool IsDmCommonNotifyEventValid(DmCommonNotifyEvent dmCommonNotifyEvent); -std::string SafetyDump(const JsonItemObject &jsonObj); +EXPORT std::string SafetyDump(const JsonItemObject &jsonObj); std::string GetSubStr(const std::string &rawStr, const std::string &separator, int32_t index); bool IsJsonValIntegerString(const JsonItemObject &jsonObj, const std::string &key); } // namespace DistributedHardware diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index ecd06f4abb7029d8d61850ebce4d26c37046b6f4..9461a30f1461a2685b38ad7f667cd4918c7cd27e 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -20,136 +20,140 @@ #include "dm_error_type.h" +#ifndef EXPORT +#define EXPORT __attribute__ ((visibility ("default"))) +#endif // EXPORT + namespace OHOS { namespace DistributedHardware { -extern const char* TAG_GROUP_ID; -extern const char* TAG_GROUP_NAME; -extern const char* TAG_REQUEST_ID; -extern const char* TAG_DEVICE_ID; -extern const char* TAG_AUTH_TYPE; -extern const char* TAG_CRYPTO_SUPPORT; -extern const char* TAG_VER; -extern const char* TAG_MSG_TYPE; -extern const char* DM_ITF_VER; -extern const char* DM_PKG_NAME; -extern const char* DM_SESSION_NAME; -extern const char* DM_PIN_HOLDER_SESSION_NAME; -extern const char* DM_SYNC_USERID_SESSION_NAME; -extern const char* DM_CAPABILITY_OSD; -extern const char* DM_CAPABILITY_APPROACH; -extern const char* DM_CAPABILITY_TOUCH; -extern const char* DM_CAPABILITY_CASTPLUS; -extern const char* DM_CAPABILITY_VIRTUAL_LINK; -extern const char* DM_CAPABILITY_SHARE; -extern const char* DM_CAPABILITY_WEAR; -extern const char* DM_CAPABILITY_OOP; -extern const char* DM_CREDENTIAL_TYPE; -extern const char* DM_CREDENTIAL_REQJSONSTR; -extern const char* DM_CREDENTIAL_RETURNJSONSTR; -extern const char* DEVICE_MANAGER_GROUPNAME; -extern const char* FIELD_CREDENTIAL_EXISTS; -extern const char* DM_TYPE_MINE; -extern const char* DM_TYPE_OH; -extern const char* TAG_SESSION_HEARTBEAT; +EXPORT extern const char* TAG_GROUP_ID; +EXPORT extern const char* TAG_GROUP_NAME; +EXPORT extern const char* TAG_REQUEST_ID; +EXPORT extern const char* TAG_DEVICE_ID; +EXPORT extern const char* TAG_AUTH_TYPE; +EXPORT extern const char* TAG_CRYPTO_SUPPORT; +EXPORT extern const char* TAG_VER; +EXPORT extern const char* TAG_MSG_TYPE; +EXPORT extern const char* DM_ITF_VER; +EXPORT extern const char* DM_PKG_NAME; +EXPORT extern const char* DM_SESSION_NAME; +EXPORT extern const char* DM_PIN_HOLDER_SESSION_NAME; +EXPORT extern const char* DM_SYNC_USERID_SESSION_NAME; +EXPORT extern const char* DM_CAPABILITY_OSD; +EXPORT extern const char* DM_CAPABILITY_APPROACH; +EXPORT extern const char* DM_CAPABILITY_TOUCH; +EXPORT extern const char* DM_CAPABILITY_CASTPLUS; +EXPORT extern const char* DM_CAPABILITY_VIRTUAL_LINK; +EXPORT extern const char* DM_CAPABILITY_SHARE; +EXPORT extern const char* DM_CAPABILITY_WEAR; +EXPORT extern const char* DM_CAPABILITY_OOP; +EXPORT extern const char* DM_CREDENTIAL_TYPE; +EXPORT extern const char* DM_CREDENTIAL_REQJSONSTR; +EXPORT extern const char* DM_CREDENTIAL_RETURNJSONSTR; +EXPORT extern const char* DEVICE_MANAGER_GROUPNAME; +EXPORT extern const char* FIELD_CREDENTIAL_EXISTS; +EXPORT extern const char* DM_TYPE_MINE; +EXPORT extern const char* DM_TYPE_OH; +EXPORT extern const char* TAG_SESSION_HEARTBEAT; //The following constant are provided only for HiLink. -extern const char *EXT_PART; +EXPORT extern const char *EXT_PART; // Auth -extern const char* AUTH_TYPE; -extern const char* APP_OPERATION; -extern const char* CUSTOM_DESCRIPTION; -extern const char* TOKEN; -extern const char* PIN_TOKEN; -extern const char* PIN_CODE_KEY; -extern const int32_t CHECK_AUTH_ALWAYS_POS; -extern const char AUTH_ALWAYS; -extern const char AUTH_ONCE; -extern const char* TAG_TARGET_DEVICE_NAME; -extern const int32_t INVALID_PINCODE; +EXPORT extern const char* AUTH_TYPE; +EXPORT extern const char* APP_OPERATION; +EXPORT extern const char* CUSTOM_DESCRIPTION; +EXPORT extern const char* TOKEN; +EXPORT extern const char* PIN_TOKEN; +EXPORT extern const char* PIN_CODE_KEY; +EXPORT extern const int32_t CHECK_AUTH_ALWAYS_POS; +EXPORT extern const char AUTH_ALWAYS; +EXPORT extern const char AUTH_ONCE; +EXPORT extern const char* TAG_TARGET_DEVICE_NAME; +EXPORT extern const int32_t INVALID_PINCODE; // HiChain -extern const int32_t SERVICE_INIT_TRY_MAX_NUM; +EXPORT extern const int32_t SERVICE_INIT_TRY_MAX_NUM; constexpr int32_t DEVICE_UUID_LENGTH = 65; -extern const int32_t DEVICE_NETWORKID_LENGTH; -extern const int32_t GROUP_TYPE_INVALID_GROUP; -extern const int32_t GROUP_TYPE_IDENTICAL_ACCOUNT_GROUP; -extern const int32_t GROUP_TYPE_PEER_TO_PEER_GROUP; -extern const int32_t GROUP_TYPE_ACROSS_ACCOUNT_GROUP; -extern const int32_t GROUP_VISIBILITY_PUBLIC; -extern const int64_t MIN_REQUEST_ID; -extern const int64_t MAX_REQUEST_ID; -extern const int32_t AUTH_DEVICE_REQ_NEGOTIATE; -extern const int32_t AUTH_DEVICE_RESP_NEGOTIATE; -extern const int32_t DEVICEID_LEN; +EXPORT extern const int32_t DEVICE_NETWORKID_LENGTH; +EXPORT extern const int32_t GROUP_TYPE_INVALID_GROUP; +EXPORT extern const int32_t GROUP_TYPE_IDENTICAL_ACCOUNT_GROUP; +EXPORT extern const int32_t GROUP_TYPE_PEER_TO_PEER_GROUP; +EXPORT extern const int32_t GROUP_TYPE_ACROSS_ACCOUNT_GROUP; +EXPORT extern const int32_t GROUP_VISIBILITY_PUBLIC; +EXPORT extern const int64_t MIN_REQUEST_ID; +EXPORT extern const int64_t MAX_REQUEST_ID; +EXPORT extern const int32_t AUTH_DEVICE_REQ_NEGOTIATE; +EXPORT extern const int32_t AUTH_DEVICE_RESP_NEGOTIATE; +EXPORT extern const int32_t DEVICEID_LEN; // Key of filter parameter -extern const char* FILTER_PARA_RANGE; -extern const char* FILTER_PARA_DEVICE_TYPE; -extern const char* FILTER_PARA_INCLUDE_TRUST; +EXPORT extern const char* FILTER_PARA_RANGE; +EXPORT extern const char* FILTER_PARA_DEVICE_TYPE; +EXPORT extern const char* FILTER_PARA_INCLUDE_TRUST; // Connection address type -extern const char* CONN_ADDR_TYPE_ID; -extern const char* CONN_ADDR_TYPE_BR; -extern const char* CONN_ADDR_TYPE_BLE; -extern const char* CONN_ADDR_TYPE_USB; -extern const char* CONN_ADDR_TYPE_WLAN_IP; -extern const char* CONN_ADDR_TYPE_ETH_IP; +EXPORT extern const char* CONN_ADDR_TYPE_ID; +EXPORT extern const char* CONN_ADDR_TYPE_BR; +EXPORT extern const char* CONN_ADDR_TYPE_BLE; +EXPORT extern const char* CONN_ADDR_TYPE_USB; +EXPORT extern const char* CONN_ADDR_TYPE_WLAN_IP; +EXPORT extern const char* CONN_ADDR_TYPE_ETH_IP; // Softbus connection address type int -extern const int32_t CONNECTION_ADDR_USB; +EXPORT extern const int32_t CONNECTION_ADDR_USB; // Parameter Key -extern const char* PARAM_KEY_META_TYPE; -extern const char* PARAM_KEY_TARGET_ID; -extern const char* PARAM_KEY_BR_MAC; -extern const char* PARAM_KEY_BLE_MAC; -extern const char* PARAM_KEY_WIFI_IP; -extern const char* PARAM_KEY_WIFI_PORT; -extern const char* PARAM_KEY_USB_IP; -extern const char* PARAM_KEY_USB_PORT; -extern const char* PARAM_KEY_AUTH_TOKEN; -extern const char* PARAM_KEY_AUTH_TYPE; -extern const char* PARAM_KEY_PIN_CODE; -extern const char* PARAM_KEY_APP_OPER; -extern const char* PARAM_KEY_APP_DESC; -extern const char* PARAM_KEY_BLE_UDID_HASH; +EXPORT extern const char* PARAM_KEY_META_TYPE; +EXPORT extern const char* PARAM_KEY_TARGET_ID; +EXPORT extern const char* PARAM_KEY_BR_MAC; +EXPORT extern const char* PARAM_KEY_BLE_MAC; +EXPORT extern const char* PARAM_KEY_WIFI_IP; +EXPORT extern const char* PARAM_KEY_WIFI_PORT; +EXPORT extern const char* PARAM_KEY_USB_IP; +EXPORT extern const char* PARAM_KEY_USB_PORT; +EXPORT extern const char* PARAM_KEY_AUTH_TOKEN; +EXPORT extern const char* PARAM_KEY_AUTH_TYPE; +EXPORT extern const char* PARAM_KEY_PIN_CODE; +EXPORT extern const char* PARAM_KEY_APP_OPER; +EXPORT extern const char* PARAM_KEY_APP_DESC; +EXPORT extern const char* PARAM_KEY_BLE_UDID_HASH; constexpr const char* PARAM_KEY_CUSTOM_DATA = "CUSTOM_DATA"; -extern const char* PARAM_KEY_CONN_ADDR_TYPE; -extern const char* PARAM_KEY_PUBLISH_ID; -extern const char* PARAM_KEY_SUBSCRIBE_ID; -extern const char* PARAM_KEY_TARGET_PKG_NAME; -extern const char* PARAM_KEY_PEER_BUNDLE_NAME; -extern const char* PARAM_KEY_DISC_FREQ; -extern const char* PARAM_KEY_DISC_MEDIUM; -extern const char* PARAM_KEY_DISC_CAPABILITY; -extern const char* PARAM_KEY_DISC_MODE; -extern const char* PARAM_KEY_AUTO_STOP_ADVERTISE; -extern const char* PARAM_KEY_FILTER_OPTIONS; -extern const char* PARAM_KEY_BIND_EXTRA_DATA; -extern const char* PARAM_KEY_OS_TYPE; -extern const char* PARAM_KEY_OS_VERSION; -extern const char* PARAM_KEY_IS_SHOW_TRUST_DIALOG; -extern const char* PARAM_KEY_UDID; -extern const char* PARAM_KEY_UUID; -extern const char* DM_CONNECTION_DISCONNECTED; -extern const char* BIND_LEVEL; -extern const char* TOKENID; -extern const char* DM_BIND_RESULT_NETWORK_ID; -extern const char* PARAM_KEY_POLICY_STRATEGY_FOR_BLE; -extern const char* PARAM_KEY_POLICY_TIME_OUT; -extern const char* DEVICE_SCREEN_STATUS; -extern const char* PROCESS_NAME; -extern const char* PARAM_CLOSE_SESSION_DELAY_SECONDS; -extern const char* DM_AUTHENTICATION_TYPE; +EXPORT extern const char* PARAM_KEY_CONN_ADDR_TYPE; +EXPORT extern const char* PARAM_KEY_PUBLISH_ID; +EXPORT extern const char* PARAM_KEY_SUBSCRIBE_ID; +EXPORT extern const char* PARAM_KEY_TARGET_PKG_NAME; +EXPORT extern const char* PARAM_KEY_PEER_BUNDLE_NAME; +EXPORT extern const char* PARAM_KEY_DISC_FREQ; +EXPORT extern const char* PARAM_KEY_DISC_MEDIUM; +EXPORT extern const char* PARAM_KEY_DISC_CAPABILITY; +EXPORT extern const char* PARAM_KEY_DISC_MODE; +EXPORT extern const char* PARAM_KEY_AUTO_STOP_ADVERTISE; +EXPORT extern const char* PARAM_KEY_FILTER_OPTIONS; +EXPORT extern const char* PARAM_KEY_BIND_EXTRA_DATA; +EXPORT extern const char* PARAM_KEY_OS_TYPE; +EXPORT extern const char* PARAM_KEY_OS_VERSION; +EXPORT extern const char* PARAM_KEY_IS_SHOW_TRUST_DIALOG; +EXPORT extern const char* PARAM_KEY_UDID; +EXPORT extern const char* PARAM_KEY_UUID; +EXPORT extern const char* DM_CONNECTION_DISCONNECTED; +EXPORT extern const char* BIND_LEVEL; +EXPORT extern const char* TOKENID; +EXPORT extern const char* DM_BIND_RESULT_NETWORK_ID; +EXPORT extern const char* PARAM_KEY_POLICY_STRATEGY_FOR_BLE; +EXPORT extern const char* PARAM_KEY_POLICY_TIME_OUT; +EXPORT extern const char* DEVICE_SCREEN_STATUS; +EXPORT extern const char* PROCESS_NAME; +EXPORT extern const char* PARAM_CLOSE_SESSION_DELAY_SECONDS; +EXPORT extern const char* DM_AUTHENTICATION_TYPE; -extern const char* PARAM_KEY_CONN_SESSIONTYPE; -extern const char* PARAM_KEY_HML_RELEASETIME; -extern const char* PARAM_KEY_HML_ENABLE_160M; -extern const char* PARAM_KEY_HML_ACTIONID; +EXPORT extern const char* PARAM_KEY_CONN_SESSIONTYPE; +EXPORT extern const char* PARAM_KEY_HML_RELEASETIME; +EXPORT extern const char* PARAM_KEY_HML_ENABLE_160M; +EXPORT extern const char* PARAM_KEY_HML_ACTIONID; -extern const char* CONN_SESSION_TYPE_HML; -extern const char* CONN_SESSION_TYPE_BLE; +EXPORT extern const char* CONN_SESSION_TYPE_HML; +EXPORT extern const char* CONN_SESSION_TYPE_BLE; // screen state enum ScreenState { DM_SCREEN_UNKNOWN = -1, @@ -158,9 +162,9 @@ enum ScreenState { }; // errCode map -extern const std::map MAP_ERROR_CODE; +EXPORT extern const std::map MAP_ERROR_CODE; // wise device -extern const int32_t MAX_DEVICE_PROFILE_SIZE; +EXPORT extern const int32_t MAX_DEVICE_PROFILE_SIZE; const int32_t DEIVCE_NAME_MAX_BYTES = 100; } // namespace DistributedHardware } // namespace OHOS diff --git a/common/include/dm_single_instance.h b/common/include/dm_single_instance.h index 7ecf417976c32c51fddd8c0ed2c8412b32361f1c..18720862af0483f155f4dc4514bdf7caf1da45e6 100644 --- a/common/include/dm_single_instance.h +++ b/common/include/dm_single_instance.h @@ -16,11 +16,15 @@ #ifndef OHOS_DM_SINGLE_INSTANCE_H #define OHOS_DM_SINGLE_INSTANCE_H +#ifndef EXPORT +#define EXPORT __attribute__ ((visibility ("default"))) +#endif // EXPORT + namespace OHOS { namespace DistributedHardware { #define DM_DECLARE_SINGLE_INSTANCE_BASE(className) \ public: \ - static className &GetInstance(); \ + EXPORT static className &GetInstance(); \ \ private: \ className(const className &) = delete; \ @@ -36,7 +40,7 @@ private: \ ~className() = default; #define DM_IMPLEMENT_SINGLE_INSTANCE(className) \ - className &className::GetInstance() \ + EXPORT className &className::GetInstance() \ { \ static auto instance = new className(); \ return *instance; \ diff --git a/common/include/json_object.h b/common/include/json_object.h index 940a5d6f869fd8603560993bb5002a460a0a9d87..aaf6c8ef0cb19ba3c0f24401be6fe7cbe8b39cb0 100644 --- a/common/include/json_object.h +++ b/common/include/json_object.h @@ -22,6 +22,10 @@ #include "cJSON.h" #include "dm_log.h" +#ifndef EXPORT +#define EXPORT __attribute__ ((visibility ("default"))) +#endif // EXPORT + namespace OHOS { namespace DistributedHardware { class JsonObject; @@ -38,23 +42,23 @@ class JsonItemObject { friend void ToJson(JsonItemObject &itemObject, const int64_t &value); friend void ToJson(JsonItemObject &itemObject, const uint64_t &value); public: - JsonItemObject(const JsonItemObject &object); + EXPORT JsonItemObject(const JsonItemObject &object); JsonItemObject(const JsonObject &object) = delete; - virtual ~JsonItemObject(); - bool IsString() const; + EXPORT virtual ~JsonItemObject(); + EXPORT bool IsString() const; bool IsNumber() const; - bool IsNumberInteger() const; + EXPORT bool IsNumberInteger() const; bool IsArray() const; bool IsBoolean() const; bool IsObject() const; JsonItemObject& operator=(const JsonItemObject &object); JsonItemObject& operator=(const JsonObject &object) = delete; - JsonItemObject operator[](const std::string &key); - const JsonItemObject operator[](const std::string &key) const; + EXPORT JsonItemObject operator[](const std::string &key); + EXPORT const JsonItemObject operator[](const std::string &key) const; std::string DumpFormated() const; std::string Dump() const; - bool Contains(const std::string &key) const; - bool IsDiscarded() const; + EXPORT bool Contains(const std::string &key) const; + EXPORT bool IsDiscarded() const; bool PushBack(const std::string &strValue); bool PushBack(const double &strValue); bool PushBack(const JsonItemObject &item); @@ -129,13 +133,13 @@ public: return *this; } protected: - JsonItemObject(); + EXPORT JsonItemObject(); void Delete(); - std::string Dump(bool formatFlag) const; + EXPORT std::string Dump(bool formatFlag) const; bool AddToArray(cJSON *newItem); - bool InitItem(JsonItemObject &item); + EXPORT bool InitItem(JsonItemObject &item); bool InitArray(); - bool ReplaceItem(cJSON *newItem); + EXPORT bool ReplaceItem(cJSON *newItem); protected: cJSON *item_ = nullptr; cJSON *parent_ = nullptr; @@ -154,16 +158,16 @@ class JsonObject : public JsonItemObject { public: using JsonItemObject::operator=; JsonObject(JsonCreateType type = JsonCreateType::JSON_CREATE_TYPE_OBJECT); - JsonObject(const std::string &strJson); + EXPORT JsonObject(const std::string &strJson); JsonObject(const JsonObject &object) = delete; JsonObject& operator=(const JsonObject &object) = delete; JsonObject& operator=(const JsonItemObject &object) = delete; - ~JsonObject(); + EXPORT ~JsonObject(); bool Parse(const std::string &strJson); void Duplicate(const JsonObject &object); }; -void ToJson(JsonItemObject &itemObject, const std::string &value); +EXPORT void ToJson(JsonItemObject &itemObject, const std::string &value); void ToJson(JsonItemObject &itemObject, const char *value); void ToJson(JsonItemObject &itemObject, const double &value); void ToJson(JsonItemObject &itemObject, const bool &value); @@ -172,9 +176,9 @@ void ToJson(JsonItemObject &itemObject, const int16_t &value); void ToJson(JsonItemObject &itemObject, const uint16_t &value); void ToJson(JsonItemObject &itemObject, const int32_t &value); void ToJson(JsonItemObject &itemObject, const uint32_t &value); -void ToJson(JsonItemObject &itemObject, const int64_t &value); +EXPORT void ToJson(JsonItemObject &itemObject, const int64_t &value); void ToJson(JsonItemObject &itemObject, const uint64_t &value); -void FromJson(const JsonItemObject &itemObject, std::string &value); +EXPORT void FromJson(const JsonItemObject &itemObject, std::string &value); void FromJson(const JsonItemObject &itemObject, double &value); void FromJson(const JsonItemObject &itemObject, bool &value); void FromJson(const JsonItemObject &itemObject, uint8_t &value); @@ -182,7 +186,7 @@ void FromJson(const JsonItemObject &itemObject, int16_t &value); void FromJson(const JsonItemObject &itemObject, uint16_t &value); void FromJson(const JsonItemObject &itemObject, int32_t &value); void FromJson(const JsonItemObject &itemObject, uint32_t &value); -void FromJson(const JsonItemObject &itemObject, int64_t &value); +EXPORT void FromJson(const JsonItemObject &itemObject, int64_t &value); void FromJson(const JsonItemObject &itemObject, uint64_t &value); std::string ToString(const JsonItemObject &jsonItem); } // namespace DistributedHardware diff --git a/common/src/dm_anonymous.cpp b/common/src/dm_anonymous.cpp index 0bf73567f010750bfb57fe9a1edc37ef4f86b9a2..15d940b42c4cc07f5fac48d71e1305c60ad7c9b6 100644 --- a/common/src/dm_anonymous.cpp +++ b/common/src/dm_anonymous.cpp @@ -368,7 +368,7 @@ bool IsDmCommonNotifyEventValid(DmCommonNotifyEvent dmCommonNotifyEvent) return false; } -std::string SafetyDump(const JsonItemObject &jsonObj) +EXPORT std::string SafetyDump(const JsonItemObject &jsonObj) { return jsonObj.Dump(); } diff --git a/common/src/json_object.cpp b/common/src/json_object.cpp index 0cae1100d35e8afde8a76ea886eb15417746717e..2234ac7793c288601faac51a2038837e6bcc9bef 100644 --- a/common/src/json_object.cpp +++ b/common/src/json_object.cpp @@ -18,7 +18,7 @@ namespace OHOS { namespace DistributedHardware { -void ToJson(JsonItemObject &itemObject, const std::string &value) +EXPORT void ToJson(JsonItemObject &itemObject, const std::string &value) { if (itemObject.item_ != nullptr) { cJSON_Delete(itemObject.item_); @@ -90,7 +90,7 @@ void ToJson(JsonItemObject &itemObject, const uint32_t &value) itemObject.item_ = cJSON_CreateNumber(value); } -void ToJson(JsonItemObject &itemObject, const int64_t &value) +EXPORT void ToJson(JsonItemObject &itemObject, const int64_t &value) { if (itemObject.item_ != nullptr) { cJSON_Delete(itemObject.item_); @@ -106,7 +106,7 @@ void ToJson(JsonItemObject &itemObject, const uint64_t &value) itemObject.item_ = cJSON_CreateNumber(value); } -void FromJson(const JsonItemObject &itemObject, std::string &value) +EXPORT void FromJson(const JsonItemObject &itemObject, std::string &value) { itemObject.GetTo(value); } @@ -154,7 +154,7 @@ void FromJson(const JsonItemObject &itemObject, uint32_t &value) value = static_cast(tmpValue); } -void FromJson(const JsonItemObject &itemObject, int64_t &value) +EXPORT void FromJson(const JsonItemObject &itemObject, int64_t &value) { itemObject.GetTo(value); } @@ -171,10 +171,10 @@ std::string ToString(const JsonItemObject &jsonItem) return jsonItem.Dump(); } -JsonItemObject::JsonItemObject() +EXPORT JsonItemObject::JsonItemObject() {} -JsonItemObject::JsonItemObject(const JsonItemObject &object) +EXPORT JsonItemObject::JsonItemObject(const JsonItemObject &object) { item_ = object.item_; parent_ = object.parent_; @@ -185,7 +185,7 @@ JsonItemObject::JsonItemObject(const JsonItemObject &object) } } -JsonItemObject::~JsonItemObject() +EXPORT JsonItemObject::~JsonItemObject() { Delete(); } @@ -198,7 +198,7 @@ void JsonItemObject::Delete() item_ = nullptr; } -bool JsonItemObject::IsString() const +EXPORT bool JsonItemObject::IsString() const { if (item_ == nullptr) { return false; @@ -214,7 +214,7 @@ bool JsonItemObject::IsNumber() const return cJSON_IsNumber(item_); } -bool JsonItemObject::IsNumberInteger() const +EXPORT bool JsonItemObject::IsNumberInteger() const { if (!IsNumber()) { return false; @@ -285,7 +285,7 @@ std::string JsonItemObject::DumpFormated() const return Dump(true); } -std::string JsonItemObject::Dump() const +EXPORT std::string JsonItemObject::Dump() const { return Dump(false); } @@ -305,7 +305,7 @@ std::string JsonItemObject::Dump(bool formatFlag) const return out; } -JsonItemObject JsonItemObject::operator[](const std::string &key) +EXPORT JsonItemObject JsonItemObject::operator[](const std::string &key) { JsonItemObject itemObject = At(key); if (itemObject.item_ == nullptr) { @@ -324,12 +324,12 @@ JsonItemObject JsonItemObject::operator[](const std::string &key) return itemObject; } -const JsonItemObject JsonItemObject::operator[](const std::string &key) const +EXPORT const JsonItemObject JsonItemObject::operator[](const std::string &key) const { return At(key); } -bool JsonItemObject::Contains(const std::string &key) const +EXPORT bool JsonItemObject::Contains(const std::string &key) const { if (item_ == nullptr) { LOGE("item_ is nullptr"); @@ -339,7 +339,7 @@ bool JsonItemObject::Contains(const std::string &key) const return (item != nullptr); } -bool JsonItemObject::IsDiscarded() const +EXPORT bool JsonItemObject::IsDiscarded() const { return (item_ == nullptr); } @@ -505,7 +505,7 @@ std::vector JsonItemObject::Items() const return items; } -bool JsonItemObject::InitItem(JsonItemObject &item) +EXPORT bool JsonItemObject::InitItem(JsonItemObject &item) { if (!beValid_) { LOGE("invalid item"); @@ -539,7 +539,7 @@ bool JsonItemObject::InitArray() return true; } -bool JsonItemObject::ReplaceItem(cJSON *newItem) +EXPORT bool JsonItemObject::ReplaceItem(cJSON *newItem) { if (parent_ != nullptr) { if (cJSON_IsObject(parent_)) { @@ -582,14 +582,14 @@ JsonObject::JsonObject(JsonCreateType type) } } -JsonObject::JsonObject(const std::string &strJson) +EXPORT JsonObject::JsonObject(const std::string &strJson) { needDeleteItem_ = true; beValid_ = true; Parse(strJson); } -JsonObject::~JsonObject() +EXPORT JsonObject::~JsonObject() { Delete(); } diff --git a/commondependency/BUILD.gn b/commondependency/BUILD.gn index 615025355e0ca70367f2ff69cb607332b3d014b1..a0ef0841c04e739f0f86c1299be7991f7fcf8b19 100644 --- a/commondependency/BUILD.gn +++ b/commondependency/BUILD.gn @@ -13,6 +13,19 @@ import("//build/ohos.gni") import("//foundation/distributedhardware/device_manager/device_manager.gni") +config("cflags_config") { + cflags = [ + "-Werror", + "-fPIC", + "-fstack-protector-strong", + "-ffunction-sections", + "-fdata-sections", + "-fvisibility=hidden", + "-Oz", + "-flto", + ] + ldflags = [ "-flto" ] +} ohos_shared_library("devicemanagerdependency") { branch_protector_ret = "pac_ret" @@ -36,6 +49,76 @@ ohos_shared_library("devicemanagerdependency") { "-Wl,-z,now", ] + configs = [ ":cflags_config" ] + + include_dirs = [ + "include", + "${common_path}/include", + "${innerkits_path}/native_cpp/include", + "${servicesimpl_path}/include/cryptomgr", + "${utils_path}/include/crypto", + ] + + sources = [ + "src/deviceprofile_connector.cpp", + "src/multiple_user_connector.cpp", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"devicemanagerdependency\"", + "LOG_DOMAIN=0xD004112", + ] + + deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${utils_path}:devicemanagerutils", + ] + + external_deps = [ + "ability_base:want", + "c_utils:utils", + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", + "hilog:libhilog", + "ipc:ipc_core", + "os_account:libaccountkits", + "samgr:samgr_proxy", + ] + + if (os_account_part_exists) { + defines += [ "OS_ACCOUNT_PART_EXISTS" ] + external_deps += [ "os_account:os_account_innerkits" ] + } + + subsystem_name = "distributedhardware" + + part_name = "device_manager" +} + +ohos_shared_library("devicemanagerdependencytest") { + branch_protector_ret = "pac_ret" + + sanitize = { + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + integer_overflow = true + ubsan = true + } + + cflags = [ + "-Werror", + "-fPIC", + "-fstack-protector-strong", + ] + + ldflags = [ + "-Wl,-z,relro", + "-Wl,-z,now", + ] + include_dirs = [ "include", "${common_path}/include", diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index 3cff80ef815fbbcf19add3a6c73383952d2a579c..64533caa197df44e02c1f3721e24f21699ffb3fb 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -29,20 +29,20 @@ enum AllowAuthType { ALLOW_AUTH_ALWAYS = 2 }; -extern const uint32_t INVALIED_TYPE; -extern const uint32_t APP_PEER_TO_PEER_TYPE; -extern const uint32_t APP_ACROSS_ACCOUNT_TYPE; -extern const uint32_t DEVICE_PEER_TO_PEER_TYPE; -extern const uint32_t DEVICE_ACROSS_ACCOUNT_TYPE; -extern const uint32_t IDENTICAL_ACCOUNT_TYPE; +EXPORT extern const uint32_t INVALIED_TYPE; +EXPORT extern const uint32_t APP_PEER_TO_PEER_TYPE; +EXPORT extern const uint32_t APP_ACROSS_ACCOUNT_TYPE; +EXPORT extern const uint32_t DEVICE_PEER_TO_PEER_TYPE; +EXPORT extern const uint32_t DEVICE_ACROSS_ACCOUNT_TYPE; +EXPORT extern const uint32_t IDENTICAL_ACCOUNT_TYPE; -extern const uint32_t DM_IDENTICAL_ACCOUNT; -extern const uint32_t DM_POINT_TO_POINT; -extern const uint32_t DM_ACROSS_ACCOUNT; -extern const uint32_t DM_INVALIED_BINDTYPE; -extern const uint32_t DEVICE; -extern const uint32_t SERVICE; -extern const uint32_t APP; +EXPORT extern const uint32_t DM_IDENTICAL_ACCOUNT; +EXPORT extern const uint32_t DM_POINT_TO_POINT; +EXPORT extern const uint32_t DM_ACROSS_ACCOUNT; +EXPORT extern const uint32_t DM_INVALIED_BINDTYPE; +EXPORT extern const uint32_t DEVICE; +EXPORT extern const uint32_t SERVICE; +EXPORT extern const uint32_t APP; enum ProfileState { INACTIVE = 0, @@ -112,92 +112,119 @@ public: class DeviceProfileConnector : public IDeviceProfileConnector { DM_DECLARE_SINGLE_INSTANCE(DeviceProfileConnector); public: - std::vector GetAccessControlProfile(); + EXPORT std::vector + GetAccessControlProfile(); std::vector GetAccessControlProfileByUserId(int32_t userId); std::vector GetAclProfileByDeviceIdAndUserId( const std::string &deviceId, int32_t userId); - uint32_t CheckBindType(std::string peerUdid, std::string localUdid); - int32_t PutAccessControlList(DmAclInfo aclInfo, DmAccesser dmAccesser, DmAccessee dmAccessee); + EXPORT uint32_t CheckBindType(std::string peerUdid, std::string localUdid); + EXPORT int32_t PutAccessControlList(DmAclInfo aclInfo, DmAccesser dmAccesser, + DmAccessee dmAccessee); int32_t UpdateAccessControlList(int32_t userId, std::string &oldAccountId, std::string &newAccountId); - std::unordered_map GetAppTrustDeviceList(const std::string &pkgName, - const std::string &deviceId); - std::vector GetBindTypeByPkgName(std::string pkgName, std::string requestDeviceId, - std::string trustUdid); - uint64_t GetTokenIdByNameAndDeviceId(std::string pkgName, std::string requestDeviceId); - std::vector SyncAclByBindType(std::string pkgName, std::vector bindTypeVec, - std::string localDeviceId, std::string targetDeviceId); + EXPORT std::unordered_map GetAppTrustDeviceList( + const std::string &pkgName, const std::string &deviceId); + EXPORT std::vector GetBindTypeByPkgName(std::string pkgName, + std::string requestDeviceId, std::string trustUdid); + EXPORT uint64_t GetTokenIdByNameAndDeviceId(std::string pkgName, + std::string requestDeviceId); + EXPORT std::vector SyncAclByBindType(std::string pkgName, + std::vector bindTypeVec, std::string localDeviceId, std::string targetDeviceId); int32_t GetDeviceAclParam(DmDiscoveryInfo discoveryInfo, bool &isOnline, int32_t &authForm); - bool DeleteAclForAccountLogOut(const std::string &localUdid, int32_t localUserId, - const std::string &peerUdid, int32_t peerUserId); - void DeleteAclForUserRemoved(std::string localUdid, int32_t userId); - void DeleteAclForRemoteUserRemoved(std::string peerUdid, int32_t peerUserId, std::vector &userIds); - DmOfflineParam DeleteAccessControlList(const std::string &pkgName, const std::string &localDeviceId, - const std::string &remoteDeviceId, int32_t bindLevel, const std::string &extra); - std::vector GetProcessInfoFromAclByUserId(const std::string &localDeviceId, - const std::string &targetDeviceId, int32_t userId); + EXPORT bool DeleteAclForAccountLogOut(const std::string &localUdid, + int32_t localUserId, const std::string &peerUdid, int32_t peerUserId); + EXPORT void DeleteAclForUserRemoved(std::string localUdid, int32_t userId); + EXPORT void DeleteAclForRemoteUserRemoved(std::string peerUdid, + int32_t peerUserId, std::vector &userIds); + EXPORT DmOfflineParam DeleteAccessControlList(const std::string &pkgName, + const std::string &localDeviceId, const std::string &remoteDeviceId, int32_t bindLevel, + const std::string &extra); + EXPORT std::vector + GetProcessInfoFromAclByUserId(const std::string &localDeviceId, const std::string &targetDeviceId, + int32_t userId); bool CheckIdenticalAccount(int32_t userId, const std::string &accountId); - bool CheckSrcDevIdInAclForDevBind(const std::string &pkgName, const std::string &deviceId); - bool CheckSinkDevIdInAclForDevBind(const std::string &pkgName, const std::string &deviceId); - uint32_t DeleteTimeOutAcl(const std::string &deviceId); - int32_t GetTrustNumber(const std::string &deviceId); + EXPORT bool CheckSrcDevIdInAclForDevBind(const std::string &pkgName, + const std::string &deviceId); + EXPORT bool CheckSinkDevIdInAclForDevBind(const std::string &pkgName, + const std::string &deviceId); + EXPORT uint32_t DeleteTimeOutAcl(const std::string &deviceId); + EXPORT int32_t GetTrustNumber(const std::string &deviceId); bool CheckDevIdInAclForDevBind(const std::string &pkgName, const std::string &deviceId); std::vector CompareBindType(std::vector profiles, std::string pkgName, std::vector &sinkBindType, std::string localDeviceId, std::string targetDeviceId); - int32_t IsSameAccount(const std::string &udid); - int32_t CheckAccessControl(const DmAccessCaller &caller, const std::string &srcUdid, - const DmAccessCallee &callee, const std::string &sinkUdid); - int32_t CheckIsSameAccount(const DmAccessCaller &caller, const std::string &srcUdid, - const DmAccessCallee &callee, const std::string &sinkUdid); - void DeleteAccessControlList(const std::string &udid); - int32_t GetBindLevel(const std::string &pkgName, const std::string &localUdid, - const std::string &udid, uint64_t &tokenId); + EXPORT int32_t IsSameAccount(const std::string &udid); + EXPORT int32_t CheckAccessControl(const DmAccessCaller &caller, + const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid); + EXPORT int32_t CheckIsSameAccount(const DmAccessCaller &caller, + const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid); + EXPORT void DeleteAccessControlList(const std::string &udid); + EXPORT int32_t GetBindLevel(const std::string &pkgName, + const std::string &localUdid, const std::string &udid, uint64_t &tokenId); std::map GetDeviceIdAndBindLevel(std::vector userIds, const std::string &localUdid); - std::multimap GetDeviceIdAndUserId(int32_t userId, const std::string &accountId, - const std::string &localUdid); + EXPORT std::multimap GetDeviceIdAndUserId( + int32_t userId, const std::string &accountId, const std::string &localUdid); int32_t HandleAccountLogoutEvent(int32_t remoteUserId, const std::string &remoteAccountHash, const std::string &remoteUdid, const std::string &localUdid); - int32_t HandleDevUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, const std::string &localUdid); - OHOS::DistributedHardware::ProcessInfo HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, - int32_t tokenId, const std::string &localUdid); - OHOS::DistributedHardware::ProcessInfo HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, - int32_t tokenId, const std::string &localUdid, int32_t peerTokenId); - std::vector GetAllAccessControlProfile(); - void DeleteAccessControlById(int64_t accessControlId); - int32_t HandleUserSwitched(const std::string &localUdid, const std::vector &deviceVec, - int32_t currentUserId, int32_t beforeUserId); - int32_t HandleUserSwitched(const std::string &localUdid, const std::vector &deviceVec, - const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); + EXPORT int32_t HandleDevUnBindEvent(int32_t remoteUserId, + const std::string &remoteUdid, const std::string &localUdid); + EXPORT OHOS::DistributedHardware::ProcessInfo HandleAppUnBindEvent( + int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId, const std::string &localUdid); + EXPORT OHOS::DistributedHardware::ProcessInfo HandleAppUnBindEvent( + int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId, const std::string &localUdid, + int32_t peerTokenId); + EXPORT std::vector + GetAllAccessControlProfile(); + EXPORT void DeleteAccessControlById(int64_t accessControlId); + EXPORT int32_t HandleUserSwitched(const std::string &localUdid, + const std::vector &deviceVec, int32_t currentUserId, int32_t beforeUserId); + EXPORT int32_t HandleUserSwitched(const std::string &localUdid, + const std::vector &deviceVec, const std::vector &foregroundUserIds, + const std::vector &backgroundUserIds); bool CheckAclStatusAndForegroundNotMatch(const std::string &localUdid, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); - void HandleUserSwitched(const std::vector &activeProfiles, + EXPORT void HandleUserSwitched( + const std::vector &activeProfiles, const std::vector &inActiveProfiles, const std::vector &delActiveProfiles); - void HandleSyncForegroundUserIdEvent(const std::vector &remoteUserIds, const std::string &remoteUdid, + EXPORT void HandleSyncForegroundUserIdEvent( + const std::vector &remoteUserIds, const std::string &remoteUdid, const std::vector &localUserIds, std::string &localUdid); std::vector GetOfflineProcessInfo(std::string &localUdid, const std::vector &localUserIds, const std::string &remoteUdid, const std::vector &remoteUserIds); - std::map GetUserIdAndBindLevel(const std::string &localUdid, const std::string &peerUdid); - void UpdateACL(std::string &localUdid, const std::vector &localUserIds, - const std::string &remoteUdid, const std::vector &remoteFrontUserIds, - const std::vector &remoteBackUserIds); - std::multimap GetDevIdAndUserIdByActHash(const std::string &localUdid, - const std::string &peerUdid, int32_t peerUserId, const std::string &peerAccountHash); - std::multimap GetDeviceIdAndUserId(const std::string &localUdid, int32_t localUserId); - void HandleSyncBackgroundUserIdEvent(const std::vector &remoteUserIds, const std::string &remoteUdid, + EXPORT std::map GetUserIdAndBindLevel( + const std::string &localUdid, const std::string &peerUdid); + EXPORT void UpdateACL(std::string &localUdid, + const std::vector &localUserIds, const std::string &remoteUdid, + const std::vector &remoteFrontUserIds, const std::vector &remoteBackUserIds); + EXPORT std::multimap GetDevIdAndUserIdByActHash( + const std::string &localUdid, const std::string &peerUdid, int32_t peerUserId, + const std::string &peerAccountHash); + EXPORT std::multimap GetDeviceIdAndUserId( + const std::string &localUdid, int32_t localUserId); + EXPORT void HandleSyncBackgroundUserIdEvent( + const std::vector &remoteUserIds, const std::string &remoteUdid, const std::vector &localUserIds, std::string &localUdid); - void HandleDeviceUnBind(int32_t bindType, const std::string &peerUdid, + EXPORT void HandleDeviceUnBind(int32_t bindType, const std::string &peerUdid, const std::string &localUdid, int32_t localUserId, const std::string &localAccountId); - int32_t SubscribeDeviceProfileInited(sptr dpInitedCallback); - int32_t UnSubscribeDeviceProfileInited(); - int32_t PutAllTrustedDevices(const std::vector &deviceInfos); - int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId); - int32_t UpdateAclDeviceName(const std::string &udid, const std::string &newDeviceName); - int32_t PutLocalServiceInfo(const DistributedDeviceProfile::LocalServiceInfo &localServiceInfo); - int32_t DeleteLocalServiceInfo(const std::string &bundleName, int32_t pinExchangeType); - int32_t UpdateLocalServiceInfo(const DistributedDeviceProfile::LocalServiceInfo &localServiceInfo); - int32_t GetLocalServiceInfoByBundleNameAndPinExchangeType(const std::string &bundleName, - int32_t pinExchangeType, DistributedDeviceProfile::LocalServiceInfo &localServiceInfo); - int32_t PutSessionKey(const std::vector &sessionKeyArray, int32_t &sessionKeyId); + EXPORT int32_t SubscribeDeviceProfileInited( + sptr dpInitedCallback); + EXPORT int32_t UnSubscribeDeviceProfileInited(); + EXPORT int32_t PutAllTrustedDevices( + const std::vector &deviceInfos); + EXPORT int32_t CheckDeviceInfoPermission(const std::string &localUdid, + const std::string &peerDeviceId); + EXPORT int32_t UpdateAclDeviceName(const std::string &udid, + const std::string &newDeviceName); + EXPORT int32_t PutLocalServiceInfo( + const DistributedDeviceProfile::LocalServiceInfo &localServiceInfo); + EXPORT int32_t DeleteLocalServiceInfo(const std::string &bundleName, + int32_t pinExchangeType); + EXPORT int32_t UpdateLocalServiceInfo( + const DistributedDeviceProfile::LocalServiceInfo &localServiceInfo); + EXPORT int32_t GetLocalServiceInfoByBundleNameAndPinExchangeType( + const std::string &bundleName, int32_t pinExchangeType, + DistributedDeviceProfile::LocalServiceInfo &localServiceInfo); + EXPORT int32_t PutSessionKey(const std::vector &sessionKeyArray, + int32_t &sessionKeyId); int32_t HandleUserStop(int32_t stopUserId, const std::string &stopEventUdid); int32_t HandleUserStop(int32_t stopUserId, const std::string &localUdid, const std::vector &acceptEventUdids); diff --git a/commondependency/include/multiple_user_connector.h b/commondependency/include/multiple_user_connector.h index ac9a105bb352de23663a0a8b366c693869d123b8..a96752c432cdf3f134ad77613589d7f0387b3686 100644 --- a/commondependency/include/multiple_user_connector.h +++ b/commondependency/include/multiple_user_connector.h @@ -21,6 +21,11 @@ #include #include #include + +#ifndef EXPORT +#define EXPORT __attribute__ ((visibility ("default"))) +#endif // EXPORT + namespace OHOS { namespace DistributedHardware { typedef struct DMAccountInfo { @@ -34,14 +39,14 @@ public: * @tc.desc: Get Current Account UserID of the Multiple User Connector * @tc.type: FUNC */ - static int32_t GetCurrentAccountUserID(void); + EXPORT static int32_t GetCurrentAccountUserID(void); /** * @tc.name: MultipleUserConnector::SetSwitchOldUserId * @tc.desc: Set Switch Old UserId of the Multiple User Connector * @tc.type: FUNC */ - static void SetSwitchOldUserId(int32_t userId); + EXPORT static void SetSwitchOldUserId(int32_t userId); /** * @tc.name: MultipleUserConnector::GetSwitchOldUserId @@ -55,7 +60,7 @@ public: * @tc.desc: Get Current AccountId of current user * @tc.type: FUNC */ - static std::string GetOhosAccountId(void); + EXPORT static std::string GetOhosAccountId(void); /** * @brief Get the Ohos Account Id By Userid @@ -63,14 +68,14 @@ public: * @param userId the user id in which account login * @return std::string the account id */ - static std::string GetOhosAccountIdByUserId(int32_t userId); + EXPORT static std::string GetOhosAccountIdByUserId(int32_t userId); /** * @tc.name: MultipleUserConnector::SetSwitchOldAccountId * @tc.desc: Set Switch Old UserId of the Multiple User Connector * @tc.type: FUNC */ - static void SetSwitchOldAccountId(std::string accountId); + EXPORT static void SetSwitchOldAccountId(std::string accountId); /** * @tc.name: MultipleUserConnector::GetSwitchOldAccountId @@ -91,7 +96,7 @@ public: * @tc.desc: Get Current AccountName of the Multiple User Connector * @tc.type: FUNC */ - static std::string GetOhosAccountName(void); + EXPORT static std::string GetOhosAccountName(void); /** * @tc.name: MultipleUserConnector::GetSwitchOldAccountName @@ -100,20 +105,22 @@ public: */ static std::string GetSwitchOldAccountName(void); - static void SetAccountInfo(int32_t userId, DMAccountInfo dmAccountInfo); - static DMAccountInfo GetAccountInfoByUserId(int32_t userId); - static void DeleteAccountInfoByUserId(int32_t userId); - static void GetTokenIdAndForegroundUserId(uint32_t &tokenId, int32_t &userId); - static void GetCallerUserId(int32_t &userId); - static int32_t GetForegroundUserIds(std::vector &userVec); - static int32_t GetFirstForegroundUserId(void); - static int32_t GetBackgroundUserIds(std::vector &userIdVec); + EXPORT static void SetAccountInfo(int32_t userId, DMAccountInfo dmAccountInfo); + EXPORT static DMAccountInfo GetAccountInfoByUserId(int32_t userId); + EXPORT static void DeleteAccountInfoByUserId(int32_t userId); + EXPORT static void GetTokenIdAndForegroundUserId(uint32_t &tokenId, + int32_t &userId); + EXPORT static void GetCallerUserId(int32_t &userId); + EXPORT static int32_t GetForegroundUserIds(std::vector &userVec); + EXPORT static int32_t GetFirstForegroundUserId(void); + EXPORT static int32_t GetBackgroundUserIds(std::vector &userIdVec); static int32_t GetAllUserIds(std::vector &userIdVec); - static std::string GetAccountNickName(int32_t userId); - static bool IsUserUnlocked(int32_t userId); - static void ClearLockedUser(std::vector &foregroundUserVec); - static void ClearLockedUser(std::vector &foregroundUserVec, std::vector &backgroundUserVec); - static DMAccountInfo GetCurrentDMAccountInfo(); + EXPORT static std::string GetAccountNickName(int32_t userId); + EXPORT static bool IsUserUnlocked(int32_t userId); + EXPORT static void ClearLockedUser(std::vector &foregroundUserVec); + EXPORT static void ClearLockedUser(std::vector &foregroundUserVec, + std::vector &backgroundUserVec); + EXPORT static DMAccountInfo GetCurrentDMAccountInfo(); private: static int32_t oldUserId_; static std::string accountId_; diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index e4eb57b8f3b47706d01b13537523aa1326b44778..add64d362c7dd2f8c6e1c5198f454acaaf15352c 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -44,7 +44,8 @@ constexpr uint32_t MAX_SESSION_KEY_LENGTH = 512; namespace OHOS { namespace DistributedHardware { DM_IMPLEMENT_SINGLE_INSTANCE(DeviceProfileConnector); -std::vector DeviceProfileConnector::GetAccessControlProfile() + +EXPORT std::vector DeviceProfileConnector::GetAccessControlProfile() { std::vector profiles; std::map queryParams; @@ -89,7 +90,7 @@ std::vector DeviceProfileConnector::GetAclProfileByDeviceI return aclProfileVec; } -std::unordered_map DeviceProfileConnector::GetAppTrustDeviceList(const std::string &pkgName, +EXPORT std::unordered_map DeviceProfileConnector::GetAppTrustDeviceList(const std::string &pkgName, const std::string &deviceId) { int32_t userId = MultipleUserConnector::GetFirstForegroundUserId(); @@ -213,7 +214,8 @@ int32_t DeviceProfileConnector::HandleDmAuthForm(AccessControlProfile profiles, return DmAuthForm::INVALID_TYPE; } -uint32_t DeviceProfileConnector::CheckBindType(std::string peerUdid, std::string localUdid) +EXPORT uint32_t DeviceProfileConnector::CheckBindType(std::string peerUdid, + std::string localUdid) { std::vector filterProfiles = GetAclProfileByUserId(localUdid, MultipleUserConnector::GetFirstForegroundUserId(), peerUdid); @@ -263,8 +265,8 @@ int32_t DeviceProfileConnector::GetAuthForm(DistributedDeviceProfile::AccessCont return priority; } -std::vector DeviceProfileConnector::GetBindTypeByPkgName(std::string pkgName, std::string requestDeviceId, - std::string trustUdid) +EXPORT std::vector DeviceProfileConnector::GetBindTypeByPkgName( + std::string pkgName, std::string requestDeviceId, std::string trustUdid) { LOGI("Start requestDeviceId %{public}s, trustUdid %{public}s.", GetAnonyString(requestDeviceId).c_str(), GetAnonyString(trustUdid).c_str()); @@ -285,7 +287,8 @@ std::vector DeviceProfileConnector::GetBindTypeByPkgName(std::string pk return bindTypeVec; } -uint64_t DeviceProfileConnector::GetTokenIdByNameAndDeviceId(std::string pkgName, std::string requestDeviceId) +EXPORT uint64_t DeviceProfileConnector::GetTokenIdByNameAndDeviceId( + std::string pkgName, std::string requestDeviceId) { std::vector profiles = GetAccessControlProfile(); uint64_t peerTokenId = 0; @@ -403,8 +406,8 @@ void DeviceProfileConnector::ProcessBindType(AccessControlProfile profiles, std: } } -std::vector DeviceProfileConnector::SyncAclByBindType(std::string pkgName, std::vector bindTypeVec, - std::string localDeviceId, std::string targetDeviceId) +EXPORT std::vector DeviceProfileConnector::SyncAclByBindType( + std::string pkgName, std::vector bindTypeVec, std::string localDeviceId, std::string targetDeviceId) { std::vector profiles = GetAccessControlProfileByUserId(MultipleUserConnector::GetFirstForegroundUserId()); @@ -431,6 +434,7 @@ std::vector DeviceProfileConnector::SyncAclByBindType(std::string pkgNa return bindType; } +EXPORT std::vector DeviceProfileConnector::GetProcessInfoFromAclByUserId( const std::string &localDeviceId, const std::string &targetDeviceId, int32_t userId) { @@ -495,7 +499,8 @@ int32_t DeviceProfileConnector::PutAccessControlList(DmAclInfo aclInfo, DmAccess return ret; } -bool DeviceProfileConnector::DeleteAclForAccountLogOut(const std::string &localUdid, int32_t localUserId, +EXPORT bool DeviceProfileConnector::DeleteAclForAccountLogOut( + const std::string &localUdid, int32_t localUserId, const std::string &peerUdid, int32_t peerUserId) { LOGI("localUdid %{public}s, localUserId %{public}d, peerUdid %{public}s, peerUserId %{public}d.", @@ -540,7 +545,8 @@ bool DeviceProfileConnector::DeleteAclForAccountLogOut(const std::string &localU return notifyOffline; } -void DeviceProfileConnector::DeleteAclForUserRemoved(std::string localUdid, int32_t userId) +EXPORT void DeviceProfileConnector::DeleteAclForUserRemoved(std::string localUdid, + int32_t userId) { LOGI("localUdid %{public}s, userId %{public}d.", GetAnonyString(localUdid).c_str(), userId); std::vector profiles = GetAccessControlProfileByUserId(userId); @@ -556,8 +562,8 @@ void DeviceProfileConnector::DeleteAclForUserRemoved(std::string localUdid, int3 } } -void DeviceProfileConnector::DeleteAclForRemoteUserRemoved(std::string peerUdid, int32_t peerUserId, - std::vector &userIds) +EXPORT void DeviceProfileConnector::DeleteAclForRemoteUserRemoved( + std::string peerUdid, int32_t peerUserId, std::vector &userIds) { LOGI("peerUdid %{public}s, peerUserId %{public}d.", GetAnonyString(peerUdid).c_str(), peerUserId); std::vector profiles = GetAccessControlProfileByUserId(peerUserId); @@ -581,7 +587,7 @@ void DeviceProfileConnector::DeleteAclForRemoteUserRemoved(std::string peerUdid, } } -void DeviceProfileConnector::DeleteAccessControlList(const std::string &udid) +EXPORT void DeviceProfileConnector::DeleteAccessControlList(const std::string &udid) { LOGI("Udid: %{public}s.", GetAnonyString(udid).c_str()); if (udid.empty()) { @@ -823,7 +829,8 @@ int32_t DeviceProfileConnector::UpdateAccessControlList(int32_t userId, std::str return DM_OK; } -bool DeviceProfileConnector::CheckSrcDevIdInAclForDevBind(const std::string &pkgName, const std::string &deviceId) +EXPORT bool DeviceProfileConnector::CheckSrcDevIdInAclForDevBind( + const std::string &pkgName, const std::string &deviceId) { std::vector profiles = GetAccessControlProfile(); LOGI("AccessControlProfile size is %{public}zu", profiles.size()); @@ -858,7 +865,7 @@ bool DeviceProfileConnector::CheckDevIdInAclForDevBind(const std::string &pkgNam return (CheckSinkDevIdInAclForDevBind(pkgName, deviceId) || CheckSrcDevIdInAclForDevBind(pkgName, deviceId)); } -uint32_t DeviceProfileConnector::DeleteTimeOutAcl(const std::string &deviceId) +EXPORT uint32_t DeviceProfileConnector::DeleteTimeOutAcl(const std::string &deviceId) { std::vector profiles = GetAccessControlProfile(); LOGI("AccessControlProfile size is %{public}zu", profiles.size()); @@ -876,7 +883,7 @@ uint32_t DeviceProfileConnector::DeleteTimeOutAcl(const std::string &deviceId) return res; } -int32_t DeviceProfileConnector::GetTrustNumber(const std::string &deviceId) +EXPORT int32_t DeviceProfileConnector::GetTrustNumber(const std::string &deviceId) { std::vector profiles = GetAccessControlProfile(); LOGI("AccessControlProfile size is %{public}zu", profiles.size()); @@ -889,7 +896,7 @@ int32_t DeviceProfileConnector::GetTrustNumber(const std::string &deviceId) return trustNumber; } -int32_t DeviceProfileConnector::IsSameAccount(const std::string &udid) +EXPORT int32_t DeviceProfileConnector::IsSameAccount(const std::string &udid) { std::vector profiles = GetAccessControlProfile(); for (auto &item : profiles) { @@ -961,7 +968,8 @@ std::vector GetACLByDeviceIdAndUserId(std::vector(profile.GetAccesser().GetAccesserTokenId()) == caller.tokenId && + static_cast(profile.GetAccessee().GetAccesseeTokenId()) == callee.tokenId) || + (static_cast(profile.GetAccesser().GetAccesserTokenId()) == callee.tokenId && + static_cast(profile.GetAccessee().GetAccesseeTokenId()) == caller.tokenId)) { return true; } else { return false; @@ -1051,7 +1059,8 @@ bool DeviceProfileConnector::CheckAppLevelAccess(const DistributedDeviceProfile: } } -int32_t DeviceProfileConnector::CheckIsSameAccount(const DmAccessCaller &caller, const std::string &srcUdid, +EXPORT int32_t DeviceProfileConnector::CheckIsSameAccount( + const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid) { LOGI("DeviceProfileConnector::CheckIsSameAccount pkgName %{public}s, srcUdid %{public}s, sinkUdid %{public}s", @@ -1072,8 +1081,8 @@ int32_t DeviceProfileConnector::CheckIsSameAccount(const DmAccessCaller &caller, return ERR_DM_FAILED; } -int32_t DeviceProfileConnector::GetBindLevel(const std::string &pkgName, const std::string &localUdid, - const std::string &udid, uint64_t &tokenId) +EXPORT int32_t DeviceProfileConnector::GetBindLevel(const std::string &pkgName, + const std::string &localUdid, const std::string &udid, uint64_t &tokenId) { LOGI("pkgName %{public}s, tokenId %{public}" PRId64", udid %{public}s.", pkgName.c_str(), tokenId, GetAnonyString(udid).c_str()); @@ -1126,8 +1135,9 @@ std::map DeviceProfileConnector::GetDeviceIdAndBindLevel(s return deviceIdMap; } -std::multimap DeviceProfileConnector::GetDeviceIdAndUserId(int32_t userId, - const std::string &accountId, const std::string &localUdid) +EXPORT +std::multimap DeviceProfileConnector::GetDeviceIdAndUserId( + int32_t userId, const std::string &accountId, const std::string &localUdid) { LOGI("localUdid %{public}s, userId %{public}d, accountId %{public}s.", GetAnonyString(localUdid).c_str(), userId, GetAnonyString(accountId).c_str()); @@ -1195,8 +1205,8 @@ int32_t DeviceProfileConnector::HandleAccountLogoutEvent(int32_t remoteUserId, return bindType; } -int32_t DeviceProfileConnector::HandleDevUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, - const std::string &localUdid) +EXPORT int32_t DeviceProfileConnector::HandleDevUnBindEvent(int32_t remoteUserId, + const std::string &remoteUdid, const std::string &localUdid) { LOGI("RemoteUserId %{public}d, remoteUdid %{public}s, localUdid %{public}s.", remoteUserId, GetAnonyString(remoteUdid).c_str(), GetAnonyString(localUdid).c_str()); @@ -1216,6 +1226,7 @@ int32_t DeviceProfileConnector::HandleDevUnBindEvent(int32_t remoteUserId, const return bindType; } +EXPORT OHOS::DistributedHardware::ProcessInfo DeviceProfileConnector::HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId, const std::string &localUdid) { @@ -1252,6 +1263,7 @@ OHOS::DistributedHardware::ProcessInfo DeviceProfileConnector::HandleAppUnBindEv return processInfo; } +EXPORT OHOS::DistributedHardware::ProcessInfo DeviceProfileConnector::HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId, const std::string &localUdid, int32_t peerTokenId) { @@ -1290,6 +1302,7 @@ OHOS::DistributedHardware::ProcessInfo DeviceProfileConnector::HandleAppUnBindEv return processInfo; } +EXPORT std::vector DeviceProfileConnector::GetAllAccessControlProfile() { std::vector profiles; @@ -1299,13 +1312,15 @@ std::vector DeviceProfileConnector::GetAllAccessControlPro return profiles; } -void DeviceProfileConnector::DeleteAccessControlById(int64_t accessControlId) +EXPORT void DeviceProfileConnector::DeleteAccessControlById( + int64_t accessControlId) { DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(accessControlId); } -int32_t DeviceProfileConnector::HandleUserSwitched(const std::string &localUdid, - const std::vector &deviceVec, int32_t currentUserId, int32_t beforeUserId) +EXPORT int32_t DeviceProfileConnector::HandleUserSwitched( + const std::string &localUdid, const std::vector &deviceVec, int32_t currentUserId, + int32_t beforeUserId) { if (deviceVec.empty()) { LOGI("no remote device."); @@ -1345,7 +1360,8 @@ int32_t DeviceProfileConnector::HandleUserSwitched(const std::string &localUdid, return DM_OK; } -void DeviceProfileConnector::HandleUserSwitched(const std::vector &activeProfiles, +EXPORT void DeviceProfileConnector::HandleUserSwitched( + const std::vector &activeProfiles, const std::vector &inActiveProfiles, const std::vector &delActiveProfiles) { @@ -1381,8 +1397,9 @@ std::vector DeviceProfileConnector::GetAclProfileByUserId( return profilesTemp; } -void DeviceProfileConnector::HandleSyncForegroundUserIdEvent(const std::vector &remoteUserIds, - const std::string &remoteUdid, const std::vector &localUserIds, std::string &localUdid) +EXPORT void DeviceProfileConnector::HandleSyncForegroundUserIdEvent( + const std::vector &remoteUserIds, const std::string &remoteUdid, + const std::vector &localUserIds, std::string &localUdid) { LOGI("localUdid %{public}s, remoteUdid %{public}s.", GetAnonyString(localUdid).c_str(), GetAnonyString(remoteUdid).c_str()); @@ -1452,8 +1469,8 @@ std::vector DeviceProfileConnector::GetOfflineProcessInfo(std::stri return processInfos; } -std::map DeviceProfileConnector::GetUserIdAndBindLevel(const std::string &localUdid, - const std::string &peerUdid) +EXPORT std::map DeviceProfileConnector::GetUserIdAndBindLevel( + const std::string &localUdid, const std::string &peerUdid) { LOGI("localUdid %{public}s, peerUdid %{public}s.", GetAnonyString(localUdid).c_str(), GetAnonyString(peerUdid).c_str()); @@ -1483,9 +1500,9 @@ std::map DeviceProfileConnector::GetUserIdAndBindLevel(const s return userIdAndBindLevel; } -void DeviceProfileConnector::UpdateACL(std::string &localUdid, const std::vector &localUserIds, - const std::string &remoteUdid, const std::vector &remoteFrontUserIds, - const std::vector &remoteBackUserIds) +EXPORT void DeviceProfileConnector::UpdateACL(std::string &localUdid, + const std::vector &localUserIds, const std::string &remoteUdid, + const std::vector &remoteFrontUserIds, const std::vector &remoteBackUserIds) { LOGI("localUdid %{public}s, remoteUdid %{public}s.", GetAnonyString(localUdid).c_str(), GetAnonyString(remoteUdid).c_str()); @@ -1545,6 +1562,7 @@ void DeviceProfileConnector::UpdatePeerUserId(AccessControlProfile profile, std: } } +EXPORT std::multimap DeviceProfileConnector::GetDevIdAndUserIdByActHash(const std::string &localUdid, const std::string &peerUdid, int32_t peerUserId, const std::string &peerAccountHash) { @@ -1587,8 +1605,8 @@ std::multimap DeviceProfileConnector::GetDevIdAndUserIdByA return deviceIdMap; } -std::multimap DeviceProfileConnector::GetDeviceIdAndUserId(const std::string &localUdid, - int32_t localUserId) +EXPORT std::multimap DeviceProfileConnector::GetDeviceIdAndUserId( + const std::string &localUdid, int32_t localUserId) { LOGI("localUdid %{public}s, userId %{public}d.", GetAnonyString(localUdid).c_str(), localUserId); std::vector profiles = GetAllAccessControlProfile(); @@ -1614,8 +1632,9 @@ std::multimap DeviceProfileConnector::GetDeviceIdAndUserId return deviceIdMap; } -void DeviceProfileConnector::HandleSyncBackgroundUserIdEvent(const std::vector &remoteUserIds, - const std::string &remoteUdid, const std::vector &localUserIds, std::string &localUdid) +EXPORT void DeviceProfileConnector::HandleSyncBackgroundUserIdEvent( + const std::vector &remoteUserIds, const std::string &remoteUdid, + const std::vector &localUserIds, std::string &localUdid) { LOGI("localUdid %{public}s, remoteUdid %{public}s.", GetAnonyString(localUdid).c_str(), GetAnonyString(remoteUdid).c_str()); @@ -1649,8 +1668,8 @@ void DeviceProfileConnector::HandleSyncBackgroundUserIdEvent(const std::vector profiles = DeviceProfileConnector::GetInstance().GetAllAccessControlProfile(); @@ -1669,7 +1688,7 @@ void DeviceProfileConnector::HandleDeviceUnBind(int32_t bindType, const std::str } } -int32_t DeviceProfileConnector::SubscribeDeviceProfileInited( +EXPORT int32_t DeviceProfileConnector::SubscribeDeviceProfileInited( sptr dpInitedCallback) { LOGI("In"); @@ -1686,7 +1705,7 @@ int32_t DeviceProfileConnector::SubscribeDeviceProfileInited( return DM_OK; } -int32_t DeviceProfileConnector::UnSubscribeDeviceProfileInited() +EXPORT int32_t DeviceProfileConnector::UnSubscribeDeviceProfileInited() { LOGI("In"); int32_t ret = DistributedDeviceProfileClient::GetInstance().UnSubscribeDeviceProfileInited( @@ -1698,7 +1717,7 @@ int32_t DeviceProfileConnector::UnSubscribeDeviceProfileInited() return DM_OK; } -int32_t DeviceProfileConnector::PutAllTrustedDevices( +EXPORT int32_t DeviceProfileConnector::PutAllTrustedDevices( const std::vector &deviceInfos) { LOGI("In deviceInfos.size:%{public}zu", deviceInfos.size()); @@ -1710,8 +1729,8 @@ int32_t DeviceProfileConnector::PutAllTrustedDevices( return DM_OK; } -int32_t DeviceProfileConnector::CheckDeviceInfoPermission(const std::string &localUdid, - const std::string &peerDeviceId) +EXPORT int32_t DeviceProfileConnector::CheckDeviceInfoPermission( + const std::string &localUdid, const std::string &peerDeviceId) { LOGI("CheckDeviceInfoPermission Start."); int32_t localUserId = 0; @@ -1866,9 +1885,9 @@ bool DeviceProfileConnector::CheckAclStatusAndForegroundNotMatch(const std::stri return false; } -int32_t DeviceProfileConnector::HandleUserSwitched(const std::string &localUdid, - const std::vector &deviceVec, const std::vector &foregroundUserIds, - const std::vector &backgroundUserIds) +EXPORT int32_t DeviceProfileConnector::HandleUserSwitched( + const std::string &localUdid, const std::vector &deviceVec, + const std::vector &foregroundUserIds, const std::vector &backgroundUserIds) { LOGI("OnStart HandleUserSwitched"); if (deviceVec.empty()) { diff --git a/commondependency/src/multiple_user_connector.cpp b/commondependency/src/multiple_user_connector.cpp index 1c7a83a985fdb17953d6dd177936d9caece4ce42..1bcaa8d8eadc0e09cfa829854703eef59836642e 100644 --- a/commondependency/src/multiple_user_connector.cpp +++ b/commondependency/src/multiple_user_connector.cpp @@ -56,7 +56,7 @@ int32_t MultipleUserConnector::GetCurrentAccountUserID(void) #endif } -std::string MultipleUserConnector::GetOhosAccountId(void) +EXPORT std::string MultipleUserConnector::GetOhosAccountId(void) { #if (defined(__LITEOS_M__) || defined(LITE_DEVICE)) return ""; @@ -73,7 +73,7 @@ std::string MultipleUserConnector::GetOhosAccountId(void) #endif } -std::string MultipleUserConnector::GetOhosAccountIdByUserId(int32_t userId) +EXPORT std::string MultipleUserConnector::GetOhosAccountIdByUserId(int32_t userId) { #if (defined(__LITEOS_M__) || defined(LITE_DEVICE)) (void)userId; @@ -92,7 +92,7 @@ std::string MultipleUserConnector::GetOhosAccountIdByUserId(int32_t userId) #endif } -std::string MultipleUserConnector::GetOhosAccountName(void) +EXPORT std::string MultipleUserConnector::GetOhosAccountName(void) { #if (defined(__LITEOS_M__) || defined(LITE_DEVICE)) return ""; @@ -140,7 +140,7 @@ void MultipleUserConnector::GetCallerUserId(int32_t &userId) #endif } -void MultipleUserConnector::SetSwitchOldUserId(int32_t userId) +EXPORT void MultipleUserConnector::SetSwitchOldUserId(int32_t userId) { std::lock_guard lock(lock_); oldUserId_ = userId; @@ -152,7 +152,7 @@ int32_t MultipleUserConnector::GetSwitchOldUserId(void) return oldUserId_; } -void MultipleUserConnector::SetSwitchOldAccountId(std::string accountId) +EXPORT void MultipleUserConnector::SetSwitchOldAccountId(std::string accountId) { std::lock_guard lock(lock_); accountId_ = accountId; @@ -176,13 +176,14 @@ std::string MultipleUserConnector::GetSwitchOldAccountName(void) return accountName_; } -void MultipleUserConnector::SetAccountInfo(int32_t userId, DMAccountInfo dmAccountInfo) +EXPORT void MultipleUserConnector::SetAccountInfo(int32_t userId, + DMAccountInfo dmAccountInfo) { std::lock_guard lock(dmAccountInfoMaplock_); dmAccountInfoMap_[userId] = dmAccountInfo; } -DMAccountInfo MultipleUserConnector::GetAccountInfoByUserId(int32_t userId) +EXPORT DMAccountInfo MultipleUserConnector::GetAccountInfoByUserId(int32_t userId) { DMAccountInfo dmAccountInfo; { @@ -196,7 +197,7 @@ DMAccountInfo MultipleUserConnector::GetAccountInfoByUserId(int32_t userId) return dmAccountInfo; } -void MultipleUserConnector::DeleteAccountInfoByUserId(int32_t userId) +EXPORT void MultipleUserConnector::DeleteAccountInfoByUserId(int32_t userId) { std::lock_guard lock(dmAccountInfoMaplock_); LOGI("userId: %{public}d", userId); @@ -205,7 +206,8 @@ void MultipleUserConnector::DeleteAccountInfoByUserId(int32_t userId) } } -int32_t MultipleUserConnector::GetForegroundUserIds(std::vector &userVec) +EXPORT int32_t MultipleUserConnector::GetForegroundUserIds( + std::vector &userVec) { #if (defined(__LITEOS_M__) || defined(LITE_DEVICE)) userVec.push_back(DEFAULT_OS_ACCOUNT_ID); @@ -239,7 +241,8 @@ int32_t MultipleUserConnector::GetFirstForegroundUserId(void) return userVec[0]; } -int32_t MultipleUserConnector::GetBackgroundUserIds(std::vector &userIdVec) +EXPORT int32_t MultipleUserConnector::GetBackgroundUserIds( + std::vector &userIdVec) { #if (defined(__LITEOS_M__) || defined(LITE_DEVICE)) return DM_OK; @@ -301,7 +304,7 @@ int32_t MultipleUserConnector::GetAllUserIds(std::vector &userIdVec) #endif } -std::string MultipleUserConnector::GetAccountNickName(int32_t userId) +EXPORT std::string MultipleUserConnector::GetAccountNickName(int32_t userId) { #if (defined(__LITEOS_M__) || defined(LITE_DEVICE)) return ""; @@ -335,7 +338,8 @@ bool MultipleUserConnector::IsUserUnlocked(int32_t userId) #endif } -void MultipleUserConnector::ClearLockedUser(std::vector &foregroundUserVec) +EXPORT void MultipleUserConnector::ClearLockedUser( + std::vector &foregroundUserVec) { for (auto iter = foregroundUserVec.begin(); iter != foregroundUserVec.end();) { if (!IsUserUnlocked(*iter)) { @@ -346,8 +350,8 @@ void MultipleUserConnector::ClearLockedUser(std::vector &foregroundUser } } -void MultipleUserConnector::ClearLockedUser(std::vector &foregroundUserVec, - std::vector &backgroundUserVec) +EXPORT void MultipleUserConnector::ClearLockedUser( + std::vector &foregroundUserVec, std::vector &backgroundUserVec) { for (auto iter = foregroundUserVec.begin(); iter != foregroundUserVec.end();) { if (!IsUserUnlocked(*iter)) { diff --git a/interfaces/inner_kits/native_cpp/include/device_manager.h b/interfaces/inner_kits/native_cpp/include/device_manager.h index 0ea47be34bc83fbe14be8cee35db5716c974bf70..3db4c6e7675fb7d18aa278b4447710e750cb71f0 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager.h @@ -23,7 +23,7 @@ namespace OHOS { namespace DistributedHardware { class DeviceManager { public: - static DeviceManager &GetInstance(); + EXPORT static DeviceManager &GetInstance(); public: /** 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 8a13dfc19f9728978056c9b92ca995458fe0a3df..243012f277a02d9da10f5888f7bdda1444b34d8c 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -24,6 +24,10 @@ #define DM_MAX_DEVICE_ID_LEN (97) #define DM_MAX_DEVICE_NAME_LEN (129) +#ifndef EXPORT +#define EXPORT __attribute__ ((visibility ("default"))) +#endif // EXPORT + namespace OHOS { namespace DistributedHardware { /** @@ -351,16 +355,16 @@ typedef enum { MAX = 9, } DmCommonNotifyEvent; -extern const char* DEVICE_TYPE_UNKNOWN_STRING; -extern const char* DEVICE_TYPE_PHONE_STRING; -extern const char* DEVICE_TYPE_PAD_STRING; -extern const char* DEVICE_TYPE_TV_STRING; -extern const char* DEVICE_TYPE_CAR_STRING; -extern const char* DEVICE_TYPE_WATCH_STRING; -extern const char* DEVICE_TYPE_WIFICAMERA_STRING; -extern const char* DEVICE_TYPE_PC_STRING; -extern const char* DEVICE_TYPE_SMART_DISPLAY_STRING; -extern const char* DEVICE_TYPE_2IN1_STRING; +EXPORT extern const char* DEVICE_TYPE_UNKNOWN_STRING; +EXPORT extern const char* DEVICE_TYPE_PHONE_STRING; +EXPORT extern const char* DEVICE_TYPE_PAD_STRING; +EXPORT extern const char* DEVICE_TYPE_TV_STRING; +EXPORT extern const char* DEVICE_TYPE_CAR_STRING; +EXPORT extern const char* DEVICE_TYPE_WATCH_STRING; +EXPORT extern const char* DEVICE_TYPE_WIFICAMERA_STRING; +EXPORT extern const char* DEVICE_TYPE_PC_STRING; +EXPORT extern const char* DEVICE_TYPE_SMART_DISPLAY_STRING; +EXPORT extern const char* DEVICE_TYPE_2IN1_STRING; typedef struct DmAccessCaller { std::string accountId; diff --git a/radar/BUILD.gn b/radar/BUILD.gn index 21119763e3ff3fa830761b001a44e6f0ba5c2b46..ff44ebe01c2b4b22739d2d18b7a1118653c60b3e 100644 --- a/radar/BUILD.gn +++ b/radar/BUILD.gn @@ -46,6 +46,20 @@ if (defined(ohos_lite)) { } } } else { + config("cflags_config") { + cflags = [ + "-Werror", + "-fPIC", + "-fstack-protector-strong", + "-ffunction-sections", + "-fdata-sections", + "-fvisibility=hidden", + "-Oz", + "-flto", + ] + ldflags = [ "-flto" ] + } + ohos_shared_library("devicemanagerradar") { include_dirs = [ "include", @@ -53,6 +67,65 @@ if (defined(ohos_lite)) { "${innerkits_path}/native_cpp/include", ] + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + + cflags = [ + "-Werror", + "-fPIC", + "-fstack-protector-strong", + ] + + ldflags = [ + "-Wl,-z,relro", + "-Wl,-z,now", + ] + + configs = [ ":cflags_config" ] + + sources = [ "src/dm_radar_helper.cpp" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"devicemanagerradar\"", + "LOG_DOMAIN=0xD004110", + ] + + deps = [ "${innerkits_path}/native_cpp:devicemanagersdk" ] + + external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "cJSON:cjson", + "c_utils:utils", + "hilog:libhilog", + "hisysevent:libhisysevent", + "init:libbegetutil", + "ipc:ipc_core", + "ipc:ipc_single", + ] + + subsystem_name = "distributedhardware" + + part_name = "device_manager" + } + + ohos_shared_library("devicemanagerradartest") { + include_dirs = [ + "include", + "${common_path}/include", + "${innerkits_path}/native_cpp/include", + ] + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + cflags = [ "-Werror", "-fPIC", diff --git a/radar/include/dm_radar_helper.h b/radar/include/dm_radar_helper.h index 1bfb18159c614c960a8e574a1cededc4404a4557..3123d85369e718e08cfc58c317f3be4d5cf0462d 100644 --- a/radar/include/dm_radar_helper.h +++ b/radar/include/dm_radar_helper.h @@ -27,9 +27,9 @@ namespace OHOS { namespace DistributedHardware { -extern const char* ORGPKGNAME; -extern const char* SOFTBUSNAME; -extern const char* HICHAINNAME; +EXPORT extern const char* ORGPKGNAME; +EXPORT extern const char* SOFTBUSNAME; +EXPORT extern const char* HICHAINNAME; enum class DiscoverScene : int32_t { DM_DISCOVER = 0x1, DM_GET_TRUST_DEVICE_LIST = 0x2, @@ -217,8 +217,8 @@ public: std::string funcName, DmDeviceInfo &info, int32_t errCode, std::string localUdid) override; std::string GetDeviceInfoList(std::vector &deviceInfoList) override; std::string ConvertHexToString(uint16_t hex); - int32_t GetErrCode(int32_t errCode); - std::string GetAnonyLocalUdid(); + EXPORT int32_t GetErrCode(int32_t errCode); + EXPORT std::string GetAnonyLocalUdid(); int32_t ReportDiscoverRegCallbackStageIdle(struct RadarInfo &info); int32_t ReportDiscoverUserResStageCancel(struct RadarInfo &info); int32_t ReportDiscoverUserResStageSucc(struct RadarInfo &info); diff --git a/services/implementation/include/config/json_config.h b/services/implementation/include/config/json_config.h index f9598faa33124f428d3afe297e9174f80dbe2f43..e357d8666fe7e667b6368234ef32a404e98b2505 100644 --- a/services/implementation/include/config/json_config.h +++ b/services/implementation/include/config/json_config.h @@ -20,7 +20,7 @@ namespace OHOS { namespace DistributedHardware { -const std::string adapterJsonConfigString = + EXPORT const std::string adapterJsonConfigString = R"({ "devicemanager_adapter_components": [ { @@ -42,7 +42,7 @@ const std::string adapterJsonConfigString = ] })"; -const std::string authJsonConfigString = +EXPORT const std::string authJsonConfigString = R"({ "devicemanager_auth_components": [ { diff --git a/services/service/BUILD.gn b/services/service/BUILD.gn index 62d980a618db79db640d156c849c6727fb36c653..7fe1423a0bb997463707c6820d820c3bd4a5d1da 100644 --- a/services/service/BUILD.gn +++ b/services/service/BUILD.gn @@ -156,7 +156,19 @@ if (defined(ohos_lite)) { "${utils_path}/include/timer", ] } - + config("cflags_config") { + cflags = [ + "-Werror", + "-fPIC", + "-fstack-protector-strong", + "-ffunction-sections", + "-fdata-sections", + "-fvisibility=hidden", + "-Oz", + "-flto", + ] + ldflags = [ "-flto" ] + } ohos_shared_library("devicemanagerservice") { branch_protector_ret = "pac_ret" @@ -180,6 +192,151 @@ if (defined(ohos_lite)) { "-Wl,-z,now", ] + configs = [ ":cflags_config" ] + + sources = [ + "${common_path}/src/dfx/standard/dm_hidumper.cpp", + "${common_path}/src/dm_anonymous.cpp", + "${common_path}/src/ipc/standard/ipc_cmd_register.cpp", + "${common_path}/src/ipc/standard/ipc_model_codec.cpp", + "src/advertise/advertise_manager.cpp", + "src/device_manager_service.cpp", + "src/device_manager_service_listener.cpp", + "src/devicenamemgr/device_name_change_monitor.cpp", + "src/devicenamemgr/device_name_manager.cpp", + "src/devicenamemgr/local_device_name_mgr.cpp", + "src/devicenamemgr/settings_data_event_monitor.cpp", + "src/discovery/discovery_filter.cpp", + "src/discovery/discovery_manager.cpp", + "src/hichain/hichain_listener.cpp", + "src/ipc/standard/ipc_cmd_parser.cpp", + "src/ipc/standard/ipc_server_client_proxy.cpp", + "src/ipc/standard/ipc_server_listener.cpp", + "src/ipc/standard/ipc_server_stub.cpp", + "src/notify/device_manager_service_notify.cpp", + "src/permission/standard/permission_manager.cpp", + "src/pinholder/pin_holder.cpp", + "src/pinholder/pin_holder_session.cpp", + "src/publishcommonevent/dm_account_common_event.cpp", + "src/publishcommonevent/dm_datashare_common_event.cpp", + "src/publishcommonevent/dm_package_common_event.cpp", + "src/publishcommonevent/dm_screen_common_event.cpp", + "src/relationshipsyncmgr/dm_comm_tool.cpp", + "src/relationshipsyncmgr/dm_transport.cpp", + "src/relationshipsyncmgr/dm_transport_msg.cpp", + "src/relationshipsyncmgr/relationship_sync_mgr.cpp", + "src/softbus/mine_softbus_listener.cpp", + "src/softbus/softbus_listener.cpp", + ] + + public_configs = [ ":devicemanagerservice_config" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"devicemanagerservice\"", + "LOG_DOMAIN=0xD004110", + ] + + deps = [ + "${devicemanager_path}/commondependency:devicemanagerdependency", + "${devicemanager_path}/radar:devicemanagerradar", + "${innerkits_path}/native_cpp:devicemanagersdk", + "${softbuscache_parh}:dmdevicecache", + "${utils_path}:devicemanagerutils", + ] + + external_deps = [ + "ability_base:want", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "bundle_framework:appexecfwk_base", + "cJSON:cjson", + "c_utils:utils", + "common_event_service:cesfwk_core", + "common_event_service:cesfwk_innerkits", + "data_share:datashare_common", + "data_share:datashare_consumer", + "device_auth:deviceauth_sdk", + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", + "dsoftbus:softbus_client", + "eventhandler:libeventhandler", + "ffrt:libffrt", + "hicollie:libhicollie", + "hilog:libhilog", + "init:libbeget_proxy", + "init:libbegetutil", + "ipc:ipc_core", + "ipc:ipc_single", + "openssl:libcrypto_shared", + "os_account:libaccountkits", + "os_account:os_account_innerkits", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + if ((support_bluetooth || support_wifi) && + device_manager_feature_product == "default") { + sources += [ + "src/publishcommonevent/dm_publish_common_event.cpp", + "src/softbus/softbus_publish.cpp", + ] + } + + if (support_bluetooth && device_manager_feature_product == "default") { + defines += [ "SUPPORT_BLUETOOTH" ] + external_deps += [ "bluetooth:btframework" ] + } + + if (support_wifi && device_manager_feature_product == "default") { + defines += [ "SUPPORT_WIFI" ] + external_deps += [ "wifi:wifi_sdk" ] + } + + if (support_power_manager) { + defines += [ "SUPPORT_POWER_MANAGER" ] + external_deps += [ "power_manager:powermgr_client" ] + } + + if (support_memmgr) { + defines += [ "SUPPORT_MEMMGR" ] + external_deps += [ "memmgr:memmgrclient" ] + } + + if (device_manager_common) { + defines += [ "DEVICE_MANAGER_COMMON_FLAG" ] + } + + public_external_deps = [ "cJSON:cjson" ] + + subsystem_name = "distributedhardware" + + part_name = "device_manager" + } + + ohos_shared_library("devicemanagerservicetest") { + branch_protector_ret = "pac_ret" + + sanitize = { + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + integer_overflow = true + ubsan = true + } + + cflags = [ + "-Werror", + "-fPIC", + "-fstack-protector-strong", + ] + + ldflags = [ + "-Wl,-z,relro", + "-Wl,-z,now", + ] + sources = [ "${common_path}/src/dfx/standard/dm_hidumper.cpp", "${common_path}/src/dm_anonymous.cpp", diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index a78a2152c9017520061b8ccc003ed17176ff24b6..8b40da361de4cc8b9c948e410a4e99f8a483bb4d 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -58,15 +58,15 @@ public: void InitHichainListener(); - void RegisterCallerAppId(const std::string &pkgName); + EXPORT void RegisterCallerAppId(const std::string &pkgName); - void UnRegisterCallerAppId(const std::string &pkgName); + EXPORT void UnRegisterCallerAppId(const std::string &pkgName); void UninitSoftbusListener(); int32_t InitDMServiceListener(); - void UninitDMServiceListener(); + EXPORT void UninitDMServiceListener(); int32_t GetTrustedDeviceList(const std::string &pkgName, const std::string &extra, std::vector &deviceList); @@ -283,12 +283,15 @@ private: #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) void SubscribeAccountCommonEvent(); - void AccountCommonEventCallback(const std::string commonEventType, int32_t currentUserId, int32_t beforeUserId); + EXPORT void AccountCommonEventCallback(const std::string commonEventType, + int32_t currentUserId, int32_t beforeUserId); void SubscribeScreenLockEvent(); void ScreenCommonEventCallback(std::string commonEventType); - void ConvertUdidHashToAnoyDeviceId(DmDeviceInfo &deviceInfo); - int32_t ConvertUdidHashToAnoyDeviceId(const std::string &udidHash, std::string &anoyDeviceId); - int32_t GetUdidHashByAnoyDeviceId(const std::string &anoyDeviceId, std::string &udidHash); + EXPORT void ConvertUdidHashToAnoyDeviceId(DmDeviceInfo &deviceInfo); + EXPORT int32_t ConvertUdidHashToAnoyDeviceId(const std::string &udidHash, + std::string &anoyDeviceId); + EXPORT int32_t GetUdidHashByAnoyDeviceId(const std::string &anoyDeviceId, + std::string &udidHash); void HandleAccountLogout(int32_t userId, const std::string &accountId, const std::string &accountName); void HandleUserRemoved(int32_t removedUserId); /** @@ -338,7 +341,7 @@ private: void SubscribePublishCommonEvent(); void QueryDependsSwitchState(); #endif // SUPPORT_BLUETOOTH SUPPORT_WIFI - void SubscribeDataShareCommonEvent(); + EXPORT void SubscribeDataShareCommonEvent(); #endif void CheckRegisterInfoWithWise(int32_t curUserId); @@ -365,7 +368,7 @@ private: #if defined(SUPPORT_BLUETOOTH) || defined(SUPPORT_WIFI) std::shared_ptr publshCommonEventManager_; #endif // SUPPORT_BLUETOOTH SUPPORT_WIFI - std::shared_ptr dataShareCommonEventManager_; + EXPORT std::shared_ptr dataShareCommonEventManager_; #endif std::string localNetWorkId_ = ""; std::shared_ptr timer_; diff --git a/services/service/include/device_manager_service_listener.h b/services/service/include/device_manager_service_listener.h index 648d1283a11a7e188efa9ab3e4797a38acd4f1f6..9766358fb77cde194719f2d77c5065abf6940e5e 100644 --- a/services/service/include/device_manager_service_listener.h +++ b/services/service/include/device_manager_service_listener.h @@ -59,11 +59,11 @@ public: void OnCredentialResult(const ProcessInfo &processInfo, int32_t action, const std::string &resultInfo) override; - void OnBindResult(const ProcessInfo &processInfo, const PeerTargetId &targetId, int32_t result, - int32_t status, std::string content) override; + EXPORT void OnBindResult(const ProcessInfo &processInfo, + const PeerTargetId &targetId, int32_t result, int32_t status, std::string content) override; - void OnUnbindResult(const ProcessInfo &processInfo, const PeerTargetId &targetId, int32_t result, - std::string content) override; + EXPORT void OnUnbindResult(const ProcessInfo &processInfo, + const PeerTargetId &targetId, int32_t result, std::string content) override; void OnPinHolderCreate(const ProcessInfo &processInfo, const std::string &deviceId, DmPinType pinType, const std::string &payload) override; @@ -104,7 +104,8 @@ private: const DmDeviceInfo &deviceInfo); void RemoveOnlinePkgName(const DmDeviceInfo &info); #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) - int32_t ConvertUdidHashToAnoyAndSave(const std::string &pkgName, DmDeviceInfo &deviceInfo); + EXPORT int32_t ConvertUdidHashToAnoyAndSave(const std::string &pkgName, + DmDeviceInfo &deviceInfo); int32_t ConvertUdidHashToAnoyDeviceId(const std::string &pkgName, const std::string &udidHash, std::string &anoyDeviceId); #endif diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index d4646ac4fbdb4bda603d0eba64c16e54805f524d..07434b79c45c5fc6e8fe60ab63a59f49901ce51d 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -161,7 +161,7 @@ void DeviceManagerService::SubscribePublishCommonEvent() return; } #endif // SUPPORT_BLUETOOTH SUPPORT_WIFI -void DeviceManagerService::SubscribeDataShareCommonEvent() +EXPORT void DeviceManagerService::SubscribeDataShareCommonEvent() { LOGI("DeviceManagerServiceImpl::SubscribeDataShareCommonEvent"); if (dataShareCommonEventManager_ == nullptr) { @@ -269,7 +269,7 @@ int32_t DeviceManagerService::InitDMServiceListener() return DM_OK; } -void DeviceManagerService::UninitDMServiceListener() +EXPORT void DeviceManagerService::UninitDMServiceListener() { listener_ = nullptr; advertiseMgr_ = nullptr; @@ -281,12 +281,12 @@ void DeviceManagerService::UninitDMServiceListener() LOGI("Uninit."); } -void DeviceManagerService::RegisterCallerAppId(const std::string &pkgName) +EXPORT void DeviceManagerService::RegisterCallerAppId(const std::string &pkgName) { AppManager::GetInstance().RegisterCallerAppId(pkgName); } -void DeviceManagerService::UnRegisterCallerAppId(const std::string &pkgName) +EXPORT void DeviceManagerService::UnRegisterCallerAppId(const std::string &pkgName) { AppManager::GetInstance().UnRegisterCallerAppId(pkgName); } @@ -1869,8 +1869,8 @@ void DeviceManagerService::SubscribeScreenLockEvent() return; } -void DeviceManagerService::AccountCommonEventCallback(const std::string commonEventType, int32_t currentUserId, - int32_t beforeUserId) +EXPORT void DeviceManagerService::AccountCommonEventCallback( + const std::string commonEventType, int32_t currentUserId, int32_t beforeUserId) { LOGI("CommonEventType: %{public}s, currentUserId: %{public}d, beforeUserId: %{public}d", commonEventType.c_str(), currentUserId, beforeUserId); @@ -2350,7 +2350,8 @@ int32_t DeviceManagerService::SetDnPolicy(const std::string &pkgName, std::map &bundleManager); std::mutex appIdMapLock_; diff --git a/utils/include/crypto/dm_crypto.h b/utils/include/crypto/dm_crypto.h index 6f766087ac51bed25d674a4aaaabe86b36370bcf..bd4bbaa8ce61a67a46276171f3bf20cc6c8fd717 100644 --- a/utils/include/crypto/dm_crypto.h +++ b/utils/include/crypto/dm_crypto.h @@ -20,29 +20,37 @@ #include "dm_kv_info.h" #endif +#ifndef EXPORT +#define EXPORT __attribute__ ((visibility ("default"))) +#endif // EXPORT + + namespace OHOS { namespace DistributedHardware { class Crypto { public: - static void DmGenerateStrHash(const void *data, size_t dataSize, unsigned char *outBuf, uint32_t outBufLen, - uint32_t startIndex); - static std::string Sha256(const std::string &text, bool isUpper = false); - static std::string Sha256(const void *data, size_t size, bool isUpper = false); - static int32_t ConvertHexStringToBytes(unsigned char *outBuf, uint32_t outBufLen, - const char *inBuf, uint32_t inLen); - static int32_t GetUdidHash(const std::string &udid, unsigned char *udidHash); - static std::string GetGroupIdHash(const std::string &groupId); + EXPORT static void DmGenerateStrHash(const void *data, size_t dataSize, + unsigned char *outBuf, uint32_t outBufLen, uint32_t startIndex); + EXPORT static std::string Sha256(const std::string &text, bool isUpper = false); + EXPORT static std::string Sha256(const void *data, size_t size, + bool isUpper = false); + EXPORT static int32_t ConvertHexStringToBytes(unsigned char *outBuf, + uint32_t outBufLen, const char *inBuf, uint32_t inLen); + EXPORT static int32_t GetUdidHash(const std::string &udid, + unsigned char *udidHash); + EXPORT static std::string GetGroupIdHash(const std::string &groupId); static int32_t GetSecRandom(uint8_t *out, size_t outLen); static std::string GetSecSalt(); static std::string GetHashWithSalt(const std::string &text, const std::string &salt); - static int32_t GetAccountIdHash(const std::string &accountId, unsigned char *accountIdHash); - static int32_t ConvertBytesToHexString(char *outBuf, uint32_t outBufLen, + EXPORT static int32_t GetAccountIdHash(const std::string &accountId, + unsigned char *accountIdHash); + EXPORT static int32_t ConvertBytesToHexString(char *outBuf, uint32_t outBufLen, const unsigned char *inBuf, uint32_t inLen); #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) - static int32_t ConvertUdidHashToAnoyAndSave(const std::string &appId, const std::string &udidHash, - DmKVValue &kvValue); - static int32_t ConvertUdidHashToAnoyDeviceId(const std::string &appId, const std::string &udidHash, - DmKVValue &kvValue); + EXPORT static int32_t ConvertUdidHashToAnoyAndSave(const std::string &appId, + const std::string &udidHash, DmKVValue &kvValue); + EXPORT static int32_t ConvertUdidHashToAnoyDeviceId(const std::string &appId, + const std::string &udidHash, DmKVValue &kvValue); static int32_t GetAnoyDeviceInfo(const std::string &appId, const std::string &udidHash, DmKVValue &kvValue); static int32_t ConvertUdidHashToAnoyGenerate(const std::string &appId, const std::string &udidHash, DmKVValue &kvValue); diff --git a/utils/include/dm_random.h b/utils/include/dm_random.h index 901cfab0b885c104b7c6f0bedf2e51cb33108e6c..0947b4404a27f19f92543ffba465d315e09a7d66 100644 --- a/utils/include/dm_random.h +++ b/utils/include/dm_random.h @@ -19,12 +19,16 @@ #include #include +#ifndef EXPORT +#define EXPORT __attribute__ ((visibility ("default"))) +#endif // EXPORT + namespace OHOS { namespace DistributedHardware { -int32_t GenRandInt(int32_t randMin, int32_t randMax); -int64_t GenRandLongLong(int64_t randMin, int64_t randMax); -uint16_t GenRandUint(uint16_t randMin, uint16_t randMax); -uint16_t GenUniqueRandUint(std::set &randUint16Set); +EXPORT int32_t GenRandInt(int32_t randMin, int32_t randMax); +EXPORT int64_t GenRandLongLong(int64_t randMin, int64_t randMax); +EXPORT uint16_t GenRandUint(uint16_t randMin, uint16_t randMax); +EXPORT uint16_t GenUniqueRandUint(std::set &randUint16Set); } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/include/fwkload/standard/dm_distributed_hardware_load.h b/utils/include/fwkload/standard/dm_distributed_hardware_load.h index a6c0e5e256bcd018ee9aa1c1ce24a7ee020ff5cd..b0c17a9141ee101b5d1ee8309b1e620bab5892c7 100644 --- a/utils/include/fwkload/standard/dm_distributed_hardware_load.h +++ b/utils/include/fwkload/standard/dm_distributed_hardware_load.h @@ -31,7 +31,7 @@ public: class DmDistributedHardwareLoad { DM_DECLARE_SINGLE_INSTANCE(DmDistributedHardwareLoad); public: - void LoadDistributedHardwareFwk(void); + EXPORT void LoadDistributedHardwareFwk(void); void InitDistributedHardwareLoadCount(void); uint32_t GetDistributedHardwareLoadCount(void); private: diff --git a/utils/include/kvadapter/kv_adapter_manager.h b/utils/include/kvadapter/kv_adapter_manager.h index 8dacc074cb384dba9268c396280d143fa332ea98..dde193fcf1e25fa1a6420a9e574b54f28bf5b771 100644 --- a/utils/include/kvadapter/kv_adapter_manager.h +++ b/utils/include/kvadapter/kv_adapter_manager.h @@ -31,13 +31,13 @@ namespace DistributedHardware { class KVAdapterManager { DM_DECLARE_SINGLE_INSTANCE_BASE(KVAdapterManager); public: - int32_t Init(); - void UnInit(); - void ReInit(); + EXPORT int32_t Init(); + EXPORT void UnInit(); + EXPORT void ReInit(); int32_t PutByAnoyDeviceId(const std::string &key, const DmKVValue &value); - int32_t Get(const std::string &key, DmKVValue &value); - int32_t DeleteAgedEntry(); - int32_t AppUnintall(const std::string &appId); + EXPORT int32_t Get(const std::string &key, DmKVValue &value); + EXPORT int32_t DeleteAgedEntry(); + EXPORT int32_t AppUnintall(const std::string &appId); private: KVAdapterManager() = default; diff --git a/utils/include/timer/dm_timer.h b/utils/include/timer/dm_timer.h index 28365a193bfddbbe1f71efe0ee2ae96127db7f9a..52ee3cf4a5addf794bbdf32ca0f5a43adea4668c 100644 --- a/utils/include/timer/dm_timer.h +++ b/utils/include/timer/dm_timer.h @@ -26,35 +26,40 @@ #include "ffrt.h" +#ifndef EXPORT +#define EXPORT __attribute__ ((visibility ("default"))) +#endif // EXPORT + namespace OHOS { namespace DistributedHardware { using TimerCallback = std::function; class DmTimer { public: - DmTimer(); - ~DmTimer(); + EXPORT DmTimer(); + EXPORT ~DmTimer(); /** * @tc.name: DmTimer::StartTimer * @tc.desc: start timer running * @tc.type: FUNC */ - int32_t StartTimer(std::string name, int32_t timeOut, TimerCallback callback); + EXPORT int32_t StartTimer(std::string name, int32_t timeOut, + TimerCallback callback); /** * @tc.name: DmTimer::DeleteTimer * @tc.desc: delete timer * @tc.type: FUNC */ - int32_t DeleteTimer(std::string timerName); + EXPORT int32_t DeleteTimer(std::string timerName); /** * @tc.name: DmTimer::DeleteAll * @tc.desc: delete all timer * @tc.type: FUNC */ - int32_t DeleteAll(); + EXPORT int32_t DeleteAll(); private: mutable std::mutex timerMutex_; diff --git a/utils/src/appInfo/standard/app_manager.cpp b/utils/src/appInfo/standard/app_manager.cpp index 9ed51e77bfe7c2f4b79c152fff8354a036040e5b..5ed61dee5dec98749f6f2b1112ad222115f4534e 100644 --- a/utils/src/appInfo/standard/app_manager.cpp +++ b/utils/src/appInfo/standard/app_manager.cpp @@ -70,7 +70,7 @@ const std::string AppManager::GetAppId() return appId; } -void AppManager::RegisterCallerAppId(const std::string &pkgName) +EXPORT void AppManager::RegisterCallerAppId(const std::string &pkgName) { if (pkgName.empty()) { LOGE("Invalid parameter, pkgName is empty."); @@ -86,7 +86,7 @@ void AppManager::RegisterCallerAppId(const std::string &pkgName) appIdMap_[pkgName] = appId; } -void AppManager::UnRegisterCallerAppId(const std::string &pkgName) +EXPORT void AppManager::UnRegisterCallerAppId(const std::string &pkgName) { if (pkgName.empty()) { LOGE("Invalid parameter, pkgName is empty."); @@ -153,13 +153,13 @@ bool AppManager::IsSystemSA() return false; } -bool AppManager::IsSystemApp() +EXPORT bool AppManager::IsSystemApp() { uint64_t fullTokenId = IPCSkeleton::GetCallingFullTokenID(); return OHOS::Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(fullTokenId); } -int32_t AppManager::GetCallerName(bool isSystemSA, std::string &callerName) +EXPORT int32_t AppManager::GetCallerName(bool isSystemSA, std::string &callerName) { AccessTokenID tokenCaller = IPCSkeleton::GetCallingTokenID(); if (tokenCaller == 0) { @@ -191,7 +191,8 @@ int32_t AppManager::GetCallerName(bool isSystemSA, std::string &callerName) return DM_OK; } -int32_t AppManager::GetNativeTokenIdByName(std::string &processName, int64_t &tokenId) +EXPORT int32_t AppManager::GetNativeTokenIdByName(std::string &processName, + int64_t &tokenId) { AccessTokenID nativeTokenId = AccessTokenKit::GetNativeTokenId(processName); if (nativeTokenId == INVALID_TOKENID) { @@ -202,7 +203,8 @@ int32_t AppManager::GetNativeTokenIdByName(std::string &processName, int64_t &to return DM_OK; } -int32_t AppManager::GetHapTokenIdByName(int32_t userId, std::string &bundleName, int32_t instIndex, int64_t &tokenId) +EXPORT int32_t AppManager::GetHapTokenIdByName(int32_t userId, + std::string &bundleName, int32_t instIndex, int64_t &tokenId) { auto hapTokenId = AccessTokenKit::GetHapTokenID(userId, bundleName, instIndex); if (hapTokenId == 0) { @@ -213,7 +215,7 @@ int32_t AppManager::GetHapTokenIdByName(int32_t userId, std::string &bundleName, return DM_OK; } -int32_t AppManager::GetCallerProcessName(std::string &processName) +EXPORT int32_t AppManager::GetCallerProcessName(std::string &processName) { AccessTokenID tokenCaller = IPCSkeleton::GetCallingTokenID(); if (tokenCaller == 0) { diff --git a/utils/src/crypto/dm_crypto.cpp b/utils/src/crypto/dm_crypto.cpp index 8cc5a88462f4204dd162f3bb21757f9dd6e3e058..6d2ec638da249a11c3338365d3a08a9d1330d28c 100644 --- a/utils/src/crypto/dm_crypto.cpp +++ b/utils/src/crypto/dm_crypto.cpp @@ -64,8 +64,8 @@ void Crypto::DmGenerateStrHash(const void *data, size_t dataSize, unsigned char SHA256_Final(&outBuf[startIndex], &ctx); } -int32_t Crypto::ConvertBytesToHexString(char *outBuf, uint32_t outBufLen, const unsigned char *inBuf, - uint32_t inLen) +EXPORT int32_t Crypto::ConvertBytesToHexString(char *outBuf, uint32_t outBufLen, + const unsigned char *inBuf, uint32_t inLen) { if ((outBuf == nullptr) || (inBuf == nullptr) || (outBufLen < HexifyLen(inLen))) { return ERR_DM_INPUT_PARA_INVALID; @@ -124,8 +124,8 @@ int32_t Crypto::GetUdidHash(const std::string &udid, unsigned char *udidHash) return DM_OK; } -int32_t Crypto::ConvertHexStringToBytes(unsigned char *outBuf, uint32_t outBufLen, const char *inBuf, - uint32_t inLen) +EXPORT int32_t Crypto::ConvertHexStringToBytes(unsigned char *outBuf, + uint32_t outBufLen, const char *inBuf, uint32_t inLen) { (void)outBufLen; if ((outBuf == NULL) || (inBuf == NULL) || (inLen % HEX_TO_UINT8 != 0)) { @@ -164,7 +164,7 @@ int32_t Crypto::ConvertHexStringToBytes(unsigned char *outBuf, uint32_t outBufLe return DM_OK; } -std::string Crypto::GetGroupIdHash(const std::string &groupId) +EXPORT std::string Crypto::GetGroupIdHash(const std::string &groupId) { unsigned char hash[SHA256_DIGEST_LENGTH] = ""; DmGenerateStrHash(groupId.data(), groupId.size(), hash, SHA256_DIGEST_LENGTH, 0); @@ -211,7 +211,8 @@ std::string Crypto::GetHashWithSalt(const std::string &text, const std::string & return Crypto::Sha256(rawText); } -int32_t Crypto::GetAccountIdHash(const std::string &accountId, unsigned char *accountIdHash) +EXPORT int32_t Crypto::GetAccountIdHash(const std::string &accountId, + unsigned char *accountIdHash) { unsigned char hash[SHA256_DIGEST_LENGTH] = ""; DmGenerateStrHash(accountId.data(), accountId.size(), hash, SHA256_DIGEST_LENGTH, 0); @@ -224,8 +225,8 @@ int32_t Crypto::GetAccountIdHash(const std::string &accountId, unsigned char *ac } #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) -int32_t Crypto::ConvertUdidHashToAnoyAndSave(const std::string &appId, const std::string &udidHash, - DmKVValue &kvValue) +EXPORT int32_t Crypto::ConvertUdidHashToAnoyAndSave(const std::string &appId, + const std::string &udidHash, DmKVValue &kvValue) { if (GetAnoyDeviceInfo(appId, udidHash, kvValue) == DM_OK) { kvValue.lastModifyTime = GetSecondsSince1970ToNow(); @@ -241,8 +242,8 @@ int32_t Crypto::ConvertUdidHashToAnoyAndSave(const std::string &appId, const std return DM_OK; } -int32_t Crypto::ConvertUdidHashToAnoyDeviceId(const std::string &appId, const std::string &udidHash, - DmKVValue &kvValue) +EXPORT int32_t Crypto::ConvertUdidHashToAnoyDeviceId(const std::string &appId, + const std::string &udidHash, DmKVValue &kvValue) { LOGI("start."); if (GetAnoyDeviceInfo(appId, udidHash, kvValue) == DM_OK) { diff --git a/utils/src/dm_random.cpp b/utils/src/dm_random.cpp index 0d5955f40d4d609bc5b5d481a15efd38eac2f3b8..4c8f8375afaac4a89e9fa9b558b17640f511a4bd 100644 --- a/utils/src/dm_random.cpp +++ b/utils/src/dm_random.cpp @@ -44,7 +44,7 @@ int32_t GenRandInt(int32_t randMin, int32_t randMax) #endif } -int64_t GenRandLongLong(int64_t randMin, int64_t randMax) +EXPORT int64_t GenRandLongLong(int64_t randMin, int64_t randMax) { std::random_device randDevice; std::mt19937 genRand(randDevice()); diff --git a/utils/src/fwkload/standard/dm_distributed_hardware_load.cpp b/utils/src/fwkload/standard/dm_distributed_hardware_load.cpp index b7c7499e5acaced284dd1a2f0ac9b1cce950f9e4..428a146a5183ccc6ec29cbf561be19401ee048f8 100644 --- a/utils/src/fwkload/standard/dm_distributed_hardware_load.cpp +++ b/utils/src/fwkload/standard/dm_distributed_hardware_load.cpp @@ -25,7 +25,7 @@ namespace DistributedHardware { DM_IMPLEMENT_SINGLE_INSTANCE(DmDistributedHardwareLoad); constexpr uint32_t MAX_LOAD_VALUE = 3; constexpr int32_t DM_OK = 0; -void DmDistributedHardwareLoad::LoadDistributedHardwareFwk(void) +EXPORT void DmDistributedHardwareLoad::LoadDistributedHardwareFwk(void) { LOGI("enter DmDistributedHardwareLoad::LoadDistributedHardwareFwk"); sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); diff --git a/utils/src/kvadapter/kv_adapter_manager.cpp b/utils/src/kvadapter/kv_adapter_manager.cpp index d6bc63755655cf921b6320b096a46a042fcd2c2a..51dc4ece27bc1fe7243b3507db2a47b68a6bebfd 100644 --- a/utils/src/kvadapter/kv_adapter_manager.cpp +++ b/utils/src/kvadapter/kv_adapter_manager.cpp @@ -35,7 +35,7 @@ constexpr int64_t MAX_SUPPORTED_EXIST_TIME = 3 * 24 * 60 * 60; // 3days DM_IMPLEMENT_SINGLE_INSTANCE(KVAdapterManager); -int32_t KVAdapterManager::Init() +EXPORT int32_t KVAdapterManager::Init() { LOGI("Init Kv-Adapter manager"); { @@ -46,7 +46,7 @@ int32_t KVAdapterManager::Init() return kvAdapter_->Init(); } -void KVAdapterManager::UnInit() +EXPORT void KVAdapterManager::UnInit() { LOGI("Uninit Kv-Adapter manager"); CHECK_NULL_VOID(kvAdapter_); @@ -54,7 +54,7 @@ void KVAdapterManager::UnInit() kvAdapter_ = nullptr; } -void KVAdapterManager::ReInit() +EXPORT void KVAdapterManager::ReInit() { LOGI("Re init kv adapter"); CHECK_NULL_VOID(kvAdapter_); @@ -88,7 +88,7 @@ int32_t KVAdapterManager::PutByAnoyDeviceId(const std::string &key, const DmKVVa return DM_OK; } -int32_t KVAdapterManager::Get(const std::string &key, DmKVValue &value) +EXPORT int32_t KVAdapterManager::Get(const std::string &key, DmKVValue &value) { std::string dmKey = DM_KV_STORE_PREFIX + key; std::lock_guard lock(idCacheMapMtx_); @@ -110,7 +110,7 @@ int32_t KVAdapterManager::Get(const std::string &key, DmKVValue &value) return DM_OK; } -int32_t KVAdapterManager::DeleteAgedEntry() +EXPORT int32_t KVAdapterManager::DeleteAgedEntry() { int64_t nowTime = GetSecondsSince1970ToNow(); std::lock_guard lock(idCacheMapMtx_); @@ -129,7 +129,7 @@ inline bool KVAdapterManager::IsTimeOut(int64_t sourceTime, int64_t targetTime, return targetTime - sourceTime >= timeOut ? true : false; } -int32_t KVAdapterManager::AppUnintall(const std::string &appId) +EXPORT int32_t KVAdapterManager::AppUnintall(const std::string &appId) { LOGI("appId %{public}s.", GetAnonyString(appId).c_str()); std::lock_guard lock(idCacheMapMtx_); diff --git a/utils/src/timer/dm_timer.cpp b/utils/src/timer/dm_timer.cpp index cac733ecfdbacddf9e1335927ecd99adfe478e16..e076bebbfaf5f5361b4699f1decde9cb3e37686b 100644 --- a/utils/src/timer/dm_timer.cpp +++ b/utils/src/timer/dm_timer.cpp @@ -85,7 +85,7 @@ int32_t DmTimer::DeleteTimer(std::string timerName) return DM_OK; } -int32_t DmTimer::DeleteAll() +EXPORT int32_t DmTimer::DeleteAll() { LOGI("DmTimer DeleteAll start"); std::lock_guard locker(timerMutex_);