PrivateStorage

Struct PrivateStorage 

Source
pub struct PrivateStorage<'a, R: Runtime>(/* private fields */);
Expand description

API of file storage intended for the app’s use only.

§Examples

fn example(app: &tauri::AppHandle) {
    use tauri_plugin_android_fs::AndroidFsExt as _;
 
    let api = app.android_fs();
    let private_storage = api.private_storage();
}

Implementations§

Source§

impl<'a, R: Runtime> PrivateStorage<'a, R>

Source

pub fn resolve_path(&self, dir: PrivateDir) -> Result<PathBuf>

Get an absolute path of the app-specific directory on the internal storage.
App can fully manage entries within this directory.

This function does not create any directories; it only constructs the path.

Since these locations may contain files created by other Tauri plugins or webview systems, it is recommended to add a subdirectory with a unique name.

These entries will be deleted when the app is uninstalled and may also be deleted at the user’s initialising request.
When using PrivateDir::Cache, the system will automatically delete entries as disk space is needed elsewhere on the device.

The system prevents other apps and user from accessing these locations. In cases where the device is rooted or the user has special permissions, the user may be able to access this.

Since the returned paths can change when the app is moved to an adopted storage, only relative paths should be stored.

§Note

This provides a separate area for each user in a multi-user environment.

§Support

All Android version.

Source

pub fn resolve_outside_path( &self, volume_id: Option<&StorageVolumeId>, dir: OutsidePrivateDir, ) -> Result<PathBuf>

Get an absolute path of the app-specific directory on the specified storage volume.
App can fully manage entries within this directory.

This function does not create any directories; it only constructs the path.

Since these locations may contain files created by other Tauri plugins or webview systems, it is recommended to add a subdirectory with a unique name.

These entries will be deleted when the app is uninstalled and may also be deleted at the user’s initialising request.

§Note

If you are unsure between this function and PrivateStorage::resolve_path, you don’t need to use this one.
The difference from PrivateStorage::resolve_path is that these files may be accessed by other apps that have specific permissions, and it cannot always be available since removable storage can be ejected.

One advantage of using this is that it allows storing large app-specific data/cache on SD cards or other supplementary storage, which can be useful on older devices with limited built-in storage capacity. However on modern devices, the built-in storage capacity is relatively large, and there is little advantage in using this.

By using StorageVolume { is_emulated, .. }, you can determine whether this belongs to the same storage volume as PrivateStorage::resolve_path. In this case, there is no advantage in using this instead of PrivateStorage::resolve_path. It only reduces security.

§Args
  • volume_id :
    ID of the storage volume, such as internal storage, SD card, etc.
    If None is provided, the primary storage volume will be used.
§Support

All Android version.

Source

pub fn get_volumes(&self) -> Result<Vec<StorageVolume>>

Gets a list of currently available storage volumes (internal storage, SD card, USB drive, etc.). Be aware of TOCTOU.

Since read-only SD cards and similar cases may be included, please use StorageVolume { is_readonly, .. } for filtering as needed.

This function returns only storage volume that is considered stable by system. It includes device’s built-in storage and physical media slots under protective covers, but does not include storage volume considered temporary, such as USB flash drives connected to handheld devices.

This typically includes primary storage volume, but it may occasionally be absent if primary torage volume is inaccessible (e.g., mounted on a computer, removed, or another issue).

Primary storage volume is always listed first, if included. But the order of the others is not guaranteed.

§Note

The volume represents the logical view of a storage volume for an individual user: each user may have a different view for the same physical volume. In other words, it provides a separate area for each user in a multi-user environment.

§Support

All Android version.

Source

pub fn get_primary_volume(&self) -> Result<Option<StorageVolume>>

Gets a primary storage volume.
In many cases, it is device’s built-in storage.

A device always has one (and one only) primary storage volume.

Primary volume may not currently be accessible if it has been mounted by the user on their computer, has been removed from the device, or some other problem has happened. If so, this returns None.

§Note

The volume represents the logical view of a storage volume for an individual user: each user may have a different view for the same physical volume. In other words, it provides a separate area for each user in a multi-user environment.

§Support

All Android version.

Source

pub fn resolve_uri( &self, dir: PrivateDir, relative_path: impl AsRef<Path>, ) -> Result<FileUri>

👎Deprecated: Use FileUri::from_path instead

This is same as FileUri::from_path

Auto Trait Implementations§

§

impl<'a, R> Freeze for PrivateStorage<'a, R>

§

impl<'a, R> !RefUnwindSafe for PrivateStorage<'a, R>

§

impl<'a, R> Send for PrivateStorage<'a, R>

§

impl<'a, R> Sync for PrivateStorage<'a, R>

§

impl<'a, R> Unpin for PrivateStorage<'a, R>

§

impl<'a, R> !UnwindSafe for PrivateStorage<'a, R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,