1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//! Configuration types for virtual MTP devices.
use PathBuf;
use Duration;
/// Configuration for a virtual MTP device.
///
/// Defines the identity and storages of a virtual device that operates against
/// a local filesystem directory instead of real USB hardware.
///
/// Build one from [`Default`] and set only the fields your test cares about.
/// New fields then arrive with a working default instead of breaking every
/// construction site.
///
/// # Example
///
/// ```rust
/// use std::path::PathBuf;
/// use mtp_rs::transport::virtual_device::config::{VirtualDeviceConfig, VirtualStorageConfig};
///
/// let config = VirtualDeviceConfig {
/// manufacturer: "Google".into(),
/// model: "Virtual Pixel 9".into(),
/// serial: "virtual-001".into(),
/// storages: vec![VirtualStorageConfig {
/// description: "Internal Storage".into(),
/// capacity: 64 * 1024 * 1024 * 1024,
/// backing_dir: PathBuf::from("/tmp/mtp-test"),
/// read_only: false,
/// }],
/// ..Default::default()
/// };
/// ```
/// A ready-to-extend starting point: an obviously-fake identity plus the
/// behavior flags a modern Android device would report.
///
/// **You must set `storages`**: the default is empty, which is not a usable
/// device. `MtpDeviceBuilder::open_virtual` rejects it up front with
/// "VirtualDeviceConfig requires at least one storage", and
/// `register_virtual_device` produces a device with nothing on it. There is no
/// honest default here, since only the caller knows which directory backs the
/// storage.
///
/// Two other fields are worth overriding:
///
/// - `serial` defaults to a fixed string, so give each device its own when you
/// register more than one at a time.
/// - `event_poll_interval` and `watch_backing_dirs` default to production-like
/// values (50 ms, watching on). Tests that don't exercise the watcher run
/// faster with `Duration::ZERO` and `false`.
/// Configuration for a single storage within a virtual device.
///
/// Deliberately has no `Default`, unlike [`VirtualDeviceConfig`]: an unset
/// `backing_dir` is never caught. Nothing validates it, so the storage just
/// reports zero objects and zero used space, and the test fails somewhere far
/// from the cause. A compile error is the better outcome here.