android_manifest/
activity_alias.rs

1use crate::VarOrBool;
2
3use super::intent_filter::IntentFilter;
4use super::meta_data::MetaData;
5use super::resources::{MipmapOrDrawableResource, Resource, StringResource};
6use serde::{Deserialize, Serialize};
7
8/// An alias for an activity, named by the `targetActivity` attribute.
9///
10/// The target must be in the same application as the alias and it must be declared before
11/// the alias in the manifest.
12///
13/// The alias presents the target activity as an independent entity. It can have its own
14/// set of intent filters, and they, rather than the intent filters on the target activity
15/// itself, determine which intents can activate the target through the alias and how the
16/// system treats the alias. For example, the intent filters on the alias may specify the
17/// "[`android.intent.action.MAIN`]" and "[`android.intent.category.LAUNCHER`]" flags,
18/// causing it to be represented in the application launcher, even though none of the
19/// filters on the target activity itself set these flags.
20///
21/// With the exception of `targetActivity`, `<activity-alias>` attributes are a subset of
22/// [`<activity>`] attributes. For attributes in the subset, none of the values set for
23/// the target carry over to the alias. However, for attributes not in the subset, the
24/// values set for the target activity also apply to the alias.
25///
26/// ## XML Syntax
27/// ```xml
28/// <activity-alias android:enabled=["true" | "false"]
29///                 android:exported=["true" | "false"]
30///                 android:icon="drawable resource"
31///                 android:label="string resource"
32///                 android:name="string"
33///                 android:permission="string"
34///                 android:targetActivity="string" >
35///     ...
36/// </activity-alias>
37/// ```
38///
39/// ## Contained in
40/// * [`<application>`]
41///
42/// ## Can contain
43/// * [`<intent-filter>`]
44/// * [`<meta-data>`]
45///
46/// ## Introduced in
47/// API Level 1
48///
49/// [`<application>`]: crate::Application
50/// [`<intent-filter>`]: crate::IntentFilter
51/// [`<meta-data>`]: crate::MetaData
52/// [`<activity>`]: crate::Activity
53/// [`android.intent.action.MAIN`]: https://developer.android.com/reference/android/content/Intent#ACTION_MAIN
54/// [`android.intent.category.LAUNCHER`]: https://developer.android.com/reference/android/content/Intent#CATEGORY_LAUNCHER
55#[derive(
56    Debug, Deserialize, Serialize, YaSerialize, YaDeserialize, PartialEq, Eq, Default, Clone,
57)]
58pub struct ActivityAlias {
59    /// Whether or not the target activity can be instantiated by the system through this
60    /// alias — "`true`" if it can be, and "`false`" if not. The default value is
61    /// "`true`".
62    ///
63    /// The [`<application>`] element has its own [`enabled`] attribute that applies to
64    /// all application components, including activity aliases. The [`<application>`]
65    /// and `<activity-alias>` attributes must both be "`true`" for the system
66    /// to be able to instantiate the target activity through the alias. If
67    /// either is "`false`", the alias does not work.
68    ///
69    /// [`<application>`]: crate::Application
70    /// [`enabled`]: crate::Application#structfield.enabled
71    #[yaserde(attribute, prefix = "android")]
72    pub enabled: Option<VarOrBool>,
73    /// Whether the broadcast receiver can receive messages from non-system sources
74    /// outside its application — "`true`" if it can, and "`false`" if
75    /// not. If "`false`", the target activity can be launched through the
76    /// alias only by components of the same application as the alias or
77    /// applications with the same user ID.
78    ///
79    /// The default value depends on whether the alias contains intent filters. The
80    /// absence of any filters means that the activity can be invoked through the
81    /// alias only by specifying the exact name of the alias. This implies that the
82    /// alias is intended only for application-internal use (since others would not
83    /// know its name) — so the default value is "`false`". On the other hand, the
84    /// presence of at least one filter implies that the alias is intended for
85    /// external use — so the default value is "`true`".
86    #[yaserde(attribute, prefix = "android")]
87    pub exported: Option<VarOrBool>,
88    /// An icon for the target activity when presented to users through the alias. See the
89    /// [`<activity>`] element's [`icon`] attribute for more information.
90    ///
91    /// [`<activity>`]: crate::Activity
92    /// [`icon`]: crate::Activity#structfield.icon
93    #[yaserde(attribute, prefix = "android")]
94    pub icon: Option<MipmapOrDrawableResource>,
95    /// A user-readable label for the alias when presented to users through the alias. See
96    /// the [`<activity>`] element's [`label`] attribute for more information.
97    ///
98    /// [`<activity>`]: crate::Activity
99    /// [`label`]: crate::Activity#structfield.label
100    #[yaserde(attribute, prefix = "android")]
101    pub label: Option<Resource<StringResource>>,
102    /// A unique name for the alias. The name should resemble a fully qualified class
103    /// name. But, unlike the name of the target activity, the alias name
104    /// is arbitrary; it does not refer to an actual class.
105    #[yaserde(attribute, prefix = "android")]
106    pub name: Option<String>,
107    /// The name of a permission that clients must have to launch the target activity or
108    /// get it to do something via the alias. If a caller of [`startActivity()`] or
109    /// [`startActivityForResult()`] has not been granted the specified permission,
110    /// the target activity will not be activated.
111    ///
112    /// This attribute supplants any permission set for the target activity itself. If it
113    /// is not set, a permission is not needed to activate the target through the
114    /// alias.
115    ///
116    /// For more information on permissions, see the [`Permissions`] section in
117    /// the introduction.
118    ///
119    /// [`startActivity()`]: https://developer.android.com/reference/android/content/Context#startActivity(android.content.Intent)
120    /// [`startActivityForResult()`]: https://developer.android.com/reference/android/app/Activity#startActivityForResult(android.content.Intent,%20int)
121    /// [`Permissions`]: https://developer.android.com/guide/topics/manifest/manifest-intro#perms
122    #[yaserde(attribute, prefix = "android")]
123    pub permission: Option<String>,
124    /// The name of the activity that can be activated through the alias. This name must
125    /// match the `name` attribute of an [`<activity>`] element that precedes the
126    /// alias in the manifest.
127    ///
128    /// [`<activity>`]: crate::Activity
129    #[yaserde(attribute, prefix = "android", rename = "targetActivity")]
130    pub target_activity: Option<String>,
131    /// List of `<intent-filter>` tags.
132    #[yaserde(rename = "intent-filter")]
133    #[serde(default, skip_serializing_if = "Vec::is_empty")]
134    pub intent_filter: Vec<IntentFilter>,
135    /// List of `<meta-data>` tags.
136    #[yaserde(rename = "meta-data")]
137    #[serde(default, skip_serializing_if = "Vec::is_empty")]
138    pub meta_data: Vec<MetaData>,
139}