1 /*
2  * Copyright (C) 2024 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 //! `aconfig_mainline` is a crate that defines library functions that are needed by
18 //! aconfig daemon for mainline (aconfigd-mainline binary).
19 
20 pub mod aconfigd;
21 pub mod storage_files;
22 pub mod storage_files_manager;
23 pub mod utils;
24 
25 #[cfg(test)]
26 mod test_utils;
27 
28 /// aconfigd-mainline error
29 #[non_exhaustive]
30 #[derive(thiserror::Error, Debug)]
31 pub enum AconfigdError {
32     #[error("failed to update file permission of {} to {}: {:?}", .file, .mode, .errmsg)]
33     FailToUpdateFilePerm { file: String, mode: u32, errmsg: std::io::Error },
34 
35     #[error("failed to copy file from {} to {}: {:?}", .src, .dst, .errmsg)]
36     FailToCopyFile { src: String, dst: String, errmsg: std::io::Error },
37 
38     #[error("fail to remove file {}: {:?}", .file, .errmsg)]
39     FailToRemoveFile { file: String, errmsg: std::io::Error },
40 
41     #[error("fail to open file {}: {:?}", .file, .errmsg)]
42     FailToOpenFile { file: String, errmsg: std::io::Error },
43 
44     #[error("fail to read file {}: {:?}", .file, .errmsg)]
45     FailToReadFile { file: String, errmsg: std::io::Error },
46 
47     #[error("fail to write file {}: {:?}", .file, .errmsg)]
48     FailToWriteFile { file: String, errmsg: std::io::Error },
49 
50     #[error("fail to parse to protobuf from bytes for {}: {:?}", .file, .errmsg)]
51     FailToParsePbFromBytes { file: String, errmsg: protobuf::Error },
52 
53     #[error("fail to serialize protobuf to bytes for file {}: {:?}", .file, .errmsg)]
54     FailToSerializePb { file: String, errmsg: protobuf::Error },
55 
56     #[error("fail to get hasher for digest: {:?}", .errmsg)]
57     FailToGetHasherForDigest { errmsg: openssl::error::ErrorStack },
58 
59     #[error("failed to hash file {}: {:?}", .file, .errmsg)]
60     FailToHashFile { file: String, errmsg: openssl::error::ErrorStack },
61 
62     #[error("failed to get files digest: {:?}", .errmsg)]
63     FailToGetDigest { errmsg: openssl::error::ErrorStack },
64 
65     #[error("fail to get storage file version of {}: {:?}", .file, .errmsg)]
66     FailToGetFileVersion { file: String, errmsg: aconfig_storage_file::AconfigStorageError },
67 
68     #[error("fail to map storage file {}: {:?}", .file, .errmsg)]
69     FailToMapFile { file: String, errmsg: aconfig_storage_file::AconfigStorageError },
70 
71     #[error("mapped storage file {} is none", .file)]
72     MappedFileIsNone { file: String },
73 
74     #[error("invalid flag value type for {}: {:?}", .flag, .errmsg)]
75     InvalidFlagValueType { flag: String, errmsg: aconfig_storage_file::AconfigStorageError },
76 
77     #[error("flag {} does not exist", .flag)]
78     FlagDoesNotExist { flag: String },
79 
80     #[error("fail to get package context for {}: {:?}", .package, .errmsg)]
81     FailToGetPackageContext { package: String, errmsg: aconfig_storage_file::AconfigStorageError },
82 
83     #[error("fail to get flag context for {}: {:?}", .flag, .errmsg)]
84     FailToGetFlagContext { flag: String, errmsg: aconfig_storage_file::AconfigStorageError },
85 
86     #[error("fail to get flag attribute for {}: {:?}", .flag, .errmsg)]
87     FailToGetFlagAttribute { flag: String, errmsg: aconfig_storage_file::AconfigStorageError },
88 
89     #[error("fail to get flag value for {}: {:?}", .flag, .errmsg)]
90     FailToGetFlagValue { flag: String, errmsg: aconfig_storage_file::AconfigStorageError },
91 
92     #[error("flag {} has no local override", .flag)]
93     FlagHasNoLocalOverride { flag: String },
94 
95     #[error("invalid flag value {} for flag {}", .value, .flag)]
96     InvalidFlagValue { flag: String, value: String },
97 
98     #[error("failed to set flag value for flag {}: {:?}", .flag, .errmsg)]
99     FailToSetFlagValue { flag: String, errmsg: aconfig_storage_file::AconfigStorageError },
100 
101     #[error("failed to set flag has server override for flag {}: {:?}", .flag, .errmsg)]
102     FailToSetFlagHasServerOverride {
103         flag: String,
104         errmsg: aconfig_storage_file::AconfigStorageError,
105     },
106 
107     #[error("failed to set flag has local override for flag {}: {:?}", .flag, .errmsg)]
108     FailToSetFlagHasLocalOverride {
109         flag: String,
110         errmsg: aconfig_storage_file::AconfigStorageError,
111     },
112 
113     #[error("flag {} is readonly", .flag)]
114     FlagIsReadOnly { flag: String },
115 
116     #[error("fail to list flags for cotnainer {}: {:?}", .container, .errmsg)]
117     FailToListFlags { container: String, errmsg: aconfig_storage_file::AconfigStorageError },
118 
119     #[error("fail to list flags with info for container {}: {:?}", .container, .errmsg)]
120     FailToListFlagsWithInfo { container: String, errmsg: aconfig_storage_file::AconfigStorageError },
121 
122     #[error("fail to get storage files for {}", .container)]
123     FailToGetStorageFiles { container: String },
124 
125     #[error("unexpected internal error")]
126     InternalError(#[source] anyhow::Error),
127 
128     #[error("fail to get metadata of file {}: {:?}", .file, .errmsg)]
129     FailToGetFileMetadata { file: String, errmsg: std::io::Error },
130 
131     #[error("fail to read /apex dir: {:?}", .errmsg)]
132     FailToReadApexDir { errmsg: std::io::Error },
133 
134     #[error("cannot find container for package {}", .package)]
135     FailToFindContainer { package: String },
136 
137     #[error("invalid socket request: {}", .errmsg)]
138     InvalidSocketRequest { errmsg: String },
139 
140     #[error("fail to read from socket unix stream: {:?}", .errmsg)]
141     FailToReadFromSocket { errmsg: std::io::Error },
142 
143     #[error("fail to write to socket unix stream: {:?}", .errmsg)]
144     FailToWriteToSocket { errmsg: std::io::Error },
145 
146     #[error("fail to read device build fingerpirnt: {:?}", .errmsg)]
147     FailToReadBuildFingerPrint { errmsg: rustutils::system_properties::PropertyWatcherError },
148 }
149