feat(jni): implement Android framework class emulation and device properties
This commit is contained in:
parent
1a9d0b0153
commit
45c56f342f
3 changed files with 79 additions and 0 deletions
59
crates/molotov-core/src/jni/framework.rs
Normal file
59
crates/molotov-core/src/jni/framework.rs
Normal file
|
|
@ -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<String>,
|
||||
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<usize> {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
19
crates/molotov-core/tests/jni_framework_test.rs
Normal file
19
crates/molotov-core/tests/jni_framework_test.rs
Normal file
|
|
@ -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());
|
||||
}
|
||||
Reference in a new issue