blob: d42e7b15deb4e1ccfe7847845d227cdc8e7865be [file] [log] [blame]
Abhishek Bhardwaj0249a2c2023-05-01 23:39:111// Copyright 2023 The ChromiumOS Authors
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 LIBSEGMENTATION_FEATURE_MANAGEMENT_UTIL_H_
6#define LIBSEGMENTATION_FEATURE_MANAGEMENT_UTIL_H_
7
Allen Shih87ce1a12025-04-17 05:22:348#include <optional>
Abhishek Bhardwaj0249a2c2023-05-01 23:39:119#include <string>
Abhishek Bhardwaj64a204b2023-05-08 22:23:4110
Abhishek Bhardwaj0249a2c2023-05-01 23:39:1111#include <base/files/file_path.h>
Allen Shih87ce1a12025-04-17 05:22:3412#include <base/values.h>
Abhishek Bhardwaj0249a2c2023-05-01 23:39:1113#include <brillo/brillo_export.h>
Abhishek Bhardwaj64a204b2023-05-08 22:23:4114
Abhishek Bhardwaj64a204b2023-05-08 22:23:4115#include "libsegmentation/device_info.pb.h"
16#include "libsegmentation/feature_management_interface.h"
Abhishek Bhardwaj0249a2c2023-05-01 23:39:1117
18namespace segmentation {
19
20// An implementation that invokes the corresponding functions provided
21// in feature_management_interface.h.
22class BRILLO_EXPORT FeatureManagementUtil {
23 public:
Gwendal Grignou9a8d51e2024-01-10 17:50:1024 // Reads device info from string. Returns std::nullopt if the read wasn't
25 // successful.
26 static std::optional<libsegmentation::DeviceInfo> ReadDeviceInfo(
27 const std::string& encoded);
28
Abhishek Bhardwaj0249a2c2023-05-01 23:39:1129 // Reads device info from |file_path|. Returns std::nullopt if the read wasn't
30 // successful.
Gwendal Grignou9a8d51e2024-01-10 17:50:1031 static std::optional<libsegmentation::DeviceInfo> ReadDeviceInfo(
Abhishek Bhardwaj0249a2c2023-05-01 23:39:1132 const base::FilePath& file_path);
33
Gwendal Grignou9a8d51e2024-01-10 17:50:1034 // Returns |device_info| as base64.
35 static std::string EncodeDeviceInfo(
36 const libsegmentation::DeviceInfo& device_info);
Abhishek Bhardwaj0249a2c2023-05-01 23:39:1137
38 // Converts feature level from the internal proto to the external API.
39 static FeatureManagementInterface::FeatureLevel ConvertProtoFeatureLevel(
40 libsegmentation::DeviceInfo_FeatureLevel feature_level);
Abhishek Bhardwaj30d2ee82023-05-05 01:22:2841
42 // Converts scope level from the internal proto to the external API.
43 static FeatureManagementInterface::ScopeLevel ConvertProtoScopeLevel(
44 libsegmentation::DeviceInfo_ScopeLevel scope_level);
Gwendal Grignouee8efd12023-06-21 00:05:0945
Gwendal Grignou98c9e712023-06-21 22:48:0046 // Return the size of a block device.
47 // dev format is '/dev/sda', '/dev/nvme0n1', '/dev/mmcblk0', ...
48 // TODO(b:176492189): Move to a common library
49 static std::optional<int64_t> GetDiskSpace(const base::FilePath& dev);
50
51 // Find the fixed block device on the device.
52 // It may not be the device the rootfs is when we run ChromeOS from a
53 // removable device.
54 // The block device will be for example /dev/sda, /dev/mmcblk1, ...
55 // TODO(b:176492189): Move to a common library
56 // root is the usual '/', unless we are unit testing. In that case.
57 // root points to a temporary directory set up for testing.
58 static std::optional<base::FilePath> GetDefaultRoot(
59 const base::FilePath& root);
Abhishek Bhardwaj0249a2c2023-05-01 23:39:1160};
61
62} // namespace segmentation
63
64#endif // LIBSEGMENTATION_FEATURE_MANAGEMENT_UTIL_H_