android_manifest/
instrumentation.rs

1use crate::VarOrBool;
2
3use super::resources::{MipmapOrDrawableResource, StringResourceOrString};
4use serde::{Deserialize, Serialize};
5
6/// Declares an [`Instrumentation`] class that enables you to monitor an application's
7/// interaction with the system.
8///
9/// The Instrumentation object is instantiated before any of the application's
10/// components.
11///
12/// ## XML Syntax
13/// ```xml
14/// <instrumentation android:functionalTest=["true" | "false"]
15///                  android:handleProfiling=["true" | "false"]
16///                  android:icon="drawable resource"
17///                  android:label="string resource"
18///                  android:name="string"
19///                  android:targetPackage="string"
20///                  android:targetProcesses="string" />
21/// ```
22///
23/// ## Contained in:
24/// * [`<manifest>`]
25///
26/// ## Introduced in
27/// API Level 1
28///
29/// [`Instrumentation`]: https://developer.android.com/reference/android/app/Instrumentation
30/// [`<manifest>`]: crate::AndroidManifest
31#[derive(
32    Debug, Deserialize, Serialize, YaSerialize, YaDeserialize, PartialEq, Eq, Default, Clone,
33)]
34pub struct Instrumentation {
35    /// Whether or not the Instrumentation class should run as a functional test —
36    /// `"true"` if it should, and `"false"` if not. The default value is `"false"`.
37    #[yaserde(attribute, prefix = "android", rename = "functionalTest")]
38    pub functional_test: Option<VarOrBool>,
39    /// Whether or not the Instrumentation object will turn profiling on and off —
40    /// `"true"` if it determines when profiling starts and stops, and `"false"` if
41    /// profiling continues the entire time it is running. A value of `"true"` enables
42    /// the object to target profiling at a specific set of operations. The default
43    /// value is `"false"`.
44    #[yaserde(attribute, prefix = "android", rename = "handleProfiling")]
45    pub handle_profiling: Option<VarOrBool>,
46    /// An icon that represents the Instrumentation class. This attribute must be set as a
47    /// reference to a drawable resource.
48    #[yaserde(attribute, prefix = "android")]
49    pub icon: Option<MipmapOrDrawableResource>,
50    /// A user-readable label for the Instrumentation class. The label can be set as a raw
51    /// string or a reference to a string resource.
52    #[yaserde(attribute, prefix = "android")]
53    pub label: Option<StringResourceOrString>,
54    /// The name of the [`Instrumentation`] subclass. This should be a fully qualified
55    /// class name (such as, `"com.example.project.StringInstrumentation"`). However,
56    /// as a shorthand, if the first character of the name is a period, it is
57    /// appended to the package name specified in the [`<manifest>`] element.
58    /// There is no default. The name must be specified.
59    ///
60    /// [`Instrumentation`]: https://developer.android.com/reference/android/app/Instrumentation
61    /// [`<manifest>`]: crate::AndroidManifest
62    #[yaserde(attribute, prefix = "android")]
63    pub name: String,
64    /// The application that the [`Instrumentation`] object will run against. An
65    /// application is identified by the package name assigned in its manifest file by
66    /// the [`<manifest>`] element.
67    ///
68    /// [`Instrumentation`]: https://developer.android.com/reference/android/app/Instrumentation
69    /// [`<manifest>`]: crate::AndroidManifest
70    #[yaserde(attribute, prefix = "android", rename = "targetPackage")]
71    pub target_package: Option<String>,
72    /// The processes that the [`Instrumentation`] object will run against. A
73    /// comma-separated list indicates that the instrumentation will run against those
74    /// specific processes. A value of `"*"` indicates that the instrumentation will
75    /// run against all processes of the app defined in [`android:targetPackage`]. If
76    /// this value isn't provided in the manifest, the instrumentation will run only
77    /// against the main process of the app defined in [`android:targetPackage`].
78    ///
79    /// [`Instrumentation`]: https://developer.android.com/reference/android/app/Instrumentation
80    /// [`android:targetPackage`]: crate::Instrumentation#structfield.target_package
81    #[yaserde(attribute, prefix = "android", rename = "targetProcesses")]
82    pub target_processes: Option<String>,
83}