-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
134 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use crate::daemon::MagiskD; | ||
use crate::db::DbArg::Integer; | ||
use crate::db::{SqlTable, SqliteResult, SqliteReturn}; | ||
use crate::ffi::{DbValues, RootSettings, SuPolicy}; | ||
use base::{libc, ResultExt}; | ||
use std::ptr; | ||
|
||
impl Default for SuPolicy { | ||
fn default() -> Self { | ||
SuPolicy::Query | ||
} | ||
} | ||
|
||
impl Default for RootSettings { | ||
fn default() -> Self { | ||
RootSettings { | ||
policy: Default::default(), | ||
log: true, | ||
notify: true, | ||
} | ||
} | ||
} | ||
|
||
impl SqlTable for RootSettings { | ||
fn on_row(&mut self, columns: &[String], values: &DbValues) { | ||
for (i, column) in columns.iter().enumerate() { | ||
let val = values.get_int(i as i32); | ||
if column == "policy" { | ||
self.policy.repr = val; | ||
} else if column == "logging" { | ||
self.log = val != 0; | ||
} else if column == "notify" { | ||
self.notify = val != 0; | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl MagiskD { | ||
fn get_root_settings(&self, uid: i32, settings: &mut RootSettings) -> SqliteResult { | ||
self.db_exec_with_rows( | ||
"SELECT policy, logging, notification FROM policies \ | ||
WHERE uid=? AND (until=0 OR until>?)", | ||
&[ | ||
Integer(uid as i64), | ||
Integer(unsafe { libc::time(ptr::null_mut()).into() }), | ||
], | ||
settings, | ||
) | ||
.sql_result() | ||
} | ||
|
||
pub fn get_root_settings_for_cxx(&self, uid: i32, settings: &mut RootSettings) -> bool { | ||
self.get_root_settings(uid, settings).log().is_ok() | ||
} | ||
} | ||
|
||
pub fn get_default_root_settings() -> RootSettings { | ||
RootSettings::default() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.