add OnUserSwitched

Signed-off-by: dengxiaoyu <dengxiaoyu6@huawei.com>
This commit is contained in:
dengxiaoyu 2024-09-09 10:25:53 +08:00
parent 8dd6726bed
commit c21b65ab37
4 changed files with 13 additions and 8 deletions

View File

@ -31,7 +31,8 @@ public:
void OnReceiveEvent(const EventFwk::CommonEventData &eventData);
int32_t GetForegroundOsAccountLocalId();
void OnUserSwitched(int32_t &accountId);
int32_t GetOsAccountType(int32_t &accountId);
void OnUserSwitched();
};
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -42,8 +42,6 @@ private:
std::string GetSwitchStatus(const std::string &key, const std::string &defaultValue);
std::shared_ptr<DataShare::DataShareHelper> GetDataShareHelper();
std::mutex dataShareMutex_;
const std::string SETTINGS_DATA_URI_PREFIX =
"datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true";
std::string switchStatus_;
};
} // namespace DistributedSchedule

View File

@ -70,7 +70,7 @@ void CommonEventListener::OnReceiveEvent(const EventFwk::CommonEventData &eventD
break;
case USER_SWITCHED :
HILOGI("USER_SWITCHED");
GetForegroundOsAccountLocalId();
OnUserSwitched();
break;
case PACKAGE_ADDED :
HILOGI("PACKAGE_ADDED: %{public}s", want.GetElement().GetBundleName().c_str());
@ -98,17 +98,25 @@ int32_t CommonEventListener::GetForegroundOsAccountLocalId()
return INVALID_PARAMETERS_ERR;
}
HILOGD("GetForegroundOsAccountLocalId accountId is: %{public}d", accountId);
OnUserSwitched(accountId);
return accountId;
}
void CommonEventListener::OnUserSwitched(int32_t& accountId)
int32_t CommonEventListener::GetOsAccountType(int32_t& accountId)
{
AccountSA::OsAccountType type;
ErrCode err = AccountSA::OsAccountManager::GetOsAccountType(accountId, type);
if (err != ERR_OK) {
HILOGE("GetOsAccountType passing param invalid or return error!, err : %{public}d", err);
return INVALID_PARAMETERS_ERR;
}
return type;
}
void CommonEventListener::OnUserSwitched()
{
int32_t accountId = GetForegroundOsAccountLocalId();
AccountSA::OsAccountType type = GetOsAccountType(accountId);
HILOGI("OnUserSwitched called, accountId = %{public}d, type = %{public}d", accountId, type);
if (type == AccountSA::OsAccountType::PRIVATE) {
HILOGI("GetOsAccountType : OsAccountType is PRIVATE, type : %{public}d", type);
DataShareManager::GetInstance().UpdateSwitchStatus(SwitchStatusDependency::GetInstance()

View File

@ -29,8 +29,6 @@ namespace OHOS {
namespace DistributedSchedule {
namespace {
const std::string TAG = "DMSSwitchStatusDep";
const std::string SETTINGS_DATA_URI =
"datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=Continue_Switch_Status";
}
SwitchStatusDependency &SwitchStatusDependency::GetInstance()
{