Check if statssocket is availble before sending atoms

The first APEXd instance starts without any APEXes. Hence it can't use
libraries from APEXes. Even though the method
installAndActivatePackage() is invoked by PackageManager after APEXes
are activated, the first apexd instance may be still alive and serve the
method. In such case, because it can't use APEX libraries
it should check the API availability before using it.

Bug: 281162849
Test: atest StagedRollbackTest
Change-Id: I27f562b90d3efc04857ab1b8091e4b95541f8939
diff --git a/apexd/apexd.cpp b/apexd/apexd.cpp
index 4c169fe..db3434b 100644
--- a/apexd/apexd.cpp
+++ b/apexd/apexd.cpp
@@ -39,6 +39,7 @@
 #include <linux/f2fs.h>
 #include <linux/loop.h>
 #include <selinux/android.h>
+#include <statssocket_lazy.h>
 #include <stdlib.h>
 #include <sys/inotify.h>
 #include <sys/ioctl.h>
@@ -719,6 +720,10 @@
 void SendApexInstallationRequestedAtom(const std::string& package_path,
                                        const bool is_rollback,
                                        const unsigned int install_type) {
+  if (!statssocket::lazy::IsAvailable()) {
+    LOG(WARNING) << "Unable to send Apex Atom; libstatssocket is not available";
+    return;
+  }
   auto apex_file = ApexFile::Open(package_path);
   if (!apex_file.ok()) {
     LOG(WARNING) << "Unable to send Apex Atom; Failed to open ApexFile "
@@ -753,6 +758,10 @@
 
 void SendApexInstallationEndedAtom(const std::string apex_package_path,
                                    int install_result) {
+  if (!statssocket::lazy::IsAvailable()) {
+    LOG(WARNING) << "Unable to send Apex Atom; libstatssocket is not available";
+    return;
+  }
   Result<std::string> apex_file_sha256_str = CalculateSha256(apex_package_path);
   if (!apex_file_sha256_str.ok()) {
     LOG(WARNING) << "Unable to get sha256 of ApexFile: "