blob: 8c56d067d20241a594c255397c151e4ee871a79b [file] [log] [blame]
Satoru Takabayashie7f6d2a2018-08-08 17:06:29 +09001// Copyright 2018 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_UTIL_H_
6#define CRASH_REPORTER_UTIL_H_
7
Satoru Takabayashib2ca40d2018-08-09 14:02:04 +09008#include <string>
9#include <vector>
10
11#include <base/files/file_path.h>
Jeffrey Kardatzke18d50982019-03-21 14:13:34 -070012#include <brillo/process.h>
Jeffrey Kardatzke437fa922019-05-09 11:34:32 -070013#include <brillo/streams/stream.h>
Satoru Takabayashi8ce6db82018-08-17 15:18:41 +090014#include <session_manager/dbus-proxies.h>
Satoru Takabayashib2ca40d2018-08-09 14:02:04 +090015
Satoru Takabayashie7f6d2a2018-08-08 17:06:29 +090016namespace util {
17
18// Returns true if integration tests are currently running.
19bool IsCrashTestInProgress();
20
Satoru Takabayashi2d728042018-12-10 09:19:00 +090021// Returns true if uploading of device coredumps is allowed.
22bool IsDeviceCoredumpUploadAllowed();
23
Satoru Takabayashie7f6d2a2018-08-08 17:06:29 +090024// Returns true if running on a developer image.
25bool IsDeveloperImage();
26
Satoru Takabayashif6a36802018-08-14 16:23:05 +090027// Returns true if running on a test image.
28bool IsTestImage();
29
Satoru Takabayashi9a587522018-10-29 09:36:27 +090030// Returns true if running on an official image.
31bool IsOfficialImage();
32
Jeffrey Kardatzkeea333932019-04-12 10:17:51 -070033// Gets a string describing the hardware class of the device. Returns
34// "undefined" if this cannot be determined.
35std::string GetHardwareClass();
36
37// Returns the boot mode which will either be "dev", "missing-crossystem" (if it
38// cannot be determined) or the empty string.
39std::string GetBootModeString();
40
Satoru Takabayashib2ca40d2018-08-09 14:02:04 +090041// Tries to find |key| in a key-value file named |base_name| in |directories| in
42// the specified order, and writes the value to |value|. This function returns
43// as soon as the key is found (i.e. if the key is found in the first directory,
44// the remaining directories won't be checked). Returns true on success.
45bool GetCachedKeyValue(const base::FilePath& base_name,
46 const std::string& key,
47 const std::vector<base::FilePath>& directories,
48 std::string* value);
49
50// Similar to GetCachedKeyValue(), but this version checks the predefined
51// default directories.
52bool GetCachedKeyValueDefault(const base::FilePath& base_name,
53 const std::string& key,
54 std::string* value);
55
Satoru Takabayashi8ce6db82018-08-17 15:18:41 +090056// Gets the user crash directories via D-Bus using |session_manager_proxy|.
57// Returns true on success. The original contents of |directories| will be lost.
58bool GetUserCrashDirectories(
59 org::chromium::SessionManagerInterfaceProxyInterface* session_manager_proxy,
60 std::vector<base::FilePath>* directories);
61
Jeffrey Kardatzke437fa922019-05-09 11:34:32 -070062// Gzip-compresses |path|, removes the original file, and returns the path of
63// the new file. On failure, the original file is left alone and an empty path
64// is returned.
65base::FilePath GzipFile(const base::FilePath& path);
66
67// Gzip's the |data| passed in and returns the compressed data. Returns an empty
68// string on failure.
69std::string GzipStream(brillo::StreamPtr data);
70
Jeffrey Kardatzke18d50982019-03-21 14:13:34 -070071// Runs |process| and redirects |fd| to |output|. Returns the exit code, or -1
72// if the process failed to start.
73int RunAndCaptureOutput(brillo::ProcessImpl* process,
74 int fd,
75 std::string* output);
76
77// Breaks up |error| using std::getline and then does a LOG(ERROR) of each
78// individual line.
79void LogMultilineError(const std::string& error);
80
Satoru Takabayashie7f6d2a2018-08-08 17:06:29 +090081} // namespace util
82
83#endif // CRASH_REPORTER_UTIL_H_