New logging and more (#446)

- `TT_LOG_*` macros are replaced by `Logger` via `#include<Tactility/Logger.h>`
- Changed default timezone to Europe/Amsterdam
- Fix for logic bug in unPhone hardware
- Fix for init/deinit in DRV2605 driver
- Other fixes
- Removed optimization that broke unPhone (disabled the moving of heap-related functions to flash)
This commit is contained in:
Ken Van Hoeylandt
2026-01-06 22:35:39 +01:00
committed by GitHub
parent 719f7bcece
commit f620255c41
188 changed files with 1973 additions and 1755 deletions
+28 -31
View File
@@ -6,35 +6,32 @@
#include <Tactility/file/FileLock.h>
#include <Tactility/file/PropertiesFile.h>
#include <Tactility/hal/Device.h>
#include <Tactility/hal/sdcard/SdCardDevice.h>
#include <Tactility/Logger.h>
#include <Tactility/Paths.h>
#include <cerrno>
#include <cstdio>
#include <cstring>
#include <fcntl.h>
#include <format>
#include <libgen.h>
#include <map>
#include <sys/types.h>
#include <unistd.h>
#include <minitar.h>
constexpr auto* TAG = "App";
namespace tt::app {
static const auto LOGGER = Logger("App");
static bool untarFile(minitar* mp, const minitar_entry* entry, const std::string& destinationPath) {
const auto absolute_path = destinationPath + "/" + entry->metadata.path;
if (!file::findOrCreateDirectory(destinationPath, 0777)) {
TT_LOG_E(TAG, "Can't find or create directory %s", destinationPath.c_str());
LOGGER.error("Can't find or create directory {}", destinationPath.c_str());
return false;
}
// minitar_read_contents(&mp, &entry, file_buffer, entry.metadata.size);
if (!minitar_read_contents_to_file(mp, entry, absolute_path.c_str())) {
TT_LOG_E(TAG, "Failed to write data to %s", absolute_path.c_str());
LOGGER.error("Failed to write data to {}", absolute_path.c_str());
return false;
}
@@ -63,32 +60,32 @@ static bool untar(const std::string& tarPath, const std::string& destinationPath
do {
if (minitar_read_entry(&mp, &entry) == 0) {
TT_LOG_I(TAG, "Extracting %s", entry.metadata.path);
LOGGER.info("Extracting {}", entry.metadata.path);
if (entry.metadata.type == MTAR_DIRECTORY) {
if (!strcmp(entry.metadata.name, ".") || !strcmp(entry.metadata.name, "..") || !strcmp(entry.metadata.name, "/")) continue;
if (!untarDirectory(&entry, destinationPath)) {
TT_LOG_E(TAG, "Failed to create directory %s/%s: %s", destinationPath.c_str(), entry.metadata.name, strerror(errno));
LOGGER.error("Failed to create directory {}/{}: {}", destinationPath, entry.metadata.name, strerror(errno));
success = false;
break;
}
} else if (entry.metadata.type == MTAR_REGULAR) {
if (!untarFile(&mp, &entry, destinationPath)) {
TT_LOG_E(TAG, "Failed to extract file %s: %s", entry.metadata.path, strerror(errno));
LOGGER.error("Failed to extract file {}: {}", entry.metadata.path, strerror(errno));
success = false;
break;
}
} else if (entry.metadata.type == MTAR_SYMLINK) {
TT_LOG_E(TAG, "SYMLINK not supported");
LOGGER.error("SYMLINK not supported");
} else if (entry.metadata.type == MTAR_HARDLINK) {
TT_LOG_E(TAG, "HARDLINK not supported");
LOGGER.error("HARDLINK not supported");
} else if (entry.metadata.type == MTAR_FIFO) {
TT_LOG_E(TAG, "FIFO not supported");
LOGGER.error("FIFO not supported");
} else if (entry.metadata.type == MTAR_BLKDEV) {
TT_LOG_E(TAG, "BLKDEV not supported");
LOGGER.error("BLKDEV not supported");
} else if (entry.metadata.type == MTAR_CHRDEV) {
TT_LOG_E(TAG, "CHRDEV not supported");
LOGGER.error("CHRDEV not supported");
} else {
TT_LOG_E(TAG, "Unknown entry type: %d", entry.metadata.type);
LOGGER.error("Unknown entry type: {}", static_cast<int>(entry.metadata.type));
success = false;
break;
}
@@ -100,7 +97,7 @@ static bool untar(const std::string& tarPath, const std::string& destinationPath
void cleanupInstallDirectory(const std::string& path) {
if (!file::deleteRecursively(path)) {
TT_LOG_W(TAG, "Failed to delete existing installation at %s", path.c_str());
LOGGER.warn("Failed to delete existing installation at {}", path);
}
}
@@ -109,16 +106,16 @@ bool install(const std::string& path) {
// the lock with the display. We don't want to lock the display for very long.
auto app_parent_path = getAppInstallPath();
TT_LOG_I(TAG, "Installing app %s to %s", path.c_str(), app_parent_path.c_str());
LOGGER.info("Installing app {} to {}", path, app_parent_path);
auto filename = file::getLastPathSegment(path);
const std::string app_target_path = std::format("{}/{}", app_parent_path, filename);
if (file::isDirectory(app_target_path) && !file::deleteRecursively(app_target_path)) {
TT_LOG_W(TAG, "Failed to delete %s", app_target_path.c_str());
LOGGER.warn("Failed to delete {}", app_target_path);
}
if (!file::findOrCreateDirectory(app_target_path, 0777)) {
TT_LOG_I(TAG, "Failed to create directory %s", app_target_path.c_str());
LOGGER.info("Failed to create directory {}", app_target_path);
return false;
}
@@ -126,9 +123,9 @@ bool install(const std::string& path) {
auto source_path_lock = file::getLock(path)->asScopedLock();
target_path_lock.lock();
source_path_lock.lock();
TT_LOG_I(TAG, "Extracting app from %s to %s", path.c_str(), app_target_path.c_str());
LOGGER.info("Extracting app from {} to {}", path, app_target_path);
if (!untar(path, app_target_path)) {
TT_LOG_E(TAG, "Failed to extract");
LOGGER.error("Failed to extract");
return false;
}
source_path_lock.unlock();
@@ -136,21 +133,21 @@ bool install(const std::string& path) {
auto manifest_path = app_target_path + "/manifest.properties";
if (!file::isFile(manifest_path)) {
TT_LOG_E(TAG, "Manifest not found at %s", manifest_path.c_str());
LOGGER.error("Manifest not found at {}", manifest_path);
cleanupInstallDirectory(app_target_path);
return false;
}
std::map<std::string, std::string> properties;
if (!file::loadPropertiesFile(manifest_path, properties)) {
TT_LOG_E(TAG, "Failed to load manifest at %s", manifest_path.c_str());
LOGGER.error("Failed to load manifest at {}", manifest_path);
cleanupInstallDirectory(app_target_path);
return false;
}
AppManifest manifest;
if (!parseManifest(properties, manifest)) {
TT_LOG_W(TAG, "Invalid manifest");
LOGGER.warn("Invalid manifest");
cleanupInstallDirectory(app_target_path);
return false;
}
@@ -163,7 +160,7 @@ bool install(const std::string& path) {
const std::string renamed_target_path = std::format("{}/{}", app_parent_path, manifest.appId);
if (file::isDirectory(renamed_target_path)) {
if (!file::deleteRecursively(renamed_target_path)) {
TT_LOG_W(TAG, "Failed to delete existing installation at %s", renamed_target_path.c_str());
LOGGER.warn("Failed to delete existing installation at {}", renamed_target_path);
cleanupInstallDirectory(app_target_path);
return false;
}
@@ -174,7 +171,7 @@ bool install(const std::string& path) {
target_path_lock.unlock();
if (!rename_success) {
TT_LOG_E(TAG, "Failed to rename \"%s\" to \"%s\"", app_target_path.c_str(), manifest.appId.c_str());
LOGGER.error(R"(Failed to rename "{}" to "{}")", app_target_path, manifest.appId);
cleanupInstallDirectory(app_target_path);
return false;
}
@@ -187,7 +184,7 @@ bool install(const std::string& path) {
}
bool uninstall(const std::string& appId) {
TT_LOG_I(TAG, "Uninstalling app %s", appId.c_str());
LOGGER.info("Uninstalling app {}", appId);
// If the app was running, then stop it
if (isRunning(appId)) {
@@ -196,7 +193,7 @@ bool uninstall(const std::string& appId) {
auto app_path = getAppInstallPath(appId);
if (!file::isDirectory(app_path)) {
TT_LOG_E(TAG, "App %s not found at %s", appId.c_str(), app_path.c_str());
LOGGER.error("App {} not found at {}", appId, app_path);
return false;
}
@@ -205,7 +202,7 @@ bool uninstall(const std::string& appId) {
}
if (!removeAppManifest(appId)) {
TT_LOG_W(TAG, "Failed to remove app %s from registry", appId.c_str());
LOGGER.warn("Failed to remove app {} from registry", appId);
}
return true;