creator_simctl/
privacy.rs1use super::{Device, Result, Validate};
4
5#[derive(Copy, Clone, Debug, Eq, PartialEq)]
8pub enum PrivacyService {
9 All,
11
12 Calendar,
14
15 ContactsLimited,
17
18 Contacts,
20
21 Location,
23
24 LocationAlways,
26
27 PhotosAdd,
29
30 Photos,
32
33 MediaLibrary,
35
36 Microphone,
39
40 Motion,
42
43 Reminders,
45
46 Siri,
48}
49
50impl ToString for PrivacyService {
51 fn to_string(&self) -> String {
52 match self {
53 PrivacyService::All => "all",
54 PrivacyService::Calendar => "calendar",
55 PrivacyService::ContactsLimited => "contacts-limited",
56 PrivacyService::Contacts => "contacts",
57 PrivacyService::Location => "location",
58 PrivacyService::LocationAlways => "location-always",
59 PrivacyService::PhotosAdd => "photos-add",
60 PrivacyService::Photos => "photos",
61 PrivacyService::MediaLibrary => "media-library",
62 PrivacyService::Microphone => "microphone",
63 PrivacyService::Motion => "motion",
64 PrivacyService::Reminders => "reminders",
65 PrivacyService::Siri => "siri",
66 }
67 .to_owned()
68 }
69}
70
71pub struct Privacy {
73 device: Device,
74}
75
76impl Device {
77 pub fn privacy(&self) -> Privacy {
79 Privacy {
80 device: self.clone(),
81 }
82 }
83}
84
85impl Privacy {
86 pub fn grant(&self, service: PrivacyService, bundle_id: &str) -> Result<()> {
89 self.device
90 .simctl()
91 .command("privacy")
92 .arg(&self.device.udid)
93 .arg("grant")
94 .arg(service.to_string())
95 .arg(bundle_id)
96 .output()?
97 .validate()
98 }
99
100 pub fn revoke(&self, service: PrivacyService, bundle_id: &str) -> Result<()> {
103 self.device
104 .simctl()
105 .command("privacy")
106 .arg(&self.device.udid)
107 .arg("revoke")
108 .arg(service.to_string())
109 .arg(bundle_id)
110 .output()?
111 .validate()
112 }
113
114 pub fn reset(&self, service: PrivacyService, bundle_id: &str) -> Result<()> {
118 self.device
119 .simctl()
120 .command("privacy")
121 .arg(&self.device.udid)
122 .arg("reset")
123 .arg(service.to_string())
124 .arg(bundle_id)
125 .output()?
126 .validate()
127 }
128
129 pub fn reset_all(&self, service: PrivacyService) -> Result<()> {
132 self.device
133 .simctl()
134 .command("privacy")
135 .arg(&self.device.udid)
136 .arg("reset")
137 .arg(service.to_string())
138 .output()?
139 .validate()
140 }
141}
142
143#[cfg(test)]
144mod tests {
145 use serial_test::serial;
146
147 use super::*;
148 use crate::mock;
149
150 #[test]
151 #[serial]
152 fn test_privacy_grant() -> Result<()> {
153 mock::device()?.boot()?;
154 mock::device()?
155 .privacy()
156 .grant(PrivacyService::Location, "com.apple.Maps")?;
157 mock::device()?.shutdown()?;
158
159 Ok(())
160 }
161
162 #[test]
163 #[serial]
164 fn test_privacy_revoke() -> Result<()> {
165 mock::device()?.boot()?;
166 mock::device()?
167 .privacy()
168 .revoke(PrivacyService::Location, "com.apple.Maps")?;
169 mock::device()?.shutdown()?;
170
171 Ok(())
172 }
173
174 #[test]
175 #[serial]
176 fn test_privacy_reset() -> Result<()> {
177 mock::device()?.boot()?;
178 mock::device()?
179 .privacy()
180 .grant(PrivacyService::Location, "com.apple.Maps")?;
181 mock::device()?
182 .privacy()
183 .reset(PrivacyService::Location, "com.apple.Maps")?;
184 mock::device()?.shutdown()?;
185
186 Ok(())
187 }
188
189 #[test]
190 #[serial]
191 fn test_privacy_reset_all() -> Result<()> {
192 mock::device()?.boot()?;
193 mock::device()?
194 .privacy()
195 .grant(PrivacyService::Location, "com.apple.Maps")?;
196 mock::device()?
197 .privacy()
198 .reset_all(PrivacyService::Location)?;
199 mock::device()?.shutdown()?;
200
201 Ok(())
202 }
203}