diff --git a/service/account_manager/include/account_manager.h b/service/account_manager/include/account_manager.h index 550ce456a5f8cd64daa81a175dbe6bdf0556acf3..32a9e818f192e4317812529d12efc393d10e4be8 100644 --- a/service/account_manager/include/account_manager.h +++ b/service/account_manager/include/account_manager.h @@ -69,6 +69,7 @@ public: }; static std::shared_ptr GetInstance(); + int32_t GetCurrentAccountId(); AccountManager(); ~AccountManager(); @@ -119,6 +120,11 @@ inline int32_t AccountManager::AccountSetting::GetAccShortcutTimeout() const return accShortcutTimeout_; } +inline int32_t AccountManager::GetCurrentAccountId() +{ + return currentAccountId_; +} + #define ACCOUNT_MGR ::OHOS::MMI::AccountManager::GetInstance() } // namespace MMI } // namespace OHOS diff --git a/service/account_manager/src/account_manager.cpp b/service/account_manager/src/account_manager.cpp index 508308f27c56037fd04d7e5b97767a7ac49f5a38..c2223133d43d58149565f066453fa8e88d3a82c0 100644 --- a/service/account_manager/src/account_manager.cpp +++ b/service/account_manager/src/account_manager.cpp @@ -14,6 +14,7 @@ */ #include "account_manager.h" +#include "i_preference_manager.h" #ifdef SCREENLOCK_MANAGER_ENABLED #include @@ -412,6 +413,8 @@ void AccountManager::SetupMainAccount() if (!isNew) { MMI_HILOGW("Account(%{public}d) has existed", MAIN_ACCOUNT_ID); } + PREFERENCES_MGR->MainUserHandler(currentAccountId_); + MMI_HILOGI("Setup main account(%{public}d)", currentAccountId_); } void AccountManager::OnCommonEvent(const EventFwk::CommonEventData &data) @@ -434,6 +437,7 @@ void AccountManager::OnAddUser(const EventFwk::CommonEventData &data) if (!isNew) { MMI_HILOGW("Account(%d) has existed", accountId); } + PREFERENCES_MGR->AddUserHandler(accountId); } void AccountManager::OnRemoveUser(const EventFwk::CommonEventData &data) @@ -446,6 +450,7 @@ void AccountManager::OnRemoveUser(const EventFwk::CommonEventData &data) } else { MMI_HILOGW("No account(%d)", accountId); } + PREFERENCES_MGR->RemoveUserHandler(accountId); } void AccountManager::OnSwitchUser(const EventFwk::CommonEventData &data) @@ -459,6 +464,7 @@ void AccountManager::OnSwitchUser(const EventFwk::CommonEventData &data) currentAccountId_ = accountId; MMI_HILOGI("Switched to account(%d)", currentAccountId_); } + PREFERENCES_MGR->SwitchUserHandler(currentAccountId_); } } // namespace MMI } // namespace OHOS diff --git a/service/module_loader/include/i_preference_manager.h b/service/module_loader/include/i_preference_manager.h index ac2422317deeefaf0b6d5ba356da0d4d3c0c2b1e..86441ed3fda9068678753de10f701fe91dd6a9d5 100644 --- a/service/module_loader/include/i_preference_manager.h +++ b/service/module_loader/include/i_preference_manager.h @@ -34,6 +34,10 @@ public: virtual int32_t GetShortKeyDuration(const std::string &key) = 0; virtual int32_t SetShortKeyDuration(const std::string &key, int32_t setValue) = 0; virtual bool IsInitPreference() = 0; + virtual void AddUserHandler(int32_t userId) = 0; + virtual void RemoveUserHandler(int32_t userId) = 0; + virtual void SwitchUserHandler(int32_t userId) = 0; + virtual void MainUserHandler(int32_t& userId) = 0; static std::shared_ptr GetInstance(); diff --git a/service/module_loader/include/multimodal_input_preferences_manager.h b/service/module_loader/include/multimodal_input_preferences_manager.h index 486860d76f8bff3fb55cfe3f840baba5ff150c63..96199d99a5ba70dc0d13a6b4decdf653d95d37f4 100644 --- a/service/module_loader/include/multimodal_input_preferences_manager.h +++ b/service/module_loader/include/multimodal_input_preferences_manager.h @@ -40,9 +40,16 @@ public: int32_t SetShortKeyDuration(const std::string &key, int32_t setValue); bool IsInitPreference(); + void AddUserHandler(int32_t userId); + void RemoveUserHandler(int32_t userId); + void SwitchUserHandler(int32_t userId); + void MainUserHandler(int32_t& userId); + private: std::map> preferencesMap_; + std::map multiuserPreferencesMap_; std::map shortcutKeyMap_; + bool isEnableFlag_ { false }; int32_t keyboardRepeatRate_ { 50 }; int32_t keyboardRepeatDelay_ { 500 }; int32_t mouseScrollRows_ { 3 }; @@ -66,6 +73,8 @@ private: int32_t pointerSize_ { 1 }; int32_t pointerStyle_ { 0 }; int32_t touchpadScrollRows_ { 3 }; + const std::string strLastMainUserId_ = { "lastMainUserId" }; + const std::string strIsEnableFlag_ = { "isEnableFlag" }; const std::string strKeyboardRepeatRate_ = "keyboardRepeatRate"; const std::string strKeyboardRepeatDelay_ = "keyboardRepeatDelay"; const std::string strMouseScrollRows_ = "rows"; @@ -94,6 +103,19 @@ private: const std::string strMagicPointerColor_ = "magicPointerColor"; const std::string strMagicPointerSize_ = "magicPointerSize"; #endif // OHOS_BUILD_ENABLE_MAGICCURSOR + + void SetDefaultValues(); + void GetPreferencesByXml(); + void UpdateMultiuserPreferencesMap(); + void PutPreferencesToDataShare(int32_t userId); + void GetPreferencesByDataShare(int32_t userId); + int32_t GetIntValueByXml(const std::string &key, int32_t defaultValue); + bool GetBoolValueByXml(const std::string &key, bool defaultValue); + void GetIntValueByDataShare(int32_t userId, const std::string& key, int32_t& value, int32_t defaultValue); + void GetBoolValueByDataShare(int32_t userId, const std::string& key, bool& value, bool defaultValue); + void PutIntValueToDataShare(int32_t userId, const std::string& key, int32_t value); + void PutBoolValueToDataShare(int32_t userId, const std::string& key, bool value); + void TimerCallback(int32_t& timerId, int32_t userId); }; } // namespace MMI } // namespace OHOS diff --git a/service/module_loader/src/multimodal_input_preferences_manager.cpp b/service/module_loader/src/multimodal_input_preferences_manager.cpp index ef0cddf44dd99a28ab136d86ae69072a50e073c8..b5c69716153cbaf64c82f83c0342137e272c2af8 100644 --- a/service/module_loader/src/multimodal_input_preferences_manager.cpp +++ b/service/module_loader/src/multimodal_input_preferences_manager.cpp @@ -14,9 +14,15 @@ */ #include "multimodal_input_preferences_manager.h" +#include +#include +#include "account_manager.h" #include "mmi_log.h" +#include "i_pointer_drawing_manager.h" #include "param_wrapper.h" +#include "setting_datashare.h" +#include "timer_manager.h" #undef MMI_LOG_DOMAIN #define MMI_LOG_DOMAIN MMI_LOG_SERVER @@ -26,6 +32,11 @@ namespace OHOS { namespace MMI { namespace { +constexpr int32_t REPEAT_ONCE { 1 }; +constexpr int32_t MAIN_ACCOUNT_ID { 100 }; +constexpr int32_t PUT_PREFERENCES_TIME { 100 }; +constexpr size_t DEFAULT_BUFFER_LENGTH { 512 }; +constexpr bool IS_ENABLE_FLAG { false }; constexpr int32_t KEYBOARD_REPEATRATE { 50 }; constexpr int32_t KEYBOARD_REPEATDELAY { 500 }; constexpr int32_t MOUSE_SCROLL_ROWS { 3 }; @@ -48,6 +59,8 @@ const std::string MOUSE_FILE_NAME { "mouse_settings.xml" }; const std::string KEYBOARD_FILE_NAME { "keyboard_settings.xml" }; const std::string TOUCHPAD_FILE_NAME { "touchpad_settings.xml" }; const std::string DEFAULT_MOUSE_SPEED_NAME { "const.multimodalinput.default_mouse_speed" }; +const std::string SECURE_SETTING_URI_PROXY { + "datashare:///com.ohos.settingsdata/entry/settingsdata/USER_SETTINGSDATA_SECURE_%d?Proxy=true" }; } // namespace std::shared_ptr IPreferenceManager::instance_; @@ -166,93 +179,75 @@ int32_t MultiModalInputPreferencesManager::InitPreferencesMap() int32_t MultiModalInputPreferencesManager::GetIntValue(const std::string &key, int32_t defaultValue) { - auto iter = preferencesMap_.find(key); - if (iter == preferencesMap_.end()) { + auto iter = multiuserPreferencesMap_.find(key); + if (iter == multiuserPreferencesMap_.end()) { return defaultValue; } - auto [fileName, value] = iter->second; - return value; + return iter->second; } bool MultiModalInputPreferencesManager::GetBoolValue(const std::string &key, bool defaultValue) { - auto iter = preferencesMap_.find(key); - if (iter == preferencesMap_.end()) { + auto iter = multiuserPreferencesMap_.find(key); + if (iter == multiuserPreferencesMap_.end()) { return defaultValue; } - auto [fileName, value] = iter->second; - return static_cast(value); + return static_cast(iter->second); } int32_t MultiModalInputPreferencesManager::SetIntValue(const std::string &key, const std::string &setFile, int32_t setValue) { - auto iter = preferencesMap_.find(key); - std::string filePath = ""; - if (iter == preferencesMap_.end()) { - preferencesMap_[key] = {setFile, setValue}; - filePath = PATH + setFile; + auto iter = multiuserPreferencesMap_.find(key); + if (iter == multiuserPreferencesMap_.end()) { + MMI_HILOGE("key(%{public}s) is invalid", key.c_str()); + return RET_ERR; } else { - auto [fileName, value] = iter->second; - if (value == setValue) { + if (iter->second == setValue) { MMI_HILOGD("The set value is same"); return RET_OK; } - filePath = PATH + fileName; - preferencesMap_[key].second = setValue; } - - int32_t errCode = RET_OK; - std::shared_ptr pref = - NativePreferences::PreferencesHelper::GetPreferences(filePath, errCode); - CHKPR(pref, errno); - int32_t ret = pref->PutInt(key, setValue); - if (ret != RET_OK) { - MMI_HILOGE("Put value is failed, ret:%{public}d", ret); + char buf[DEFAULT_BUFFER_LENGTH] {}; + if (sprintf_s(buf, sizeof(buf), SECURE_SETTING_URI_PROXY.c_str(), ACCOUNT_MGR->GetCurrentAccountId()) < 0) { + MMI_HILOGE("Failed to format URI"); return RET_ERR; } - ret = pref->FlushSync(); + auto ret = SettingDataShare::GetInstance(MULTIMODAL_INPUT_SERVICE_ID).PutIntValue( + key, setValue, false, std::string(buf)); if (ret != RET_OK) { - MMI_HILOGE("Flush sync is failed, ret:%{public}d", ret); + MMI_HILOGE("[AccountSetting] Failed to acquire '%{public}s', error:%{public}d", key.c_str(), ret); return RET_ERR; } - NativePreferences::PreferencesHelper::RemovePreferencesFromCache(filePath); + multiuserPreferencesMap_[key] = setValue; return RET_OK; } int32_t MultiModalInputPreferencesManager::SetBoolValue(const std::string &key, const std::string &setFile, bool setValue) { - auto iter = preferencesMap_.find(key); - std::string filePath = ""; - if (iter == preferencesMap_.end()) { - preferencesMap_[key] = {setFile, static_cast(setValue)}; - filePath = PATH + setFile; + auto iter = multiuserPreferencesMap_.find(key); + if (iter == multiuserPreferencesMap_.end()) { + MMI_HILOGE("key(%{public}s) is invalid", key.c_str()); + return RET_ERR; } else { - auto [fileName, value] = iter->second; - if (static_cast(value) == setValue) { + if (iter->second == setValue) { MMI_HILOGD("The set value is same"); return RET_OK; } - filePath = PATH + fileName; - preferencesMap_[key].second = setValue; } - - int32_t errCode = RET_OK; - std::shared_ptr pref = - NativePreferences::PreferencesHelper::GetPreferences(filePath, errCode); - CHKPR(pref, errno); - int32_t ret = pref->PutBool(key, setValue); - if (ret != RET_OK) { - MMI_HILOGE("Put value is failed, ret:%{public}d", ret); + char buf[DEFAULT_BUFFER_LENGTH] {}; + if (sprintf_s(buf, sizeof(buf), SECURE_SETTING_URI_PROXY.c_str(), ACCOUNT_MGR->GetCurrentAccountId()) < 0) { + MMI_HILOGE("Failed to format URI"); return RET_ERR; } - ret = pref->FlushSync(); + auto ret = SettingDataShare::GetInstance(MULTIMODAL_INPUT_SERVICE_ID).PutBoolValue( + key, setValue, false, std::string(buf)); if (ret != RET_OK) { - MMI_HILOGE("Flush sync is failed, ret:%{public}d", ret); + MMI_HILOGE("[AccountSetting] Failed to acquire '%{public}s', error:%{public}d", key.c_str(), ret); return RET_ERR; } - NativePreferences::PreferencesHelper::RemovePreferencesFromCache(filePath); + multiuserPreferencesMap_[key] = static_cast(setValue); return RET_OK; } @@ -297,5 +292,295 @@ int32_t MultiModalInputPreferencesManager::SetShortKeyDuration(const std::string NativePreferences::PreferencesHelper::RemovePreferencesFromCache(PATH + SHORT_KEY_FILE_NAME); return RET_OK; } + +int32_t MultiModalInputPreferencesManager::GetIntValueByXml(const std::string &key, int32_t defaultValue) +{ + auto iter = preferencesMap_.find(key); + if (iter == preferencesMap_.end()) { + return defaultValue; + } + auto [fileName, value] = iter->second; + return value; +} + +bool MultiModalInputPreferencesManager::GetBoolValueByXml(const std::string &key, bool defaultValue) +{ + auto iter = preferencesMap_.find(key); + if (iter == preferencesMap_.end()) { + return defaultValue; + } + auto [fileName, value] = iter->second; + return static_cast(value); +} + +void MultiModalInputPreferencesManager::GetPreferencesByXml() +{ + keyboardRepeatRate_ = GetIntValueByXml(strKeyboardRepeatRate_, KEYBOARD_REPEATRATE); + keyboardRepeatDelay_ = GetIntValueByXml(strKeyboardRepeatDelay_, KEYBOARD_REPEATDELAY); + mouseScrollRows_ = GetIntValueByXml(strMouseScrollRows_, MOUSE_SCROLL_ROWS); + mousePrimaryButton_ = GetIntValueByXml(strMousePrimaryButton_, PRIMARY_BUTTON); + pointerSpeed_ = GetIntValueByXml(strPointerSpeed_, POINTER_SPEED); + touchpadRightClickType_ = GetIntValueByXml(strTouchpadRightClickType_, RIGHT_CLICK_TYPE); + touchpadPointerSpeed_ = GetIntValueByXml(strTouchpadPointerSpeed_, TOUCHPAD_POINTER_SPEED); + touchpadTapSwitch_ = GetBoolValueByXml(strTouchpadTapSwitch_, BOOL_DEFAULT); + touchpadDoubleTapAndDrag_ = GetBoolValueByXml(strTouchpadDoubleTapAndDrag_, BOOL_DEFAULT); + touchpadScrollDirection_ = GetBoolValueByXml(strTouchpadScrollDirection_, BOOL_DEFAULT); + touchpadScrollSwitch_ = GetBoolValueByXml(strTouchpadScrollSwitch_, BOOL_DEFAULT); + touchpadPinchSwitch_ = GetBoolValueByXml(strTouchpadPinchSwitch_, BOOL_DEFAULT); + touchpadSwipeSwitch_ = GetBoolValueByXml(strTouchpadSwipeSwitch_, BOOL_DEFAULT); + hoverScrollState_ = GetBoolValueByXml(strHoverScrollState_, BOOL_DEFAULT); +#ifdef OHOS_BUILD_ENABLE_MOVE_EVENT_FILTERS + moveEventFilterFlag_ = GetBoolValueByXml(strMoveEventFilterFlag_, BOOL_DEFAULT); +#endif // OHOS_BUILD_ENABLE_MOVE_EVENT_FILTERS + touchpadThreeFingerTapSwitch_ = GetBoolValueByXml(strTouchpadThreeFingerTapSwitch_, BOOL_DEFAULT); + pointerColor_ = GetIntValueByXml(strPointerColor_, POINTER_COLOR); + pointerSize_ = GetIntValueByXml(strPointerSize_, POINTER_SIZE); + pointerStyle_ = GetIntValueByXml(strPointerStyle_, POINTER_STYLE); + touchpadScrollRows_ = GetIntValueByXml(strTouchpadScrollRows_, TOUCHPAD_SCROLL_ROWS); +#ifdef OHOS_BUILD_ENABLE_MAGICCURSOR + magicPointerColor_ = GetIntValueByXml(strMagicPointerColor_, POINTER_COLOR); + magicPointerSize_ = GetIntValueByXml(strMagicPointerSize_, MAGIC_POINTER_SIZE); +#endif // OHOS_BUILD_ENABLE_MAGICCURSOR +} + +void MultiModalInputPreferencesManager::PutIntValueToDataShare(int32_t userId, const std::string& key, int32_t value) +{ + char buf[DEFAULT_BUFFER_LENGTH] {}; + if (sprintf_s(buf, sizeof(buf), SECURE_SETTING_URI_PROXY.c_str(), userId) < 0) { + MMI_HILOGE("Failed to format URI"); + return; + } + auto ret = SettingDataShare::GetInstance(MULTIMODAL_INPUT_SERVICE_ID).PutIntValue( + key, value, false, std::string(buf)); + if (ret != RET_OK) { + MMI_HILOGE("[AccountSetting] Failed to acquire '%{public}s', error:%{public}d", key.c_str(), ret); + } +} + +void MultiModalInputPreferencesManager::PutBoolValueToDataShare(int32_t userId, const std::string& key, bool value) +{ + char buf[DEFAULT_BUFFER_LENGTH] {}; + if (sprintf_s(buf, sizeof(buf), SECURE_SETTING_URI_PROXY.c_str(), userId) < 0) { + MMI_HILOGE("Failed to format URI"); + return; + } + auto ret = SettingDataShare::GetInstance(MULTIMODAL_INPUT_SERVICE_ID).PutBoolValue( + key, value, false, std::string(buf)); + if (ret != RET_OK) { + MMI_HILOGE("[AccountSetting] Failed to acquire '%{public}s', error:%{public}d", key.c_str(), ret); + } +} + +void MultiModalInputPreferencesManager::SetDefaultValues() +{ + keyboardRepeatRate_ = KEYBOARD_REPEATRATE; + keyboardRepeatDelay_ = KEYBOARD_REPEATDELAY; + mouseScrollRows_ = MOUSE_SCROLL_ROWS; + mousePrimaryButton_ = PRIMARY_BUTTON; + pointerSpeed_ = POINTER_SPEED; + touchpadRightClickType_ = RIGHT_CLICK_TYPE; + touchpadPointerSpeed_ = TOUCHPAD_POINTER_SPEED; + touchpadTapSwitch_ = BOOL_DEFAULT; + touchpadDoubleTapAndDrag_ = BOOL_DEFAULT; + touchpadScrollDirection_ = BOOL_DEFAULT; + touchpadScrollSwitch_ = BOOL_DEFAULT; + touchpadPinchSwitch_ = BOOL_DEFAULT; + touchpadSwipeSwitch_ = BOOL_DEFAULT; + hoverScrollState_ = BOOL_DEFAULT; +#ifdef OHOS_BUILD_ENABLE_MOVE_EVENT_FILTERS + moveEventFilterFlag_ = BOOL_DEFAULT; +#endif // OHOS_BUILD_ENABLE_MOVE_EVENT_FILTERS + touchpadThreeFingerTapSwitch_ = BOOL_DEFAULT; + pointerColor_ = POINTER_COLOR; + pointerSize_ = POINTER_SIZE; + pointerStyle_ = POINTER_STYLE; + touchpadScrollRows_ = TOUCHPAD_SCROLL_ROWS; +#ifdef OHOS_BUILD_ENABLE_MAGICCURSOR + magicPointerColor_ = POINTER_COLOR; + magicPointerSize_ = MAGIC_POINTER_SIZE; +#endif // OHOS_BUILD_ENABLE_MAGICCURSOR +} + +void MultiModalInputPreferencesManager::PutPreferencesToDataShare(int32_t userId) +{ + PutBoolValueToDataShare(userId, strIsEnableFlag_, isEnableFlag_); + PutIntValueToDataShare(userId, strKeyboardRepeatRate_, keyboardRepeatRate_); + PutIntValueToDataShare(userId, strKeyboardRepeatDelay_, keyboardRepeatDelay_); + PutIntValueToDataShare(userId, strMouseScrollRows_, mouseScrollRows_); + PutIntValueToDataShare(userId, strMousePrimaryButton_, mousePrimaryButton_); + PutIntValueToDataShare(userId, strPointerSpeed_, pointerSpeed_); + PutIntValueToDataShare(userId, strTouchpadRightClickType_, touchpadRightClickType_); + PutIntValueToDataShare(userId, strTouchpadPointerSpeed_, touchpadPointerSpeed_); + PutBoolValueToDataShare(userId, strTouchpadTapSwitch_, touchpadTapSwitch_); + PutBoolValueToDataShare(userId, strTouchpadScrollDirection_, touchpadScrollDirection_); + PutBoolValueToDataShare(userId, strTouchpadScrollSwitch_, touchpadScrollSwitch_); + PutBoolValueToDataShare(userId, strTouchpadPinchSwitch_, touchpadPinchSwitch_); + PutBoolValueToDataShare(userId, strTouchpadSwipeSwitch_, touchpadSwipeSwitch_); + PutBoolValueToDataShare(userId, strHoverScrollState_, hoverScrollState_); +#ifdef OHOS_BUILD_ENABLE_MOVE_EVENT_FILTERS + PutBoolValueToDataShare(userId, strMoveEventFilterFlag_, moveEventFilterFlag_); +#endif + PutIntValueToDataShare(userId, strPointerColor_, pointerColor_); + PutIntValueToDataShare(userId, strPointerSize_, pointerSize_); + PutIntValueToDataShare(userId, strPointerStyle_, pointerStyle_); + PutBoolValueToDataShare(userId, strTouchpadThreeFingerTapSwitch_, touchpadThreeFingerTapSwitch_); + PutBoolValueToDataShare(userId, strTouchpadDoubleTapAndDrag_, touchpadDoubleTapAndDrag_); + PutIntValueToDataShare(userId, strTouchpadScrollRows_, touchpadScrollRows_); +#ifdef OHOS_BUILD_ENABLE_MAGICCURSOR + PutIntValueToDataShare(userId, strMagicPointerColor_, magicPointerColor_); + PutIntValueToDataShare(userId, strMagicPointerSize_, magicPointerSize_); +#endif +} + +void MultiModalInputPreferencesManager::GetIntValueByDataShare(int32_t userId, const std::string& key, + int32_t& value, int32_t defaultValue) +{ + char buf[DEFAULT_BUFFER_LENGTH] {}; + if (sprintf_s(buf, sizeof(buf), SECURE_SETTING_URI_PROXY.c_str(), userId) < 0) { + MMI_HILOGE("Failed to format URI"); + value = defaultValue; + return; + } + auto ret = SettingDataShare::GetInstance(MULTIMODAL_INPUT_SERVICE_ID).GetIntValue(key, value, std::string(buf)); + if (ret != RET_OK) { + value = defaultValue; + MMI_HILOGE("[AccountSetting] Failed to acquire '%{public}s', error:%{public}d", key.c_str(), ret); + } +} + +void MultiModalInputPreferencesManager::GetBoolValueByDataShare(int32_t userId, const std::string& key, + bool& value, bool defaultValue) +{ + char buf[DEFAULT_BUFFER_LENGTH] {}; + if (sprintf_s(buf, sizeof(buf), SECURE_SETTING_URI_PROXY.c_str(), userId) < 0) { + MMI_HILOGE("Failed to format URI"); + value = defaultValue; + return; + } + auto ret = SettingDataShare::GetInstance(MULTIMODAL_INPUT_SERVICE_ID).GetBoolValue(key, value, std::string(buf)); + if (ret != RET_OK) { + value = defaultValue; + MMI_HILOGE("[AccountSetting] Failed to acquire '%{public}s', error:%{public}d", key.c_str(), ret); + } +} + +void MultiModalInputPreferencesManager::GetPreferencesByDataShare(int32_t userId) +{ + GetIntValueByDataShare(userId, strKeyboardRepeatRate_, keyboardRepeatRate_, KEYBOARD_REPEATRATE); + GetIntValueByDataShare(userId, strKeyboardRepeatDelay_, keyboardRepeatDelay_, KEYBOARD_REPEATDELAY); + GetIntValueByDataShare(userId, strMouseScrollRows_, mouseScrollRows_, MOUSE_SCROLL_ROWS); + GetIntValueByDataShare(userId, strMousePrimaryButton_, mousePrimaryButton_, PRIMARY_BUTTON); + GetIntValueByDataShare(userId, strPointerSpeed_, pointerSpeed_, POINTER_SPEED); + GetIntValueByDataShare(userId, strTouchpadRightClickType_, touchpadRightClickType_, RIGHT_CLICK_TYPE); + GetIntValueByDataShare(userId, strTouchpadPointerSpeed_, touchpadPointerSpeed_, TOUCHPAD_POINTER_SPEED); + GetBoolValueByDataShare(userId, strTouchpadTapSwitch_, touchpadTapSwitch_, BOOL_DEFAULT); + GetBoolValueByDataShare(userId, strTouchpadDoubleTapAndDrag_, touchpadDoubleTapAndDrag_, BOOL_DEFAULT); + GetBoolValueByDataShare(userId, strTouchpadScrollDirection_, touchpadScrollDirection_, BOOL_DEFAULT); + GetBoolValueByDataShare(userId, strTouchpadScrollSwitch_, touchpadScrollSwitch_, BOOL_DEFAULT); + GetBoolValueByDataShare(userId, strTouchpadPinchSwitch_, touchpadPinchSwitch_, BOOL_DEFAULT); + GetBoolValueByDataShare(userId, strTouchpadSwipeSwitch_, touchpadSwipeSwitch_, BOOL_DEFAULT); + GetBoolValueByDataShare(userId, strHoverScrollState_, hoverScrollState_, BOOL_DEFAULT); +#ifdef OHOS_BUILD_ENABLE_MOVE_EVENT_FILTERS + GetBoolValueByDataShare(userId, strMoveEventFilterFlag_, moveEventFilterFlag_, BOOL_DEFAULT); +#endif + GetBoolValueByDataShare(userId, strTouchpadThreeFingerTapSwitch_, touchpadThreeFingerTapSwitch_, BOOL_DEFAULT); + GetIntValueByDataShare(userId, strPointerColor_, pointerColor_, POINTER_COLOR); + GetIntValueByDataShare(userId, strPointerSize_, pointerSize_, POINTER_SIZE); + GetIntValueByDataShare(userId, strPointerStyle_, pointerStyle_, POINTER_STYLE); + GetIntValueByDataShare(userId, strTouchpadScrollRows_, touchpadScrollRows_, TOUCHPAD_SCROLL_ROWS); +#ifdef OHOS_BUILD_ENABLE_MAGICCURSOR + GetIntValueByDataShare(userId, strMagicPointerColor_, magicPointerColor_, POINTER_COLOR); + GetIntValueByDataShare(userId, strMagicPointerSize_, magicPointerSize_, MAGIC_POINTER_SIZE); +#endif +} + +void MultiModalInputPreferencesManager::UpdateMultiuserPreferencesMap() +{ + multiuserPreferencesMap_[strKeyboardRepeatRate_] = keyboardRepeatRate_; + multiuserPreferencesMap_[strKeyboardRepeatDelay_] = keyboardRepeatDelay_; + multiuserPreferencesMap_[strMouseScrollRows_] = mouseScrollRows_; + multiuserPreferencesMap_[strMousePrimaryButton_] = mousePrimaryButton_; + multiuserPreferencesMap_[strPointerSpeed_] = pointerSpeed_; + multiuserPreferencesMap_[strTouchpadRightClickType_] = touchpadRightClickType_; + multiuserPreferencesMap_[strTouchpadPointerSpeed_] = touchpadPointerSpeed_; + multiuserPreferencesMap_[strTouchpadTapSwitch_] = static_cast(touchpadTapSwitch_); + multiuserPreferencesMap_[strTouchpadDoubleTapAndDrag_] = static_cast(touchpadDoubleTapAndDrag_); + multiuserPreferencesMap_[strTouchpadScrollDirection_] = static_cast(touchpadScrollDirection_); + multiuserPreferencesMap_[strTouchpadScrollSwitch_] = static_cast(touchpadScrollSwitch_); + multiuserPreferencesMap_[strTouchpadPinchSwitch_] = static_cast(touchpadPinchSwitch_); + multiuserPreferencesMap_[strTouchpadSwipeSwitch_] = static_cast(touchpadSwipeSwitch_); + multiuserPreferencesMap_[strHoverScrollState_] = static_cast(hoverScrollState_); +#ifdef OHOS_BUILD_ENABLE_MOVE_EVENT_FILTERS + + multiuserPreferencesMap_[strMoveEventFilterFlag_] = static_cast(moveEventFilterFlag_); +#endif + multiuserPreferencesMap_[strTouchpadThreeFingerTapSwitch_] = static_cast(touchpadThreeFingerTapSwitch_); + multiuserPreferencesMap_[strPointerColor_] = pointerColor_; + multiuserPreferencesMap_[strPointerSize_] = pointerSize_; + multiuserPreferencesMap_[strPointerStyle_] = pointerStyle_; + multiuserPreferencesMap_[strTouchpadScrollRows_] = touchpadScrollRows_; +#ifdef OHOS_BUILD_ENABLE_MAGICCURSOR + multiuserPreferencesMap_[strMagicPointerColor_] = magicPointerColor_; + multiuserPreferencesMap_[strMagicPointerSize_] = magicPointerSize_; +#endif +} + +void MultiModalInputPreferencesManager::SwitchUserHandler(int32_t userId) +{ + GetBoolValueByDataShare(userId, strIsEnableFlag_, isEnableFlag_, IS_ENABLE_FLAG); + if (!isEnableFlag_) { + GetPreferencesByXml(); + isEnableFlag_ = true; + PutPreferencesToDataShare(userId); + } else { + GetPreferencesByDataShare(userId); + } + UpdateMultiuserPreferencesMap(); + PutIntValueToDataShare(MAIN_ACCOUNT_ID, strLastMainUserId_, userId); + IPointerDrawingManager::GetInstance()->PreferencesUpdateMouseStyle(); +} + +void MultiModalInputPreferencesManager::MainUserHandler(int32_t& userId) +{ + GetBoolValueByDataShare(userId, strIsEnableFlag_, isEnableFlag_, IS_ENABLE_FLAG); + if (!isEnableFlag_) { + GetPreferencesByXml(); + isEnableFlag_ = true; + PutPreferencesToDataShare(userId); + PutIntValueToDataShare(MAIN_ACCOUNT_ID, strLastMainUserId_, userId); + } else { + GetIntValueByDataShare(MAIN_ACCOUNT_ID, strLastMainUserId_, userId, MAIN_ACCOUNT_ID); + GetPreferencesByDataShare(userId); + } + UpdateMultiuserPreferencesMap(); +} + +void MultiModalInputPreferencesManager::TimerCallback(int32_t& timerId, int32_t userId) +{ + PutPreferencesToDataShare(userId); + if (timerId >= 0) { + TimerMgr->RemoveTimer(timerId); + timerId = -1; + } +} + +void MultiModalInputPreferencesManager::AddUserHandler(int32_t userId) +{ + SetDefaultValues(); + isEnableFlag_ = true; + int32_t timerId_ = TimerMgr->AddTimer(PUT_PREFERENCES_TIME, REPEAT_ONCE, [this, &timerId_, userId]() { + TimerCallback(timerId_, userId); + }); +} + +void MultiModalInputPreferencesManager::RemoveUserHandler(int32_t userId) +{ + GetBoolValueByDataShare(userId, strIsEnableFlag_, isEnableFlag_, IS_ENABLE_FLAG); + if (isEnableFlag_ == true) { + SetDefaultValues(); + isEnableFlag_ = false; + PutPreferencesToDataShare(userId); + } +} } // namespace MMI } // namespace OHOS \ No newline at end of file diff --git a/service/window_manager/include/i_pointer_drawing_manager.h b/service/window_manager/include/i_pointer_drawing_manager.h index c8b4489ee7eee7893e4b280dd7e227f9678755a5..d4294e9194f9a96022cb60c456af84e90d4c2b5c 100644 --- a/service/window_manager/include/i_pointer_drawing_manager.h +++ b/service/window_manager/include/i_pointer_drawing_manager.h @@ -33,6 +33,7 @@ public: virtual void UpdateDisplayInfo(const DisplayInfo& displayInfo) {} virtual void OnDisplayInfo(const DisplayGroupInfo& displayGroupInfo) {} virtual void OnWindowInfo(const WinInfo &info) {} + virtual void PreferencesUpdateMouseStyle() {} virtual bool Init() { return true; diff --git a/service/window_manager/include/pointer_drawing_manager.h b/service/window_manager/include/pointer_drawing_manager.h index b280cc36db6fe3510db151f326211aa9253e258a..d7dfecd781c3c430c3924d3a0808dce4c61521b1 100644 --- a/service/window_manager/include/pointer_drawing_manager.h +++ b/service/window_manager/include/pointer_drawing_manager.h @@ -174,6 +174,7 @@ private: int32_t InitLayer(const MOUSE_ICON mouseStyle); int32_t SetPointerStylePreference(PointerStyle pointerStyle); void UpdateMouseStyle(); + void PreferencesUpdateMouseStyle() override; int32_t UpdateCursorProperty(void* pixelMap, const int32_t &focusX, const int32_t &focusY); int32_t UpdateCursorProperty(CustomCursor cursor); void RotateDegree(Direction direction); diff --git a/service/window_manager/src/pointer_drawing_manager.cpp b/service/window_manager/src/pointer_drawing_manager.cpp index 472402262b7942567b4c072720408688339b38b9..9d50082f33724fae7ee700ab9d23f745cfdc3578 100644 --- a/service/window_manager/src/pointer_drawing_manager.cpp +++ b/service/window_manager/src/pointer_drawing_manager.cpp @@ -559,6 +559,18 @@ void PointerDrawingManager::DrawPointer(int32_t displayId, int32_t physicalX, in MMI_HILOGI("Leave, display:%{public}d, physicalX:%d, physicalY:%d", displayId, physicalX, physicalY); } +void PointerDrawingManager::PreferencesUpdateMouseStyle() +{ + CALL_DEBUG_ENTER; + PointerStyle curPointerStyle; + GetPointerStyle(pid_, GLOBAL_WINDOW_ID, curPointerStyle); + MMI_HILOGI("Preferences update mouse style from database"); + lastMouseStyle_.id = curPointerStyle.id; + lastMouseStyle_.color = curPointerStyle.color; + lastMouseStyle_.size = curPointerStyle.size; + lastMouseStyle_.options = curPointerStyle.options; +} + void PointerDrawingManager::UpdateMouseStyle() { CALL_DEBUG_ENTER;