Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ecffc47f authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Change BootActions to use oem.props."

parents 9482963b 428ed51f
Loading
Loading
Loading
Loading
+4 −66
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ BootAction::~BootAction() {
    }
}

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 @@ bool BootAction::init(const std::string& libraryPath, const std::string& config)
    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 @@ bool BootAction::loadSymbol(const char* symbol, void** loaded) {
    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
+3 −7
Original line number Diff line number Diff line
@@ -26,11 +26,9 @@ namespace android {
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 @@ private:
    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;
+13 −9
Original line number Diff line number Diff line
@@ -39,17 +39,21 @@ namespace {

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)) {
        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("/oem/app/lib", bootActionConf)) {
        if (!mBootAction->init(library_path)) {
            mBootAction = NULL;
        }
        } else {
            ALOGI("No boot actions specified");
        }

    };

    void playPart(int partNumber, const Animation::Part&, int playNumber) override {