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_app_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    /// これは常に存在すると期待していい。
61    pub(crate) top_dir_path: Option<std::path::PathBuf>,
62
63    /// USB drive などの一時的な storage volume の場合は存在しない。
64    pub(crate) app_data_dir_path: Option<std::path::PathBuf>,
65
66    /// USB drive などの一時的な storage volume の場合は存在しない。
67    pub(crate) app_cache_dir_path: Option<std::path::PathBuf>,
68
69    /// USB drive などの一時的な storage volume の場合は存在しない。
70    pub(crate) app_media_dir_path: Option<std::path::PathBuf>,
71
72    /// 常に存在するとは限らない。
73    /// primary storage volume はこれが None になることが多い。
74    pub(crate) uid: Option<String>,
75
76    /// None の場合は primary storage volume を指す。
77    /// None でないから primary storage volume でないとは限らない。
78    /// Android 9 以下は常に None。
79    pub(crate) media_store_volume_name: Option<String>,
80
81    /// 常に存在するとは限らない。
82    /// Android 11 以下は常に None。
83    pub(crate) storage_uuid: Option<String>,
84}
85
86#[allow(unused)]
87impl StorageVolumeId {
88
89    pub(crate) fn app_dir_path(&self, dir: impl Into<AppDir>) -> Option<&std::path::PathBuf> {
90        match dir.into() {
91            AppDir::Data => self.app_data_dir_path.as_ref(),
92            AppDir::Cache => self.app_cache_dir_path.as_ref(),
93
94            #[allow(deprecated)]
95            AppDir::PublicMedia => self.app_media_dir_path.as_ref()
96        }
97    }
98}