Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ndk-build: Add support for <queries> element #259

Merged
merged 11 commits into from
May 6, 2022
19 changes: 19 additions & 0 deletions cargo-apk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,25 @@ version = 1
name = "android.permission.WRITE_EXTERNAL_STORAGE"
max_sdk_version = 18

# See https://developer.android.com/guide/topics/manifest/queries-element#provider
[[package.metadata.android.queries.provider]]
authorities = "org.khronos.openxr.runtime_broker;org.khronos.openxr.system_runtime_broker"
# Note: `name` attribute is not required for queries-provider however this is a workaround for aapt throwing errors about missing `android:name` attributes.
name = "org.khronos.openxr"

# See https://developer.android.com/guide/topics/manifest/queries-element#intent
[[package.metadata.android.queries.intent]]
actions = ["android.intent.action.SEND"]

# See https://developer.android.com/guide/topics/manifest/queries-element#intent
# Note: there can be several .data entries.
[[package.metadata.android.queries.intent.data]]
mime_type = "image/jpeg"
MarijnS95 marked this conversation as resolved.
Show resolved Hide resolved

# See https://developer.android.com/guide/topics/manifest/queries-element#package
[[package.metadata.android.queries.package]]
name = "org.freedesktop.monado.openxr_runtime.in_process"

# See https://developer.android.com/guide/topics/manifest/application-element
[package.metadata.android.application]

Expand Down
35 changes: 35 additions & 0 deletions ndk-build/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub struct AndroidManifest {
#[serde(default)]
pub uses_permission: Vec<Permission>,

#[serde(default)]
pub queries: Option<Queries>,

#[serde(default)]
pub application: Application,
}
Expand All @@ -44,6 +47,7 @@ impl Default for AndroidManifest {
sdk: Default::default(),
uses_feature: Default::default(),
uses_permission: Default::default(),
queries: Default::default(),
application: Default::default(),
}
}
Expand Down Expand Up @@ -258,6 +262,37 @@ pub struct Permission {
pub max_sdk_version: Option<u32>,
}

/// Android [package element](https://developer.android.com/guide/topics/manifest/queries-element#package).
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct Package {
#[serde(rename(serialize = "android:name"))]
pub name: String,
}

/// Android [provider element](https://developer.android.com/guide/topics/manifest/queries-element#provider).
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct QueryProvider {
#[serde(rename(serialize = "android:authorities"))]
pub authorities: String,

// The specs say only an `authorities` attribute is required for providers contained in a `queries` element
// however aapt throws errors requiring an `android:name` attribute,
// This is possibly due to ndk-build using aapt instead of aapt2?
MarijnS95 marked this conversation as resolved.
Show resolved Hide resolved
#[serde(rename(serialize = "android:name"))]
pub name: String,
}

/// Android [queries element](https://developer.android.com/guide/topics/manifest/queries-element).
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct Queries {
#[serde(default)]
pub package: Vec<Package>,
#[serde(default)]
pub intent: Vec<IntentFilter>,
#[serde(default)]
pub provider: Vec<QueryProvider>,
}

/// Android [uses-sdk element](https://developer.android.com/guide/topics/manifest/uses-sdk-element).
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Sdk {
Expand Down