Skip to main content

lingxia_platform/traits/
device.rs

1use crate::error::PlatformError;
2use crate::{DeviceInfo, ScreenInfo};
3
4pub trait Device: Send + Sync + 'static {
5    fn device_info(&self) -> DeviceInfo;
6    fn screen_info(&self) -> ScreenInfo;
7    fn vibrate(&self, long: bool) -> Result<(), PlatformError>;
8    fn make_phone_call(&self, phone_number: &str) -> Result<(), PlatformError>;
9}
10
11pub trait DeviceSecureStore: Send + Sync + 'static {
12    /// Read a persisted value from a secure, app-scoped store that survives reinstall where supported.
13    fn secure_store_read(&self, key: &str) -> Result<Option<Vec<u8>>, PlatformError> {
14        Err(PlatformError::Platform(format!(
15            "secure_store_read not implemented for key {}",
16            key
17        )))
18    }
19
20    /// Persist a value into the secure store.
21    fn secure_store_write(&self, key: &str, value: &[u8]) -> Result<(), PlatformError> {
22        let _ = (key, value);
23        Err(PlatformError::Platform(
24            "secure_store_write not implemented".to_string(),
25        ))
26    }
27
28    /// Delete a value from the secure store.
29    fn secure_store_delete(&self, key: &str) -> Result<(), PlatformError> {
30        Err(PlatformError::Platform(format!(
31            "secure_store_delete not implemented for key {}",
32            key
33        )))
34    }
35}
36
37pub trait DeviceHardware: Send + Sync + 'static {
38    /// Get total physical memory in bytes.
39    fn get_memory_info(&self) -> Result<u64, PlatformError> {
40        Err(PlatformError::Platform(
41            "get_memory_info not implemented".to_string(),
42        ))
43    }
44
45    /// Get the number of logical CPU cores available.
46    fn get_cpu_count(&self) -> usize {
47        std::thread::available_parallelism()
48            .map(|count| count.get())
49            .unwrap_or(1)
50    }
51
52    /// Get total ROM storage in bytes.
53    fn get_storage_total_bytes(&self) -> Result<u64, PlatformError> {
54        Err(PlatformError::Platform(
55            "get_storage_total_bytes not implemented".to_string(),
56        ))
57    }
58}