pub struct MtpDevice { /* private fields */ }
Expand description
Result from opening a raw device descriptor, holds information about the device like default folders, battery level, manufacturer, model, storage, etc.
Storage is directly tied to an MTP device by the StoragePool
struct abstraction,
which you may get with storage_pool
after
updating the storage with update_storage
.
§Example
mtp_device.update_storage().expect("Couldn't update storage");
let storage_pool = mtp_device.storage_pool();
Implementations§
Source§impl MtpDevice
impl MtpDevice
Sourcepub fn default_music_folder(&self) -> u32
pub fn default_music_folder(&self) -> u32
Retrieves the default music folder, if there isn’t one this value may be garbage. Therefore, it’s not recommended to depend on this value, unless you know exactly how the device you are interacting with handles this setting.
Sourcepub fn default_playlist_folder(&self) -> u32
pub fn default_playlist_folder(&self) -> u32
Retrieves the default playlist folder, if there isn’t one this value may be garbage. Therefore, it’s not recommended to depend on this value, unless you know exactly how the device you are interacting with handles this setting.
Sourcepub fn default_picture_folder(&self) -> u32
pub fn default_picture_folder(&self) -> u32
Retrieves the default picture folder, if there isn’t one this value may be garbage. Therefore, it’s not recommended to depend on this value, unless you know exactly how the device you are interacting with handles this setting.
Sourcepub fn default_video_folder(&self) -> u32
pub fn default_video_folder(&self) -> u32
Retrieves the default video folder, if there isn’t one this value may be garbage. Therefore, it’s not recommended to depend on this value, unless you know exactly how the device you are interacting with handles this setting.
Sourcepub fn default_organizer_folder(&self) -> u32
pub fn default_organizer_folder(&self) -> u32
Retrieves the default organizer folder, if there isn’t one this value may be garbage. Therefore, it’s not recommended to depend on this value, unless you know exactly how the device you are interacting with handles this setting.
Sourcepub fn default_zencast_folder(&self) -> u32
pub fn default_zencast_folder(&self) -> u32
Retrieves the default zencast folder, if there isn’t one this value may be garbage. Therefore, it’s not recommended to depend on this value, unless you know exactly how the device you are interacting with handles this setting.
Sourcepub fn default_album_folder(&self) -> u32
pub fn default_album_folder(&self) -> u32
Retrieves the default album folder, if there isn’t one this value may be garbage. Therefore, it’s not recommended to depend on this value, unless you know exactly how the device you are interacting with handles this setting.
Sourcepub fn default_text_folder(&self) -> u32
pub fn default_text_folder(&self) -> u32
Retrieves the default text folder, if there isn’t one this value may be garbage. Therefore, it’s not recommended to depend on this value, unless you know exactly how the device you are interacting with handles this setting.
Sourcepub fn get_friendly_name(&self) -> Result<String>
pub fn get_friendly_name(&self) -> Result<String>
Gets the friendly name of this device, e.g. “Kevin’s Android”
Sourcepub fn set_friendly_name(&self, name: &str) -> Result<()>
pub fn set_friendly_name(&self, name: &str) -> Result<()>
Sets the friendly name of this device
Sourcepub fn get_sync_partner(&self) -> Result<String>
pub fn get_sync_partner(&self) -> Result<String>
Retrieves the synchronization partner of this device.
Sourcepub fn set_sync_partner(&self, partner: &str) -> Result<()>
pub fn set_sync_partner(&self, partner: &str) -> Result<()>
Sets the synchronization partner of this device.
Sourcepub fn manufacturer_name(&self) -> Result<String>
pub fn manufacturer_name(&self) -> Result<String>
Returns the manufacturer name of this device.
Sourcepub fn model_name(&self) -> Result<String>
pub fn model_name(&self) -> Result<String>
Returns the model name of this device.
Sourcepub fn serial_number(&self) -> Result<String>
pub fn serial_number(&self) -> Result<String>
Returns the serial number of this device.
Sourcepub fn device_certificate(&self) -> Result<String>
pub fn device_certificate(&self) -> Result<String>
Returns the device (public key) certificate as an XML document string.
Sourcepub fn battery_level(&self) -> Result<(BatteryLevel, u8)>
pub fn battery_level(&self) -> Result<(BatteryLevel, u8)>
Retrieves the current and maximum battery level of this device.
Sourcepub fn secure_time(&self) -> Result<String>
pub fn secure_time(&self) -> Result<String>
Returns the secure time as an XML document string.
Sourcepub fn supported_filetypes(&self) -> Result<Vec<Filetype>>
pub fn supported_filetypes(&self) -> Result<Vec<Filetype>>
Retrieves a list of supported file types that this device claims it supports.
This list is mitigated to include the filetypes that libmtp
(C library) can handle.
Sourcepub fn check_capability(&self, capability: DeviceCapability) -> bool
pub fn check_capability(&self, capability: DeviceCapability) -> bool
Check whether this device has some specific capabilitiy.
Sourcepub fn reset_device(&self) -> Result<()>
pub fn reset_device(&self) -> Result<()>
Reset the device only if this one supports the PTP_OC_ResetDevice
operation code
(0x1010
)
Sourcepub fn update_storage(&mut self, sort_by: StorageSort) -> Result<UpdateResult>
pub fn update_storage(&mut self, sort_by: StorageSort) -> Result<UpdateResult>
Updates all the internal storage ids and properties of this device, it can also optionally sort the list. This operation may success, partially success (only ids were retrieved) or fail.
Sourcepub fn storage_pool(&self) -> StoragePool<'_>
pub fn storage_pool(&self) -> StoragePool<'_>
Returns the inner storage pool, you need to call this if you updated
the storage with update_storage
. Note that the pool may be empty.
Sourcepub fn dump_device_info(&self)
pub fn dump_device_info(&self)
Dumps out a large chunk of textual information provided from the PTP protocol and additionally some extra MTP specific information where applicable.
Sourcepub fn is_property_supported(
&self,
property: Property,
filetype: Filetype,
) -> Result<bool>
pub fn is_property_supported( &self, property: Property, filetype: Filetype, ) -> Result<bool>
Determines wheter a property is supported for a given file type.
Sourcepub fn allowed_property_values(
&self,
property: Property,
filetype: Filetype,
) -> Result<AllowedValues>
pub fn allowed_property_values( &self, property: Property, filetype: Filetype, ) -> Result<AllowedValues>
Retrieves the allowes values (range or enumeration) for an specific property.
Sourcepub fn dummy_object(&self, id: impl AsObjectId) -> DummyObject<'_>
pub fn dummy_object(&self, id: impl AsObjectId) -> DummyObject<'_>
Build a dummy object, it’s useful to work with objects when we only have an id.
§Example
let id = 30; // stored id
let dummy_object = mtp_device.dummy_object(id);
let string = dummy_object.get_string(Property::ObjectFileName);
Sourcepub fn search_file(&self, id: impl AsObjectId) -> Result<File<'_>>
pub fn search_file(&self, id: impl AsObjectId) -> Result<File<'_>>
Search for a file with the given id in this device, note that you don’t need to use a
Storage for this, since ids are unique across all the device. Don’t call this function
repeatedly, the search is O(n)
and the call may involve slow USB traffic. Instead use
Storage::files_and_folders
to cache files.