tauri_plugin_android_fs/models/storage_volume.rs
1use serde::{Deserialize, Serialize};
2use crate::*;
3
4
5#[derive(Debug, Clone, Hash, PartialEq, Eq, Deserialize, Serialize)]
6#[serde(rename_all = "camelCase")]
7pub struct StorageVolume {
8
9 /// A user-visible description of the volume.
10 /// This can be determined by the manufacturer and is often localized according to the user’s language.
11 ///
12 /// e.g.
13 /// - `Internal shared storage`
14 /// - `SDCARD`
15 /// - `SD card`
16 /// - `Virtual SD card`
17 pub description: String,
18
19 /// Indicates whether this is primary storage volume.
20 /// A device always has one (and one only) primary storage volume.
21 pub is_primary: bool,
22
23 /// Indicates whether this is physically removable.
24 /// If `false`, this is device's built-in storage.
25 pub is_removable: bool,
26
27 /// Indicates whether thit is stable part of the device.
28 ///
29 /// For example, a device’s built-in storage and physical media slots under protective covers are considered stable,
30 /// while USB flash drives connected to handheld devices are not.
31 pub is_stable: bool,
32
33 /// Indicates whether this is backed by private user data partition,
34 /// either internal storage or [adopted storage](https://source.android.com/docs/core/storage/adoptable).
35 ///
36 /// On most recent devices, the primary storage volume will often have this set to `true`.
37 pub is_emulated: bool,
38
39 /// Indicates whether this is readonly storage volume.
40 ///
41 /// e.g. SD card with readonly mode.
42 ///
43 /// # Remark
44 /// As far as I understand, this should never be `true`
45 /// when either `is_primary` or `is_emulated` is true,
46 /// or when `is_removable` is false,
47 /// but it might not be the case due to any issues or rare cases.
48 pub is_readonly: bool,
49
50 pub is_available_for_private_storage: bool,
51
52 pub is_available_for_public_storage: bool,
53
54 pub id: StorageVolumeId
55}
56
57#[derive(Debug, Clone, Hash, PartialEq, Eq, Deserialize, Serialize)]
58#[serde(rename_all = "camelCase")]
59pub struct StorageVolumeId {
60 pub(crate) top_directory_path: Option<std::path::PathBuf>,
61 pub(crate) media_store_volume_name: Option<String>,
62 pub(crate) private_data_dir_path: Option<std::path::PathBuf>,
63 pub(crate) private_cache_dir_path: Option<std::path::PathBuf>,
64 pub(crate) uuid: Option<String>,
65}
66
67#[allow(unused)]
68impl StorageVolumeId {
69
70 pub(crate) fn outside_private_dir_path(&self, dir: OutsidePrivateDir) -> Option<&std::path::PathBuf> {
71 match dir {
72 OutsidePrivateDir::Data => self.private_data_dir_path.as_ref(),
73 OutsidePrivateDir::Cache => self.private_cache_dir_path.as_ref(),
74 }
75 }
76}