datashare整改同步5.0.1分支

Signed-off-by: guojin31 <guojin31@huawei.com>
This commit is contained in:
guojin31 2024-11-18 11:28:23 +08:00
parent c2640940c2
commit 4ec6ecd641
5 changed files with 38 additions and 17 deletions

View File

@ -32,7 +32,8 @@ enum {
MSG_ID_USER_START = 0, // a user started
MSG_ID_USER_REMOVED, // a user removed
MSG_ID_PACKAGE_REMOVED, // a package is removed
MSG_ID_BUNDLE_SCAN_FINISHED, // bundle scan finished, ready to create data share helper
MSG_ID_BUNDLE_SCAN_FINISHED, // bundle scan finished
MSG_ID_DATA_SHARE_READY, // datashare ready, ready to create data share helper
MSG_ID_PACKAGE_ADDED,
MSG_ID_PACKAGE_CHANGED,
MSG_ID_SYS_LANGUAGE_CHANGED,

View File

@ -56,6 +56,7 @@ public:
void RemoveUser(const EventFwk::CommonEventData &data);
void StopUser(const EventFwk::CommonEventData &data);
void OnBundleScanFinished(const EventFwk::CommonEventData &data);
void OnDataShareReady(const EventFwk::CommonEventData &data);
void AddPackage(const EventFwk::CommonEventData &data);
void ChangePackage(const EventFwk::CommonEventData &data);
void HandleBootCompleted(const EventFwk::CommonEventData &data);

View File

@ -133,11 +133,11 @@ private:
void HandleUserSwitched(int32_t userId);
void HandleWmsStarted();
void HandleMemStarted();
void HandleDataShareReady();
void HandleOsAccountStarted();
void HandleFocusChanged(bool isFocused, int32_t pid, int32_t uid);
void StopImeInBackground();
int32_t InitAccountMonitor();
int32_t RegisterDataShareObserver();
static std::shared_ptr<AppExecFwk::EventHandler> serviceHandler_;
int32_t userId_;
static constexpr const char *SELECT_DIALOG_ACTION = "action.system.inputmethodchoose";

View File

@ -66,6 +66,7 @@ bool ImCommonEventManager::SubscribeEvent()
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED);
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED);
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_BUNDLE_SCAN_FINISHED);
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_DATA_SHARE_READY);
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_STOPPED);
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED);
@ -219,6 +220,10 @@ ImCommonEventManager::EventSubscriber::EventSubscriber(const EventFwk::CommonEve
[] (EventSubscriber *that, const EventFwk::CommonEventData &data) {
return that->OnBundleScanFinished(data);
};
EventManagerFunc_[CommonEventSupport::COMMON_EVENT_DATA_SHARE_READY] =
[] (EventSubscriber *that, const EventFwk::CommonEventData &data) {
return that->OnDataShareReady(data);
};
EventManagerFunc_[CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED] =
[] (EventSubscriber *that, const EventFwk::CommonEventData &data) {
return that->AddPackage(data);
@ -293,6 +298,23 @@ void ImCommonEventManager::EventSubscriber::OnBundleScanFinished(const EventFwk:
MessageHandler::Instance()->SendMessage(msg);
}
void ImCommonEventManager::EventSubscriber::OnDataShareReady(const EventFwk::CommonEventData &data)
{
IMSA_HILOGI("ImCommonEventManager start.");
auto parcel = new (std::nothrow) MessageParcel();
if (parcel == nullptr) {
IMSA_HILOGE("failed to create MessageParcel!");
return;
}
auto msg = new (std::nothrow) Message(MessageID::MSG_ID_DATA_SHARE_READY, parcel);
if (msg == nullptr) {
IMSA_HILOGE("failed to create Message!");
delete parcel;
return;
}
MessageHandler::Instance()->SendMessage(msg);
}
void ImCommonEventManager::EventSubscriber::RemovePackage(const CommonEventData &data)
{
HandlePackageEvent(MessageID::MSG_ID_PACKAGE_REMOVED, data);

View File

@ -962,8 +962,10 @@ void InputMethodSystemAbility::WorkThread()
break;
}
case MSG_ID_BUNDLE_SCAN_FINISHED: {
RegisterDataShareObserver();
FullImeInfoManager::GetInstance().Init();
break;
}
case MSG_ID_DATA_SHARE_READY: {
HandleDataShareReady();
break;
}
case MSG_ID_PACKAGE_ADDED:
@ -1353,28 +1355,23 @@ void InputMethodSystemAbility::InitMonitors()
ret = InitWmsMonitor();
IMSA_HILOGI("init wms monitor, ret: %{public}d.", ret);
InitSystemLanguageMonitor();
}
void InputMethodSystemAbility::HandleDataShareReady()
{
if (ImeInfoInquirer::GetInstance().IsEnableInputMethod()) {
IMSA_HILOGW("Enter enable mode.");
RegisterEnableImeObserver();
EnableImeDataParser::GetInstance()->Initialize(userId_);
enableImeOn_.store(true);
}
if (ImeInfoInquirer::GetInstance().IsEnableSecurityMode()) {
IMSA_HILOGW("Enter security mode.");
RegisterSecurityModeObserver();
SecurityModeParser::GetInstance()->Initialize(userId_);
enableSecurityMode_.store(true);
}
RegisterDataShareObserver();
}
int32_t InputMethodSystemAbility::RegisterDataShareObserver()
{
IMSA_HILOGD("start.");
if (ImeInfoInquirer::GetInstance().IsEnableInputMethod()) {
RegisterEnableImeObserver();
}
if (ImeInfoInquirer::GetInstance().IsEnableSecurityMode()) {
RegisterSecurityModeObserver();
}
return ErrorCode::NO_ERROR;
FullImeInfoManager::GetInstance().Init();
}
int32_t InputMethodSystemAbility::InitAccountMonitor()