android_manifest/manifest.rs
1use super::application::Application;
2use super::compatible_screens::CompatibleScreens;
3use super::instrumentation::Instrumentation;
4use super::permission::Permission;
5use super::permission_group::PermissionGroup;
6use super::permission_tree::PermissionTree;
7use super::queries::Queries;
8use super::resources::{Resource, StringResource};
9use super::supports_gl_texture::SupportsGlTexture;
10use super::supports_screens::SupportsScreens;
11use super::uses_configuration::UsesConfiguration;
12use super::uses_feature::UsesFeature;
13use super::uses_permission::UsesPermission;
14use super::uses_permission_sdk_23::UsesPermissionSdk23;
15use super::uses_sdk::UsesSdk;
16use serde::{Deserialize, Serialize};
17
18/// The root element of the `AndroidManifest.xml` file.
19///
20/// It must contain an [`<application>`] element and specify `xmlns:android` and
21/// `package` attributes.
22///
23/// ## XML Syntax
24/// ```xml
25/// <manifest xmlns:android="http://schemas.android.com/apk/res/android"
26/// xmlns:tools="http://schemas.android.com/tools"
27/// package="string"
28/// android:sharedUserId="string"
29/// android:sharedUserLabel="string resource"
30/// android:versionCode="integer"
31/// android:versionName="string"
32/// android:installLocation=["auto" | "internalOnly" | "preferExternal"]
33/// tools:ignore="string"
34/// tools:targetApi="string"
35/// tools:locale="string"
36/// tools:shrinkMode=["safe" | "strict"]
37/// tools:keep="string"
38/// tools:discard="string" >
39/// ...
40/// </manifest>
41/// ```
42///
43/// ## Must contain
44/// * [`<application>`]
45///
46/// ## Can contain
47/// * [`<compatible-screens>`]
48/// * [`<instrumentation>`]
49/// * [`<permission>`]
50/// * [`<permission-group>`]
51/// * [`<permission-tree>`]
52/// * [`<queries>`]
53/// * [`<supports-gl-texture>`]
54/// * [`<supports-screens>`]
55/// * [`<uses-configuration>`]
56/// * [`<uses-feature>`]
57/// * [`<uses-permission>`]
58/// * [`<uses-permission-sdk-23>`]
59/// * [`<uses-sdk>`]
60///
61/// ## Introduced in
62/// API Level 1 for all attributes, unless noted otherwise in the attribute description.
63///
64/// [`<application>`]: crate::Application
65/// [`<compatible-screens>`]: crate::CompatibleScreens
66/// [`<instrumentation>`]: crate::Instrumentation
67/// [`<permission>`]: crate::Permission
68/// [`<permission-group>`]: crate::PermissionGroup
69/// [`<permission-tree>`]: crate::PermissionTree
70/// [`<supports-gl-texture>`]: crate::SupportsGlTexture
71/// [`<supports-screens>`]: crate::SupportsScreens
72/// [`<uses-configuration>`]: crate::UsesConfiguration
73/// [`<uses-feature>`]: crate::UsesFeature
74/// [`<uses-permission>`]: crate::UsesPermission
75/// [`<uses-permission-sdk-23>`]: crate::UsesPermissionSdk23
76/// [`<uses-sdk>`]: crate::UsesSdk
77/// [`<queries>`]: crate::Queries
78#[derive(
79 Debug, Deserialize, Serialize, XmlSerialize, XmlDeserialize, PartialEq, Default, Clone,
80)]
81#[xml(
82 rename = "manifest",
83 namespaces = {
84 "android" = "http://schemas.android.com/apk/res/android",
85 "tools" = "http://schemas.android.com/tools"
86 }
87)]
88pub struct AndroidManifest {
89 /// A full Java-language-style package name for the Android app. The name may contain
90 /// uppercase or lowercase letters ('A' through 'Z'), numbers, and underscores
91 /// ('_'). However, individual package name parts may only start with letters.
92 ///
93 /// While building your app into the an application package (APK), the build system
94 /// uses the package attribute for two things:
95 ///
96 /// * It applies this name as the namespace for your app's generated R.java class
97 /// (used to access your [`app resources`]).
98 ///
99 /// For example, if package is set to `"com.example.myapp"`, the R class is created at
100 /// `com.example.myapp.R`.
101 ///
102 /// * It uses this name to resolve any relative class names that are declared in the
103 /// manifest file. For example, if package is set to `"com.example.myapp"`, an
104 /// activity declared as
105 /// `<activity android:name=".MainActivity">` is resolved to be
106 /// `com.example.myapp.MainActivity`.
107 ///
108 /// This name is also the default name for your app process (see the `<application>`
109 /// element's [`process`] attribute). And it's the default task affinity for your
110 /// activities (see the `<activity>` element's [`taskAffinity`] attribute).
111 ///
112 /// This name also represents the application ID, which must be universally unique in
113 /// order to publish your app in [`Google Play`]. However, toward the end of the APK
114 /// build process, the build tools override the package name using the
115 /// applicationId property from the build.gradle file (used by Android Studio
116 /// projects). As long as you keep the manifest's package name the same as the
117 /// build file's applicationId, this won't be a concern. But if these two values
118 /// differ, you should understand the differences between the `"package name"` and
119 /// `"application ID"` by reading [`how to set the application ID`].
120 ///
121 /// To avoid conflicts with other developers, you should use Internet domain ownership
122 /// as the basis for your package names (in reverse). For example, apps published by
123 /// Google start with com.google.
124 ///
125 /// ## Note
126 /// Both the `com.example` and `com.android` namespaces are forbidden by Google Play.
127 ///
128 /// ## Caution
129 /// `If you want to change your package name` after you publish your app, you can, but
130 /// `you must keep the applicationId the same`. The applicationId defines the unique
131 /// identity for your app on Google Play. So if you change it, the APK is considered
132 /// to be a different app and users of the previous version will not receive an
133 /// update. For more information, see [`how to set the application ID`].
134 ///
135 /// [`app resources`]: https://developer.android.com/guide/topics/resources/providing-resources
136 /// [`process`]: crate::Application#structfield.process
137 /// [`taskAffinity`]: crate::Activity#structfield.task_affinitys
138 /// [`Google Play`]: https://developer.android.com/distribute/google-play
139 /// [`how to set the application ID`]: https://developer.android.com/studio/build/application-id
140 #[xml(attribute = true)]
141 #[serde(skip_serializing_if = "Option::is_none")]
142 pub package: Option<String>,
143 /// ## Caution
144 /// `This constant was deprecated in API level 29.`
145 /// Shared user IDs cause non-deterministic behavior within the package manager. As
146 /// such, its use is strongly discouraged and may be removed in a future version of
147 /// Android. Instead, apps should use proper communication mechanisms, such as
148 /// services and content providers, to facilitate interoperability between shared
149 /// components. Note that existing apps cannot remove this value, as migrating off a
150 /// shared user ID is not supported.
151 ///
152 /// The name of a Linux user ID that will be shared with other apps. By default,
153 /// Android assigns each app its own unique user ID. However, if this attribute is
154 /// set to the same value for two or more apps, they will all share the same ID —
155 /// provided that their certificate sets are identical. Apps with the same user ID
156 /// can access each other's data and, if desired, run in the same process.
157 #[xml(attribute = true, prefix = "android", rename = "sharedUserId")]
158 pub shared_user_id: Option<String>,
159 /// The higher the sandbox version number, the higher the level of security. Its
160 /// default value is 1; you can also set it to 2. Setting this attribute
161 /// to 2 switches the app to a different SELinux sandbox.
162 ///
163 /// The following restrictions apply to a level 2 sandbox:
164 ///
165 /// * The default value of `usesCleartextTraffic` in the Network Security Config is
166 /// false.
167 /// * Uid sharing is not permitted.
168 ///
169 /// For Android Instant Apps targeting Android 8.0 (API level 26) or higher, this
170 /// attribute must be set to 2. You can set the sandbox level in the installed version
171 /// of your app to the less restrictive level 1, but if you do so, your app does not
172 /// persist app data from the instant app to the installed version of your app. You
173 /// must set the installed app's sandbox value to 2 in order for the data to persist
174 /// from the instant app to the installed version.
175 ///
176 /// Once an app is installed, you can only update its target sandbox value to a higher
177 /// value. To downgrade the target sandbox value, you must uninstall the app and
178 /// replace it with a version whose manifest contains a lower value for this
179 /// attribute.
180 #[xml(attribute = true, prefix = "android", rename = "targetSandboxVersion")]
181 pub target_sandbox_version: Option<String>,
182 /// ## Caution
183 /// `This constant was deprecated in API level 29`. Shared user IDs cause
184 /// non-deterministic behavior within the package manager. As such, its use is
185 /// strongly discouraged and may be removed in a future version of Android. Instead,
186 /// apps should use proper communication mechanisms, such as services and content
187 /// providers, to facilitate interoperability between shared components. Note that
188 /// existing apps cannot remove this value, as migrating off a shared user ID is not
189 /// supported
190 ///
191 /// A user-readable label for the shared user ID. The label must be set as a reference
192 /// to a string resource; it cannot be a raw string.
193 ///
194 /// This attribute was introduced in API Level 3. It is meaningful only if the
195 /// [`sharedUserId`] attribute is also set.
196 ///
197 /// [`sharedUserId`]: crate::AndroidManifest#structfield.shared_user_id
198 #[xml(attribute = true, prefix = "android", rename = "sharedUserLabel")]
199 pub shared_user_label: Option<Resource<StringResource>>,
200 /// An internal version number. This number is used only to determine whether one
201 /// version is more recent than another, with higher numbers indicating more
202 /// recent versions. This is not the version number shown to users; that number is
203 /// set by the `versionName` attribute.
204 ///
205 /// The value must be set as an integer, such as
206 /// "100". You can define it however you want, as long as each successive version
207 /// has a higher number. For example, it could be a build number. Or you could
208 /// translate a version number in "x.y" format to an integer by encoding the "x" and
209 /// "y" separately in the lower and upper 16 bits. Or you could simply increase the
210 /// number by one each time a new version is released.
211 #[xml(attribute = true, prefix = "android", rename = "versionCode")]
212 pub version_code: Option<u32>,
213 /// The version number shown to users. This attribute can be set as a raw string or as
214 /// a reference to a string resource. The string has no other purpose than to be
215 /// displayed to users. The `versionCode` attribute holds the significant version
216 /// number used internally.
217 #[xml(attribute = true, prefix = "android", rename = "versionName")]
218 pub version_name: Option<String>,
219 /// When an app is installed on the external storage:
220 ///
221 /// * The `.apk` file is saved to the external storage, but any app data (such as
222 /// databases) is still saved on the internal device memory.
223 /// * The container in which the `.apk` file is saved is encrypted with a key that
224 /// allows the app to operate only on the device that installed it. (A user cannot
225 /// transfer the SD card to another device and use apps installed on the card.)
226 /// Though, multiple SD cards can be used with the same device.
227 /// * At the user's request, the app can be moved to the internal storage.
228 ///
229 /// The user may also request to move an app from the internal storage to the external
230 /// storage. However, the system will not allow the user to move the app to external
231 /// storage if this attribute is set to internalOnly, which is the default setting.
232 ///
233 /// Read [`App Install Location`] for more information about using this attribute
234 /// (including how to maintain backward compatibility).
235 ///
236 /// Introduced in: API Level 8.
237 ///
238 /// [`App Install Location`]: https://developer.android.com/guide/topics/data/install-location
239 #[xml(attribute = true, prefix = "android", rename = "installLocation")]
240 pub install_location: Option<InstallLocation>,
241 /// This attribute accepts a comma-separated list of lint issue IDs that you'd like
242 /// the tools to ignore on this element or any of its descendants.
243 ///
244 /// For example: `tools:ignore="MissingTranslation"`
245 ///
246 /// Reference: [Tools Attributes - tools:ignore](https://developer.android.com/studio/write/tool-attributes#tools-ignore)
247 #[xml(attribute = true, prefix = "tools")]
248 pub ignore: Option<String>,
249 /// This attribute works the same as the @TargetApi annotation in Java code. It lets
250 /// you specify the API level (either as an integer or as a code name) that supports
251 /// this element.
252 ///
253 /// For example: `tools:targetApi="14"`
254 ///
255 /// Reference: [Tools Attributes - tools:targetApi](https://developer.android.com/studio/write/tool-attributes#toolstargetapi)
256 #[xml(attribute = true, prefix = "tools", rename = "targetApi")]
257 pub target_api: Option<String>,
258 /// This tells the tools what the default language or locale is for the resources in
259 /// the given `<resources>` element to avoid warnings from the spellchecker.
260 ///
261 /// For example: `tools:locale="es"`
262 ///
263 /// Reference: [Tools Attributes - tools:locale](https://developer.android.com/studio/write/tool-attributes#toolslocale)
264 #[xml(attribute = true, prefix = "tools")]
265 pub locale: Option<String>,
266 /// Required `<application>` tag.
267 #[serde(default, skip_serializing_if = "Application::is_default")]
268 pub application: Application,
269 /// Optional `<uses-sdk>` tag.
270 #[xml(rename = "uses-sdk")]
271 pub uses_sdk: Option<UsesSdk>,
272 /// List of `<compatible-screens>` tags.
273 #[xml(rename = "compatible-screens")]
274 pub compatible_screens: Option<CompatibleScreens>,
275 /// Optional `<uses-configuration>` tag.
276 #[xml(rename = "uses-configuration")]
277 pub uses_configuration: Option<UsesConfiguration>,
278 /// List of `<queries>` tags.
279 pub queries: Option<Queries>,
280 /// List of `<instrumentation>` tags.
281 #[serde(default, skip_serializing_if = "Vec::is_empty")]
282 pub instrumentation: Vec<Instrumentation>,
283 /// List of `<permission>` tags.
284 #[serde(default, skip_serializing_if = "Vec::is_empty")]
285 pub permission: Vec<Permission>,
286 /// List of `<permission-group>` tags.
287 #[xml(rename = "permission-group")]
288 #[serde(default, skip_serializing_if = "Vec::is_empty")]
289 pub permission_group: Vec<PermissionGroup>,
290 /// List of `<permission-tree>` tags.
291 #[xml(rename = "permission-tree")]
292 #[serde(default, skip_serializing_if = "Vec::is_empty")]
293 pub permission_tree: Vec<PermissionTree>,
294 /// List of `<supports-gl-texture>` tags.
295 #[xml(rename = "supports-gl-texture")]
296 #[serde(default, skip_serializing_if = "Vec::is_empty")]
297 pub supports_gl_texture: Vec<SupportsGlTexture>,
298 /// List of `<supports-screens>` tags.
299 #[xml(rename = "supports-screens")]
300 #[serde(default, skip_serializing_if = "Vec::is_empty")]
301 pub supports_screens: Vec<SupportsScreens>,
302 /// List of `<uses-feature>` tags.
303 #[xml(rename = "uses-feature")]
304 #[serde(default, skip_serializing_if = "Vec::is_empty")]
305 pub uses_feature: Vec<UsesFeature>,
306 /// List of `<uses-permission>` tags.
307 #[xml(rename = "uses-permission")]
308 #[serde(default, skip_serializing_if = "Vec::is_empty")]
309 pub uses_permission: Vec<UsesPermission>,
310 /// List of `<uses-permission-sdk-23>` tags.
311 #[xml(rename = "uses-permission-sdk-23")]
312 #[serde(default, skip_serializing_if = "Vec::is_empty")]
313 pub uses_permission_sdk_23: Vec<UsesPermissionSdk23>,
314 /// This attribute lets you specify whether the build tools should use safe mode
315 /// (keep all resources that are explicitly cited and that might be referenced
316 /// dynamically) or strict mode (keep only the resources that are explicitly cited
317 /// in code or in other resources).
318 ///
319 /// For example: `tools:shrinkMode="strict"`
320 ///
321 /// Reference: [Tools Attributes - tools:shrinkMode](https://developer.android.com/studio/write/tool-attributes#toolsshrinkmode)
322 #[xml(attribute = true, prefix = "tools", rename = "shrinkMode")]
323 pub shrink_mode: Option<String>,
324 /// When using resource shrinking to remove unused resources, this attribute lets
325 /// you specify resources to keep, typically because they are referenced in an
326 /// indirect way at runtime. You can use the asterisk character as a wild card.
327 ///
328 /// For example: `tools:keep="@layout/used_1,@layout/used_2,@layout/*_3"`
329 ///
330 /// Reference: [Tools Attributes - tools:keep](https://developer.android.com/studio/write/tool-attributes#toolskeep)
331 #[xml(attribute = true, prefix = "tools")]
332 pub keep: Option<String>,
333 /// When using resource shrinking to remove unused resources, this attribute lets
334 /// you specify resources you want to manually discard, typically because the resource
335 /// is referenced but in a way that does not affect your app.
336 ///
337 /// For example: `tools:discard="@layout/unused_1"`
338 ///
339 /// Reference: [Tools Attributes - tools:discard](https://developer.android.com/studio/write/tool-attributes#toolsdiscard)
340 #[xml(attribute = true, prefix = "tools")]
341 pub discard: Option<String>,
342}
343
344/// The default install location for the app.
345#[derive(Debug, Deserialize, Serialize, XmlSerialize, XmlDeserialize, PartialEq, Eq, Clone)]
346#[serde(rename_all = "camelCase")]
347#[derive(Default)]
348pub enum InstallLocation {
349 /// The app may be installed on the external storage, but the system will install the
350 /// app on the internal storage by default. If the internal storage is full, then
351 /// the system will install it on the external storage. Once installed, the user
352 /// can move the app to either internal or external storage through the system
353 /// settings.
354 #[xml(rename = "auto")]
355 Auto,
356 /// The app must be installed on the internal device storage only. If this is set, the
357 /// app will never be installed on the external storage. If the internal storage
358 /// is full, then the system will not install the app. This is also the default
359 /// behavior if you do not define android:installLocation.
360 #[xml(rename = "internalOnly")]
361 #[default]
362 InternalOnly,
363 /// The app prefers to be installed on the external storage (SD card). There is no
364 /// guarantee that the system will honor this request. The app might be installed
365 /// on internal storage if the external media is unavailable or full. Once
366 /// installed, the user can move the app to either internal or external storage
367 /// through the system settings.
368 #[xml(rename = "preferExternal")]
369 PreferExternal,
370}