android_manifest/
uses_permission.rs

1use serde::{Deserialize, Serialize};
2
3/// Specifies a system permission that the user must grant in order for the app
4/// to operate correctly.
5///
6/// Permissions are granted by the user when the application is installed (on devices
7/// running Android 5.1 and lower) or while the app is running (on devices running Android
8/// 6.0 and higher). For more information on permissions, see the [`Permissions`] section
9/// in the introduction and the separate [`System Permissions`] API guide. A list of
10/// permissions defined by the base platform can be found at
11/// [`android.Manifest.permission`].
12///
13/// ## Note
14/// In some cases, the permissions that you request through
15/// `<uses-permission>` can affect how your application is filtered by Google Play.
16///
17/// If you request a hardware-related permission — `CAMERA`, for example — Google Play
18/// assumes that your application requires the underlying hardware feature and filters the
19/// application from devices that do not offer it.
20///
21/// To control filtering, always explicitly declare hardware features in `<uses-feature>`
22/// elements, rather than relying on Google Play to "discover" the requirements in
23/// `<uses-permission>` elements. Then, if you want to disable filtering for a particular
24/// feature, you can add a `android:required`="`false`" attribute to the <uses-feature>
25/// declaration.
26///
27/// For a list of permissions that imply hardware features, see the documentation for the
28/// [`<uses-feature>`] element.
29///
30/// ## XML Syntax
31/// ```xml
32/// <uses-permission android:name="string"
33///          android:maxSdkVersion="integer" />
34/// ```
35///
36/// ## Contained in
37/// * [`<manifest>`]
38///
39/// ## Introduced in
40/// API Level 1
41///
42/// [`Permissions`]: https://developer.android.com/guide/topics/manifest/manifest-intro#perms
43/// [`System Permissions`]: https://developer.android.com/guide/topics/permissions/overview
44/// [`android.Manifest.permission`]: https://developer.android.com/reference/android/Manifest.permission
45/// [`<uses-feature>`]: https://developer.android.com/guide/topics/manifest/uses-feature-element#permissions-features
46/// [`<manifest>`]: crate::AndroidManifest
47#[derive(
48    Debug, Deserialize, Serialize, YaSerialize, YaDeserialize, PartialEq, Eq, Default, Clone,
49)]
50pub struct UsesPermission {
51    /// The name of the permission. It can be a permission defined by theapplication with
52    /// the [`<permission>`] element, a permission defined by another application, or
53    /// one of the standard system permissions (such as [`android.permission.CAMERA`]
54    /// or [`android.permission.READ_CONTACTS`]). As these examples show, a
55    /// permission name typically includes the package name as a prefix.
56    ///
57    /// [`<permission>`]: crate::Permission
58    /// [`android.permission.CAMERA`]: https://developer.android.com/reference/android/Manifest.permission#CAMERA
59    /// [`android.permission.READ_CONTACTS`]: https://developer.android.com/reference/android/Manifest.permission#READ_CONTACTS
60    #[yaserde(attribute = true, prefix = "android")]
61    pub name: Option<String>,
62    /// The highest API level at which this permission should be granted to your app.
63    /// Setting this attribute is useful if the permission your app requires is no
64    /// longer needed beginning at a certain API level.
65    ///
66    /// ## XML Examples
67    /// Beginning with Android 4.4 (API level 19), it's no longer necessary for your app
68    /// to request the [`WRITE_EXTERNAL_STORAGE`] permission when your app wants to
69    /// write to its own application-specific directories on external storage (the
70    /// directories provided by [`getExternalFilesDir()`]). However, the permission is
71    /// required for API level 18 and lower. So you can declare that this permission
72    /// is needed only up to API level 18 with a declaration such as this:
73    ///
74    /// ```xml
75    /// <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
76    ///                  android:maxSdkVersion="18" />
77    /// ```
78    /// This way, beginning with API level 19, the system will no longer grant your app
79    /// the [`WRITE_EXTERNAL_STORAGE`] permission.
80    ///
81    /// This attribute was added in API level 19.
82    ///
83    /// [`WRITE_EXTERNAL_STORAGE`]: https://developer.android.com/reference/android/Manifest.permission#WRITE_EXTERNAL_STORAGE
84    /// [`getExternalFilesDir()`]: https://developer.android.com/reference/android/content/Context#getExternalFilesDir(java.lang.String)
85    #[yaserde(attribute = true, prefix = "android", rename = "maxSdkVersion")]
86    pub max_sdk_version: Option<u32>,
87}