diff --git a/services/samgr/native/BUILD.gn b/services/samgr/native/BUILD.gn index c8a0fadb693941eb69f4e7c17f760e95ee998703..8c99fe1eb33506bee4f27f1c4dc534ace486feb0 100644 --- a/services/samgr/native/BUILD.gn +++ b/services/samgr/native/BUILD.gn @@ -53,7 +53,8 @@ ohos_executable("samgr") { "//foundation/systemabilitymgr/samgr/utils/native/source/tools.cpp", ] - deps = [ "//foundation/systemabilitymgr/samgr/interfaces/innerkits/common:samgr_common" ] + deps = [ "//foundation/systemabilitymgr/samgr/interfaces/innerkits/common:samgr_common", + "//foundation/ability/ability_runtime/frameworks/native/ability/native:abilitykit_native", ] configs = [ ":sam_config", @@ -64,11 +65,14 @@ ohos_executable("samgr") { defines = [] if (is_standard_system) { external_deps = [ + "ability_base:zuri", "access_token:libaccesstoken_sdk", "c_utils:utils", "eventhandler:libeventhandler", "hisysevent_native:libhisysevent", "hitrace_native:hitrace_meter", + "data_share:datashare_common", + "data_share:datashare_consumer", "hiviewdfx_hilog_native:libhilog", "init:libbeget_proxy", "init:libbegetutil", diff --git a/services/samgr/native/source/collect/device_networking_collect.cpp b/services/samgr/native/source/collect/device_networking_collect.cpp index c07dcae9fd1bf925977d4a6efe1192dcde83969c..da4e81f31c3ab449aa12b51cd050ff81342d772b 100644 --- a/services/samgr/native/source/collect/device_networking_collect.cpp +++ b/services/samgr/native/source/collect/device_networking_collect.cpp @@ -13,12 +13,16 @@ * limitations under the License. */ + #include "device_networking_collect.h" +#include "datashare_helper.h" +#include "datashare_predicates.h" #include "sam_log.h" #include "sa_profiles.h" #include "system_ability_definition.h" #include "system_ability_manager.h" +#include "uri.h" using namespace std; @@ -29,6 +33,11 @@ namespace OHOS { namespace { const std::string PKG_NAME = "Samgr_Networking"; const std::string SA_TAG_DEVICE_ON_LINE = "deviceonline"; +static const std::string SETTINGS_DATA_FIELD_KEYWORD = "KEYWORD"; +static const std::string SETTINGS_DATA_FIELD_VALUE = "VALUE"; +static const std::string PREDICATES_STRING = "settings.general.device_name"; +static const std::string SETTINGS_DATA_BASE_URI = + "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true"; constexpr uint32_t INIT_EVENT = 10; constexpr uint32_t DM_DIED_EVENT = 11; constexpr int64_t DELAY_TIME = 1000; @@ -38,8 +47,40 @@ DeviceNetworkingCollect::DeviceNetworkingCollect(const sptr& report) { } +int32_t settingtest() +{ + auto remoteObj = SystemAbilityManager::GetInstance()->GetSystemAbility(1401); + std::string val; + if (remoteObj == nullptr) { + return -1; + } + auto dataShareHelper = DataShare::DataShareHelper::Creator(remoteObj, SETTINGS_DATA_BASE_URI); + if (dataShareHelper == nullptr) { + return -1; + } + Uri uri(SETTINGS_DATA_BASE_URI); + std::vector columns{SETTINGS_DATA_FIELD_VALUE}; + DataShare::DataSharePredicates predicates; + predicates.EqualTo(SETTINGS_DATA_FIELD_KEYWORD, PREDICATES_STRING); + auto resultset = dataShareHelper->Query(uri, predicates, columns); + if (resultset == nullptr) { + return -1; + } + int32_t numRows = 0; + resultset->GetRowCount(numRows); + + int columnIndex = 0; + resultset->GoToFirstRow(); + resultset->GetColumnIndex(SETTINGS_DATA_FIELD_VALUE, columnIndex); + resultset->GetString(columnIndex, val); + // resultset->close() + return ERR_OK; +} + + int32_t DeviceNetworkingCollect::OnStart() { + settingtest(); HILOGI("DeviceNetworkingCollect OnStart called"); std::shared_ptr handler = EventHandler::Current(); if (handler == nullptr) { diff --git a/services/samgr/native/source/system_ability_manager.cpp b/services/samgr/native/source/system_ability_manager.cpp index 903fa7ac2e32512b24ff355706616b9372379bbb..b9849e934b311bcd561d9ac2592cc6cc62752c9b 100644 --- a/services/samgr/native/source/system_ability_manager.cpp +++ b/services/samgr/native/source/system_ability_manager.cpp @@ -57,6 +57,7 @@ constexpr int32_t MAX_SA_FREQUENCY_COUNT = INT32_MAX - 1000000; constexpr int32_t SHFIT_BIT = 32; constexpr int64_t ONDEMAND_PERF_DELAY_TIME = 60 * 1000; // ms constexpr int64_t CHECK_LOADED_DELAY_TIME = 4 * 1000; // ms + } std::mutex SystemAbilityManager::instanceLock;