解冲突

Signed-off-by: guoyi <guoyi39@huawei.com>
This commit is contained in:
guoyi 2024-11-03 10:16:53 +08:00
parent ea064373f3
commit 5dc20b9ff7
24 changed files with 134 additions and 276 deletions

View File

@ -26,8 +26,9 @@
"components": [
"cJSON",
"c_utils",
"config_policy",
"common_event_service",
"config_policy",
"ffrt",
"hisysevent",
"hilog",
"ipc",

View File

@ -132,16 +132,7 @@ constexpr int32_t MAX_INTERFACE_SIZE = 20;
constexpr int32_t MAX_SUBSCRIBE_INFO_SIZE = 500;
constexpr int32_t MAX_SYNC_RESULTS_SIZE = 50;
constexpr int32_t MAX_STATIC_CAPABILITY_SIZE = 100;
<<<<<<< HEAD
const std::string SEPARATOR = "#";
const std::string DEV_PREFIX = "dev";
const std::string SVR_PREFIX = "svr";
const std::string CHAR_PREFIX = "char";
const std::string USER_ID = "user_id";
const std::string IS_MULTI_USER = "is_muilt_user";
const std::string TOKEN_ID = "token_id";
const std::string ALL_PROC = "all";
=======
extern const std::string IS_MULTI_USER;
extern const std::string SEPARATOR;
extern const std::string DEV_PREFIX;
extern const std::string SVR_PREFIX;
@ -149,11 +140,12 @@ extern const std::string CHAR_PREFIX;
extern const std::string USER_ID;
extern const std::string TOKEN_ID;
extern const std::string ALL_PROC;
>>>>>>> dc018b8 (update)
constexpr int32_t NUM_1 = 1;
constexpr int32_t NUM_2 = 2;
constexpr int32_t NUM_3 = 3;
constexpr int32_t NUM_4 = 4;
constexpr int32_t NUM_5 = 5;
constexpr int32_t NUM_6 = 6;
constexpr int32_t DEFAULT_USER_ID = -1;
constexpr uint32_t NUM_1U = 1;
constexpr uint32_t NUM_8U = 8;

View File

@ -151,7 +151,14 @@ constexpr int32_t DP_NULLPTR = 98566273;
constexpr int32_t DP_SUBSCRIBE_INITED_FALI = 98566274;
constexpr int32_t DP_GET_DEVICE_ENTRIES_FAIL = 98566275;
constexpr int32_t DP_RDB_DATABASE_RESTORE_FAIL = 98566276;
// multi-user
constexpr int32_t DP_GET_FOREGROUND_ID_FAIL = 98566277;
constexpr int32_t DP_GET_MULTI_USER_PROFILE_PARAMS_INVALID = 98566278;
constexpr int32_t DP_GET_LOCAL_PROFILE_IS_NOT_FOREGROUND_ID = 98566279;
constexpr int32_t DP_GET_USER_ID_IS_NOT_TRUSTED = 98566280;
constexpr int32_t DP_MULTI_USER_MANAGER_INIT_FAIL = 98566281;
constexpr int32_t DP_MULTI_USER_MANAGER_UNINIT_FAIL = 98566282;
} // namespace DistributedDeviceProfile
} // namespace OHOS
#endif // OHOS_DP_DISTRIBUTED_DEVICE_PROFILE_ERRORS_H

View File

@ -52,16 +52,10 @@ public:
virtual int32_t GetServiceProfile(const std::string& deviceId, const std::string& serviceName,
ServiceProfile& serviceProfile, bool isMultiUser = false, int32_t userId = DEFAULT_USER_ID) = 0;
virtual int32_t GetCharacteristicProfile(const std::string& deviceId, const std::string& serviceName,
<<<<<<< HEAD
const std::string& characteristicId, CharacteristicProfile& charProfile) = 0;
virtual int32_t DeleteServiceProfile(const std::string& deviceId, const std::string& serviceName,
bool isMuitUser = false, int32_t userId = -1) = 0;
=======
const std::string& characteristicId, CharacteristicProfile& charProfile, bool isMultiUser = false,
int32_t userId = DEFAULT_USER_ID) = 0;
virtual int32_t DeleteServiceProfile(const std::string& deviceId, const std::string& serviceName,
bool isMultiUser = false, int32_t userId = DEFAULT_USER_ID) = 0;
>>>>>>> 6cd545d ()
virtual int32_t DeleteCharacteristicProfile(const std::string& deviceId, const std::string& serviceName,
const std::string& characteristicId, bool isMultiUser = false, int32_t userId = DEFAULT_USER_ID) = 0;
virtual int32_t SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) = 0;

View File

@ -26,6 +26,7 @@
#include "access_control_profile.h"
#include "characteristic_profile.h"
#include "device_profile.h"
#include "distributed_device_profile_constants.h"
#include "service_profile.h"
#include "trust_device_profile.h"
@ -37,6 +38,7 @@ class ProfileUtils {
public:
static std::string GetDbKeyAnonyString(const std::string& value);
static std::string GetAnonyString(const std::string& value);
static std::string GetAnonyInt32(const int32_t value);
static std::vector<std::string> GetOnlineDevices();
static std::string GetLocalUdidFromDM();
static bool FilterAndGroupOnlineDevices(const std::vector<std::string>& deviceList,
@ -82,7 +84,7 @@ public:
static int32_t EntriesToServiceProfile(std::map<std::string, std::string> values, ServiceProfile& profile);
static int32_t EntriesToCharProfile(std::map<std::string, std::string> values, CharacteristicProfile& profile);
static std::string GenerateDBKey(const std::string& profileKey, const std::string& profileProperty,
int32_t userId = -1);
int32_t userId = DEFAULT_USER_ID);
static std::string GetProfileKey(const std::string& dbKey);
static std::string GetDeviceIdByDBKey(const std::string& dbKey);
static std::string GetServiceNameByDBKey(const std::string& dbKey);
@ -94,21 +96,9 @@ public:
static std::string GetDbKeyByProfile(const CharacteristicProfile& profile);
static int32_t SplitString(const std::string& str, const std::string& splits, std::vector<std::string>& res);
static std::string JoinString(const std::vector<std::string>& strs, const std::string& delimiter);
<<<<<<< HEAD
static std::string GetProfileProperty(const std::string& dbKey);
<<<<<<< HEAD
static std::map<std::string, std::string> GetProfilePropertiesMap(std::map<std::string, std::string> dbEntries);
=======
static std::map<std::string, std::string> GetProfilePropertiesMap(
const std::map<std::string, std::string>& dbEntries, int32_t userId = DEFAULT_USER_ID);
static void GetProfilePropertiesMap(const std::map<std::string, std::string>& dbEntries,
std::map<std::string, std::string>& propertiesMap);
>>>>>>> fdcd212 ()
=======
static std::string GetProfileProperty(const std::string& dbKey, int32_t userId = DEFAULT_USER_ID);
static std::map<std::string, std::string> GetProfilePropertiesMap(std::map<std::string, std::string> dbEntries,
int32_t userId = DEFAULT_USER_ID);
>>>>>>> 1d65cf1 (fix codecheck)
static std::string toString(const std::u16string& str16);
static bool IsPropertyValid(const std::map<std::string, std::string>& propertyMap, const std::string& property,
int32_t maxValue);
@ -120,24 +110,13 @@ public:
static bool GetUdidByNetworkId(const std::string& networkId, std::string& udid);
static bool GetUuidByNetworkId(const std::string& networkId, std::string& uuid);
static bool IsNumStr(const std::string& inString);
<<<<<<< HEAD
=======
static int32_t GetUserIdFromDbKey(const std::string& dbKey);
static std::string RemoveUserIdFromDbKey(const std::string& dbKey);
static int32_t GenerateServiceDBkeys(const std::string& deviceId, const std::string& serviceName,
std::vector<std::string>& dbKeys, bool isMultiUser = false, int32_t userId = DEFAULT_USER_ID);
static int32_t GenerateCharacteristicDBkeys(const std::string& deviceId, const std::string& serviceName,
<<<<<<< HEAD
const std::string& characteristicKey, std::vector<std::string>& dbKeys, bool isMuiltUser = false,
<<<<<<< HEAD
int32_t userId = -1);
>>>>>>> 507ffd4 (KV Delete接口适配多用户)
=======
=======
const std::string& characteristicKey, std::vector<std::string>& dbKeys, bool isMultiUser = false,
>>>>>>> fdcd212 ()
int32_t userId = DEFAULT_USER_ID);
>>>>>>> 6cd545d ()
};
} // namespace DistributedDeviceProfile
} // namespace OHOS

View File

@ -224,17 +224,9 @@ std::string DeviceProfile::dump() const
cJSON_AddNumberToObject(json, OS_API_LEVEL.c_str(), osApiLevel_);
cJSON_AddStringToObject(json, OS_VERSION.c_str(), osVersion_.c_str());
cJSON_AddNumberToObject(json, OS_TYPE.c_str(), osType_);
<<<<<<< HEAD
cJSON_AddBoolToObject(json, IS_MULTI_USER.c_str(), isMuitUser_);
<<<<<<< HEAD
cJSON_AddNumberToObject(json, USER_ID.c_str(), userId_);
=======
=======
cJSON_AddBoolToObject(json, IS_MULTI_USER.c_str(), isMultiUser_);
>>>>>>> 6cd545d ()
cJSON_AddStringToObject(json, USER_ID.c_str(),
ProfileUtils::GetAnonyString(std::to_string(userId_)).c_str());
>>>>>>> 776ed34 (userId匿名dump)
char* jsonChars = cJSON_PrintUnformatted(json);
if (jsonChars == NULL) {
cJSON_Delete(json);

View File

@ -28,12 +28,12 @@ namespace {
}
SubscribeInfo::SubscribeInfo(int32_t saId, const std::string& subscribeKey,
std::unordered_set<ProfileChangeType> subscribeChangeTypes, sptr<IProfileChangeListener> profileChangeListener,
int32_t userId = DEFAULT_USER_ID)
int32_t userId)
{
this->saId_ = saId;
this->subscribeKey_ = subscribeKey;
if (userId != DEFAULT_USER_ID) {
this->subscribeKey_ = this->subscribeKey_ + SEPARATOR + userId;
this->subscribeKey_ = this->subscribeKey_ + SEPARATOR + std::to_string(userId);
}
this->subscribeChangeTypes_ = subscribeChangeTypes;
if (profileChangeListener == nullptr) {
@ -66,29 +66,29 @@ void SubscribeInfo::SetSaId(int32_t saId)
}
void SubscribeInfo::SetSubscribeKey(const std::string& deviceId, const std::string& deviceAttribute,
int32_t userId = DEFAULT_USER_ID)
int32_t userId)
{
subscribeKey_ = DEV_PREFIX + SEPARATOR + deviceId + SEPARATOR + deviceAttribute;
if (userId != DEFAULT_USER_ID) {
subscribeKey_ = subscribeKey_ + SEPARATOR + userId;
subscribeKey_ = subscribeKey_ + SEPARATOR + std::to_string(userId);
}
}
void SubscribeInfo::SetSubscribeKey(const std::string& deviceId, const std::string& serviceName,
const std::string& serviceAttribute, int32_t userId = DEFAULT_USER_ID)
const std::string& serviceAttribute, int32_t userId)
{
subscribeKey_ = SVR_PREFIX + SEPARATOR + deviceId + SEPARATOR + serviceName + SEPARATOR + serviceAttribute;
if (userId != DEFAULT_USER_ID) {
subscribeKey_ = subscribeKey_ + SEPARATOR + userId;
subscribeKey_ = subscribeKey_ + SEPARATOR + std::to_string(userId);
}
}
void SubscribeInfo::SetSubscribeKey(const std::string& deviceId, const std::string& serviceName,
const std::string& characteristicKey, const std::string& characteristicAttribute, int32_t userId = DEFAULT_USER_ID)
const std::string& characteristicKey, const std::string& characteristicAttribute, int32_t userId)
{
subscribeKey_ = CHAR_PREFIX + SEPARATOR + deviceId + SEPARATOR + serviceName + SEPARATOR + characteristicKey +
SEPARATOR + characteristicAttribute;
if (userId != DEFAULT_USER_ID) {
subscribeKey_ = subscribeKey_ + SEPARATOR + userId;
subscribeKey_ = subscribeKey_ + SEPARATOR + std::to_string(userId);
}
}
@ -97,7 +97,7 @@ std::string SubscribeInfo::GetSubscribeKey() const
return subscribeKey_;
}
void SubscribeInfo::SetSubscribeKey(const std::string& subscribeKey)
void SubscribeInfo::SetSubscribeKey(const std::string& subscribeKey, int32_t userId)
{
subscribeKey_ = subscribeKey;
}

View File

@ -150,4 +150,4 @@ std::string ServiceProfile::dump() const
return jsonStr;
}
} // namespace DistributedDeviceProfile
} // namespace OHOS
} // namespace OHOS

View File

@ -80,6 +80,26 @@ std::string ProfileUtils::GetAnonyString(const std::string& value)
return res;
}
std::string ProfileUtils::GetAnonyInt32(const int32_t value)
{
constexpr int32_t INT32_STRING_LENGTH = 40;
char tempBuffer[INT32_STRING_LENGTH] = "";
int32_t secRet = sprintf_s(tempBuffer, INT32_STRING_LENGTH, "%d", value);
size_t length = strlen(tempBuffer);
if (secRet <= 0 || length == 0) {
std::string nullString("");
return nullString;
}
for (size_t i = 1; i <= length - 1; ++i) {
tempBuffer[i] = '*';
}
if (length == 0x01) {
tempBuffer[0] = '*';
}
std::string tempBufferStr(tempBuffer);
return tempBufferStr;
}
std::vector<std::string> ProfileUtils::GetOnlineDevices()
{
std::vector<std::string> targetDevices;
@ -647,7 +667,7 @@ int32_t ProfileUtils::EntriesToDeviceProfile(std::map<std::string, std::string>
HILOGI("Entries size is invalid!size: %{public}zu!", values.size());
return DP_INVALID_PARAMS;
}
auto propertiesMap = GetProfilePropertiesMap(values);
auto propertiesMap = GetProfilePropertiesMap(values, profile.GetUserId());
if (IsPropertyValid(propertiesMap, OS_SYS_CAPACITY, MAX_STRING_LEN)) {
profile.SetOsSysCap(propertiesMap[OS_SYS_CAPACITY]);
}
@ -676,7 +696,7 @@ int32_t ProfileUtils::EntriesToServiceProfile(std::map<std::string, std::string>
}
auto iter = values.begin();
profile.SetDeviceId(GetDeviceIdByDBKey(iter->first));
auto propertiesMap = GetProfilePropertiesMap(values);
auto propertiesMap = GetProfilePropertiesMap(values, profile.GetUserId());
if (propertiesMap.count(SERVICE_NAME) != 0 && 0 < propertiesMap[SERVICE_NAME].length() &&
propertiesMap[SERVICE_NAME].length() < MAX_STRING_LEN) {
profile.SetServiceName(CheckAndRemoveOhSuffix(propertiesMap[SERVICE_NAME]));
@ -697,7 +717,7 @@ int32_t ProfileUtils::EntriesToCharProfile(std::map<std::string, std::string> va
auto iter = values.begin();
profile.SetDeviceId(GetDeviceIdByDBKey(iter->first));
profile.SetServiceName(GetNonOhSuffixServiceNameByDBKey(iter->first));
auto propertiesMap = GetProfilePropertiesMap(values);
auto propertiesMap = GetProfilePropertiesMap(values, profile.GetUserId());
if (propertiesMap.count(CHARACTERISTIC_KEY) != 0 && 0 < propertiesMap[CHARACTERISTIC_KEY].length() &&
propertiesMap[CHARACTERISTIC_KEY].length() < MAX_STRING_LEN) {
profile.SetCharacteristicKey(propertiesMap[CHARACTERISTIC_KEY]);
@ -721,44 +741,12 @@ std::string ProfileUtils::GenerateDBKey(const std::string& profileKey, const std
return DBKey;
}
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> fdcd212 ()
std::string ProfileUtils::GetProfileProperty(const std::string& dbKey)
=======
std::string ProfileUtils::GetProfileProperty(const std::string& dbKey, int32_t userId)
>>>>>>> 1d65cf1 (fix codecheck)
{
if (dbKey.length() == 0 || dbKey.length() > MAX_STRING_LEN || (userId <= 0 && userId != DEFAULT_USER_ID)) {
return "";
}
<<<<<<< HEAD
<<<<<<< HEAD
std::size_t pos = dbKey.find_last_of("#");
if (pos == std::string::npos) {
return "";
}
return dbKey.substr(pos + 1);
}
std::map<std::string, std::string> ProfileUtils::GetProfilePropertiesMap(std::map<std::string, std::string> dbEntries)
{
std::map<std::string, std::string> propertiesMap;
for (const auto& item : dbEntries) {
std::string profileProperty = GetProfileProperty(item.first);
if (profileProperty.empty()) {
HILOGE("GetProfileProperty fail, %{public}s!", GetDbKeyAnonyString(item.first).c_str());
continue;
}
propertiesMap[profileProperty] = item.second;
}
return propertiesMap;
=======
=======
int32_t getUserId = GetUserIdFromDbKey(dbKey);
>>>>>>> 1d65cf1 (fix codecheck)
std::vector<std::string> splitKeys;
if (SplitString(dbKey, SEPARATOR, splitKeys) != DP_SUCCESS || splitKeys.size() < NUM_3) {
HILOGE("GetProfileProperty SplitString fail");
@ -766,36 +754,11 @@ std::map<std::string, std::string> ProfileUtils::GetProfilePropertiesMap(std::ma
}
if (splitKeys[0] == DEV_PREFIX) {
<<<<<<< HEAD
<<<<<<< HEAD
if ((userId == DEFAULT_USER_ID && getUserId == DEFAULT_USER_ID) ||
(userId == DEFAULT_USER_ID && getUserId == DEFAULT_USER_ID)) {
return splitKeys[NUM_2];
}
return (userId == getUserId) ? splitKeys[NUM_2] : "";
}
if (splitKeys[0] == SVR_PREFIX && splitKeys.size() >= NUM_4) {
if ((userId == DEFAULT_USER_ID && getUserId == DEFAULT_USER_ID) ||
(userId == DEFAULT_USER_ID && getUserId == DEFAULT_USER_ID)) {
return splitKeys[NUM_3];
}
return (userId == getUserId) ? splitKeys[NUM_3] : "";
}
if (splitKeys[0] == CHAR_PREFIX && splitKeys.size() >= NUM_5) {
if ((userId == DEFAULT_USER_ID && getUserId == DEFAULT_USER_ID) ||
(userId == DEFAULT_USER_ID && getUserId == DEFAULT_USER_ID)) {
return splitKeys[NUM_4];
}
return (userId == getUserId) ? splitKeys[NUM_4] : "";
=======
return splitKeys[NUM_2];
=======
if ((userId == DEFAULT_USER_ID && getUserId == DEFAULT_USER_ID) ||
(userId != DEFAULT_USER_ID && getUserId == DEFAULT_USER_ID)) {
return splitKeys[NUM_2];
}
return (userId == getUserId) ? splitKeys[NUM_2] : "";
>>>>>>> 66a9bff (Revert "转换dbEnties到Profile")
}
if (splitKeys[0] == SVR_PREFIX && splitKeys.size() >= NUM_4) {
if ((userId == DEFAULT_USER_ID && getUserId == DEFAULT_USER_ID) ||
@ -804,18 +767,12 @@ std::map<std::string, std::string> ProfileUtils::GetProfilePropertiesMap(std::ma
}
return (userId == getUserId) ? splitKeys[NUM_3] : "";
}
<<<<<<< HEAD
if (splitKeys[0] == CHAR_PREFIX && splitKeys.size() > NUM_4) {
return splitKeys[NUM_4];
>>>>>>> f19f01a (dbEnties到Profile)
=======
if (splitKeys[0] == CHAR_PREFIX && splitKeys.size() >= NUM_5) {
if ((userId == DEFAULT_USER_ID && getUserId == DEFAULT_USER_ID) ||
(userId != DEFAULT_USER_ID && getUserId == DEFAULT_USER_ID)) {
return splitKeys[NUM_4];
}
return (userId == getUserId) ? splitKeys[NUM_4] : "";
>>>>>>> 66a9bff (Revert "转换dbEnties到Profile")
}
HILOGE("dbKey has wrong prefix");
@ -843,9 +800,6 @@ std::map<std::string, std::string> ProfileUtils::GetProfilePropertiesMap(std::ma
}
propertiesWithUserId[profileProperty] = item.second;
}
<<<<<<< HEAD
>>>>>>> fdcd212 ()
=======
if (userId != DEFAULT_USER_ID && !propertiesWithUserId.empty()) {
HILOGI("GetProfile with multi-user");
@ -856,7 +810,6 @@ std::map<std::string, std::string> ProfileUtils::GetProfilePropertiesMap(std::ma
//2. Get profile with multi-user, but remote device without multi-user;
//3. Get profile with multi-user, but can't find in DB;
return propertiesWithoutUserId;
>>>>>>> 1d65cf1 (fix codecheck)
}
std::string ProfileUtils::toString(const std::u16string& str16)
@ -953,8 +906,6 @@ std::string ProfileUtils::GetDbKeyByProfile(const CharacteristicProfile& profile
SEPARATOR + profile.GetCharacteristicKey() + SEPARATOR + CHARACTERISTIC_VALUE;
return dbKey;
}
<<<<<<< HEAD
=======
int32_t ProfileUtils::GetUserIdFromDbKey(const std::string& dbKey)
{
@ -964,16 +915,6 @@ int32_t ProfileUtils::GetUserIdFromDbKey(const std::string& dbKey)
HILOGE("SplitString fail");
return userId;
}
<<<<<<< HEAD
if(splitKeys[0] == DEV_PREFIX && splitKeys.size() == NUM_4 && IsNumStr(splitKeys[NUM_3])) {
userId = std::atoi(splitKeys[NUM_3]);
}
if(splitKeys[0] == SVR_PREFIX && splitKeys.size() == NUM_5 && IsNumStr(splitKeys[NUM_4])) {
userId = std::atoi(splitKeys[NUM_4]);
}
if(splitKeys[0] == CHAR_PREFIX && splitKeys.size() == NUM_6 && IsNumStr(splitKeys[NUM_5])) {
userId = std::atoi(splitKeys[NUM_5]);
=======
if (splitKeys[0] == DEV_PREFIX && splitKeys.size() > NUM_3 && IsNumStr(splitKeys[NUM_3])) {
userId = std::atoi(splitKeys[NUM_3].c_str());
}
@ -982,7 +923,6 @@ int32_t ProfileUtils::GetUserIdFromDbKey(const std::string& dbKey)
}
if (splitKeys[0] == CHAR_PREFIX && splitKeys.size() > NUM_5 && IsNumStr(splitKeys[NUM_5])) {
userId = std::atoi(splitKeys[NUM_5].c_str());
>>>>>>> 86ce8ca ()
}
return userId;
}
@ -1041,6 +981,5 @@ int32_t ProfileUtils::GenerateCharacteristicDBkeys(const std::string& deviceId,
}
return DP_SUCCESS;
}
>>>>>>> 507ffd4 (KV Delete接口适配多用户)
} // namespace DistributedDeviceProfile
} // namespace OHOS

View File

@ -40,6 +40,7 @@ config("device_info_manager_config") {
"${device_profile_service}/include/permissionmanager",
"${device_profile_service}/include/persistenceadapter/kvadapter",
"${device_profile_service}/include/persistenceadapter/rdbadapter",
"${device_profile_service}/include/publishcommonevent",
"${device_profile_service}/include/subscribeprofilemanager",
"${device_profile_service}/include/trustprofilemanager",
"${device_profile_service}/include/utils",

View File

@ -68,7 +68,8 @@ private:
std::unordered_set<int32_t> depSaIds_ {
SOFTBUS_SERVER_SA_ID,
DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID,
DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID
DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID,
SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN
};
};
} // namespace DeviceProfile

View File

@ -263,6 +263,7 @@ void DistributedDeviceProfileService::OnStart(const SystemAbilityOnDemandReason&
AddSystemAbilityListener(SOFTBUS_SERVER_SA_ID);
AddSystemAbilityListener(DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID);
AddSystemAbilityListener(DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID);
AddSystemAbilityListener(SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN);
if (!Publish(this)) {
HILOGE("publish SA failed");
return;

View File

@ -116,6 +116,7 @@ ohos_shared_library("distributed_device_profile_svr") {
"device_manager:devicemanagersdk",
"dmsfwk:common_sdk",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"hilog:libhilog",
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",

View File

@ -74,6 +74,7 @@ public:
void OnDeviceOnline(const DistributedHardware::DmDeviceInfo deviceInfo);
void OnDeviceTrustChange(const std::string& peerUdid, const std::string& peerUuid,
const DistributedHardware::DmAuthForm authform);
void OnUserChange(int32_t lastUserId, int32_t curUserId);
private:
bool LoadDpSyncAdapter();
@ -98,7 +99,12 @@ private:
void NotifyNotOHBaseOnline(const DistributedHardware::DmDeviceInfo deviceInfo);
void E2ESyncDynamicProfile(const DistributedHardware::DmDeviceInfo deviceInfo);
void ClearDataWithPeerLogout(const std::string& peerUdid, const std::string& peerUuid);
int32_t SaveBatchByKeys(const std::map<std::string, std::string>& entries);
void FixDiffProfiles();
template <typename T>
int32_t IsMultiUserValid(const T& profile);
bool IsSameAccount(const std::string deviceId, const int32_t userId);
bool HasTrustP2PRelation(const std::string deviceId, const int32_t userId);
bool isAdapterSoLoaded_ = false;
std::mutex isAdapterLoadLock_;
std::mutex dynamicStoreMutex_;

View File

@ -21,6 +21,7 @@
#include <mutex>
#include <unordered_set>
#include "distributed_device_profile_stub_new.h"
#include "dp_account_common_event.h"
#include "i_dp_inited_callback.h"
#include "event_handler.h"
#include "event_runner.h"
@ -82,6 +83,7 @@ protected:
void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
private:
void AccountCommonEventCallback(int32_t userId, const std::string commonEventType);
int32_t CreateUnloadHandler();
int32_t DestroyUnloadHandler();
int32_t AddSvrProfilesToCache(const std::vector<ServiceProfile>& serviceProfiles);
@ -89,10 +91,12 @@ private:
int32_t SaveSwitchProfilesFromTempCache();
int32_t SaveDynamicProfilesFromTempCache();
int32_t NotifyDeviceProfileInited();
void SubscribeAccountCommonEvent();
void GetDynamicProfilesFromTempCache(std::map<std::string, std::string>& entries);
void ClearProfileCache();
private:
std::shared_ptr<DpAccountCommonEventManager> accountCommonEventManager_;
std::shared_ptr<AppExecFwk::EventHandler> unloadHandler_;
std::mutex unloadMutex_;
std::atomic<bool> isInited_{false};
@ -106,7 +110,8 @@ private:
std::unordered_set<int32_t> depSaIds_ {
SOFTBUS_SERVER_SA_ID,
DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID,
DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID
DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID,
SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN
};
};
} // namespace DeviceProfile

View File

@ -37,6 +37,8 @@ public:
void SetCurrentForegroundUserID(int32_t userId);
int32_t GetForegroundUserIDFromOs();
private:
int32_t foregroundUserId_ = -1;
std::mutex foregroundUserIdLock_;

View File

@ -95,11 +95,6 @@ private:
int32_t RefreshStaticProfileCache(const std::unordered_map<std::string, CharacteristicProfile>& staticProfiles);
private:
<<<<<<< HEAD
std:mutex foregroundIdMutex_;
int32_t foregroundId_ = -1;
=======
>>>>>>> 8f3393c (cache中不必要的代码)
std::string localNetworkId_;
std::mutex switchMutex_;
uint32_t curLocalSwitch_ = 0x0000;

View File

@ -25,6 +25,7 @@
#include "content_sensor_manager_utils.h"
#include "distributed_device_profile_errors.h"
#include "distributed_device_profile_enums.h"
#include "distributed_device_profile_log.h"
#include "event_handler_factory.h"
#include "i_sync_completed_callback.h"
@ -35,6 +36,7 @@
#include "profile_control_utils.h"
#include "profile_utils.h"
#include "static_profile_manager.h"
#include "trust_profile_manager.h"
namespace OHOS {
namespace DistributedDeviceProfile {
@ -295,16 +297,6 @@ int32_t DeviceProfileManager::PutCharacteristicProfileBatch(const std::vector<Ch
int32_t DeviceProfileManager::GetDeviceProfile(const std::string& deviceId, DeviceProfile& deviceProfile,
bool isMultiUser, int32_t userId)
{
<<<<<<< HEAD
HILOGD("call!");
=======
<<<<<<< HEAD
if ((deviceProfile.GetIsMuitUser() && deviceProfile.GetUserId() <= 0) ||
(!deviceProfile.GetIsMuitUser() && deviceProfile.GetUserId() != DEFAULT_USER_ID)) {
HILOGE("multi-user params are invalid, isMultiUser: %{public}d, userId: %{public}s",
deviceProfile.GetIsMuitUser(),
ProfileUtils::GetAnonyString(std::to_string(deviceProfile.GetUserId()).c_str()).c_str());
=======
deviceProfile.SetDeviceId(deviceId);
deviceProfile.SetIsMultiUser(isMultiUser);
deviceProfile.SetUserId(userId);
@ -312,16 +304,7 @@ int32_t DeviceProfileManager::GetDeviceProfile(const std::string& deviceId, Devi
if (res != DP_SUCCESS) {
HILOGE("GetDeviceProfile IsMultiUserValid failed, res: %{public}d", res);
return res;
>>>>>>> f7ce896 (get接口添加默认参数)
}
if (deviceProfile.GetIsMuitUser()) {
HILOGI("this profile support multi-user, userId: %{public}s",
ProfileUtils::GetAnonyString(std::to_string(deviceProfile.GetUserId()).c_str()).c_str());
}
HILOGI("this profile not support multi-user");
>>>>>>> 6468278 ()
int32_t res = 0;
{
std::lock_guard<std::mutex> lock(dynamicStoreMutex_);
res = ProfileControlUtils::GetDeviceProfile(deviceProfileStore_, deviceId, deviceProfile);
@ -337,16 +320,6 @@ int32_t DeviceProfileManager::GetDeviceProfile(const std::string& deviceId, Devi
int32_t DeviceProfileManager::GetServiceProfile(const std::string& deviceId, const std::string& serviceName,
ServiceProfile& serviceProfile, bool isMultiUser, int32_t userId)
{
<<<<<<< HEAD
HILOGD("call!");
=======
<<<<<<< HEAD
if ((serviceProfile.GetIsMuitUser() && serviceProfile.GetUserId() <= 0) ||
(!serviceProfile.GetIsMuitUser() && serviceProfile.GetUserId() != DEFAULT_USER_ID)) {
HILOGE("multi-user params are invalid, isMultiUser: %{public}d, userId: %{public}s",
serviceProfile.GetIsMuitUser(),
ProfileUtils::GetAnonyString(std::to_string(serviceProfile.GetUserId()).c_str()).c_str());
=======
serviceProfile.SetDeviceId(deviceId);
serviceProfile.SetIsMultiUser(isMultiUser);
serviceProfile.SetUserId(userId);
@ -354,16 +327,7 @@ int32_t DeviceProfileManager::GetServiceProfile(const std::string& deviceId, con
if (res != DP_SUCCESS) {
HILOGE("GetServiceProfile IsMultiUserValid failed, res: %{public}d", res);
return res;
>>>>>>> f7ce896 (get接口添加默认参数)
}
if (serviceProfile.GetIsMuitUser()) {
HILOGI("this profile support multi-user, userId: %{public}s",
ProfileUtils::GetAnonyString(std::to_string(serviceProfile.GetUserId()).c_str()).c_str());
}
HILOGI("this profile not support multi-user");
>>>>>>> 6468278 ()
int32_t res = 0;
{
std::lock_guard<std::mutex> lock(dynamicStoreMutex_);
res = ProfileControlUtils::GetServiceProfile(deviceProfileStore_, deviceId, serviceName,
@ -380,16 +344,6 @@ int32_t DeviceProfileManager::GetServiceProfile(const std::string& deviceId, con
int32_t DeviceProfileManager::GetCharacteristicProfile(const std::string& deviceId, const std::string& serviceName,
const std::string& characteristicKey, CharacteristicProfile& charProfile, bool isMultiUser, int32_t userId)
{
<<<<<<< HEAD
HILOGD("call!");
=======
<<<<<<< HEAD
if ((charProfile.GetIsMuitUser() && charProfile.GetUserId() <= 0) ||
(!charProfile.GetIsMuitUser() && charProfile.GetUserId() != DEFAULT_USER_ID)) {
HILOGE("multi-user params are invalid, isMultiUser: %{public}d, userId: %{public}s",
charProfile.GetIsMuitUser(),
ProfileUtils::GetAnonyString(std::to_string(charProfile.GetUserId()).c_str()).c_str());
=======
charProfile.SetDeviceId(deviceId);
charProfile.SetIsMultiUser(isMultiUser);
charProfile.SetUserId(userId);
@ -397,16 +351,7 @@ int32_t DeviceProfileManager::GetCharacteristicProfile(const std::string& device
if (res != DP_SUCCESS) {
HILOGE("GetCharacteristicProfile IsMultiUserValid failed, res: %{public}d", res);
return res;
>>>>>>> f7ce896 (get接口添加默认参数)
}
if (charProfile.GetIsMuitUser()) {
HILOGI("this profile support multi-user, userId: %{public}s",
ProfileUtils::GetAnonyString(std::to_string(charProfile.GetUserId()).c_str()).c_str());
}
HILOGI("this profile not support multi-user");
>>>>>>> 6468278 ()
int32_t res = 0;
{
std::lock_guard<std::mutex> lock(dynamicStoreMutex_);
res = ProfileControlUtils::GetCharacteristicProfile(deviceProfileStore_, deviceId, serviceName,
@ -1120,8 +1065,6 @@ void DeviceProfileManager::FixDiffProfiles()
}
return;
}
<<<<<<< HEAD
=======
void DeviceProfileManager::OnUserChange(int32_t lastUserId, int32_t curUserId)
{
@ -1193,11 +1136,6 @@ int32_t DeviceProfileManager::SaveBatchByKeys(const std::map<std::string, std::s
}
return DP_SUCCESS;
}
<<<<<<< HEAD
>>>>>>> 86ce8ca ()
=======
<<<<<<< HEAD
=======
template <typename T>
int32_t DeviceProfileManager::IsMultiUserValid(const T& profile)
@ -1289,7 +1227,5 @@ bool DeviceProfileManager::HasTrustP2PRelation(const std::string deviceId, const
return false;
}
>>>>>>> ad8db23 (update)
>>>>>>> 6468278 ()
} // namespace DeviceProfile
} // namespace OHOS

View File

@ -134,7 +134,7 @@ void KvDataChangeListener::FilterEntries(const std::vector<DistributedKv::Entry>
HILOGW("%{public}s is invalid dbKey", ProfileUtils::GetDbKeyAnonyString(dbKey).c_str());
continue;
}
if (res[0] == CHAR_PREFIX && res.size() > NUM_3 && res[NUM_3] == CHARACTERISTIC_KEY) {
if (res[0] == CHAR_PREFIX && res.size() > NUM_4 && res[NUM_4] == CHARACTERISTIC_KEY) {
HILOGD("%{public}s is charProfileKey", ProfileUtils::GetDbKeyAnonyString(dbKey).c_str());
continue;
}

View File

@ -24,6 +24,7 @@
#include "iservice_registry.h"
#include "sa_profiles.h"
#include "common_event_support.h"
#include "content_sensor_manager.h"
#include "device_profile_dumper.h"
#include "distributed_device_profile_constants.h"
@ -32,6 +33,7 @@
#include "device_profile_manager.h"
#include "dp_radar_helper.h"
#include "event_handler_factory.h"
#include "multi_user_manager.h"
#include "permission_manager.h"
#include "profile_cache.h"
#include "static_profile_manager.h"
@ -115,6 +117,10 @@ int32_t DistributedDeviceProfileServiceNew::PostInit()
HILOGE("ContentSensorManager init failed");
return DP_CONTENT_SENSOR_MANAGER_INIT_FAIL;
}
if (MultiUserManager::GetInstance().Init() != DP_SUCCESS) {
HILOGE("MultiUserManager init failed");
return DP_MULTI_USER_MANAGER_INIT_FAIL;
}
SaveSwitchProfilesFromTempCache();
SaveDynamicProfilesFromTempCache();
isInited_ = true;
@ -578,6 +584,7 @@ void DistributedDeviceProfileServiceNew::OnStart(const SystemAbilityOnDemandReas
AddSystemAbilityListener(SOFTBUS_SERVER_SA_ID);
AddSystemAbilityListener(DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID);
AddSystemAbilityListener(DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID);
AddSystemAbilityListener(SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN);
if (!Publish(this)) {
HILOGE("publish SA failed");
return;
@ -615,9 +622,47 @@ void DistributedDeviceProfileServiceNew::OnAddSystemAbility(int32_t systemAbilit
return;
}
}
if (systemAbilityId == SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN) {
SubscribeAccountCommonEvent();
}
PostInit();
}
void DistributedDeviceProfileServiceNew::SubscribeAccountCommonEvent()
{
HILOGI("Start");
if (accountCommonEventManager_ == nullptr) {
accountCommonEventManager_ = std::make_shared<DpAccountCommonEventManager>();
}
AccountEventCallback callback = [=](const auto &arg1, const auto &arg2) {
this->AccountCommonEventCallback(arg1, arg2);
};
std::vector<std::string> AccountCommonEventVec;
AccountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
AccountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED);
AccountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGOUT);
AccountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGIN);
if (accountCommonEventManager_->SubscribeAccountCommonEvent(AccountCommonEventVec, callback)) {
HILOGI("Success");
}
return;
}
void DistributedDeviceProfileServiceNew::AccountCommonEventCallback(int32_t userId, const std::string commonEventType)
{
HILOGI("CommonEventType: %{public}s, userId: %{public}d", commonEventType.c_str(), userId);
if (commonEventType == EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED) {
// swithed
MultiUserManager::GetInstance().SetCurrentForegroundUserID(userId);
} else if (commonEventType == EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGIN) {
} else if (commonEventType == EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGOUT) {
} else if (commonEventType == EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED) {
} else {
HILOGE("Invalied account common event.");
}
return;
}
int32_t DistributedDeviceProfileServiceNew::AddSvrProfilesToCache(const std::vector<ServiceProfile>& serviceProfiles)
{
if (serviceProfiles.empty()) {

View File

@ -16,8 +16,10 @@
#include "multi_user_manager.h"
#include "device_profile_manager.h"
#include "distributed_device_profile_constants.h"
#include "distributed_device_profile_errors.h"
#include "distributed_device_profile_log.h"
#include "profile_utils.h"
#include "account_info.h"
#include "ohos_account_kits.h"
@ -34,12 +36,12 @@ namespace {
int32_t MultiUserManager::Init()
{
HILOGI("Init");
int32_t foregroundId;
int32_t foregroundId = DEFAULT_USER_ID;
int32_t res = OHOS::AccountSA::OsAccountManager::GetForegroundOsAccountLocalId(foregroundId);
if (res != DP_SUCCESS) {
if (res != DP_SUCCESS || foregroundId == DEFAULT_USER_ID) {
HILOGD("GetForegroundId failed, res:%{public}d", res);
}
HILOGI("current foregroundId = %{public}d", foregroundId);
HILOGI("current foregroundId = %{public}s", ProfileUtils::GetAnonyInt32(foregroundId).c_str());
SetCurrentForegroundUserID(foregroundId);
return DP_SUCCESS;
@ -63,5 +65,17 @@ int32_t MultiUserManager::GetCurrentForegroundUserID()
return foregroundUserId_;
}
int32_t MultiUserManager::GetForegroundUserIDFromOs()
{
int32_t foregroundId = DEFAULT_USER_ID;
int32_t res = OHOS::AccountSA::OsAccountManager::GetForegroundOsAccountLocalId(foregroundId);
if (res != DP_SUCCESS || foregroundId == DEFAULT_USER_ID) {
HILOGD("GetForegroundId failed, res:%{public}d", res);
return DP_GET_FOREGROUND_ID_FAIL;
}
HILOGI("GetForegroundUserIDFromOs foregroundId = %{public}s", ProfileUtils::GetAnonyInt32(foregroundId).c_str());
return foregroundId;
}
} // namespace DistributedHardware
} // namespace OHOS

View File

@ -21,6 +21,7 @@
#include "common_event_support.h"
#include "distributed_device_profile_errors.h"
#include "distributed_device_profile_log.h"
#include "ffrt.h"
#include "iservice_registry.h"
#include "multi_user_manager.h"
#include "system_ability_definition.h"
@ -150,6 +151,7 @@ void DpAccountEventSubscriber::OnReceiveEvent(const CommonEventData &data)
HILOGE("Invalied account type event.");
return;
}
ffrt::submit([=]() { callback_(userId, receiveEvent); });
}
void DpAccountCommonEventManager::SystemAbilityStatusChangeListener::OnAddSystemAbility(
@ -168,14 +170,6 @@ void DpAccountCommonEventManager::SystemAbilityStatusChangeListener::OnAddSystem
if (!CommonEventManager::SubscribeCommonEvent(changeSubscriber_)) {
HILOGE("failed to subscribe account commom event: %{public}zu", eventNameVec.size());
}
// int32_t userId = MultipleUserConnector::GetCurrentAccountUserID();
// std::string accountId = MultipleUserConnector::GetOhosAccountId();
// HILOGI("after subscribe account event accountId: %{public}s, userId: %{public}s",
// GetAnonyString(accountId).c_str(), GetAnonyInt32(userId).c_str());
// if (userId > 0) {
// MultipleUserConnector::SetSwitchOldUserId(userId);
// MultipleUserConnector::SetSwitchOldAccountId(accountId);
// }
}
void DpAccountCommonEventManager::SystemAbilityStatusChangeListener::OnRemoveSystemAbility(

View File

@ -51,16 +51,6 @@ int32_t ProfileCache::Init()
HILOGW("GetTrustedDeviceList failed, res: %{public}d", res);
return DP_SUCCESS;
}
<<<<<<< HEAD
{
std::lock_guard<std::mutex> lock(foregroundIdMutex_);
foregroundId_ = GetForegroundId();
if (foregroundId_ == DP_GET_FOREGROUND_ID_FAIL) {
LOGE("GetForegroundId id failed, ForegroundId: %{public}d", foregroundId_);
}
}
=======
>>>>>>> 8f3393c (cache中不必要的代码)
std::string udid = EMPTY_STRING;
std::lock_guard<std::mutex> lock(onlineDeviceLock_);
@ -843,21 +833,5 @@ std::string ProfileCache::GetLocalUuid()
localUuid_ = localUuid;
return localUuid;
}
<<<<<<< HEAD
int32_t ProfileCache::GetForegroundId()
{
int32_t foregroundId;
int32_t res = OHOS::AccountSA::OsAccountManager::GetForegroundOsAccountLocalId(foregroundId);
if (res != DP_SUCCESS) {
LOGE("GetForegroundId failed, res:%{public}d", res);
return DP_GET_FOREGROUND_ID_FAIL;
}
LOGI("current foregroundId = %{public}d", foregroundId);
return foregroundId;
}
=======
>>>>>>> 8f3393c (cache中不必要的代码)
} // namespace DeviceProfile
} // namespace OHOS

View File

@ -51,19 +51,12 @@ class MockDistributedDeviceProfileStubNew : public DistributedDeviceProfileStubN
int32_t GetServiceProfile(const std::string& deviceId, const std::string& serviceName,
ServiceProfile& serviceProfile, bool isMultiUser = false, int32_t userId = DEFAULT_USER_ID) override;
int32_t GetCharacteristicProfile(const std::string& deviceId, const std::string& serviceName,
<<<<<<< HEAD
const std::string& characteristicId, CharacteristicProfile& charProfile) override;
int32_t DeleteServiceProfile(const std::string& deviceId, const std::string& serviceName) override;
int32_t DeleteCharacteristicProfile(const std::string& deviceId, const std::string& serviceName,
const std::string& characteristicId) override;
=======
const std::string& characteristicId, CharacteristicProfile& charProfile, bool isMultiUser = false,
int32_t userId = DEFAULT_USER_ID) override;
int32_t DeleteServiceProfile(const std::string& deviceId, const std::string& serviceName, bool isMultiUser = false,
int32_t userId = DEFAULT_USER_ID) override;
int32_t DeleteCharacteristicProfile(const std::string& deviceId, const std::string& serviceName,
const std::string& characteristicId, bool isMultiUser = false, int32_t userId = DEFAULT_USER_ID) override;
>>>>>>> 6cd545d ()
int32_t SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) override;
int32_t UnSubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) override;
int32_t SubscribeDeviceProfileInited(int32_t saId, sptr<IRemoteObject> dpInitedCallback) override;
@ -197,16 +190,6 @@ int32_t MockDistributedDeviceProfileStubNew::GetCharacteristicProfile(const std:
return 0;
}
int32_t MockDistributedDeviceProfileStubNew::DeleteServiceProfile(const std::string& deviceId,
<<<<<<< HEAD
const std::string& serviceName)
{
(void)deviceId;
(void)serviceName;
return 0;
}
int32_t MockDistributedDeviceProfileStubNew::DeleteCharacteristicProfile(const std::string& deviceId,
const std::string& serviceName, const std::string& characteristicId)
=======
const std::string& serviceName, bool isMultiUser, int32_t userId)
{
(void)deviceId;
@ -217,16 +200,12 @@ int32_t MockDistributedDeviceProfileStubNew::DeleteCharacteristicProfile(const s
}
int32_t MockDistributedDeviceProfileStubNew::DeleteCharacteristicProfile(const std::string& deviceId,
const std::string& serviceName, const std::string& characteristicId, bool isMultiUser, int32_t userId)
>>>>>>> 6cd545d ()
{
(void)deviceId;
(void)serviceName;
(void)characteristicId;
<<<<<<< HEAD
=======
(void)isMultiUser;
(void)userId;
>>>>>>> 6cd545d ()
return 0;
}
int32_t MockDistributedDeviceProfileStubNew::SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo)