diff --git a/etc/init/distributedsched.cfg b/etc/init/distributedsched.cfg index 84667bcf..42b5d6a3 100644 --- a/etc/init/distributedsched.cfg +++ b/etc/init/distributedsched.cfg @@ -21,15 +21,15 @@ "ohos.permission.INPUT_MONITORING", "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", "ohos.permission.GET_WIFI_INFO", + "ohos.permission.MANAGE_LOCAL_ACCOUNTS", "ohos.permission.MANAGE_MISSIONS", + "ohos.permission.MANAGE_SECURE_SETTINGS", "ohos.permission.MANAGE_WIFI_CONNECTION", "ohos.permission.MONITOR_DEVICE_NETWORK_STATE", "ohos.permission.PUBLISH_SYSTEM_COMMON_EVENT", "ohos.permission.REPORT_RESOURCE_SCHEDULE_EVENT", "ohos.permission.RUNNING_STATE_OBSERVER", - "ohos.permission.START_INVISIBLE_ABILITY", - "ohos.permission.MANAGE_LOCAL_ACCOUNTS", - "ohos.permission.MANAGE_SECURE_SETTINGS" + "ohos.permission.START_INVISIBLE_ABILITY" ], "permission_acls" : [ "ohos.permission.INPUT_MONITORING", diff --git a/services/dtbschedmgr/include/common_event_listener.h b/services/dtbschedmgr/include/common_event_listener.h index fd00d93c..fb451f6a 100644 --- a/services/dtbschedmgr/include/common_event_listener.h +++ b/services/dtbschedmgr/include/common_event_listener.h @@ -19,9 +19,6 @@ #include "common_event_data.h" #include "common_event_manager.h" #include "common_event_support.h" -#include "datashare_manager.h" -#include "os_account_manager.h" -#include "switch_status_dependency.h" namespace OHOS { namespace DistributedSchedule { @@ -35,7 +32,6 @@ public: void OnReceiveEvent(const EventFwk::CommonEventData &eventData); ErrCode GetForegroundOsAccountLocalId(int32_t &accountId); ErrCode GetOsAccountType(int32_t &accountId); - DataShareManager dataShareManager_; }; } // namespace DistributedSchedule } // namespace OHOS diff --git a/services/dtbschedmgr/include/datashare_manager.h b/services/dtbschedmgr/include/datashare_manager.h index 2549b402..ce18e1ce 100644 --- a/services/dtbschedmgr/include/datashare_manager.h +++ b/services/dtbschedmgr/include/datashare_manager.h @@ -20,6 +20,7 @@ #include "datashare_helper.h" #include "data_ability_observer_stub.h" +#include "single_instance.h" namespace OHOS { namespace DistributedSchedule { @@ -41,6 +42,8 @@ private: }; class DataShareManager { + DECLARE_SINGLE_INSTANCE(DataShareManager); + public: void RegisterObserver(const std::string &key, SettingObserver::ObserverCallback &observerCallback); void UnregisterObserver(const std::string &key); @@ -50,7 +53,9 @@ public: int32_t GetLocalAccountId(); Uri AssembleUserSecureUri(int userId, const std::string& key); void UpdateSwitchStatus(const std::string &key, const std::string &value); - std::atomic isContinueSwitchOn_ = false; + std::atomic isCurrentContinueSwitchOn_ = true; + bool IsCurrentContinueSwitchOn(); + void SetCurrentContinueSwitch(bool status); private: std::shared_ptr CreateDataShareHelper(); diff --git a/services/dtbschedmgr/include/mission/dms_continue_recv_manager.h b/services/dtbschedmgr/include/mission/dms_continue_recv_manager.h index 835cdd3a..7259c2c3 100644 --- a/services/dtbschedmgr/include/mission/dms_continue_recv_manager.h +++ b/services/dtbschedmgr/include/mission/dms_continue_recv_manager.h @@ -25,7 +25,6 @@ #include #include "bundle/bundle_manager_internal.h" -#include "datashare_manager.h" #include "distributed_mission_broadcast_listener.h" #include "distributed_mission_died_listener.h" #include "distributed_mission_focused_listener.h" @@ -98,7 +97,6 @@ private: std::mutex iconMutex_; std::shared_ptr eventHandler_; bool hasRegSoftbusEventListener_ = false; - DataShareManager dataShareManager_; }; } // namespace DistributedSchedule } // namespace OHOS diff --git a/services/dtbschedmgr/include/mission/dms_continue_send_manager.h b/services/dtbschedmgr/include/mission/dms_continue_send_manager.h index 33b1e9c8..270ff53d 100644 --- a/services/dtbschedmgr/include/mission/dms_continue_send_manager.h +++ b/services/dtbschedmgr/include/mission/dms_continue_send_manager.h @@ -25,7 +25,6 @@ #include #include "bundle/bundle_manager_internal.h" -#include "datashare_manager.h" #include "distributed_mission_died_listener.h" #include "event_handler.h" #include "mission_info.h" @@ -158,7 +157,6 @@ private: std::shared_ptr screenOffHandler_; int32_t mmiMonitorId_ = INVALID_MISSION_ID; std::map aliveMission_; - DataShareManager dataShareManager_; }; } // namespace DistributedSchedule } // namespace OHOS diff --git a/services/dtbschedmgr/include/switch_status_dependency.h b/services/dtbschedmgr/include/switch_status_dependency.h index 0e92292e..decf922b 100644 --- a/services/dtbschedmgr/include/switch_status_dependency.h +++ b/services/dtbschedmgr/include/switch_status_dependency.h @@ -21,7 +21,6 @@ #include #include "json/json.h" #include "datashare_helper.h" -#include "datashare_manager.h" namespace OHOS { namespace DistributedSchedule { @@ -45,7 +44,6 @@ private: const std::string CONTINUE_SWITCH_OFF = "0"; const std::string CONTINUE_SWITCH_ON = "1"; std::string switchStatus_; - DataShareManager dataShareManager_; }; } // namespace DistributedSchedule } // namespace OHOS diff --git a/services/dtbschedmgr/src/common_event_listener.cpp b/services/dtbschedmgr/src/common_event_listener.cpp index e94d9717..51aa656e 100644 --- a/services/dtbschedmgr/src/common_event_listener.cpp +++ b/services/dtbschedmgr/src/common_event_listener.cpp @@ -20,7 +20,6 @@ #include "mission/distributed_bm_storage.h" #include "mission/dms_continue_recv_manager.h" #include "mission/dms_continue_send_manager.h" -#include "os_account_manager.h" #include "switch_status_dependency.h" namespace OHOS { @@ -45,8 +44,6 @@ std::map receiveEvent = { {EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED, PACKAGE_CHANGED}, {EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED, PACKAGE_REMOVED}, }; -const std::string CONTINUE_SWITCH_STATUS_KEY = "Continue_Switch_Status"; -const std::string CONTINUE_SWITCH_OFF = "0"; } void CommonEventListener::OnReceiveEvent(const EventFwk::CommonEventData &eventData) { @@ -111,9 +108,10 @@ ErrCode CommonEventListener::GetOsAccountType(int32_t& accountId) HILOGE("GetOsAccountType passing param invalid or return error!, err : %{public}d", err); return INVALID_PARAMETERS_ERR; } - if (type == OsAccountType::PRIVATE) { + if (type == AccountSA::OsAccountType::PRIVATE) { HILOGI("GetOsAccountType : OsAccountType is PRIVATE, type : %{public}d", type); - dataShareManager_.UpdateSwitchStatus(CONTINUE_SWITCH_STATUS_KEY, CONTINUE_SWITCH_OFF); + DataShareManger::GetInstance().UpdateSwitchStatus(SwitchStatusDependency::GetInstance() + .CONTINUE_SWITCH_STATUS_KEY, SwitchStatusDependency::GetInstance().CONTINUE_SWITCH_OFF); } return ERR_OK; } diff --git a/services/dtbschedmgr/src/datashare_manager.cpp b/services/dtbschedmgr/src/datashare_manager.cpp index e0d65d53..40678c5c 100644 --- a/services/dtbschedmgr/src/datashare_manager.cpp +++ b/services/dtbschedmgr/src/datashare_manager.cpp @@ -26,6 +26,7 @@ namespace OHOS { namespace DistributedSchedule { +IMPLEMENT_SINGLE_INSTANCE(DataShareManager); namespace { const std::string TAG = "DMSDataShareManager"; const std::string SETTINGS_DATA_URI_PREFIX = @@ -61,11 +62,6 @@ sptr DataShareManager::GetSettingObserver(const std::string &ke return nullptr; } -Uri DataShareManager::AssembleUri(const std::string &key) -{ - return Uri(SETTINGS_DATA_URI_PREFIX + "&key=" + key); -} - std::shared_ptr DataShareManager::CreateDataShareHelper() { HILOGI("DataShareManager CreateDataShareHelper start"); @@ -122,6 +118,7 @@ void DataShareManager::UnregisterObserver(const std::string &key) dataShareHelper->UnregisterObserver(uri, observer); dataShareHelper->Release(); if (observer != nullptr){ + HILOGI("UnregisterObserver delete observer"); delete observer; } std::lock_guard lockGuard(observerMapMutex_); @@ -131,7 +128,7 @@ void DataShareManager::UnregisterObserver(const std::string &key) Uri DataShareManager::AssembleUserSecureUri(int userId, const std::string &key) { - Uri uri(SETTING_USER_SECURE_URI + "_" + std::to_string(userId) + "?Proxy=true&key" + key); + Uri uri(SETTING_USER_SECURE_URI + "_" + std::to_string(userId) + "?Proxy=true&key=" + key); return uri; } @@ -146,11 +143,11 @@ int32_t DataShareManager::GetLocalAccountId() return id; } -int32_t DataShareManager::UpdateSwitchStatus(const std::string &key, const std::string &value) +void DataShareManager::UpdateSwitchStatus(const std::string &key, const std::string &value) { HILOGI("Start UpdateSwitchStatus"); std::shared_ptr dataShareHelper = CreateDataShareHelper(); - if ( dataShareHelper == nullptr) { + if (dataShareHelper == nullptr) { HILOGE("dataShareHelper is null, key is %{public}s", key.c_str()); return; } @@ -159,19 +156,33 @@ int32_t DataShareManager::UpdateSwitchStatus(const std::string &key, const std:: int32_t userId = GetLocalAccountId(); Uri uri(AssembleUserSecureUri(userId, key)); DataShare::DataSharePredicates predicates; - predicates.EqualTo(SETTINGS_DATA_FIELD_KEY, KEY); + predicates.EqualTo(SETTINGS_DATA_FIELD_KEY, key); DataShare::DataShareValuesBucket bucket; bucket.Put(SETTINGS_DATA_FIELD_KEY, key); bucket.Put(SETTINGS_DATA_FIELD_VAL, value); - auto result = dataShareHelper->UpDateEx(uri, predicates, bucket); + auto result = dataShareHelper->UpdateEx(uri, predicates, bucket); dataShareHelper->Release(); - if (result.first != 0) { - HILOGE("Updata status failed: %{public}d", result.first); + if (result.first != ERR_OK) { + HILOGE("Update status failed: %{public}d", result.first); } - HILOGD("Finish UpdateSwitchStatus, Updata status success: %{public}d", result.first); + HILOGI("Finish UpdateSwitchStatus, Updata status success: %{public}d", result.first); return; } + +bool DataShareManager::IsCurrentContinueSwitchOn() +{ + HILOGD(IsCurrentContinueSwitchOn start); + return isCurrentContinueSwitchOn_.load(); +} + +void DataShareManager::SetCurrentContinueSwitch(bool status) +{ + HILOGD(SetCurrentContinueSwitch start); + isCurrentContinueSwitchOn_.store(status); + + +} } // namespace DistributedSchedule } // namespace OHOS \ No newline at end of file diff --git a/services/dtbschedmgr/src/distributed_sched_service.cpp b/services/dtbschedmgr/src/distributed_sched_service.cpp index d69fc140..ad3d79f2 100644 --- a/services/dtbschedmgr/src/distributed_sched_service.cpp +++ b/services/dtbschedmgr/src/distributed_sched_service.cpp @@ -140,7 +140,7 @@ constexpr int32_t DMSDURATION_SRCTODSTRPCTIME = 5; constexpr int32_t DMSDURATION_STARTABILITY = 6; constexpr int32_t HID_HAP = 10000; /* first hap user */ constexpr int32_t WINDOW_MANAGER_SERVICE_ID = 4606; -static const std::string CONTINUE_SWITCH_STATUS_KEY = "Continue_Switch_Status"; +DataShareManager &dataShareManager = DataShareManager::GetInstance(); } IMPLEMENT_SINGLE_INSTANCE(DistributedSchedService); @@ -205,6 +205,7 @@ void DistributedSchedService::OnStop(const SystemAbilityOnDemandReason &stopReas dlclose(dllHandle_); dllHandle_ = nullptr; #endif + dataShareManager.UnregisterObserver(SwitchStatusDependency::GetInstance().CONTINUE_SWITCH_STATUS_KEY); HILOGI("OnStop dms service end"); } @@ -325,15 +326,15 @@ void DistributedSchedService::OnAddSystemAbility(int32_t systemAbilityId, const void DistributedSchedService::InitDataShareManager() { DataShareManager::ObserverCallback observerCallback = [this]() { - dataShareManager_.isContinueSwitchOn_.store(SwitchStatusDependency::GetInstance().IsContinueSwitchOn()); - HILOGD("dataShareManager_.isContinueSwitchOn_ : %{public}d", dataShareManager_.isContinueSwitchOn_.load()); + dataShareManager.SetCurrentContinueSwitch(SwitchStatusDependency::GetInstance().IsContinueSwitchOn()); + HILOGD("dataShareManager.IsCurrentContinueSwitchOn : %{public}d", dataShareManager.IsCurrentContinueSwitchOn()); int32_t missionId = GetCurrentMissionId(); if (missionId <= 0) { HILOGW("GetCurrentMissionId failed, init end. ret: %{public}d", missionId); return; } - DmsUE::GetInstance().ChangedSwitchState(dataShareManager_.isContinueSwitchOn_.load(), ERR_OK); - if (dataShareManager_.isContinueSwitchOn_.load()) { + DmsUE::GetInstance().ChangedSwitchState(dataShareManager.IsCurrentContinueSwitchOn(), ERR_OK); + if (dataShareManager.IsCurrentContinueSwitchOn()) { DMSContinueSendMgr::GetInstance().NotifyMissionFocused(missionId, FocusedReason::INIT); DSchedContinueManager::GetInstance().Init(); } else { @@ -342,7 +343,8 @@ void DistributedSchedService::InitDataShareManager() DSchedContinueManager::GetInstance().UnInit(); }; }; - dataShareManager_.RegisterObserver(CONTINUE_SWITCH_STATUS_KEY, observerCallback); + dataShareManager.SetCurrentContinueSwitch(SwitchStatusDependency::GetInstance().CONTINUE_SWITCH_STATUS_KEY) + dataShareManager.RegisterObserver(SwitchStatusDependency::GetInstance().CONTINUE_SWITCH_STATUS_KEY, observerCallback); DmsUE::GetInstance().OriginalSwitchState(SwitchStatusDependency::GetInstance().IsContinueSwitchOn(), ERR_OK); HILOGI("Init data share manager, register observer end."); } @@ -818,7 +820,7 @@ int32_t DistributedSchedService::ContinueLocalMissionDealFreeInstall(OHOS::AAFwk int32_t DistributedSchedService::ContinueLocalMission(const std::string& dstDeviceId, int32_t missionId, const sptr& callback, const OHOS::AAFwk::WantParams& wantParams) { - if (!dataShareManager_.isContinueSwitchOn_.load()) { + if (!dataShareManager.IsCurrentContinueSwitchOn()) { HILOGE("ContinueSwitch status is off"); return DMS_PERMISSION_DENIED; } @@ -894,7 +896,7 @@ int32_t DistributedSchedService::ContinueAbilityWithTimeout(const std::string& d int32_t DistributedSchedService::ContinueRemoteMission(const std::string& srcDeviceId, const std::string& dstDeviceId, int32_t missionId, const sptr& callback, const OHOS::AAFwk::WantParams& wantParams) { - if (!dataShareManager_.isContinueSwitchOn_.load()) { + if (!dataShareManager.IsCurrentContinueSwitchOn()) { HILOGE("ContinueSwitch status is off"); return DMS_PERMISSION_DENIED; } @@ -3175,7 +3177,7 @@ int32_t DistributedSchedService::StartLocalAbility(const FreeInstallInfo& info, int32_t DistributedSchedService::StartAbility(const OHOS::AAFwk::Want& want, int32_t requestCode) { - if (!SwitchStatusDependency::GetInstance().IsContinueSwitchOn()) { + if (!dataShareManager.IsCurrentContinueSwitchOn()) { HILOGE("ContinueSwitch status is off"); return DMS_PERMISSION_DENIED; } diff --git a/services/dtbschedmgr/src/mission/dms_continue_recv_manager.cpp b/services/dtbschedmgr/src/mission/dms_continue_recv_manager.cpp index 58594a95..8821338b 100644 --- a/services/dtbschedmgr/src/mission/dms_continue_recv_manager.cpp +++ b/services/dtbschedmgr/src/mission/dms_continue_recv_manager.cpp @@ -93,7 +93,7 @@ void DMSContinueRecvMgr::NotifyDataRecv(std::string& senderNetworkId, HILOGE("Forbid sending and receiving"); return; } - if (!dataShareManager_.isContinueSwitchOn_.load()) { + if (!DataShareManager::GetInstance().IsCurrentContinueSwitchOn()) { HILOGE("ContinueSwitch status is off"); return; } diff --git a/services/dtbschedmgr/src/mission/dms_continue_send_manager.cpp b/services/dtbschedmgr/src/mission/dms_continue_send_manager.cpp index 2ceaa116..f022441e 100644 --- a/services/dtbschedmgr/src/mission/dms_continue_send_manager.cpp +++ b/services/dtbschedmgr/src/mission/dms_continue_send_manager.cpp @@ -45,7 +45,6 @@ constexpr int64_t TIME_DELAYED = 250; // determines whether normal unfocused or const std::string TAG = "DMSContinueSendMgr"; const std::string TIMEOUT_UNFOCUSED_TASK = "timeout_unfocused_task"; const std::string SCREEN_OFF_UNFOCUSED_TASK = "screen_off_unfocused_task"; -static const std::string CONTINUE_SWITCH_STATUS_KEY = "Continue_Switch_Status"; } IMPLEMENT_SINGLE_INSTANCE(DMSContinueSendMgr); @@ -444,7 +443,7 @@ int32_t DMSContinueSendMgr::SendScreenOffEvent(uint8_t type) return REMOTE_DEVICE_BIND_ABILITY_ERR; } - if (!dataShareManager_.isContinueSwitchOn_.load()) { + if (!DataShareManager::GetInstance().IsCurrentContinueSwitchOn()) { HILOGE("ContinueSwitch status is off"); return DMS_PERMISSION_DENIED; } @@ -741,7 +740,7 @@ int32_t DMSContinueSendMgr::SetStateSendEvent(const uint16_t bundleNameId, const AddMMIListener(); } - if (!dataShareManager_.isContinueSwitchOn_.load()) { + if (!DataShareManager::GetInstance().IsCurrentContinueSwitchOn()) { HILOGE("ContinueSwitch status is off"); return DMS_PERMISSION_DENIED; } diff --git a/services/dtbschedmgr/src/switch_status_dependency.cpp b/services/dtbschedmgr/src/switch_status_dependency.cpp index 1162a284..bfe4afe9 100644 --- a/services/dtbschedmgr/src/switch_status_dependency.cpp +++ b/services/dtbschedmgr/src/switch_status_dependency.cpp @@ -37,6 +37,7 @@ SwitchStatusDependency &SwitchStatusDependency::GetInstance() static SwitchStatusDependency instance; return instance; } + bool SwitchStatusDependency::IsContinueSwitchOn() { HILOGD("IsContinueSwitchOn start"); @@ -54,8 +55,8 @@ std::string SwitchStatusDependency::GetSwitchStatus(const std::string &key, cons HILOGE("dataShareHelper is null, key is %{public}s", key.c_str()); return defaultValue; } - int32_t userId = dataShareManager_.GetLocalAccountId(); - Uri uri(dataShareManager_.AssembleUserSecureUri(userId, key)); + int32_t userId = DataShareManager::GetInstance().GetLocalAccountId(); + Uri uri(DataShareManager::GetInstance().AssembleUserSecureUri(userId, key)); DataShare::DataSharePredicates dataSharePredicates; std::vector columns; dataSharePredicates.EqualTo(SETTINGS_DATA_FIELD_KEY, key); @@ -87,7 +88,6 @@ std::string SwitchStatusDependency::GetSwitchStatus(const std::string &key, cons } resultSet->Close(); dataShareHelper->Release(); - HILOGD("get switch status, query end"); HILOGI("GetStringValue, setting value is %{public}s with key is %{public}s", valueResult.c_str(), key.c_str()); return valueResult; }