Skip to content

Commit

Permalink
Merge pull request #6 from fornwall/ndk-sys-0.5
Browse files Browse the repository at this point in the history
Upgrade `ndk-sys` to v0.5
  • Loading branch information
raftario committed Apr 12, 2024
2 parents acbe210 + f438394 commit adf4ce4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: nttld/setup-ndk@v1
id: setup-ndk
with:
ndk-version: r21e
ndk-version: r23c
- uses: actions-rs/cargo@v1
with:
command: install
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "paranoid-android"
version = "0.2.1"
version = "0.2.2"
edition = "2018"
authors = ["Raphaël Thériault <self@raftar.io>"]
description = "Integration layer between tracing and Android logs"
Expand All @@ -24,7 +24,7 @@ lazy_static = "1"
smallvec = "1"

[target.'cfg(target_os = "android")'.dependencies]
ndk-sys = "0.3"
ndk-sys = "0.5"

[features]
api-30 = []
Expand Down
43 changes: 18 additions & 25 deletions src/logging.rs
Original file line number Diff line number Diff line change
@@ -1,55 +1,48 @@
use ndk_sys::{
android_LogPriority, android_LogPriority_ANDROID_LOG_DEBUG,
android_LogPriority_ANDROID_LOG_ERROR, android_LogPriority_ANDROID_LOG_FATAL,
android_LogPriority_ANDROID_LOG_INFO, android_LogPriority_ANDROID_LOG_VERBOSE,
android_LogPriority_ANDROID_LOG_WARN, log_id, log_id_LOG_ID_CRASH, log_id_LOG_ID_DEFAULT,
log_id_LOG_ID_EVENTS, log_id_LOG_ID_KERNEL, log_id_LOG_ID_MAIN, log_id_LOG_ID_RADIO,
log_id_LOG_ID_SECURITY, log_id_LOG_ID_STATS, log_id_LOG_ID_SYSTEM,
};
use ndk_sys::{android_LogPriority, log_id};
use tracing_core::Level;

#[repr(u32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Priority {
Verbose = android_LogPriority_ANDROID_LOG_VERBOSE,
Debug = android_LogPriority_ANDROID_LOG_DEBUG,
Info = android_LogPriority_ANDROID_LOG_INFO,
Warn = android_LogPriority_ANDROID_LOG_WARN,
Error = android_LogPriority_ANDROID_LOG_ERROR,
Fatal = android_LogPriority_ANDROID_LOG_FATAL,
Verbose = android_LogPriority::ANDROID_LOG_VERBOSE.0,
Debug = android_LogPriority::ANDROID_LOG_DEBUG.0,
Info = android_LogPriority::ANDROID_LOG_INFO.0,
Warn = android_LogPriority::ANDROID_LOG_WARN.0,
Error = android_LogPriority::ANDROID_LOG_ERROR.0,
Fatal = android_LogPriority::ANDROID_LOG_FATAL.0,
}

/// An [Android log buffer](https://developer.android.com/ndk/reference/group/logging#log_id).
#[repr(u32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Buffer {
/// Let the logging function choose the best log target.
Default = log_id_LOG_ID_DEFAULT,
Default = log_id::LOG_ID_DEFAULT.0,

/// The main log buffer.
///
/// This is the only log buffer available to apps.
Main = log_id_LOG_ID_MAIN,
Main = log_id::LOG_ID_MAIN.0,

/// The crash log buffer.
Crash = log_id_LOG_ID_CRASH,
Crash = log_id::LOG_ID_CRASH.0,
/// The statistics log buffer.
Stats = log_id_LOG_ID_STATS,
Stats = log_id::LOG_ID_STATS.0,
/// The event log buffer.
Events = log_id_LOG_ID_EVENTS,
Events = log_id::LOG_ID_EVENTS.0,
/// The security log buffer.
Security = log_id_LOG_ID_SECURITY,
Security = log_id::LOG_ID_SECURITY.0,
/// The system log buffer.
System = log_id_LOG_ID_SYSTEM,
System = log_id::LOG_ID_SYSTEM.0,
/// The kernel log buffer.
Kernel = log_id_LOG_ID_KERNEL,
Kernel = log_id::LOG_ID_KERNEL.0,
/// The radio log buffer.
Radio = log_id_LOG_ID_RADIO,
Radio = log_id::LOG_ID_RADIO.0,
}

impl Priority {
pub fn as_raw(self) -> android_LogPriority {
self as u32
android_LogPriority(self as u32)
}
}

Expand Down Expand Up @@ -79,7 +72,7 @@ impl From<Priority> for Level {

impl Buffer {
pub(crate) fn as_raw(self) -> log_id {
self as u32
log_id(self as u32)
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ impl Write for AndroidLogWriter<'_> {
}
.filter_map(PooledCString::as_ptr);

let buffer = self.buffer.as_raw() as i32;
let priority = self.priority.as_raw() as i32;
let buffer = self.buffer.as_raw().0 as i32;
let priority = self.priority.as_raw().0 as i32;
let tag = self.tag.as_ptr();

#[cfg(feature = "api-30")]
Expand All @@ -87,7 +87,7 @@ impl Write for AndroidLogWriter<'_> {

for message in messages {
let mut message = __android_log_message {
struct_size: size_of::<__android_log_message>() as u64,
struct_size: size_of::<__android_log_message>(),
buffer_id: buffer,
priority,
tag,
Expand Down

0 comments on commit adf4ce4

Please sign in to comment.