Change BootActions to use oem.props.

Use /oem/oem.props to configure what the library name for the boot
action
will be, expect that library to be found in /oem/lib

Bug: 62090281
Test: Ran locally against an imx7d, reads oem.props, finds, and loads
library.

Change-Id: I13c161e140747091595efa36f76297ba92cdfa4d
diff --git a/cmds/bootanimation/iot/BootAction.cpp b/cmds/bootanimation/iot/BootAction.cpp
index 8fda87e..889eb2f 100644
--- a/cmds/bootanimation/iot/BootAction.cpp
+++ b/cmds/bootanimation/iot/BootAction.cpp
@@ -37,7 +37,7 @@
     }
 }
 
-bool BootAction::init(const std::string& libraryPath, const std::string& config) {
+bool BootAction::init(const std::string& libraryPath) {
     APeripheralManagerClient* client = nullptr;
     ALOGD("Connecting to peripheralmanager");
     // Wait for peripheral manager to come up.
@@ -51,16 +51,11 @@
     ALOGD("Peripheralmanager is up.");
     APeripheralManagerClient_delete(client);
 
-    std::string path_to_lib = libraryPath;
-    if (!parseConfig(config, &path_to_lib)) {
-        return false;
-    }
-
-    ALOGI("Loading boot action %s", path_to_lib.c_str());
-    mLibHandle = dlopen(path_to_lib.c_str(), RTLD_NOW);
+    ALOGI("Loading boot action %s", libraryPath.c_str());
+    mLibHandle = dlopen(libraryPath.c_str(), RTLD_NOW);
     if (mLibHandle == nullptr) {
         ALOGE("Unable to load library at %s :: %s",
-              path_to_lib.c_str(), dlerror());
+              libraryPath.c_str(), dlerror());
         return false;
     }
 
@@ -115,61 +110,4 @@
     return true;
 }
 
-
-bool BootAction::parseConfig(const std::string& config, std::string* path) {
-    auto lines = Split(config, "\n");
-
-    if (lines.size() < 1) {
-        ALOGE("Config format invalid, expected one line, found %d",
-              lines.size());
-        return false;
-    }
-
-    size_t lineNumber = 0;
-    auto& line1 = lines.at(lineNumber);
-    while (StartsWith(line1, "#")) {
-      if (lines.size() < ++lineNumber) {
-        ALOGE("Config file contains no non-comment lines.");
-        return false;
-      }
-      line1 = lines.at(lineNumber);
-    }
-
-    const std::string libraryNameToken("LIBRARY_NAME=");
-    if (!StartsWith(line1, libraryNameToken.c_str())) {
-        ALOGE("Invalid config format, expected second line to start  with %s "
-              "Instead found: %s", libraryNameToken.c_str(), line1.c_str());
-        return false;
-    }
-
-    std::string libraryName = line1.substr(libraryNameToken.length());
-
-    *path += "/";
-    *path += architectureDirectory();
-    *path += "/";
-    *path += libraryName;
-
-    return true;
-}
-
-const char* BootAction::architectureDirectory() {
-  switch(android_getCpuFamily()) {
-      case ANDROID_CPU_FAMILY_ARM:
-          return "arm";
-      case ANDROID_CPU_FAMILY_X86:
-          return "x86";
-      case ANDROID_CPU_FAMILY_MIPS:
-          return "mips";
-      case ANDROID_CPU_FAMILY_ARM64:
-          return "arm64";
-      case ANDROID_CPU_FAMILY_X86_64:
-          return "x86_64";
-      case ANDROID_CPU_FAMILY_MIPS64:
-          return "mips64";
-      default:
-          ALOGE("Unsupported cpu family: %d", android_getCpuFamily());
-          return "";
-  }
-}
-
 }  // namespace android
diff --git a/cmds/bootanimation/iot/BootAction.h b/cmds/bootanimation/iot/BootAction.h
index 31d0d1f..495aa4f 100644
--- a/cmds/bootanimation/iot/BootAction.h
+++ b/cmds/bootanimation/iot/BootAction.h
@@ -26,11 +26,9 @@
 class BootAction : public RefBase {
 public:
     ~BootAction();
-    // Parse the contents of the config file. We expect one line:
-    // LIBRARY_NAME=
-    //
-    // LIBRARY_NAME is the name of the shared library that contains the boot action.
-    bool init(const std::string& libraryPath, const std::string& config);
+
+    // libraryPath is a fully qualified path to the target .so library.
+    bool init(const std::string& libraryPath);
 
     // The animation is going to start playing partNumber for the playCount'th
     // time, update the action as needed.
@@ -47,9 +45,7 @@
     typedef void (*libStartPart)(int partNumber, int playNumber);
     typedef void (*libShutdown)();
 
-    bool parseConfig(const std::string& config, std::string* path);
     bool loadSymbol(const char* symbol, void** loaded);
-    const char* architectureDirectory();
 
     void* mLibHandle = nullptr;
     libInit mLibInit = nullptr;
diff --git a/cmds/bootanimation/iot/iotbootanimation_main.cpp b/cmds/bootanimation/iot/iotbootanimation_main.cpp
index d1ae786..d62478b 100644
--- a/cmds/bootanimation/iot/iotbootanimation_main.cpp
+++ b/cmds/bootanimation/iot/iotbootanimation_main.cpp
@@ -39,17 +39,21 @@
 
 class BootActionAnimationCallbacks : public android::BootAnimation::Callbacks {public:
     void init(const Vector<Animation::Part>&) override {
-        // Create and initialize BootActions if we have a boot_action.conf.
-        std::string bootActionConf;
-        if (ReadFileToString("/oem/app/etc/boot_action.conf", &bootActionConf)) {
-            mBootAction = new BootAction();
-            if (!mBootAction->init("/oem/app/lib", bootActionConf)) {
-                mBootAction = NULL;
-            }
-        } else {
-            ALOGI("No boot actions specified");
-        }
+        std::string library_path("/oem/lib/");
 
+        // This value is optionally provided by the user and will be written to
+        // /oem/oem.prop.
+        char property[PROP_VALUE_MAX] = {0};
+        if (property_get("ro.oem.bootactions.lib", property, "") < 1) {
+            ALOGI("No bootaction specified");
+            return;
+        }
+        library_path += property;
+
+        mBootAction = new BootAction();
+        if (!mBootAction->init(library_path)) {
+            mBootAction = NULL;
+        }
     };
 
     void playPart(int partNumber, const Animation::Part&, int playNumber) override {