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

Commit 938a1327 authored by Elliott Hughes's avatar Elliott Hughes
Browse files

Remove product_is_iot.

Test: treehugger
Change-Id: I975f86999e4e40c06d6239fbc63e200042d37cc4
parent 649965cd
Loading
Loading
Loading
Loading
+0 −27
Original line number Diff line number Diff line
@@ -40,27 +40,6 @@ cc_binary {
        "audioplay.cpp",
    ],

    product_variables: {
        product_is_iot: {
            shared_libs: [
                "libandroidthings",
                "libandroidthings_protos",
                "libchrome",
                "libprotobuf-cpp-lite",
            ],
            static_libs: ["libjsoncpp"],
            srcs: [
                "iot/iotbootanimation_main.cpp",
                "iot/BootAction.cpp",
                "iot/BootParameters.cpp",
            ],
            exclude_srcs: [
                "bootanimation_main.cpp",
                "audioplay.cpp",
            ],
        },
    },

    init_rc: ["bootanim.rc"],
}

@@ -80,10 +59,4 @@ cc_library_shared {
        "libGLESv1_CM",
        "libgui",
    ],

    product_variables: {
        product_is_iot: {
            init_rc: ["iot/bootanim_iot.rc"],
        },
    },
}

cmds/bootanimation/iot/Android.bp

deleted100644 → 0
+0 −49
Original line number Diff line number Diff line
// Copyright (C) 2018 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.
//

// libbootanimation_iot_test
// ===========================================================
cc_test {
    name: "libbootanimation_iot_test",
    cflags: [
        "-Wall",
        "-Werror",
        "-Wunused",
        "-Wunreachable-code",
    ],

    shared_libs: [
        "libandroidthings",
        "libandroidthings_protos",
        "libbase",
        "libchrome",
        "liblog",
        "libprotobuf-cpp-lite",
    ],

    static_libs: ["libjsoncpp"],

    srcs: [
        "BootParameters.cpp",
        "BootParameters_test.cpp",
    ],

    enabled: false,
    product_variables: {
        product_is_iot: {
            enabled: true,
        },
    },
}
+0 −132
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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 "BootAction.h"

#define LOG_TAG "BootAction"

#include <dlfcn.h>

#include <pio/peripheral_manager_client.h>
#include <utils/Log.h>

namespace android {

BootAction::~BootAction() {
    if (mLibHandle != nullptr) {
        dlclose(mLibHandle);
    }
}

bool BootAction::init(const std::string& libraryPath,
                      const std::unique_ptr<BootParameters>& bootParameters) {
    APeripheralManagerClient* client = nullptr;
    ALOGD("Connecting to peripheralmanager");
    // Wait for peripheral manager to come up.
    while (client == nullptr) {
        client = APeripheralManagerClient_new();
        if (client == nullptr) {
          ALOGV("peripheralmanager is not up, sleeping before we check again.");
          usleep(250000);
        }
    }
    ALOGD("Peripheralmanager is up.");
    APeripheralManagerClient_delete(client);


    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",
              libraryPath.c_str(), dlerror());
        return false;
    }

    void* loaded = nullptr;
    if (!loadSymbol("boot_action_init", &loaded) || loaded == nullptr) {
        return false;
    }
    mLibInit = reinterpret_cast<libInit>(loaded);

    loaded = nullptr;
    if (!loadSymbol("boot_action_shutdown", &loaded) || loaded == nullptr) {
        return false;
    }
    mLibShutdown = reinterpret_cast<libShutdown>(loaded);

    // StartPart is considered optional, if it isn't exported by the library
    // we will still call init and shutdown.
    loaded = nullptr;
    if (!loadSymbol("boot_action_start_part", &loaded) || loaded == nullptr) {
        ALOGI("No boot_action_start_part found, action will not be told when "
              "Animation parts change.");
    } else {
        mLibStartPart = reinterpret_cast<libStartPart>(loaded);
    }

    // SilentBoot is considered optional, if it isn't exported by the library
    // and the boot is silent, no method is called.
    loaded = nullptr;
    if (!loadSymbol("boot_action_silent_boot", &loaded) || loaded == nullptr) {
        ALOGW("No boot_action_silent_boot found, boot action will not be "
              "executed during a silent boot.");
    } else {
        mLibSilentBoot = reinterpret_cast<libInit>(loaded);
    }

    bool result = true;
    const auto& parameters = bootParameters->getParameters();
    if (bootParameters->isSilentBoot()) {
        if (mLibSilentBoot != nullptr) {
            ALOGD("Entering boot_action_silent_boot");
            result = mLibSilentBoot(parameters.data(), parameters.size());
            ALOGD("Returned from boot_action_silent_boot");
        } else {
            ALOGW("Skipping missing boot_action_silent_boot");
        }
    } else {
        ALOGD("Entering boot_action_init");
        result = mLibInit(parameters.data(), parameters.size());
        ALOGD("Returned from boot_action_init");
    }

    return result;
}

void BootAction::startPart(int partNumber, int playNumber) {
    if (mLibStartPart == nullptr) return;

    ALOGD("Entering boot_action_start_part");
    mLibStartPart(partNumber, playNumber);
    ALOGD("Returned from boot_action_start_part");
}

void BootAction::shutdown() {
    ALOGD("Entering boot_action_shutdown");
    mLibShutdown();
    ALOGD("Returned from boot_action_shutdown");
}

bool BootAction::loadSymbol(const char* symbol, void** loaded) {
    *loaded = dlsym(mLibHandle, symbol);
    if (*loaded == nullptr) {
        ALOGE("Unable to load symbol : %s :: %s", symbol, dlerror());
        return false;
    }
    return true;
}

}  // namespace android
+0 −68
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.
 */

#ifndef _BOOTANIMATION_BOOTACTION_H
#define _BOOTANIMATION_BOOTACTION_H

#include <string>
#include <vector>

#include "BootParameters.h"

#include <boot_action/boot_action.h>  // libandroidthings native API.
#include <utils/RefBase.h>

namespace android {

class BootAction : public RefBase {
public:
    ~BootAction();

    // libraryPath is a fully qualified path to the target .so library.
    bool init(const std::string& libraryPath,
              const std::unique_ptr<BootParameters>& bootParameters);

    // The animation is going to start playing partNumber for the playCount'th
    // time, update the action as needed.
    // This is run in the same thread as the boot animation,
    // you must not block here.
    void startPart(int partNumber, int playCount);

    // Shutdown the boot action, this will be called shortly before the
    // process is shut down to allow time for cleanup.
    void shutdown();

private:
    typedef bool (*libInit)(const ABootActionParameter* parameters,
                            size_t numParameters);
    typedef void (*libStartPart)(int partNumber, int playNumber);
    typedef void (*libShutdown)();

    bool loadSymbol(const char* symbol, void** loaded);

    void* mLibHandle = nullptr;
    libInit mLibInit = nullptr;
    libStartPart mLibStartPart = nullptr;
    libShutdown mLibShutdown = nullptr;

    // Called only if the boot is silent.
    libInit mLibSilentBoot = nullptr;
};

}  // namespace android


#endif  // _BOOTANIMATION_BOOTACTION_H
+0 −197
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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 "BootParameters.h"

#define LOG_TAG "BootParameters"

#include <errno.h>
#include <fcntl.h>

#include <android-base/file.h>
#include <json/json.h>
#include <utils/Log.h>

using android::base::ReadFileToString;
using android::base::RemoveFileIfExists;
using android::base::WriteStringToFile;
using Json::ArrayIndex;
using Json::Reader;
using Json::Value;

namespace android {

namespace {

// Keys for deprecated parameters. Devices that OTA from N to O and that used
// the hidden BootParameters API will store these in the JSON blob. To support
// the transition from N to O, these keys are mapped to the new parameters.
constexpr const char *kKeyLegacyVolume = "volume";
constexpr const char *kKeyLegacyAnimationsDisabled = "boot_animation_disabled";
constexpr const char *kKeyLegacyParamNames = "param_names";
constexpr const char *kKeyLegacyParamValues = "param_values";

constexpr const char *kNextBootFile = "/data/misc/bootanimation/next_boot.proto";
constexpr const char *kLastBootFile = "/data/misc/bootanimation/last_boot.proto";

constexpr const char *kLegacyNextBootFile = "/data/misc/bootanimation/next_boot.json";
constexpr const char *kLegacyLastBootFile = "/data/misc/bootanimation/last_boot.json";

void removeLegacyFiles() {
    std::string err;
    if (!RemoveFileIfExists(kLegacyLastBootFile, &err)) {
        ALOGW("Unable to delete %s: %s", kLegacyLastBootFile, err.c_str());
    }

    err.clear();
    if (!RemoveFileIfExists(kLegacyNextBootFile, &err)) {
        ALOGW("Unable to delete %s: %s", kLegacyNextBootFile, err.c_str());
    }
}

void createNextBootFile() {
    errno = 0;
    int fd = open(kNextBootFile, O_CREAT, DEFFILEMODE);
    if (fd == -1) {
        ALOGE("Unable to create next boot file: %s", strerror(errno));
    } else {
        // Make next_boot.json writable to everyone so DeviceManagementService
        // can save saved_parameters there.
        if (fchmod(fd, DEFFILEMODE))
            ALOGE("Unable to set next boot file permissions: %s", strerror(errno));
        close(fd);
    }
}

}  // namespace

// Renames the 'next' boot file to the 'last' file and reads its contents.
bool BootParameters::swapAndLoadBootConfigContents(const char *lastBootFile,
                                                   const char *nextBootFile,
                                                   std::string *contents) {
    if (!ReadFileToString(nextBootFile, contents)) {
        RemoveFileIfExists(lastBootFile);
        return false;
    }

    errno = 0;
    if (rename(nextBootFile, lastBootFile) && errno != ENOENT)
        ALOGE("Unable to swap boot files: %s", strerror(errno));

    return true;
}

BootParameters::BootParameters() {
    loadParameters();
}

// Saves the boot parameters state to disk so the framework can read it.
void BootParameters::storeParameters() {
    errno = 0;
    if (!WriteStringToFile(mProto.SerializeAsString(), kLastBootFile)) {
        ALOGE("Failed to write boot parameters to %s: %s", kLastBootFile, strerror(errno));
    }

    // WriteStringToFile sets the file permissions to 0666, but these are not
    // honored by the system.
    errno = 0;
    if (chmod(kLastBootFile, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) {
        ALOGE("Failed to set permissions for %s: %s", kLastBootFile, strerror(errno));
    }
}

// Load the boot parameters from disk, try the old location and format if the
// file does not exist. Note:
// - Parse errors result in defaults being used (a normal boot).
// - Legacy boot parameters default to a silent boot.
void BootParameters::loadParameters() {
    // Precedence is given to the new file format (.proto).
    std::string contents;
    if (swapAndLoadBootConfigContents(kLastBootFile, kNextBootFile, &contents)) {
        parseBootParameters(contents);
    } else if (swapAndLoadBootConfigContents(kLegacyLastBootFile, kLegacyNextBootFile, &contents)) {
        parseLegacyBootParameters(contents);
        storeParameters();
        removeLegacyFiles();
    }

    createNextBootFile();
}

void BootParameters::parseBootParameters(const std::string &contents) {
    if (!mProto.ParseFromString(contents)) {
        ALOGW("Failed to parse parameters from %s", kLastBootFile);
        return;
    }

    loadStateFromProto();
}

// Parses the JSON in the proto.
void BootParameters::parseLegacyBootParameters(const std::string &contents) {
    Value json;
    if (!Reader().parse(contents, json)) {
        ALOGW("Failed to parse parameters from %s", kLegacyLastBootFile);
        return;
    }

    int volume = 0;
    bool bootAnimationDisabled = true;

    Value &jsonValue = json[kKeyLegacyVolume];
    if (jsonValue.isIntegral()) {
        volume = jsonValue.asInt();
    }

    jsonValue = json[kKeyLegacyAnimationsDisabled];
    if (jsonValue.isIntegral()) {
        bootAnimationDisabled = jsonValue.asInt() == 1;
    }

    // Assume a silent boot unless all of the following are true -
    // 1. The volume is neither 0 nor -1000 (the legacy default value).
    // 2. The boot animations are explicitly enabled.
    // Note: brightness was never used.
    mProto.set_silent_boot((volume == 0) || (volume == -1000) || bootAnimationDisabled);

    Value &keys = json[kKeyLegacyParamNames];
    Value &values = json[kKeyLegacyParamValues];
    if (keys.isArray() && values.isArray() && (keys.size() == values.size())) {
        for (ArrayIndex i = 0; i < keys.size(); ++i) {
            auto &key = keys[i];
            auto &value = values[i];
            if (key.isString() && value.isString()) {
                auto userParameter = mProto.add_user_parameter();
                userParameter->set_key(key.asString());
                userParameter->set_value(value.asString());
            }
        }
    }

    loadStateFromProto();
}

void BootParameters::loadStateFromProto() {
    // A missing key returns a safe, default value.
    // Ignore invalid or missing parameters.
    mIsSilentBoot = mProto.silent_boot();

    for (const auto &param : mProto.user_parameter()) {
        mParameters.push_back({.key = param.key().c_str(), .value = param.value().c_str()});
    }
}

}  // namespace android
Loading