diff --git a/crates/molotov-core/src/jni/framework.rs b/crates/molotov-core/src/jni/framework.rs new file mode 100644 index 0000000..b5739ab --- /dev/null +++ b/crates/molotov-core/src/jni/framework.rs @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +#![allow(dead_code)] +use super::objects::JniObjectRegistry; +use std::collections::HashSet; +use std::path::PathBuf; + +pub struct AndroidEnvironment { + pub registry: JniObjectRegistry, + known_classes: HashSet, + files_dir: PathBuf, + cache_dir: PathBuf, +} + +impl Default for AndroidEnvironment { + fn default() -> Self { + Self::new() + } +} + +impl AndroidEnvironment { + pub fn new() -> Self { + let mut known = HashSet::new(); + known.insert("android/content/Context".to_string()); + known.insert("android/app/Activity".to_string()); + known.insert("android/os/Build".to_string()); + known.insert("android/os/Build$VERSION".to_string()); + known.insert("android/view/SurfaceView".to_string()); + known.insert("com/roblox/client/RobloxApplication".to_string()); + known.insert("com/roblox/client/ActivityNativeMain".to_string()); + + Self { + registry: JniObjectRegistry::new(), + known_classes: known, + files_dir: PathBuf::from("/tmp/molotov_files"), + cache_dir: PathBuf::from("/tmp/molotov_cache"), + } + } + + pub fn package_name(&self) -> &'static str { + "com.roblox.client" + } + + pub fn build_model(&self) -> &'static str { + "Pixel Tablet (x86_64)" + } + + pub fn build_sdk_version(&self) -> i32 { + 33 // Android 13 + } + + pub fn find_class(&mut self, class_name: &str) -> Option { + if self.known_classes.contains(class_name) { + Some(self.registry.alloc_class(class_name)) + } else { + tracing::warn!("JNI: FindClass requested unknown class '{}' -> returning NULL", class_name); + None + } + } +} diff --git a/crates/molotov-core/src/jni/mod.rs b/crates/molotov-core/src/jni/mod.rs index bb39e42..38975d1 100644 --- a/crates/molotov-core/src/jni/mod.rs +++ b/crates/molotov-core/src/jni/mod.rs @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-or-later pub mod env; +pub mod framework; pub mod objects; pub mod types; pub mod vm; diff --git a/crates/molotov-core/tests/jni_framework_test.rs b/crates/molotov-core/tests/jni_framework_test.rs new file mode 100644 index 0000000..e8a09c7 --- /dev/null +++ b/crates/molotov-core/tests/jni_framework_test.rs @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +use molotov_core::jni::framework::AndroidEnvironment; + +#[test] +fn test_android_environment_package_name_and_build() { + let env = AndroidEnvironment::new(); + assert_eq!(env.package_name(), "com.roblox.client"); + assert_eq!(env.build_model(), "Pixel Tablet (x86_64)"); + assert_eq!(env.build_sdk_version(), 33); +} + +#[test] +fn test_find_known_android_classes() { + let mut env = AndroidEnvironment::new(); + assert!(env.find_class("android/content/Context").is_some()); + assert!(env.find_class("android/os/Build").is_some()); + assert!(env.find_class("com/roblox/client/RobloxApplication").is_some()); + assert!(env.find_class("com/unknown/BogusClass").is_none()); +}