rebootFunction: Allow reboot function in ADB without root

This commit is contained in:
2025-08-10 22:16:12 +03:00
parent 6ccead8532
commit f9eea8aef7
6 changed files with 17 additions and 4 deletions

View File

@@ -187,7 +187,7 @@ pmt type partition(s) [OPTIONS]
--- ---
### 9. `reboot` ### 9. `reboot`
Reboot the device. Default reboot target is normal. General syntax: Reboot the device. Default reboot target is normal. If you are using it via ADB terminal, you **DO NOT** need root to use this feature. General syntax:
```bash ```bash
pmt reboot [rebootTarget] [OPTIONS] pmt reboot [rebootTarget] [OPTIONS]
``` ```

View File

@@ -55,6 +55,7 @@ private:
public: public:
void registerFunction(std::unique_ptr<basic_function> _func, CLI::App &_app); void registerFunction(std::unique_ptr<basic_function> _func, CLI::App &_app);
[[nodiscard]] bool isUsed(std::string name) const;
[[nodiscard]] bool handleAll() const; [[nodiscard]] bool handleAll() const;
}; };

View File

@@ -69,6 +69,14 @@ void basic_function_manager::registerFunction(
<< std::endl; << std::endl;
} }
bool basic_function_manager::isUsed(const std::string name) const {
if (_functions.empty()) return false;
for (const auto &func : _functions) {
if (func->name() == name) return func->isUsed();
}
return false;
}
bool basic_function_manager::handleAll() const { bool basic_function_manager::handleAll() const {
LOGN(PMTF, INFO) << "running caught function commands in command-line." LOGN(PMTF, INFO) << "running caught function commands in command-line."
<< std::endl; << std::endl;

View File

@@ -112,9 +112,11 @@ int Main(int argc, char **argv) {
"directory with -S " "directory with -S "
"(--search-path)"); "(--search-path)");
if (!Helper::hasSuperUser()) if (!Helper::hasSuperUser()) {
if (!(FuncManager.isUsed("reboot") && Helper::hasAdbPermissions()))
throw Error( throw Error(
"Partition Manager Tool is requires super-user privileges!\n"); "Partition Manager Tool is requires super-user privileges!\n");
}
return FuncManager.handleAll() == true ? EXIT_SUCCESS : EXIT_FAILURE; return FuncManager.handleAll() == true ? EXIT_SUCCESS : EXIT_FAILURE;
} catch (Helper::Error &error) { } catch (Helper::Error &error) {

View File

@@ -105,6 +105,7 @@ void reset();
// Checkers // Checkers
bool hasSuperUser(); bool hasSuperUser();
bool hasAdbPermissions();
bool isExists(std::string_view entry); bool isExists(std::string_view entry);
bool fileIsExists(std::string_view file); bool fileIsExists(std::string_view file);
bool directoryIsExists(std::string_view directory); bool directoryIsExists(std::string_view directory);

View File

@@ -23,6 +23,7 @@
namespace Helper { namespace Helper {
bool hasSuperUser() { return (getuid() == AID_ROOT); } bool hasSuperUser() { return (getuid() == AID_ROOT); }
bool hasAdbPermissions() { return (getuid() == AID_ADB); }
bool isExists(const std::string_view entry) { bool isExists(const std::string_view entry) {
struct stat st{}; struct stat st{};