rebootFunction: Allow reboot function in ADB without root
This commit is contained in:
2
USAGE.md
2
USAGE.md
@@ -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]
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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()) {
|
||||||
throw Error(
|
if (!(FuncManager.isUsed("reboot") && Helper::hasAdbPermissions()))
|
||||||
"Partition Manager Tool is requires super-user privileges!\n");
|
throw Error(
|
||||||
|
"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) {
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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{};
|
||||||
|
|||||||
Reference in New Issue
Block a user