1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
use crate::error::PlatformError;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WifiInfo {
/// SSID of the access point.
pub ssid: String,
/// BSSID of the access point (MAC address format: "aa:bb:cc:dd:ee:ff").
#[serde(skip_serializing_if = "Option::is_none")]
pub bssid: Option<String>,
/// Whether the access point requires authentication.
pub secure: bool,
/// Signal strength in the range [0, 100], where 100 is strongest.
pub signal_strength: u8,
/// Center frequency in MHz (if available).
#[serde(skip_serializing_if = "Option::is_none")]
pub frequency: Option<u32>,
}
#[derive(Debug, Clone)]
pub struct WifiConnectRequest {
/// SSID of the access point.
pub ssid: String,
/// Password for the access point.
pub password: Option<String>,
/// Callback ID for success/failure.
pub callback_id: u64,
}
#[derive(Debug, Clone)]
pub struct WifiGetConnectedRequest {
/// Callback ID for success/failure.
pub callback_id: u64,
}
pub trait Wifi: Send + Sync + 'static {
/// Initialize Wi-Fi module (wx.startWifi).
///
/// # Platform Requirements
/// - Android: Requires ACCESS_WIFI_STATE and CHANGE_WIFI_STATE permissions
/// - iOS: Requires NEHotspotConfiguration API (iOS 11+)
/// - HarmonyOS: Requires ohos.permission.GET_WIFI_INFO
fn start_wifi(&self, callback_id: u64) -> Result<(), PlatformError> {
let _ = callback_id;
Err(PlatformError::NotSupported(
"start_wifi not implemented".to_string(),
))
}
/// Stop Wi-Fi module (wx.stopWifi).
fn stop_wifi(&self, callback_id: u64) -> Result<(), PlatformError> {
let _ = callback_id;
Err(PlatformError::NotSupported(
"stop_wifi not implemented".to_string(),
))
}
/// Connect to a Wi-Fi access point (wx.connectWifi).
///
/// # Platform Limitations
/// - iOS: Only works for pre-configured networks or hotspot networks
/// - Android: May require location permissions on Android 6.0+
fn connect_wifi(&self, request: WifiConnectRequest) -> Result<(), PlatformError> {
let _ = request;
Err(PlatformError::NotSupported(
"connect_wifi not implemented".to_string(),
))
}
/// Request a Wi-Fi scan and return results via callback (wx.getWifiList).
///
/// Unlike WeChat's event-driven approach, this directly returns scan results
/// via the callback for Stage 1 simplicity.
///
/// Callback receives: JSON array of WifiInfo objects
/// Example: [{"ssid":"MyWiFi","bssid":"aa:bb:cc:dd:ee:ff","secure":true,"signalStrength":80,"frequency":2412}]
fn get_wifi_list(&self, callback_id: u64) -> Result<(), PlatformError> {
let _ = callback_id;
Err(PlatformError::NotSupported(
"get_wifi_list not implemented".to_string(),
))
}
/// Get current connected Wi-Fi (wx.getConnectedWifi).
///
/// Always returns full WiFi information (SSID, BSSID, secure, signalStrength).
fn get_connected_wifi(&self, request: WifiGetConnectedRequest) -> Result<(), PlatformError> {
let _ = request;
Err(PlatformError::NotSupported(
"get_connected_wifi not implemented".to_string(),
))
}
/// Check if WiFi is currently enabled on the device (synchronous).
///
/// Returns true if WiFi hardware is active and available for use.
///
/// # Platform Notes
/// - Android: Checks WifiManager.isWifiEnabled()
/// - iOS: Always returns true (WiFi state not accessible)
/// - HarmonyOS: Checks OH_Wifi_IsWifiEnabled()
fn is_wifi_enabled(&self) -> Result<bool, PlatformError> {
Err(PlatformError::NotSupported(
"is_wifi_enabled not implemented".to_string(),
))
}
/// Add a listener for WiFi connection state changes.
///
/// Multiple listeners can be registered (supports multiple LxApp instances).
/// Platform should invoke the callback with connected WiFi info JSON payload
/// each time WiFi connection state changes.
///
/// # Multi-LxApp Support
/// - Platform maintains a set of callback_ids
/// - First listener triggers system WiFi state monitoring
/// - Each new listener immediately receives current WiFi state
fn add_wifi_state_listener(&self, callback_id: u64) -> Result<(), PlatformError> {
let _ = callback_id;
Ok(())
}
/// Remove a previously registered WiFi state listener.
///
/// # Multi-LxApp Support
/// - Removes the specific callback_id from the listener set
/// - Last listener stops system WiFi state monitoring
fn remove_wifi_state_listener(&self, callback_id: u64) -> Result<(), PlatformError> {
let _ = callback_id;
Ok(())
}
}