Use apex name for apex linker namespace

Linkerconfig now uses apex_names to automatically generate linker
namespaces from apexes.

Bug: 148826508
Test: build / boot
Change-Id: Id7fa68531033124727e618284af4fd2a61bdd85f
diff --git a/libnativeloader/library_namespaces.cpp b/libnativeloader/library_namespaces.cpp
index 08a2290..5971917 100644
--- a/libnativeloader/library_namespaces.cpp
+++ b/libnativeloader/library_namespaces.cpp
@@ -42,9 +42,9 @@
 // vendor and system namespaces.
 constexpr const char* kVendorNamespaceName = "sphal";
 constexpr const char* kVndkNamespaceName = "vndk";
-constexpr const char* kArtNamespaceName = "art";
-constexpr const char* kNeuralNetworksNamespaceName = "neuralnetworks";
-constexpr const char* kCronetNamespaceName = "cronet";
+constexpr const char* kArtNamespaceName = "com.android.art";
+constexpr const char* kNeuralNetworksNamespaceName = "com.android.neuralnetworks";
+constexpr const char* kCronetNamespaceName = "com.android.cronet";
 
 // classloader-namespace is a linker namespace that is created for the loaded
 // app. To be specific, it is created for the app classloader. When
diff --git a/libnativeloader/native_loader.cpp b/libnativeloader/native_loader.cpp
index 4e5189b..3998f61 100644
--- a/libnativeloader/native_loader.cpp
+++ b/libnativeloader/native_loader.cpp
@@ -52,17 +52,15 @@
 android_namespace_t* FindExportedNamespace(const char* caller_location) {
   std::string location = caller_location;
   // Lots of implicit assumptions here: we expect `caller_location` to be of the form:
-  // /apex/com.android...modulename/...
+  // /apex/modulename/...
   //
   // And we extract from it 'modulename', which is the name of the linker namespace.
   if (android::base::StartsWith(location, kApexPath)) {
-    size_t slash_index = location.find_first_of('/', strlen(kApexPath));
+    size_t start_index = strlen(kApexPath);
+    size_t slash_index = location.find_first_of('/', start_index);
     LOG_ALWAYS_FATAL_IF((slash_index == std::string::npos),
                         "Error finding namespace of apex: no slash in path %s", caller_location);
-    size_t dot_index = location.find_last_of('.', slash_index);
-    LOG_ALWAYS_FATAL_IF((dot_index == std::string::npos),
-                        "Error finding namespace of apex: no dot in apex name %s", caller_location);
-    std::string name = location.substr(dot_index + 1, slash_index - dot_index - 1);
+    std::string name = location.substr(start_index, slash_index - start_index);
     android_namespace_t* boot_namespace = android_get_exported_namespace(name.c_str());
     LOG_ALWAYS_FATAL_IF((boot_namespace == nullptr),
                         "Error finding namespace of apex: no namespace called %s", name.c_str());
diff --git a/libnativeloader/native_loader_test.cpp b/libnativeloader/native_loader_test.cpp
index e73af6d..39cc753 100644
--- a/libnativeloader/native_loader_test.cpp
+++ b/libnativeloader/native_loader_test.cpp
@@ -94,11 +94,11 @@
 static std::unordered_map<std::string, Platform::mock_namespace_handle> namespaces = {
     {"system", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("system"))},
     {"default", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("default"))},
-    {"art", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("art"))},
+    {"com.android.art", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("com.android.art"))},
     {"sphal", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("sphal"))},
     {"vndk", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("vndk"))},
-    {"neuralnetworks", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("neuralnetworks"))},
-    {"cronet", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("cronet"))},
+    {"com.android.neuralnetworks", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("com.android.neuralnetworks"))},
+    {"com.android.cronet", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("com.android.cronet"))},
 };
 
 // The actual gmock object
@@ -383,7 +383,7 @@
           .WillOnce(Return(true));
     }
     if (expected_link_with_art_ns) {
-      EXPECT_CALL(*mock, mock_link_namespaces(Eq(IsBridged()), _, NsEq("art"),
+      EXPECT_CALL(*mock, mock_link_namespaces(Eq(IsBridged()), _, NsEq("com.android.art"),
                                               StrEq(expected_shared_libs_to_art_ns)))
           .WillOnce(Return(true));
     }
@@ -403,12 +403,12 @@
           .WillOnce(Return(true));
     }
     if (expected_link_with_neuralnetworks_ns) {
-      EXPECT_CALL(*mock, mock_link_namespaces(Eq(IsBridged()), _, NsEq("neuralnetworks"),
+      EXPECT_CALL(*mock, mock_link_namespaces(Eq(IsBridged()), _, NsEq("com.android.neuralnetworks"),
                                               StrEq(expected_shared_libs_to_neuralnetworks_ns)))
           .WillOnce(Return(true));
     }
     if (expected_link_with_cronet_ns) {
-      EXPECT_CALL(*mock, mock_link_namespaces(Eq(IsBridged()), _, NsEq("cronet"),
+      EXPECT_CALL(*mock, mock_link_namespaces(Eq(IsBridged()), _, NsEq("com.android.cronet"),
                                               StrEq(expected_shared_libs_to_cronet_ns)))
           .WillOnce(Return(true));
     }