Merge "Support legacy and vndklite mode" am: 5cdad7a708 am: 9033ba7bcd
am: e3c6175e60

Change-Id: I398514945e13ac91dcabc213fd2f97c3d92286e6
diff --git a/contents/configuration/baseconfig.cc b/contents/configuration/baseconfig.cc
index 0e49b15..eca4d31 100644
--- a/contents/configuration/baseconfig.cc
+++ b/contents/configuration/baseconfig.cc
@@ -15,6 +15,7 @@
  */
 
 #include "linkerconfig/baseconfig.h"
+#include "linkerconfig/environment.h"
 #include "linkerconfig/sectionbuilder.h"
 
 using android::linkerconfig::modules::DirToSection;
@@ -57,7 +58,11 @@
 namespace contents {
 android::linkerconfig::modules::Configuration CreateBaseConfiguration() {
   std::vector<Section> sections;
+
   Context current_context;
+  if (android::linkerconfig::modules::IsVndkLiteDevice()) {
+    current_context.SetCurrentLinkerConfigType(LinkerConfigType::Vndklite);
+  }
 
   sections.emplace_back(BuildSystemSection(current_context));
   sections.emplace_back(BuildVendorSection(current_context));
diff --git a/contents/configuration/legacy.cc b/contents/configuration/legacy.cc
index aa9a1b6..70b0c4a 100644
--- a/contents/configuration/legacy.cc
+++ b/contents/configuration/legacy.cc
@@ -17,6 +17,7 @@
 #include "linkerconfig/legacy.h"
 #include "linkerconfig/sectionbuilder.h"
 
+using android::linkerconfig::contents::LinkerConfigType;
 using android::linkerconfig::modules::DirToSection;
 using android::linkerconfig::modules::Section;
 
@@ -24,7 +25,8 @@
 const std::vector<DirToSection> kDirToSection = {
     // All binaries gets the same configuration 'legacy'
     {"/system", "legacy"},
-    {"/product", "legacy"},
+    {"/@{SYSTEM_EXT:system_ext}", "legacy"},
+    {"/@{PRODUCT:product}", "legacy"},
     {"/vendor", "legacy"},
     {"/odm", "legacy"},
     {"/sbin", "legacy"},
@@ -42,6 +44,7 @@
 android::linkerconfig::modules::Configuration CreateLegacyConfiguration() {
   std::vector<Section> sections;
   Context current_context;
+  current_context.SetCurrentLinkerConfigType(LinkerConfigType::Legacy);
 
   sections.emplace_back(BuildLegacySection(current_context));
   sections.emplace_back(BuildPostInstallSection(current_context));
diff --git a/contents/context/context.cc b/contents/context/context.cc
index da7f719..d1535ff 100644
--- a/contents/context/context.cc
+++ b/contents/context/context.cc
@@ -27,12 +27,32 @@
   return current_section == SectionType::Vendor;
 }
 
+bool Context::IsDefaultConfig() const {
+  return current_linkerconfig_type == LinkerConfigType::Default;
+}
+
+bool Context::IsLegacyConfig() const {
+  return current_linkerconfig_type == LinkerConfigType::Legacy;
+}
+
+bool Context::IsVndkliteConfig() const {
+  return current_linkerconfig_type == LinkerConfigType::Vndklite;
+}
+
+bool Context::IsRecoveryConfig() const {
+  return current_linkerconfig_type == LinkerConfigType::Recovery;
+}
+
 void Context::SetCurrentSection(SectionType section_type) {
   current_section = section_type;
 }
 
 std::string Context::GetSystemNamespaceName() const {
-  return IsVendorSection() ? "system" : "default";
+  return IsVendorSection() && !IsVndkliteConfig() ? "system" : "default";
+}
+
+void Context::SetCurrentLinkerConfigType(LinkerConfigType config_type) {
+  current_linkerconfig_type = config_type;
 }
 }  // namespace contents
 }  // namespace linkerconfig
diff --git a/contents/include/linkerconfig/context.h b/contents/include/linkerconfig/context.h
index 0460870..a2c0a7e 100644
--- a/contents/include/linkerconfig/context.h
+++ b/contents/include/linkerconfig/context.h
@@ -27,20 +27,36 @@
   Other,
 };
 
+enum class LinkerConfigType {
+  Default,
+  Legacy,
+  Vndklite,
+  Recovery,
+};
+
 class Context {
  public:
-  Context() : current_section(SectionType::System) {
+  Context()
+      : current_section(SectionType::System),
+        current_linkerconfig_type(LinkerConfigType::Default) {
   }
   bool IsSystemSection() const;
   bool IsVendorSection() const;
 
+  bool IsDefaultConfig() const;
+  bool IsLegacyConfig() const;
+  bool IsVndkliteConfig() const;
+  bool IsRecoveryConfig() const;
+
   void SetCurrentSection(SectionType value);
+  void SetCurrentLinkerConfigType(LinkerConfigType value);
 
   // Returns the namespace that covers /system/${LIB}.
   std::string GetSystemNamespaceName() const;
 
  private:
   SectionType current_section;
+  LinkerConfigType current_linkerconfig_type;
 };
 }  // namespace contents
 }  // namespace linkerconfig
diff --git a/contents/namespace/conscrypt.cc b/contents/namespace/conscrypt.cc
index c28a1f0..2bb765d 100644
--- a/contents/namespace/conscrypt.cc
+++ b/contents/namespace/conscrypt.cc
@@ -19,6 +19,8 @@
 #include <string>
 #include <vector>
 
+#include "linkerconfig/environment.h"
+
 using android::linkerconfig::modules::AsanPath;
 using android::linkerconfig::modules::Namespace;
 
diff --git a/contents/namespace/media.cc b/contents/namespace/media.cc
index afecca2..0208963 100644
--- a/contents/namespace/media.cc
+++ b/contents/namespace/media.cc
@@ -45,20 +45,22 @@
 namespace linkerconfig {
 namespace contents {
 Namespace BuildMediaNamespace([[maybe_unused]] const Context& ctx) {
-  bool is_legacy = android::linkerconfig::modules::IsLegacyDevice();
+  bool is_legacy = ctx.IsLegacyConfig();
+  bool is_vndklite = ctx.IsVndkliteConfig();
   bool is_system_section = ctx.IsSystemSection();
 
   Namespace ns("media", /*is_isolated=*/true, /*is_visible=*/true);
   ns.AddSearchPath("/apex/com.android.media/${LIB}", AsanPath::SAME_PATH);
-  ns.AddPermittedPath("/apex/com.android.media/${LIB}/extractors",
-                      AsanPath::SAME_PATH);
+  ns.AddPermittedPath(
+      "/apex/com.android.media/${LIB}/extractors",
+      (is_legacy || is_vndklite) ? AsanPath::NONE : AsanPath::SAME_PATH);
 
   Link& system_link = ns.GetLink(ctx.GetSystemNamespaceName());
   if (is_legacy) {
     system_link.AddSharedLib(kLibsFromDefaultLegacy);
   } else {
     system_link.AddSharedLib(kLibsFromDefault);
-    if (is_system_section) {
+    if (is_system_section && !is_vndklite) {
       system_link.AddSharedLib(kLibsFromDefaultSystem);
     }
   }
diff --git a/contents/namespace/resolv.cc b/contents/namespace/resolv.cc
index 1a279ed..3156fa3 100644
--- a/contents/namespace/resolv.cc
+++ b/contents/namespace/resolv.cc
@@ -27,10 +27,6 @@
                                                    "libbinder_ndk.so",
                                                    "liblog.so",
                                                    "libvndksupport.so"};
-
-const std::vector<std::string> kLibsFromUnrestrictedDefault = {
-    "libbinder_ndk.so",
-    "liblog.so"};
 }  // namespace
 
 namespace android {
@@ -39,9 +35,8 @@
 Namespace BuildResolvNamespace([[maybe_unused]] const Context& ctx) {
   Namespace ns("resolv", /*is_isolated=*/true, /*is_visible=*/true);
   ns.AddSearchPath("/apex/com.android.resolv/${LIB}", AsanPath::SAME_PATH);
-  ns.GetLink(ctx.GetSystemNamespaceName())
-      .AddSharedLib(ctx.IsSystemSection() ? kLibsFromDefault
-                                          : kLibsFromUnrestrictedDefault);
+
+  ns.GetLink(ctx.GetSystemNamespaceName()).AddSharedLib(kLibsFromDefault);
 
   return ns;
 }
diff --git a/contents/namespace/systemdefault.cc b/contents/namespace/systemdefault.cc
index 2915cd4..03bee7c 100644
--- a/contents/namespace/systemdefault.cc
+++ b/contents/namespace/systemdefault.cc
@@ -14,25 +14,14 @@
  * limitations under the License.
  */
 
-#include "linkerconfig/namespacebuilder.h"
-
 #include "linkerconfig/environment.h"
 #include "linkerconfig/namespace.h"
+#include "linkerconfig/namespacebuilder.h"
 
 using android::linkerconfig::modules::AsanPath;
 using android::linkerconfig::modules::Namespace;
 
 namespace {
-const std::vector<std::string> kLibsFromArtLegacy = {
-    "libart.so:libartd.so",
-    "libdexfile_external.so",
-    "libnativebridge.so",
-    "libnativehelper.so",
-    "libnativeloader.so",
-    "libandroidicu.so",
-    // TODO(b/122876336): Remove libpac.so once it's migrated to Webview
-    "libpac.so"};
-
 const std::vector<std::string> kLibsFromArt = {
     "libdexfile_external.so",
     "libdexfiled_external.so",
@@ -41,10 +30,11 @@
     "libnativeloader.so",
     "libandroidicu.so",
     "libpac.so",
-    // TODO(b/120786417 or b/134659294): libicuuc.so and libicui18n.so are kept
-    // for app compat.
+    // TODO(b/120786417 or b/134659294): libicuuc.so
+    // and libicui18n.so are kept for app compat.
     "libicui18n.so",
-    "libicuuc.so"};
+    "libicuuc.so",
+};
 
 const std::vector<std::string> kPermittedPaths = {
     "/system/${LIB}/drm",
@@ -89,23 +79,25 @@
 namespace linkerconfig {
 namespace contents {
 Namespace BuildSystemDefaultNamespace([[maybe_unused]] const Context& ctx) {
-  bool is_legacy = android::linkerconfig::modules::IsLegacyDevice();
-  Namespace ns("default", /*is_isolated=*/!is_legacy,
+  bool is_fully_treblelized = ctx.IsDefaultConfig();
+  Namespace ns("default",
+               /*is_isolated=*/is_fully_treblelized,
                /*is_visible=*/true);
 
   ns.AddSearchPath("/system/${LIB}", AsanPath::WITH_DATA_ASAN);
   ns.AddSearchPath("/@{SYSTEM_EXT:system_ext}/${LIB}", AsanPath::WITH_DATA_ASAN);
   ns.AddSearchPath("/@{PRODUCT:product}/${LIB}", AsanPath::WITH_DATA_ASAN);
-  if (is_legacy) {
+  if (!is_fully_treblelized) {
     ns.AddSearchPath("/vendor/${LIB}", AsanPath::WITH_DATA_ASAN);
     ns.AddSearchPath("/odm/${LIB}", AsanPath::WITH_DATA_ASAN);
   }
 
-  if (!is_legacy) {
+  if (is_fully_treblelized) {
     BuildPermittedPath(ns);
   }
 
-  ns.GetLink("art").AddSharedLib(is_legacy ? kLibsFromArtLegacy : kLibsFromArt);
+  ns.GetLink("art").AddSharedLib(kLibsFromArt);
+
   ns.GetLink("resolv").AddSharedLib("libnetd_resolv.so");
   ns.GetLink("neuralnetworks").AddSharedLib("libneuralnetworks.so");
 
diff --git a/contents/namespace/vendordefault.cc b/contents/namespace/vendordefault.cc
index 9322cee..669f30d 100644
--- a/contents/namespace/vendordefault.cc
+++ b/contents/namespace/vendordefault.cc
@@ -14,24 +14,64 @@
  * limitations under the License.
  */
 
-#include "linkerconfig/namespacebuilder.h"
-
 #include "linkerconfig/environment.h"
+#include "linkerconfig/namespacebuilder.h"
 
 using android::linkerconfig::modules::AsanPath;
 using android::linkerconfig::modules::GetVendorVndkVersion;
 using android::linkerconfig::modules::Namespace;
 
+namespace {
+const std::vector<std::string> kVndkLiteArtLibs = {
+    "libdexfile_external.so",
+    "libdexfiled_external.so",
+    "libnativebridge.so",
+    "libnativehelper.so",
+    "libnativeloader.so",
+    // TODO(b/120786417 or b/134659294): libicuuc.so
+    // and libicui18n.so are kept for app compat.
+    "libicui18n.so",
+    "libicuuc.so",
+};
+}  // namespace
+
 namespace android {
 namespace linkerconfig {
 namespace contents {
 Namespace BuildVendorDefaultNamespace([[maybe_unused]] const Context& ctx) {
-  Namespace ns("default", /*is_isolated=*/true, /*is_visible=*/true);
+  bool is_vndklite = ctx.IsVndkliteConfig();
+
+  Namespace ns(
+      "default", /*is_isolated=*/!is_vndklite, /*is_visible=*/!is_vndklite);
 
   ns.AddSearchPath("/odm/${LIB}", AsanPath::WITH_DATA_ASAN);
-  ns.AddSearchPath("/vendor/${LIB}", AsanPath::WITH_DATA_ASAN);
+  // Allow loosen restriction between vndk and private platform libraries
+  if (is_vndklite) {
+    ns.AddSearchPath("/odm/${LIB}/vndk", AsanPath::WITH_DATA_ASAN);
+    ns.AddSearchPath("/odm/${LIB}/vndk-sp", AsanPath::WITH_DATA_ASAN);
+  }
 
-  if (GetVendorVndkVersion() == "27") {
+  ns.AddSearchPath("/vendor/${LIB}", AsanPath::WITH_DATA_ASAN);
+  // Allow loosen restriction between vndk and private platform libraries
+  if (is_vndklite) {
+    ns.AddSearchPath("/vendor/${LIB}/vndk", AsanPath::WITH_DATA_ASAN);
+    ns.AddSearchPath("/vendor/${LIB}/vndk-sp", AsanPath::WITH_DATA_ASAN);
+  }
+
+  // VNDK-Lite devices require broader access from vendor to system/product partition
+  if (is_vndklite) {
+    ns.AddSearchPath("/system/${LIB}/vndk-sp-@{VNDK_VER}",
+                     AsanPath::WITH_DATA_ASAN);
+    ns.AddSearchPath("/system/${LIB}", AsanPath::WITH_DATA_ASAN);
+    ns.AddSearchPath("/@{SYSTEM_EXT:system_ext}/${LIB}",
+                     AsanPath::WITH_DATA_ASAN);
+    ns.AddSearchPath("/@{PRODUCT:product}/${LIB}", AsanPath::WITH_DATA_ASAN);
+    // Put /system/lib/vndk at the last search order in vndk_lite for GSI
+    ns.AddSearchPath("/system/${LIB}/vndk-@{VNDK_VER}",
+                     AsanPath::WITH_DATA_ASAN);
+  }
+
+  if (ctx.IsDefaultConfig() && GetVendorVndkVersion() == "27") {
     ns.AddSearchPath("/vendor/${LIB}/hw", AsanPath::WITH_DATA_ASAN);
     ns.AddSearchPath("/vendor/${LIB}/egl", AsanPath::WITH_DATA_ASAN);
   }
@@ -40,12 +80,16 @@
   ns.AddPermittedPath("/vendor", AsanPath::WITH_DATA_ASAN);
   ns.AddPermittedPath("/system/vendor", AsanPath::NONE);
 
-  ns.GetLink(ctx.GetSystemNamespaceName()).AddSharedLib("@{LLNDK_LIBRARIES}");
-  ns.GetLink("vndk").AddSharedLib(
-      {"@{VNDK_SAMEPROCESS_LIBRARIES}", "@{VNDK_CORE_LIBRARIES}"});
-  if (android::linkerconfig::modules::IsVndkInSystemNamespace()) {
-    ns.GetLink("vndk_in_system")
-        .AddSharedLib("@{VNDK_USING_CORE_VARIANT_LIBRARIES}");
+  if (is_vndklite) {
+    ns.GetLink("art").AddSharedLib(kVndkLiteArtLibs);
+  } else {
+    ns.GetLink(ctx.GetSystemNamespaceName()).AddSharedLib("@{LLNDK_LIBRARIES}");
+    ns.GetLink("vndk").AddSharedLib(
+        {"@{VNDK_SAMEPROCESS_LIBRARIES}", "@{VNDK_CORE_LIBRARIES}"});
+    if (android::linkerconfig::modules::IsVndkInSystemNamespace()) {
+      ns.GetLink("vndk_in_system")
+          .AddSharedLib("@{VNDK_USING_CORE_VARIANT_LIBRARIES}");
+    }
   }
   ns.GetLink("neuralnetworks").AddSharedLib("libneuralnetworks.so");
 
diff --git a/contents/namespace/vndk.cc b/contents/namespace/vndk.cc
index 593121c..2ffeef7 100644
--- a/contents/namespace/vndk.cc
+++ b/contents/namespace/vndk.cc
@@ -26,6 +26,7 @@
 namespace contents {
 Namespace BuildVndkNamespace([[maybe_unused]] const Context& ctx) {
   bool is_system_section = ctx.IsSystemSection();
+  bool is_vndklite = ctx.IsVndkliteConfig();
   Namespace ns("vndk",
                /*is_isolated=*/is_system_section,
                /*is_visible=*/is_system_section);
@@ -47,7 +48,9 @@
     ns.AddPermittedPath("/odm/${LIB}/egl", AsanPath::WITH_DATA_ASAN);
     ns.AddPermittedPath("/vendor/${LIB}/hw", AsanPath::WITH_DATA_ASAN);
     ns.AddPermittedPath("/vendor/${LIB}/egl", AsanPath::WITH_DATA_ASAN);
-    ns.AddPermittedPath("/system/vendor/${LIB}/hw", AsanPath::NONE);
+    if (!is_vndklite) {
+      ns.AddPermittedPath("/system/vendor/${LIB}/hw", AsanPath::NONE);
+    }
     ns.AddPermittedPath("/system/vendor/${LIB}/egl", AsanPath::NONE);
     ns.AddPermittedPath("/apex/com.android.vndk.v@{VNDK_VER}/${LIB}/hw",
                         AsanPath::SAME_PATH);
@@ -55,14 +58,16 @@
 
   ns.GetLink(ctx.GetSystemNamespaceName()).AddSharedLib({"@{LLNDK_LIBRARIES}"});
 
-  if (is_system_section) {
-    ns.GetLink("sphal").AllowAllSharedLibs();
-  } else {
-    ns.GetLink("default").AllowAllSharedLibs();
+  if (!is_vndklite) {
+    if (is_system_section) {
+      ns.GetLink("sphal").AllowAllSharedLibs();
+    } else {
+      ns.GetLink("default").AllowAllSharedLibs();
 
-    if (android::linkerconfig::modules::IsVndkInSystemNamespace()) {
-      ns.GetLink("vndk_in_system")
-          .AddSharedLib("@{VNDK_USING_CORE_VARIANT_LIBRARIES}");
+      if (android::linkerconfig::modules::IsVndkInSystemNamespace()) {
+        ns.GetLink("vndk_in_system")
+            .AddSharedLib("@{VNDK_USING_CORE_VARIANT_LIBRARIES}");
+      }
     }
   }
 
diff --git a/contents/section/vendor.cc b/contents/section/vendor.cc
index 0b70e22..7674433 100644
--- a/contents/section/vendor.cc
+++ b/contents/section/vendor.cc
@@ -32,10 +32,17 @@
   ctx.SetCurrentSection(SectionType::Vendor);
   std::vector<Namespace> namespaces;
 
+  bool is_vndklite = ctx.IsVndkliteConfig();
+
   namespaces.emplace_back(BuildVendorDefaultNamespace(ctx));
   namespaces.emplace_back(BuildArtNamespace(ctx));
-  namespaces.emplace_back(BuildVndkNamespace(ctx));
-  namespaces.emplace_back(BuildSystemNamespace(ctx));
+  // VNDK-Lite devices does not contain VNDK and System namespace in vendor
+  // section. Instead they (except libraries from APEX) will be loaded from
+  // default namespace, so VNDK libraries can access private platform libraries.
+  if (!is_vndklite) {
+    namespaces.emplace_back(BuildVndkNamespace(ctx));
+    namespaces.emplace_back(BuildSystemNamespace(ctx));
+  }
   namespaces.emplace_back(BuildNeuralNetworksNamespace(ctx));
 
   if (android::linkerconfig::modules::IsVndkInSystemNamespace()) {
diff --git a/contents/tests/backward_compatibility/legacy_test.cc b/contents/tests/backward_compatibility/legacy_test.cc
index 22d5171..3afaf79 100644
--- a/contents/tests/backward_compatibility/legacy_test.cc
+++ b/contents/tests/backward_compatibility/legacy_test.cc
@@ -18,11 +18,13 @@
 
 #include "linkerconfig/legacy.h"
 #include "linkerconfig/variables.h"
+#include "testbase.h"
 
 using android::linkerconfig::modules::AsanPath;
 
-TEST(linkerconfig_legacy, backward_compatibility) {
-  android::linkerconfig::modules::Variables::AddValue("is_legacy", "true");
+TEST(linkerconfig_legacy_backward_compatibility, default_namespace) {
+  MockVariables();
+
   auto config = android::linkerconfig::contents::CreateLegacyConfiguration();
 
   auto legacy_section = config.GetSection("legacy");
diff --git a/contents/tests/backward_compatibility/testbase.h b/contents/tests/backward_compatibility/testbase.h
index affbc30..ccfed2e 100644
--- a/contents/tests/backward_compatibility/testbase.h
+++ b/contents/tests/backward_compatibility/testbase.h
@@ -34,4 +34,8 @@
                                                       "vndk_core_libraries");
   android::linkerconfig::modules::Variables::AddValue(
       "VNDK_USING_CORE_VARIANT_LIBRARIES", "vndk_using_core_variant_libraries");
+}
+
+inline void MockVnkdLite() {
+  android::linkerconfig::modules::Variables::AddValue("ro.vndk.lite", "true");
 }
\ No newline at end of file
diff --git a/contents/tests/backward_compatibility/vndklite_test.cc b/contents/tests/backward_compatibility/vndklite_test.cc
new file mode 100644
index 0000000..73b5aa7
--- /dev/null
+++ b/contents/tests/backward_compatibility/vndklite_test.cc
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include "linkerconfig/baseconfig.h"
+#include "linkerconfig/variables.h"
+#include "testbase.h"
+
+using android::linkerconfig::modules::AsanPath;
+
+TEST(linkerconfig_vndklite_backward_compatibility, system_section) {
+  MockVariables();
+  MockVnkdLite();
+
+  auto config = android::linkerconfig::contents::CreateBaseConfiguration();
+
+  auto system_section = config.GetSection("system");
+  ASSERT_TRUE(system_section);
+
+  auto default_namespace = system_section->GetNamespace("default");
+  ASSERT_TRUE(default_namespace);
+
+  EXPECT_TRUE(default_namespace->ContainsSearchPath("/vendor/${LIB}",
+                                                    AsanPath::WITH_DATA_ASAN));
+  EXPECT_TRUE(default_namespace->ContainsSearchPath("/odm/${LIB}",
+                                                    AsanPath::WITH_DATA_ASAN));
+
+  auto sphal_namespace = system_section->GetNamespace("sphal");
+  ASSERT_TRUE(sphal_namespace);
+
+  EXPECT_TRUE(sphal_namespace->ContainsSearchPath("/odm/${LIB}",
+                                                  AsanPath::WITH_DATA_ASAN));
+  EXPECT_TRUE(sphal_namespace->ContainsSearchPath("/vendor/${LIB}",
+                                                  AsanPath::WITH_DATA_ASAN));
+  EXPECT_TRUE(
+      sphal_namespace->ContainsSearchPath("/vendor/${LIB}/hw", AsanPath::NONE));
+
+  EXPECT_TRUE(sphal_namespace->ContainsPermittedPath("/odm/${LIB}",
+                                                     AsanPath::WITH_DATA_ASAN));
+  EXPECT_TRUE(sphal_namespace->ContainsPermittedPath("/vendor/${LIB}",
+                                                     AsanPath::WITH_DATA_ASAN));
+  EXPECT_TRUE(sphal_namespace->ContainsPermittedPath("/system/vendor/${LIB}",
+                                                     AsanPath::NONE));
+
+  auto rs_namespace = system_section->GetNamespace("rs");
+  ASSERT_TRUE(rs_namespace);
+
+  EXPECT_TRUE(rs_namespace->ContainsSearchPath("/odm/${LIB}/vndk-sp",
+                                               AsanPath::WITH_DATA_ASAN));
+  EXPECT_TRUE(rs_namespace->ContainsSearchPath("/vendor/${LIB}/vndk-sp",
+                                               AsanPath::WITH_DATA_ASAN));
+  EXPECT_TRUE(rs_namespace->ContainsSearchPath("/odm/${LIB}",
+                                               AsanPath::WITH_DATA_ASAN));
+  EXPECT_TRUE(rs_namespace->ContainsSearchPath("/vendor/${LIB}",
+                                               AsanPath::WITH_DATA_ASAN));
+
+  EXPECT_TRUE(rs_namespace->ContainsPermittedPath("/odm/${LIB}",
+                                                  AsanPath::WITH_DATA_ASAN));
+  EXPECT_TRUE(rs_namespace->ContainsPermittedPath("/vendor/${LIB}",
+                                                  AsanPath::WITH_DATA_ASAN));
+  EXPECT_TRUE(rs_namespace->ContainsPermittedPath("/system/vendor/${LIB}",
+                                                  AsanPath::NONE));
+
+  auto vndk_namespace = system_section->GetNamespace("vndk");
+  ASSERT_TRUE(vndk_namespace);
+
+  EXPECT_TRUE(vndk_namespace->ContainsSearchPath("/odm/${LIB}/vndk-sp",
+                                                 AsanPath::WITH_DATA_ASAN));
+  EXPECT_TRUE(vndk_namespace->ContainsSearchPath("/vendor/${LIB}/vndk-sp",
+                                                 AsanPath::WITH_DATA_ASAN));
+
+  EXPECT_TRUE(vndk_namespace->ContainsPermittedPath("/odm/${LIB}/hw",
+                                                    AsanPath::WITH_DATA_ASAN));
+  EXPECT_TRUE(vndk_namespace->ContainsPermittedPath("/odm/${LIB}/egl",
+                                                    AsanPath::WITH_DATA_ASAN));
+  EXPECT_TRUE(vndk_namespace->ContainsPermittedPath("/vendor/${LIB}/hw",
+                                                    AsanPath::WITH_DATA_ASAN));
+  EXPECT_TRUE(vndk_namespace->ContainsPermittedPath("/vendor/${LIB}/egl",
+                                                    AsanPath::WITH_DATA_ASAN));
+}
+
+TEST(linkerconfig_vndklite_backward_compatibility, vendor_section) {
+  MockVariables();
+  MockVnkdLite();
+
+  auto config = android::linkerconfig::contents::CreateBaseConfiguration();
+
+  auto vendor_section = config.GetSection("vendor");
+  ASSERT_TRUE(vendor_section);
+
+  auto default_namespace = vendor_section->GetNamespace("default");
+  ASSERT_TRUE(default_namespace);
+
+  EXPECT_TRUE(default_namespace->ContainsSearchPath("/odm/${LIB}",
+                                                    AsanPath::WITH_DATA_ASAN));
+  EXPECT_TRUE(default_namespace->ContainsSearchPath("/odm/${LIB}/vndk",
+                                                    AsanPath::WITH_DATA_ASAN));
+  EXPECT_TRUE(default_namespace->ContainsSearchPath("/odm/${LIB}/vndk-sp",
+                                                    AsanPath::WITH_DATA_ASAN));
+  EXPECT_TRUE(default_namespace->ContainsSearchPath("/vendor/${LIB}",
+                                                    AsanPath::WITH_DATA_ASAN));
+  EXPECT_TRUE(default_namespace->ContainsSearchPath("/vendor/${LIB}/vndk",
+                                                    AsanPath::WITH_DATA_ASAN));
+  EXPECT_TRUE(default_namespace->ContainsSearchPath("/vendor/${LIB}/vndk-sp",
+                                                    AsanPath::WITH_DATA_ASAN));
+}
+
+TEST(linkerconfig_vndklite_backward_compatibility, unrestricted_section) {
+  MockVariables();
+  MockVnkdLite();
+
+  auto config = android::linkerconfig::contents::CreateBaseConfiguration();
+
+  auto unrestricted_section = config.GetSection("unrestricted");
+  ASSERT_TRUE(unrestricted_section);
+
+  auto default_namespace = unrestricted_section->GetNamespace("default");
+  ASSERT_TRUE(default_namespace);
+
+  EXPECT_TRUE(default_namespace->ContainsSearchPath("/odm/${LIB}",
+                                                    AsanPath::WITH_DATA_ASAN));
+  EXPECT_TRUE(default_namespace->ContainsSearchPath("/vendor/${LIB}",
+                                                    AsanPath::WITH_DATA_ASAN));
+}
\ No newline at end of file
diff --git a/contents/tests/configuration/baseconfig_test.cc b/contents/tests/configuration/baseconfig_test.cc
index 231b087..c10003d 100644
--- a/contents/tests/configuration/baseconfig_test.cc
+++ b/contents/tests/configuration/baseconfig_test.cc
@@ -29,6 +29,19 @@
   VerifyConfiguration(config_writer.ToString());
 }
 
+TEST(linkerconfig_configuration_fulltest,
+     baseconfig_vndk_using_core_variant_test) {
+  MockGenericVariables();
+  MockVndkUsingCoreVariant();
+
+  auto base_config = android::linkerconfig::contents::CreateBaseConfiguration();
+  android::linkerconfig::modules::ConfigWriter config_writer;
+
+  base_config.WriteConfig(config_writer);
+
+  VerifyConfiguration(config_writer.ToString());
+}
+
 TEST(linkerconfig_configuration_fulltest, baseconfig_vndk_27_test) {
   MockGenericVariables();
   MockVndkVersion("27");
@@ -38,4 +51,17 @@
   base_config.WriteConfig(config_writer);
 
   VerifyConfiguration(config_writer.ToString());
+}
+
+TEST(linkerconfig_configuration_fulltest, vndklite_test) {
+  MockGenericVariables();
+  MockVnkdLite();
+
+  auto vndklite_config =
+      android::linkerconfig::contents::CreateBaseConfiguration();
+  android::linkerconfig::modules::ConfigWriter config_writer;
+
+  vndklite_config.WriteConfig(config_writer);
+
+  VerifyConfiguration(config_writer.ToString());
 }
\ No newline at end of file
diff --git a/contents/tests/configuration/include/mockenv.h b/contents/tests/configuration/include/mockenv.h
index f7e37f7..2815b4a 100644
--- a/contents/tests/configuration/include/mockenv.h
+++ b/contents/tests/configuration/include/mockenv.h
@@ -33,9 +33,18 @@
   android::linkerconfig::modules::Variables::AddValue("VNDK_CORE_LIBRARIES",
                                                       "vndk_core_libraries");
   android::linkerconfig::modules::Variables::AddValue(
-      "VNDK_USING_CORE_VARIANT_LIBRARIES", "vndk_using_core_variant_libraries");
+      "VNDK_USING_CORE_VARIANT_LIBRARIES", "");
 }
 
 inline void MockVndkVersion(std::string vndk_version) {
   android::linkerconfig::modules::Variables::AddValue("VNDK_VER", vndk_version);
+}
+
+inline void MockVndkUsingCoreVariant() {
+  android::linkerconfig::modules::Variables::AddValue(
+      "VNDK_USING_CORE_VARIANT_LIBRARIES", "vndk_using_core_variant_libraries");
+}
+
+inline void MockVnkdLite() {
+  android::linkerconfig::modules::Variables::AddValue("ro.vndk.lite", "true");
 }
\ No newline at end of file
diff --git a/main.cc b/main.cc
index a7dc090..a721485 100644
--- a/main.cc
+++ b/main.cc
@@ -15,12 +15,15 @@
  */
 
 #include <getopt.h>
+
 #include <cstring>
 #include <fstream>
 #include <iostream>
 #include <string>
 
 #include "linkerconfig/baseconfig.h"
+#include "linkerconfig/environment.h"
+#include "linkerconfig/legacy.h"
 #include "linkerconfig/log.h"
 #include "linkerconfig/variableloader.h"
 #include "linkerconfig/variables.h"
@@ -81,9 +84,9 @@
 }
 
 android::linkerconfig::modules::Configuration GetConfiguration() {
-  // TODO : Use legacy if needed
-
-  // TODO : Use vndk lite if needed
+  if (android::linkerconfig::modules::IsLegacyDevice()) {
+    return android::linkerconfig::contents::CreateLegacyConfiguration();
+  }
 
   // TODO : Use recovery if needed
 
diff --git a/modules/environment.cc b/modules/environment.cc
index d79c066..198e1e9 100644
--- a/modules/environment.cc
+++ b/modules/environment.cc
@@ -15,17 +15,18 @@
  */
 
 #include "linkerconfig/environment.h"
-
 #include "linkerconfig/variables.h"
 
 namespace android {
 namespace linkerconfig {
 namespace modules {
 bool IsLegacyDevice() {
-  // TODO : Implement
-  auto legacy_device = Variables::GetValue("is_legacy").value_or("false");
+  return !Variables::GetValue("ro.vndk.version").has_value() &&
+         !Variables::GetValue("ro.vndk.lite").has_value();
+}
 
-  return legacy_device == "true";
+bool IsVndkLiteDevice() {
+  return Variables::GetValue("ro.vndk.lite").value_or("") == "true";
 }
 
 bool IsVndkInSystemNamespace() {
diff --git a/modules/include/linkerconfig/environment.h b/modules/include/linkerconfig/environment.h
index 48c50a7..44eecae 100644
--- a/modules/include/linkerconfig/environment.h
+++ b/modules/include/linkerconfig/environment.h
@@ -20,6 +20,7 @@
 namespace linkerconfig {
 namespace modules {
 bool IsLegacyDevice();
+bool IsVndkLiteDevice();
 bool IsVndkInSystemNamespace();
 std::string GetVendorVndkVersion();
 }  // namespace modules