Satoru Takabayashi | e7f6d2a | 2018-08-08 17:06:29 +0900 | [diff] [blame] | 1 | // 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 Takabayashi | b2ca40d | 2018-08-09 14:02:04 +0900 | [diff] [blame] | 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include <base/files/file_path.h> |
Jeffrey Kardatzke | 18d5098 | 2019-03-21 14:13:34 -0700 | [diff] [blame] | 12 | #include <brillo/process.h> |
Satoru Takabayashi | 8ce6db8 | 2018-08-17 15:18:41 +0900 | [diff] [blame] | 13 | #include <session_manager/dbus-proxies.h> |
Satoru Takabayashi | b2ca40d | 2018-08-09 14:02:04 +0900 | [diff] [blame] | 14 | |
Satoru Takabayashi | e7f6d2a | 2018-08-08 17:06:29 +0900 | [diff] [blame] | 15 | namespace util { |
| 16 | |
| 17 | // Returns true if integration tests are currently running. |
| 18 | bool IsCrashTestInProgress(); |
| 19 | |
Satoru Takabayashi | 2d72804 | 2018-12-10 09:19:00 +0900 | [diff] [blame] | 20 | // Returns true if uploading of device coredumps is allowed. |
| 21 | bool IsDeviceCoredumpUploadAllowed(); |
| 22 | |
Satoru Takabayashi | e7f6d2a | 2018-08-08 17:06:29 +0900 | [diff] [blame] | 23 | // Returns true if running on a developer image. |
| 24 | bool IsDeveloperImage(); |
| 25 | |
Satoru Takabayashi | f6a3680 | 2018-08-14 16:23:05 +0900 | [diff] [blame] | 26 | // Returns true if running on a test image. |
| 27 | bool IsTestImage(); |
| 28 | |
Satoru Takabayashi | 9a58752 | 2018-10-29 09:36:27 +0900 | [diff] [blame] | 29 | // Returns true if running on an official image. |
| 30 | bool IsOfficialImage(); |
| 31 | |
Jeffrey Kardatzke | ea33393 | 2019-04-12 10:17:51 -0700 | [diff] [blame] | 32 | // Gets a string describing the hardware class of the device. Returns |
| 33 | // "undefined" if this cannot be determined. |
| 34 | std::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. |
| 38 | std::string GetBootModeString(); |
| 39 | |
Satoru Takabayashi | b2ca40d | 2018-08-09 14:02:04 +0900 | [diff] [blame] | 40 | // 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. |
| 44 | bool 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. |
| 51 | bool GetCachedKeyValueDefault(const base::FilePath& base_name, |
| 52 | const std::string& key, |
| 53 | std::string* value); |
| 54 | |
Satoru Takabayashi | 8ce6db8 | 2018-08-17 15:18:41 +0900 | [diff] [blame] | 55 | // 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. |
| 57 | bool GetUserCrashDirectories( |
| 58 | org::chromium::SessionManagerInterfaceProxyInterface* session_manager_proxy, |
| 59 | std::vector<base::FilePath>* directories); |
| 60 | |
Jeffrey Kardatzke | 18d5098 | 2019-03-21 14:13:34 -0700 | [diff] [blame] | 61 | // Runs |process| and redirects |fd| to |output|. Returns the exit code, or -1 |
| 62 | // if the process failed to start. |
| 63 | int 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. |
| 69 | void LogMultilineError(const std::string& error); |
| 70 | |
Satoru Takabayashi | e7f6d2a | 2018-08-08 17:06:29 +0900 | [diff] [blame] | 71 | } // namespace util |
| 72 | |
| 73 | #endif // CRASH_REPORTER_UTIL_H_ |