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

Parse permissions into manifest #90

Merged
merged 20 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions crossbundle/cli/src/cargo_manifest.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crossbundle_tools::types::{android_manifest::UsesPermission, *};
use crossbundle_tools::types::{
android_manifest::{UsesFeature, UsesPermission, UsesPermissionSdk23},
*,
};
use serde::{Deserialize, Serialize};
use std::path::PathBuf;

Expand Down Expand Up @@ -29,14 +32,19 @@ pub struct Metadata {
/// Android build targets.
pub android_build_targets: Option<Vec<AndroidTarget>>,

// Android permissions for target sdk version = 22 and lower
pub android_permissions: Option<Vec<UsesPermission>>,
/// To declare a permission only on devices that support runtime permissions—that is,
/// devices that run Android 6.0 (API level 23) or higher—include the uses-permission-sdk-23
/// element instead of the uses-permission element.
pub android_permissions_sdk_23: Option<Vec<UsesPermissionSdk23>>,
/// Declares a single hardware or software android feature that is used by the application
pub android_features: Option<Vec<UsesFeature>>,

/// Apple build targets.
pub apple_build_targets: Option<Vec<AppleTarget>>,
/// Apple resources directory path relatively to project path.
pub apple_res: Option<PathBuf>,
/// Apple assets directory path relatively to project path.
pub apple_assets: Option<PathBuf>,

/// TODO: Add android android_uses_features.
#[serde(default)]
pub android_permissions: Vec<UsesPermission>,
}
13 changes: 8 additions & 5 deletions crossbundle/cli/src/commands/build/build_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl BuildContext {
pub fn gen_android_manifest(
&self,
sdk: &AndroidSdk,
package_name: &String,
package_name: &str,
debuggable: bool,
) -> Result<AndroidManifest> {
if self.metadata.use_android_manifest {
Expand All @@ -106,7 +106,7 @@ impl BuildContext {
.unwrap_or_else(|| self.project_path.join("AndroidManifest.xml"));
Ok(android::read_android_manifest(&path)?)
} else if !self.metadata.use_android_manifest {
let mut manifest = android::gen_minimal_android_manifest(
let manifest = android::gen_minimal_android_manifest(
self.metadata.android_package_name.clone(),
package_name,
self.metadata.app_name.clone(),
Expand All @@ -122,10 +122,10 @@ impl BuildContext {
self.metadata.max_sdk_version,
self.metadata.icon.clone(),
debuggable,
self.metadata.android_permissions_sdk_23.clone(),
self.metadata.android_permissions.clone(),
self.metadata.android_features.clone(),
);
if !self.metadata.android_permissions.is_empty() {
manifest.uses_permission = self.metadata.android_permissions.clone();
}
Ok(manifest)
} else {
let target_sdk_version = sdk.default_platform();
Expand All @@ -140,6 +140,9 @@ impl BuildContext {
None,
None,
debuggable,
None,
None,
None,
))
}
}
Expand Down
11 changes: 6 additions & 5 deletions crossbundle/tools/src/commands/android/gen_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ pub fn gen_minimal_android_manifest(
max_sdk_version: Option<u32>,
icon: Option<String>,
debuggable: bool,
permissions_sdk_23: Option<Vec<UsesPermissionSdk23>>,
permissions: Option<Vec<UsesPermission>>,
features: Option<Vec<UsesFeature>>,
) -> AndroidManifest {
AndroidManifest {
package: app_id.unwrap_or(format!("com.rust.{}", package_name.replace('-', "_"))),
Expand All @@ -23,11 +26,9 @@ pub fn gen_minimal_android_manifest(
target_sdk_version: Some(target_sdk_version),
max_sdk_version,
}),
uses_feature: vec![UsesFeature {
name: None,
gl_es_version: Some("0x00030002".to_string()),
required: Some(true),
}],
uses_permission_sdk_23: permissions_sdk_23.unwrap_or_default(),
uses_permission: permissions.unwrap_or_default(),
uses_feature: features.unwrap_or_default(),
application: Application {
has_code: Some(false),
label: Some(StringResourceOrString::string(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ pub fn gen_minimal_unsigned_aab(
None,
None,
false,
None,
None,
None,
);
let manifest_path = super::save_android_manifest(aab_build_dir, &android_manifest)?;
let apk_path = aab_build_dir.join(format!("{}_module.apk", package_name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ fn build_arg(start: &str, end: impl AsRef<std::ffi::OsStr>) -> std::ffi::OsStrin
new_arg
}

/// Replace cmd with new arguments
/// Replace cmd with new arguments. For more information see the [`Target Selection`]
///
/// [Target Selection]: https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md#target-selection
pub fn new_ndk_quad_args(
tool_root: std::path::PathBuf,
build_target: &AndroidTarget,
Expand Down
3 changes: 3 additions & 0 deletions crossbundle/tools/tests/aab_full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ fn test_aab_full() {
None,
None,
false,
None,
None,
None,
);
let manifest_path = android::save_android_manifest(&android_build_dir, &manifest).unwrap();
assert!(manifest_path.exists());
Expand Down
3 changes: 3 additions & 0 deletions crossbundle/tools/tests/aapt2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ fn test_aapt2_link() {
None,
None,
false,
None,
None,
None,
);

// Saves android manifest into temporary directory
Expand Down
3 changes: 3 additions & 0 deletions crossbundle/tools/tests/android_full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ fn test_android_full() {
None,
None,
true,
None,
None,
None,
);
let apk_build_dir = target_dir.join(&profile).join("apk");
let manifest_path = android::save_android_manifest(&apk_build_dir, &manifest).unwrap();
Expand Down
1 change: 1 addition & 0 deletions examples/bevy-explorer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ apple_res = "res/apple"

[[package.metadata.android_permissions]]
name = "android.permission.INTERNET"
max_sdk_version = 31
2 changes: 1 addition & 1 deletion plugins/permissions/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Crossbow Permissions

The main purpose of this plugin is to give cross-platform access to permissions.
The main purpose of this plugin is to give cross-platform access to permissions.