100600bfbSopenharmony_ci/*
200600bfbSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
300600bfbSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
400600bfbSopenharmony_ci * you may not use this file except in compliance with the License.
500600bfbSopenharmony_ci * You may obtain a copy of the License at
600600bfbSopenharmony_ci *
700600bfbSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
800600bfbSopenharmony_ci *
900600bfbSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1000600bfbSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1100600bfbSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1200600bfbSopenharmony_ci * See the License for the specific language governing permissions and
1300600bfbSopenharmony_ci * limitations under the License.
1400600bfbSopenharmony_ci */
1500600bfbSopenharmony_ci#include "dump_utils.h"
1600600bfbSopenharmony_ci
1700600bfbSopenharmony_ci#include <cerrno>
1800600bfbSopenharmony_ci#include <csignal>
1900600bfbSopenharmony_ci#include <fcntl.h>
2000600bfbSopenharmony_ci#include <poll.h>
2100600bfbSopenharmony_ci#include <set>
2200600bfbSopenharmony_ci#include <map>
2300600bfbSopenharmony_ci#include <sys/stat.h>
2400600bfbSopenharmony_ci#include <sys/utsname.h>
2500600bfbSopenharmony_ci#include <unistd.h>
2600600bfbSopenharmony_ci#include <fstream>
2700600bfbSopenharmony_ci#include <iostream>
2800600bfbSopenharmony_ci
2900600bfbSopenharmony_ci#include <sys/prctl.h>
3000600bfbSopenharmony_ci#include <sys/resource.h>
3100600bfbSopenharmony_ci#include <sys/times.h>
3200600bfbSopenharmony_ci#include <sys/types.h>
3300600bfbSopenharmony_ci#include <sys/wait.h>
3400600bfbSopenharmony_ci
3500600bfbSopenharmony_ci#include "common.h"
3600600bfbSopenharmony_ci#include "datetime_ex.h"
3700600bfbSopenharmony_ci#include "file_ex.h"
3800600bfbSopenharmony_ci#include "iservice_registry.h"
3900600bfbSopenharmony_ci#include "parameters.h"
4000600bfbSopenharmony_ci#include "securec.h"
4100600bfbSopenharmony_ci#include "string_ex.h"
4200600bfbSopenharmony_ci
4300600bfbSopenharmony_ci#include "system_ability_definition.h"
4400600bfbSopenharmony_ci#include "hilog_wrapper.h"
4500600bfbSopenharmony_ci
4600600bfbSopenharmony_ci#ifdef HIDUMPER_BUNDLEMANAGER_FRAMEWORK_ENABLE
4700600bfbSopenharmony_ci#include "application_info.h"
4800600bfbSopenharmony_ci#include "bundlemgr/bundle_mgr_proxy.h"
4900600bfbSopenharmony_ci#endif
5000600bfbSopenharmony_ci
5100600bfbSopenharmony_cinamespace OHOS {
5200600bfbSopenharmony_ciinline const std::map<int, std::string> saNameMap_ = {
5300600bfbSopenharmony_ci    { 0, "SystemAbilityManager" },
5400600bfbSopenharmony_ci    { 200, "AccountMgr" },
5500600bfbSopenharmony_ci    { 301, "AIEngine" },
5600600bfbSopenharmony_ci    { ABILITY_MGR_SERVICE_ID, "AbilityManagerService" },
5700600bfbSopenharmony_ci    { DATAOBS_MGR_SERVICE_SA_ID, "DataObserverMgr" },
5800600bfbSopenharmony_ci    { APP_MGR_SERVICE_ID, "ApplicationManagerService" },
5900600bfbSopenharmony_ci    { URI_PERMISSION_MGR_SERVICE_ID, "UriPermissionMgr" },
6000600bfbSopenharmony_ci    { QUICK_FIX_MGR_SERVICE_ID, "QuickFixMgrService"},
6100600bfbSopenharmony_ci    { BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, "BundleMgr" },
6200600bfbSopenharmony_ci    { SERVICE_ROUTER_MGR_SERVICE_ID, "ServiceRouterMgr" },
6300600bfbSopenharmony_ci    { INSTALLD_SERVICE_ID, "Installd" },
6400600bfbSopenharmony_ci    { FORM_MGR_SERVICE_ID, "FormMgr" },
6500600bfbSopenharmony_ci    { WIFI_DEVICE_SYS_ABILITY_ID, "WifiDevice" },
6600600bfbSopenharmony_ci    { WIFI_HOTSPOT_SYS_ABILITY_ID, "WifiHotspot" },
6700600bfbSopenharmony_ci    { WIFI_ENHANCER_SYS_ABILITY_ID, "WifiEnhancer" },
6800600bfbSopenharmony_ci    { WIFI_P2P_SYS_ABILITY_ID, "WifiP2p" },
6900600bfbSopenharmony_ci    { WIFI_SCAN_SYS_ABILITY_ID, "WifiScan" },
7000600bfbSopenharmony_ci    { BLUETOOTH_HOST_SYS_ABILITY_ID, "BluetoothHost" },
7100600bfbSopenharmony_ci    { NFC_MANAGER_SYS_ABILITY_ID, "NfcManager" },
7200600bfbSopenharmony_ci    { SE_MANAGER_SYS_ABILITY_ID, "SeManager" },
7300600bfbSopenharmony_ci    { NET_MANAGER_SYS_ABILITY_ID, "NetManager" },
7400600bfbSopenharmony_ci    { DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID, "DistributedKvData" },
7500600bfbSopenharmony_ci    { DISTRIBUTED_SCHED_SA_ID, "DistributedSched" },
7600600bfbSopenharmony_ci    { DISTRIBUTED_SCHED_ADAPTER_SA_ID, "DistributedSchedAdapter" },
7700600bfbSopenharmony_ci    { DISTRIBUTED_SCENARIO_MGR_SA_ID, "DistributedScenarioMgr" },
7800600bfbSopenharmony_ci    { CONTINUATION_MANAGER_SA_ID, "ContinuationManagerService" },
7900600bfbSopenharmony_ci    { RES_SCHED_SYS_ABILITY_ID, "ResourceSched" },
8000600bfbSopenharmony_ci    { RESSCHEDD_SA_ID, "ResourceSchedDamon" },
8100600bfbSopenharmony_ci    { BACKGROUND_TASK_MANAGER_SERVICE_ID, "BackgroundTaskManager" },
8200600bfbSopenharmony_ci    { WORK_SCHEDULE_SERVICE_ID, "WorkSchedule" },
8300600bfbSopenharmony_ci    { CONCURRENT_TASK_SERVICE_ID, "ConcurrentTaskService" },
8400600bfbSopenharmony_ci    { RESOURCE_QUOTA_CONTROL_SYSTEM_ABILITY_ID, "ResourceQuotaControl"},
8500600bfbSopenharmony_ci    { DEVICE_STANDBY_SERVICE_SYSTEM_ABILITY_ID, "DeviceStandbyService"},
8600600bfbSopenharmony_ci    { TASK_HEARTBEAT_MGR_SYSTEM_ABILITY_ID, "TaskHeartbeatMgrService"},
8700600bfbSopenharmony_ci    { COMPONENT_SCHEDULE_SERVICE_ID, "ComponentSchedServer" },
8800600bfbSopenharmony_ci    { SOC_PERF_SERVICE_SA_ID, "SocPerfService" },
8900600bfbSopenharmony_ci    { SUSPEND_MANAGER_SYSTEM_ABILITY_ID, "SuspendManager" },
9000600bfbSopenharmony_ci    { APP_NAP_SYSTEM_ABILITY_ID, "AppNap" },
9100600bfbSopenharmony_ci    { ABNORMAL_EFFICIENCY_MGR_SYSTEM_ABILITY_ID, "AbnormalEfficiencyManager" },
9200600bfbSopenharmony_ci    { LOCATION_GEO_CONVERT_SA_ID, "LocationGeoConvert" },
9300600bfbSopenharmony_ci    { LOCATION_LOCATOR_SA_ID, "LocationLocator" },
9400600bfbSopenharmony_ci    { LOCATION_GNSS_SA_ID, "LocationGnss" },
9500600bfbSopenharmony_ci    { LOCATION_NETWORK_LOCATING_SA_ID, "LocationNetworkLocating" },
9600600bfbSopenharmony_ci    { LOCATION_NOPOWER_LOCATING_SA_ID, "LocationNopowerLocating" },
9700600bfbSopenharmony_ci    { AUDIO_DISTRIBUTED_SERVICE_ID, "AudioDistributed" },
9800600bfbSopenharmony_ci    { COMMON_EVENT_SERVICE_ABILITY_ID, "CommonEventService" },
9900600bfbSopenharmony_ci    { ADVANCED_NOTIFICATION_SERVICE_ABILITY_ID, "DistributedNotificationService" },
10000600bfbSopenharmony_ci    { COMMON_EVENT_SERVICE_ID, "CommonEventService" },
10100600bfbSopenharmony_ci    { POWER_MANAGER_SERVICE_ID, "PowerManagerService" },
10200600bfbSopenharmony_ci    { POWER_MANAGER_BATT_SERVICE_ID, "BatteryService" },
10300600bfbSopenharmony_ci    { POWER_MANAGER_BATT_STATS_SERVICE_ID, "BatteryStatisticsService" },
10400600bfbSopenharmony_ci    { POWER_MANAGER_THERMAL_SERVICE_ID, "ThermalService" },
10500600bfbSopenharmony_ci    { DISPLAY_MANAGER_SERVICE_ID, "DisplayPowerManagerService" },
10600600bfbSopenharmony_ci    { 3502, "DpmsService" },
10700600bfbSopenharmony_ci    { 3510, "KeystoreService" },
10800600bfbSopenharmony_ci    { DEVICE_SECURITY_LEVEL_MANAGER_SA_ID, "DslmService" },
10900600bfbSopenharmony_ci    { CERT_MANAGER_SERVICE_SA_ID, "CertManagerService"},
11000600bfbSopenharmony_ci    { DEVICE_THREAT_DETECTION_SERVICE_SA_ID, "DeviceThreatDetectionService" },
11100600bfbSopenharmony_ci    { SENSOR_SERVICE_ABILITY_ID, "SensorService" },
11200600bfbSopenharmony_ci    { MISCDEVICE_SERVICE_ABILITY_ID, "MiscDeviceService" },
11300600bfbSopenharmony_ci    { PASTEBOARD_SERVICE_ID, "PasteboardService" },
11400600bfbSopenharmony_ci    { SCREENLOCK_SERVICE_ID, "ScreenlockService" },
11500600bfbSopenharmony_ci    { WALLPAPER_MANAGER_SERVICE_ID, "WallpaperManagerService" },
11600600bfbSopenharmony_ci    { PRINT_SERVICE_ID, "PrintFramework" },
11700600bfbSopenharmony_ci    { SCAN_SERVICE_ID, "ScanFramework" },
11800600bfbSopenharmony_ci    { TELEPHONY_SYS_ABILITY_ID, "Telephony" },
11900600bfbSopenharmony_ci    { DCALL_SYS_ABILITY_ID, "DistributedCallMgr" },
12000600bfbSopenharmony_ci    { TELEPHONY_CALL_MANAGER_SYS_ABILITY_ID, "TelephonyCallManager" },
12100600bfbSopenharmony_ci    { TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID, "TelephonyCellularCall" },
12200600bfbSopenharmony_ci    { TELEPHONY_CELLULAR_DATA_SYS_ABILITY_ID, "TelephonyCellularData" },
12300600bfbSopenharmony_ci    { TELEPHONY_SMS_MMS_SYS_ABILITY_ID, "TelephonySmsMms" },
12400600bfbSopenharmony_ci    { TELEPHONY_STATE_REGISTRY_SYS_ABILITY_ID, "TelephonyStateRegistry" },
12500600bfbSopenharmony_ci    { TELEPHONY_CORE_SERVICE_SYS_ABILITY_ID, "TelephonyCoreService" },
12600600bfbSopenharmony_ci    { TELEPHONY_DATA_STORAGE_SYS_ABILITY_ID, "TelephonyDataStorage" },
12700600bfbSopenharmony_ci    { TELEPHONY_IMS_SYS_ABILITY_ID, "TelephonyIms" },
12800600bfbSopenharmony_ci    { DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID, "DeviceManagerService" },
12900600bfbSopenharmony_ci    { DISTRIBUTED_HARDWARE_SA_ID, "DistributedHardwareFramework" },
13000600bfbSopenharmony_ci    { DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID, "DistributedCameraSourceService" },
13100600bfbSopenharmony_ci    { DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID, "DistributedCameraSinkService" },
13200600bfbSopenharmony_ci    { DISTRIBUTED_HARDWARE_AUDIO_SOURCE_SA_ID, "DistributedAudioSourceService" },
13300600bfbSopenharmony_ci    { DISTRIBUTED_HARDWARE_AUDIO_SINK_SA_ID, "DistributedAudioSinkService" },
13400600bfbSopenharmony_ci    { DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID, "DistributedScreenSourceService" },
13500600bfbSopenharmony_ci    { DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID, "DistributedScreenSinkService" },
13600600bfbSopenharmony_ci    { DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, "DistributedInputSourceService" },
13700600bfbSopenharmony_ci    { DISTRIBUTED_HARDWARE_INPUT_SINK_SA_ID, "DistributedInputSinkService" },
13800600bfbSopenharmony_ci    { INPUT_METHOD_SYSTEM_ABILITY_ID, "InputMethodService" },
13900600bfbSopenharmony_ci    { MEDICAL_SENSOR_SERVICE_ABILITY_ID, "MedicalSensorService" },
14000600bfbSopenharmony_ci    { USB_SYSTEM_ABILITY_ID, "UsbService" },
14100600bfbSopenharmony_ci    { STORAGE_MANAGER_DAEMON_ID, "StorageDaemon" },
14200600bfbSopenharmony_ci    { STORAGE_MANAGER_MANAGER_ID, "StorageManager"},
14300600bfbSopenharmony_ci    { FILEMANAGEMENT_DISTRIBUTED_FILE_DAEMON_SA_ID, "DistributedFileDaemon"},
14400600bfbSopenharmony_ci    { FILEMANAGEMENT_CLOUD_SYNC_SERVICE_SA_ID, "CloudFileSyncService"},
14500600bfbSopenharmony_ci    { FILEMANAGEMENT_CLOUD_DAEMON_SERVICE_SA_ID, "CloudFileDaemonService"},
14600600bfbSopenharmony_ci    { DEVICE_SERVICE_MANAGER_SA_ID, "HdfDeviceServiceManager" },
14700600bfbSopenharmony_ci    { HDF_EXTERNAL_DEVICE_MANAGER_SA_ID, "HdfExternalDeviceManager" },
14800600bfbSopenharmony_ci    { DISTRIBUTED_DEVICE_PROFILE_SA_ID, "DistributedDeviceProfile" },
14900600bfbSopenharmony_ci    { WINDOW_MANAGER_SERVICE_ID, "WindowManagerService" },
15000600bfbSopenharmony_ci    { DISPLAY_MANAGER_SERVICE_SA_ID, "DisplayManagerService" },
15100600bfbSopenharmony_ci    { SOFTBUS_SERVER_SA_ID, "DSoftbus" },
15200600bfbSopenharmony_ci    { DEVICE_AUTH_SERVICE_ID, "DeviceAuthService" },
15300600bfbSopenharmony_ci    { WINDOW_MANAGER_ID, "WindowManager" },
15400600bfbSopenharmony_ci    { VSYNC_MANAGER_ID, "VsyncManager" },
15500600bfbSopenharmony_ci    { VSYNC_MANAGER_TEST_ID, "VsyncManagerTest" },
15600600bfbSopenharmony_ci    { GRAPHIC_DUMPER_SERVICE_SA_ID, "GraphicDumperService" },
15700600bfbSopenharmony_ci    { GRAPHIC_DUMPER_COMMAND_SA_ID, "GraphicDumperCommand" },
15800600bfbSopenharmony_ci    { ANIMATION_SERVER_SA_ID, "AnimationServer" },
15900600bfbSopenharmony_ci    { CA_DAEMON_ID, "CaDaemon" },
16000600bfbSopenharmony_ci    { ACCESSIBILITY_MANAGER_SERVICE_ID, "AccessibilityManagerService" },
16100600bfbSopenharmony_ci    { DEVICE_USAGE_STATISTICS_SYS_ABILITY_ID, "DeviceUsageStatistics" },
16200600bfbSopenharmony_ci    { MEMORY_MANAGER_SA_ID, "MemoryManagerService" },
16300600bfbSopenharmony_ci    { AVSESSION_SERVICE_ID, "AVSessionService" },
16400600bfbSopenharmony_ci    { SYS_INSTALLER_DISTRIBUTED_SERVICE_ID, "SysInstallerService" },
16500600bfbSopenharmony_ci    { MODULE_UPDATE_SERVICE_ID, "ModuleUpdateService" },
16600600bfbSopenharmony_ci    { SUBSYS_ACE_SYS_ABILITY_ID_BEGIN, "UiService" },
16700600bfbSopenharmony_ci    { ARKUI_UI_APPEARANCE_SERVICE_ID, "UiAppearanceService" },
16800600bfbSopenharmony_ci    { SUBSYS_USERIAM_SYS_ABILITY_USERIDM, "UserIdmService" },
16900600bfbSopenharmony_ci    { SUBSYS_USERIAM_SYS_ABILITY_AUTHEXECUTORMGR, "AuthExecutorMgrService" },
17000600bfbSopenharmony_ci    { RENDER_SERVICE, "RenderService" },
17100600bfbSopenharmony_ci    { ACCESS_TOKEN_MANAGER_SERVICE_ID, "AccessTokenManagerService" },
17200600bfbSopenharmony_ci    { TOKEN_SYNC_MANAGER_SERVICE_ID, "TokenSyncManagerService" },
17300600bfbSopenharmony_ci    { SANDBOX_MANAGER_SERVICE_ID, "SandboxManagerService" },
17400600bfbSopenharmony_ci    { DLP_PERMISSION_SERVICE_ID, "DlpPermissionService" },
17500600bfbSopenharmony_ci    { RISK_ANALYSIS_MANAGER_SA_ID, "RiskAnalysisManagerService" },
17600600bfbSopenharmony_ci    { DATA_COLLECT_MANAGER_SA_ID, "DataCollectManagerService" },
17700600bfbSopenharmony_ci    { MSDP_DEVICESTATUS_SERVICE_ID, "DeviceStatusService" },
17800600bfbSopenharmony_ci    { MULTIMODAL_INPUT_SERVICE_ID, "MultimodalInput" },
17900600bfbSopenharmony_ci    { DFX_SYS_HIVIEW_ABILITY_ID, "HiviewService" },
18000600bfbSopenharmony_ci    { PRIVACY_MANAGER_SERVICE_ID, "PrivacyManagerService"},
18100600bfbSopenharmony_ci    { DFX_FAULT_LOGGER_ABILITY_ID, "HiviewFaultLogger" },
18200600bfbSopenharmony_ci    { DFX_SYS_EVENT_SERVICE_ABILITY_ID, "HiviewSysEventService" },
18300600bfbSopenharmony_ci    { DFX_SYS_NATIVE_MEMORY_PROFILER_SERVICE_ABILITY_ID, "HiviewSysNativeMemoryProfilerService"},
18400600bfbSopenharmony_ci    { XPERF_SYS_TRACE_SERVICE_ABILITY_ID, "XperfTraceService" },
18500600bfbSopenharmony_ci    { XPERF_SYS_IO_SERVICE_ABILITY_ID, "XperfIoService" },
18600600bfbSopenharmony_ci    { XPERF_BIGDATA_MANAGER_SERVICE_ABILITY_ID, "XperfBigDataManagerService" },
18700600bfbSopenharmony_ci    { DFX_HI_DUMPER_SERVICE_ABILITY_ID, "HiDumperService" },
18800600bfbSopenharmony_ci    { XPOWER_MANAGER_SYSTEM_ABILITY_ID, "XpowerManager"},
18900600bfbSopenharmony_ci    { DFX_HI_PERF_SERVICE_ABILITY_ID, "HiPerfService"},
19000600bfbSopenharmony_ci    { DFX_HI_DUMPER_CPU_SERVICE_ABILITY_ID, "HiDumperCpuService" },
19100600bfbSopenharmony_ci    { SUBSYS_USERIAM_SYS_ABILITY_USERAUTH, "UserAuthService" },
19200600bfbSopenharmony_ci    { SUBSYS_USERIAM_SYS_ABILITY_PINAUTH, "PinAuthService" },
19300600bfbSopenharmony_ci    { SUBSYS_USERIAM_SYS_ABILITY_FACEAUTH, "FaceAuthService" },
19400600bfbSopenharmony_ci    { SUBSYS_USERIAM_SYS_ABILITY_FINGERPRINTAUTH, "FingerprintAuthService" },
19500600bfbSopenharmony_ci    { SUBSYS_USERIAM_SYS_ABILITY_FINGERPRINTAUTH_EX, "FingerprintAuthServiceEx" },
19600600bfbSopenharmony_ci    { NET_MANAGER_SYS_ABILITY_ID, "NetManager" },
19700600bfbSopenharmony_ci    { COMM_NET_CONN_MANAGER_SYS_ABILITY_ID, "NetConnManager" },
19800600bfbSopenharmony_ci    { COMM_NET_POLICY_MANAGER_SYS_ABILITY_ID, "NetPolicyManager" },
19900600bfbSopenharmony_ci    { COMM_NET_STATS_MANAGER_SYS_ABILITY_ID, "NetStatsManager" },
20000600bfbSopenharmony_ci    { COMM_NET_TETHERING_MANAGER_SYS_ABILITY_ID, "NetTetheringManager" },
20100600bfbSopenharmony_ci    { COMM_VPN_MANAGER_SYS_ABILITY_ID, "VPNManager" },
20200600bfbSopenharmony_ci    { COMM_DNS_MANAGER_SYS_ABILITY_ID, "DNSManager"},
20300600bfbSopenharmony_ci    { COMM_ETHERNET_MANAGER_SYS_ABILITY_ID, "EthernetManager" },
20400600bfbSopenharmony_ci    { COMM_NETSYS_NATIVE_SYS_ABILITY_ID, "NetsysNative" },
20500600bfbSopenharmony_ci    { COMM_MDNS_MANAGER_SYS_ABILITY_ID, "MDNSManager"},
20600600bfbSopenharmony_ci    { COMM_NETSYS_EXT_SYS_ABILITY_ID, "NetsysExtService"},
20700600bfbSopenharmony_ci    { COMM_DISTRIBUTED_NET_ABILITY_ID, "DistributedNet"},
20800600bfbSopenharmony_ci    { COMM_WEARABLE_DISTRIBUTED_NET_ABILITY_ID, "WearableDistributedNet"},
20900600bfbSopenharmony_ci    { ENTERPRISE_DEVICE_MANAGER_SA_ID, "EnterpriseDeviceManagerService" },
21000600bfbSopenharmony_ci    { I18N_SA_ID, "I18nService" },
21100600bfbSopenharmony_ci    { PARAM_WATCHER_DISTRIBUTED_SERVICE_ID, "ParamWatcher" },
21200600bfbSopenharmony_ci    { SYSPARAM_DEVICE_SERVICE_ID, "SysParamDevice" },
21300600bfbSopenharmony_ci    { TIME_SERVICE_ID, "TimeService" },
21400600bfbSopenharmony_ci    { PLAYER_DISTRIBUTED_SERVICE_ID, "PlayerDistributedService"},
21500600bfbSopenharmony_ci    { AV_CODEC_SERVICE_ID, "AVCodecService"},
21600600bfbSopenharmony_ci    { CAMERA_SERVICE_ID, "CameraService"},
21700600bfbSopenharmony_ci    { MEDIA_KEY_SYSTEM_SERVICE_ID, "MediaKeySystemService"},
21800600bfbSopenharmony_ci    { AUDIO_POLICY_SERVICE_ID, "AudioPolicyService"},
21900600bfbSopenharmony_ci    { DLP_CREDENTIAL_SERVICE_ID, "DlpCreService"},
22000600bfbSopenharmony_ci    { QUICKFIX_ENGINE_SERVICE_ID, "QuickfixEngineService"},
22100600bfbSopenharmony_ci    { DEVICE_ATTEST_PROFILE_SA_ID, "devattest_service" },
22200600bfbSopenharmony_ci    { AIDISPATCHER_ENGINE_SERVICE, "AIDispatcherEngineService" },
22300600bfbSopenharmony_ci    { SECURITY_COMPONENT_SERVICE_ID, "SecurityComponentService" },
22400600bfbSopenharmony_ci    { ADVERTISING_SA_ID, "Advertising" },
22500600bfbSopenharmony_ci    { LOCAL_CODE_SIGN_SERVICE_ID, "LocalCodeSignService" },
22600600bfbSopenharmony_ci    { INTELL_VOICE_SERVICE_ID, "IntellVoiceService" },
22700600bfbSopenharmony_ci    { FILE_ACCESS_SERVICE_ID, "FileAccessService" },
22800600bfbSopenharmony_ci    { MSDP_USER_STATUS_SERVICE_ID, "UserStatusAwarenessService" },
22900600bfbSopenharmony_ci    { NEARLINK_HOST_SYS_ABILITY_ID, "NearLinkHost" },
23000600bfbSopenharmony_ci    { ECOLOGICAL_RULE_MANAGER_SA_ID, "EcologicalRuleManager" },
23100600bfbSopenharmony_ci    { ASSET_SERVICE_ID, "AssetService" },
23200600bfbSopenharmony_ci    { TEST_SERVER_SA_ID, "TestServer" },
23300600bfbSopenharmony_ci    { APP_DOMAIN_VERIFY_MANAGER_SA_ID, "AppDomainVerifyManager" },
23400600bfbSopenharmony_ci    { APP_DOMAIN_VERIFY_AGENT_SA_ID, "AppDomainVerifyAgent" },
23500600bfbSopenharmony_ci    { AOT_COMPILER_SERVICE_ID, "AotCompilerService" },
23600600bfbSopenharmony_ci    { EL5_FILEKEY_MANAGER_SERVICE_ID, "El5FilekeyManager"},
23700600bfbSopenharmony_ci    { COMM_FIREWALL_MANAGER_SYS_ABILITY_ID, "NetFirewallManager" },
23800600bfbSopenharmony_ci    { SUBSYS_WEBVIEW_SYS_UPDATE_SERVICE_ID, "AppFwkUpdateService"},
23900600bfbSopenharmony_ci};
24000600bfbSopenharmony_ci
24100600bfbSopenharmony_cinamespace HiviewDFX {
24200600bfbSopenharmony_civoid DumpUtils::IgnorePipeQuit()
24300600bfbSopenharmony_ci{
24400600bfbSopenharmony_ci    signal(SIGPIPE, SIG_IGN); // protect from pipe quit
24500600bfbSopenharmony_ci}
24600600bfbSopenharmony_ci
24700600bfbSopenharmony_civoid DumpUtils::IgnoreStdoutCache()
24800600bfbSopenharmony_ci{
24900600bfbSopenharmony_ci    setvbuf(stdout, nullptr, _IONBF, 0); // never cache stdout
25000600bfbSopenharmony_ci}
25100600bfbSopenharmony_ci
25200600bfbSopenharmony_civoid DumpUtils::IgnoreOom()
25300600bfbSopenharmony_ci{
25400600bfbSopenharmony_ci    setpriority(PRIO_PROCESS, 0, TOP_PRIORITY); // protect from OOM
25500600bfbSopenharmony_ci}
25600600bfbSopenharmony_ci
25700600bfbSopenharmony_civoid DumpUtils::SetAdj(int adj)
25800600bfbSopenharmony_ci{
25900600bfbSopenharmony_ci    int fd = FdToWrite(FILE_CUR_OOM_ADJ);
26000600bfbSopenharmony_ci    if (fd < 0) {
26100600bfbSopenharmony_ci        return;
26200600bfbSopenharmony_ci    }
26300600bfbSopenharmony_ci    dprintf(fd, "%d", adj);
26400600bfbSopenharmony_ci    close(fd);
26500600bfbSopenharmony_ci}
26600600bfbSopenharmony_ci
26700600bfbSopenharmony_civoid DumpUtils::BoostPriority()
26800600bfbSopenharmony_ci{
26900600bfbSopenharmony_ci    IgnoreOom();
27000600bfbSopenharmony_ci    IgnorePipeQuit();
27100600bfbSopenharmony_ci    IgnoreStdoutCache();
27200600bfbSopenharmony_ci    SetAdj(TOP_OOM_ADJ);
27300600bfbSopenharmony_ci}
27400600bfbSopenharmony_ci
27500600bfbSopenharmony_cistd::string DumpUtils::ErrnoToMsg(const int &error)
27600600bfbSopenharmony_ci{
27700600bfbSopenharmony_ci    const int bufSize = 128;
27800600bfbSopenharmony_ci    char buf[bufSize] = {0};
27900600bfbSopenharmony_ci    strerror_r(error, buf, bufSize);
28000600bfbSopenharmony_ci    return buf;
28100600bfbSopenharmony_ci}
28200600bfbSopenharmony_ci
28300600bfbSopenharmony_ciint DumpUtils::FdToRead(const std::string &file)
28400600bfbSopenharmony_ci{
28500600bfbSopenharmony_ci    char path[PATH_MAX] = {0};
28600600bfbSopenharmony_ci    if (realpath(file.c_str(), path) == nullptr) {
28700600bfbSopenharmony_ci        DUMPER_HILOGE(MODULE_COMMON, "realpath, no such file. path=[%{public}s], file=[%{public}s]",
28800600bfbSopenharmony_ci            path, file.c_str());
28900600bfbSopenharmony_ci        return -1;
29000600bfbSopenharmony_ci    }
29100600bfbSopenharmony_ci
29200600bfbSopenharmony_ci    if (file != std::string(path)) {
29300600bfbSopenharmony_ci        DUMPER_HILOGI(MODULE_COMMON, "fail to check consistency. path=[%{public}s], file=[%{public}s]",
29400600bfbSopenharmony_ci            path, file.c_str());
29500600bfbSopenharmony_ci    }
29600600bfbSopenharmony_ci
29700600bfbSopenharmony_ci    int fd = TEMP_FAILURE_RETRY(open(path, O_RDONLY | O_CLOEXEC | O_NONBLOCK));
29800600bfbSopenharmony_ci    if (fd == -1) {
29900600bfbSopenharmony_ci        DUMPER_HILOGE(MODULE_COMMON, "open [%{public}s] %{public}s", path, ErrnoToMsg(errno).c_str());
30000600bfbSopenharmony_ci    }
30100600bfbSopenharmony_ci    return fd;
30200600bfbSopenharmony_ci}
30300600bfbSopenharmony_ci
30400600bfbSopenharmony_ciint DumpUtils::FdToWrite(const std::string &file)
30500600bfbSopenharmony_ci{
30600600bfbSopenharmony_ci    std::string split = "/";
30700600bfbSopenharmony_ci    auto pos = file.find_last_of(split);
30800600bfbSopenharmony_ci    if (pos == std::string::npos) {
30900600bfbSopenharmony_ci        DUMPER_HILOGE(MODULE_COMMON, "file path:[%{public}s] error", file.c_str());
31000600bfbSopenharmony_ci        return -1;
31100600bfbSopenharmony_ci    }
31200600bfbSopenharmony_ci    std::string tempPath = file.substr(0, pos + 1);
31300600bfbSopenharmony_ci    std::string name = file.substr(pos + 1);
31400600bfbSopenharmony_ci
31500600bfbSopenharmony_ci    char path[PATH_MAX] = {0};
31600600bfbSopenharmony_ci    if (realpath(tempPath.c_str(), path) != nullptr) {
31700600bfbSopenharmony_ci        std::string fileName = path + split + name;
31800600bfbSopenharmony_ci        int fd = -1;
31900600bfbSopenharmony_ci        if (access(fileName.c_str(), F_OK) == 0) {
32000600bfbSopenharmony_ci            fd = open(fileName.c_str(), O_WRONLY);
32100600bfbSopenharmony_ci            if (lseek(fd, 0, SEEK_END) == -1) {
32200600bfbSopenharmony_ci                DUMPER_HILOGE(MODULE_COMMON, "lseek fail fd:%{public}d, errno:%{public}d", fd, errno);
32300600bfbSopenharmony_ci            }
32400600bfbSopenharmony_ci        } else {
32500600bfbSopenharmony_ci            fd = TEMP_FAILURE_RETRY(open(fileName.c_str(), O_WRONLY | O_CREAT | O_CLOEXEC | O_NOFOLLOW,
32600600bfbSopenharmony_ci                                         S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH));
32700600bfbSopenharmony_ci        }
32800600bfbSopenharmony_ci        if (fd == -1) {
32900600bfbSopenharmony_ci            DUMPER_HILOGE(MODULE_COMMON, "open [%{public}s] %{public}s",
33000600bfbSopenharmony_ci                fileName.c_str(), ErrnoToMsg(errno).c_str());
33100600bfbSopenharmony_ci        }
33200600bfbSopenharmony_ci        return fd;
33300600bfbSopenharmony_ci    }
33400600bfbSopenharmony_ci    DUMPER_HILOGD(MODULE_COMMON, "realpath, no such file. path=[%{public}s], tempPath=[%{public}s]",
33500600bfbSopenharmony_ci        path, tempPath.c_str());
33600600bfbSopenharmony_ci    return -1;
33700600bfbSopenharmony_ci}
33800600bfbSopenharmony_ci
33900600bfbSopenharmony_cibool DumpUtils::CheckProcessAlive(uint32_t pid)
34000600bfbSopenharmony_ci{
34100600bfbSopenharmony_ci    char path[PATH_MAX] = {0};
34200600bfbSopenharmony_ci    char pathPid[PATH_MAX] = {0};
34300600bfbSopenharmony_ci    int ret = sprintf_s(pathPid, PATH_MAX, "/proc/%u", pid);
34400600bfbSopenharmony_ci    if (ret < 0) {
34500600bfbSopenharmony_ci        return false;
34600600bfbSopenharmony_ci    }
34700600bfbSopenharmony_ci    if (realpath(pathPid, path) != nullptr) { // path exist
34800600bfbSopenharmony_ci        if (access(path, F_OK) == 0) {        // can be read
34900600bfbSopenharmony_ci            return true;
35000600bfbSopenharmony_ci        }
35100600bfbSopenharmony_ci    }
35200600bfbSopenharmony_ci    return false;
35300600bfbSopenharmony_ci}
35400600bfbSopenharmony_ci
35500600bfbSopenharmony_civoid DumpUtils::RemoveDuplicateString(std::vector<std::string> &strList)
35600600bfbSopenharmony_ci{
35700600bfbSopenharmony_ci    std::vector<std::string> tmpVtr;
35800600bfbSopenharmony_ci    std::set<std::string> tmpSet;
35900600bfbSopenharmony_ci    for (auto &it : strList) {
36000600bfbSopenharmony_ci        auto ret = tmpSet.insert(it);
36100600bfbSopenharmony_ci        if (ret.second) {
36200600bfbSopenharmony_ci            tmpVtr.push_back(it);
36300600bfbSopenharmony_ci        }
36400600bfbSopenharmony_ci    }
36500600bfbSopenharmony_ci    strList = tmpVtr;
36600600bfbSopenharmony_ci}
36700600bfbSopenharmony_ci
36800600bfbSopenharmony_ciint DumpUtils::StrToId(const std::string &name)
36900600bfbSopenharmony_ci{
37000600bfbSopenharmony_ci    int id = -1;
37100600bfbSopenharmony_ci    auto iter = std::find_if(saNameMap_.begin(), saNameMap_.end(), [&](const std::pair<int, std::string> &item) {
37200600bfbSopenharmony_ci        return name.compare(item.second) == 0;
37300600bfbSopenharmony_ci    });
37400600bfbSopenharmony_ci    if (iter == saNameMap_.end()) {
37500600bfbSopenharmony_ci        if (!StrToInt(name, id)) { // Decimal string
37600600bfbSopenharmony_ci            return -1; // invalid ability ID
37700600bfbSopenharmony_ci        }
37800600bfbSopenharmony_ci    } else {
37900600bfbSopenharmony_ci        id = iter->first;
38000600bfbSopenharmony_ci    }
38100600bfbSopenharmony_ci    return id;
38200600bfbSopenharmony_ci}
38300600bfbSopenharmony_ci
38400600bfbSopenharmony_cistd::string DumpUtils::ConvertSaIdToSaName(const std::string &saIdStr)
38500600bfbSopenharmony_ci{
38600600bfbSopenharmony_ci    int saId = StrToId(saIdStr);
38700600bfbSopenharmony_ci    auto iter = saNameMap_.find(saId);
38800600bfbSopenharmony_ci    if (iter == saNameMap_.end()) {
38900600bfbSopenharmony_ci        return saIdStr;
39000600bfbSopenharmony_ci    }
39100600bfbSopenharmony_ci    return iter->second;
39200600bfbSopenharmony_ci}
39300600bfbSopenharmony_ci
39400600bfbSopenharmony_cibool DumpUtils::DirectoryExists(const std::string &path)
39500600bfbSopenharmony_ci{
39600600bfbSopenharmony_ci    struct stat fileInfo;
39700600bfbSopenharmony_ci    if (stat(path.c_str(), &fileInfo) == 0) {
39800600bfbSopenharmony_ci        return S_ISDIR(fileInfo.st_mode);
39900600bfbSopenharmony_ci    }
40000600bfbSopenharmony_ci    return false;
40100600bfbSopenharmony_ci}
40200600bfbSopenharmony_ci
40300600bfbSopenharmony_cibool DumpUtils::PathIsValid(const std::string &path)
40400600bfbSopenharmony_ci{
40500600bfbSopenharmony_ci    return access(path.c_str(), F_OK) == 0;
40600600bfbSopenharmony_ci}
40700600bfbSopenharmony_ci
40800600bfbSopenharmony_cibool DumpUtils::CopyFile(const std::string &src, const std::string &des)
40900600bfbSopenharmony_ci{
41000600bfbSopenharmony_ci    std::ifstream fin(src);
41100600bfbSopenharmony_ci    std::ofstream fout(des);
41200600bfbSopenharmony_ci    if ((!fin.is_open()) || (!fout.is_open())) {
41300600bfbSopenharmony_ci        return false;
41400600bfbSopenharmony_ci    }
41500600bfbSopenharmony_ci    fout << fin.rdbuf();
41600600bfbSopenharmony_ci    if (fout.fail()) {
41700600bfbSopenharmony_ci        fout.clear();
41800600bfbSopenharmony_ci    }
41900600bfbSopenharmony_ci    fout.flush();
42000600bfbSopenharmony_ci    return true;
42100600bfbSopenharmony_ci}
42200600bfbSopenharmony_ci
42300600bfbSopenharmony_cibool DumpUtils::IsCommercialVersion()
42400600bfbSopenharmony_ci{
42500600bfbSopenharmony_ci    bool isCommercialVersion = OHOS::system::GetParameter("const.logsystem.versiontype", "unknown") == "commercial";
42600600bfbSopenharmony_ci    return isCommercialVersion;
42700600bfbSopenharmony_ci}
42800600bfbSopenharmony_ci
42900600bfbSopenharmony_cibool DumpUtils::IsUserMode()
43000600bfbSopenharmony_ci{
43100600bfbSopenharmony_ci    std::string debugMode = "0";
43200600bfbSopenharmony_ci    debugMode = OHOS::system::GetParameter("const.debuggable", debugMode);
43300600bfbSopenharmony_ci    return debugMode == "0";
43400600bfbSopenharmony_ci}
43500600bfbSopenharmony_ci
43600600bfbSopenharmony_cibool DumpUtils::CheckAppDebugVersion(int pid)
43700600bfbSopenharmony_ci{
43800600bfbSopenharmony_ci    if (pid <= 0) {
43900600bfbSopenharmony_ci        DUMPER_HILOGE(MODULE_COMMON, "AppDebugVersion pid %{public}d false", pid);
44000600bfbSopenharmony_ci        return false;
44100600bfbSopenharmony_ci    }
44200600bfbSopenharmony_ci    std::string bundleName;
44300600bfbSopenharmony_ci    std::string filePath = "/proc/" + std::to_string(pid) + "/cmdline";
44400600bfbSopenharmony_ci    if (!OHOS::LoadStringFromFile(filePath, bundleName)) {
44500600bfbSopenharmony_ci        DUMPER_HILOGE(MODULE_COMMON, "Get process name by pid %{public}d failed!", pid);
44600600bfbSopenharmony_ci        return false;
44700600bfbSopenharmony_ci    }
44800600bfbSopenharmony_ci    if (bundleName.empty()) {
44900600bfbSopenharmony_ci        DUMPER_HILOGE(MODULE_COMMON, "Pid %{public}d or process name is illegal!", pid);
45000600bfbSopenharmony_ci        return false;
45100600bfbSopenharmony_ci    }
45200600bfbSopenharmony_ci    auto pos = bundleName.find(":");
45300600bfbSopenharmony_ci    if (pos != std::string::npos) {
45400600bfbSopenharmony_ci        bundleName = bundleName.substr(0, pos);
45500600bfbSopenharmony_ci    }
45600600bfbSopenharmony_ci    std::string appName = bundleName.substr(0, strlen(bundleName.c_str()));
45700600bfbSopenharmony_ci    sptr<ISystemAbilityManager> sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
45800600bfbSopenharmony_ci    if (sam == nullptr) {
45900600bfbSopenharmony_ci        DUMPER_HILOGE(MODULE_COMMON, "Pid %{public}d GetSystemAbilityManager", pid);
46000600bfbSopenharmony_ci        return false;
46100600bfbSopenharmony_ci    }
46200600bfbSopenharmony_ci    sptr<IRemoteObject> remoteObject = sam->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
46300600bfbSopenharmony_ci    if (remoteObject == nullptr) {
46400600bfbSopenharmony_ci        DUMPER_HILOGE(MODULE_COMMON, "Pid %{public}d Get BundleMgr SA failed!", pid);
46500600bfbSopenharmony_ci        return false;
46600600bfbSopenharmony_ci    }
46700600bfbSopenharmony_ci#ifdef HIDUMPER_BUNDLEMANAGER_FRAMEWORK_ENABLE
46800600bfbSopenharmony_ci    sptr<AppExecFwk::BundleMgrProxy> proxy = iface_cast<AppExecFwk::BundleMgrProxy>(remoteObject);
46900600bfbSopenharmony_ci    AppExecFwk::ApplicationInfo appInfo;
47000600bfbSopenharmony_ci    bool ret = proxy->GetApplicationInfo(appName, AppExecFwk::GET_APPLICATION_INFO_WITH_DISABLE,
47100600bfbSopenharmony_ci                                         AppExecFwk::Constants::ANY_USERID, appInfo);
47200600bfbSopenharmony_ci    if (!ret) {
47300600bfbSopenharmony_ci        DUMPER_HILOGE(MODULE_COMMON, "Pid %{public}d %{public}s Get App info failed!", pid, appName.c_str());
47400600bfbSopenharmony_ci        return false;
47500600bfbSopenharmony_ci    }
47600600bfbSopenharmony_ci    bool isDebugApp = (appInfo.appProvisionType == AppExecFwk::Constants::APP_PROVISION_TYPE_DEBUG);
47700600bfbSopenharmony_ci    DUMPER_HILOGD(MODULE_COMMON, "debug|pid %{public}d %{public}s DebugVersion %{public}d",
47800600bfbSopenharmony_ci        pid, appName.c_str(), isDebugApp);
47900600bfbSopenharmony_ci    return isDebugApp;
48000600bfbSopenharmony_ci#else
48100600bfbSopenharmony_ci    DUMPER_HILOGD(MODULE_COMMON, "debug|pid %{public}d %{public}s DebugVersion false", pid, appName.c_str());
48200600bfbSopenharmony_ci    return false;
48300600bfbSopenharmony_ci#endif
48400600bfbSopenharmony_ci}
48500600bfbSopenharmony_ci
48600600bfbSopenharmony_cibool DumpUtils::IsHmKernel()
48700600bfbSopenharmony_ci{
48800600bfbSopenharmony_ci    bool isHM = false;
48900600bfbSopenharmony_ci    utsname unameBuf;
49000600bfbSopenharmony_ci    if ((uname(&unameBuf)) == 0) {
49100600bfbSopenharmony_ci        std::string osRelease = unameBuf.release;
49200600bfbSopenharmony_ci        isHM = osRelease.find("HongMeng") != std::string::npos;
49300600bfbSopenharmony_ci    }
49400600bfbSopenharmony_ci    return isHM;
49500600bfbSopenharmony_ci}
49600600bfbSopenharmony_ci} // namespace HiviewDFX
49700600bfbSopenharmony_ci} // namespace OHOS
498