diff --git a/interfaces/innerkits/common/BUILD.gn b/interfaces/innerkits/common/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..9d7ebc18babbd98360cfd315a69d0a944e5acd8a --- /dev/null +++ b/interfaces/innerkits/common/BUILD.gn @@ -0,0 +1,43 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") + +config("config_samgr_common") { + include_dirs = [ + "include", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include", + "//third_party/libxml2/include", + ] +} + +################################################################################ +ohos_shared_library("samgr_common") { + sources = [ + "//foundation/distributedschedule/samgr/services/common/src/parse_util.cpp", + ] + + configs = [ ":config_samgr_common" ] + public_configs = [ ":config_samgr_common" ] + if (is_standard_system) { + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "utils_base:utils", + ] + part_name = "samgr_standard" + } + + public_deps = [ "//third_party/libxml2:libxml2" ] + subsystem_name = "distributedschedule" +} +################################################################################ diff --git a/interfaces/innerkits/common/include/parse_util.h b/interfaces/innerkits/common/include/parse_util.h new file mode 100755 index 0000000000000000000000000000000000000000..be6224a900dabc9ab1cf91e9a64ca30db0f3370a --- /dev/null +++ b/interfaces/innerkits/common/include/parse_util.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SAMGR_INTERFACE_INNERKITS_COMMOM_INCLUDE_PARSE_UTIL_H +#define SAMGR_INTERFACE_INNERKITS_COMMOM_INCLUDE_PARSE_UTIL_H + +#include +#include +#include +#include +#include "sa_profiles.h" +#include "libxml/parser.h" +#include "libxml/xpath.h" + +namespace OHOS { +class ParseUtil { +public: + ~ParseUtil(); + bool ParseSaProfiles(const std::string& profilePath); + + const std::list& GetAllSaProfiles() const; + bool GetProfile(int32_t saId, SaProfile& saProfile); + void ClearResource(); + void OpenSo(); + void CloseSo(int32_t systemAbilityId); + bool LoadSaLib(int32_t systemAbilityId); + bool ParseTrustConfig(const std::string& profilePath, std::map>& values); + void RemoveSaProfile(int32_t saId); + bool CheckPathExist(const std::string& profilePath); + std::u16string GetProcessName() const; +private: + void CloseSo(); + void OpenSo(SaProfile& saProfile); + void CloseHandle(SaProfile& saProfile); + bool ParseSystemAbility(const xmlNode& rootNode, const std::u16string& processName); + bool ParseProcess(const xmlNodePtr& rootNode, std::u16string& processName); + void ParseSAProp(const std::string& nodeName, const std::string& nodeContent, SaProfile& saProfile); + bool CheckRootTag(const xmlNodePtr& rootNodePtr); + bool ParseTrustConfigInner(const xmlNodePtr& rootNodePtr, std::map>& values); + bool ParseSaId(const xmlNodePtr& rootNode, int32_t& saId); + std::list saProfiles_; + std::u16string procName_; +}; +} // namespace OHOS + +#endif // SAMGR_INTERFACE_INNERKITS_COMMOM_INCLUDE_PARSE_UTIL_H diff --git a/interfaces/innerkits/common/include/sa_profiles.h b/interfaces/innerkits/common/include/sa_profiles.h new file mode 100755 index 0000000000000000000000000000000000000000..d3e0b505bed6b8eb8e737de7b8613b083bab312f --- /dev/null +++ b/interfaces/innerkits/common/include/sa_profiles.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SAMGR_INTERFACE_INNERKITS_COMMOM_INCLUDE_SAPROFILE_H +#define SAMGR_INTERFACE_INNERKITS_COMMOM_INCLUDE_SAPROFILE_H + +#include +#include + +namespace OHOS { +using DlHandle = void*; + +struct SaProfile { + std::u16string process; + int32_t saId = 0; + std::u16string libPath; + std::vector dependSa; + int32_t dependTimeout = 0; + bool runOnCreate = false; + bool distributed = false; + int32_t dumpLevel = 0; + std::u16string capability; + std::u16string permission; + std::u16string bootPhase; + DlHandle handle = nullptr; +}; +} +#endif // SAMGR_INTERFACE_INNERKITS_COMMOM_INCLUDE_SAPROFILE_H diff --git a/interfaces/innerkits/lsamgr/BUILD.gn b/interfaces/innerkits/lsamgr/BUILD.gn index 932b647b5e92c6b84d318ff39c96a4cfd58838a3..9fc817eca28b709c55880eab48080fc7648a70cf 100755 --- a/interfaces/innerkits/lsamgr/BUILD.gn +++ b/interfaces/innerkits/lsamgr/BUILD.gn @@ -16,10 +16,8 @@ import("//build/ohos.gni") config("config_samgr") { visibility = [ ":*" ] include_dirs = [ - "//developtools/liblog", "//foundation/distributedschedule/samgr/services/lsamgr/include", - "//utils/native/base/include", - "//utils/system/safwk/native/include", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include", ] } @@ -32,11 +30,11 @@ ohos_shared_library("lsamgr") { external_deps = [ "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", + "utils_base:utils", ] part_name = "samgr_standard" } - deps = [ "//utils/native/base:utils" ] subsystem_name = "distributedschedule" } ################################################################################ diff --git a/interfaces/innerkits/samgr_proxy/include/system_ability_definition.h b/interfaces/innerkits/samgr_proxy/include/system_ability_definition.h new file mode 100755 index 0000000000000000000000000000000000000000..2928c80bbee859612b6b19df5ac12e646a918c3f --- /dev/null +++ b/interfaces/innerkits/samgr_proxy/include/system_ability_definition.h @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SAMGR_INTERFACES_INNERKITS_SAMGR_PROXY_INCLUDE_SYSTEM_ABILITY_DEFINITION_H +#define SAMGR_INTERFACES_INNERKITS_SAMGR_PROXY_INCLUDE_SYSTEM_ABILITY_DEFINITION_H + +#include +#include + +namespace OHOS { +// system ability definition should be a number between FIRST_SYS_ABILITY_ID and LAST_SYS_ABILITY_ID +enum { + FIRST_SYS_ABILITY_ID = 0x00000001, + SUBSYS_COMMON_SYS_ABILITY_ID_BEGIN = 1, + SUBSYS_AAFWK_SYS_ABILITY_ID_BEGIN = 100, + ABILITY_TOOLS_SERVICE_ID = 116, + ABILITY_TEST_SERVICE_ID = 179, + ABILITY_MGR_SERVICE_ID = 180, + ABILITY_MST_SERVICE_ID = 181, + DATAOBS_MGR_SERVICE_SA_ID = 182, + SUBSYS_AAFWK_SYS_ABILITY_ID_END = 199, + SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN = 200, + SUBSYS_AI_SYS_ABILITY_ID_BEGIN = 300, + SUBSYS_APPEXECFWK_SYS_ABILITY_ID_BEGIN = 400, + BUNDLE_MGR_SERVICE_SYS_ABILITY_ID = 401, + FORM_MGR_SERVICE_ID = 403, + SUBSYS_APPLICATIONS_SYS_ABILITY_ID_BEGIN = 500, + APP_MGR_SERVICE_ID = 501, + INSTALLD_SERVICE_ID = 511, + SUBSYS_ARVR_SYS_ABILITY_ID_BEGIN = 600, + SUBSYS_ARVRHARDWARE_SYS_ABILITY_ID_BEGIN = 700, + SUBSYS_BARRIERFREE_SYS_ABILITY_ID_BEGIN = 800, + SUBSYS_BIOMETRICS_SYS_ABILITY_ID_BEGIN = 900, + SUBSYS_BIOMETRICS_SYS_ABILITY_FACERECOGNIZE = 901, + SUBSYS_BIOMETRICS_SYS_ABILITY_FINGERPRINT = 902, + SUBSYS_BIOMETRICS_SYS_ABILITY_VOICEID = 903, + SUBSYS_CCRUNTIME_SYS_ABILITY_ID_BEGIN = 1000, + SUBSYS_COMMUNICATION_SYS_ABILITY_ID_BEGIN = 1100, + RPC_UNREGISTERED_TEST_SERVICE = 1108, + RPC_TEST_SERVICE = 1109, + RPC_TEST_SERVICE2 = 1110, + IPC_MSG_SEV = 1114, + IPC_MSG_UNREGISTERED_SERVER = 1115, + IPC_MSG_REPEAT_SERVER = 1116, + IPC_MSG_SERVER = 1117, + IPC_TEST_SERVICE = 1118, + IPC_EXTRA_TEST_SERVICE = 1119, + WIFI_DEVICE_SYS_ABILITY_ID = 1120, + WIFI_HOTSPOT_SYS_ABILITY_ID = 1121, + WIFI_ENHANCER_SYS_ABILITY_ID = 1122, + WIFI_P2P_SYS_ABILITY_ID = 1123, + BLUETOOTH_HOST_SYS_ABILITY_ID = 1130, + NFC_MANAGER_SYS_ABILITY_ID = 1140, + DISCOVER_SYS_ABILITY_ID = 1160, + DNET_SYS_ABILITY_ID = 1170, + NET_MANAGER_SYS_ABILITY_ID = 1150, + COMM_NET_CONN_MANAGER_SYS_ABILITY_ID = 1151, + COMM_NET_POLICY_MANAGER_SYS_ABILITY_ID = 1152, + COMM_NET_STATS_MANAGER_SYS_ABILITY_ID = 1153, + COMM_NET_TETHERING_MANAGER_SYS_ABILITY_ID = 1154, + COMM_VPN_MANAGER_SYS_ABILITY_ID = 1155, + COMM_DNS_MANAGER_SYS_ABILITY_ID = 1156, + COMM_ETHERNET_MANAGER_SYS_ABILITY_ID = 1157, + COMM_NETD_NATIVE_SYS_ABILITY_ID = 1158, + SMART_COMM_SYS_ABILITY_ID = 1180, + SUBSYS_DFX_SYS_ABILITY_ID_BEGIN = 1200, + DFX_SYS_HIVIEW_ABILITY_ID = 1201, + DFX_SYS_EVENT_SERVICE_ABILITY_ID = 1203, + SUBSYS_DISTRIBUTEDDATAMNG_SYS_ABILITY_ID_BEGIN = 1300, + DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID = 1301, + DISTRIBUTED_FS_DAEMON_SERVICE_ID = 1302, + DISTRIBUTED_FS_META_SERVICE_ID = 1303, + DISTRIBUTED_FS_STORAGE_SERVICE_ID = 1304, + SUBSYS_DISTRIBUTEDSCHEDULE_SYS_ABILITY_ID_BEGIN = 1400, + DISTRIBUTED_SCHED_SA_ID = 1401, + DISTRIBUTED_SCHED_ADAPTER_SA_ID = 1402, + DISTRIBUTED_SCENARIO_MGR_SA_ID = 1403, + DISTRIBUTED_SCHED_TEST_SO_ID = 1490, + DISTRIBUTED_SCHED_TEST_OS_ID = 1491, + DISTRIBUTED_SCHED_TEST_OOS_ID = 1492, + DISTRIBUTED_SCHED_TEST_TT_ID = 1493, + DISTRIBUTED_SCHED_TEST_LISTEN_ID = 1494, + DISTRIBUTED_SCHED_TEST_CONNECTION_ID = 1495, + DISTRIBUTED_SCHED_TEST_INCOMPLETE_ID = 1496, + DISTRIBUTED_SCHED_TEST_ONDEMAND_ID = 1497, + DISTRIBUTED_SCHED_TEST_AUDIO_ID = 1498, + DISTRIBUTED_SCHED_TEST_MEDIA_ID = 1499, + SUBSYS_DRIVERS_SYS_ABILITY_ID_BEGIN = 1500, + SUBSYS_GLOBAL_SYS_ABILITY_ID_BEGIN = 1600, + SUBSYS_GRAPHIC_SYS_ABILITY_ID_BEGIN = 1700, + SUBSYS_HBS_SYS_ABILITY_ID_BEGIN = 1800, + SUBSYS_IAWARE_SYS_ABILITY_ID_BEGIN = 1900, + RES_SCHED_SYS_ABILITY_ID = 1901, + RESSCHEDD_SA_ID = 1902, + BACKGROUND_TASK_MANAGER_SERVICE_ID = 1903, + WORK_SCHEDULE_SERVICE_ID = 1904, + SUBSYS_IDE_SYS_ABILITY_ID_BEGIN = 2000, + SUBSYS_INTELLIACCESSORIES_SYS_ABILITY_ID_BEGIN = 2100, + SUBSYS_INTELLISPEAKER_SYS_ABILITY_ID_BEGIN = 2200, + SUBSYS_INTELLITV_SYS_ABILITY_ID_BEGIN = 2300, + SUBSYS_IOT_SYS_ABILITY_ID_BEGIN = 2400, + SUBSYS_IOTHARDWARE_SYS_ABILITY_ID_BEGIN = 2500, + SUBSYS_IVIHARDWARE_SYS_ABILITY_ID_BEGIN = 2600, + IVIHARDWARE_MANAGER_SA_ID = 2601, + IVIHARDWARE_ADAS_SA_ID = 2602, + IVIHARDWARE_TBOX_SA_ID = 2603, + IVIHARDWARE_CLUSTER_SA_ID = 2604, + SUBSYS_KERNEL_SYS_ABILITY_ID_BEGIN = 2700, + SUBSYS_LOCATION_SYS_ABILITY_ID_BEGIN = 2800, + LOCATION_GEO_CONVERT_SA_ID = 2801, + LOCATION_LOCATOR_SA_ID = 2802, + LOCATION_GNSS_SA_ID = 2803, + LOCATION_NETWORK_LOCATING_SA_ID = 2804, + LOCATION_NOPOWER_LOCATING_SA_ID = 2805, + LOCATION_NOTIFICATION_SA_ID = 2806, + SUBSYS_MSDP_SYS_ABILITY_ID_BEGIN = 2900, + MSDP_MOTION_SERVICE_ID = 2901, + MSDP_DEVICESTATUS_SERVICE_ID = 2902, + MSDP_MOVEMENT_SERVICE_ID = 2903, + MSDP_SPATIAL_AWARENESS_SERVICE_ID = 2904, + MSDP_GEOFENCE_SERVICE_ID = 2905, + MSDP_TIMELINE_SERVICE_ID = 2906, + SUBSYS_MULTIMEDIA_SYS_ABILITY_ID_BEGIN = 3000, + AUDIO_DISTRIBUTED_SERVICE_ID = 3001, + PLAYER_DISTRIBUTED_SERVICE_ID = 3002, + RADIO_IVI_SERVICE_ID = 3003, + AUDIO_SWIFT_SERVICE_ID = 3004, + UPDATE_DISTRIBUTED_SERVICE_ID = 3006, + MEDIA_LIBRARY_SERVICE_ID = 3007, + CAMERA_SERVICE_ID = 3008, + AUDIO_POLICY_SERVICE_ID = 3009, + SUBSYS_MULTIMODAINPUT_SYS_ABILITY_ID_BEGIN = 3100, + MULTIMODAL_INPUT_SERVICE_ID = 3101, + MULTIMODAL_CHANNEL_SERVICE_ID = 3102, + SUBSYS_NOTIFICATION_SYS_ABILITY_ID_BEGIN = 3200, + EVENT_MANAGER_SERVICE_ID = 3201, + COMMON_EVENT_SERVICE_ABILITY_ID = 3202, + ADVANCED_NOTIFICATION_SERVICE_ABILITY_ID = 3203, + COMMON_EVENT_SERVICE_ID = 3299, + SUBSYS_POWERMNG_SYS_ABILITY_ID_BEGIN = 3300, + POWER_MANAGER_SERVICE_ID = 3301, + POWER_MANAGER_BATT_SERVICE_ID = 3302, + DISPLAY_MANAGER_SERVICE_ID = 3308, + IVIPOWER_ENHANCED_SERVICE_ID = 3309, + SUBSYS_ROUTER_SYS_ABILITY_ID_BEGIN = 3400, + SUBSYS_SECURITY_SYS_ABILITY_ID_BEGIN = 3500, + SUBSYS_SENSORS_SYS_ABILITY_ID_BEGIN = 3600, + SENSOR_SERVICE_ABILITY_ID = 3601, + MISCDEVICE_SERVICE_ABILITY_ID = 3602, + EXTSHB_SERVICE_ABILITY_ID = 3603, + SUBSYS_SMALLSERVICES_SYS_ABILITY_ID_BEGIN = 3700, + PASTEBOARD_SERVICE_ID = 3701, + TIME_SERVICE_ID = 3702, + INPUT_METHOD_SYSTEM_ABILITY_ID = 3703, + SUBSYS_SOURCECODETRANSFORMER_SYS_ABILITY_ID_BEGIN = 3800, + SUBSYS_STARTUP_SYS_ABILITY_ID_BEGIN = 3900, + PARAM_WATCHER_DISTRIBUTED_SERVICE_ID = 3901, + SUBSYS_TELEPONY_SYS_ABILITY_ID_BEGIN = 4000, + TELEPHONY_SYS_ABILITY_ID = 4001, + DCALL_SYS_ABILITY_ID = 4002, + TELEPHONY_CALL_MANAGER_SYS_ABILITY_ID = 4005, + TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID = 4006, + TELEPHONY_CELLULAR_DATA_SYS_ABILITY_ID = 4007, + TELEPHONY_SMS_MMS_SYS_ABILITY_ID = 4008, + TELEPHONY_STATE_REGISTRY_SYS_ABILITY_ID = 4009, + TELEPHONY_CORE_SERVICE_SYS_ABILITY_ID = 4010, + TELEPHONY_DATA_STORAGE_SYS_ABILITY_ID = 4012, + SUBSYS_UPDATE_SYS_ABILITY_ID_BEGIN = 4100, + SUBSYS_USB_SYS_ABILITY_ID_BEGIN = 4200, + USB_SYSTEM_ABILITY_ID = 4201, + SUBSYS_WEARABLE_SYS_ABILITY_ID_BEGIN = 4300, + SUBSYS_WEARABLEHARDWARE_SYS_ABILITY_ID_BEGIN = 4400, + SUBSYS_IVI_SYS_ABILITY_ID_BEGIN = 4500, + IVI_DRIVINGSAFETY_SA_ID = 4501, + IVI_CONFIGMANAGER_SA_ID = 4502, + IVI_COCKPITMONITOR_SA_ID = 4503, + WINDOW_MANAGER_ID = 4600, + VSYNC_MANAGER_ID = 4601, + VSYNC_MANAGER_TEST_ID = 4602, + GRAPHIC_DUMPER_SERVICE_SA_ID = 4603, + GRAPHIC_DUMPER_COMMAND_SA_ID = 4604, + ANIMATION_SERVER_SA_ID = 4605, + SOFTBUS_SERVER_SA_ID = 4700, + DEVICE_AUTH_SERVICE_ID = 4701, + SUBSYS_DISTRIBUTED_HARDWARE_SYS_ABILITY_ID_BEGIN = 4800, + DISTRIBUTED_HARDWARE_SA_ID = 4801, + DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID = 4802, + SUBSYS_STORAGE_SYS_ABILITY_ID_BEGIN = 4900, + STORAGE_DISTRIBUTED_FILE_DAEMON_SA_ID = 4901, + STORAGE_DISTRIBUTED_FILE_SERVICE_SA_ID = 4902, + DEVICE_STORAGE_MANAGER_SERVICE_ID = 5000, + STORAGE_SERVICE_ID = 5001, + DEVICE_SERVICE_MANAGER_SA_ID = 5100, + DISTRIBUTED_DEVICE_PROFILE_SA_ID = 6001, + LAST_SYS_ABILITY_ID = 0x00ffffff, // 16777215 +}; + +static const std::map saNameMap_ = { + { 200, "AccountMgr" }, + { 301, "AIEngine" }, + { BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, "BundleMgr" }, + { FORM_MGR_SERVICE_ID, "FormMgr" }, + { WIFI_DEVICE_SYS_ABILITY_ID, "WifiDevice" }, + { WIFI_HOTSPOT_SYS_ABILITY_ID, "WifiHotspot" }, + { WIFI_ENHANCER_SYS_ABILITY_ID, "WifiEnhancer" }, + { WIFI_P2P_SYS_ABILITY_ID, "WifiP2p" }, + { BLUETOOTH_HOST_SYS_ABILITY_ID, "BluetoothHost" }, + { NFC_MANAGER_SYS_ABILITY_ID, "NfcManager" }, + { NET_MANAGER_SYS_ABILITY_ID, "NetManager" }, + { DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID, "DistributedKvData" }, + { DISTRIBUTED_SCHED_SA_ID, "DistributedSched" }, + { DISTRIBUTED_SCHED_ADAPTER_SA_ID, "DistributedSchedAdapter" }, + { DISTRIBUTED_SCENARIO_MGR_SA_ID, "DistributedScenarioMgr" }, + { RES_SCHED_SYS_ABILITY_ID, "ResourceSched" }, + { RESSCHEDD_SA_ID, "ResourceSchedDamon" }, + { BACKGROUND_TASK_MANAGER_SERVICE_ID, "BackgroundTaskManager" }, + { WORK_SCHEDULE_SERVICE_ID, "WorkSchedule" }, + { LOCATION_GEO_CONVERT_SA_ID, "LocationGeoConvert" }, + { LOCATION_LOCATOR_SA_ID, "LocationLocator" }, + { LOCATION_GNSS_SA_ID, "LocationGnss" }, + { LOCATION_NETWORK_LOCATING_SA_ID, "LocationNetworkLocating" }, + { LOCATION_NOPOWER_LOCATING_SA_ID, "LocationNopowerLocating" }, + { AUDIO_DISTRIBUTED_SERVICE_ID, "AudioDistributed" }, + { COMMON_EVENT_SERVICE_ABILITY_ID, "CommonEventService" }, + { ADVANCED_NOTIFICATION_SERVICE_ABILITY_ID, "AdvancedNotificationService" }, + { POWER_MANAGER_SERVICE_ID, "PowerManagerService" }, + { POWER_MANAGER_BATT_SERVICE_ID, "PowerManagerBatt" }, + { 3502, "DpmsService" }, + { 3510, "KeystoreService" }, + { SENSOR_SERVICE_ABILITY_ID, "SensorService" }, + { MISCDEVICE_SERVICE_ABILITY_ID, "MiscDeviceService" }, + { PASTEBOARD_SERVICE_ID, "DPasteboardService" }, + { TELEPHONY_SYS_ABILITY_ID, "Telephony" }, + { DCALL_SYS_ABILITY_ID, "DistributedCallMgr" }, + { DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID, "DeviceManagerService" }, + { USB_SYSTEM_ABILITY_ID, "UsbService" }, + { DEVICE_SERVICE_MANAGER_SA_ID, "HdfDeviceServiceManager" }, + { DISTRIBUTED_DEVICE_PROFILE_SA_ID, "DistributedDeviceProfile" }, + { WINDOW_MANAGER_ID, "WindowManager" }, + { VSYNC_MANAGER_ID, "VsyncManager" }, + { VSYNC_MANAGER_TEST_ID, "VsyncManagerTest" }, + { GRAPHIC_DUMPER_SERVICE_SA_ID, "GraphicDumperService" }, + { GRAPHIC_DUMPER_COMMAND_SA_ID, "GraphicDumperCommand" }, + { ANIMATION_SERVER_SA_ID, "AnimationServer" }, +}; +} // namespace OHOS + +#endif diff --git a/ohos.build b/ohos.build index d24de4ff7b3253df798dd7f64a46551c2b0a9271..7465c6664fff3f98b8a0c75ce230e5999d052bb6 100755 --- a/ohos.build +++ b/ohos.build @@ -16,15 +16,29 @@ ] }, "name": "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy" + }, + { + "header": { + "header_base": "//foundation/distributedschedule/samgr/interfaces/innerkits/common/include/", + "header_files": [ + "sa_profiles.h", + "parse_util.h" + ] + }, + "name": "//foundation/distributedschedule/samgr/interfaces/innerkits/common:samgr_common" } ], "module_list": [ + "//foundation/distributedschedule/samgr/interfaces/innerkits/common:samgr_common", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "//foundation/distributedschedule/samgr/services/samgr/native:samgr", "//foundation/distributedschedule/samgr/services/samgr/native:etc", "//third_party/libxml2:libxml2" ], - "test_list": ["//foundation/distributedschedule/samgr/services/samgr/native/test:unittest"], + "test_list": [ + "//foundation/distributedschedule/samgr/services/samgr/native/test:unittest", + "//foundation/distributedschedule/samgr/services/common/test:unittest" + ], "system_kits": [] } }, diff --git a/services/common/src/parse_util.cpp b/services/common/src/parse_util.cpp new file mode 100755 index 0000000000000000000000000000000000000000..884fdebc464ba625e224fb2f50f1c19c123f693c --- /dev/null +++ b/services/common/src/parse_util.cpp @@ -0,0 +1,360 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "parse_util.h" + +#include +#include +#include +#include +#include "datetime_ex.h" + +#include "sam_log.h" +#include "string_ex.h" + +namespace OHOS { +using std::string; + +namespace { +const auto XML_TAG_PROFILE = "profile"; +const auto XML_TAG_INFO = "info"; +const auto XML_TAG_SYSTEM_ABILITY = "systemability"; +const auto XML_TAG_PROCESS = "process"; +const auto XML_TAG_LIB_PATH = "libpath"; +const auto XML_TAG_NAME = "name"; +const auto XML_TAG_DEPEND = "depend"; +const auto XML_TAG_DEPEND_TIMEOUT = "depend-time-out"; +const auto XML_TAG_RUN_ON_CREATE = "run-on-create"; +const auto XML_TAG_DISTRIBUTED = "distributed"; +const auto XML_TAG_DUMP_LEVEL = "dump-level"; +const auto XML_TAG_CAPABILITY = "capability"; +const auto XML_TAG_PERMISSION = "permission"; +const auto XML_TAG_BOOT_PHASE = "bootphase"; +const auto XML_TAG_SAID = "said"; +} + +ParseUtil::~ParseUtil() +{ + ClearResource(); +} + +void ParseUtil::CloseHandle(SaProfile& saProfile) +{ + if (saProfile.handle == nullptr) { + return; + } + int32_t ret = dlclose(saProfile.handle); + if (ret) { + HILOGW("close handle failed with errno:%{public}d!", errno); + } + saProfile.handle = nullptr; +} + +void ParseUtil::CloseSo() +{ + for (auto& saProfile : saProfiles_) { + CloseHandle(saProfile); + } +} + +void ParseUtil::CloseSo(int32_t systemAbilityId) +{ + for (auto& saProfile : saProfiles_) { + if (saProfile.saId == systemAbilityId) { + CloseHandle(saProfile); + break; + } + } +} + +void ParseUtil::ClearResource() +{ + CloseSo(); + saProfiles_.clear(); +} + +void ParseUtil::OpenSo() +{ + for (auto& saProfile : saProfiles_) { + if (saProfile.runOnCreate) { + OpenSo(saProfile); + } + } +} + +void ParseUtil::OpenSo(SaProfile& saProfile) +{ + if (saProfile.handle == nullptr) { + int64_t begin = GetTickCount(); + DlHandle handle = dlopen(Str16ToStr8(saProfile.libPath).c_str(), RTLD_NOW); + HILOGI("[PerformanceTest] SA:%{public}d OpenSo spend %{public}" PRId64 " ms", + saProfile.saId, GetTickCount() - begin); + if (handle == nullptr) { + std::vector libPathVec; + string fileName = ""; + SplitStr(Str16ToStr8(saProfile.libPath), "/", libPathVec); + if ((libPathVec.size() > 0)) { + fileName = libPathVec[libPathVec.size() - 1]; + } + HILOGE("dlopen %{public}s failed with errno:%s!", fileName.c_str(), dlerror()); + return; + } + saProfile.handle = handle; + } else { + HILOGI("SA:%{public}d handle is not null", saProfile.saId); + } +} + +bool ParseUtil::LoadSaLib(int32_t systemAbilityId) +{ + for (auto& saProfile : saProfiles_) { + if (saProfile.saId == systemAbilityId) { + OpenSo(saProfile); + return true; + } + } + return false; +} + +const std::list& ParseUtil::GetAllSaProfiles() const +{ + return saProfiles_; +} + +bool ParseUtil::GetProfile(int32_t saId, SaProfile& saProfile) +{ + auto iter = std::find_if(saProfiles_.begin(), saProfiles_.end(), [saId](auto saProfile) { + return saProfile.saId == saId; + }); + if (iter != saProfiles_.end()) { + saProfile = *iter; + return true; + } + return false; +} + +void ParseUtil::RemoveSaProfile(int32_t saId) +{ + saProfiles_.remove_if([saId] (auto saInfo) -> bool { return saInfo.saId == saId; }); +} + +void ParseUtil::ParseSAProp(const string& nodeName, const string& nodeContent, SaProfile& saProfile) +{ + if (nodeName == XML_TAG_NAME) { + StrToInt(nodeContent.c_str(), saProfile.saId); + } else if (nodeName == XML_TAG_LIB_PATH) { + saProfile.libPath = Str8ToStr16(nodeContent); + } else if (nodeName == XML_TAG_DEPEND) { + saProfile.dependSa.emplace_back(Str8ToStr16(nodeContent)); + } else if (nodeName == XML_TAG_DEPEND_TIMEOUT) { + StrToInt(nodeContent.c_str(), saProfile.dependTimeout); + } else if (nodeName == XML_TAG_RUN_ON_CREATE) { + std::istringstream(nodeContent) >> std::boolalpha >> saProfile.runOnCreate; + } else if (nodeName == XML_TAG_DISTRIBUTED) { + std::istringstream(nodeContent) >> std::boolalpha >> saProfile.distributed; + } else if (nodeName == XML_TAG_DUMP_LEVEL) { + std::stringstream ss(nodeContent); + ss >> saProfile.dumpLevel; + } else if (nodeName == XML_TAG_CAPABILITY) { + saProfile.capability = Str8ToStr16(nodeContent); + } else if (nodeName == XML_TAG_PERMISSION) { + saProfile.permission = Str8ToStr16(nodeContent); + } else if (nodeName == XML_TAG_BOOT_PHASE) { + saProfile.bootPhase = Str8ToStr16(nodeContent); + } +} + +bool ParseUtil::ParseSystemAbility(const xmlNode& rootNode, const std::u16string& process) +{ + auto currNodePtr = rootNode.xmlChildrenNode; + if (currNodePtr == nullptr) { + return false; + } + SaProfile saProfile; + saProfile.process = process; + for (; currNodePtr != nullptr; currNodePtr = currNodePtr->next) { + if (currNodePtr->name == nullptr || currNodePtr->type == XML_COMMENT_NODE) { + continue; + } + auto contentPtr = xmlNodeGetContent(currNodePtr); + if (contentPtr == nullptr) { + continue; + } + string nodeName(reinterpret_cast(currNodePtr->name)); + string nodeContent(reinterpret_cast(contentPtr)); + ParseSAProp(nodeName, nodeContent, saProfile); + xmlFree(contentPtr); + } + saProfiles_.emplace_back(saProfile); + return true; +} + +bool ParseUtil::ParseProcess(const xmlNodePtr& rootNode, std::u16string& processName) +{ + if (rootNode->name == nullptr || rootNode->type == XML_COMMENT_NODE) { + return false; + } + auto contentPtr = xmlNodeGetContent(rootNode); + if (contentPtr == nullptr) { + return false; + } + string nodeContent(reinterpret_cast(contentPtr)); + processName = Str8ToStr16(nodeContent); + xmlFree(contentPtr); + return true; +} + +bool ParseUtil::ParseSaProfiles(const string& profilePath) +{ + HILOGI("xmlFile:%{private}s", profilePath.c_str()); + if (!CheckPathExist(profilePath.c_str())) { + HILOGE("bad profile path!"); + return false; + } + std::unique_ptr ptrDoc( + xmlReadFile(profilePath.c_str(), nullptr, XML_PARSE_NOBLANKS), xmlFreeDoc); + + if (ptrDoc == nullptr) { + HILOGE("xmlReadFile error!"); + return false; + } + xmlNodePtr rootNodePtr = xmlDocGetRootElement(ptrDoc.get()); + if (!CheckRootTag(rootNodePtr)) { + HILOGW("wrong root element tag!"); + return false; + } + bool isParseCorrect = false; + xmlNodePtr currNodePtr = rootNodePtr->xmlChildrenNode; + std::u16string process = u""; + for (; currNodePtr != nullptr; currNodePtr = currNodePtr->next) { + if (currNodePtr->name == nullptr || currNodePtr->type == XML_COMMENT_NODE) { + continue; + } + + string nodeName(reinterpret_cast(currNodePtr->name)); + HILOGI("profile nodeName:%{public}s", nodeName.c_str()); + if (nodeName == XML_TAG_PROCESS && process.empty()) { + if (!ParseProcess(currNodePtr, process)) { + HILOGW("profile %{public}s wrong tag!", currNodePtr->name); + return false; + } + } + if (nodeName == XML_TAG_SYSTEM_ABILITY) { + if (!ParseSystemAbility(*currNodePtr, process)) { + HILOGW("profile %{public}s wrong tag!", currNodePtr->name); + return false; + } + isParseCorrect = true; + } + } + procName_ = process; + return isParseCorrect; +} + +std::u16string ParseUtil::GetProcessName() const +{ + return procName_; +} + +bool ParseUtil::CheckPathExist(const string& profilePath) +{ + std::ifstream profileStream(profilePath.c_str()); + return profileStream.good(); +} + +bool ParseUtil::ParseTrustConfig(const string& profilePath, + std::map>& values) +{ + HILOGI("config path:%{private}s", profilePath.c_str()); + if (!CheckPathExist(profilePath.c_str())) { + HILOGE("bad profile path!"); + return false; + } + std::unique_ptr docPtr( + xmlReadFile(profilePath.c_str(), nullptr, XML_PARSE_NOBLANKS), xmlFreeDoc); + if (docPtr == nullptr) { + HILOGE("ParseTrustConfig xmlReadFile error!"); + return false; + } + xmlNodePtr rootNodePtr = xmlDocGetRootElement(docPtr.get()); + if (!CheckRootTag(rootNodePtr)) { + HILOGW("ParseTrustConfig wrong root element tag!"); + return false; + } + + return ParseTrustConfigInner(rootNodePtr, values); +} + +bool ParseUtil::CheckRootTag(const xmlNodePtr& rootNodePtr) +{ + if (rootNodePtr == nullptr || rootNodePtr->name == nullptr || + (xmlStrcmp(rootNodePtr->name, reinterpret_cast(XML_TAG_PROFILE)) != 0 && + xmlStrcmp(rootNodePtr->name, reinterpret_cast(XML_TAG_INFO)) != 0)) { + return false; + } + return true; +} + +bool ParseUtil::ParseTrustConfigInner(const xmlNodePtr& rootNodePtr, + std::map>& values) +{ + xmlNodePtr currNodePtr = rootNodePtr->xmlChildrenNode; + if (currNodePtr == nullptr) { + return false; + } + std::u16string processName = u""; + for (; currNodePtr != nullptr; currNodePtr = currNodePtr->next) { + if (currNodePtr->name == nullptr || currNodePtr->type == XML_COMMENT_NODE) { + continue; + } + + string nodeName(reinterpret_cast(currNodePtr->name)); + HILOGI("profile nodeName:%{public}s", nodeName.c_str()); + + if (nodeName == XML_TAG_NAME && processName.empty()) { + // parse process name + if (!ParseProcess(currNodePtr, processName)) { + HILOGE("ParseTrustConfigInner wrong name tag!"); + return false; + } + } else if (nodeName == XML_TAG_SAID) { + // parse said + int32_t saId = -1; + if (!ParseSaId(currNodePtr, saId)) { + HILOGE("ParseTrustConfigInner wrong said tag!"); + continue; + } + auto& saIds = values[processName]; + saIds.emplace(saId); + } + } + return true; +} + +bool ParseUtil::ParseSaId(const xmlNodePtr& rootNode, int32_t& saId) +{ + if (rootNode->name == nullptr || rootNode->type == XML_COMMENT_NODE) { + return false; + } + auto contentPtr = xmlNodeGetContent(rootNode); + if (contentPtr == nullptr) { + return false; + } + string nodeContent(reinterpret_cast(contentPtr)); + bool ret = StrToInt(nodeContent.c_str(), saId); + xmlFree(contentPtr); + return ret; +} +} // namespace OHOS diff --git a/services/common/test/BUILD.gn b/services/common/test/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..1f43d59e13822fb2b4aca48bded54504c55d61b8 --- /dev/null +++ b/services/common/test/BUILD.gn @@ -0,0 +1,19 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") + +group("unittest") { + testonly = true + deps = [ "unittest:unittest" ] +} diff --git a/services/common/test/unittest/BUILD.gn b/services/common/test/unittest/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..57269998281b63b8b01ca54400e595e10f56f18c --- /dev/null +++ b/services/common/test/unittest/BUILD.gn @@ -0,0 +1,48 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") + +module_output_path = "samgr/samgr" + +ohos_unittest("ParseUtilTest") { + module_out_path = module_output_path + resource_config_file = + "//foundation/distributedschedule/samgr/test/resource/ohos_test.xml" + + include_dirs = [ + "//foundation/distributedschedule/samgr/interfaces/innerkits/common/include", + "//foundation/distributedschedule/samgr/utils/native/include", + ] + + sources = [ "./parse_util_test.cpp" ] + + deps = [ + "//foundation/distributedschedule/samgr/interfaces/innerkits/common:samgr_common", + "//third_party/googletest:gtest_main", + ] + + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + + external_deps = [ "utils_base:utils" ] + + public_deps = [ "//third_party/libxml2:libxml2" ] +} + +group("unittest") { + testonly = true + deps = [ ":ParseUtilTest" ] +} diff --git a/services/common/test/unittest/parse_util_test.cpp b/services/common/test/unittest/parse_util_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..8792bfec64a0e15a633ee45f1483aeade9098d0a --- /dev/null +++ b/services/common/test/unittest/parse_util_test.cpp @@ -0,0 +1,495 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include "parse_util.h" +#include "string_ex.h" +#include "test_log.h" + +using namespace std; +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace SAMGR { +namespace { + const std::string TEST_RESOURCE_PATH = "/data/test/resource/samgr/profile/"; + const std::u16string TEST_PROCESS_NAME = u"sa_test"; + const int32_t TEST_PROFILE_SAID = 9999; +} + +class ParseUtilTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +protected: + std::shared_ptr parser_; +}; + +void ParseUtilTest::SetUpTestCase() +{ + DTEST_LOG << "SetUpTestCase" << std::endl; +} + +void ParseUtilTest::TearDownTestCase() +{ + DTEST_LOG << "TearDownTestCase" << std::endl; +} + +void ParseUtilTest::SetUp() +{ + DTEST_LOG << "SetUp" << std::endl; + if (parser_ == nullptr) { + parser_ = std::make_shared(); + } +} + +void ParseUtilTest::TearDown() +{ + DTEST_LOG << "TearDown" << std::endl; + if (parser_ != nullptr) { + parser_->ClearResource(); + } +} + +/** + * @tc.name: ParseSaProfile001 + * @tc.desc: Verify if can load not exist file + * @tc.type: FUNC + * @tc.require: AR000GGVQF + */ +HWTEST_F(ParseUtilTest, ParseSaProfile001, TestSize.Level1) +{ + DTEST_LOG << " ParseSaProfile001 start " << std::endl; + /** + * @tc.steps: step1. parse not exsit config file + * @tc.expected: step1. return false when load not exist file + */ + bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "notExist"); + EXPECT_FALSE(ret); +} + +/** + * @tc.name: ParseSaProfile002 + * @tc.desc: Verify if can load invalid root file + * @tc.type: FUNC + * @tc.require: SR000GGVP1 + */ +HWTEST_F(ParseUtilTest, ParseSaProfile002, TestSize.Level1) +{ + DTEST_LOG << " ParseSaProfile002 start " << std::endl; + /** + * @tc.steps: step1. load invalid root config file + * @tc.expected: step1. return false when load invalid format config file + */ + bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "invalid_root.xml"); + EXPECT_FALSE(ret); +} + +/** + * @tc.name: ParseSaProfile003 + * @tc.desc: Verify if can load normal profile + * @tc.type: FUNC + * @tc.require: AR000GGVQF + */ +HWTEST_F(ParseUtilTest, ParseSaProfile003, TestSize.Level1) +{ + DTEST_LOG << " ParseSaProfile003 start " << std::endl; + /** + * @tc.steps: step1. load correct system ability profile + * @tc.expected: step1. return true when load invalid format config file + */ + bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "profile.xml"); + EXPECT_TRUE(ret); +} + +/** + * @tc.name: GetSaProfiles001 + * @tc.desc: Verify if not load sa file return empty list + * @tc.type: FUNC + * @tc.require: SR000GGVP1 + */ +HWTEST_F(ParseUtilTest, GetSaProfiles001, TestSize.Level1) +{ + DTEST_LOG << " GetSaProfiles001 start " << std::endl; + /** + * @tc.steps: step1. Get empty config when not parse sa file. + * @tc.expected: step1. return empty list when not load sa file + */ + list profiles = parser_->GetAllSaProfiles(); + EXPECT_TRUE(profiles.empty()); +} + +/** + * @tc.name: GetSaProfiles002 + * @tc.desc: Verify if can load normal sa profile + * @tc.type: FUNC + * @tc.require: SR000GGVP1 + */ +HWTEST_F(ParseUtilTest, GetSaProfiles002, TestSize.Level1) +{ + DTEST_LOG << " GetSaProfiles002 start " << std::endl; + /** + * @tc.steps: step1. Get correct profile when parse sa file. + * @tc.expected: step1. return correct profile object when load correct config file + */ + bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "profile.xml"); + ASSERT_TRUE(ret); + list profiles = parser_->GetAllSaProfiles(); + if (!profiles.empty()) { + SaProfile& profile = *(profiles.begin()); + EXPECT_EQ(profile.process, TEST_PROCESS_NAME); + EXPECT_EQ(profile.saId, TEST_PROFILE_SAID); + } +} + +/** + * @tc.name: ParseTrustConfig001 + * @tc.desc: Verify if can load file with one sa + * @tc.type: FUNC + * @tc.require: AR000GICSU + */ +HWTEST_F(ParseUtilTest, ParseTrustConfig001, TestSize.Level1) +{ + DTEST_LOG << " ParseTrustConfig001 start " << std::endl; + /** + * @tc.steps: step1. Get correct map when parse config file. + * @tc.expected: step1. return correct profile object when load correct config file + */ + std::map> values; + bool ret = parser_->ParseTrustConfig(TEST_RESOURCE_PATH + "test_trust_one_sa.xml", values); + ASSERT_TRUE(ret); + /** + * @tc.steps: step2. Check map values + * @tc.expected: step2. return expect values + */ + for (const auto& [process, saIds] : values) { + EXPECT_EQ(Str16ToStr8(process), "test"); + EXPECT_EQ(saIds.size(), 1); + EXPECT_EQ(saIds.count(1401), 1); + } +} + +/** + * @tc.name: ParseTrustConfig002 + * @tc.desc: Verify if can load file with muti sa + * @tc.type: FUNC + * @tc.require: AR000GICSU + */ +HWTEST_F(ParseUtilTest, ParseTrustConfig002, TestSize.Level1) +{ + DTEST_LOG << " ParseTrustConfig002 start " << std::endl; + /** + * @tc.steps: step1. Get correct map when parse config file. + * @tc.expected: step1. return correct profile object when load correct config file + */ + std::map> values; + bool ret = parser_->ParseTrustConfig(TEST_RESOURCE_PATH + "test_trust_muti_sa.xml", values); + ASSERT_TRUE(ret); + /** + * @tc.steps: step2. Check map values + * @tc.expected: step2. return expect values + */ + for (const auto& [process, saIds] : values) { + EXPECT_EQ(Str16ToStr8(process), "test"); + EXPECT_EQ(saIds.size(), 5); + EXPECT_EQ(saIds.count(1401), 1); + } +} + +/** + * @tc.name: ParseTrustConfig003 + * @tc.desc: Verify if can load not invalid root file + * @tc.type: FUNC + * @tc.require: AR000GICSU + */ +HWTEST_F(ParseUtilTest, ParseTrustConfig003, TestSize.Level1) +{ + DTEST_LOG << " ParseTrustConfig003 start " << std::endl; + /** + * @tc.steps: step1. Get correct map when parse config file. + * @tc.expected: step1. return false when load invalid root file + */ + std::map> values; + bool ret = parser_->ParseTrustConfig(TEST_RESOURCE_PATH + "invalid_root_trust.xml", values); + ASSERT_FALSE(ret); +} + +/** + * @tc.name: ParseTrustConfig004 + * @tc.desc: Verify if can load not exist file + * @tc.type: FUNC + * @tc.require: AR000GICSU + */ +HWTEST_F(ParseUtilTest, ParseTrustConfig004, TestSize.Level1) +{ + DTEST_LOG << " ParseTrustConfig004 start " << std::endl; + /** + * @tc.steps: step1. Get correct profile when parse sa file. + * @tc.expected: step1. return false when not exist file + */ + std::map> values; + bool ret = parser_->ParseTrustConfig(TEST_RESOURCE_PATH + "notExist", values); + ASSERT_FALSE(ret); +} + +/** + * @tc.name: ParseTrustConfig005 + * @tc.desc: Verify if can load invalid element config + * @tc.type: FUNC + * @tc.require: AR000GICSU + */ +HWTEST_F(ParseUtilTest, ParseTrustConfig005, TestSize.Level1) +{ + DTEST_LOG << " ParseTrustConfig005 start " << std::endl; + /** + * @tc.steps: step1. Get correct profile when parse invalid element config. + * @tc.expected: step1. return correct profile object when load correct config file + */ + std::map> values; + bool ret = parser_->ParseTrustConfig(TEST_RESOURCE_PATH + "invalid_element_trust.xml", values); + ASSERT_TRUE(ret); + for (const auto& [process, saIds] : values) { + EXPECT_EQ(Str16ToStr8(process), "test"); + EXPECT_EQ(saIds.size(), 3); + EXPECT_EQ(saIds.count(1401), 1); + } +} + +/** + * @tc.name: ParseTrustConfig006 + * @tc.desc: Verify if can load invalid muti root file + * @tc.type: FUNC + * @tc.require: AR000GICSU + */ +HWTEST_F(ParseUtilTest, ParseTrustConfig006, TestSize.Level1) +{ + DTEST_LOG << " ParseTrustConfig006 start " << std::endl; + /** + * @tc.steps: step1. Get correct profile when parse sa file. + * @tc.expected: step1. return correct profile object when load correct config file + */ + std::map> values; + bool ret = parser_->ParseTrustConfig(TEST_RESOURCE_PATH + "invalid_muti_root_trust.xml", values); + ASSERT_FALSE(ret); +} + +/** + * @tc.name: RemoveSaProfile001 + * @tc.desc: Verify if can remove not-existed id + * @tc.type: FUNC + * @tc.require: AR000GICSU + */ +HWTEST_F(ParseUtilTest, RemoveSaProfile001, TestSize.Level1) +{ + DTEST_LOG << " RemoveSaProfile001 start " << std::endl; + /** + * @tc.steps: step1. parse not exsit config file + * @tc.expected: step1. return false when load not exist file + */ + bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "notExist"); + EXPECT_FALSE(ret); + /** + * @tc.steps: step2. remove not-existed id + * @tc.expected: step2. not crash + */ + parser_->RemoveSaProfile(111); + auto profiles = parser_->GetAllSaProfiles(); + EXPECT_EQ(profiles.size(), 0); +} + +/** + * @tc.name: RemoveSaProfile002 + * @tc.desc: Verify if can can remove not-existed id + * @tc.type: FUNC + * @tc.require: AR000GICSU + */ +HWTEST_F(ParseUtilTest, RemoveSaProfile002, TestSize.Level1) +{ + DTEST_LOG << " RemoveSaProfile002 start " << std::endl; + /** + * @tc.steps: step1. parse multi-sa profile + * @tc.expected: step1. return true when load multi-sa profile + */ + bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "multi_sa_profile.xml"); + EXPECT_TRUE(ret); + auto profiles = parser_->GetAllSaProfiles(); + EXPECT_EQ(profiles.size(), 4); + /** + * @tc.steps: step2. remove not-existed id + * @tc.expected: step2. not crash + */ + parser_->RemoveSaProfile(111); + profiles = parser_->GetAllSaProfiles(); + EXPECT_EQ(profiles.size(), 4); +} + +/** + * @tc.name: RemoveSaProfile003 + * @tc.desc: Verify if can remove one existed id + * @tc.type: FUNC + * @tc.require: AR000GICSU + */ +HWTEST_F(ParseUtilTest, RemoveSaProfile003, TestSize.Level1) +{ + DTEST_LOG << " RemoveSaProfile003 start " << std::endl; + /** + * @tc.steps: step1. parse multi-sa profile + * @tc.expected: step1. return true when load multi-sa profile + */ + bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "multi_sa_profile.xml"); + EXPECT_TRUE(ret); + auto profiles = parser_->GetAllSaProfiles(); + EXPECT_EQ(profiles.size(), 4); + /** + * @tc.steps: step2. remove one existed id + * @tc.expected: step2. remove successed + */ + parser_->RemoveSaProfile(9999); + profiles = parser_->GetAllSaProfiles(); + EXPECT_EQ(profiles.size(), 3); +} + +/** + * @tc.name: RemoveSaProfile004 + * @tc.desc: Verify if can remove one existed id + * @tc.type: FUNC + * @tc.require: AR000GICSU + */ +HWTEST_F(ParseUtilTest, RemoveSaProfile004, TestSize.Level1) +{ + DTEST_LOG << " RemoveSaProfile004 start " << std::endl; + /** + * @tc.steps: step1. parse multi-sa profile + * @tc.expected: step1. return true when load multi-sa profile + */ + bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "multi_sa_profile.xml"); + EXPECT_TRUE(ret); + auto profiles = parser_->GetAllSaProfiles(); + EXPECT_EQ(profiles.size(), 4); + /** + * @tc.steps: step2. remove one existed id + * @tc.expected: step2. remove successed + */ + parser_->RemoveSaProfile(9997); + profiles = parser_->GetAllSaProfiles(); + EXPECT_EQ(profiles.size(), 2); +} + +/** + * @tc.name: RemoveSaProfile005 + * @tc.desc: Verify if can remove more existed id + * @tc.type: FUNC + * @tc.require: AR000GICSU + */ +HWTEST_F(ParseUtilTest, RemoveSaProfile005, TestSize.Level1) +{ + DTEST_LOG << " RemoveSaProfile004 start " << std::endl; + /** + * @tc.steps: step1. parse multi-sa profile + * @tc.expected: step1. return true when load multi-sa profile + */ + bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "multi_sa_profile.xml"); + EXPECT_TRUE(ret); + auto profiles = parser_->GetAllSaProfiles(); + EXPECT_EQ(profiles.size(), 4); + /** + * @tc.steps: step2. remove more existed id + * @tc.expected: step2. remove successed + */ + parser_->RemoveSaProfile(9997); + parser_->RemoveSaProfile(9998); + parser_->RemoveSaProfile(9998); + profiles = parser_->GetAllSaProfiles(); + EXPECT_EQ(profiles.size(), 1); +} + +/** + * @tc.name: CheckPathExist001 + * @tc.desc: Verify if can check not exist file + * @tc.type: FUNC + * @tc.require: AR000GICSU + */ +HWTEST_F(ParseUtilTest, CheckPathExist001, TestSize.Level1) +{ + DTEST_LOG << " CheckPathExist001 start " << std::endl; + /** + * @tc.steps: step1. check not exsit config file + * @tc.expected: step1. return false when check not exist file + */ + bool ret = parser_->CheckPathExist(TEST_RESOURCE_PATH + "not_exist.xml"); + EXPECT_FALSE(ret); +} + +/** + * @tc.name: CheckPathExist002 + * @tc.desc: Verify if can check exist file + * @tc.type: FUNC + * @tc.require: AR000GICSU + */ +HWTEST_F(ParseUtilTest, CheckPathExist002, TestSize.Level1) +{ + DTEST_LOG << " CheckPathExist002 start " << std::endl; + /** + * @tc.steps: step1. check exsit config file + * @tc.expected: step1. return true when load not exist file + */ + bool ret = parser_->CheckPathExist(TEST_RESOURCE_PATH + "multi_sa_profile.xml"); + EXPECT_TRUE(ret); +} + +/** + * @tc.name: GetProfile001 + * @tc.desc: Verify if can get not-exist profile + * @tc.type: FUNC + * @tc.require: AR000GH56I + */ +HWTEST_F(ParseUtilTest, GetProfile001, TestSize.Level1) +{ + DTEST_LOG << " GetProfile001 start " << std::endl; + /** + * @tc.steps: step1. check exsit config file + * @tc.expected: step1. return true when load not exist file + */ + SaProfile saProfile; + bool ret = parser_->GetProfile(9999, saProfile); + EXPECT_FALSE(ret); +} + +/** + * @tc.name: GetProfile002 + * @tc.desc: Verify if can get exist profile + * @tc.type: FUNC + * @tc.require: AR000GH56I + */ +HWTEST_F(ParseUtilTest, GetProfile002, TestSize.Level1) +{ + DTEST_LOG << " GetProfile002 start " << std::endl; + /** + * @tc.steps: step1. check exsit config file + * @tc.expected: step1. return true when load not exist file + */ + bool ret = parser_->ParseSaProfiles(TEST_RESOURCE_PATH + "multi_sa_profile.xml"); + EXPECT_TRUE(ret); + SaProfile saProfile; + ret = parser_->GetProfile(9999, saProfile); + EXPECT_TRUE(ret); + EXPECT_EQ(saProfile.saId, 9999); + EXPECT_TRUE(saProfile.runOnCreate); +} +} // namespace SAMGR +} // namespace OHOS diff --git a/services/samgr/native/BUILD.gn b/services/samgr/native/BUILD.gn index b8433036c16364e332c41da2531c5691ca29d737..db125811cbe395dc63e65a2c842b3d61b290b260 100755 --- a/services/samgr/native/BUILD.gn +++ b/services/samgr/native/BUILD.gn @@ -33,6 +33,7 @@ config("sam_config") { "//utils/native/base/include", "//utils/system/safwk/native/include", "//foundation/distributedschedule/samgr/services/lsamgr/include", + "//foundation/distributedschedule/samgr/interfaces/innerkits/common/include", ] } @@ -63,7 +64,7 @@ ohos_executable("samgr") { ] deps = [ - "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", + "//foundation/distributedschedule/samgr/interfaces/innerkits/common:samgr_common", "//foundation/distributedschedule/samgr/interfaces/innerkits/lsamgr:lsamgr", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "//utils/native/base:utils", @@ -71,6 +72,7 @@ ohos_executable("samgr") { configs = [ ":sam_config", + "//foundation/distributedschedule/samgr/interfaces/innerkits/common:config_samgr_common", "//foundation/distributedschedule/samgr/interfaces/innerkits/lsamgr:config_samgr", ":distributed_store_config", ] diff --git a/services/samgr/native/test/unittest/BUILD.gn b/services/samgr/native/test/unittest/BUILD.gn index 8271d5363dd4969172c4653d6980914a2533a248..7f948fb6d9d7330c77fb0b1910bfe827c2998019 100755 --- a/services/samgr/native/test/unittest/BUILD.gn +++ b/services/samgr/native/test/unittest/BUILD.gn @@ -48,9 +48,9 @@ ohos_unittest("SystemAbilityMgrTest") { } deps = [ + "${samgr_dir}/interfaces/innerkits/common:samgr_common", "${samgr_dir}/interfaces/innerkits/lsamgr:lsamgr", "${samgr_dir}/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", "//third_party/googletest:gtest_main", "//utils/native/base:utils", ] diff --git a/test/resource/ohos_test.xml b/test/resource/ohos_test.xml new file mode 100755 index 0000000000000000000000000000000000000000..3b843f584925d74a635c266be880dcb5f055b639 --- /dev/null +++ b/test/resource/ohos_test.xml @@ -0,0 +1,30 @@ + + + + + + + + diff --git a/test/resource/profile/invalid_element_trust.xml b/test/resource/profile/invalid_element_trust.xml new file mode 100755 index 0000000000000000000000000000000000000000..cfb7128e9bead33ec593b9f6928e4d55418af520 --- /dev/null +++ b/test/resource/profile/invalid_element_trust.xml @@ -0,0 +1,30 @@ + + + + test + test_two + test_three + 1401 + hhh + true + false + 1402 + 1402 + -1 + 1111111111111111111 + ./~ + 0 + + diff --git a/test/resource/profile/invalid_muti_root_trust.xml b/test/resource/profile/invalid_muti_root_trust.xml new file mode 100755 index 0000000000000000000000000000000000000000..6eccd0be1f35e4917e9a4f1881a28628637501dc --- /dev/null +++ b/test/resource/profile/invalid_muti_root_trust.xml @@ -0,0 +1,26 @@ + + + + test + 1401 + 1402 + 1403 + 1404 + 1405 + + + TEST + 1401 + diff --git a/test/resource/profile/invalid_root.xml b/test/resource/profile/invalid_root.xml new file mode 100755 index 0000000000000000000000000000000000000000..9b747a63b46d343965434941956a68cea6040cf5 --- /dev/null +++ b/test/resource/profile/invalid_root.xml @@ -0,0 +1,28 @@ + + + + + liboos_ability.z.so + + + 1492 + liboos_ability.z.so + + + true + true + 1 + + diff --git a/test/resource/profile/invalid_root_trust.xml b/test/resource/profile/invalid_root_trust.xml new file mode 100755 index 0000000000000000000000000000000000000000..1ae762f77bcafbec60a9b12285ce5e47ac5d4d8f --- /dev/null +++ b/test/resource/profile/invalid_root_trust.xml @@ -0,0 +1,22 @@ + + + + test + 1401 + 1402 + 1403 + 1404 + 1405 + diff --git a/test/resource/profile/multi_sa_profile.xml b/test/resource/profile/multi_sa_profile.xml new file mode 100755 index 0000000000000000000000000000000000000000..3457054bd7157e81e4737de7c13140b6569f4de7 --- /dev/null +++ b/test/resource/profile/multi_sa_profile.xml @@ -0,0 +1,51 @@ + + + + test + + liboos_ability.z.so + liboos_ability.z.so + liboos_ability.z.so + liboos_ability.z.so + + + 9999 + liboos_ability.z.so + true + false + 1 + + + 9998 + liboos_ability.z.so + true + false + 1 + + + 9997 + liboos_ability.z.so + true + false + 1 + + + 9997 + liboos_ability.z.so + true + false + 1 + + diff --git a/test/resource/profile/profile.xml b/test/resource/profile/profile.xml new file mode 100755 index 0000000000000000000000000000000000000000..02242039b0772dda3329060264300ff1ec770d78 --- /dev/null +++ b/test/resource/profile/profile.xml @@ -0,0 +1,27 @@ + + + + sa_test + + liboos_ability.z.so + + + 9999 + liboos_ability.z.so + true + false + 1 + + diff --git a/test/resource/profile/profile_audio.xml b/test/resource/profile/profile_audio.xml new file mode 100755 index 0000000000000000000000000000000000000000..262edb965a39f3b5a2d041012263e4f62656087e --- /dev/null +++ b/test/resource/profile/profile_audio.xml @@ -0,0 +1,48 @@ + + + + + libtest_audio_ability.z.so + libtest_ondemand_ability.z.so + + profile_audio + + 1499 + libtest_audio_ability.z.so + + + true + false + 1 + + + 1497 + libtest_ondemand_ability.z.so + + + true + false + 1 + + + 1496 + libincomplete_ability.z.so + + + false + false + + + diff --git a/test/resource/profile/test_trust_all_allow.xml b/test/resource/profile/test_trust_all_allow.xml new file mode 100755 index 0000000000000000000000000000000000000000..0b88eb2213012fc7388ea47004c97f95d08002f2 --- /dev/null +++ b/test/resource/profile/test_trust_all_allow.xml @@ -0,0 +1,20 @@ + + + + test + 9999 + 9998 + 9997 + diff --git a/test/resource/profile/test_trust_muti_sa.xml b/test/resource/profile/test_trust_muti_sa.xml new file mode 100755 index 0000000000000000000000000000000000000000..ffd246dfd52d606bf4bb1a90e02f2c95ac2f000e --- /dev/null +++ b/test/resource/profile/test_trust_muti_sa.xml @@ -0,0 +1,22 @@ + + + + test + 1401 + 1402 + 1403 + 1404 + 1405 + diff --git a/test/resource/profile/test_trust_not_all_allow.xml b/test/resource/profile/test_trust_not_all_allow.xml new file mode 100755 index 0000000000000000000000000000000000000000..2e91091b42a211976095c53a67e4e14119dc9158 --- /dev/null +++ b/test/resource/profile/test_trust_not_all_allow.xml @@ -0,0 +1,19 @@ + + + + test + 9999 + 9998 + diff --git a/test/resource/profile/test_trust_one_sa.xml b/test/resource/profile/test_trust_one_sa.xml new file mode 100755 index 0000000000000000000000000000000000000000..7ccb3a2f9973a53a34a2ba6d745265ef98474947 --- /dev/null +++ b/test/resource/profile/test_trust_one_sa.xml @@ -0,0 +1,18 @@ + + + + test + 1401 + diff --git a/utils/native/include/test_log.h b/utils/native/include/test_log.h new file mode 100755 index 0000000000000000000000000000000000000000..f3e30f986433900d729296710f7dea4a5fddf7e5 --- /dev/null +++ b/utils/native/include/test_log.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SAMGR_UTIL_NATIVE_INCLUDE_TEST_LOG_H +#define SAMGR_UTIL_NATIVE_INCLUDE_TEST_LOG_H +namespace OHOS { +#define DTEST_LOG std::cout << __FILE__ << ":" << __LINE__ << ":" +} // namespace OHOS +#endif /* SAMGR_UTIL_NATIVE_INCLUDE_TEST_LOG_H */