1 /*
2  * Copyright (C) 2020 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 ART_ODREFRESH_ODR_COMMON_H_
18 #define ART_ODREFRESH_ODR_COMMON_H_
19 
20 #include <initializer_list>
21 #include <string>
22 #include <string_view>
23 
24 #include "android-base/result.h"
25 
26 namespace art {
27 namespace odrefresh {
28 
29 // Quotes a path with single quotes (').
30 std::string QuotePath(std::string_view path);
31 
32 // Converts the security patch date to a comparable integer.
33 android::base::Result<int> ParseSecurityPatchStr(const std::string& security_patch_str);
34 
35 // Returns true if partial compilation should be disabled. Takes a string from
36 // `ro.build.version.security_patch`, which represents the security patch date.
37 bool ShouldDisablePartialCompilation(const std::string& security_patch_str);
38 
39 // Returns true if there is no need to load existing artifacts that are already up-to-date and write
40 // them back. See `OnDeviceRefresh::RefreshExistingArtifacts` for more details. Takes a string from
41 // `ro.build.version.sdk`, which represents the SDK version.
42 bool ShouldDisableRefresh(const std::string& sdk_version_str);
43 
44 // Passes the name and the value for each system property to the provided callback.
45 void SystemPropertyForeach(std::function<void(const char* name, const char* value)> action);
46 
47 // Returns true if the build-time UFFD GC matches the runtime's choice.
48 bool CheckBuildUserfaultFdGc(bool build_enable_uffd_gc,
49                              bool is_at_most_u,
50                              bool kernel_supports_uffd);
51 
52 }  // namespace odrefresh
53 }  // namespace art
54 
55 #endif  // ART_ODREFRESH_ODR_COMMON_H_
56