blob: de31aa0d6bdff4ac6edd53c6374a0a820e8236f5 [file] [log] [blame]
Kansho Nishida630cc7a2019-10-23 17:37:41 +09001// 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 Onaka8aef16f2021-01-15 00:04:29 +090015#include <base/time/tick_clock.h>
16#include <base/time/time.h>
17#include <session_manager/dbus-proxies.h>
Kansho Nishida630cc7a2019-10-23 17:37:41 +090018
19#include "crash-reporter/crash_collector.h"
20
21namespace arc_util {
22
23using CrashLogHeaderMap = std::unordered_map<std::string, std::string>;
24
25extern const char kArcProduct[];
26
27// Metadata fields included in reports.
Long Cheng6b72d282020-11-05 18:40:30 -080028extern const char kAbiMigrationField[];
Kansho Nishida630cc7a2019-10-23 17:37:41 +090029extern const char kAndroidVersionField[];
30extern const char kArcVersionField[];
31extern const char kBoardField[];
32extern const char kChromeOsVersionField[];
33extern const char kCpuAbiField[];
34extern const char kCrashTypeField[];
35extern const char kDeviceField[];
36extern const char kProcessField[];
37extern const char kProductField[];
38extern const char kUptimeField[];
39
40// For Java Crash
41extern const char kExceptionInfoField[];
42extern 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.
46extern const char kSilentKey[];
47
48// Keys for crash log headers.
Kansho Nishida630cc7a2019-10-23 17:37:41 +090049extern const char kProcessKey[];
50extern const char kSubjectKey[];
51
52extern const std::vector<std::pair<const char*, const char*>>
53 kHeaderToFieldMapping;
54
Kimiyuki Onakada90c602020-09-03 10:58:06 +090055// The property about ARC build. These values comes from a Mojo method,
56// SetBuildProperties.
57struct BuildProperty {
58 std::string device;
59 std::string board;
60 std::string cpu_abi;
61 std::string fingerprint;
62};
63
Kansho Nishida630cc7a2019-10-23 17:37:41 +090064// Returns the Android version (eg: 7.1.1) from the fingerprint.
65base::Optional<std::string> GetVersionFromFingerprint(
66 const std::string& fingerprint);
67
68bool ParseCrashLog(const std::string& type,
69 std::stringstream* stream,
70 CrashLogHeaderMap* map,
71 std::string* exception_info,
72 std::string* log);
73
74const char* GetSubjectTag(const std::string& type);
75
76bool IsSilentReport(const std::string& type);
77
78std::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.
87pid_t CreateRandomPID();
88
Kimiyuki Onaka919f22202020-10-29 21:12:09 +090089// Lists metadata from |build_property| as a list of pairs of key and value.
90std::vector<std::pair<std::string, std::string>> ListMetadataForBuildProperty(
91 const BuildProperty& build_property);
92
Kimiyuki Onakabfedeec2021-01-20 20:26:54 +090093// GetChromeVersion returns the version of Chrome browser. ARC++ and ARCVM crash
94// reports use versions of Chrome browser as their product version.
95bool GetChromeVersion(std::string* version);
96
Kimiyuki Onaka8aef16f2021-01-15 00:04:29 +090097// Format the given time delta in human-readable manner.
98std::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.
103bool GetArcContainerUptime(
104 org::chromium::SessionManagerInterfaceProxyInterface* session_manager_proxy,
105 base::TimeDelta* uptime,
106 base::TickClock* test_clock = nullptr);
107
Kansho Nishida630cc7a2019-10-23 17:37:41 +0900108} // namespace arc_util
109
110#endif // CRASH_REPORTER_ARC_UTIL_H_