Vendor things
This commit is contained in:
parent
5deceec006
commit
977e3c17e5
19434 changed files with 10682014 additions and 0 deletions
1
third-party/vendor/ndk-context/.cargo-checksum.json
vendored
Normal file
1
third-party/vendor/ndk-context/.cargo-checksum.json
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"files":{"CHANGELOG.md":"81ac073a715cce96428a28ae5e994c84b76dce3a19ec399eb486a8c6626afa3c","Cargo.toml":"caed75f8ae352e5f07b1cf5b34cfb1e47cc4d76485dbaf12fe6cd033075bc67a","README.md":"24e409d9297a8a294eb8cd8a11522bce794d2b87842c8860682482050c0ab1f4","src/lib.rs":"db7df8ed08d6ba3d1ecfaad324efea0a665070204b341ae2254693ab4527ea5b"},"package":"27b02d87554356db9e9a873add8782d4ea6e3e58ea071a9adb9a2e8ddb884a8b"}
|
||||
9
third-party/vendor/ndk-context/CHANGELOG.md
vendored
Normal file
9
third-party/vendor/ndk-context/CHANGELOG.md
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# Unreleased
|
||||
|
||||
# 0.1.1 (2022-04-19)
|
||||
|
||||
- Add `release_android_context()` function to remove `AndroidContext` when activity is destroyed. (#263)
|
||||
|
||||
# 0.1.0 (2022-02-14)
|
||||
|
||||
- Initial release! 🎉
|
||||
27
third-party/vendor/ndk-context/Cargo.toml
vendored
Normal file
27
third-party/vendor/ndk-context/Cargo.toml
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
|
||||
#
|
||||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g., crates.io) dependencies.
|
||||
#
|
||||
# If you are reading this file be aware that the original Cargo.toml
|
||||
# will likely look very different (and much more reasonable).
|
||||
# See Cargo.toml.orig for the original contents.
|
||||
|
||||
[package]
|
||||
edition = "2021"
|
||||
name = "ndk-context"
|
||||
version = "0.1.1"
|
||||
authors = ["The Rust Windowing contributors"]
|
||||
description = "Handles for accessing Android APIs"
|
||||
homepage = "https://github.com/rust-windowing/android-ndk-rs"
|
||||
documentation = "https://docs.rs/ndk-context"
|
||||
keywords = [
|
||||
"android",
|
||||
"ndk",
|
||||
"apk",
|
||||
"jni",
|
||||
]
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/rust-windowing/android-ndk-rs"
|
||||
6
third-party/vendor/ndk-context/README.md
vendored
Normal file
6
third-party/vendor/ndk-context/README.md
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
# ndk-context
|
||||
|
||||
Provides a stable api to rust crates for interfacing with the Android platform. It is
|
||||
initialized by the runtime, usually [__ndk-glue__](https://crates.io/crates/ndk-glue),
|
||||
but could also be initialized by Java or Kotlin code when embedding in an existing Android
|
||||
project.
|
||||
100
third-party/vendor/ndk-context/src/lib.rs
vendored
Normal file
100
third-party/vendor/ndk-context/src/lib.rs
vendored
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
//! Provides a stable api to rust crates for interfacing with the Android platform. It is
|
||||
//! initialized by the runtime, usually [__ndk-glue__](https://crates.io/crates/ndk-glue),
|
||||
//! but could also be initialized by Java or Kotlin code when embedding in an existing Android
|
||||
//! project.
|
||||
//!
|
||||
//! ```no_run
|
||||
//! let ctx = ndk_context::android_context();
|
||||
//! let vm = unsafe { jni::JavaVM::from_raw(ctx.vm().cast()) }?;
|
||||
//! let env = vm.attach_current_thread();
|
||||
//! let class_ctx = env.find_class("android/content/Context")?;
|
||||
//! let audio_service = env.get_static_field(class_ctx, "AUDIO_SERVICE", "Ljava/lang/String;")?;
|
||||
//! let audio_manager = env
|
||||
//! .call_method(
|
||||
//! ctx.context() as jni::sys::jobject,
|
||||
//! "getSystemService",
|
||||
//! "(Ljava/lang/String;)Ljava/lang/Object;",
|
||||
//! &[audio_service],
|
||||
//! )?
|
||||
//! .l()?;
|
||||
//! ```
|
||||
use std::ffi::c_void;
|
||||
|
||||
static mut ANDROID_CONTEXT: Option<AndroidContext> = None;
|
||||
|
||||
/// [`AndroidContext`] provides the pointers required to interface with the jni on Android
|
||||
/// platforms.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct AndroidContext {
|
||||
java_vm: *mut c_void,
|
||||
context_jobject: *mut c_void,
|
||||
}
|
||||
|
||||
impl AndroidContext {
|
||||
/// A handle to the `JavaVM` object.
|
||||
///
|
||||
/// Usage with [__jni__](https://crates.io/crates/jni) crate:
|
||||
/// ```no_run
|
||||
/// let ctx = ndk_context::android_context();
|
||||
/// let vm = unsafe { jni::JavaVM::from_raw(ctx.vm().cast()) }?;
|
||||
/// let env = vm.attach_current_thread();
|
||||
/// ```
|
||||
pub fn vm(self) -> *mut c_void {
|
||||
self.java_vm
|
||||
}
|
||||
|
||||
/// A handle to an [android.content.Context](https://developer.android.com/reference/android/content/Context).
|
||||
/// In most cases this will be a ptr to an `Activity`, but this isn't guaranteed.
|
||||
///
|
||||
/// Usage with [__jni__](https://crates.io/crates/jni) crate:
|
||||
/// ```no_run
|
||||
/// let ctx = ndk_context::android_context();
|
||||
/// let vm = unsafe { jni::JavaVM::from_raw(ctx.vm().cast()) }?;
|
||||
/// let env = vm.attach_current_thread();
|
||||
/// let class_ctx = env.find_class("android/content/Context")?;
|
||||
/// let audio_service = env.get_static_field(class_ctx, "AUDIO_SERVICE", "Ljava/lang/String;")?;
|
||||
/// let audio_manager = env
|
||||
/// .call_method(
|
||||
/// ctx.context() as jni::sys::jobject,
|
||||
/// "getSystemService",
|
||||
/// "(Ljava/lang/String;)Ljava/lang/Object;",
|
||||
/// &[audio_service],
|
||||
/// )?
|
||||
/// .l()?;
|
||||
/// ```
|
||||
pub fn context(self) -> *mut c_void {
|
||||
self.context_jobject
|
||||
}
|
||||
}
|
||||
|
||||
/// Main entry point to this crate. Returns an [`AndroidContext`].
|
||||
pub fn android_context() -> AndroidContext {
|
||||
unsafe { ANDROID_CONTEXT.expect("android context was not initialized") }
|
||||
}
|
||||
|
||||
/// Initializes the [`AndroidContext`]. [`AndroidContext`] is initialized by [__ndk-glue__](https://crates.io/crates/ndk-glue)
|
||||
/// before `main` is called.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The pointers must be valid and this function must be called exactly once before `main` is
|
||||
/// called.
|
||||
pub unsafe fn initialize_android_context(java_vm: *mut c_void, context_jobject: *mut c_void) {
|
||||
let previous = ANDROID_CONTEXT.replace(AndroidContext {
|
||||
java_vm,
|
||||
context_jobject,
|
||||
});
|
||||
assert!(previous.is_none());
|
||||
}
|
||||
|
||||
/// Removes the [`AndroidContext`]. It is released by [__ndk-glue__](https://crates.io/crates/ndk-glue)
|
||||
/// when the activity is finished and destroyed.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// This function must only be called after [`initialize_android_context()`],
|
||||
/// when the activity is subsequently destroyed according to Android.
|
||||
pub unsafe fn release_android_context() {
|
||||
let previous = ANDROID_CONTEXT.take();
|
||||
assert!(previous.is_some());
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue