~aleteoryx/muditaos

18e9a260931dacea7fdb8ddaed88bd545df2303f — Alek Rudnik 4 years ago 82030a3 + ae5e4bd
Merge branch 'master' into stable
M host-tools/pure-flash/CMakeLists.txt => host-tools/pure-flash/CMakeLists.txt +1 -1
@@ 9,4 9,4 @@ set(PUREFLASH_SRCS

add_executable(${PROJECT_NAME} ${PUREFLASH_SRCS})
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -pedantic -Werror -Wextra )
target_compile_definitions(${PROJECT_NAME} PRIVATE _GNU_SOURCE )
target_compile_definitions(${PROJECT_NAME} PRIVATE _GNU_SOURCE _DEFAULT_SOURCE)

M host-tools/pure-flash/pure-flash.c => host-tools/pure-flash/pure-flash.c +66 -9
@@ 14,6 14,8 @@

#include <linux/fs.h>
#include <linux/fiemap.h>
#include <mntent.h>
#include <sys/sysmacros.h>

static void syntax(char **argv)
{


@@ 140,6 142,40 @@ static off_t copy_extent(int fd_dest, int fd_src, off_t start_offs, size_t len)
    return 0;
}

static int device_is_mounted(const char *block_device, char *mntpath, size_t mntpath_len)
{
    struct mntent *ent;
    FILE *fil = setmntent("/proc/mounts", "r");
    if (!fil) {
        return -1;
    }
    int major_blk;
    {
        struct stat blkinfo;
        if (lstat(block_device, &blkinfo)) {
            return -1;
        }
        major_blk = gnu_dev_major(blkinfo.st_rdev);
    }
    while ((ent = getmntent(fil)) != NULL) {
        struct stat info;
        if (lstat(ent->mnt_dir, &info)) {
            if (errno == EACCES)
                continue;
            else
                return -1;
        }
        const int mnt_major_dev = gnu_dev_major(info.st_dev);
        if (major_blk == mnt_major_dev) {
            strncpy(mntpath, ent->mnt_dir, mntpath_len - 1);
            mntpath[mntpath_len - 1] = '\0';
            return 1;
        }
    }
    endmntent(fil);
    return 0;
}

static int verify_image(const char *image_file, const char *block_device)
{
    int fd_sparse, fd_block;


@@ 176,7 212,7 @@ static int verify_image(const char *image_file, const char *block_device)
                fprintf(stderr, "Error: Data mismatch at offset %ld\n", result);
            }
            else {
                perror("System error:");
                perror("System error (Verify):");
            }
            break;
        }


@@ 191,7 227,7 @@ static int write_image(const char *image_file, const char *block_device)
{
    struct stat sbuf;
    if (stat(image_file, &sbuf)) {
        perror("stat image");
        perror("System error (stat image_file):");
        return EXIT_FAILURE;
    }
    if (!S_ISREG(sbuf.st_mode)) {


@@ 199,26 235,44 @@ static int write_image(const char *image_file, const char *block_device)
        return EXIT_FAILURE;
    }
    if (stat(block_device, &sbuf)) {
        perror("stat blkdev");
        perror("System error (stat block_device):");
        return EXIT_FAILURE;
    }
    if (!S_ISBLK(sbuf.st_mode)) {
        fprintf(stderr, "Error: %s is not a block device\n", block_device);
        return EXIT_FAILURE;
    }
    if (gnu_dev_minor(sbuf.st_rdev)) {
        fprintf(stderr, "Error: %s is partition device not a disc\n", block_device);
        fprintf(stderr, "Please specify disk device instead of a partition\n");
        return EXIT_FAILURE;
    }
    {
        char mntpath[FILENAME_MAX];
        const int err = device_is_mounted(block_device, mntpath, sizeof mntpath);
        if (err > 0) {
            fprintf(stderr, "Error: Block device %s is already mounted at %s\n", block_device, mntpath);
            fprintf(stderr, "Please umount device first before flashing\n");
            return EXIT_FAILURE;
        }
        else if (err < 0) {
            perror("System error (check mount):");
            return EXIT_FAILURE;
        }
    }
    int fd_sparse, fd_block;
    if ((fd_sparse = open(image_file, O_RDONLY)) < 0) {
        fprintf(stderr, "Cannot open sparse file %s\n", image_file);
        fprintf(stderr, "Error: Cannot open sparse file %s\n", image_file);
        return EXIT_FAILURE;
    }
    if ((fd_block = open(block_device, O_WRONLY)) < 0) {
        fprintf(stderr, "Cannot open block device %s\n", block_device);
        fprintf(stderr, "Error: Cannot open block device %s\n", block_device);
        close(fd_sparse);
        return EXIT_FAILURE;
    }
    struct fiemap *fiemap;
    if (!(fiemap = read_fiemap(fd_sparse))) {
        fprintf(stderr, "Unable to read fiemap %s\n", image_file);
        fprintf(stderr, "Error: Unable to read fiemap %s\n", image_file);
        close(fd_block);
        close(fd_sparse);
        return EXIT_FAILURE;


@@ 234,7 288,8 @@ static int write_image(const char *image_file, const char *block_device)
               fiemap->fm_extents[i].fe_length,
               result ? "FAIL" : "OK");
        if (result) {
            perror("System error:");
            if (errno)
                perror("System error (Write copy_extent):");
            break;
        }
    }


@@ 242,7 297,9 @@ static int write_image(const char *image_file, const char *block_device)
    // Sync block filesystem
    syncfs(fd_block);
    // Re-read partition table on the device
    ioctl(fd_block, BLKRRPART, NULL);
    if (ioctl(fd_block, BLKRRPART, NULL)) {
        fprintf(stderr, "Warning: Unable to re-read kernel partition table\n");
    }
    close(fd_block);
    close(fd_sparse);
    return result ? EXIT_FAILURE : EXIT_SUCCESS;


@@ 252,7 309,7 @@ int main(int argc, char **argv)
{
    if (argc < 3) {
        syntax(argv);
        exit(EXIT_FAILURE);
        return EXIT_FAILURE;
    }
    if (write_image(argv[1], argv[2])) {
        return EXIT_FAILURE;

M image/user/db/settings_v2_002.sql => image/user/db/settings_v2_002.sql +1 -1
@@ 19,7 19,7 @@ INSERT OR IGNORE INTO settings_tab (path, value) VALUES
    ('gs_display_language', 'English'),
    ('gs_input_language', 'English'),
    ('gs_eula_accepted', '0'),
    ('gs_onboarding_done', '1'),
    ('\ApplicationManager\\gs_onboarding_done', '1'),
    ('gs_usb_security', '1'),
    ('gs_usb_devices', ''),
    ('gs_os_update_version', '0.00.0'),

M module-apps/application-onboarding/ApplicationOnBoarding.cpp => module-apps/application-onboarding/ApplicationOnBoarding.cpp +2 -2
@@ 69,7 69,7 @@ namespace app
        createUserInterface();

        connect(typeid(manager::GetCurrentDisplayLanguageResponse), [&](sys::Message *msg) {
            if (gui::window::name::onBoarding_languages == getCurrentWindow()->getName()) {
            if (gui::name::window::main_window == getCurrentWindow()->getName()) {
                switchWindow(gui::window::name::onBoarding_eula, nullptr);
                return sys::msgHandled();
            }


@@ 124,7 124,7 @@ namespace app
    void ApplicationOnBoarding::createUserInterface()
    {
        windowsFactory.attach(gui::name::window::main_window, [](Application *app, const std::string &name) {
            return std::make_unique<app::onBoarding::OnBoardingLanguagesWindow>(app);
            return std::make_unique<app::onBoarding::OnBoardingLanguagesWindow>(app, gui::name::window::main_window);
        });
        windowsFactory.attach(gui::window::name::onBoarding_start_configuration,
                              [](Application *app, const std::string &name) {

M module-apps/application-onboarding/windows/OnBoardingLanguagesWindow.cpp => module-apps/application-onboarding/windows/OnBoardingLanguagesWindow.cpp +2 -2
@@ 10,8 10,8 @@

namespace app::onBoarding
{
    OnBoardingLanguagesWindow::OnBoardingLanguagesWindow(app::Application *app)
        : LanguagesWindow(app, gui::window::name::onBoarding_languages)
    OnBoardingLanguagesWindow::OnBoardingLanguagesWindow(app::Application *app, const std::string &name)
        : LanguagesWindow(app, name)
    {}

    void OnBoardingLanguagesWindow::onBeforeShow(gui::ShowMode mode, gui::SwitchData *data)

M module-apps/application-onboarding/windows/OnBoardingLanguagesWindow.hpp => module-apps/application-onboarding/windows/OnBoardingLanguagesWindow.hpp +1 -1
@@ 10,7 10,7 @@ namespace app::onBoarding
    class OnBoardingLanguagesWindow : public gui::LanguagesWindow
    {
      public:
        explicit OnBoardingLanguagesWindow(app::Application *app);
        explicit OnBoardingLanguagesWindow(app::Application *app, const std::string &);

      private:
        void onBeforeShow(gui::ShowMode mode, gui::SwitchData *data) override;

M module-apps/locks/handlers/SimLockHandler.cpp => module-apps/locks/handlers/SimLockHandler.cpp +5 -4
@@ 14,9 14,10 @@

namespace locks
{
    constexpr unsigned int default_attempts = 4;
    constexpr unsigned int max_input_size   = 8;
    constexpr unsigned int min_input_size   = 4;
    constexpr unsigned int default_attempts           = 4;
    constexpr unsigned int max_input_size             = 8;
    constexpr unsigned int min_input_size             = 4;
    constexpr unsigned int sim_not_responding_timeout = 3;

    SimLockHandler::SimLockHandler(sys::Service *owner)
        : owner(owner), lock(Lock::LockState::Unlocked, default_attempts)


@@ 24,7 25,7 @@ namespace locks
        lock.setInputSizeBounds(min_input_size, max_input_size);

        simResponseTimer = sys::TimerFactory::createSingleShotTimer(
            owner, simResponseTimerName, std::chrono::seconds{1}, [this](sys::Timer &) {
            owner, simResponseTimerName, std::chrono::seconds{sim_not_responding_timeout}, [this](sys::Timer &) {
                handleSimNotRespondingMessage();
            });
    }

M module-services/service-appmgr/model/ApplicationManager.cpp => module-services/service-appmgr/model/ApplicationManager.cpp +6 -2
@@ 45,6 45,7 @@
#include <service-cellular-api>

#include "module-services/service-appmgr/service-appmgr/messages/ApplicationStatus.hpp"
#include <event-manager-api>

namespace app::manager
{


@@ 1212,8 1213,7 @@ namespace app::manager
            autoLockTimer.stop();
            return;
        }
        auto focusedApp = getFocusedApplication();
        if (focusedApp == nullptr || focusedApp->preventsAutoLocking()) {
        if (auto focusedApp = getFocusedApplication(); focusedApp == nullptr || focusedApp->preventsAutoLocking()) {
            autoLockTimer.start();
            return;
        }


@@ 1221,6 1221,10 @@ namespace app::manager
            autoLockTimer.start();
            return;
        }
        if (event::service::api::isTorchOn()) {
            autoLockTimer.start();
            return;
        }
        phoneLockHandler.handleLockRequest();
    }


M module-services/service-cellular/include/service-cellular-api => module-services/service-cellular/include/service-cellular-api +1 -0
@@ 1,3 1,4 @@
// -*- C++ -*-
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md


M module-services/service-evtmgr/CMakeLists.txt => module-services/service-evtmgr/CMakeLists.txt +3 -0
@@ 5,6 5,7 @@ set(SOURCES
        EventManager.cpp
        WorkerEvent.cpp
        api/EventManagerServiceAPI.cpp
        api/torch.cpp
        battery-level-check/BatteryLevelCheck.cpp
        backlight-handler/BacklightHandler.cpp
        battery-brownout-detector/BatteryBrownoutDetector.cpp


@@ 18,7 19,9 @@ add_library(${PROJECT_NAME} STATIC ${SOURCES})
target_include_directories(${PROJECT_NAME}
    PUBLIC
        "${CMAKE_CURRENT_LIST_DIR}"
         ${CMAKE_CURRENT_LIST_DIR}/service-evtmgr/include
)
 

target_link_libraries(${PROJECT_NAME}
    PRIVATE

A module-services/service-evtmgr/api/torch.cpp => module-services/service-evtmgr/api/torch.cpp +17 -0
@@ 0,0 1,17 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "service-evtmgr/torch.hpp"
#include "bsp/torch/torch.hpp"

// Static API for torch

namespace event::service::api
{
    bool isTorchOn()
    {
        auto [works, isOn] = bsp::torch::getState();
        assert(works);
        return isOn == bsp::torch::State::on;
    }
} // namespace event::service::api

A module-services/service-evtmgr/service-evtmgr/include/event-manager-api => module-services/service-evtmgr/service-evtmgr/include/event-manager-api +7 -0
@@ 0,0 1,7 @@
// -*- C++ -*-
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "service-evtmgr/torch.hpp"

A module-services/service-evtmgr/service-evtmgr/torch.hpp => module-services/service-evtmgr/service-evtmgr/torch.hpp +11 -0
@@ 0,0 1,11 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

// Static API for torch

namespace event::service::api
{
    bool isTorchOn();
}