From 2ba2dd398cbafb22521292d14bcc42c33704aa39 Mon Sep 17 00:00:00 2001 From: Adrien Bennadji Date: Wed, 24 Nov 2021 09:13:53 +0100 Subject: [PATCH 1/2] Add android:exported support in manifest --- cargo-apk/README.md | 5 +++++ ndk-build/src/manifest.rs | 3 +++ 2 files changed, 8 insertions(+) diff --git a/cargo-apk/README.md b/cargo-apk/README.md index 0b8f84d6..df1c05f9 100644 --- a/cargo-apk/README.md +++ b/cargo-apk/README.md @@ -126,6 +126,11 @@ launch_mode = "singleTop" # Defaults to "unspecified". orientation = "landscape" +# See https://developer.android.com/guide/topics/manifest/activity-element#exported +# +# Defaults to "unspecified". +exported = "true" + # See https://developer.android.com/guide/topics/manifest/meta-data-element # # Note: there can be several .meta_data entries. diff --git a/ndk-build/src/manifest.rs b/ndk-build/src/manifest.rs index fe4f1854..8b2306f8 100644 --- a/ndk-build/src/manifest.rs +++ b/ndk-build/src/manifest.rs @@ -93,6 +93,8 @@ pub struct Activity { pub name: String, #[serde(rename(serialize = "android:screenOrientation"))] pub orientation: Option, + #[serde(rename(serialize = "android:exported"))] + pub exported: Option, #[serde(rename(serialize = "meta-data"))] #[serde(default)] @@ -111,6 +113,7 @@ impl Default for Activity { launch_mode: None, name: default_activity_name(), orientation: None, + exported: None, meta_data: Default::default(), intent_filters: Default::default(), } From ec8cd390416a5308ab6cf16d12b87f38d2aeda1c Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Wed, 16 Mar 2022 17:06:31 +0100 Subject: [PATCH 2/2] cargo-apk: Export native activity by default on Android S and up Similar to how we help the user with a default `MAIN` intent filter to launch the sole `NativeActivity` in their application (and setting a few other sensible defaults), we should also set Android's new `android:exported` attribute to `true` if they're targeting Android S (SDK 31) or higher. Without this set to `true` the Rust app is not allowed to be started externally (by ie. a launcher or `adb`) on Android S+, and with only a single `Activity` currently supported by `ndk-build` it is unlikely (but not impossible, see shared user IDs etc), that there are other means to start it internally. https://developer.android.com/guide/topics/manifest/activity-element#exported --- cargo-apk/CHANGELOG.md | 1 + cargo-apk/README.md | 2 +- cargo-apk/src/apk.rs | 9 ++++++++- ndk-build/CHANGELOG.md | 1 + 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/cargo-apk/CHANGELOG.md b/cargo-apk/CHANGELOG.md index a00aedd3..fb0426ff 100644 --- a/cargo-apk/CHANGELOG.md +++ b/cargo-apk/CHANGELOG.md @@ -7,6 +7,7 @@ https://developer.android.com/distribute/best-practices/develop/target-sdk - Allow manifest `package` property to be provided in `Cargo.toml`. ([#236](https://github.com/rust-windowing/android-ndk-rs/pull/236)) - Add `MAIN` intent filter in `from_subcommand` instead of relying on a custom serialization function in `ndk-build`. ([#241](https://github.com/rust-windowing/android-ndk-rs/pull/241)) +- Export the sole `NativeActivity` (through `android:exported="true"`) to allow it to be started by default if targeting Android S or higher. ([#242](https://github.com/rust-windowing/android-ndk-rs/pull/242)) # 0.8.2 (2021-11-22) diff --git a/cargo-apk/README.md b/cargo-apk/README.md index df1c05f9..2c545416 100644 --- a/cargo-apk/README.md +++ b/cargo-apk/README.md @@ -128,7 +128,7 @@ orientation = "landscape" # See https://developer.android.com/guide/topics/manifest/activity-element#exported # -# Defaults to "unspecified". +# Unset by default, or "true" when targeting Android >= 31 (S and up). exported = "true" # See https://developer.android.com/guide/topics/manifest/meta-data-element diff --git a/cargo-apk/src/apk.rs b/cargo-apk/src/apk.rs index 32b6da90..2f8ba928 100644 --- a/cargo-apk/src/apk.rs +++ b/cargo-apk/src/apk.rs @@ -53,7 +53,7 @@ impl<'a> ApkBuilder<'a> { panic!("version_code should not be set in TOML"); } - manifest + let target_sdk_version = *manifest .android_manifest .sdk .target_sdk_version @@ -80,6 +80,13 @@ impl<'a> ApkBuilder<'a> { }); } + // Export the sole Rust activity on Android S and up, if the user didn't explicitly do so. + // Without this, apps won't start on S+. + // https://developer.android.com/about/versions/12/behavior-changes-12#exported + if target_sdk_version >= 31 { + activity.exported.get_or_insert(true); + } + Ok(Self { cmd, ndk, diff --git a/ndk-build/CHANGELOG.md b/ndk-build/CHANGELOG.md index 641dd254..06446154 100644 --- a/ndk-build/CHANGELOG.md +++ b/ndk-build/CHANGELOG.md @@ -5,6 +5,7 @@ https://developer.android.com/distribute/best-practices/develop/target-sdk - Remove default insertion of `MAIN` intent filter through a custom serialization function, this is better filled in by the default setup in `cargo-apk`. ([#241](https://github.com/rust-windowing/android-ndk-rs/pull/241)) +- Add `android:exported` attribute to the manifest's `Activity` element. ([#242](https://github.com/rust-windowing/android-ndk-rs/pull/242)) # 0.4.3 (2021-11-22)