integrate sandbox manager with app lifecycle (LaunchApp, StopApp, IsAppRunning)

This commit is contained in:
2026-01-18 23:11:24 +01:00
parent 0278acc0fc
commit 2364d0d327
4 changed files with 67 additions and 22 deletions

View File

@@ -11,9 +11,10 @@ set(AIDL_EXE "${ANDROID_SDK}/build-tools/36.1.0/aidl.exe")
# Find Lua from vcpkg # Find Lua from vcpkg
find_package(Lua REQUIRED) find_package(Lua REQUIRED)
# Find nlohmann_json and minizip for app management # Find nlohmann_json, minizip and sqlite3 for app management and sandbox
find_package(nlohmann_json CONFIG REQUIRED) find_package(nlohmann_json CONFIG REQUIRED)
find_package(minizip CONFIG REQUIRED) find_package(minizip CONFIG REQUIRED)
find_package(unofficial-sqlite3 CONFIG REQUIRED)
# Fetch RmlUi from GitHub with Lua bindings enabled # Fetch RmlUi from GitHub with Lua bindings enabled
include(FetchContent) include(FetchContent)
@@ -70,6 +71,28 @@ add_library(mosis-service SHARED
apps/app_manager.cpp apps/app_manager.cpp
apps/app_api.cpp apps/app_api.cpp
apps/update_service.cpp apps/update_service.cpp
sandbox/lua_sandbox.cpp
sandbox/permission_gate.cpp
sandbox/audit_log.cpp
sandbox/rate_limiter.cpp
sandbox/path_sandbox.cpp
sandbox/timer_manager.cpp
sandbox/json_api.cpp
sandbox/crypto_api.cpp
sandbox/virtual_fs.cpp
sandbox/database_manager.cpp
sandbox/http_validator.cpp
sandbox/network_manager.cpp
sandbox/websocket_manager.cpp
sandbox/camera_interface.cpp
sandbox/microphone_interface.cpp
sandbox/audio_output.cpp
sandbox/location_interface.cpp
sandbox/sensor_interface.cpp
sandbox/bluetooth_interface.cpp
sandbox/contacts_interface.cpp
sandbox/message_bus.cpp
sandbox/sandbox_manager.cpp
) )
target_compile_definitions(mosis-service PUBLIC target_compile_definitions(mosis-service PUBLIC
RMLUI_NUM_MSAA_SAMPLES=2 RMLUI_NUM_MSAA_SAMPLES=2
@@ -86,6 +109,8 @@ target_link_libraries(mosis-service
rmlui rmlui_lua rmlui rmlui_lua
nlohmann_json::nlohmann_json nlohmann_json::nlohmann_json
minizip::minizip minizip::minizip
unofficial::sqlite3::sqlite3
${LUA_LIBRARIES}
) )
add_library(mosis-test SHARED add_library(mosis-test SHARED

View File

@@ -4,8 +4,7 @@
#include "app_manager.h" #include "app_manager.h"
#include "../logger.h" #include "../logger.h"
// TODO: Integrate with sandbox manager when available #include "../sandbox/sandbox_manager.h"
// #include "../sandbox/sandbox_manager.h"
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
@@ -180,10 +179,10 @@ bool AppManager::Uninstall(const std::string& package_id, bool keep_data) {
LOG_INFO("Uninstalling app: %s (keep_data=%d)", package_id.c_str(), keep_data); LOG_INFO("Uninstalling app: %s (keep_data=%d)", package_id.c_str(), keep_data);
// Stop app if running // Stop app if running
// TODO: Integrate with sandbox manager if (m_sandbox_manager && m_sandbox_manager->IsAppRunning(package_id)) {
// if (m_sandbox_manager && m_sandbox_manager->IsAppRunning(package_id)) { LOG_INFO("Stopping running app before uninstall: %s", package_id.c_str());
// m_sandbox_manager->StopApp(package_id); m_sandbox_manager->StopApp(package_id);
// } }
// Remove files // Remove files
std::string install_path = it->second.install_path; std::string install_path = it->second.install_path;
@@ -315,29 +314,48 @@ bool AppManager::RestoreAppData(const std::string& package_id) {
} }
bool AppManager::LaunchApp(const std::string& package_id) { bool AppManager::LaunchApp(const std::string& package_id) {
// TODO: Integrate with sandbox manager
auto app = GetApp(package_id); auto app = GetApp(package_id);
if (!app) { if (!app) {
LOG_ERROR("Cannot launch app: not installed: %s", package_id.c_str()); LOG_ERROR("Cannot launch app: not installed: %s", package_id.c_str());
return false; return false;
} }
LOG_INFO("Launching app: %s (sandbox integration pending)", package_id.c_str()); if (!m_sandbox_manager) {
// When sandbox is integrated: LOG_ERROR("Cannot launch app: sandbox manager not set");
// std::string app_path = app->install_path + "/package"; return false;
// return m_sandbox_manager->StartApp(package_id, app_path, app->permissions, app->is_system_app); }
return true;
if (m_sandbox_manager->IsAppRunning(package_id)) {
LOG_WARN("App already running: %s", package_id.c_str());
return true;
}
std::string app_path = app->install_path + "/package";
LOG_INFO("Launching app: %s from %s", package_id.c_str(), app_path.c_str());
return m_sandbox_manager->StartApp(package_id, app_path, app->permissions, app->is_system_app);
} }
bool AppManager::StopApp(const std::string& package_id) { bool AppManager::StopApp(const std::string& package_id) {
// TODO: Integrate with sandbox manager if (!m_sandbox_manager) {
LOG_INFO("Stopping app: %s (sandbox integration pending)", package_id.c_str()); LOG_ERROR("Cannot stop app: sandbox manager not set");
return true; return false;
}
if (!m_sandbox_manager->IsAppRunning(package_id)) {
LOG_WARN("App not running: %s", package_id.c_str());
return true;
}
LOG_INFO("Stopping app: %s", package_id.c_str());
return m_sandbox_manager->StopApp(package_id);
} }
bool AppManager::IsAppRunning(const std::string& package_id) const { bool AppManager::IsAppRunning(const std::string& package_id) const {
// TODO: Integrate with sandbox manager if (!m_sandbox_manager) {
return false; return false;
}
return m_sandbox_manager->IsAppRunning(package_id);
} }
void AppManager::SetSandboxManager(LuaSandboxManager* manager) { void AppManager::SetSandboxManager(LuaSandboxManager* manager) {

View File

@@ -379,9 +379,10 @@ std::optional<FileStat> VirtualFS::Stat(const std::string& path, std::string& er
} }
auto ftime = fs::last_write_time(physical_path, ec); auto ftime = fs::last_write_time(physical_path, ec);
auto sctp = std::chrono::time_point_cast<std::chrono::seconds>( // Convert file_time_type to system_clock (portable workaround for clock_cast)
std::chrono::clock_cast<std::chrono::system_clock>(ftime)); auto file_time_ns = ftime.time_since_epoch();
stat.modified = sctp.time_since_epoch().count(); auto sys_time_ns = std::chrono::duration_cast<std::chrono::seconds>(file_time_ns);
stat.modified = sys_time_ns.count();
return stat; return stat;
} }

View File

@@ -5,6 +5,7 @@
"lua", "lua",
"freetype", "freetype",
"nlohmann-json", "nlohmann-json",
"minizip" "minizip",
"sqlite3"
] ]
} }