Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 1 | /* |
| 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 Jeong | 9b6bcca | 2019-11-08 16:37:13 -0800 | [diff] [blame] | 19 | #include <android-base/properties.h> |
Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 20 | #include <android-base/stringprintf.h> |
Eric Jeong | 9b6bcca | 2019-11-08 16:37:13 -0800 | [diff] [blame] | 21 | #include <android-base/strings.h> |
Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 22 | #include <android/hidl/manager/1.0/IServiceManager.h> |
| 23 | #include <dumputils/dump_utils.h> |
| 24 | #include <log/log.h> |
| 25 | |
| 26 | /* list of native processes to include in the native dumps */ |
| 27 | // This matches the /proc/pid/exe link instead of /proc/pid/cmdline. |
| 28 | static const char* native_processes_to_dump[] = { |
| 29 | "/system/bin/audioserver", |
| 30 | "/system/bin/cameraserver", |
| 31 | "/system/bin/drmserver", |
| 32 | "/system/bin/mediadrmserver", |
| 33 | "/system/bin/mediaextractor", // media.extractor |
| 34 | "/system/bin/mediametrics", // media.metrics |
| 35 | "/system/bin/mediaserver", |
Chalard Jean | bd52694 | 2019-04-04 18:23:04 +0900 | [diff] [blame] | 36 | "/system/bin/netd", |
Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 37 | "/system/bin/sdcard", |
Howard Ro | 6a446a2 | 2020-02-20 04:57:00 +0000 | [diff] [blame] | 38 | "/apex/com.android.os.statsd/bin/statsd", |
Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 39 | "/system/bin/surfaceflinger", |
| 40 | "/system/bin/vehicle_network_service", |
| 41 | "/vendor/bin/hw/android.hardware.media.omx@1.0-service", // media.codec |
Chong Zhang | 31f6899 | 2019-03-27 16:08:53 -0700 | [diff] [blame] | 42 | "/apex/com.android.media.swcodec/bin/mediaswcodec", // media.swcodec |
Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 43 | NULL, |
| 44 | }; |
| 45 | |
Josh Gao | e73b7ee | 2020-01-09 21:54:50 -0800 | [diff] [blame] | 46 | |
| 47 | // Native processes to dump on debuggable builds. |
| 48 | static const char* debuggable_native_processes_to_dump[] = { |
Eric Biggers | e846316 | 2021-05-04 15:03:48 -0700 | [diff] [blame^] | 49 | "/system/bin/keystore2", |
Josh Gao | e73b7ee | 2020-01-09 21:54:50 -0800 | [diff] [blame] | 50 | "/system/bin/vold", |
| 51 | NULL, |
| 52 | }; |
| 53 | |
Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 54 | /* list of hal interface to dump containing process during native dumps */ |
| 55 | static const char* hal_interfaces_to_dump[] { |
Mikhail Naganov | ac1e32c | 2018-05-01 09:03:40 -0700 | [diff] [blame] | 56 | "android.hardware.audio@4.0::IDevicesFactory", |
Carter Hsu | 723e8cd | 2019-09-11 13:57:58 +0800 | [diff] [blame] | 57 | "android.hardware.audio@5.0::IDevicesFactory", |
Mikhail Naganov | 091e5d8 | 2020-01-27 12:11:51 -0800 | [diff] [blame] | 58 | "android.hardware.audio@6.0::IDevicesFactory", |
Mikhail Naganov | b9c8185 | 2020-08-06 19:38:38 +0000 | [diff] [blame] | 59 | "android.hardware.audio@7.0::IDevicesFactory", |
Stefano Galarraga | 5101b33 | 2020-03-23 08:49:08 +0000 | [diff] [blame] | 60 | "android.hardware.automotive.audiocontrol@1.0::IAudioControl", |
Hayden Gomes | 8f54d11 | 2020-03-26 14:23:33 -0700 | [diff] [blame] | 61 | "android.hardware.automotive.audiocontrol@2.0::IAudioControl", |
Stefano Galarraga | 5101b33 | 2020-03-23 08:49:08 +0000 | [diff] [blame] | 62 | "android.hardware.automotive.evs@1.0::IEvsCamera", |
| 63 | "android.hardware.automotive.vehicle@2.0::IVehicle", |
Kevin Chyn | 3bad810 | 2019-06-19 11:05:53 -0700 | [diff] [blame] | 64 | "android.hardware.biometrics.face@1.0::IBiometricsFace", |
Kris Chen | e93e6c9 | 2020-03-03 17:50:11 +0800 | [diff] [blame] | 65 | "android.hardware.biometrics.fingerprint@2.1::IBiometricsFingerprint", |
Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 66 | "android.hardware.bluetooth@1.0::IBluetoothHci", |
| 67 | "android.hardware.camera.provider@2.4::ICameraProvider", |
Jeff Tinker | 5fce882 | 2018-04-02 17:24:41 -0700 | [diff] [blame] | 68 | "android.hardware.drm@1.0::IDrmFactory", |
Chia-I Wu | 078dc42 | 2018-08-09 16:04:51 -0700 | [diff] [blame] | 69 | "android.hardware.graphics.allocator@2.0::IAllocator", |
Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 70 | "android.hardware.graphics.composer@2.1::IComposer", |
Yifan Hong | 77a5617 | 2018-11-27 16:43:49 -0800 | [diff] [blame] | 71 | "android.hardware.health@2.0::IHealth", |
Chong Zhang | 31f6899 | 2019-03-27 16:08:53 -0700 | [diff] [blame] | 72 | "android.hardware.media.c2@1.0::IComponentStore", |
Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 73 | "android.hardware.media.omx@1.0::IOmx", |
Pawin Vongmasa | b4c85df | 2018-04-18 07:00:30 -0700 | [diff] [blame] | 74 | "android.hardware.media.omx@1.0::IOmxStore", |
Stefano Galarraga | 5101b33 | 2020-03-23 08:49:08 +0000 | [diff] [blame] | 75 | "android.hardware.neuralnetworks@1.0::IDevice", |
Wei Wang | 0773561 | 2019-04-23 14:12:24 -0700 | [diff] [blame] | 76 | "android.hardware.power@1.3::IPower", |
Benjamin Schwartz | 525651b | 2019-04-08 15:26:10 -0700 | [diff] [blame] | 77 | "android.hardware.power.stats@1.0::IPowerStats", |
Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 78 | "android.hardware.sensors@1.0::ISensors", |
Wei Wang | 0773561 | 2019-04-23 14:12:24 -0700 | [diff] [blame] | 79 | "android.hardware.thermal@2.0::IThermal", |
Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 80 | "android.hardware.vr@1.0::IVr", |
| 81 | NULL, |
| 82 | }; |
| 83 | |
Eric Jeong | 9b6bcca | 2019-11-08 16:37:13 -0800 | [diff] [blame] | 84 | /* list of extra hal interfaces to dump containing process during native dumps */ |
| 85 | // This is filled when dumpstate is called. |
| 86 | static std::set<const std::string> extra_hal_interfaces_to_dump; |
| 87 | |
| 88 | static void read_extra_hals_to_dump_from_property() { |
| 89 | // extra hals to dump are already filled |
| 90 | if (extra_hal_interfaces_to_dump.size() > 0) { |
| 91 | return; |
| 92 | } |
| 93 | std::string value = android::base::GetProperty("ro.dump.hals.extra", ""); |
| 94 | std::vector<std::string> tokens = android::base::Split(value, ","); |
| 95 | for (const auto &token : tokens) { |
| 96 | std::string trimmed_token = android::base::Trim(token); |
| 97 | if (trimmed_token.length() == 0) { |
| 98 | continue; |
| 99 | } |
| 100 | extra_hal_interfaces_to_dump.insert(trimmed_token); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | // check if interface is included in either default hal list or extra hal list |
| 105 | bool should_dump_hal_interface(const std::string& interface) { |
Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 106 | for (const char** i = hal_interfaces_to_dump; *i; i++) { |
Eric Jeong | 9b6bcca | 2019-11-08 16:37:13 -0800 | [diff] [blame] | 107 | if (interface == *i) { |
Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 108 | return true; |
| 109 | } |
| 110 | } |
Eric Jeong | 9b6bcca | 2019-11-08 16:37:13 -0800 | [diff] [blame] | 111 | return extra_hal_interfaces_to_dump.find(interface) != extra_hal_interfaces_to_dump.end(); |
Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | bool should_dump_native_traces(const char* path) { |
| 115 | for (const char** p = native_processes_to_dump; *p; p++) { |
| 116 | if (!strcmp(*p, path)) { |
| 117 | return true; |
| 118 | } |
| 119 | } |
Josh Gao | e73b7ee | 2020-01-09 21:54:50 -0800 | [diff] [blame] | 120 | |
| 121 | if (android::base::GetBoolProperty("ro.debuggable", false)) { |
| 122 | for (const char** p = debuggable_native_processes_to_dump; *p; p++) { |
| 123 | if (!strcmp(*p, path)) { |
| 124 | return true; |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | |
Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 129 | return false; |
| 130 | } |
| 131 | |
| 132 | std::set<int> get_interesting_hal_pids() { |
| 133 | using android::hidl::manager::V1_0::IServiceManager; |
| 134 | using android::sp; |
| 135 | using android::hardware::Return; |
| 136 | |
| 137 | sp<IServiceManager> manager = IServiceManager::getService(); |
| 138 | std::set<int> pids; |
| 139 | |
Eric Jeong | 9b6bcca | 2019-11-08 16:37:13 -0800 | [diff] [blame] | 140 | read_extra_hals_to_dump_from_property(); |
| 141 | |
Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 142 | Return<void> ret = manager->debugDump([&](auto& hals) { |
| 143 | for (const auto &info : hals) { |
| 144 | if (info.pid == static_cast<int>(IServiceManager::PidConstant::NO_PID)) { |
| 145 | continue; |
| 146 | } |
| 147 | |
Eric Jeong | 9b6bcca | 2019-11-08 16:37:13 -0800 | [diff] [blame] | 148 | if (!should_dump_hal_interface(info.interfaceName)) { |
Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 149 | continue; |
| 150 | } |
| 151 | |
| 152 | pids.insert(info.pid); |
| 153 | } |
| 154 | }); |
| 155 | |
| 156 | if (!ret.isOk()) { |
| 157 | ALOGE("Could not get list of HAL PIDs: %s\n", ret.description().c_str()); |
| 158 | } |
| 159 | |
| 160 | return pids; // whether it was okay or not |
| 161 | } |
| 162 | |
| 163 | bool IsZygote(int pid) { |
Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 164 | std::string cmdline; |
| 165 | if (!android::base::ReadFileToString(android::base::StringPrintf("/proc/%d/cmdline", pid), |
| 166 | &cmdline)) { |
| 167 | return true; |
| 168 | } |
| 169 | |
Josh Gao | 33e622a | 2019-05-16 16:05:04 -0700 | [diff] [blame] | 170 | // cmdline has embedded nulls; only consider argv[0]. |
| 171 | cmdline = std::string(cmdline.c_str()); |
| 172 | |
| 173 | return cmdline == "zygote" || cmdline == "zygote64" || cmdline == "usap32" || |
| 174 | cmdline == "usap64"; |
Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 175 | } |