Kansho Nishida | 630cc7a | 2019-10-23 17:37:41 +0900 | [diff] [blame] | 1 | // Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CRASH_REPORTER_ARC_UTIL_H_ |
| 6 | #define CRASH_REPORTER_ARC_UTIL_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | #include <unordered_map> |
| 10 | #include <unordered_set> |
| 11 | #include <utility> |
| 12 | #include <vector> |
| 13 | |
| 14 | #include <base/optional.h> |
Kimiyuki Onaka | 8aef16f | 2021-01-15 00:04:29 +0900 | [diff] [blame] | 15 | #include <base/time/tick_clock.h> |
| 16 | #include <base/time/time.h> |
| 17 | #include <session_manager/dbus-proxies.h> |
Kansho Nishida | 630cc7a | 2019-10-23 17:37:41 +0900 | [diff] [blame] | 18 | |
| 19 | #include "crash-reporter/crash_collector.h" |
| 20 | |
| 21 | namespace arc_util { |
| 22 | |
| 23 | using CrashLogHeaderMap = std::unordered_map<std::string, std::string>; |
| 24 | |
| 25 | extern const char kArcProduct[]; |
| 26 | |
| 27 | // Metadata fields included in reports. |
Long Cheng | 6b72d28 | 2020-11-05 18:40:30 -0800 | [diff] [blame] | 28 | extern const char kAbiMigrationField[]; |
Kansho Nishida | 630cc7a | 2019-10-23 17:37:41 +0900 | [diff] [blame] | 29 | extern const char kAndroidVersionField[]; |
| 30 | extern const char kArcVersionField[]; |
| 31 | extern const char kBoardField[]; |
| 32 | extern const char kChromeOsVersionField[]; |
| 33 | extern const char kCpuAbiField[]; |
| 34 | extern const char kCrashTypeField[]; |
| 35 | extern const char kDeviceField[]; |
| 36 | extern const char kProcessField[]; |
| 37 | extern const char kProductField[]; |
| 38 | extern const char kUptimeField[]; |
| 39 | |
| 40 | // For Java Crash |
| 41 | extern const char kExceptionInfoField[]; |
| 42 | extern const char kSignatureField[]; |
| 43 | |
| 44 | // If this metadata key is set to "true", the report is uploaded silently, i.e. |
| 45 | // it does not appear in chrome://crashes. |
| 46 | extern const char kSilentKey[]; |
| 47 | |
| 48 | // Keys for crash log headers. |
Kansho Nishida | 630cc7a | 2019-10-23 17:37:41 +0900 | [diff] [blame] | 49 | extern const char kProcessKey[]; |
| 50 | extern const char kSubjectKey[]; |
| 51 | |
| 52 | extern const std::vector<std::pair<const char*, const char*>> |
| 53 | kHeaderToFieldMapping; |
| 54 | |
Kimiyuki Onaka | da90c60 | 2020-09-03 10:58:06 +0900 | [diff] [blame] | 55 | // The property about ARC build. These values comes from a Mojo method, |
| 56 | // SetBuildProperties. |
| 57 | struct BuildProperty { |
| 58 | std::string device; |
| 59 | std::string board; |
| 60 | std::string cpu_abi; |
| 61 | std::string fingerprint; |
| 62 | }; |
| 63 | |
Kansho Nishida | 630cc7a | 2019-10-23 17:37:41 +0900 | [diff] [blame] | 64 | // Returns the Android version (eg: 7.1.1) from the fingerprint. |
| 65 | base::Optional<std::string> GetVersionFromFingerprint( |
| 66 | const std::string& fingerprint); |
| 67 | |
| 68 | bool ParseCrashLog(const std::string& type, |
| 69 | std::stringstream* stream, |
| 70 | CrashLogHeaderMap* map, |
| 71 | std::string* exception_info, |
| 72 | std::string* log); |
| 73 | |
| 74 | const char* GetSubjectTag(const std::string& type); |
| 75 | |
| 76 | bool IsSilentReport(const std::string& type); |
| 77 | |
| 78 | std::string GetCrashLogHeader(const CrashLogHeaderMap& map, const char* key); |
| 79 | |
| 80 | // Return Random PID. |
| 81 | // FormatDumpBasename relies on the assumption that the combination of process |
| 82 | // name, timestamp, and PID is unique. This does not hold if a process crashes |
| 83 | // more than once in the span of a second. While this is improbable for native |
| 84 | // crashes, Java crashes are not always fatal and may happen in bursts. Hence, |
| 85 | // ensure uniqueness by replacing the PID with the number of microseconds |
| 86 | // since the current second. |
| 87 | pid_t CreateRandomPID(); |
| 88 | |
Kimiyuki Onaka | 919f2220 | 2020-10-29 21:12:09 +0900 | [diff] [blame] | 89 | // Lists metadata from |build_property| as a list of pairs of key and value. |
| 90 | std::vector<std::pair<std::string, std::string>> ListMetadataForBuildProperty( |
| 91 | const BuildProperty& build_property); |
| 92 | |
Kimiyuki Onaka | bfedeec | 2021-01-20 20:26:54 +0900 | [diff] [blame] | 93 | // GetChromeVersion returns the version of Chrome browser. ARC++ and ARCVM crash |
| 94 | // reports use versions of Chrome browser as their product version. |
| 95 | bool GetChromeVersion(std::string* version); |
| 96 | |
Kimiyuki Onaka | 8aef16f | 2021-01-15 00:04:29 +0900 | [diff] [blame] | 97 | // Format the given time delta in human-readable manner. |
| 98 | std::string FormatDuration(base::TimeDelta delta); |
| 99 | |
| 100 | // Return the uptime of current ARC container instance from the time when the |
| 101 | // container upgraded from the mini-container. This works only for ARC container |
| 102 | // and only after the full container is started. |
| 103 | bool GetArcContainerUptime( |
| 104 | org::chromium::SessionManagerInterfaceProxyInterface* session_manager_proxy, |
| 105 | base::TimeDelta* uptime, |
| 106 | base::TickClock* test_clock = nullptr); |
| 107 | |
Kansho Nishida | 630cc7a | 2019-10-23 17:37:41 +0900 | [diff] [blame] | 108 | } // namespace arc_util |
| 109 | |
| 110 | #endif // CRASH_REPORTER_ARC_UTIL_H_ |