Skip to content

Commit 22884e1

Browse files
committed
Implement reboot in Rust
1 parent d182930 commit 22884e1

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

native/src/core/daemon.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,6 @@ static void poll_ctrl_handler(pollfd *pfd) {
128128
}
129129
}
130130

131-
void MagiskD::reboot() const noexcept {
132-
if (is_recovery())
133-
exec_command_sync("/system/bin/reboot", "recovery");
134-
else
135-
exec_command_sync("/system/bin/reboot");
136-
}
137-
138131
bool get_client_cred(int fd, sock_cred *cred) {
139132
socklen_t len = sizeof(ucred);
140133
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, cred, &len) != 0)

native/src/core/daemon.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use base::{
1717
use std::fmt::Write as FmtWrite;
1818
use std::io::{BufReader, Write};
1919
use std::os::unix::net::UnixStream;
20+
use std::process::Command;
2021
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
2122
use std::sync::{Mutex, OnceLock};
2223

@@ -79,10 +80,6 @@ impl MagiskD {
7980
unsafe { MAGISKD.get().unwrap_unchecked() }
8081
}
8182

82-
pub fn is_recovery(&self) -> bool {
83-
self.is_recovery
84-
}
85-
8683
pub fn zygisk_enabled(&self) -> bool {
8784
self.zygisk_enabled.load(Ordering::Acquire)
8885
}
@@ -217,6 +214,15 @@ impl MagiskD {
217214
}
218215
}
219216
}
217+
218+
pub fn reboot(&self) {
219+
if self.is_recovery {
220+
Command::new("/system/bin/reboot").arg("recovery").status()
221+
} else {
222+
Command::new("/system/bin/reboot").status()
223+
}
224+
.ok();
225+
}
220226
}
221227

222228
pub fn daemon_entry() {

native/src/core/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ pub mod ffi {
231231
// FFI for MagiskD
232232
extern "Rust" {
233233
type MagiskD;
234-
fn is_recovery(&self) -> bool;
234+
fn reboot(&self);
235235
fn sdk_int(&self) -> i32;
236236
fn zygisk_enabled(&self) -> bool;
237237
fn boot_stage_handler(&self, client: i32, code: i32);
@@ -253,8 +253,6 @@ pub mod ffi {
253253
fn get() -> &'static MagiskD;
254254
}
255255
unsafe extern "C++" {
256-
#[allow(dead_code)]
257-
fn reboot(self: &MagiskD);
258256
fn handle_modules(self: &MagiskD) -> Vec<ModuleInfo>;
259257
}
260258
}

0 commit comments

Comments
 (0)