mirror of
https://gitee.com/openharmony/deviceprofile_device_info_manager
synced 2024-11-23 07:30:13 +00:00
commit
0e593d4eee
@ -133,6 +133,8 @@ 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;
|
||||
constexpr int32_t MIN_USER_ID = 0;
|
||||
constexpr int32_t MAX_USER_ID = 100000;
|
||||
extern const std::string IS_MULTI_USER;
|
||||
extern const std::string SEPARATOR;
|
||||
extern const std::string DEV_PREFIX;
|
||||
|
@ -60,6 +60,7 @@ public:
|
||||
int32_t userId = DEFAULT_USER_ID);
|
||||
int32_t DeleteCharacteristicProfile(const std::string& deviceId, const std::string& serviceName,
|
||||
const std::string& characteristicKey, bool isMultiUser = false, int32_t userId = DEFAULT_USER_ID);
|
||||
int32_t DeleteRemovedUserData(int32_t userId);
|
||||
int32_t GetAllDeviceProfile(std::vector<DeviceProfile>& deviceProfiles);
|
||||
int32_t GetAllServiceProfile(std::vector<ServiceProfile>& serviceProfiles);
|
||||
int32_t GetAllCharacteristicProfile(std::vector<CharacteristicProfile>& charProfiles);
|
||||
|
@ -394,6 +394,43 @@ int32_t DeviceProfileManager::DeleteCharacteristicProfile(const std::string& dev
|
||||
return DP_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DeviceProfileManager::DeleteRemovedUserData(int32_t userId)
|
||||
{
|
||||
if (userId < MIN_USER_ID || userId > MAX_USER_ID) {
|
||||
HILOGE("Invalid userId: %{public}d", userId);
|
||||
return DP_INVALID_PARAM;
|
||||
}
|
||||
std::map<std::string, std::string> allLocalEntries;
|
||||
std::vector<std::string> keysToDelete;
|
||||
std::string localDeviceId = ProfileCache::GetInstance().GetLocalUdid();
|
||||
if (localDeviceId.empty()) {
|
||||
HILOGE("GetLocalUdid fail");
|
||||
return DP_GET_LOCAL_UDID_FAILED;
|
||||
}
|
||||
int32_t getRet = GetProfilesByKeyPrefix(localDeviceId, allLocalEntries);
|
||||
if (getRet != DP_SUCCESS) {
|
||||
HILOGE("GetLocalProfile fail,deviceId: %{public}s,reason: %{public}d!",
|
||||
ProfileUtils::GetAnonyString(localDeviceId).c_str(), getRet);
|
||||
return getRet;
|
||||
}
|
||||
for (const auto& pair : allLocalEntries) {
|
||||
if (userId == ProfileUtils::GetUserIdFromDbKey(pair.first)) {
|
||||
keysToDelete.emplace_back(pair.first);
|
||||
}
|
||||
}
|
||||
if (keysToDelete.empty()) {
|
||||
HILOGI("userId:%{public}d has no multi-user data.", userId);
|
||||
return DP_SUCCESS;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(dynamicStoreMutex_);
|
||||
int32_t delRet = deviceProfileStore_->DeleteBatch(keysToDelete);
|
||||
if (delRet != DP_SUCCESS) {
|
||||
HILOGE("DeleteBatch fail, reason: %{public}d!", delRet);
|
||||
return delRet;
|
||||
}
|
||||
return DP_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DeviceProfileManager::GetAllDeviceProfile(std::vector<DeviceProfile>& deviceProfiles)
|
||||
{
|
||||
HILOGD("call!");
|
||||
|
@ -640,8 +640,6 @@ void DistributedDeviceProfileServiceNew::SubscribeAccountCommonEvent()
|
||||
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);
|
||||
std::lock_guard<std::mutex> lock(accountCommonEventManagerMtx_);
|
||||
if (accountCommonEventManager_->SubscribeAccountCommonEvent(AccountCommonEventVec, callback)) {
|
||||
HILOGI("Success");
|
||||
@ -655,9 +653,18 @@ void DistributedDeviceProfileServiceNew::AccountCommonEventCallback(int32_t user
|
||||
if (commonEventType == EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED) {
|
||||
// swithed
|
||||
MultiUserManager::GetInstance().SetCurrentForegroundUserID(userId);
|
||||
} else {
|
||||
HILOGE("Invalied account common event.");
|
||||
return;
|
||||
}
|
||||
if (commonEventType == EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED) {
|
||||
// removed
|
||||
if (DeviceProfileManager::GetInstance().DeleteRemovedUserData(userId) != DP_SUCCESS) {
|
||||
HILOGE("DeleteRemovedUserData failed,userId=%{public}d", userId);
|
||||
} else {
|
||||
HILOGI("DeleteRemovedUserData succeed,userId=%{public}d", userId);
|
||||
}
|
||||
return;
|
||||
}
|
||||
HILOGE("Invalied account common event.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -142,11 +142,6 @@ void DpAccountEventSubscriber::OnReceiveEvent(const CommonEventData &data)
|
||||
userId = data.GetCode();
|
||||
isValidEvent = true;
|
||||
}
|
||||
if (receiveEvent == EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGOUT ||
|
||||
receiveEvent == EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGIN) {
|
||||
userId = data.GetWant().GetIntParam("userId", 0);
|
||||
isValidEvent = true;
|
||||
}
|
||||
if (userId <= 0 || !isValidEvent) {
|
||||
HILOGE("Invalid account type event.");
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user