diff --git a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md
index 7a44a95c9963726fb5e8452b245e8441787de5b2..1ac680cbd6e34e07cfdb029049c5609105233586 100644
--- a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md
+++ b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md
@@ -32,3 +32,7 @@
**TDD结果**:
**XTS结果**:
+
+### L0新增用例自检结果
+- [ ] 是,有新增L0用例,且完成自检
+- [ ] 否
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/OAT.xml b/OAT.xml
index c44c80974dafbb33b72de47ebba92f130c413368..df03b803c468eabd3b9ce50905bd9b77104b2940 100644
--- a/OAT.xml
+++ b/OAT.xml
@@ -67,21 +67,6 @@ Note:If the text contains special characters, please escape them according to th
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/bundle.json b/bundle.json
index 6f03c8187d134548243b3432ab4e40f478c6cf72..b21b96d140450fb0d80e65916245bb1ac6ed1117 100644
--- a/bundle.json
+++ b/bundle.json
@@ -16,7 +16,8 @@
"syscap": ["SystemCapability.DistributedHardware.DeviceManager"],
"features": [
"device_manager_no_interaction_auth",
- "device_manager_feature_product"
+ "device_manager_feature_product",
+ "device_manager_enable_ets_frontend"
],
"adapted_system_type": ["standard", "mini"],
"rom": "2048KB",
@@ -56,10 +57,12 @@
"power_manager",
"safwk",
"samgr",
+ "selinux_adapter",
"resource_management",
"wifi",
"screenlock_mgr",
- "mbedtls"
+ "mbedtls",
+ "runtime_core"
],
"third_party": []
},
@@ -67,7 +70,8 @@
"group_type": {
"base_group": [],
"fwk_group": [
- "//foundation/distributedhardware/device_manager:device_manager_fwk"
+ "//foundation/distributedhardware/device_manager:device_manager_fwk",
+ "//foundation/distributedhardware/device_manager/interfaces/kits/taihe:devicemanager_ani"
],
"service_group": [
"//foundation/distributedhardware/device_manager:device_manager",
@@ -98,6 +102,27 @@
],
"header_base": "//foundation/distributedhardware/device_manager/interfaces/mini_tools_kits/native_cpp/include"
}
+ }, {
+ "name": "//foundation/distributedhardware/device_manager/interfaces/cj/kits:cj_distributed_device_manager_ffi"
+ }, {
+ "type": "so",
+ "name": "//foundation/distributedhardware/device_manager/json:devicemanagerjson",
+ "header": {
+ "header_files": [
+ "json_object.h"
+ ],
+ "header_base": "//foundation/distributedhardware/device_manager/json/include"
+ }
+ }, {
+ "type": "so",
+ "name": "//foundation/distributedhardware/device_manager/interfaces/kits/ndk:devicemanager_ndk",
+ "header": {
+ "header_files": [
+ "oh_device_manager_err_code.h",
+ "oh_device_manager.h"
+ ],
+ "header_base": "//foundation/distributedhardware/device_manager/interfaces/kits/ndk/include"
+ }
}],
"test": [
"//foundation/distributedhardware/device_manager:device_manager_test"
diff --git a/common/include/device_manager_ipc_interface_code.h b/common/include/device_manager_ipc_interface_code.h
index 2205bb1d3cb3be9bae26a647160570ca746e88d5..87fd37a49462a65baf4609c41adcfe6b40cc0339 100644
--- a/common/include/device_manager_ipc_interface_code.h
+++ b/common/include/device_manager_ipc_interface_code.h
@@ -115,6 +115,12 @@ enum DMIpcCmdInterfaceCode {
GET_SERVICEINFO_BYBUNDLENAME_PINEXCHANGETYPE,
RESTORE_LOCAL_DEVICE_NAME,
GET_DEVICE_NETWORK_ID_LIST,
+ UNREGISTER_PIN_HOLDER_CALLBACK,
+ GET_LOCAL_DEVICE_NAME,
+ CHECK_SRC_ACCESS_CONTROL,
+ CHECK_SINK_ACCESS_CONTROL,
+ CHECK_SRC_SAME_ACCOUNT,
+ CHECK_SINK_SAME_ACCOUNT,
// Add ipc msg here
IPC_MSG_BUTT
};
diff --git a/common/include/dfx/standard/dm_hisysevent.h b/common/include/dfx/standard/dm_hisysevent.h
index 4553087bdacc2ecc43f334a8823cd3492ea06e33..2b422e7b4f4a68d6e47b62392fd9d1ec1febfae8 100644
--- a/common/include/dfx/standard/dm_hisysevent.h
+++ b/common/include/dfx/standard/dm_hisysevent.h
@@ -18,9 +18,14 @@
#include
+#ifndef DM_EXPORT
+#define DM_EXPORT __attribute__ ((visibility ("default")))
+#endif // DM_EXPORT
+
namespace OHOS {
namespace DistributedHardware {
-void SysEventWrite(const std::string &status, int32_t eventType, const std::string &msg);
+DM_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..260e8c57f2ab881bb85905c9b7aa3052b97e5dd2 100644
--- a/common/include/dfx/standard/dm_hitrace.h
+++ b/common/include/dfx/standard/dm_hitrace.h
@@ -18,10 +18,14 @@
#include
+#ifndef DM_EXPORT
+#define DM_EXPORT __attribute__ ((visibility ("default")))
+#endif // DM_EXPORT
+
namespace OHOS {
namespace DistributedHardware {
-void DmTraceStart(const std::string &msg);
-void DmTraceEnd();
+DM_EXPORT void DmTraceStart(const std::string &msg);
+DM_EXPORT void DmTraceEnd();
} // namespace DistributedHardware
} // namespace OHOS
#endif
diff --git a/common/include/dm_anonymous.h b/common/include/dm_anonymous.h
index 447e310d793acb48ebe953aa981d6d01e2108bd2..f6ba0fdd8172e1c08a518af7bbc5c31fe7599e2f 100644
--- a/common/include/dm_anonymous.h
+++ b/common/include/dm_anonymous.h
@@ -27,15 +27,16 @@ namespace DistributedHardware {
extern const char* PRINT_LIST_SPLIT;
extern const int32_t LIST_SPLIT_LEN;
-std::string GetAnonyString(const std::string &value);
+DM_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);
+DM_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 IsUint64(const JsonItemObject &jsonObj, const std::string &key);
bool IsArray(const JsonItemObject &jsonObj, const std::string &key);
bool IsBool(const JsonItemObject &jsonObj, const std::string &key);
std::string ConvertMapToJsonString(const std::map ¶mMap);
@@ -47,6 +48,7 @@ int64_t StringToInt64(const std::string &str, int32_t base);
void VersionSplitToInt(const std::string &str, const char split, std::vector &numVec);
bool CompareVecNum(const std::vector &srcVecNum, const std::vector &sinkVecNum);
bool CompareVersion(const std::string &remoteVersion, const std::string &oldVersion);
+bool GetVersionNumber(const std::string dmVersion, int32_t &versionNum);
std::string ComposeStr(const std::string &pkgName, uint16_t subscribeId);
std::string GetCallerPkgName(const std::string &pkgName);
uint16_t GetSubscribeId(const std::string &pkgName);
@@ -101,9 +103,11 @@ 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);
+DM_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);
+std::string GetAnonyJsonString(const std::string &value);
+int64_t GetCurrentTimestamp();
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DM_ANONYMOUS_H
diff --git a/common/include/dm_cert.h b/common/include/dm_cert.h
new file mode 100644
index 0000000000000000000000000000000000000000..5080ef8603a258794371a09acfc78e9ec7267d47
--- /dev/null
+++ b/common/include/dm_cert.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2025 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef OHOS_DM_CERT_H
+#define OHOS_DM_CERT_H
+
+#define DM_CERTS_COUNT 4
+#define UDID_BUF_LEN 65
+#define DM_CERTIFICATE_SIZE 8192
+
+#include
+#include
+
+#include "dm_random.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+typedef struct DmBlob {
+ uint32_t size;
+ uint8_t *data;
+} DmBlob;
+
+typedef struct DmCertChain {
+ DmBlob *cert;
+ uint32_t certCount;
+} DmCertChain;
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif //OHOS_DM_CERT_H
\ No newline at end of file
diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h
index cbb3e2a6cd12a48ce89058e4d06c7b1901e583de..e888cde225c58344c6e0da51a09a42526f3c7075 100755
--- a/common/include/dm_constants.h
+++ b/common/include/dm_constants.h
@@ -20,136 +20,147 @@
#include "dm_error_type.h"
+#ifndef DM_EXPORT
+#define DM_EXPORT __attribute__ ((visibility ("default")))
+#endif // DM_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;
+DM_EXPORT extern const char* TAG_GROUP_ID;
+DM_EXPORT extern const char* TAG_GROUP_NAME;
+DM_EXPORT extern const char* TAG_REQUEST_ID;
+DM_EXPORT extern const char* TAG_DEVICE_ID;
+DM_EXPORT extern const char* TAG_AUTH_TYPE;
+DM_EXPORT extern const char* TAG_CRYPTO_SUPPORT;
+DM_EXPORT extern const char* TAG_VER;
+DM_EXPORT extern const char* TAG_MSG_TYPE;
+DM_EXPORT extern const char* DM_ITF_VER;
+DM_EXPORT extern const char* DM_PKG_NAME;
+DM_EXPORT extern const char* DM_SESSION_NAME;
+DM_EXPORT extern const char* DM_PIN_HOLDER_SESSION_NAME;
+DM_EXPORT extern const char* DM_SYNC_USERID_SESSION_NAME;
+DM_EXPORT extern const char* DM_CAPABILITY_OSD;
+DM_EXPORT extern const char* DM_CAPABILITY_APPROACH;
+DM_EXPORT extern const char* DM_CAPABILITY_OH_APPROACH;
+DM_EXPORT extern const char* DM_CAPABILITY_TOUCH;
+DM_EXPORT extern const char* DM_CAPABILITY_CASTPLUS;
+DM_EXPORT extern const char* DM_CAPABILITY_VIRTUAL_LINK;
+DM_EXPORT extern const char* DM_CAPABILITY_SHARE;
+DM_EXPORT extern const char* DM_CAPABILITY_WEAR;
+DM_EXPORT extern const char* DM_CAPABILITY_OOP;
+DM_EXPORT extern const char* DM_CREDENTIAL_TYPE;
+DM_EXPORT extern const char* DM_CREDENTIAL_REQJSONSTR;
+DM_EXPORT extern const char* DM_CREDENTIAL_RETURNJSONSTR;
+DM_EXPORT extern const char* DEVICE_MANAGER_GROUPNAME;
+DM_EXPORT extern const char* FIELD_CREDENTIAL_EXISTS;
+DM_EXPORT extern const char* DM_TYPE_MINE;
+DM_EXPORT extern const char* DM_TYPE_OH;
+DM_EXPORT extern const char* TAG_SESSION_HEARTBEAT;
//The following constant are provided only for HiLink.
-extern const char *EXT_PART;
+DM_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;
-
+DM_EXPORT extern const char* AUTH_TYPE;
+DM_EXPORT extern const char* APP_OPERATION;
+DM_EXPORT extern const char* CUSTOM_DESCRIPTION;
+DM_EXPORT extern const char* TOKEN;
+DM_EXPORT extern const char* PIN_TOKEN;
+DM_EXPORT extern const char* PIN_CODE_KEY;
+DM_EXPORT extern const int32_t CHECK_AUTH_ALWAYS_POS;
+DM_EXPORT extern const char AUTH_ALWAYS;
+DM_EXPORT extern const char AUTH_ONCE;
+DM_EXPORT extern const char* TAG_TARGET_DEVICE_NAME;
+DM_EXPORT extern const int32_t MIN_PINCODE_SIZE;
// HiChain
-extern const int32_t SERVICE_INIT_TRY_MAX_NUM;
+DM_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;
+DM_EXPORT extern const int32_t DEVICE_NETWORKID_LENGTH;
+DM_EXPORT extern const int32_t GROUP_TYPE_INVALID_GROUP;
+DM_EXPORT extern const int32_t GROUP_TYPE_IDENTICAL_ACCOUNT_GROUP;
+DM_EXPORT extern const int32_t GROUP_TYPE_PEER_TO_PEER_GROUP;
+DM_EXPORT extern const int32_t GROUP_TYPE_ACROSS_ACCOUNT_GROUP;
+DM_EXPORT extern const int32_t GROUP_VISIBILITY_PUBLIC;
+DM_EXPORT extern const int64_t MIN_REQUEST_ID;
+DM_EXPORT extern const int64_t MAX_REQUEST_ID;
+DM_EXPORT extern const int32_t AUTH_DEVICE_REQ_NEGOTIATE;
+DM_EXPORT extern const int32_t AUTH_DEVICE_RESP_NEGOTIATE;
+DM_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;
+DM_EXPORT extern const char* FILTER_PARA_RANGE;
+DM_EXPORT extern const char* FILTER_PARA_DEVICE_TYPE;
+DM_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;
+DM_EXPORT extern const char* CONN_ADDR_TYPE_ID;
+DM_EXPORT extern const char* CONN_ADDR_TYPE_BR;
+DM_EXPORT extern const char* CONN_ADDR_TYPE_BLE;
+DM_EXPORT extern const char* CONN_ADDR_TYPE_USB;
+DM_EXPORT extern const char* CONN_ADDR_TYPE_WLAN_IP;
+DM_EXPORT extern const char* CONN_ADDR_TYPE_ETH_IP;
+DM_EXPORT extern const char* CONN_ADDR_TYPE_NCM;
// Softbus connection address type int
-extern const int32_t CONNECTION_ADDR_USB;
+DM_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;
+DM_EXPORT extern const char* PARAM_KEY_META_TYPE;
+DM_EXPORT extern const char* PARAM_KEY_TARGET_ID;
+DM_EXPORT extern const char* PARAM_KEY_BR_MAC;
+DM_EXPORT extern const char* PARAM_KEY_BLE_MAC;
+DM_EXPORT extern const char* PARAM_KEY_WIFI_IP;
+DM_EXPORT extern const char* PARAM_KEY_WIFI_PORT;
+DM_EXPORT extern const char* PARAM_KEY_USB_IP;
+DM_EXPORT extern const char* PARAM_KEY_USB_PORT;
+DM_EXPORT extern const char* PARAM_KEY_NCM_IP;
+DM_EXPORT extern const char* PARAM_KEY_NCM_PORT;
+DM_EXPORT extern const char* PARAM_KEY_AUTH_TOKEN;
+DM_EXPORT extern const char* PARAM_KEY_AUTH_TYPE;
+DM_EXPORT extern const char* PARAM_KEY_PIN_CODE;
+DM_EXPORT extern const char* PARAM_KEY_APP_OPER;
+DM_EXPORT extern const char* PARAM_KEY_APP_DESC;
+DM_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;
-
-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;
-
-extern const char* CONN_SESSION_TYPE_HML;
-extern const char* CONN_SESSION_TYPE_BLE;
+DM_EXPORT extern const char* PARAM_KEY_CONN_ADDR_TYPE;
+DM_EXPORT extern const char* PARAM_KEY_PUBLISH_ID;
+DM_EXPORT extern const char* PARAM_KEY_SUBSCRIBE_ID;
+DM_EXPORT extern const char* PARAM_KEY_TARGET_PKG_NAME;
+DM_EXPORT extern const char* PARAM_KEY_PEER_BUNDLE_NAME;
+DM_EXPORT extern const char* PARAM_KEY_DISC_FREQ;
+DM_EXPORT extern const char* PARAM_KEY_DISC_MEDIUM;
+DM_EXPORT extern const char* PARAM_KEY_DISC_CAPABILITY;
+DM_EXPORT extern const char* PARAM_KEY_DISC_MODE;
+DM_EXPORT extern const char* PARAM_KEY_AUTO_STOP_ADVERTISE;
+DM_EXPORT extern const char* PARAM_KEY_FILTER_OPTIONS;
+DM_EXPORT extern const char* PARAM_KEY_BIND_EXTRA_DATA;
+DM_EXPORT extern const char* PARAM_KEY_OS_TYPE;
+DM_EXPORT extern const char* PARAM_KEY_OS_VERSION;
+DM_EXPORT extern const char* PARAM_KEY_IS_SHOW_TRUST_DIALOG;
+DM_EXPORT extern const char* PARAM_KEY_UDID;
+DM_EXPORT extern const char* PARAM_KEY_UUID;
+DM_EXPORT extern const char* DM_CONNECTION_DISCONNECTED;
+DM_EXPORT extern const char* BIND_LEVEL;
+DM_EXPORT extern const char* TOKENID;
+DM_EXPORT extern const char* DM_BIND_RESULT_NETWORK_ID;
+DM_EXPORT extern const char* PARAM_KEY_POLICY_STRATEGY_FOR_BLE;
+DM_EXPORT extern const char* PARAM_KEY_POLICY_TIME_OUT;
+DM_EXPORT extern const char* DEVICE_SCREEN_STATUS;
+DM_EXPORT extern const char* PROCESS_NAME;
+DM_EXPORT extern const char* PARAM_CLOSE_SESSION_DELAY_SECONDS;
+DM_EXPORT extern const char* DM_AUTHENTICATION_TYPE;
+
+DM_EXPORT extern const char* PARAM_KEY_CONN_SESSIONTYPE;
+DM_EXPORT extern const char* PARAM_KEY_HML_RELEASETIME;
+DM_EXPORT extern const char* PARAM_KEY_HML_ENABLE_160M;
+DM_EXPORT extern const char* PARAM_KEY_HML_ACTIONID;
+
+DM_EXPORT extern const char* CONN_SESSION_TYPE_HML;
+DM_EXPORT extern const char* CONN_SESSION_TYPE_BLE;
+DM_EXPORT extern const char* UN_BIND_PARAM_UDID_KEY;
+
+DM_EXPORT extern const char* DM_BUSINESS_ID;
+
// screen state
enum ScreenState {
DM_SCREEN_UNKNOWN = -1,
@@ -158,12 +169,25 @@ enum ScreenState {
};
// errCode map
-extern const std::map MAP_ERROR_CODE;
+DM_EXPORT extern const std::map MAP_ERROR_CODE;
// wise device
-extern const int32_t MAX_DEVICE_PROFILE_SIZE;
-const int32_t DEIVCE_NAME_MAX_BYTES = 100;
+DM_EXPORT extern const int32_t MAX_DEVICE_PROFILE_SIZE;
+const int32_t DEVICE_NAME_MAX_BYTES = 100;
+
+DM_EXPORT extern const char* ACL_IS_LNN_ACL_KEY;
+DM_EXPORT extern const char* ACL_IS_LNN_ACL_VAL_TRUE;
+DM_EXPORT extern const char* ACL_IS_LNN_ACL_VAL_FALSE;
-extern const char* PICKER_PROXY_SPLIT;
+extern const char* DM_VERSION_5_0_1;
+extern const char* DM_VERSION_5_0_2;
+extern const char* DM_VERSION_5_0_3;
+extern const char* DM_VERSION_5_0_4;
+extern const char* DM_VERSION_5_0_5;
+extern const char* DM_VERSION_5_1_0;
+extern const char* DM_VERSION_5_1_1;
+extern const char* DM_CURRENT_VERSION;
+extern const char* DM_ACL_AGING_VERSION;
+extern const char* DM_VERSION_5_0_OLD_MAX; // Estimated highest version number of the old version
} // namespace DistributedHardware
} // namespace OHOS
-#endif // OHOS_DM_CONSTANTS_H
\ No newline at end of file
+#endif // OHOS_DM_CONSTANTS_H
diff --git a/common/include/dm_error_type.h b/common/include/dm_error_type.h
index 2d2b96fe2d4b863912ac2f8389b1d58c5bc6d74b..e06815c3ca4e5ac02f8e9e07dd58a9a928878de2 100644
--- a/common/include/dm_error_type.h
+++ b/common/include/dm_error_type.h
@@ -22,7 +22,7 @@ enum {
DM_OK = 0,
SOFTBUS_OK = 0,
STOP_BIND = 1,
-
+ DM_ALREADY_AUTHED = 2,
/* Transfer to the other end device, not define specification error code */
ERR_DM_NOT_SYSTEM_APP = 202,
ERR_DM_TIME_OUT = -20001,
@@ -110,7 +110,7 @@ enum {
ERR_DM_CRYPTO_OPT_FAILED = 96929822,
ERR_DM_CRYPTO_PARA_INVALID = 96929823,
ERR_DM_SECURITY_FUNC_FAILED = 96929824,
- ERR_DM_MAX_SIZE_FAIL = 96929825,
+ ERR_DM_CALLBACK_REGISTER_FAILED = 96929825,
ERR_DM_HILINKSVC_RSP_PARSE_FAILD = 96929826,
ERR_DM_HILINKSVC_REPLY_FAILED = 96929827,
ERR_DM_HILINKSVC_ICON_URL_EMPTY = 96929828,
@@ -121,6 +121,28 @@ enum {
ERR_DM_PROCESS_SESSION_KEY_FAILED = 96929833,
ERR_DM_HILINKSVC_SCAS_CHECK_FAILED = 96929834,
ERR_DM_FIND_NETWORKID_LIST_EMPTY = 96929835,
+ ERR_DM_GET_SESSION_KEY_FAILED = 96929836,
+ ERR_DM_QUADRUPLE_NOT_SAME = 96929837,
+ ERR_DM_NEXT_STATE_INVALID = 96929838,
+ ERR_DM_LOGIC_SESSION_CREATE_FAILED = 96929839,
+ ERR_DM_SESSION_CLOSED = 96929840,
+ ERR_DM_GET_LOCAL_USERID_FAILED = 969298341,
+ ERR_DM_CAPABILITY_NEGOTIATE_FAILED = 969298342,
+ ERR_DM_BIND_TRUST_TARGET = 969298343,
+ ERR_DM_BINDTARGET_SCREEN_LOCK = 969298344,
+ ERR_DM_NO_REPLAY = 969298345,
+ ERR_DM_GET_TOKENID_FAILED = 969298346,
+ ERR_DM_SHOW_CONFIRM_FAILED = 969298347,
+ ERR_DM_PARSE_MESSAGE_FAILED = 969298348,
+ ERR_DM_GET_BMS_FAILED = 969298349,
+ ERR_DM_DESERIAL_CERT_FAILED = 969298350,
+ ERR_DM_VERIFY_CERT_FAILED = 969298351,
+ ERR_DM_GET_PARAM_FAILED = 969298352,
+ ERR_DM_VERIFY_SAME_ACCOUNT_FAILED = 969298353,
+ ERR_DM_GET_BUNDLE_NAME_FAILED = 969298354,
+ ERR_DM_DEVICE_FROZEN = 969298355,
+ ERR_DM_SOCKET_IN_USED = 969298356,
+ ERR_DM_ANTI_DISTURB_MODE = 969298357,
};
} // namespace DistributedHardware
} // namespace OHOS
diff --git a/common/include/dm_single_instance.h b/common/include/dm_single_instance.h
index 7ecf417976c32c51fddd8c0ed2c8412b32361f1c..11da29f4e419ba03dba4ba2865aab6da158548e9 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 DM_EXPORT
+#define DM_EXPORT __attribute__ ((visibility ("default")))
+#endif // DM_EXPORT
+
namespace OHOS {
namespace DistributedHardware {
#define DM_DECLARE_SINGLE_INSTANCE_BASE(className) \
public: \
- static className &GetInstance(); \
+ DM_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() \
+ DM_EXPORT className &className::GetInstance() \
{ \
static auto instance = new className(); \
return *instance; \
diff --git a/common/include/i_dm_auth_cert_ext.h b/common/include/i_dm_auth_cert_ext.h
new file mode 100644
index 0000000000000000000000000000000000000000..fafda279c421563357281076ee117c98e5f000f8
--- /dev/null
+++ b/common/include/i_dm_auth_cert_ext.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2025 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_I_DM_AUTH_CERT_EXT_H
+#define OHOS_I_DM_AUTH_CERT_EXT_H
+
+#include "dm_cert.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+class IDMAuthCertExt {
+public:
+ virtual ~IDMAuthCertExt() = default;
+ virtual int32_t GenerateCertificate(DmCertChain &dmCertChain) = 0;
+ virtual int32_t VerifyCertificate(const DmCertChain &dmCertChain, const char *deviceIdHash) = 0;
+};
+
+using CreateDMAuthCertFuncPtr = IDMAuthCertExt *(*)(void);
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_I_DM_AUTH_CERT_EXT_H
\ No newline at end of file
diff --git a/common/include/ipc/model/ipc_common_param_req.h b/common/include/ipc/model/ipc_common_param_req.h
index 139f74d9ba0e5ff5c1958c15703c54b9830eaba5..b5d8e6cb2bfe463bd5fa231be8caac3889ebe4b6 100644
--- a/common/include/ipc/model/ipc_common_param_req.h
+++ b/common/include/ipc/model/ipc_common_param_req.h
@@ -64,19 +64,19 @@ public:
secondParam_ = secondParam;
}
- int64_t GetInt32Param() const
+ int32_t GetInt32Param() const
{
return int32Param_;
}
- void SetInt32Param(int64_t param)
+ void SetInt32Param(int32_t param)
{
int32Param_ = param;
}
private:
std::string firstParam_;
std::string secondParam_;
- int64_t int32Param_ = 0;
+ int32_t int32Param_ = 0;
};
} // namespace DistributedHardware
} // namespace OHOS
diff --git a/common/include/ipc/model/ipc_get_local_device_name_rsp.h b/common/include/ipc/model/ipc_get_local_device_name_rsp.h
new file mode 100644
index 0000000000000000000000000000000000000000..c97c21ac00bbc903db656ad9d5ccabb3e589a670
--- /dev/null
+++ b/common/include/ipc/model/ipc_get_local_device_name_rsp.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2025 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OHOS_DM_IPC_GET_LOCAL_DEVICE_NAME_RSP_H
+#define OHOS_DM_IPC_GET_LOCAL_DEVICE_NAME_RSP_H
+
+#include "ipc_req.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+class IpcGetLocalDeviceNameRsp : public IpcRsp {
+ DECLARE_IPC_MODEL(IpcGetLocalDeviceNameRsp);
+
+public:
+
+ const std::string GetLocalDeviceName() const
+ {
+ return localDeviceName_;
+ }
+
+ void SetLocalDeviceName(const std::string &localDeviceName)
+ {
+ localDeviceName_ = localDeviceName;
+ }
+
+private:
+ std::string localDeviceName_;
+};
+} // namespace DistributedHardware
+} // namespace OHOS
+#endif // OHOS_DM_IPC_GET_LOCAL_DEVICE_NAME_RSP_H
diff --git a/common/src/dm_anonymous.cpp b/common/src/dm_anonymous.cpp
index 0bf73567f010750bfb57fe9a1edc37ef4f86b9a2..69b50d5cc8a0cd625b1935df2a6dfb1db7c1dd49 100644
--- a/common/src/dm_anonymous.cpp
+++ b/common/src/dm_anonymous.cpp
@@ -16,6 +16,8 @@
#include "dm_anonymous.h"
#include "dm_log.h"
#include
+#include
+
namespace OHOS {
namespace DistributedHardware {
namespace {
@@ -156,6 +158,16 @@ bool IsInt64(const JsonItemObject &jsonObj, const std::string &key)
return res;
}
+bool IsUint64(const JsonItemObject &jsonObj, const std::string &key)
+{
+ bool res = jsonObj.Contains(key) && jsonObj[key].IsNumberInteger() && jsonObj[key].Get() >= 0 &&
+ jsonObj[key].Get() <= UINT64_MAX;
+ if (!res) {
+ LOGE("the key %{public}s in jsonObj is invalid.", key.c_str());
+ }
+ return res;
+}
+
bool IsArray(const JsonItemObject &jsonObj, const std::string &key)
{
bool res = jsonObj.Contains(key) && jsonObj[key].IsArray();
@@ -299,6 +311,24 @@ bool CompareVersion(const std::string &remoteVersion, const std::string &oldVers
return CompareVecNum(remoteVersionVec, oldVersionVec);
}
+bool GetVersionNumber(const std::string dmVersion, int32_t &versionNum)
+{
+ LOGI("dmVersion %{public}s,", dmVersion.c_str());
+ std::string number = "";
+ std::istringstream iss(dmVersion);
+ std::string item = "";
+ while (getline(iss, item, '.')) {
+ number += item;
+ }
+ LOGI("number %{public}s,", number.c_str());
+ versionNum = atoi(number.c_str());
+ if (versionNum <= 0) {
+ LOGE("convert failed, number: %{public}s,", number.c_str());
+ return false;
+ }
+ return true;
+}
+
std::string ComposeStr(const std::string &pkgName, uint16_t subscribeId)
{
std::string strTemp = pkgName + "#" + std::to_string(subscribeId);
@@ -368,7 +398,7 @@ bool IsDmCommonNotifyEventValid(DmCommonNotifyEvent dmCommonNotifyEvent)
return false;
}
-std::string SafetyDump(const JsonItemObject &jsonObj)
+DM_EXPORT std::string SafetyDump(const JsonItemObject &jsonObj)
{
return jsonObj.Dump();
}
@@ -409,5 +439,32 @@ bool IsJsonValIntegerString(const JsonItemObject &jsonObj, const std::string &ke
}
return true;
}
+
+std::string GetAnonyJsonString(const std::string &value)
+{
+ if (value.empty()) {
+ return "";
+ }
+ JsonObject paramJson(value);
+ if (paramJson.IsDiscarded()) {
+ return "";
+ }
+ const std::set sensitiveKey = { "LOCALDEVICEID", "localAccountId", "networkId", "lnnPublicKey",
+ "transmitPublicKey", "DEVICEID", "deviceId", "keyValue", "deviceName", "REMOTE_DEVICE_NAME", "data" };
+
+ for (auto &element : paramJson.Items()) {
+ if (element.IsString() && sensitiveKey.find(element.Key()) != sensitiveKey.end()) {
+ paramJson[element.Key()] = GetAnonyString(element.Get());
+ }
+ }
+ return paramJson.Dump();
+}
+
+int64_t GetCurrentTimestamp()
+{
+ auto now = std::chrono::system_clock::now();
+ auto duration = std::chrono::duration_cast(now.time_since_epoch());
+ return duration.count();
+}
} // namespace DistributedHardware
} // namespace OHOS
\ No newline at end of file
diff --git a/common/src/dm_constants.cpp b/common/src/dm_constants.cpp
index 2f91c8ca548b0a9fb73c387c839a143d657829b5..73eee5e9c48dbb4fbd72ca726c2bb87022404878 100644
--- a/common/src/dm_constants.cpp
+++ b/common/src/dm_constants.cpp
@@ -32,6 +32,7 @@ const char* DM_PIN_HOLDER_SESSION_NAME = "ohos.distributedhardware.devicemanager
const char* DM_SYNC_USERID_SESSION_NAME = "ohos.distributedhardware.devicemanager.syncuserid";
const char* DM_CAPABILITY_OSD = "osdCapability";
const char* DM_CAPABILITY_APPROACH = "approach";
+const char* DM_CAPABILITY_OH_APPROACH = "oh_approach";
const char* DM_CAPABILITY_TOUCH = "touch";
const char* DM_CAPABILITY_CASTPLUS = "castPlus";
const char* DM_CAPABILITY_VIRTUAL_LINK = "virtualLink";
@@ -61,7 +62,7 @@ const int32_t CHECK_AUTH_ALWAYS_POS = 0;
const char AUTH_ALWAYS = '1';
const char AUTH_ONCE = '0';
const char* TAG_TARGET_DEVICE_NAME = "targetDeviceName";
-const int32_t INVALID_PINCODE = -1;
+const int32_t MIN_PINCODE_SIZE = 6;
// HiChain
const int32_t SERVICE_INIT_TRY_MAX_NUM = 200;
@@ -89,6 +90,7 @@ const char* CONN_ADDR_TYPE_BLE = "BLE_TYPE";
const char* CONN_ADDR_TYPE_USB = "USB_TYPE";
const char* CONN_ADDR_TYPE_WLAN_IP = "WLAN_IP_TYPE";
const char* CONN_ADDR_TYPE_ETH_IP = "ETH_IP_TYPE";
+const char* CONN_ADDR_TYPE_NCM = "NCM_TYPE";
// Softbus connection address type int
const int32_t CONNECTION_ADDR_USB = 5;
@@ -102,6 +104,8 @@ const char* PARAM_KEY_WIFI_IP = "WIFI_IP";
const char* PARAM_KEY_WIFI_PORT = "WIFI_PORT";
const char* PARAM_KEY_USB_IP = "USB_IP";
const char* PARAM_KEY_USB_PORT = "USB_PORT";
+const char* PARAM_KEY_NCM_IP = "NCM_IP";
+const char* PARAM_KEY_NCM_PORT = "NCM_PORT";
const char* PARAM_KEY_AUTH_TOKEN = "AUTH_TOKEN";
const char* PARAM_KEY_AUTH_TYPE = "AUTH_TYPE";
const char* PARAM_KEY_PIN_CODE = "PIN_CODE";
@@ -143,6 +147,9 @@ const char* PARAM_KEY_HML_ACTIONID = "hmlActionId";
const char* CONN_SESSION_TYPE_HML = "HML";
const char* CONN_SESSION_TYPE_BLE = "BLE";
+const char* UN_BIND_PARAM_UDID_KEY = "udidKey";
+
+const char* DM_BUSINESS_ID = "business_id";
// errCode map
const std::map MAP_ERROR_CODE = {
@@ -155,7 +162,19 @@ const std::map MAP_ERROR_CODE = {
// wise device
const int32_t MAX_DEVICE_PROFILE_SIZE = 500;
+const char* ACL_IS_LNN_ACL_KEY = "IsLnnAcl";
+const char* ACL_IS_LNN_ACL_VAL_TRUE = "true";
+const char* ACL_IS_LNN_ACL_VAL_FALSE = "false";
-const char* PICKER_PROXY_SPLIT = "_pickerProxy_";
+const char* DM_VERSION_5_0_1 = "5.0.1";
+const char* DM_VERSION_5_0_2 = "5.0.2";
+const char* DM_VERSION_5_0_3 = "5.0.3";
+const char* DM_VERSION_5_0_4 = "5.0.4";
+const char* DM_VERSION_5_0_5 = "5.0.5";
+const char* DM_VERSION_5_1_0 = "5.1.0";
+const char* DM_VERSION_5_1_1 = "5.1.1";
+const char* DM_CURRENT_VERSION = DM_VERSION_5_1_1;
+const char* DM_ACL_AGING_VERSION = DM_VERSION_5_1_0;
+const char* DM_VERSION_5_0_OLD_MAX = "5.0.99"; // Estimated highest version number of the old version
} // namespace DistributedHardware
} // namespace OHOS
\ No newline at end of file
diff --git a/common/src/ipc/standard/ipc_model_codec.cpp b/common/src/ipc/standard/ipc_model_codec.cpp
index 5790e45effa170e21ed328defcd97e96fcbefd85..e582e1bcd8eabac56fe5bb5dc5acecc1fcc225cf 100644
--- a/common/src/ipc/standard/ipc_model_codec.cpp
+++ b/common/src/ipc/standard/ipc_model_codec.cpp
@@ -23,6 +23,7 @@ namespace DistributedHardware {
namespace {
constexpr const char* UK_SEPARATOR = "#";
constexpr int32_t MAX_ICON_SIZE = 4 * 1024 * 1024;
+constexpr uint32_t IPC_VECTOR_MAX_SIZE = 1000;
}
#define READ_HELPER_RET(parcel, type, out, failRet) \
@@ -93,8 +94,10 @@ bool IpcModelCodec::EncodeDmAccessCallee(const DmAccessCallee &callee, MessagePa
bRet = (bRet && parcel.WriteString(callee.accountId));
bRet = (bRet && parcel.WriteString(callee.networkId));
bRet = (bRet && parcel.WriteString(callee.peerId));
+ bRet = (bRet && parcel.WriteString(callee.pkgName));
bRet = (bRet && parcel.WriteInt32(callee.userId));
bRet = (bRet && parcel.WriteString(callee.extra));
+ bRet = (bRet && parcel.WriteUint64(callee.tokenId));
return bRet;
}
@@ -376,6 +379,10 @@ bool IpcModelCodec::EncodeLocalServiceInfos(const std::vector IPC_VECTOR_MAX_SIZE) {
+ LOGE("num is Invalid value, num = %{public}u", num);
+ return false;
+ }
for (uint32_t k = 0; k < num; k++) {
DMLocalServiceInfo serviceInfo = serviceInfos[k];
bRet = EncodeLocalServiceInfo(serviceInfo, parcel);
@@ -460,8 +467,8 @@ bool IpcModelCodec::DecodeStringVector(MessageParcel &parcel, std::vector MAX_DEVICE_PROFILE_SIZE) {
- LOGE("num is Invalid value, num = %{public}zu", num);
+ if (num > IPC_VECTOR_MAX_SIZE) {
+ LOGE("num is Invalid value, num = %{public}u", num);
return false;
}
for (uint32_t k = 0; k < num; k++) {
diff --git a/commondependency/BUILD.gn b/commondependency/BUILD.gn
index 615025355e0ca70367f2ff69cb607332b3d014b1..db0d575ddf1a628205d04c6b321db99f80f3fac6 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,79 @@ 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",
+ "${json_path}:devicemanagerjson",
+ "${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",
+ "eventhandler:libeventhandler",
+ "hilog:libhilog",
+ "init:libbegetutil",
+ "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",
@@ -57,6 +143,7 @@ ohos_shared_library("devicemanagerdependency") {
deps = [
"${innerkits_path}/native_cpp:devicemanagersdk",
+ "${json_path}:devicemanagerjson",
"${utils_path}:devicemanagerutils",
]
@@ -65,7 +152,9 @@ ohos_shared_library("devicemanagerdependency") {
"c_utils:utils",
"device_info_manager:distributed_device_profile_common",
"device_info_manager:distributed_device_profile_sdk",
+ "eventhandler:libeventhandler",
"hilog:libhilog",
+ "init:libbegetutil",
"ipc:ipc_core",
"os_account:libaccountkits",
"samgr:samgr_proxy",
diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h
index 3cff80ef815fbbcf19add3a6c73383952d2a579c..1aa8990e17a5031f78fa60426d4f400ebc7c6ec6 100644
--- a/commondependency/include/deviceprofile_connector.h
+++ b/commondependency/include/deviceprofile_connector.h
@@ -22,27 +22,39 @@
#include "dm_single_instance.h"
#include "i_dp_inited_callback.h"
#include "local_service_info.h"
+#include "parameter.h"
#include "trusted_device_info.h"
+#include "json_object.h"
enum AllowAuthType {
ALLOW_AUTH_ONCE = 1,
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;
-
-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;
+DM_EXPORT extern const uint32_t INVALIED_TYPE;
+DM_EXPORT extern const uint32_t APP_PEER_TO_PEER_TYPE;
+DM_EXPORT extern const uint32_t APP_ACROSS_ACCOUNT_TYPE;
+DM_EXPORT extern const uint32_t SHARE_TYPE;
+DM_EXPORT extern const uint32_t DEVICE_PEER_TO_PEER_TYPE;
+DM_EXPORT extern const uint32_t DEVICE_ACROSS_ACCOUNT_TYPE;
+DM_EXPORT extern const uint32_t IDENTICAL_ACCOUNT_TYPE;
+DM_EXPORT extern const uint32_t SERVICE_PEER_TO_PEER_TYPE;
+DM_EXPORT extern const uint32_t SERVICE_ACROSS_ACCOUNT_TYPE;
+
+DM_EXPORT extern const uint32_t DM_INVALIED_TYPE;
+DM_EXPORT extern const uint32_t USER;
+DM_EXPORT extern const uint32_t SERVICE;
+DM_EXPORT extern const uint32_t APP;
+
+extern const char* TAG_PEER_BUNDLE_NAME;
+DM_EXPORT extern const char* TAG_PEER_TOKENID;
+
+const uint32_t DM_IDENTICAL_ACCOUNT = 1;
+const uint32_t DM_SHARE = 2;
+const uint32_t DM_LNN = 3;
+const uint32_t DM_POINT_TO_POINT = 256;
+const uint32_t DM_ACROSS_ACCOUNT = 1282;
+const int32_t DM_VERSION_INT_5_1_0 = 510;
enum ProfileState {
INACTIVE = 0,
@@ -86,12 +98,38 @@ typedef struct DmAccessee {
std::string trustDeviceName;
} DmAccessee;
+typedef struct DmAclIdParam {
+ std::string udid;
+ int32_t userId;
+ int64_t accessControlId;
+ int32_t skId;
+ std::string credId;
+} DmAclIdParam;
+
typedef struct DmOfflineParam {
uint32_t bindType;
std::vector processVec;
+ std::vector credIdVec;
+ std::vector skIdVec;
int32_t leftAclNumber;
+ int32_t peerUserId;
+ bool hasLnnAcl = false;
+ int64_t accessControlId;
+ // save the need unbind acl info
+ std::vector needDelAclInfos;
+ // save all the lnn acl between localdevid/localuserId -> remotedevid
+ std::vector allLnnAclInfos;
+ // save all the app or service acl between localdevid/localuserId -> remotedevid except the need del ones
+ std::vector allLeftAppOrSvrAclInfos;
+ // save all the user acl between localdevid/localuserId -> remotedevid
+ std::vector allUserAclInfos;
} DmOfflineParam;
+struct AclHashItem {
+ std::string version;
+ std::vector aclHashList;
+};
+
namespace OHOS {
namespace DistributedHardware {
class IDeviceProfileConnector {
@@ -107,101 +145,176 @@ public:
virtual int32_t HandleUserStop(int32_t stopUserId, const std::string &stopEventUdid) = 0;
virtual int32_t HandleUserStop(int32_t stopUserId, const std::string &localUdid,
const std::vector &acceptEventUdids) = 0;
+ virtual int32_t HandleAccountCommonEvent(const std::string &localUdid, const std::vector &deviceVec,
+ const std::vector &foregroundUserIds, const std::vector &backgroundUserIds) = 0;
};
class DeviceProfileConnector : public IDeviceProfileConnector {
DM_DECLARE_SINGLE_INSTANCE(DeviceProfileConnector);
public:
- std::vector GetAccessControlProfile();
+ DM_EXPORT DmOfflineParam FilterNeedDeleteACL(const std::string &localDeviceId, uint32_t localTokenId,
+ const std::string &remoteDeviceId, const std::string &extra);
+ DM_EXPORT std::vector
+ GetAccessControlProfile();
+ DM_EXPORT DmOfflineParam HandleServiceUnBindEvent(int32_t remoteUserId,
+ const std::string &remoteUdid, const std::string &localUdid, int32_t tokenId);
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);
+ DM_EXPORT uint32_t CheckBindType(std::string peerUdid, std::string localUdid);
+ DM_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);
+ DM_EXPORT std::unordered_map GetAppTrustDeviceList(
+ const std::string &pkgName, const std::string &deviceId);
+ DM_EXPORT std::vector GetBindTypeByPkgName(std::string pkgName,
+ std::string requestDeviceId, std::string trustUdid);
+ DM_EXPORT uint64_t GetTokenIdByNameAndDeviceId(std::string extra, std::string requestDeviceId);
+ DM_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);
- 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);
+
+ DM_EXPORT bool DeleteAclForAccountLogOut(const std::string &localUdid,
+ int32_t localUserId, const std::string &peerUdid, int32_t peerUserId, DmOfflineParam &offlineParam);
+ DM_EXPORT void DeleteAclForUserRemoved(std::string localUdid, int32_t userId, std::vector peerUdids,
+ std::multimap &peerUserIdMap, DmOfflineParam &offlineParam);
+ DM_EXPORT void DeleteAclForRemoteUserRemoved(std::string peerUdid,
+ int32_t peerUserId, std::vector &userIds, DmOfflineParam &offlineParam);
+ DM_EXPORT DmOfflineParam DeleteAccessControlList(const std::string &pkgName,
+ const std::string &localDeviceId, const std::string &remoteDeviceId, int32_t bindLevel,
+ const std::string &extra);
+ DM_EXPORT std::vector
+ GetProcessInfoFromAclByUserId(const std::string &localDeviceId, const std::string &targetDeviceId,
+ int32_t userId);
+ DM_EXPORT bool CheckSrcDevIdInAclForDevBind(const std::string &pkgName,
+ const std::string &deviceId);
+ DM_EXPORT bool CheckSinkDevIdInAclForDevBind(const std::string &pkgName,
+ const std::string &deviceId);
+
+ DM_EXPORT uint32_t DeleteTimeOutAcl(const std::string &deviceId, DmOfflineParam &offlineParam);
+ DM_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);
+ DM_EXPORT int32_t IsSameAccount(const std::string &udid);
+ DM_EXPORT bool CheckAccessControl(const DmAccessCaller &caller,
+ const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid);
+ DM_EXPORT bool CheckIsSameAccount(const DmAccessCaller &caller,
+ const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid);
+ DM_EXPORT void DeleteAccessControlList(const std::string &udid);
+ DM_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);
+ DM_EXPORT std::vector GetDeviceIdAndUdidListByTokenId(const std::vector &userIds,
+ const std::string &localUdid, int32_t tokenId);
+ DM_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,
+
+ DM_EXPORT int32_t HandleDevUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid,
+ const std::string &localUdid, DmOfflineParam &offlineParam);
+ DM_EXPORT DmOfflineParam 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,
+ DM_EXPORT DmOfflineParam 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);
+ DM_EXPORT std::vector
+ GetAllAccessControlProfile();
+ DM_EXPORT std::vector GetAllAclIncludeLnnAcl();
+ DM_EXPORT void DeleteAccessControlById(int64_t accessControlId);
+ DM_EXPORT int32_t HandleUserSwitched(const std::string &localUdid,
+ const std::vector &deviceVec, int32_t currentUserId, int32_t beforeUserId);
+ DM_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,
- const std::vector &inActiveProfiles,
- const std::vector &delActiveProfiles);
- void HandleSyncForegroundUserIdEvent(const std::vector &remoteUserIds, const std::string &remoteUdid,
+ DM_EXPORT void HandleUserSwitched(
+ const std::vector &activeProfiles,
+ const std::vector &inActiveProfiles);
+ DM_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,
+ DM_EXPORT std::map GetUserIdAndBindLevel(
+ const std::string &localUdid, const std::string &peerUdid);
+ DM_EXPORT 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,
+ const std::vector &remoteBackUserIds, DmOfflineParam &offlineParam);
+ DM_EXPORT std::multimap GetDevIdAndUserIdByActHash(
+ const std::string &localUdid, const std::string &peerUdid, int32_t peerUserId,
+ const std::string &peerAccountHash);
+ DM_EXPORT std::multimap GetDeviceIdAndUserId(
+ const std::string &localUdid, int32_t localUserId);
+ DM_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,
+ DM_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);
+
+ DM_EXPORT int32_t DeleteSessionKey(int32_t userId, int32_t sessionKeyId);
+ DM_EXPORT int32_t SubscribeDeviceProfileInited(
+ sptr dpInitedCallback);
+ DM_EXPORT int32_t UnSubscribeDeviceProfileInited();
+ DM_EXPORT int32_t PutAllTrustedDevices(
+ const std::vector &deviceInfos);
+ DM_EXPORT int32_t CheckDeviceInfoPermission(const std::string &localUdid,
+ const std::string &peerDeviceId);
+ DM_EXPORT int32_t UpdateAclDeviceName(const std::string &udid,
+ const std::string &newDeviceName);
+ DM_EXPORT int32_t PutLocalServiceInfo(
+ const DistributedDeviceProfile::LocalServiceInfo &localServiceInfo);
+ DM_EXPORT int32_t DeleteLocalServiceInfo(const std::string &bundleName,
+ int32_t pinExchangeType);
+ DM_EXPORT int32_t UpdateLocalServiceInfo(
+ const DistributedDeviceProfile::LocalServiceInfo &localServiceInfo);
+ DM_EXPORT int32_t GetLocalServiceInfoByBundleNameAndPinExchangeType(
+ const std::string &bundleName, int32_t pinExchangeType,
+ DistributedDeviceProfile::LocalServiceInfo &localServiceInfo);
+ DM_EXPORT int32_t PutSessionKey(int32_t userId, 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);
-
+ DM_EXPORT std::string IsAuthNewVersion(int32_t bindLevel, std::string localUdid, std::string remoteUdid,
+ int32_t tokenId, int32_t userId);
+ std::vector GetAclProfileByDeviceIdAndUserId(
+ const std::string &deviceId, int32_t userId, const std::string &remoteDeviceId);
+ DM_EXPORT std::vector GetAclList(const std::string localUdid,
+ int32_t localUserId, const std::string remoteUdid, int32_t remoteUserId);
+ DM_EXPORT bool ChecksumAcl(DistributedDeviceProfile::AccessControlProfile &acl,
+ std::vector &acLStrList);
+ DM_EXPORT std::string AccessToStr(DistributedDeviceProfile::AccessControlProfile acl);
+ DM_EXPORT int32_t GetVersionByExtra(std::string &extraInfo, std::string &dmVersion);
+ DM_EXPORT void GetAllVerionAclMap(DistributedDeviceProfile::AccessControlProfile &acl,
+ std::map> &aclMap, std::string dmVersion = "");
+ void GenerateAclHash(DistributedDeviceProfile::AccessControlProfile &acl,
+ std::map> &aclMap, const std::string &dmVersion);
+ DM_EXPORT int32_t CheckIsSameAccountByUdidHash(const std::string &udidHash);
+ DM_EXPORT int32_t GetAclListHashStr(const DevUserInfo &localDevUserInfo,
+ const DevUserInfo &remoteDevUserInfo, std::string &aclListHash, std::string dmVersion = "");
+ DM_EXPORT bool IsLnnAcl(const DistributedDeviceProfile::AccessControlProfile &profile);
+ DM_EXPORT void CacheAcerAclId(const DistributedDeviceProfile::AccessControlProfile &profile,
+ std::vector &aclInfos);
+ DM_EXPORT void CacheAceeAclId(const DistributedDeviceProfile::AccessControlProfile &profile,
+ std::vector &aclInfos);
+ DM_EXPORT void AclHashItemToJson(JsonItemObject &itemObject, const AclHashItem &value);
+ DM_EXPORT void AclHashVecToJson(JsonItemObject &itemObject, const std::vector &values);
+ DM_EXPORT void AclHashItemFromJson(const JsonItemObject &itemObject, AclHashItem &value);
+ DM_EXPORT void AclHashVecFromJson(const JsonItemObject &itemObject, std::vector &values);
+ void DeleteCacheAcl(std::vector delAclIdVec,
+ std::vector &profiles);
+ DM_EXPORT int32_t HandleAccountCommonEvent(const std::string &localUdid, const std::vector &deviceVec,
+ const std::vector &foregroundUserIds, const std::vector &backgroundUserIds);
+ DM_EXPORT bool CheckSrcAccessControl(const DmAccessCaller &caller, const std::string &srcUdid,
+ const DmAccessCallee &callee, const std::string &sinkUdid);
+ DM_EXPORT bool CheckSinkAccessControl(const DmAccessCaller &caller, const std::string &srcUdid,
+ const DmAccessCallee &callee, const std::string &sinkUdid);
+ DM_EXPORT bool CheckSrcIsSameAccount(const DmAccessCaller &caller, const std::string &srcUdid,
+ const DmAccessCallee &callee, const std::string &sinkUdid);
+ DM_EXPORT bool CheckSinkIsSameAccount(const DmAccessCaller &caller, const std::string &srcUdid,
+ const DmAccessCallee &callee, const std::string &sinkUdid);
private:
int32_t HandleDmAuthForm(DistributedDeviceProfile::AccessControlProfile profiles, DmDiscoveryInfo discoveryInfo);
void GetParamBindTypeVec(DistributedDeviceProfile::AccessControlProfile profiles, std::string requestDeviceId,
@@ -211,6 +324,10 @@ private:
uint32_t index, std::string targetDeviceId);
bool CheckAppLevelAccess(const DistributedDeviceProfile::AccessControlProfile &profile,
const DmAccessCaller &caller, const DmAccessCallee &callee);
+ bool CheckSinkShareType(const DistributedDeviceProfile::AccessControlProfile &profile,
+ const int32_t &userId, const std::string &deviceId, const std::string &trustDeviceId, const int32_t &bindType);
+ std::unordered_map GetAuthFormMap(const std::string &pkgName, const std::string &deviceId,
+ const std::vector &profilesFilter, const int32_t &userId);
int32_t GetAuthForm(DistributedDeviceProfile::AccessControlProfile profiles, const std::string &trustDev,
const std::string &reqDev);
int32_t CheckAuthForm(DmAuthForm form, DistributedDeviceProfile::AccessControlProfile profiles,
@@ -233,13 +350,69 @@ private:
std::vector GetAclProfileByUserId(const std::string &localUdid,
int32_t userId, const std::string &remoteUdid);
void DeleteSigTrustACL(DistributedDeviceProfile::AccessControlProfile profile, const std::string &remoteUdid,
- const std::vector &remoteFrontUserIds, const std::vector &remoteBackUserIds);
+ const std::vector &remoteFrontUserIds, const std::vector &remoteBackUserIds,
+ DmOfflineParam &offlineParam);
void UpdatePeerUserId(DistributedDeviceProfile::AccessControlProfile profile, std::string &localUdid,
const std::vector &localUserIds, const std::string &remoteUdid,
const std::vector &remoteFrontUserIds);
bool CheckAclStatusNotMatch(const DistributedDeviceProfile::AccessControlProfile &profile,
const std::string &localUdid, const std::vector &foregroundUserIds,
const std::vector &backgroundUserIds);
+
+ void FilterNeedDeleteACLInfos(std::vector &profiles,
+ const std::string &localUdid, const uint32_t localTokenId,
+ const std::string &remoteUdid, const std::string &extra, DmOfflineParam &offlineParam);
+ bool FindLeftAcl(const DistributedDeviceProfile::AccessControlProfile &acl,
+ const std::string &localUdid, const std::string &remoteUdid, DmOfflineParam &offlineParam);
+ bool FindUserAcl(const DistributedDeviceProfile::AccessControlProfile &acl,
+ const std::string &localUdid, const std::string &remoteUdid, DmOfflineParam &offlineParam);
+ bool FindLnnAcl(const DistributedDeviceProfile::AccessControlProfile &acl,
+ const std::string &localUdid, const std::string &remoteUdid, DmOfflineParam &offlineParam);
+ bool FindTargetAcl(const DistributedDeviceProfile::AccessControlProfile &acl,
+ const std::string &localUdid, const uint32_t localTokenId,
+ const std::string &remoteUdid, const uint32_t peerTokenId,
+ DmOfflineParam &offlineParam);
+ bool FindTargetAcl(const DistributedDeviceProfile::AccessControlProfile &acl,
+ const std::string &localUdid, const int32_t remoteUserId, const std::string &remoteUdid,
+ const int32_t tokenId, const int32_t peerTokenId, DmOfflineParam &offlineParam);
+ bool FindTargetAcl(const DistributedDeviceProfile::AccessControlProfile &acl,
+ const std::string &localUdid, const int32_t remoteUserId, const std::string &remoteUdid,
+ const int32_t remoteTokenId, DmOfflineParam &offlineParam);
+
+ std::string GetAppServiceAuthVersionInfo(std::string localUdid, std::string remoteUdid, int32_t tokenId,
+ int32_t userId, std::vector profiles);
+ std::string GetDeviceAuthVersionInfo(std::string localUdid, std::string remoteUdid,
+ std::vector profiles);
+
+ void ParseExtra(const std::string &extra, uint64_t &peerTokenId, std::string &peerBundleName);
+ bool CacheLnnAcl(DistributedDeviceProfile::AccessControlProfile profile, const std::string &localUdid,
+ DmAclIdParam &dmAclIdParam);
+ void CheckLastLnnAcl(const std::string &localDeviceId, int32_t userId, const std::string &remoteDeviceId,
+ DmOfflineParam &offlineParam, std::vector &profiles);
+ bool CheckSrcAcuntAccessControl(const DistributedDeviceProfile::AccessControlProfile &profile,
+ const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee,
+ const std::string &sinkUdid);
+ bool CheckSinkAcuntAccessControl(const DistributedDeviceProfile::AccessControlProfile &profile,
+ const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee,
+ const std::string &sinkUdid);
+ bool CheckSrcShareAccessControl(const DistributedDeviceProfile::AccessControlProfile &profile,
+ const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee,
+ const std::string &sinkUdid);
+ bool CheckSinkShareAccessControl(const DistributedDeviceProfile::AccessControlProfile &profile,
+ const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee,
+ const std::string &sinkUdid);
+ bool CheckSrcP2PAccessControl(const DistributedDeviceProfile::AccessControlProfile &profile,
+ const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee,
+ const std::string &sinkUdid);
+ bool CheckSinkP2PAccessControl(const DistributedDeviceProfile::AccessControlProfile &profile,
+ const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee,
+ const std::string &sinkUdid);
+ bool CheckSinkUserP2PAcl(const DistributedDeviceProfile::AccessControlProfile &profile,
+ const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee,
+ const std::string &sinkUdid);
+ bool CheckSinkAppOrServiceP2PAcl(const DistributedDeviceProfile::AccessControlProfile &profile,
+ const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee,
+ const std::string &sinkUdid);
};
extern "C" IDeviceProfileConnector *CreateDpConnectorInstance();
diff --git a/commondependency/include/multiple_user_connector.h b/commondependency/include/multiple_user_connector.h
index ac9a105bb352de23663a0a8b366c693869d123b8..87837560234c6d233b9174ae0c307ef1ec0ad4fc 100644
--- a/commondependency/include/multiple_user_connector.h
+++ b/commondependency/include/multiple_user_connector.h
@@ -21,6 +21,11 @@
#include
#include
#include
+
+#ifndef DM_EXPORT
+#define DM_EXPORT __attribute__ ((visibility ("default")))
+#endif // DM_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);
+ DM_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);
+ DM_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);
+ DM_EXPORT static std::string GetOhosAccountId(void);
/**
* @brief Get the Ohos Account Id By Userid
@@ -63,14 +68,22 @@ public:
* @param userId the user id in which account login
* @return std::string the account id
*/
- static std::string GetOhosAccountIdByUserId(int32_t userId);
+ DM_EXPORT static std::string GetOhosAccountIdByUserId(int32_t userId);
+
+ /**
+ * @brief Get the Ohos Account Name By Userid
+ *
+ * @param userId the user id in which account login
+ * @return std::string the account name
+ */
+ DM_EXPORT static std::string GetOhosAccountNameByUserId(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);
+ DM_EXPORT static void SetSwitchOldAccountId(std::string accountId);
/**
* @tc.name: MultipleUserConnector::GetSwitchOldAccountId
@@ -78,7 +91,7 @@ public:
* @tc.type: FUNC
*/
static std::string GetSwitchOldAccountId(void);
-
+
/**
* @tc.name: MultipleUserConnector::SetSwitchOldAccountName
* @tc.desc: Set Switch Old AccountName of the Multiple User Connector
@@ -91,7 +104,7 @@ public:
* @tc.desc: Get Current AccountName of the Multiple User Connector
* @tc.type: FUNC
*/
- static std::string GetOhosAccountName(void);
+ DM_EXPORT static std::string GetOhosAccountName(void);
/**
* @tc.name: MultipleUserConnector::GetSwitchOldAccountName
@@ -99,21 +112,25 @@ public:
* @tc.type: FUNC
*/
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);
+ DM_EXPORT static void SetAccountInfo(int32_t userId, DMAccountInfo dmAccountInfo);
+ DM_EXPORT static DMAccountInfo GetAccountInfoByUserId(int32_t userId);
+ DM_EXPORT static void DeleteAccountInfoByUserId(int32_t userId);
+ DM_EXPORT static void GetTokenId(uint32_t &tokenId);
+ DM_EXPORT static void GetTokenIdAndForegroundUserId(uint32_t &tokenId,
+ int32_t &userId);
+ DM_EXPORT static void GetCallerUserId(int32_t &userId);
+ DM_EXPORT static int32_t GetForegroundUserIds(std::vector &userVec);
+ DM_EXPORT static int32_t GetFirstForegroundUserId(void);
+ DM_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();
+ DM_EXPORT static std::string GetAccountNickName(int32_t userId);
+ DM_EXPORT static bool IsUserUnlocked(int32_t userId);
+ DM_EXPORT static void ClearLockedUser(std::vector &foregroundUserVec);
+ DM_EXPORT static void ClearLockedUser(std::vector &foregroundUserVec,
+ std::vector &backgroundUserVec);
+ DM_EXPORT static DMAccountInfo GetCurrentDMAccountInfo();
+ DM_EXPORT static void GetCallingTokenId(uint32_t &tokenId);
+ DM_EXPORT static int32_t GetUserIdByDisplayId(uint64_t displayId);
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..4b3a3b1dda40d5aa3b6c5316d630de34f47f3499 100644
--- a/commondependency/src/deviceprofile_connector.cpp
+++ b/commondependency/src/deviceprofile_connector.cpp
@@ -13,6 +13,8 @@
* limitations under the License.
*/
+#include
+
#include "deviceprofile_connector.h"
#include "crypto_mgr.h"
#include "dm_anonymous.h"
@@ -28,23 +30,578 @@ using namespace OHOS::DistributedDeviceProfile;
const uint32_t INVALIED_TYPE = 0;
const uint32_t APP_PEER_TO_PEER_TYPE = 1;
const uint32_t APP_ACROSS_ACCOUNT_TYPE = 2;
-const uint32_t DEVICE_PEER_TO_PEER_TYPE = 3;
-const uint32_t DEVICE_ACROSS_ACCOUNT_TYPE = 4;
-const uint32_t IDENTICAL_ACCOUNT_TYPE = 5;
-
-const uint32_t DM_IDENTICAL_ACCOUNT = 1;
-const uint32_t DM_POINT_TO_POINT = 256;
-const uint32_t DM_ACROSS_ACCOUNT = 1282;
-const uint32_t DM_INVALIED_BINDTYPE = 2048;
-const uint32_t DEVICE = 1;
+const uint32_t SHARE_TYPE = 3;
+const uint32_t DEVICE_PEER_TO_PEER_TYPE = 4;
+const uint32_t DEVICE_ACROSS_ACCOUNT_TYPE = 5;
+const uint32_t IDENTICAL_ACCOUNT_TYPE = 6;
+const uint32_t SERVICE_PEER_TO_PEER_TYPE = 7;
+const uint32_t SERVICE_ACROSS_ACCOUNT_TYPE = 8;
+
+
+const uint32_t DM_INVALIED_TYPE = 2048;
const uint32_t SERVICE = 2;
const uint32_t APP = 3;
+const uint32_t USER = 1;
constexpr uint32_t MAX_SESSION_KEY_LENGTH = 512;
+const char* TAG_PEER_BUNDLE_NAME = "peerBundleName";
+const char* TAG_PEER_TOKENID = "peerTokenId";
+const char* TAG_ACL = "accessControlTable";
+const char* TAG_DMVERSION = "dmVersion";
+const char* TAG_ACL_HASH_KEY_VERSION = "aclVersion";
+const char* TAG_ACL_HASH_KEY_ACLHASHLIST = "aclHashList";
+
namespace OHOS {
namespace DistributedHardware {
+namespace {
+const int32_t DM_SUPPORT_ACL_AGING_VERSION_NUM = 1;
+const std::string DM_VERSION_STR_5_1_0 = DM_VERSION_5_1_0;
+const std::vector DM_SUPPORT_ACL_AGING_VERSIONS = {DM_VERSION_STR_5_1_0};
+}
DM_IMPLEMENT_SINGLE_INSTANCE(DeviceProfileConnector);
-std::vector DeviceProfileConnector::GetAccessControlProfile()
+void PrintProfile(const AccessControlProfile &profile)
+{
+ uint32_t bindType = profile.GetBindType();
+ uint32_t bindLevel = profile.GetBindLevel();
+
+ std::string acerDeviceId = profile.GetAccesser().GetAccesserDeviceId();
+ int32_t acerUserId = profile.GetAccesser().GetAccesserUserId();
+ std::string acerAccountId = profile.GetAccesser().GetAccesserAccountId();
+ int32_t acerTokenId = static_cast(profile.GetAccesser().GetAccesserTokenId());
+ std::string acerPkgName = profile.GetAccesser().GetAccesserBundleName();
+ std::string acerCredId = profile.GetAccesser().GetAccesserCredentialIdStr();
+ int32_t acerSkId = profile.GetAccesser().GetAccesserSessionKeyId();
+
+ std::string aceeDeviceId = profile.GetAccessee().GetAccesseeDeviceId();
+ int32_t aceeUserId = profile.GetAccessee().GetAccesseeUserId();
+ std::string aceeAccountId = profile.GetAccessee().GetAccesseeAccountId();
+ int32_t aceeTokenId = static_cast(profile.GetAccessee().GetAccesseeTokenId());
+ std::string aceePkgName = profile.GetAccessee().GetAccesseeBundleName();
+ std::string aceeCredId = profile.GetAccessee().GetAccesseeCredentialIdStr();
+ int32_t aceeSkId = profile.GetAccessee().GetAccesseeSessionKeyId();
+
+ LOGI("bindType %{public}d, bindLevel %{public}d, acerDeviceId %{public}s, acerUserId %{public}d,"
+ "acerAccountId %{public}s, acerTokenId %{public}d, acerPkgName %{public}s, acerCredId %{public}s,"
+ "acerSkId %{public}d, aceeDeviceId %{public}s, aceeUserId %{public}d, aceeAccountId %{public}s,"
+ "aceeTokenId %{public}d, aceePkgName %{public}s, aceeCredId %{public}s, aceeSkId %{public}d.",
+ bindType, bindLevel, GetAnonyString(acerDeviceId).c_str(), acerUserId, GetAnonyString(acerAccountId).c_str(),
+ acerTokenId, acerPkgName.c_str(), GetAnonyString(acerCredId).c_str(), acerSkId,
+ GetAnonyString(aceeDeviceId).c_str(), aceeUserId, GetAnonyString(aceeAccountId).c_str(), aceeTokenId,
+ aceePkgName.c_str(), GetAnonyString(aceeCredId).c_str(), aceeSkId);
+}
+
+std::string GetLocalDeviceId()
+{
+ char localDeviceId[DEVICE_UUID_LENGTH] = {0};
+ GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH);
+ return std::string(localDeviceId);
+}
+
+DM_EXPORT int32_t DeviceProfileConnector::GetVersionByExtra(std::string &extraInfo, std::string &dmVersion)
+{
+ JsonObject extraInfoJson(extraInfo);
+ if (extraInfoJson.IsDiscarded()) {
+ LOGE("GetVersionByExtra extraInfoJson error");
+ return ERR_DM_FAILED;
+ }
+ if (!extraInfoJson[TAG_DMVERSION].IsString()) {
+ LOGE("GetVersionByExtra PARAM_KEY_OS_VERSION error");
+ return ERR_DM_FAILED;
+ }
+ dmVersion = extraInfoJson[TAG_DMVERSION].Get();
+ return DM_OK;
+}
+
+DM_EXPORT void DeviceProfileConnector::GetAllVerionAclMap(DistributedDeviceProfile::AccessControlProfile &acl,
+ std::map> &aclMap, std::string dmVersion)
+{
+ std::vector needGenVersions = {};
+ // if not set version, send all support version acl hash
+ if (dmVersion.empty()) {
+ for (int32_t idx = 0; idx < DM_SUPPORT_ACL_AGING_VERSION_NUM; idx++) {
+ needGenVersions.push_back(DM_SUPPORT_ACL_AGING_VERSIONS[idx]);
+ }
+ } else if (std::find(DM_SUPPORT_ACL_AGING_VERSIONS.begin(), DM_SUPPORT_ACL_AGING_VERSIONS.end(), dmVersion) !=
+ DM_SUPPORT_ACL_AGING_VERSIONS.end()) {
+ needGenVersions.push_back(dmVersion);
+ } else {
+ LOGE("dmVersion invalid, %{public}s", dmVersion.c_str());
+ return;
+ }
+
+ for (auto const &version : needGenVersions) {
+ GenerateAclHash(acl, aclMap, version);
+ }
+}
+
+void DeviceProfileConnector::GenerateAclHash(DistributedDeviceProfile::AccessControlProfile &acl,
+ std::map> &aclMap, const std::string &dmVersion)
+{
+ int32_t versionNum = 0;
+ if (!GetVersionNumber(dmVersion, versionNum)) {
+ LOGE("GetAllVerionAclMap GetVersionNumber error");
+ return;
+ }
+ std::string aclStr;
+ switch (versionNum) {
+ case DM_VERSION_INT_5_1_0:
+ aclStr = AccessToStr(acl);
+ break;
+ default:
+ LOGE("versionNum is invaild, ver: %{public}d", versionNum);
+ break;
+ }
+ if (aclStr.empty()) {
+ return;
+ }
+ auto iter = aclMap.find(dmVersion);
+ if (iter != aclMap.end()) {
+ aclMap[dmVersion].push_back(Crypto::Sha256(aclStr));
+ } else {
+ std::vector aclStrVec;
+ aclStrVec.push_back(Crypto::Sha256(aclStr));
+ aclMap[dmVersion] = aclStrVec;
+ }
+}
+
+DM_EXPORT int32_t DeviceProfileConnector::GetAclListHashStr(const DevUserInfo &localDevUserInfo,
+ const DevUserInfo &remoteDevUserInfo, std::string &aclListHash, std::string dmVersion)
+{
+ std::map> aclMap;
+ std::vector profiles =
+ DeviceProfileConnector::GetInstance().GetAllAclIncludeLnnAcl();
+ for (auto &item : profiles) {
+ if (item.GetAccesser().GetAccesserDeviceId() == localDevUserInfo.deviceId &&
+ item.GetAccesser().GetAccesserUserId() == localDevUserInfo.userId &&
+ item.GetAccessee().GetAccesseeDeviceId() == remoteDevUserInfo.deviceId &&
+ item.GetAccessee().GetAccesseeUserId() == remoteDevUserInfo.userId) {
+ GetAllVerionAclMap(item, aclMap, dmVersion);
+ continue;
+ }
+ if (item.GetAccesser().GetAccesserDeviceId() == remoteDevUserInfo.deviceId &&
+ item.GetAccesser().GetAccesserUserId() == remoteDevUserInfo.userId &&
+ item.GetAccessee().GetAccesseeDeviceId() == localDevUserInfo.deviceId &&
+ item.GetAccessee().GetAccesseeUserId() == localDevUserInfo.userId) {
+ GetAllVerionAclMap(item, aclMap, dmVersion);
+ continue;
+ }
+ }
+ if (aclMap.empty()) {
+ LOGI("DeviceProfileConnector:: acl list is empty");
+ }
+ std::vector aclStrVec;
+ for (auto &item : aclMap) {
+ aclStrVec.push_back({item.first, item.second});
+ }
+ JsonObject allAclObj(JsonCreateType::JSON_CREATE_TYPE_ARRAY);
+ AclHashVecToJson(allAclObj, aclStrVec);
+ aclListHash = allAclObj.Dump();
+ return DM_OK;
+}
+
+DM_EXPORT void DeviceProfileConnector::AclHashItemToJson(JsonItemObject &itemObject, const AclHashItem &value)
+{
+ itemObject[TAG_ACL_HASH_KEY_VERSION] = value.version;
+ JsonObject hashList(JsonCreateType::JSON_CREATE_TYPE_ARRAY);
+ for (const auto &val : value.aclHashList) {
+ hashList.PushBack(val);
+ }
+ itemObject[TAG_ACL_HASH_KEY_ACLHASHLIST] = hashList.Dump();
+}
+
+DM_EXPORT void DeviceProfileConnector::AclHashVecToJson(
+ JsonItemObject &itemObject, const std::vector &values)
+{
+ for (const auto &val : values) {
+ JsonObject object;
+ AclHashItemToJson(object, val);
+ itemObject.PushBack(object.Dump());
+ }
+}
+
+DM_EXPORT void DeviceProfileConnector::AclHashItemFromJson(const JsonItemObject &itemObject, AclHashItem &value)
+{
+ value.version = itemObject[TAG_ACL_HASH_KEY_VERSION].Get();
+ std::string hashListStr = itemObject[TAG_ACL_HASH_KEY_ACLHASHLIST].Get();
+ JsonObject hashList;
+ hashList.Parse(hashListStr);
+ for (auto const &item : hashList.Items()) {
+ value.aclHashList.push_back(item.Get());
+ }
+}
+
+DM_EXPORT void DeviceProfileConnector::AclHashVecFromJson(const JsonItemObject &itemObject,
+ std::vector &values)
+{
+ for (auto const &item : itemObject.Items()) {
+ JsonObject object;
+ AclHashItem aclItem;
+ object.Parse(item.Get());
+ AclHashItemFromJson(object, aclItem);
+ values.push_back(aclItem);
+ }
+}
+
+DM_EXPORT bool DeviceProfileConnector::ChecksumAcl(DistributedDeviceProfile::AccessControlProfile &acl,
+ std::vector &acLStrList)
+{
+ std::string aclStr = AccessToStr(acl);
+ auto aclIter = find(acLStrList.begin(), acLStrList.end(), Crypto::Sha256(aclStr));
+ return (aclIter != acLStrList.end());
+}
+
+DM_EXPORT std::string DeviceProfileConnector::AccessToStr(DistributedDeviceProfile::AccessControlProfile acl)
+{
+ std::string aclStr = "";
+ DistributedDeviceProfile::Accesser accesser = acl.GetAccesser();
+ aclStr += accesser.GetAccesserDeviceId();
+ aclStr += std::to_string(accesser.GetAccesserUserId());
+ aclStr += accesser.GetAccesserAccountId();
+ aclStr += std::to_string(accesser.GetAccesserTokenId());
+ aclStr += accesser.GetAccesserBundleName();
+ aclStr += accesser.GetAccesserHapSignature();
+ aclStr += std::to_string(accesser.GetAccesserBindLevel());
+ aclStr += accesser.GetAccesserCredentialIdStr();
+ aclStr += std::to_string(accesser.GetAccesserStatus());
+ aclStr += std::to_string(accesser.GetAccesserSKTimeStamp());
+
+ DistributedDeviceProfile::Accessee accessee = acl.GetAccessee();
+ aclStr += accessee.GetAccesseeDeviceId();
+ aclStr += std::to_string(accessee.GetAccesseeUserId());
+ aclStr += accessee.GetAccesseeAccountId();
+ aclStr += std::to_string(accessee.GetAccesseeTokenId());
+ aclStr += accessee.GetAccesseeBundleName();
+ aclStr += accessee.GetAccesseeHapSignature();
+ aclStr += std::to_string(accessee.GetAccesseeBindLevel());
+ aclStr += accessee.GetAccesseeCredentialIdStr();
+ aclStr += std::to_string(accessee.GetAccesseeStatus());
+ aclStr += std::to_string(accessee.GetAccesseeSKTimeStamp());
+ return aclStr;
+}
+
+DM_EXPORT std::vector DeviceProfileConnector::GetAclList(
+ const std::string localUdid, int32_t localUserId, const std::string remoteUdid, int32_t remoteUserId)
+{
+ std::vector profiles =
+ DeviceProfileConnector::GetInstance().GetAllAclIncludeLnnAcl();
+ std::vector aclList;
+ for (auto &item : profiles) {
+ if (item.GetAccesser().GetAccesserDeviceId() == localUdid &&
+ item.GetAccesser().GetAccesserUserId() == localUserId &&
+ item.GetAccessee().GetAccesseeDeviceId() == remoteUdid &&
+ item.GetAccessee().GetAccesseeUserId() == remoteUserId) {
+ aclList.push_back(item);
+ continue;
+ }
+ if (item.GetAccesser().GetAccesserDeviceId() == remoteUdid &&
+ item.GetAccesser().GetAccesserUserId() == remoteUserId &&
+ item.GetAccessee().GetAccesseeDeviceId() == localUdid &&
+ item.GetAccessee().GetAccesseeUserId() == localUserId) {
+ aclList.push_back(item);
+ continue;
+ }
+ }
+ if (aclList.empty()) {
+ LOGI("DeviceProfileConnector::GetAclList acl is empty");
+ }
+ return aclList;
+}
+
+DM_EXPORT std::string DeviceProfileConnector::IsAuthNewVersion(int32_t bindLevel, std::string localUdid,
+ std::string remoteUdid, int32_t tokenId, int32_t userId)
+{
+ LOGI("localUdid %{public}s, remoteUdid %{public}s, bindLevel %{public}d.",
+ GetAnonyString(localUdid).c_str(), GetAnonyString(remoteUdid).c_str(), bindLevel);
+ if (static_cast(bindLevel) > APP || static_cast(bindLevel) < USER) {
+ LOGE("Invalied bindlevel bindLevel=%{public}u.", bindLevel);
+ return "";
+ }
+ std::vector profiles = GetAclProfileByDeviceIdAndUserId(localUdid, userId);
+ if (profiles.empty()) {
+ LOGE("Acl is empty.");
+ return "";
+ }
+ switch (bindLevel) {
+ case APP:
+ case SERVICE:
+ return GetAppServiceAuthVersionInfo(localUdid, remoteUdid, tokenId, userId, profiles);
+ case USER:
+ return GetDeviceAuthVersionInfo(localUdid, remoteUdid, profiles);
+ default:
+ break;
+ }
+ return "";
+}
+
+std::string DeviceProfileConnector::GetAppServiceAuthVersionInfo(std::string localUdid, std::string remoteUdid,
+ int32_t tokenId, int32_t userId, std::vector profiles)
+{
+ for (auto &item : profiles) {
+ if (item.GetBindType() == DM_IDENTICAL_ACCOUNT ||
+ (item.GetBindLevel() != APP && item.GetBindLevel() != SERVICE)) {
+ continue;
+ }
+ int32_t acerUserId = item.GetAccesser().GetAccesserUserId();
+ int32_t aceeUserId = item.GetAccessee().GetAccesseeUserId();
+ std::string acerDeviceId = item.GetAccesser().GetAccesserDeviceId();
+ std::string aceeDeviceId = item.GetAccessee().GetAccesseeDeviceId();
+ int32_t acerTokenId = static_cast(item.GetAccesser().GetAccesserTokenId());
+ int32_t aceeTokenId = static_cast(item.GetAccessee().GetAccesseeTokenId());
+ if (acerUserId == userId && acerTokenId == tokenId &&
+ acerDeviceId == localUdid && aceeDeviceId == remoteUdid) {
+ return item.GetAccesser().GetAccesserExtraData();
+ }
+ if (aceeUserId == userId && aceeTokenId == tokenId &&
+ aceeDeviceId == localUdid && acerDeviceId == remoteUdid) {
+ return item.GetAccessee().GetAccesseeExtraData();
+ }
+ }
+ return "";
+}
+
+std::string DeviceProfileConnector::GetDeviceAuthVersionInfo(std::string localUdid, std::string remoteUdid,
+ std::vector profiles)
+{
+ for (auto &item : profiles) {
+ if (item.GetBindType() == DM_IDENTICAL_ACCOUNT || item.GetBindLevel() != USER || IsLnnAcl(item)) {
+ continue;
+ }
+ std::string acerDeviceId = item.GetAccesser().GetAccesserDeviceId();
+ std::string aceeDeviceId = item.GetAccessee().GetAccesseeDeviceId();
+ if (acerDeviceId == localUdid && aceeDeviceId == remoteUdid) {
+ return item.GetAccesser().GetAccesserExtraData();
+ }
+ if (aceeDeviceId == localUdid && acerDeviceId == remoteUdid) {
+ return item.GetAccessee().GetAccesseeExtraData();
+ }
+ }
+ return "";
+}
+DM_EXPORT DmOfflineParam DeviceProfileConnector::FilterNeedDeleteACL(const std::string &localDeviceId,
+ uint32_t localTokenId, const std::string &remoteDeviceId, const std::string &extra)
+{
+ LOGI("localDeviceId %{public}s, remoteDeviceId %{public}s",
+ GetAnonyString(localDeviceId).c_str(), GetAnonyString(remoteDeviceId).c_str());
+ DmOfflineParam offlineParam;
+ int32_t userId = MultipleUserConnector::GetCurrentAccountUserID();
+ std::vector profiles = GetAclProfileByDeviceIdAndUserId(localDeviceId, userId,
+ remoteDeviceId);
+ if (profiles.empty()) {
+ LOGE("Acl is empty.");
+ return offlineParam;
+ }
+
+ FilterNeedDeleteACLInfos(profiles, localDeviceId, localTokenId, remoteDeviceId, extra, offlineParam);
+ return offlineParam;
+}
+
+void DeviceProfileConnector::CheckLastLnnAcl(const std::string &localDeviceId, int32_t localUserId,
+ const std::string &remoteDeviceId, DmOfflineParam &offlineParam,
+ std::vector &profiles)
+{
+ LOGI("profiles size: %{public}zu", profiles.size());
+ if (profiles.size() == 1 && IsLnnAcl(profiles[0])) {
+ if (profiles[0].GetAccesser().GetAccesserDeviceId() == localDeviceId) {
+ CacheAcerAclId(profiles[0], offlineParam.needDelAclInfos);
+ }
+ if (profiles[0].GetAccessee().GetAccesseeDeviceId() == localDeviceId) {
+ CacheAceeAclId(profiles[0], offlineParam.needDelAclInfos);
+ }
+ offlineParam.hasLnnAcl = true;
+ }
+}
+
+void DeviceProfileConnector::DeleteCacheAcl(std::vector delAclIdVec,
+ std::vector &profiles)
+{
+ for (auto delAclId : delAclIdVec) {
+ for (auto item = profiles.begin(); item != profiles.end();) {
+ if (delAclId == item->GetAccessControlId()) {
+ item = profiles.erase(item);
+ } else {
+ item++;
+ }
+ }
+ }
+}
+
+void DeviceProfileConnector::ParseExtra(const std::string &extra, uint64_t &peerTokenId, std::string &peerBundleName)
+{
+ JsonObject extraInfoJson(extra);
+ if (extraInfoJson.IsDiscarded()) {
+ LOGE("ParseExtra extraInfoJson error");
+ return;
+ }
+ if (!extraInfoJson[TAG_PEER_BUNDLE_NAME].IsString() || !extraInfoJson[TAG_PEER_TOKENID].IsNumberInteger()) {
+ LOGE("ParseExtra TAG_PEER_BUNDLE_NAME or TAG_PEER_TOKENID error");
+ return;
+ }
+ peerTokenId = extraInfoJson[TAG_PEER_TOKENID].Get();
+ peerBundleName = extraInfoJson[TAG_PEER_BUNDLE_NAME].Get();
+}
+
+bool DeviceProfileConnector::FindTargetAcl(const DistributedDeviceProfile::AccessControlProfile &acl,
+ const std::string &localUdid, const uint32_t localTokenId,
+ const std::string &remoteUdid, const uint32_t peerTokenId,
+ DmOfflineParam &offlineParam)
+{
+ bool isMatch = false;
+ int64_t acerTokenId = acl.GetAccesser().GetAccesserTokenId();
+ int64_t aceeTokenId = acl.GetAccessee().GetAccesseeTokenId();
+ std::string acerDeviceId = acl.GetAccesser().GetAccesserDeviceId();
+ std::string aceeDeviceId = acl.GetAccessee().GetAccesseeDeviceId();
+ // Process target match acl which need delete
+ if ((acerTokenId == static_cast(localTokenId)) &&
+ (acerDeviceId == localUdid) && (aceeDeviceId == remoteUdid) &&
+ (peerTokenId == 0 || (peerTokenId != 0 && aceeTokenId == static_cast(peerTokenId)))) {
+ ProcessInfo processInfo;
+ processInfo.pkgName = acl.GetAccesser().GetAccesserBundleName();
+ processInfo.userId = acl.GetAccesser().GetAccesserUserId();
+ offlineParam.processVec.push_back(processInfo);
+ CacheAcerAclId(acl, offlineParam.needDelAclInfos);
+ LOGI("Src del acl aclId: %{public}" PRId64 ", localUdid %{public}s, remoteUdid %{public}s"
+ ", bindType %{public}d, bindLevel: %{public}d", acl.GetAccessControlId(),
+ GetAnonyString(localUdid).c_str(), GetAnonyString(remoteUdid).c_str(), acl.GetBindType(),
+ acl.GetBindLevel());
+ isMatch = true;
+ }
+
+ if ((aceeTokenId == static_cast(localTokenId)) &&
+ (aceeDeviceId == localUdid) && (acerDeviceId == remoteUdid) &&
+ (peerTokenId == 0 || (peerTokenId != 0 && acerTokenId == static_cast(peerTokenId)))) {
+ ProcessInfo processInfo;
+ processInfo.pkgName = acl.GetAccessee().GetAccesseeBundleName();
+ processInfo.userId = acl.GetAccessee().GetAccesseeUserId();
+ offlineParam.processVec.push_back(processInfo);
+ CacheAceeAclId(acl, offlineParam.needDelAclInfos);
+ LOGI("Sink del acl aclId: %{public}" PRId64 ", localUdid %{public}s, remoteUdid %{public}s"
+ ", bindType %{public}d, bindLevel: %{public}d", acl.GetAccessControlId(),
+ GetAnonyString(localUdid).c_str(), GetAnonyString(remoteUdid).c_str(), acl.GetBindType(),
+ acl.GetBindLevel());
+ isMatch = true;
+ }
+ return isMatch;
+}
+
+bool DeviceProfileConnector::FindLnnAcl(const DistributedDeviceProfile::AccessControlProfile &acl,
+ const std::string &localUdid, const std::string &remoteUdid, DmOfflineParam &offlineParam)
+{
+ bool isMatch = false;
+ std::string acerDeviceId = acl.GetAccesser().GetAccesserDeviceId();
+ std::string aceeDeviceId = acl.GetAccessee().GetAccesseeDeviceId();
+ if (IsLnnAcl(acl) && acl.GetTrustDeviceId() == remoteUdid) {
+ if (acerDeviceId == localUdid && aceeDeviceId == remoteUdid) {
+ LOGI("Src lnn acl aclId: %{public}" PRId64 ", localUdid %{public}s, remoteUdid %{public}s"
+ ", bindType %{public}d, bindLevel: %{public}d", acl.GetAccessControlId(),
+ GetAnonyString(localUdid).c_str(),
+ GetAnonyString(remoteUdid).c_str(), acl.GetBindType(), acl.GetBindLevel());
+ CacheAcerAclId(acl, offlineParam.allLnnAclInfos);
+ }
+
+ if (aceeDeviceId == localUdid && acerDeviceId == remoteUdid) {
+ LOGI("Sink lnn acl aclId: %{public}" PRId64 ", localUdid %{public}s, remoteUdid %{public}s"
+ ", bindType %{public}d, bindLevel: %{public}d", acl.GetAccessControlId(),
+ GetAnonyString(localUdid).c_str(), GetAnonyString(remoteUdid).c_str(), acl.GetBindType(),
+ acl.GetBindLevel());
+ CacheAceeAclId(acl, offlineParam.allLnnAclInfos);
+ }
+ isMatch = true;
+ }
+ return isMatch;
+}
+
+bool DeviceProfileConnector::FindUserAcl(const DistributedDeviceProfile::AccessControlProfile &acl,
+ const std::string &localUdid, const std::string &remoteUdid, DmOfflineParam &offlineParam)
+{
+ bool isMatch = false;
+ std::string acerDeviceId = acl.GetAccesser().GetAccesserDeviceId();
+ std::string aceeDeviceId = acl.GetAccessee().GetAccesseeDeviceId();
+ // process User Or SameAccount acl
+ if (acl.GetBindLevel() == USER || acl.GetBindType() == DM_IDENTICAL_ACCOUNT) {
+ if (acerDeviceId == localUdid && aceeDeviceId == remoteUdid) {
+ LOGI("Src User acl aclId: %{public}" PRId64 ", localUdid %{public}s, remoteUdid %{public}s"
+ ", bindType %{public}d, bindLevel: %{public}d", acl.GetAccessControlId(),
+ GetAnonyString(localUdid).c_str(), GetAnonyString(remoteUdid).c_str(), acl.GetBindType(),
+ acl.GetBindLevel());
+ CacheAcerAclId(acl, offlineParam.allUserAclInfos);
+ }
+
+ if (aceeDeviceId == localUdid && acerDeviceId == remoteUdid) {
+ LOGI("Sink User acl aclId: %{public}" PRId64 ", localUdid %{public}s, remoteUdid %{public}s"
+ ", bindType %{public}d, bindLevel: %{public}d", acl.GetAccessControlId(),
+ GetAnonyString(localUdid).c_str(), GetAnonyString(remoteUdid).c_str(), acl.GetBindType(),
+ acl.GetBindLevel());
+ CacheAceeAclId(acl, offlineParam.allUserAclInfos);
+ }
+ isMatch = true;
+ }
+ return isMatch;
+}
+
+bool DeviceProfileConnector::FindLeftAcl(const DistributedDeviceProfile::AccessControlProfile &acl,
+ const std::string &localUdid, const std::string &remoteUdid, DmOfflineParam &offlineParam)
+{
+ bool isMatch = false;
+ std::string acerDeviceId = acl.GetAccesser().GetAccesserDeviceId();
+ std::string aceeDeviceId = acl.GetAccessee().GetAccesseeDeviceId();
+ // process left service/app acl
+ if (acl.GetBindLevel() == SERVICE || acl.GetBindLevel() == APP) {
+ if (acerDeviceId == localUdid && aceeDeviceId == remoteUdid) {
+ LOGI("Src Left acl aclId: %{public}" PRId64 ", localUdid %{public}s, remoteUdid %{public}s"
+ ", bindType %{public}d, bindLevel: %{public}d", acl.GetAccessControlId(),
+ GetAnonyString(localUdid).c_str(), GetAnonyString(remoteUdid).c_str(), acl.GetBindType(),
+ acl.GetBindLevel());
+ CacheAcerAclId(acl, offlineParam.allLeftAppOrSvrAclInfos);
+ }
+
+ if (aceeDeviceId == localUdid && acerDeviceId == remoteUdid) {
+ LOGI("Sink Left acl aclId: %{public}" PRId64 ", localUdid %{public}s, remoteUdid %{public}s"
+ ", bindType %{public}d, bindLevel: %{public}d", acl.GetAccessControlId(),
+ GetAnonyString(localUdid).c_str(), GetAnonyString(remoteUdid).c_str(), acl.GetBindType(),
+ acl.GetBindLevel());
+ CacheAceeAclId(acl, offlineParam.allLeftAppOrSvrAclInfos);
+ }
+ isMatch = true;
+ }
+ return isMatch;
+}
+
+void DeviceProfileConnector::FilterNeedDeleteACLInfos(
+ std::vector &profiles,
+ const std::string &localUdid, const uint32_t localTokenId,
+ const std::string &remoteUdid, const std::string &extra, DmOfflineParam &offlineParam)
+{
+ uint64_t peerTokenId = 0;
+ std::string peerBundleName = "";
+ ParseExtra(extra, peerTokenId, peerBundleName);
+ for (auto &item : profiles) {
+ if (item.GetTrustDeviceId() != remoteUdid) {
+ continue;
+ }
+
+ // First, find need delete acl
+ if (FindTargetAcl(item, localUdid, localTokenId, remoteUdid, peerTokenId, offlineParam)) {
+ continue;
+ }
+
+ // Second, find the LNN acl
+ if (FindLnnAcl(item, localUdid, remoteUdid, offlineParam)) {
+ continue;
+ }
+
+ // Third, find the user or sameaccount acl, dertermine if report offline
+ if (FindUserAcl(item, localUdid, remoteUdid, offlineParam)) {
+ continue;
+ }
+
+ // Fourth, find the left service/app acl, determine if del lnn acl
+ if (FindLeftAcl(item, localUdid, remoteUdid, offlineParam)) {
+ continue;
+ }
+ }
+}
+
+DM_EXPORT std::vector DeviceProfileConnector::GetAccessControlProfile()
{
std::vector profiles;
std::map queryParams;
@@ -89,23 +646,52 @@ std::vector DeviceProfileConnector::GetAclProfileByDeviceI
return aclProfileVec;
}
-std::unordered_map DeviceProfileConnector::GetAppTrustDeviceList(const std::string &pkgName,
- const std::string &deviceId)
+std::vector DeviceProfileConnector::GetAclProfileByDeviceIdAndUserId(const std::string &deviceId,
+ int32_t userId, const std::string &remoteDeviceId)
+{
+ std::vector aclProfileVec;
+ std::vector profiles = GetAllAclIncludeLnnAcl();
+ for (auto &item : profiles) {
+ if ((item.GetAccesser().GetAccesserDeviceId() == deviceId &&
+ item.GetAccesser().GetAccesserUserId() == userId &&
+ item.GetAccessee().GetAccesseeDeviceId() == remoteDeviceId) ||
+ (item.GetAccessee().GetAccesseeDeviceId() == deviceId &&
+ item.GetAccessee().GetAccesseeUserId() == userId &&
+ item.GetAccesser().GetAccesserDeviceId() == remoteDeviceId)) {
+ aclProfileVec.push_back(item);
+ }
+ }
+ return aclProfileVec;
+}
+
+DM_EXPORT std::unordered_map DeviceProfileConnector::GetAppTrustDeviceList(
+ const std::string &pkgName, const std::string &deviceId)
{
- int32_t userId = MultipleUserConnector::GetFirstForegroundUserId();
- std::vector profiles = GetAclProfileByDeviceIdAndUserId(deviceId, userId);
+ int32_t userId = MultipleUserConnector::GetCurrentAccountUserID();
+ LOGI("localDeviceId: %{public}s, userId: %{public}d", GetAnonyString(deviceId).c_str(), userId);
+ std::vector profiles = GetAllAclIncludeLnnAcl();
std::vector profilesFilter = {};
for (auto &item : profiles) {
- if ((item.GetAccesser().GetAccesserUserId() == userId &&
+ if (!IsLnnAcl(item) && ((item.GetAccesser().GetAccesserUserId() == userId &&
item.GetAccesser().GetAccesserDeviceId() == deviceId) ||
(item.GetAccessee().GetAccesseeUserId() == userId &&
- item.GetAccessee().GetAccesseeDeviceId() == deviceId)) {
+ item.GetAccessee().GetAccesseeDeviceId() == deviceId))) {
profilesFilter.push_back(item);
}
}
+ return GetAuthFormMap(pkgName, deviceId, profilesFilter, userId);
+}
+
+std::unordered_map DeviceProfileConnector::GetAuthFormMap(const std::string &pkgName,
+ const std::string &deviceId, const std::vector &profilesFilter,
+ const int32_t &userId)
+{
std::unordered_map deviceIdMap;
for (auto &item : profilesFilter) {
std::string trustDeviceId = item.GetTrustDeviceId();
+ LOGI("trustDeviceId: %{public}s, status: %{public}d, acerUserId: %{public}d, aceeUserId: %{public}d",
+ GetAnonyString(trustDeviceId).c_str(), item.GetStatus(), item.GetAccesser().GetAccesserUserId(),
+ item.GetAccessee().GetAccesseeUserId());
if (trustDeviceId == deviceId || item.GetStatus() != ACTIVE) {
continue;
}
@@ -116,6 +702,10 @@ std::unordered_map DeviceProfileConnector::GetAppTrustD
continue;
}
if (deviceIdMap.find(trustDeviceId) == deviceIdMap.end()) {
+ if (CheckSinkShareType(item, userId, deviceId, trustDeviceId, bindType)) {
+ LOGI("GetAuthFormMap CheckSinkShareType true.");
+ continue;
+ }
deviceIdMap[trustDeviceId] = static_cast(bindType);
continue;
}
@@ -123,18 +713,44 @@ std::unordered_map DeviceProfileConnector::GetAppTrustD
if (bindType == authForm) {
continue;
}
- if (bindType == DmAuthForm::IDENTICAL_ACCOUNT) {
+ uint32_t highestBindType = CheckBindType(trustDeviceId, deviceId);
+ if (highestBindType == IDENTICAL_ACCOUNT_TYPE) {
deviceIdMap[trustDeviceId] = DmAuthForm::IDENTICAL_ACCOUNT;
continue;
- }
- if (bindType == DmAuthForm::PEER_TO_PEER && authForm == DmAuthForm::ACROSS_ACCOUNT) {
+ } else if (highestBindType == SHARE_TYPE) {
+ if (CheckSinkShareType(item, userId, deviceId, trustDeviceId, DmAuthForm::SHARE)) {
+ continue;
+ }
+ deviceIdMap[trustDeviceId] = DmAuthForm::SHARE;
+ continue;
+ } else if (highestBindType == DEVICE_PEER_TO_PEER_TYPE || highestBindType == APP_PEER_TO_PEER_TYPE ||
+ highestBindType == SERVICE_PEER_TO_PEER_TYPE) {
deviceIdMap[trustDeviceId] = DmAuthForm::PEER_TO_PEER;
continue;
+ } else if (highestBindType == APP_ACROSS_ACCOUNT_TYPE ||
+ highestBindType == DEVICE_ACROSS_ACCOUNT_TYPE || highestBindType == SERVICE_ACROSS_ACCOUNT_TYPE) {
+ deviceIdMap[trustDeviceId] = DmAuthForm::ACROSS_ACCOUNT;
+ continue;
+ } else {
+ LOGE("GetAuthFormMap highestBindType match failed.");
+ continue;
}
}
return deviceIdMap;
}
+bool DeviceProfileConnector::CheckSinkShareType(const DistributedDeviceProfile::AccessControlProfile &profile,
+ const int32_t &userId, const std::string &deviceId, const std::string &trustDeviceId, const int32_t &bindType)
+{
+ if (profile.GetAccessee().GetAccesseeUserId() == userId &&
+ profile.GetAccessee().GetAccesseeDeviceId() == deviceId &&
+ profile.GetAccesser().GetAccesserDeviceId() == trustDeviceId &&
+ bindType == DmAuthForm::SHARE) {
+ return true;
+ }
+ return false;
+}
+
int32_t DeviceProfileConnector::GetDeviceAclParam(DmDiscoveryInfo discoveryInfo, bool &isOnline, int32_t &authForm)
{
std::vector profiles = GetAccessControlProfileByUserId(discoveryInfo.userId);
@@ -145,7 +761,7 @@ int32_t DeviceProfileConnector::GetDeviceAclParam(DmDiscoveryInfo discoveryInfo,
LOGE("get deviceIdHash by deviceId: %{public}s failed.", GetAnonyString(deviceIdHash).c_str());
continue;
}
- if (static_cast(deviceIdHash) != discoveryInfo.remoteDeviceIdHash ||
+ if (IsLnnAcl(item) || static_cast(deviceIdHash) != discoveryInfo.remoteDeviceIdHash ||
(discoveryInfo.localDeviceId == item.GetAccesser().GetAccesserDeviceId() &&
discoveryInfo.userId != item.GetAccesser().GetAccesserUserId()) ||
(discoveryInfo.localDeviceId == item.GetAccessee().GetAccesseeDeviceId() &&
@@ -183,10 +799,14 @@ int32_t DeviceProfileConnector::GetDeviceAclParam(DmDiscoveryInfo discoveryInfo,
int32_t DeviceProfileConnector::CheckAuthForm(DmAuthForm form, AccessControlProfile profiles,
DmDiscoveryInfo discoveryInfo)
{
- if (profiles.GetBindLevel() == DEVICE || (profiles.GetBindLevel() == APP && discoveryInfo.pkgname == "")) {
+ if (IsLnnAcl(profiles)) {
+ return DmAuthForm::INVALID_TYPE;
+ }
+ if (profiles.GetBindLevel() == USER || ((profiles.GetBindLevel() == APP || profiles.GetBindLevel() == SERVICE) &&
+ discoveryInfo.pkgname == "")) {
return form;
}
- if (profiles.GetBindLevel() == APP) {
+ if (profiles.GetBindLevel() == APP || profiles.GetBindLevel() == SERVICE) {
if (discoveryInfo.pkgname == profiles.GetAccesser().GetAccesserBundleName() &&
discoveryInfo.localDeviceId == profiles.GetAccesser().GetAccesserDeviceId()) {
return form;
@@ -208,19 +828,23 @@ int32_t DeviceProfileConnector::HandleDmAuthForm(AccessControlProfile profiles,
return CheckAuthForm(DmAuthForm::PEER_TO_PEER, profiles, discoveryInfo);
}
if (profiles.GetBindType() == DM_ACROSS_ACCOUNT) {
- return CheckAuthForm(DmAuthForm::ACROSS_ACCOUNT, profiles, discoveryInfo);
+ return CheckAuthForm(DmAuthForm::PEER_TO_PEER, profiles, discoveryInfo);
+ }
+ if (profiles.GetBindType() == DM_SHARE) {
+ return CheckAuthForm(DmAuthForm::SHARE, profiles, discoveryInfo);
}
return DmAuthForm::INVALID_TYPE;
}
-uint32_t DeviceProfileConnector::CheckBindType(std::string peerUdid, std::string localUdid)
+DM_EXPORT uint32_t DeviceProfileConnector::CheckBindType(std::string peerUdid,
+ std::string localUdid)
{
std::vector filterProfiles = GetAclProfileByUserId(localUdid,
MultipleUserConnector::GetFirstForegroundUserId(), peerUdid);
LOGI("filterProfiles size is %{public}zu", filterProfiles.size());
uint32_t highestPriority = INVALIED_TYPE;
for (auto &item : filterProfiles) {
- if (peerUdid != item.GetTrustDeviceId()) {
+ if (IsLnnAcl(item) || peerUdid != item.GetTrustDeviceId()) {
continue;
}
uint32_t priority = static_cast(GetAuthForm(item, peerUdid, localUdid));
@@ -238,21 +862,33 @@ int32_t DeviceProfileConnector::GetAuthForm(DistributedDeviceProfile::AccessCont
profiles.GetBindType(), profiles.GetBindLevel());
uint32_t priority = INVALIED_TYPE;
uint32_t bindType = profiles.GetBindType();
+
switch (bindType) {
case DM_IDENTICAL_ACCOUNT:
priority = IDENTICAL_ACCOUNT_TYPE;
break;
+ case DM_SHARE:
+ priority = SHARE_TYPE;
+ break;
case DM_POINT_TO_POINT:
- if (profiles.GetBindLevel() == DEVICE) {
+ if (profiles.GetBindLevel() == USER) {
priority = DEVICE_PEER_TO_PEER_TYPE;
- } else if (profiles.GetBindLevel() == APP) {
+ }
+ if (profiles.GetBindLevel() == SERVICE) {
+ priority = SERVICE_PEER_TO_PEER_TYPE;
+ }
+ if (profiles.GetBindLevel() == APP) {
priority = APP_PEER_TO_PEER_TYPE;
}
break;
case DM_ACROSS_ACCOUNT:
- if (profiles.GetBindLevel() == DEVICE) {
+ if (profiles.GetBindLevel() == USER) {
priority = DEVICE_ACROSS_ACCOUNT_TYPE;
- } else if (profiles.GetBindLevel() == APP) {
+ }
+ if (profiles.GetBindLevel() == SERVICE) {
+ priority = SERVICE_ACROSS_ACCOUNT_TYPE;
+ }
+ if (profiles.GetBindLevel() == APP) {
priority = APP_ACROSS_ACCOUNT_TYPE;
}
break;
@@ -263,8 +899,8 @@ int32_t DeviceProfileConnector::GetAuthForm(DistributedDeviceProfile::AccessCont
return priority;
}
-std::vector DeviceProfileConnector::GetBindTypeByPkgName(std::string pkgName, std::string requestDeviceId,
- std::string trustUdid)
+DM_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());
@@ -277,7 +913,7 @@ std::vector DeviceProfileConnector::GetBindTypeByPkgName(std::string pk
GetAccessControlProfileByUserId(MultipleUserConnector::GetFirstForegroundUserId());
LOGI("AccessControlProfile size is %{public}zu", profiles.size());
for (auto &item : profiles) {
- if (trustUdid != item.GetTrustDeviceId() || item.GetStatus() != ACTIVE) {
+ if (IsLnnAcl(item) || trustUdid != item.GetTrustDeviceId() || item.GetStatus() != ACTIVE) {
continue;
}
GetParamBindTypeVec(item, requestDeviceId, bindTypeVec, trustUdid);
@@ -285,10 +921,12 @@ std::vector DeviceProfileConnector::GetBindTypeByPkgName(std::string pk
return bindTypeVec;
}
-uint64_t DeviceProfileConnector::GetTokenIdByNameAndDeviceId(std::string pkgName, std::string requestDeviceId)
+DM_EXPORT uint64_t DeviceProfileConnector::GetTokenIdByNameAndDeviceId(std::string extra, std::string requestDeviceId)
{
- std::vector profiles = GetAccessControlProfile();
uint64_t peerTokenId = 0;
+ std::string pkgName = "";
+ ParseExtra(extra, peerTokenId, pkgName);
+ std::vector profiles = GetAccessControlProfile();
for (auto &item : profiles) {
if (item.GetAccesser().GetAccesserBundleName() == pkgName &&
item.GetAccesser().GetAccesserDeviceId() == requestDeviceId) {
@@ -320,7 +958,7 @@ void DeviceProfileConnector::GetParamBindTypeVec(AccessControlProfile profile, s
bindTypeVec.push_back(IDENTICAL_ACCOUNT_TYPE);
break;
case DM_POINT_TO_POINT:
- if (profile.GetBindLevel() == DEVICE) {
+ if (profile.GetBindLevel() == USER) {
bindTypeVec.push_back(DEVICE_PEER_TO_PEER_TYPE);
}
if (profile.GetBindLevel() == APP) {
@@ -328,7 +966,7 @@ void DeviceProfileConnector::GetParamBindTypeVec(AccessControlProfile profile, s
}
break;
case DM_ACROSS_ACCOUNT:
- if (profile.GetBindLevel() == DEVICE) {
+ if (profile.GetBindLevel() == USER) {
bindTypeVec.push_back(DEVICE_ACROSS_ACCOUNT_TYPE);
}
if (profile.GetBindLevel() == APP) {
@@ -346,7 +984,8 @@ std::vector DeviceProfileConnector::CompareBindType(std::vector bindTypeIndex;
for (uint32_t index = 0; index < profiles.size(); index++) {
- if (profiles[index].GetTrustDeviceId() != targetDeviceId || profiles[index].GetStatus() != ACTIVE) {
+ if (IsLnnAcl(profiles[index]) || profiles[index].GetTrustDeviceId() != targetDeviceId ||
+ profiles[index].GetStatus() != ACTIVE) {
continue;
}
DmDiscoveryInfo paramInfo = {
@@ -366,7 +1005,7 @@ void DeviceProfileConnector::ProcessBindType(AccessControlProfile profiles, std:
bindTypeIndex.push_back(index);
}
if (profiles.GetBindType() == DM_POINT_TO_POINT) {
- if (profiles.GetBindLevel() == DEVICE) {
+ if (profiles.GetBindLevel() == USER) {
sinkBindType.push_back(DEVICE_PEER_TO_PEER_TYPE);
bindTypeIndex.push_back(index);
}
@@ -384,7 +1023,7 @@ void DeviceProfileConnector::ProcessBindType(AccessControlProfile profiles, std:
}
}
if (profiles.GetBindType() == DM_ACROSS_ACCOUNT) {
- if (profiles.GetBindLevel() == DEVICE) {
+ if (profiles.GetBindLevel() == USER) {
sinkBindType.push_back(DEVICE_ACROSS_ACCOUNT_TYPE);
bindTypeIndex.push_back(index);
}
@@ -403,8 +1042,8 @@ void DeviceProfileConnector::ProcessBindType(AccessControlProfile profiles, std:
}
}
-std::vector DeviceProfileConnector::SyncAclByBindType(std::string pkgName, std::vector bindTypeVec,
- std::string localDeviceId, std::string targetDeviceId)
+DM_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 +1070,8 @@ std::vector DeviceProfileConnector::SyncAclByBindType(std::string pkgNa
return bindType;
}
+
+DM_EXPORT
std::vector DeviceProfileConnector::GetProcessInfoFromAclByUserId(
const std::string &localDeviceId, const std::string &targetDeviceId, int32_t userId)
{
@@ -439,7 +1080,7 @@ std::vector DeviceProfileConnector::GetP
LOGI("filterProfiles size is %{public}zu", filterProfiles.size());
std::vector processInfoVec;
for (auto &item : filterProfiles) {
- if (item.GetTrustDeviceId() != targetDeviceId) {
+ if (IsLnnAcl(item) || item.GetTrustDeviceId() != targetDeviceId) {
continue;
}
std::string accesserUdid = item.GetAccesser().GetAccesserDeviceId();
@@ -495,12 +1136,13 @@ int32_t DeviceProfileConnector::PutAccessControlList(DmAclInfo aclInfo, DmAccess
return ret;
}
-bool DeviceProfileConnector::DeleteAclForAccountLogOut(const std::string &localUdid, int32_t localUserId,
- const std::string &peerUdid, int32_t peerUserId)
+DM_EXPORT bool DeviceProfileConnector::DeleteAclForAccountLogOut(
+ const std::string &localUdid, int32_t localUserId,
+ const std::string &peerUdid, int32_t peerUserId, DmOfflineParam &offlineParam)
{
LOGI("localUdid %{public}s, localUserId %{public}d, peerUdid %{public}s, peerUserId %{public}d.",
GetAnonyString(localUdid).c_str(), localUserId, GetAnonyString(peerUdid).c_str(), peerUserId);
- std::vector profiles = GetAllAccessControlProfile();
+ std::vector profiles = GetAllAclIncludeLnnAcl();
std::vector deleteProfiles;
bool notifyOffline = false;
bool isDelete = false;
@@ -519,6 +1161,7 @@ bool DeviceProfileConnector::DeleteAclForAccountLogOut(const std::string &localU
}
deleteProfiles.push_back(item);
notifyOffline = (item.GetStatus() == ACTIVE);
+ CacheAcerAclId(item, offlineParam.needDelAclInfos);
continue;
}
if (accesserUdid == peerUdid && accesserUserId == peerUserId &&
@@ -528,60 +1171,75 @@ bool DeviceProfileConnector::DeleteAclForAccountLogOut(const std::string &localU
}
deleteProfiles.push_back(item);
notifyOffline = (item.GetStatus() == ACTIVE);
+ CacheAceeAclId(item, offlineParam.needDelAclInfos);
continue;
}
}
if (!isDelete) {
return false;
}
- for (const auto &item : deleteProfiles) {
- DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(item.GetAccessControlId());
- }
return notifyOffline;
}
-void DeviceProfileConnector::DeleteAclForUserRemoved(std::string localUdid, int32_t userId)
+
+DM_EXPORT void DeviceProfileConnector::DeleteAclForUserRemoved(std::string localUdid, int32_t userId,
+ std::vector peerUdids, std::multimap &peerUserIdMap,
+ DmOfflineParam &offlineParam)
{
LOGI("localUdid %{public}s, userId %{public}d.", GetAnonyString(localUdid).c_str(), userId);
- std::vector profiles = GetAccessControlProfileByUserId(userId);
+ std::vector profiles = GetAllAclIncludeLnnAcl();
for (const auto &item : profiles) {
+ if (find(peerUdids.begin(), peerUdids.end(), item.GetTrustDeviceId()) == peerUdids.end()) {
+ continue;
+ }
std::string accesserUdid = item.GetAccesser().GetAccesserDeviceId();
std::string accesseeUdid = item.GetAccessee().GetAccesseeDeviceId();
int32_t accesserUserId = item.GetAccesser().GetAccesserUserId();
int32_t accesseeUserId = item.GetAccessee().GetAccesseeUserId();
- if ((accesserUdid == localUdid && accesserUserId == userId) ||
- (accesseeUdid == localUdid && accesseeUserId == userId)) {
- DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(item.GetAccessControlId());
+ if (accesserUdid == localUdid && accesserUserId == userId) {
+ if (!IsValueExist(peerUserIdMap, accesseeUdid, accesseeUserId)) {
+ peerUserIdMap.insert(std::pair(accesseeUdid, accesseeUserId));
+ }
+ CacheAcerAclId(item, offlineParam.needDelAclInfos);
+ continue;
+ }
+ if (accesseeUdid == localUdid && accesseeUserId == userId) {
+ if (!IsValueExist(peerUserIdMap, accesserUdid, accesserUserId)) {
+ peerUserIdMap.insert(std::pair(accesserUdid, accesserUserId));
+ }
+ CacheAceeAclId(item, offlineParam.needDelAclInfos);
+ continue;
}
}
}
-void DeviceProfileConnector::DeleteAclForRemoteUserRemoved(std::string peerUdid, int32_t peerUserId,
- std::vector &userIds)
+
+DM_EXPORT void DeviceProfileConnector::DeleteAclForRemoteUserRemoved(
+ std::string peerUdid, int32_t peerUserId, std::vector &userIds, DmOfflineParam &offlineParam)
{
LOGI("peerUdid %{public}s, peerUserId %{public}d.", GetAnonyString(peerUdid).c_str(), peerUserId);
- std::vector profiles = GetAccessControlProfileByUserId(peerUserId);
+ std::vector profiles = GetAllAclIncludeLnnAcl();
for (const auto &item : profiles) {
std::string accesserUdid = item.GetAccesser().GetAccesserDeviceId();
std::string accesseeUdid = item.GetAccessee().GetAccesseeDeviceId();
int32_t accesserUserId = item.GetAccesser().GetAccesserUserId();
int32_t accesseeUserId = item.GetAccessee().GetAccesseeUserId();
if (accesserUdid == peerUdid && accesserUserId == peerUserId) {
- DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(item.GetAccessControlId());
- if (item.GetBindLevel() == DEVICE) {
+ if (item.GetBindLevel() == USER) {
userIds.push_back(accesseeUserId);
}
+ CacheAceeAclId(item, offlineParam.needDelAclInfos);
}
if (accesseeUdid == peerUdid && accesseeUserId == peerUserId) {
- DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(item.GetAccessControlId());
- if (item.GetBindLevel() == DEVICE) {
+ if (item.GetBindLevel() == USER) {
userIds.push_back(accesserUserId);
}
+ CacheAcerAclId(item, offlineParam.needDelAclInfos);
}
}
}
-void DeviceProfileConnector::DeleteAccessControlList(const std::string &udid)
+DM_EXPORT void DeviceProfileConnector::DeleteAccessControlList(const std::string &udid)
{
LOGI("Udid: %{public}s.", GetAnonyString(udid).c_str());
if (udid.empty()) {
@@ -605,7 +1263,7 @@ DmOfflineParam DeviceProfileConnector::DeleteAccessControlList(const std::string
pkgName.c_str(), GetAnonyString(localDeviceId).c_str(), GetAnonyString(remoteDeviceId).c_str(), bindLevel);
DmOfflineParam offlineParam;
offlineParam.bindType = INVALIED_TYPE;
- if (static_cast(bindLevel) > APP || static_cast(bindLevel) < DEVICE) {
+ if (static_cast(bindLevel) > APP || static_cast(bindLevel) < USER) {
LOGE("Invalied bindlevel.");
return offlineParam;
}
@@ -626,7 +1284,7 @@ DmOfflineParam DeviceProfileConnector::DeleteAccessControlList(const std::string
case SERVICE:
DeleteServiceBindLevel(offlineParam, pkgName, profiles, localDeviceId, remoteDeviceId);
break;
- case DEVICE:
+ case USER:
DeleteDeviceBindLevel(offlineParam, profiles, localDeviceId, remoteDeviceId);
break;
default:
@@ -656,6 +1314,7 @@ void DeviceProfileConnector::DeleteAppBindLevel(DmOfflineParam &offlineParam, co
processInfo.pkgName = item.GetAccesser().GetAccesserBundleName();
processInfo.userId = item.GetAccesser().GetAccesserUserId();
offlineParam.processVec.push_back(processInfo);
+ offlineParam.peerUserId = item.GetAccessee().GetAccesseeUserId();
LOGI("Src delete acl pkgName %{public}s, bindType %{public}d, localUdid %{public}s, remoteUdid %{public}s",
pkgName.c_str(), item.GetBindType(), GetAnonyString(localUdid).c_str(),
GetAnonyString(remoteUdid).c_str());
@@ -671,7 +1330,8 @@ void DeviceProfileConnector::DeleteAppBindLevel(DmOfflineParam &offlineParam, co
processInfo.pkgName = item.GetAccessee().GetAccesseeBundleName();
processInfo.userId = item.GetAccessee().GetAccesseeUserId();
offlineParam.processVec.push_back(processInfo);
- LOGI("Sink delete acl pkgName %{public}s, bindType %{public}d, localUdid %{public}s, remoteUdid %{public}s",
+ offlineParam.peerUserId = item.GetAccesser().GetAccesserUserId();
+ LOGI("Sink delete acl pkgName %{public}s, bindType %{public}u, localUdid %{public}s, remoteUdid %{public}s",
pkgName.c_str(), item.GetBindType(), GetAnonyString(localUdid).c_str(),
GetAnonyString(remoteUdid).c_str());
continue;
@@ -687,7 +1347,9 @@ void DeviceProfileConnector::DeleteAppBindLevel(DmOfflineParam &offlineParam, co
LOGI("DeviceProfileConnector::DeleteAppBindLevel extra %{public}s", extra.c_str());
int32_t bindNums = 0;
int32_t deleteNums = 0;
- std::string peerBundleName = extra;
+ uint64_t peerTokenId = 0;
+ std::string peerBundleName;
+ ParseExtra(extra, peerTokenId, peerBundleName);
for (auto &item : profiles) {
if (item.GetTrustDeviceId() != remoteUdid || item.GetBindType() == DM_IDENTICAL_ACCOUNT ||
item.GetBindLevel() != APP) {
@@ -705,6 +1367,7 @@ void DeviceProfileConnector::DeleteAppBindLevel(DmOfflineParam &offlineParam, co
processInfo.pkgName = item.GetAccesser().GetAccesserBundleName();
processInfo.userId = item.GetAccesser().GetAccesserUserId();
offlineParam.processVec.push_back(processInfo);
+ offlineParam.peerUserId = item.GetAccessee().GetAccesseeUserId();
LOGI("Src delete acl pkgName %{public}s, bindType %{public}d, localUdid %{public}s, remoteUdid %{public}s",
pkgName.c_str(), item.GetBindType(), GetAnonyString(localUdid).c_str(),
GetAnonyString(remoteUdid).c_str());
@@ -721,7 +1384,8 @@ void DeviceProfileConnector::DeleteAppBindLevel(DmOfflineParam &offlineParam, co
processInfo.pkgName = item.GetAccessee().GetAccesseeBundleName();
processInfo.userId = item.GetAccessee().GetAccesseeUserId();
offlineParam.processVec.push_back(processInfo);
- LOGI("Sink delete acl pkgName %{public}s, bindType %{public}d, localUdid %{public}s, remoteUdid %{public}s",
+ offlineParam.peerUserId = item.GetAccesser().GetAccesserUserId();
+ LOGI("Sink delete acl pkgName %{public}s, bindType %{public}u, localUdid %{public}s, remoteUdid %{public}s",
pkgName.c_str(), item.GetBindType(), GetAnonyString(localUdid).c_str(),
GetAnonyString(remoteUdid).c_str());
continue;
@@ -744,7 +1408,7 @@ void DeviceProfileConnector::DeleteDeviceBindLevel(DmOfflineParam &offlineParam,
item.GetAccessee().GetAccesseeDeviceId() == remoteUdid) {
DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(item.GetAccessControlId());
deleteNums++;
- offlineParam.bindType = DEVICE;
+ offlineParam.bindType = USER;
LOGI("Src delete acl bindType %{public}d, localUdid %{public}s, remoteUdid %{public}s", item.GetBindType(),
GetAnonyString(localUdid).c_str(), GetAnonyString(remoteUdid).c_str());
continue;
@@ -753,8 +1417,8 @@ void DeviceProfileConnector::DeleteDeviceBindLevel(DmOfflineParam &offlineParam,
item.GetAccesser().GetAccesserDeviceId() == remoteUdid) {
DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(item.GetAccessControlId());
deleteNums++;
- offlineParam.bindType = DEVICE;
- LOGI("Sink delete acl bindType %{public}d, localUdid %{public}s, remoteUdid %{public}s", item.GetBindType(),
+ offlineParam.bindType = USER;
+ LOGI("Sink delete acl bindType %{public}u, localUdid %{public}s, remoteUdid %{public}s", item.GetBindType(),
GetAnonyString(localUdid).c_str(), GetAnonyString(remoteUdid).c_str());
continue;
}
@@ -790,7 +1454,7 @@ void DeviceProfileConnector::DeleteServiceBindLevel(DmOfflineParam &offlineParam
DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(item.GetAccessControlId());
deleteNums++;
offlineParam.bindType = SERVICE;
- LOGI("Sink delete acl pkgName %{public}s, bindType %{public}d, localUdid %{public}s, remoteUdid %{public}s",
+ LOGI("Sink delete acl pkgName %{public}s, bindType %{public}u, localUdid %{public}s, remoteUdid %{public}s",
pkgName.c_str(), item.GetBindType(), GetAnonyString(localUdid).c_str(),
GetAnonyString(remoteUdid).c_str());
continue;
@@ -823,13 +1487,14 @@ int32_t DeviceProfileConnector::UpdateAccessControlList(int32_t userId, std::str
return DM_OK;
}
-bool DeviceProfileConnector::CheckSrcDevIdInAclForDevBind(const std::string &pkgName, const std::string &deviceId)
+DM_EXPORT bool DeviceProfileConnector::CheckSrcDevIdInAclForDevBind(
+ const std::string &pkgName, const std::string &deviceId)
{
std::vector profiles = GetAccessControlProfile();
LOGI("AccessControlProfile size is %{public}zu", profiles.size());
for (auto &item : profiles) {
if (item.GetTrustDeviceId() == deviceId && item.GetStatus() == ACTIVE &&
- item.GetBindLevel() == DEVICE && (item.GetAccessee().GetAccesseeBundleName() == pkgName ||
+ item.GetBindLevel() == USER && (item.GetAccessee().GetAccesseeBundleName() == pkgName ||
item.GetAccesser().GetAccesserBundleName() == "") && item.GetAccessee().GetAccesseeUserId() == 0 &&
item.GetAccessee().GetAccesseeAccountId() == "") {
return true;
@@ -844,7 +1509,7 @@ bool DeviceProfileConnector::CheckSinkDevIdInAclForDevBind(const std::string &pk
LOGI("AccessControlProfile size is %{public}zu", profiles.size());
for (auto &item : profiles) {
if (item.GetTrustDeviceId() == deviceId && item.GetStatus() == ACTIVE &&
- item.GetBindLevel() == DEVICE && (item.GetAccesser().GetAccesserBundleName() == pkgName ||
+ item.GetBindLevel() == USER && (item.GetAccesser().GetAccesserBundleName() == pkgName ||
item.GetAccesser().GetAccesserBundleName() == "") && item.GetAccesser().GetAccesserUserId() == 0 &&
item.GetAccesser().GetAccesserAccountId() == "") {
return true;
@@ -858,25 +1523,70 @@ bool DeviceProfileConnector::CheckDevIdInAclForDevBind(const std::string &pkgNam
return (CheckSinkDevIdInAclForDevBind(pkgName, deviceId) || CheckSrcDevIdInAclForDevBind(pkgName, deviceId));
}
-uint32_t DeviceProfileConnector::DeleteTimeOutAcl(const std::string &deviceId)
+
+DM_EXPORT uint32_t DeviceProfileConnector::DeleteTimeOutAcl(const std::string &deviceId, DmOfflineParam &offlineParam)
{
- std::vector profiles = GetAccessControlProfile();
+ std::vector profiles = GetAllAclIncludeLnnAcl();
LOGI("AccessControlProfile size is %{public}zu", profiles.size());
uint32_t res = 0;
+ int32_t currentUserId = MultipleUserConnector::GetCurrentAccountUserID();
+ std::string localUdid = GetLocalDeviceId();
+ DmAclIdParam dmAclIdParam;
for (auto &item : profiles) {
if (item.GetTrustDeviceId() != deviceId || item.GetStatus() != ACTIVE) {
continue;
}
- res++;
+ if (CacheLnnAcl(item, localUdid, dmAclIdParam)) {
+ continue;
+ }
+ res++;
+ std::string accesserUdid = item.GetAccesser().GetAccesserDeviceId();
+ std::string accesseeUdid = item.GetAccessee().GetAccesseeDeviceId();
+ int32_t accesserUserId = item.GetAccesser().GetAccesserUserId();
+ int32_t accesseeUserId = item.GetAccessee().GetAccesseeUserId();
if (item.GetAuthenticationType() == ALLOW_AUTH_ONCE) {
res--;
- DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(item.GetAccessControlId());
+ if (accesserUserId == currentUserId && accesserUdid == localUdid && accesseeUdid == deviceId) {
+ CacheAcerAclId(item, offlineParam.needDelAclInfos);
+ offlineParam.peerUserId = item.GetAccessee().GetAccesseeUserId();
+ }
+ if (accesseeUserId == currentUserId && accesseeUdid == localUdid && accesserUdid == deviceId) {
+ CacheAceeAclId(item, offlineParam.needDelAclInfos);
+ offlineParam.peerUserId = item.GetAccesser().GetAccesserUserId();
+ }
}
}
+ if (res == 0) {
+ offlineParam.needDelAclInfos.push_back(dmAclIdParam);
+ }
return res;
}
-int32_t DeviceProfileConnector::GetTrustNumber(const std::string &deviceId)
+
+bool DeviceProfileConnector::CacheLnnAcl(AccessControlProfile profile, const std::string &localUdid,
+ DmAclIdParam &dmAclIdParam)
+{
+ if (IsLnnAcl(profile)) {
+ if (profile.GetAccesser().GetAccesserDeviceId() == localUdid) {
+ dmAclIdParam.udid = profile.GetAccesser().GetAccesserDeviceId();
+ dmAclIdParam.userId = profile.GetAccesser().GetAccesserUserId();
+ dmAclIdParam.skId = profile.GetAccesser().GetAccesserSessionKeyId();
+ dmAclIdParam.credId = profile.GetAccesser().GetAccesserCredentialIdStr();
+ dmAclIdParam.accessControlId = profile.GetAccessControlId();
+ }
+ if (profile.GetAccessee().GetAccesseeDeviceId() == localUdid) {
+ dmAclIdParam.udid = profile.GetAccessee().GetAccesseeDeviceId();
+ dmAclIdParam.userId = profile.GetAccessee().GetAccesseeUserId();
+ dmAclIdParam.skId = profile.GetAccessee().GetAccesseeSessionKeyId();
+ dmAclIdParam.credId = profile.GetAccessee().GetAccesseeCredentialIdStr();
+ dmAclIdParam.accessControlId = profile.GetAccessControlId();
+ }
+ return true;
+ }
+ return false;
+}
+
+DM_EXPORT int32_t DeviceProfileConnector::GetTrustNumber(const std::string &deviceId)
{
std::vector profiles = GetAccessControlProfile();
LOGI("AccessControlProfile size is %{public}zu", profiles.size());
@@ -889,12 +1599,12 @@ int32_t DeviceProfileConnector::GetTrustNumber(const std::string &deviceId)
return trustNumber;
}
-int32_t DeviceProfileConnector::IsSameAccount(const std::string &udid)
+DM_EXPORT int32_t DeviceProfileConnector::IsSameAccount(const std::string &udid)
{
std::vector profiles = GetAccessControlProfile();
for (auto &item : profiles) {
if (item.GetTrustDeviceId() == udid && item.GetStatus() == ACTIVE) {
- if (item.GetBindType() == DM_IDENTICAL_ACCOUNT) { // 同账号
+ if (item.GetBindType() == DM_IDENTICAL_ACCOUNT) {
LOGI("The udid %{public}s is identical bind.", GetAnonyString(udid).c_str());
return DM_OK;
}
@@ -903,6 +1613,24 @@ int32_t DeviceProfileConnector::IsSameAccount(const std::string &udid)
return ERR_DM_FAILED;
}
+DM_EXPORT int32_t DeviceProfileConnector::CheckIsSameAccountByUdidHash(const std::string &udidHash)
+{
+ if (udidHash.empty()) {
+ LOGE("udidHash is empty!");
+ return ERR_DM_INPUT_PARA_INVALID;
+ }
+ std::vector