blob: 02c7397cdab966a687d670fcb0479a4f94107987 [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>
Satoru Takabayashi8ce6db82018-08-17 15:18:41 +090013#include <session_manager/dbus-proxies.h>
Satoru Takabayashib2ca40d2018-08-09 14:02:04 +090014
Satoru Takabayashie7f6d2a2018-08-08 17:06:29 +090015namespace util {
16
17// Returns true if integration tests are currently running.
18bool IsCrashTestInProgress();
19
Satoru Takabayashi2d728042018-12-10 09:19:00 +090020// Returns true if uploading of device coredumps is allowed.
21bool IsDeviceCoredumpUploadAllowed();
22
Satoru Takabayashie7f6d2a2018-08-08 17:06:29 +090023// Returns true if running on a developer image.
24bool IsDeveloperImage();
25
Satoru Takabayashif6a36802018-08-14 16:23:05 +090026// Returns true if running on a test image.
27bool IsTestImage();
28
Satoru Takabayashi9a587522018-10-29 09:36:27 +090029// Returns true if running on an official image.
30bool IsOfficialImage();
31
Jeffrey Kardatzkeea333932019-04-12 10:17:51 -070032// Gets a string describing the hardware class of the device. Returns
33// "undefined" if this cannot be determined.
34std::string GetHardwareClass();
35
36// Returns the boot mode which will either be "dev", "missing-crossystem" (if it
37// cannot be determined) or the empty string.
38std::string GetBootModeString();
39
Satoru Takabayashib2ca40d2018-08-09 14:02:04 +090040// Tries to find |key| in a key-value file named |base_name| in |directories| in
41// the specified order, and writes the value to |value|. This function returns
42// as soon as the key is found (i.e. if the key is found in the first directory,
43// the remaining directories won't be checked). Returns true on success.
44bool GetCachedKeyValue(const base::FilePath& base_name,
45 const std::string& key,
46 const std::vector<base::FilePath>& directories,
47 std::string* value);
48
49// Similar to GetCachedKeyValue(), but this version checks the predefined
50// default directories.
51bool GetCachedKeyValueDefault(const base::FilePath& base_name,
52 const std::string& key,
53 std::string* value);
54
Satoru Takabayashi8ce6db82018-08-17 15:18:41 +090055// Gets the user crash directories via D-Bus using |session_manager_proxy|.
56// Returns true on success. The original contents of |directories| will be lost.
57bool GetUserCrashDirectories(
58 org::chromium::SessionManagerInterfaceProxyInterface* session_manager_proxy,
59 std::vector<base::FilePath>* directories);
60
Jeffrey Kardatzke18d50982019-03-21 14:13:34 -070061// Runs |process| and redirects |fd| to |output|. Returns the exit code, or -1
62// if the process failed to start.
63int RunAndCaptureOutput(brillo::ProcessImpl* process,
64 int fd,
65 std::string* output);
66
67// Breaks up |error| using std::getline and then does a LOG(ERROR) of each
68// individual line.
69void LogMultilineError(const std::string& error);
70
Satoru Takabayashie7f6d2a2018-08-08 17:06:29 +090071} // namespace util
72
73#endif // CRASH_REPORTER_UTIL_H_