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