| 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> | 
|  | 19 | #include <android-base/stringprintf.h> | 
|  | 20 | #include <android/hidl/manager/1.0/IServiceManager.h> | 
|  | 21 | #include <dumputils/dump_utils.h> | 
|  | 22 | #include <log/log.h> | 
|  | 23 |  | 
|  | 24 | /* list of native processes to include in the native dumps */ | 
|  | 25 | // This matches the /proc/pid/exe link instead of /proc/pid/cmdline. | 
|  | 26 | static const char* native_processes_to_dump[] = { | 
|  | 27 | "/system/bin/audioserver", | 
|  | 28 | "/system/bin/cameraserver", | 
|  | 29 | "/system/bin/drmserver", | 
|  | 30 | "/system/bin/mediadrmserver", | 
|  | 31 | "/system/bin/mediaextractor", // media.extractor | 
|  | 32 | "/system/bin/mediametrics", // media.metrics | 
|  | 33 | "/system/bin/mediaserver", | 
| Chalard Jean | 20bf748 | 2019-04-04 18:23:04 +0900 | [diff] [blame] | 34 | "/system/bin/netd", | 
| Nikita Ioffe | f59c287 | 2019-05-20 13:53:20 +0100 | [diff] [blame] | 35 | "/system/bin/vold", | 
| Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 36 | "/system/bin/sdcard", | 
|  | 37 | "/system/bin/statsd", | 
|  | 38 | "/system/bin/surfaceflinger", | 
|  | 39 | "/system/bin/vehicle_network_service", | 
|  | 40 | "/vendor/bin/hw/android.hardware.media.omx@1.0-service", // media.codec | 
|  | 41 | NULL, | 
|  | 42 | }; | 
|  | 43 |  | 
|  | 44 | /* list of hal interface to dump containing process during native dumps */ | 
|  | 45 | static const char* hal_interfaces_to_dump[] { | 
|  | 46 | "android.hardware.audio@2.0::IDevicesFactory", | 
| Mikhail Naganov | ac1e32c | 2018-05-01 09:03:40 -0700 | [diff] [blame] | 47 | "android.hardware.audio@4.0::IDevicesFactory", | 
| Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 48 | "android.hardware.bluetooth@1.0::IBluetoothHci", | 
|  | 49 | "android.hardware.camera.provider@2.4::ICameraProvider", | 
| Jeff Tinker | 5fce882 | 2018-04-02 17:24:41 -0700 | [diff] [blame] | 50 | "android.hardware.drm@1.0::IDrmFactory", | 
| Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 51 | "android.hardware.graphics.composer@2.1::IComposer", | 
| Yifan Hong | 77a5617 | 2018-11-27 16:43:49 -0800 | [diff] [blame] | 52 | "android.hardware.health@2.0::IHealth", | 
| Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 53 | "android.hardware.media.omx@1.0::IOmx", | 
| Pawin Vongmasa | b4c85df | 2018-04-18 07:00:30 -0700 | [diff] [blame] | 54 | "android.hardware.media.omx@1.0::IOmxStore", | 
| Kweku Adams | 5ce418d | 2018-02-05 16:43:53 -0800 | [diff] [blame] | 55 | "android.hardware.sensors@1.0::ISensors", | 
|  | 56 | "android.hardware.vr@1.0::IVr", | 
|  | 57 | NULL, | 
|  | 58 | }; | 
|  | 59 |  | 
|  | 60 | bool should_dump_hal_interface(const char* interface) { | 
|  | 61 | for (const char** i = hal_interfaces_to_dump; *i; i++) { | 
|  | 62 | if (!strcmp(*i, interface)) { | 
|  | 63 | return true; | 
|  | 64 | } | 
|  | 65 | } | 
|  | 66 | return false; | 
|  | 67 | } | 
|  | 68 |  | 
|  | 69 | bool should_dump_native_traces(const char* path) { | 
|  | 70 | for (const char** p = native_processes_to_dump; *p; p++) { | 
|  | 71 | if (!strcmp(*p, path)) { | 
|  | 72 | return true; | 
|  | 73 | } | 
|  | 74 | } | 
|  | 75 | return false; | 
|  | 76 | } | 
|  | 77 |  | 
|  | 78 | std::set<int> get_interesting_hal_pids() { | 
|  | 79 | using android::hidl::manager::V1_0::IServiceManager; | 
|  | 80 | using android::sp; | 
|  | 81 | using android::hardware::Return; | 
|  | 82 |  | 
|  | 83 | sp<IServiceManager> manager = IServiceManager::getService(); | 
|  | 84 | std::set<int> pids; | 
|  | 85 |  | 
|  | 86 | Return<void> ret = manager->debugDump([&](auto& hals) { | 
|  | 87 | for (const auto &info : hals) { | 
|  | 88 | if (info.pid == static_cast<int>(IServiceManager::PidConstant::NO_PID)) { | 
|  | 89 | continue; | 
|  | 90 | } | 
|  | 91 |  | 
|  | 92 | if (!should_dump_hal_interface(info.interfaceName.c_str())) { | 
|  | 93 | continue; | 
|  | 94 | } | 
|  | 95 |  | 
|  | 96 | pids.insert(info.pid); | 
|  | 97 | } | 
|  | 98 | }); | 
|  | 99 |  | 
|  | 100 | if (!ret.isOk()) { | 
|  | 101 | ALOGE("Could not get list of HAL PIDs: %s\n", ret.description().c_str()); | 
|  | 102 | } | 
|  | 103 |  | 
|  | 104 | return pids; // whether it was okay or not | 
|  | 105 | } | 
|  | 106 |  | 
|  | 107 | bool IsZygote(int pid) { | 
|  | 108 | static const std::string kZygotePrefix = "zygote"; | 
|  | 109 |  | 
|  | 110 | std::string cmdline; | 
|  | 111 | if (!android::base::ReadFileToString(android::base::StringPrintf("/proc/%d/cmdline", pid), | 
|  | 112 | &cmdline)) { | 
|  | 113 | return true; | 
|  | 114 | } | 
|  | 115 |  | 
|  | 116 | return (cmdline.find(kZygotePrefix) == 0); | 
|  | 117 | } |