@@ -308,6 +308,30 @@ bitflags::bitflags! {
308308// ADB Controller Methods
309309// ============================================================================
310310
311+ /// Raw screen resolution used by Android native control units.
312+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Serialize , Deserialize ) ]
313+ pub struct AndroidScreenResolution {
314+ /// Raw screenshot width reported by the control unit.
315+ pub width : i32 ,
316+ /// Raw screenshot height reported by the control unit.
317+ pub height : i32 ,
318+ }
319+
320+ /// Configuration for [`crate::controller::Controller::new_android_native`].
321+ #[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
322+ pub struct AndroidNativeControllerConfig {
323+ /// Path to the Android native control unit shared library.
324+ pub library_path : String ,
325+ /// Raw screenshot/touch coordinate resolution exposed by the control unit.
326+ pub screen_resolution : AndroidScreenResolution ,
327+ /// Target Android display id. Defaults to `0` when omitted by MaaFramework.
328+ #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
329+ pub display_id : Option < u32 > ,
330+ /// Whether to force-stop before `start_app`. Defaults to `false` when omitted.
331+ #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
332+ pub force_stop : Option < bool > ,
333+ }
334+
311335bitflags:: bitflags! {
312336 /// ADB screencap method flags.
313337 ///
@@ -903,3 +927,37 @@ pub struct CustomRecognitionResult {
903927 pub box_rect : ( i32 , i32 , i32 , i32 ) ,
904928 pub detail : serde_json:: Value ,
905929}
930+
931+ #[ cfg( test) ]
932+ mod tests {
933+ use super :: { AndroidNativeControllerConfig , AndroidScreenResolution } ;
934+ use serde_json:: json;
935+
936+ #[ test]
937+ fn android_native_controller_config_serializes_expected_shape ( ) {
938+ let config = AndroidNativeControllerConfig {
939+ library_path : "/data/local/tmp/libmaa_unit.so" . to_string ( ) ,
940+ screen_resolution : AndroidScreenResolution {
941+ width : 1920 ,
942+ height : 1080 ,
943+ } ,
944+ display_id : Some ( 1 ) ,
945+ force_stop : Some ( true ) ,
946+ } ;
947+
948+ let value = serde_json:: to_value ( config) . unwrap ( ) ;
949+
950+ assert_eq ! (
951+ value,
952+ json!( {
953+ "library_path" : "/data/local/tmp/libmaa_unit.so" ,
954+ "screen_resolution" : {
955+ "width" : 1920 ,
956+ "height" : 1080
957+ } ,
958+ "display_id" : 1 ,
959+ "force_stop" : true
960+ } )
961+ ) ;
962+ }
963+ }
0 commit comments