blob: 0f1a02a55352b0a2aebc8f50c9c6dc74e2c0ccc9 [file] [log] [blame]
Kweku Adams5ce418d2018-02-05 16:43:53 -08001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#include <set>
17
18#include <android-base/file.h>
Eric Jeong9b6bcca2019-11-08 16:37:13 -080019#include <android-base/properties.h>
Kweku Adams5ce418d2018-02-05 16:43:53 -080020#include <android-base/stringprintf.h>
Eric Jeong9b6bcca2019-11-08 16:37:13 -080021#include <android-base/strings.h>
Kweku Adams5ce418d2018-02-05 16:43:53 -080022#include <android/hidl/manager/1.0/IServiceManager.h>
Jayant Chowdharya0a8eb22022-05-20 03:30:09 +000023#include <binder/IServiceManager.h>
Kweku Adams5ce418d2018-02-05 16:43:53 -080024#include <dumputils/dump_utils.h>
25#include <log/log.h>
26
27/* list of native processes to include in the native dumps */
28// This matches the /proc/pid/exe link instead of /proc/pid/cmdline.
29static const char* native_processes_to_dump[] = {
30 "/system/bin/audioserver",
31 "/system/bin/cameraserver",
32 "/system/bin/drmserver",
33 "/system/bin/mediadrmserver",
34 "/system/bin/mediaextractor", // media.extractor
35 "/system/bin/mediametrics", // media.metrics
36 "/system/bin/mediaserver",
Chong Zhang7920d812020-10-15 12:06:39 -070037 "/system/bin/mediatranscoding", // media.transcoding
Chalard Jeanbd526942019-04-04 18:23:04 +090038 "/system/bin/netd",
Kweku Adams5ce418d2018-02-05 16:43:53 -080039 "/system/bin/sdcard",
Howard Ro6a446a22020-02-20 04:57:00 +000040 "/apex/com.android.os.statsd/bin/statsd",
Kweku Adams5ce418d2018-02-05 16:43:53 -080041 "/system/bin/surfaceflinger",
42 "/system/bin/vehicle_network_service",
43 "/vendor/bin/hw/android.hardware.media.omx@1.0-service", // media.codec
Chong Zhang31f68992019-03-27 16:08:53 -070044 "/apex/com.android.media.swcodec/bin/mediaswcodec", // media.swcodec
Kweku Adams5ce418d2018-02-05 16:43:53 -080045 NULL,
46};
47
Josh Gaoe73b7ee2020-01-09 21:54:50 -080048
49// Native processes to dump on debuggable builds.
50static const char* debuggable_native_processes_to_dump[] = {
Eric Biggerse8463162021-05-04 15:03:48 -070051 "/system/bin/keystore2",
Josh Gaoe73b7ee2020-01-09 21:54:50 -080052 "/system/bin/vold",
53 NULL,
54};
55
Jayant Chowdharya0a8eb22022-05-20 03:30:09 +000056/* list of hidl hal interface to dump containing process during native dumps */
57static const char* hidl_hal_interfaces_to_dump[] {
Mikhail Naganovac1e32c2018-05-01 09:03:40 -070058 "android.hardware.audio@4.0::IDevicesFactory",
Carter Hsu723e8cd2019-09-11 13:57:58 +080059 "android.hardware.audio@5.0::IDevicesFactory",
Mikhail Naganov091e5d82020-01-27 12:11:51 -080060 "android.hardware.audio@6.0::IDevicesFactory",
Mikhail Naganov783022f2020-08-06 19:38:38 +000061 "android.hardware.audio@7.0::IDevicesFactory",
Stefano Galarraga5101b332020-03-23 08:49:08 +000062 "android.hardware.automotive.audiocontrol@1.0::IAudioControl",
Hayden Gomesb11a1b72020-03-26 14:23:33 -070063 "android.hardware.automotive.audiocontrol@2.0::IAudioControl",
Stefano Galarraga5101b332020-03-23 08:49:08 +000064 "android.hardware.automotive.evs@1.0::IEvsCamera",
65 "android.hardware.automotive.vehicle@2.0::IVehicle",
Kevin Chyn3bad8102019-06-19 11:05:53 -070066 "android.hardware.biometrics.face@1.0::IBiometricsFace",
Kris Chene93e6c92020-03-03 17:50:11 +080067 "android.hardware.biometrics.fingerprint@2.1::IBiometricsFingerprint",
Kweku Adams5ce418d2018-02-05 16:43:53 -080068 "android.hardware.bluetooth@1.0::IBluetoothHci",
69 "android.hardware.camera.provider@2.4::ICameraProvider",
Jeff Tinker5fce8822018-04-02 17:24:41 -070070 "android.hardware.drm@1.0::IDrmFactory",
Chia-I Wu078dc422018-08-09 16:04:51 -070071 "android.hardware.graphics.allocator@2.0::IAllocator",
Kweku Adams5ce418d2018-02-05 16:43:53 -080072 "android.hardware.graphics.composer@2.1::IComposer",
Yifan Hong77a56172018-11-27 16:43:49 -080073 "android.hardware.health@2.0::IHealth",
Chong Zhang31f68992019-03-27 16:08:53 -070074 "android.hardware.media.c2@1.0::IComponentStore",
Kweku Adams5ce418d2018-02-05 16:43:53 -080075 "android.hardware.media.omx@1.0::IOmx",
Pawin Vongmasab4c85df2018-04-18 07:00:30 -070076 "android.hardware.media.omx@1.0::IOmxStore",
Stefano Galarraga5101b332020-03-23 08:49:08 +000077 "android.hardware.neuralnetworks@1.0::IDevice",
Wei Wang07735612019-04-23 14:12:24 -070078 "android.hardware.power@1.3::IPower",
Benjamin Schwartz525651b2019-04-08 15:26:10 -070079 "android.hardware.power.stats@1.0::IPowerStats",
Kweku Adams5ce418d2018-02-05 16:43:53 -080080 "android.hardware.sensors@1.0::ISensors",
Wei Wang07735612019-04-23 14:12:24 -070081 "android.hardware.thermal@2.0::IThermal",
Kweku Adams5ce418d2018-02-05 16:43:53 -080082 "android.hardware.vr@1.0::IVr",
83 NULL,
84};
85
Jayant Chowdharya0a8eb22022-05-20 03:30:09 +000086/* list of hal interface to dump containing process during native dumps */
87static const std::vector<std::string> aidl_interfaces_to_dump {
88 "android.hardware.camera.provider.ICameraProvider",
89};
90
Eric Jeong9b6bcca2019-11-08 16:37:13 -080091/* list of extra hal interfaces to dump containing process during native dumps */
92// This is filled when dumpstate is called.
93static std::set<const std::string> extra_hal_interfaces_to_dump;
94
95static void read_extra_hals_to_dump_from_property() {
96 // extra hals to dump are already filled
Eric Jeong961ba2d2020-06-24 11:43:15 -070097 if (!extra_hal_interfaces_to_dump.empty()) {
Eric Jeong9b6bcca2019-11-08 16:37:13 -080098 return;
99 }
100 std::string value = android::base::GetProperty("ro.dump.hals.extra", "");
101 std::vector<std::string> tokens = android::base::Split(value, ",");
102 for (const auto &token : tokens) {
103 std::string trimmed_token = android::base::Trim(token);
104 if (trimmed_token.length() == 0) {
105 continue;
106 }
107 extra_hal_interfaces_to_dump.insert(trimmed_token);
108 }
109}
110
111// check if interface is included in either default hal list or extra hal list
112bool should_dump_hal_interface(const std::string& interface) {
Jayant Chowdharya0a8eb22022-05-20 03:30:09 +0000113 for (const char** i = hidl_hal_interfaces_to_dump; *i; i++) {
Eric Jeong9b6bcca2019-11-08 16:37:13 -0800114 if (interface == *i) {
Kweku Adams5ce418d2018-02-05 16:43:53 -0800115 return true;
116 }
117 }
Eric Jeong9b6bcca2019-11-08 16:37:13 -0800118 return extra_hal_interfaces_to_dump.find(interface) != extra_hal_interfaces_to_dump.end();
Kweku Adams5ce418d2018-02-05 16:43:53 -0800119}
120
121bool should_dump_native_traces(const char* path) {
122 for (const char** p = native_processes_to_dump; *p; p++) {
123 if (!strcmp(*p, path)) {
124 return true;
125 }
126 }
Josh Gaoe73b7ee2020-01-09 21:54:50 -0800127
128 if (android::base::GetBoolProperty("ro.debuggable", false)) {
129 for (const char** p = debuggable_native_processes_to_dump; *p; p++) {
130 if (!strcmp(*p, path)) {
131 return true;
132 }
133 }
134 }
135
Kweku Adams5ce418d2018-02-05 16:43:53 -0800136 return false;
137}
138
Jayant Chowdharya0a8eb22022-05-20 03:30:09 +0000139static void get_interesting_aidl_pids(std::set<int> &pids) {
140 using ServiceDebugInfo = android::IServiceManager::ServiceDebugInfo;
141 auto sm = android::defaultServiceManager();
142 std::vector<ServiceDebugInfo> serviceDebugInfos = sm->getServiceDebugInfo();
143 for (const auto & serviceDebugInfo : serviceDebugInfos) {
144 for (const auto &aidl_prefix : aidl_interfaces_to_dump) {
145 // Check for prefix match with aidl interface to dump
146 if (serviceDebugInfo.name.rfind(aidl_prefix, 0) == 0) {
147 pids.insert(serviceDebugInfo.pid);
148 }
149 }
150 }
151}
152
153static void get_interesting_hidl_pids(std::set<int> &pids) {
Kweku Adams5ce418d2018-02-05 16:43:53 -0800154 using android::hidl::manager::V1_0::IServiceManager;
155 using android::sp;
156 using android::hardware::Return;
157
158 sp<IServiceManager> manager = IServiceManager::getService();
Eric Jeong9b6bcca2019-11-08 16:37:13 -0800159 read_extra_hals_to_dump_from_property();
160
Kweku Adams5ce418d2018-02-05 16:43:53 -0800161 Return<void> ret = manager->debugDump([&](auto& hals) {
162 for (const auto &info : hals) {
163 if (info.pid == static_cast<int>(IServiceManager::PidConstant::NO_PID)) {
164 continue;
165 }
166
Jayant Chowdharya0a8eb22022-05-20 03:30:09 +0000167 if (should_dump_hal_interface(info.interfaceName)) {
168 pids.insert(info.pid);
Kweku Adams5ce418d2018-02-05 16:43:53 -0800169 }
Kweku Adams5ce418d2018-02-05 16:43:53 -0800170 }
171 });
172
173 if (!ret.isOk()) {
174 ALOGE("Could not get list of HAL PIDs: %s\n", ret.description().c_str());
175 }
176
Jayant Chowdharya0a8eb22022-05-20 03:30:09 +0000177 return;
178}
179
180std::set<int> get_interesting_pids() {
181 std::set<int> interesting_pids;
182 get_interesting_hidl_pids(interesting_pids);
183 get_interesting_aidl_pids(interesting_pids);
184 return interesting_pids;
Kweku Adams5ce418d2018-02-05 16:43:53 -0800185}
186
187bool IsZygote(int pid) {
Kweku Adams5ce418d2018-02-05 16:43:53 -0800188 std::string cmdline;
189 if (!android::base::ReadFileToString(android::base::StringPrintf("/proc/%d/cmdline", pid),
190 &cmdline)) {
191 return true;
192 }
193
Josh Gao33e622a2019-05-16 16:05:04 -0700194 // cmdline has embedded nulls; only consider argv[0].
195 cmdline = std::string(cmdline.c_str());
196
197 return cmdline == "zygote" || cmdline == "zygote64" || cmdline == "usap32" ||
198 cmdline == "usap64";
Kweku Adams5ce418d2018-02-05 16:43:53 -0800199}