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