| Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 1 | // | 
|  | 2 | // Copyright (C) 2015 The Android Open Source Project | 
|  | 3 | // | 
|  | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | // you may not use this file except in compliance with the License. | 
|  | 6 | // You may obtain a copy of the License at | 
|  | 7 | // | 
|  | 8 | //      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | // | 
|  | 10 | // Unless required by applicable law or agreed to in writing, software | 
|  | 11 | // distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | // See the License for the specific language governing permissions and | 
|  | 14 | // limitations under the License. | 
|  | 15 | // | 
|  | 16 |  | 
|  | 17 | #ifndef UPDATE_ENGINE_METRICS_UTILS_H_ | 
|  | 18 | #define UPDATE_ENGINE_METRICS_UTILS_H_ | 
|  | 19 |  | 
| Tianjie Xu | 90aaa10 | 2017-10-10 17:39:03 -0700 | [diff] [blame] | 20 | #include <string> | 
|  | 21 |  | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 22 | #include <base/time/time.h> | 
|  | 23 |  | 
| Tianjie Xu | 90aaa10 | 2017-10-10 17:39:03 -0700 | [diff] [blame] | 24 | #include "update_engine/common/clock_interface.h" | 
| Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 25 | #include "update_engine/common/connection_utils.h" | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 26 | #include "update_engine/common/error_code.h" | 
| Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 27 | #include "update_engine/common/metrics_constants.h" | 
|  | 28 | #include "update_engine/common/metrics_reporter_interface.h" | 
| Tianjie Xu | 90aaa10 | 2017-10-10 17:39:03 -0700 | [diff] [blame] | 29 | #include "update_engine/common/prefs_interface.h" | 
| Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 30 |  | 
|  | 31 | namespace chromeos_update_engine { | 
| Alex Deymo | a259179 | 2015-11-17 00:39:40 -0300 | [diff] [blame] | 32 |  | 
| Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 33 | namespace metrics_utils { | 
|  | 34 |  | 
|  | 35 | // Transforms a ErrorCode value into a metrics::DownloadErrorCode. | 
|  | 36 | // This obviously only works for errors related to downloading so if |code| | 
|  | 37 | // is e.g. |ErrorCode::kFilesystemCopierError| then | 
|  | 38 | // |kDownloadErrorCodeInputMalformed| is returned. | 
|  | 39 | metrics::DownloadErrorCode GetDownloadErrorCode(ErrorCode code); | 
|  | 40 |  | 
|  | 41 | // Transforms a ErrorCode value into a metrics::AttemptResult. | 
|  | 42 | // | 
|  | 43 | // If metrics::AttemptResult::kPayloadDownloadError is returned, you | 
|  | 44 | // can use utils::GetDownloadError() to get more detail. | 
|  | 45 | metrics::AttemptResult GetAttemptResult(ErrorCode code); | 
|  | 46 |  | 
|  | 47 | // Calculates the internet connection type given |type| and |tethering|. | 
| Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 48 | metrics::ConnectionType GetConnectionType(ConnectionType type, | 
|  | 49 | ConnectionTethering tethering); | 
| Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 50 |  | 
| Tianjie Xu | 90aaa10 | 2017-10-10 17:39:03 -0700 | [diff] [blame] | 51 | // Returns the persisted value from prefs for the given key. It also | 
|  | 52 | // validates that the value returned is non-negative. | 
|  | 53 | int64_t GetPersistedValue(const std::string& key, PrefsInterface* prefs); | 
|  | 54 |  | 
|  | 55 | // Persists the reboot count of the update attempt to |kPrefsNumReboots|. | 
|  | 56 | void SetNumReboots(int64_t num_reboots, PrefsInterface* prefs); | 
|  | 57 |  | 
|  | 58 | // Persists the payload attempt number to |kPrefsPayloadAttemptNumber|. | 
|  | 59 | void SetPayloadAttemptNumber(int64_t payload_attempt_number, | 
|  | 60 | PrefsInterface* prefs); | 
|  | 61 |  | 
|  | 62 | // Persists the finished time of an update to the |kPrefsSystemUpdatedMarker|. | 
|  | 63 | void SetSystemUpdatedMarker(ClockInterface* clock, PrefsInterface* prefs); | 
|  | 64 |  | 
| Tianjie Xu | 2a0ea63 | 2018-08-06 12:59:23 -0700 | [diff] [blame] | 65 | // Persists the start monotonic time of an update to | 
|  | 66 | // |kPrefsUpdateTimestampStart|. | 
| Tianjie Xu | 90aaa10 | 2017-10-10 17:39:03 -0700 | [diff] [blame] | 67 | void SetUpdateTimestampStart(const base::Time& update_start_time, | 
|  | 68 | PrefsInterface* prefs); | 
|  | 69 |  | 
| Tianjie Xu | 2a0ea63 | 2018-08-06 12:59:23 -0700 | [diff] [blame] | 70 | // Persists the start boot time of an update to | 
|  | 71 | // |kPrefsUpdateBootTimestampStart|. | 
|  | 72 | void SetUpdateBootTimestampStart(const base::Time& update_start_boot_time, | 
|  | 73 | PrefsInterface* prefs); | 
|  | 74 |  | 
| Tianjie Xu | 90aaa10 | 2017-10-10 17:39:03 -0700 | [diff] [blame] | 75 | // Called at program startup if the device booted into a new update. | 
|  | 76 | // The |time_to_reboot| parameter contains the (monotonic-clock) duration | 
|  | 77 | // from when the update successfully completed (the value in | 
|  | 78 | // |kPrefsSystemUpdatedMarker|) until the device was booted into the update | 
|  | 79 | // (current monotonic-clock time). | 
|  | 80 | bool LoadAndReportTimeToReboot(MetricsReporterInterface* metrics_reporter, | 
|  | 81 | PrefsInterface* prefs, | 
|  | 82 | ClockInterface* clock); | 
|  | 83 |  | 
| Alex Deymo | 38429cf | 2015-11-11 18:27:22 -0800 | [diff] [blame] | 84 | }  // namespace metrics_utils | 
|  | 85 | }  // namespace chromeos_update_engine | 
|  | 86 |  | 
|  | 87 | #endif  // UPDATE_ENGINE_METRICS_UTILS_H_ |