1 /*
2  * Copyright (C) 2019 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 #include "linkerconfig/environment.h"
18 
19 #include <unistd.h>
20 
21 #include "linkerconfig/variables.h"
22 
23 namespace android {
24 namespace linkerconfig {
25 namespace modules {
IsLegacyDevice()26 bool IsLegacyDevice() {
27   return !Variables::GetValue("ro.vndk.version").has_value() ||
28          Variables::GetValue("ro.treble.enabled") == "false";
29 }
30 
IsVndkLiteDevice()31 bool IsVndkLiteDevice() {
32   return Variables::GetValue("ro.vndk.lite").value_or("") == "true";
33 }
34 
IsVndkInSystemNamespace()35 bool IsVndkInSystemNamespace() {
36   return Variables::GetValue("VNDK_USING_CORE_VARIANT_LIBRARIES").has_value();
37 }
38 
GetVendorVndkVersion()39 std::string GetVendorVndkVersion() {
40   return Variables::GetValue("ro.vndk.version").value_or("");
41 }
42 
GetProductVndkVersion()43 std::string GetProductVndkVersion() {
44   return Variables::GetValue("ro.product.vndk.version").value_or("");
45 }
46 
IsProductVndkVersionDefined()47 bool IsProductVndkVersionDefined() {
48   return Variables::GetValue("ro.product.vndk.version").has_value();
49 }
50 
IsRecoveryMode()51 bool IsRecoveryMode() {
52   return access("/system/bin/recovery", F_OK) == 0;
53 }
54 }  // namespace modules
55 }  // namespace linkerconfig
56 }  // namespace android
57