Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions ndk/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use std::{
ptr::NonNull,
};

use jni_sys::{jobject, JNIEnv};

/// A native [`AAssetManager *`]
///
/// [`AAssetManager *`]: https://developer.android.com/ndk/reference/group/asset#aassetmanager
Expand All @@ -35,6 +37,22 @@ impl AssetManager {
Self { ptr }
}

/// Create an [`AssetManager`] from a Java [`android.content.res.AssetManager`] object.
///
/// The Java object must be kept alive for the lifetime of the returned [`AssetManager`].
///
/// # Safety
/// `env` must be a valid [`JNIEnv`] pointer for the current thread, and `asset_manager` must
/// be a valid reference to a Java `android.content.res.AssetManager` that has not been
/// garbage collected.
///
/// [`android.content.res.AssetManager`]: https://developer.android.com/reference/android/content/res/AssetManager
#[doc(alias = "AAssetManager_fromJava")]
pub unsafe fn from_java(env: *mut JNIEnv, asset_manager: jobject) -> Option<Self> {
let ptr = unsafe { ffi::AAssetManager_fromJava(env, asset_manager) };
Some(Self::from_ptr(NonNull::new(ptr)?))
}

/// Returns the pointer to the native `AAssetManager`.
pub fn ptr(&self) -> NonNull<ffi::AAssetManager> {
self.ptr
Expand Down
Loading