pmt: Improvements for developers

- Android.bp was written to be included in ROMs/recoveries etc. in Android build system.
 - Macros have been added to simplify feature creation.
 - Some bug fixes (for JSON and pmt).
This commit is contained in:
2025-08-27 15:50:40 +03:00
parent 631c735a9a
commit e0f0b5b484
18 changed files with 200 additions and 109 deletions

110
Android.bp Normal file
View File

@@ -0,0 +1,110 @@
//
// Copyright 2025 Yağız Zengin
//
// 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.
//
// Partition manager tool source list
filegroup {
name: "pmt_srcs",
srcs: [
"src/FunctionManager.cpp",
"src/Main.cpp",
"src/PartitionManager.cpp",
"src/functions/BackupFunction.cpp",
"src/functions/EraseFunction.cpp",
"src/functions/FlashFunction.cpp",
"src/functions/InfoFunction.cpp",
"src/functions/MemoryTestFunction.cpp",
"src/functions/PartitionSizeFunction.cpp",
"src/functions/RealPathFunction.cpp",
"src/functions/RebootFunction.cpp",
"src/functions/TypeFunction.cpp",
],
}
// libhelper source list
filegroup {
name: "libhelper_srcs",
srcs: [
"srclib/libhelper/src/Checkers.cpp",
"srclib/libhelper/src/Classes.cpp",
"srclib/libhelper/src/FileUtil.cpp",
"srclib/libhelper/src/Sha256.cpp",
"srclib/libhelper/src/Utilities.cpp",
],
}
// libpartition_map source list
filegroup {
name: "libpartition_map_srcs",
srcs: [
"srclib/libpartition_map/src/Getters.cpp",
"srclib/libpartition_map/src/Magic.cpp",
"srclib/libpartition_map/src/PartitionMap.cpp",
"srclib/libpartition_map/src/Type.cpp",
],
}
// Default configurations of pmt
cc_defaults {
name: "pmt_defaults",
recovery_available: true,
cflags: [
"-Wall",
"-Werror",
"-Wno-deprecated-declarations",
"-Os",
"-fexceptions",
"-DANDROID_BUILD",
],
ldflags: ["-Wl,-s"],
local_include_dirs: [
"include",
"srclib/libhelper/include",
"srclib/libpartition_map/include",
],
export_include_dirs: [
"include",
"srclib/libhelper/include",
"srclib/libpartition_map/include",
],
shared_libs: ["libbase"],
}
// Build libhelper library
cc_library_shared {
name: "libhelper",
defaults: ["pmt_defaults"],
srcs: [":libhelper_srcs"],
}
// Build libpartition_map library
cc_library_shared {
name: "libpartition_map",
defaults: ["pmt_defaults"],
srcs: [":libpartition_map_srcs"],
shared_libs: ["libhelper"],
static_libs: ["libc++fs"],
}
// Build pmt
cc_binary {
name: "pmt",
defaults: ["pmt_defaults"],
srcs: [":pmt_srcs"],
shared_libs: [
"libhelper",
"libpartition_map",
],
}

View File

@@ -6090,12 +6090,7 @@ inline void to_json(BasicJsonType& j, const T& t)
template<typename BasicJsonType> template<typename BasicJsonType>
inline void to_json(BasicJsonType& j, const std_fs::path& p) inline void to_json(BasicJsonType& j, const std_fs::path& p)
{ {
#ifdef JSON_HAS_CPP_20
const std::u8string s = p.u8string();
j = std::string(s.begin(), s.end());
#else
j = p.u8string(); // returns std::string in C++17 j = p.u8string(); // returns std::string in C++17
#endif
} }
#endif #endif

View File

@@ -71,7 +71,7 @@ void basic_function_manager::registerFunction(
std::unique_ptr<basic_function> _func, CLI::App &_app) { std::unique_ptr<basic_function> _func, CLI::App &_app) {
LOGN(PMTF, INFO) << "registering function: " << _func->name() << std::endl; LOGN(PMTF, INFO) << "registering function: " << _func->name() << std::endl;
for (const auto &f : _functions) { for (const auto &f : _functions) {
if (strcmp(f->name(), _func->name()) != 0) { if (std::string(_func->name()) == std::string(f->name())) {
LOGN(PMTF, INFO) << "Function is already registered: " << _func->name() LOGN(PMTF, INFO) << "Function is already registered: " << _func->name()
<< ". Skipping." << std::endl; << ". Skipping." << std::endl;
return; return;

View File

@@ -20,7 +20,9 @@
#include <cstdarg> #include <cstdarg>
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#ifndef ANDROID_BUILD
#include <generated/buildInfo.hpp> #include <generated/buildInfo.hpp>
#endif
#include <string> #include <string>
#include <unistd.h> #include <unistd.h>

View File

@@ -27,7 +27,7 @@
#define BFUN "backupFunction" #define BFUN "backupFunction"
namespace PartitionManager { namespace PartitionManager {
pair backupFunction::runAsync(const std::string &partitionName, RUN_ASYNC(backupFunction)(const std::string &partitionName,
const std::string &outputName, const std::string &outputName,
const uint64_t bufferSize) { const uint64_t bufferSize) {
if (!Variables->PartMap->hasPartition(partitionName)) if (!Variables->PartMap->hasPartition(partitionName))
@@ -105,7 +105,7 @@ pair backupFunction::runAsync(const std::string &partitionName,
true}; true};
} }
bool backupFunction::init(CLI::App &_app) { INIT(backupFunction) {
LOGN(BFUN, INFO) << "Initializing variables of backup function." << std::endl; LOGN(BFUN, INFO) << "Initializing variables of backup function." << std::endl;
cmd = _app.add_subcommand("backup", "Backup partition(s) to file(s)"); cmd = _app.add_subcommand("backup", "Backup partition(s) to file(s)");
cmd->add_option("partition(s)", rawPartitions, "Partition name(s)") cmd->add_option("partition(s)", rawPartitions, "Partition name(s)")
@@ -123,7 +123,7 @@ bool backupFunction::init(CLI::App &_app) {
return true; return true;
} }
bool backupFunction::run() { RUN(backupFunction) {
processCommandLine(partitions, outputNames, rawPartitions, rawOutputNames, processCommandLine(partitions, outputNames, rawPartitions, rawOutputNames,
',', true); ',', true);
if (!outputNames.empty() && partitions.size() != outputNames.size()) if (!outputNames.empty() && partitions.size() != outputNames.size())
@@ -161,7 +161,7 @@ bool backupFunction::run() {
return endResult; return endResult;
} }
bool backupFunction::isUsed() const { return cmd->parsed(); } IS_USED_COMMON_BODY(backupFunction)
const char *backupFunction::name() const { return BFUN; } NAME(backupFunction) { return BFUN; }
} // namespace PartitionManager } // namespace PartitionManager

View File

@@ -25,7 +25,7 @@ Copyright 2025 Yağız Zengin
#define EFUN "eraseFunction" #define EFUN "eraseFunction"
namespace PartitionManager { namespace PartitionManager {
pair eraseFunction::runAsync(const std::string &partitionName, RUN_ASYNC(eraseFunction)(const std::string &partitionName,
const uint64_t bufferSize) { const uint64_t bufferSize) {
if (!Variables->PartMap->hasPartition(partitionName)) if (!Variables->PartMap->hasPartition(partitionName))
return {format("Couldn't find partition: %s", partitionName.data()), false}; return {format("Couldn't find partition: %s", partitionName.data()), false};
@@ -87,7 +87,7 @@ pair eraseFunction::runAsync(const std::string &partitionName,
true}; true};
} }
bool eraseFunction::init(CLI::App &_app) { INIT(eraseFunction) {
LOGN(EFUN, INFO) << "Initializing variables of erase function." << std::endl; LOGN(EFUN, INFO) << "Initializing variables of erase function." << std::endl;
cmd = _app.add_subcommand("erase", "Writes zero bytes to partition(s)"); cmd = _app.add_subcommand("erase", "Writes zero bytes to partition(s)");
cmd->add_option("partition(s)", partitions, "Partition name(s)") cmd->add_option("partition(s)", partitions, "Partition name(s)")
@@ -100,7 +100,7 @@ bool eraseFunction::init(CLI::App &_app) {
return true; return true;
} }
bool eraseFunction::run() { RUN(eraseFunction) {
std::vector<std::future<pair>> futures; std::vector<std::future<pair>> futures;
for (const auto &partitionName : partitions) { for (const auto &partitionName : partitions) {
uint64_t buf = bufferSize; uint64_t buf = bufferSize;
@@ -127,7 +127,7 @@ bool eraseFunction::run() {
return endResult; return endResult;
} }
bool eraseFunction::isUsed() const { return cmd->parsed(); } IS_USED_COMMON_BODY(eraseFunction)
const char *eraseFunction::name() const { return EFUN; } NAME(eraseFunction) { return EFUN; }
} // namespace PartitionManager } // namespace PartitionManager

View File

@@ -25,7 +25,7 @@ Copyright 2025 Yağız Zengin
#define FFUN "flashFunction" #define FFUN "flashFunction"
namespace PartitionManager { namespace PartitionManager {
pair flashFunction::runAsync(const std::string &partitionName, RUN_ASYNC(flashFunction)(const std::string &partitionName,
const std::string &imageName, const std::string &imageName,
const uint64_t bufferSize) { const uint64_t bufferSize) {
if (!Helper::fileIsExists(imageName)) if (!Helper::fileIsExists(imageName))
@@ -92,7 +92,7 @@ pair flashFunction::runAsync(const std::string &partitionName,
true}; true};
} }
bool flashFunction::init(CLI::App &_app) { INIT(flashFunction) {
LOGN(FFUN, INFO) << "Initializing variables of flash function." << std::endl; LOGN(FFUN, INFO) << "Initializing variables of flash function." << std::endl;
cmd = _app.add_subcommand("flash", "Flash image(s) to partition(s)"); cmd = _app.add_subcommand("flash", "Flash image(s) to partition(s)");
cmd->add_option("partition(s)", rawPartitions, "Partition name(s)") cmd->add_option("partition(s)", rawPartitions, "Partition name(s)")
@@ -110,7 +110,7 @@ bool flashFunction::init(CLI::App &_app) {
return true; return true;
} }
bool flashFunction::run() { RUN(flashFunction) {
processCommandLine(partitions, imageNames, rawPartitions, rawImageNames, ',', processCommandLine(partitions, imageNames, rawPartitions, rawImageNames, ',',
true); true);
if (partitions.size() != imageNames.size()) if (partitions.size() != imageNames.size())
@@ -148,7 +148,7 @@ bool flashFunction::run() {
return endResult; return endResult;
} }
bool flashFunction::isUsed() const { return cmd->parsed(); } IS_USED_COMMON_BODY(flashFunction)
const char *flashFunction::name() const { return FFUN; } NAME(flashFunction) { return FFUN; }
} // namespace PartitionManager } // namespace PartitionManager

View File

@@ -24,7 +24,8 @@ Copyright 2025 Yağız Zengin
#define IFUN "infoFunction" #define IFUN "infoFunction"
namespace PartitionManager { namespace PartitionManager {
bool infoFunction::init(CLI::App &_app) {
INIT(infoFunction) {
LOGN(IFUN, INFO) << "Initializing variables of info printer function." LOGN(IFUN, INFO) << "Initializing variables of info printer function."
<< std::endl; << std::endl;
cmd = _app.add_subcommand("info", "Tell info(s) of input partition list") cmd = _app.add_subcommand("info", "Tell info(s) of input partition list")
@@ -53,7 +54,7 @@ bool infoFunction::init(CLI::App &_app) {
return true; return true;
} }
bool infoFunction::run() { RUN(infoFunction) {
if (partitions.back() == "get-all" || partitions.back() == "getvar-all") { if (partitions.back() == "get-all" || partitions.back() == "getvar-all") {
partitions.clear(); partitions.clear();
const auto parts = Variables->PartMap->getPartitionList(); const auto parts = Variables->PartMap->getPartitionList();
@@ -111,7 +112,7 @@ bool infoFunction::run() {
return true; return true;
} }
bool infoFunction::isUsed() const { return cmd->parsed(); } IS_USED_COMMON_BODY(infoFunction)
const char *infoFunction::name() const { return IFUN; }; NAME(infoFunction) { return IFUN; };
} // namespace PartitionManager } // namespace PartitionManager

View File

@@ -27,7 +27,7 @@ Copyright 2025 Yağız Zengin
namespace PartitionManager { namespace PartitionManager {
bool memoryTestFunction::init(CLI::App &_app) { INIT(memoryTestFunction) {
LOGN(MTFUN, INFO) << "Initializing variables of memory test function." LOGN(MTFUN, INFO) << "Initializing variables of memory test function."
<< std::endl; << std::endl;
cmd = _app.add_subcommand("memtest", "Test your write/read speed of device."); cmd = _app.add_subcommand("memtest", "Test your write/read speed of device.");
@@ -56,7 +56,7 @@ bool memoryTestFunction::init(CLI::App &_app) {
return true; return true;
} }
bool memoryTestFunction::run() { RUN(memoryTestFunction) {
LOGN(MTFUN, INFO) << "Starting memory test on " << testPath << std::endl; LOGN(MTFUN, INFO) << "Starting memory test on " << testPath << std::endl;
Helper::garbageCollector collector; Helper::garbageCollector collector;
const std::string test = Helper::pathJoin(testPath, "test.bin"); const std::string test = Helper::pathJoin(testPath, "test.bin");
@@ -122,8 +122,7 @@ bool memoryTestFunction::run() {
return true; return true;
} }
bool memoryTestFunction::isUsed() const { return cmd->parsed(); } IS_USED_COMMON_BODY(memoryTestFunction)
const char *memoryTestFunction::name() const { return MTFUN; }
NAME(memoryTestFunction) { return MTFUN; }
} // namespace PartitionManager } // namespace PartitionManager

View File

@@ -27,7 +27,7 @@ std::string convertTo(const uint64_t size, const std::string &multiple) {
} }
namespace PartitionManager { namespace PartitionManager {
bool partitionSizeFunction::init(CLI::App &_app) { INIT(partitionSizeFunction) {
LOGN(SFUN, INFO) LOGN(SFUN, INFO)
<< "Initializing variables of partition size getter function." << "Initializing variables of partition size getter function."
<< std::endl; << std::endl;
@@ -54,7 +54,7 @@ bool partitionSizeFunction::init(CLI::App &_app) {
return true; return true;
} }
bool partitionSizeFunction::run() { RUN(partitionSizeFunction) {
for (const auto &partition : partitions) { for (const auto &partition : partitions) {
if (!Variables->PartMap->hasPartition(partition)) if (!Variables->PartMap->hasPartition(partition))
throw Error("Couldn't find partition: %s", partition.data()); throw Error("Couldn't find partition: %s", partition.data());
@@ -89,7 +89,7 @@ bool partitionSizeFunction::run() {
return true; return true;
} }
bool partitionSizeFunction::isUsed() const { return cmd->parsed(); } IS_USED_COMMON_BODY(partitionSizeFunction)
const char *partitionSizeFunction::name() const { return SFUN; } NAME(partitionSizeFunction) { return SFUN; }
} // namespace PartitionManager } // namespace PartitionManager

View File

@@ -20,7 +20,7 @@
#define RPFUN "realPathFunction" #define RPFUN "realPathFunction"
namespace PartitionManager { namespace PartitionManager {
bool realPathFunction::init(CLI::App &_app) { INIT(realPathFunction) {
LOGN(RPFUN, INFO) << "Initializing variables of real path function." LOGN(RPFUN, INFO) << "Initializing variables of real path function."
<< std::endl; << std::endl;
cmd = _app.add_subcommand("real-path", "Tell real paths of partition(s)"); cmd = _app.add_subcommand("real-path", "Tell real paths of partition(s)");
@@ -32,7 +32,7 @@ bool realPathFunction::init(CLI::App &_app) {
return true; return true;
} }
bool realPathFunction::run() { RUN(realPathFunction) {
for (const auto &partition : partitions) { for (const auto &partition : partitions) {
if (!Variables->PartMap->hasPartition(partition)) if (!Variables->PartMap->hasPartition(partition))
throw Error("Couldn't find partition: %s", partition.data()); throw Error("Couldn't find partition: %s", partition.data());
@@ -56,7 +56,7 @@ bool realPathFunction::run() {
return true; return true;
} }
bool realPathFunction::isUsed() const { return cmd->parsed(); } IS_USED_COMMON_BODY(realPathFunction)
const char *realPathFunction::name() const { return RPFUN; } NAME(realPathFunction) { return RPFUN; }
} // namespace PartitionManager } // namespace PartitionManager

View File

@@ -20,7 +20,7 @@ Copyright 2025 Yağız Zengin
#define RFUN "rebootFunction" #define RFUN "rebootFunction"
namespace PartitionManager { namespace PartitionManager {
bool rebootFunction::init(CLI::App &_app) { INIT(rebootFunction) {
LOGN(RFUN, INFO) << "Initializing variables of reboot function." << std::endl; LOGN(RFUN, INFO) << "Initializing variables of reboot function." << std::endl;
cmd = _app.add_subcommand("reboot", "Reboots device"); cmd = _app.add_subcommand("reboot", "Reboots device");
cmd->add_option("rebootTarget", rebootTarget, cmd->add_option("rebootTarget", rebootTarget,
@@ -28,7 +28,7 @@ bool rebootFunction::init(CLI::App &_app) {
return true; return true;
} }
bool rebootFunction::run() { RUN(rebootFunction) {
LOGN(RFUN, INFO) << "Rebooting device!!! (custom reboot target: " LOGN(RFUN, INFO) << "Rebooting device!!! (custom reboot target: "
<< (rebootTarget.empty() ? "none" : rebootTarget) << (rebootTarget.empty() ? "none" : rebootTarget)
<< std::endl; << std::endl;
@@ -39,7 +39,7 @@ bool rebootFunction::run() {
return true; return true;
} }
bool rebootFunction::isUsed() const { return cmd->parsed(); } IS_USED_COMMON_BODY(rebootFunction)
const char *rebootFunction::name() const { return RFUN; } NAME(rebootFunction) { return RFUN; }
} // namespace PartitionManager } // namespace PartitionManager

View File

@@ -20,7 +20,7 @@
#define TFUN "typeFunction" #define TFUN "typeFunction"
namespace PartitionManager { namespace PartitionManager {
bool typeFunction::init(CLI::App &_app) { INIT(typeFunction) {
LOGN(TFUN, INFO) << "Initializing variables of type function." << std::endl; LOGN(TFUN, INFO) << "Initializing variables of type function." << std::endl;
cmd = _app.add_subcommand("type", "Get type of the partition(s) or image(s)"); cmd = _app.add_subcommand("type", "Get type of the partition(s) or image(s)");
cmd->add_option("content(s)", contents, "Content(s)") cmd->add_option("content(s)", contents, "Content(s)")
@@ -39,7 +39,7 @@ bool typeFunction::init(CLI::App &_app) {
return true; return true;
} }
bool typeFunction::run() { RUN(typeFunction) {
std::unordered_map<uint64_t, std::string> magics; std::unordered_map<uint64_t, std::string> magics;
if (onlyCheckAndroidMagics) if (onlyCheckAndroidMagics)
magics.merge(PartitionMap::Extras::AndroidMagicMap); magics.merge(PartitionMap::Extras::AndroidMagicMap);
@@ -75,8 +75,8 @@ bool typeFunction::run() {
return true; return true;
} }
bool typeFunction::isUsed() const { return cmd->parsed(); } IS_USED_COMMON_BODY(typeFunction)
const char *typeFunction::name() const { return TFUN; } NAME(typeFunction) { return TFUN; }
} // namespace PartitionManager } // namespace PartitionManager

View File

@@ -21,6 +21,20 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#define INIT(cls) bool cls::init(CLI::App &_app)
#define RUN(cls) bool cls::run()
#define RUN_ASYNC(cls) pair cls::runAsync
#define IS_USED(cls) bool cls::isUsed() const
#define IS_USED_COMMON_BODY(cls) bool cls::isUsed() const { return cmd->parsed(); }
#define NAME(cls) const char *cls::name() const
#define COMMON_FUNCTION_BODY() \
CLI::App *cmd = nullptr; \
bool init(CLI::App &_app) override; \
bool run() override; \
[[nodiscard]] bool isUsed() const override; \
[[nodiscard]] const char *name() const override
namespace PartitionManager { namespace PartitionManager {
using pair = std::pair<std::string, bool>; using pair = std::pair<std::string, bool>;
@@ -32,15 +46,9 @@ private:
uint64_t bufferSize = 0; uint64_t bufferSize = 0;
public: public:
CLI::App *cmd = nullptr; COMMON_FUNCTION_BODY();
bool init(CLI::App &_app) override;
bool run() override;
static pair runAsync(const std::string &partitionName, static pair runAsync(const std::string &partitionName,
const std::string &outputName, uint64_t bufferSize); const std::string &outputName, uint64_t bufferSize);
[[nodiscard]] bool isUsed() const override;
[[nodiscard]] const char *name() const override;
}; };
// Image flasher function // Image flasher function
@@ -51,15 +59,9 @@ private:
uint64_t bufferSize = 0; uint64_t bufferSize = 0;
public: public:
CLI::App *cmd = nullptr; COMMON_FUNCTION_BODY();
bool init(CLI::App &_app) override;
bool run() override;
static pair runAsync(const std::string &partitionName, static pair runAsync(const std::string &partitionName,
const std::string &imageName, uint64_t bufferSize); const std::string &imageName, uint64_t bufferSize);
[[nodiscard]] bool isUsed() const override;
[[nodiscard]] const char *name() const override;
}; };
// Eraser function (writes zero bytes to partition) // Eraser function (writes zero bytes to partition)
@@ -69,14 +71,8 @@ private:
uint64_t bufferSize = 0; uint64_t bufferSize = 0;
public: public:
CLI::App *cmd = nullptr; COMMON_FUNCTION_BODY();
bool init(CLI::App &_app) override;
bool run() override;
static pair runAsync(const std::string &partitionName, uint64_t bufferSize); static pair runAsync(const std::string &partitionName, uint64_t bufferSize);
[[nodiscard]] bool isUsed() const override;
[[nodiscard]] const char *name() const override;
}; };
// Partition size getter function // Partition size getter function
@@ -87,13 +83,7 @@ private:
asGiga = false; asGiga = false;
public: public:
CLI::App *cmd = nullptr; COMMON_FUNCTION_BODY();
bool init(CLI::App &_app) override;
bool run() override;
[[nodiscard]] bool isUsed() const override;
[[nodiscard]] const char *name() const override;
}; };
// Partition info getter function // Partition info getter function
@@ -105,13 +95,7 @@ private:
bool jsonFormat = false; bool jsonFormat = false;
public: public:
CLI::App *cmd = nullptr; COMMON_FUNCTION_BODY();
bool init(CLI::App &_app) override;
bool run() override;
[[nodiscard]] bool isUsed() const override;
[[nodiscard]] const char *name() const override;
}; };
class realPathFunction final : public FunctionBase { class realPathFunction final : public FunctionBase {
@@ -120,13 +104,7 @@ private:
bool realLinkPath = false; bool realLinkPath = false;
public: public:
CLI::App *cmd = nullptr; COMMON_FUNCTION_BODY();
bool init(CLI::App &_app) override;
bool run() override;
[[nodiscard]] bool isUsed() const override;
[[nodiscard]] const char *name() const override;
}; };
class typeFunction final : public FunctionBase { class typeFunction final : public FunctionBase {
@@ -136,13 +114,7 @@ private:
uint64_t bufferSize = 0; uint64_t bufferSize = 0;
public: public:
CLI::App *cmd = nullptr; COMMON_FUNCTION_BODY();
bool init(CLI::App &_app) override;
bool run() override;
[[nodiscard]] bool isUsed() const override;
[[nodiscard]] const char *name() const override;
}; };
class rebootFunction final : public FunctionBase { class rebootFunction final : public FunctionBase {
@@ -150,13 +122,7 @@ private:
std::string rebootTarget; std::string rebootTarget;
public: public:
CLI::App *cmd = nullptr; COMMON_FUNCTION_BODY();
bool init(CLI::App &_app) override;
bool run() override;
[[nodiscard]] bool isUsed() const override;
[[nodiscard]] const char *name() const override;
}; };
class memoryTestFunction final : public FunctionBase { class memoryTestFunction final : public FunctionBase {
@@ -166,13 +132,7 @@ private:
bool doNotReadTest = false; bool doNotReadTest = false;
public: public:
CLI::App *cmd = nullptr; COMMON_FUNCTION_BODY();
bool init(CLI::App &_app) override;
bool run() override;
[[nodiscard]] bool isUsed() const override;
[[nodiscard]] const char *name() const override;
}; };
} // namespace PartitionManager } // namespace PartitionManager

View File

@@ -243,6 +243,14 @@ std::string getLibVersion();
#define LOGNF_IF(name, file, level, condition) \ #define LOGNF_IF(name, file, level, condition) \
if (condition) Helper::Logger(level, __func__, file, name, __FILE__, __LINE__) if (condition) Helper::Logger(level, __func__, file, name, __FILE__, __LINE__)
#ifdef ANDROID_BUILD
#define MKVERSION(name) \
char vinfo[512]; \
sprintf(vinfo, \
"%s 1.2.0 [XXXX-XX-XX XX.XX.XX]\nBuildType: Release\nCompiler: clang\n" \
"BuildFlags: -Wall;-Werror;-Wno-deprecated-declarations;-Os", name); \
return std::string(vinfo)
#else
#define MKVERSION(name) \ #define MKVERSION(name) \
char vinfo[512]; \ char vinfo[512]; \
sprintf(vinfo, \ sprintf(vinfo, \
@@ -251,5 +259,6 @@ std::string getLibVersion();
name, BUILD_VERSION, BUILD_DATE, BUILD_TIME, BUILD_TYPE, \ name, BUILD_VERSION, BUILD_DATE, BUILD_TIME, BUILD_TYPE, \
BUILD_CMAKE_VERSION, BUILD_COMPILER_VERSION, BUILD_FLAGS); \ BUILD_CMAKE_VERSION, BUILD_COMPILER_VERSION, BUILD_FLAGS); \
return std::string(vinfo) return std::string(vinfo)
#endif
#endif // #ifndef LIBHELPER_LIB_HPP #endif // #ifndef LIBHELPER_LIB_HPP

View File

@@ -58,10 +58,18 @@ Logger::~Logger() {
fd != -1) fd != -1)
close(fd); close(fd);
else { else {
#ifdef ANDROID_BUILD
LoggingProperties::setLogFile("/tmp/last_pmt_logs.log")
#else
LoggingProperties::setLogFile("last_logs.log"); LoggingProperties::setLogFile("last_logs.log");
#endif
LOGN(HELPER, INFO) << "Cannot create log file: " << _logFile << ": " LOGN(HELPER, INFO) << "Cannot create log file: " << _logFile << ": "
<< strerror(errno) << strerror(errno)
#ifdef ANDROID_BUILD
<< " New logging file: /tmp/last_pmt_logs.log (this file)."
#else
<< " New logging file: last_logs.log (this file)." << " New logging file: last_logs.log (this file)."
#endif
<< std::endl; << std::endl;
} }
} }

View File

@@ -19,7 +19,12 @@
#include <ctime> #include <ctime>
#include <cutils/android_reboot.h> #include <cutils/android_reboot.h>
#include <fcntl.h> #include <fcntl.h>
#ifndef ANDROID_BUILD
#include <generated/buildInfo.hpp> #include <generated/buildInfo.hpp>
#include <sys/_system_properties.h>
#else
#include <sys/system_properties.h>
#endif
#include <iostream> #include <iostream>
#include <libgen.h> #include <libgen.h>
#include <libhelper/lib.hpp> #include <libhelper/lib.hpp>

View File

@@ -20,7 +20,9 @@
#include <cstring> #include <cstring>
#include <fcntl.h> #include <fcntl.h>
#include <filesystem> #include <filesystem>
#ifndef ANDROID_BUILD
#include <generated/buildInfo.hpp> #include <generated/buildInfo.hpp>
#endif
#include <iostream> #include <iostream>
#include <libpartition_map/lib.hpp> #include <libpartition_map/lib.hpp>
#include <linux/fs.h> #include <linux/fs.h>