Skip to content

Commit 63ee0c6

Browse files
authored
Merge pull request #4 from enbop/android_support
Android support
2 parents b92764c + 2995d6e commit 63ee0c6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+869
-165
lines changed

Cargo.lock

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/config/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl FungiConfig {
9494
self.custom_hostname
9595
.as_ref()
9696
.cloned()
97-
.or(fungi_util::sysinfo::System::host_name())
97+
.or(fungi_util::get_hostname())
9898
}
9999

100100
pub fn set_custom_hostname(&self, hostname: Option<String>) -> Result<Self> {

crates/daemon/src/api.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@ use libp2p::PeerId;
88
use crate::FungiDaemon;
99

1010
impl FungiDaemon {
11-
pub fn host_name() -> Option<String> {
12-
fungi_util::sysinfo::System::host_name()
11+
pub fn host_name(&self) -> Option<String> {
12+
self.config().lock().get_hostname()
13+
}
14+
15+
#[cfg(target_os = "android")]
16+
pub fn init_mobile_device_name(name: String) {
17+
{
18+
fungi_util::init_mobile_device_name(name);
19+
}
1320
}
1421

1522
pub fn peer_id(&self) -> String {

crates/swarm/src/peer_handshake.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ impl Default for PeerHandshakePayload {
1414
impl PeerHandshakePayload {
1515
pub fn new() -> Self {
1616
Self {
17-
host_name: fungi_util::sysinfo::System::host_name(),
17+
// TODO: use [FungiConfig::get_hostname]
18+
host_name: fungi_util::get_hostname(),
1819
}
1920
}
2021

crates/util/src/lib.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ pub mod ipc;
22
pub mod keypair;
33
pub mod protocols;
44

5-
pub use sysinfo;
5+
#[cfg(target_os = "android")]
6+
mod mobile_device_info;
7+
#[cfg(target_os = "android")]
8+
pub use mobile_device_info::init_mobile_device_name;
9+
10+
use sysinfo;
611

712
pub fn get_local_ip() -> Option<String> {
813
if let Ok(socket) = std::net::UdpSocket::bind("0.0.0.0:0") {
@@ -14,3 +19,12 @@ pub fn get_local_ip() -> Option<String> {
1419
}
1520
None
1621
}
22+
23+
pub fn get_hostname() -> Option<String> {
24+
#[cfg(target_os = "android")]
25+
{
26+
return mobile_device_info::get_mobile_device_name();
27+
}
28+
#[cfg(not(target_os = "android"))]
29+
sysinfo::System::host_name()
30+
}

crates/util/src/mobile_device_info.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use std::sync::OnceLock;
2+
3+
static MOBILE_DEVICE_NAME: OnceLock<String> = OnceLock::new();
4+
5+
pub fn init_mobile_device_name(name: String) {
6+
if MOBILE_DEVICE_NAME.get().is_some() {
7+
log::warn!("Mobile device name has already been initialized.");
8+
return;
9+
}
10+
MOBILE_DEVICE_NAME.set(name).unwrap();
11+
}
12+
13+
pub fn get_mobile_device_name() -> Option<String> {
14+
MOBILE_DEVICE_NAME.get().cloned()
15+
}

flutter_app/android/app/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ plugins {
66
}
77

88
android {
9-
namespace = "com.enbop.fungi_app"
9+
namespace = "rs.fungi.fungi_app"
1010
compileSdk = flutter.compileSdkVersion
11-
ndkVersion = flutter.ndkVersion
11+
ndkVersion = "29.0.13846066"
1212

1313
compileOptions {
1414
sourceCompatibility = JavaVersion.VERSION_11
@@ -21,7 +21,7 @@ android {
2121

2222
defaultConfig {
2323
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
24-
applicationId = "com.enbop.fungi_app"
24+
applicationId = "rs.fungi.fungi_app"
2525
// You can update the following values to match your application needs.
2626
// For more information, see: https://flutter.dev/to/review-gradle-config.
2727
minSdk = flutter.minSdkVersion

flutter_app/android/app/src/main/AndroidManifest.xml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<!-- Network permissions for P2P networking -->
3+
<uses-permission android:name="android.permission.INTERNET" />
4+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
5+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
6+
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
7+
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
8+
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
9+
10+
<!-- Foreground service permissions -->
11+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
12+
<!-- foregroundServiceType: dataSync -->
13+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
14+
215
<application
3-
android:label="fungi_app"
16+
android:label="Fungi App"
417
android:name="${applicationName}"
518
android:icon="@mipmap/ic_launcher">
619
<activity
@@ -30,6 +43,17 @@
3043
<meta-data
3144
android:name="flutterEmbedding"
3245
android:value="2" />
46+
47+
<!-- Foreground service notification icon -->
48+
<meta-data
49+
android:name="logo_transparent_white"
50+
android:resource="@drawable/logo_transparent_white" />
51+
52+
<!-- Warning: Do not change service name. -->
53+
<service
54+
android:name="com.pravera.flutter_foreground_task.service.ForegroundService"
55+
android:foregroundServiceType="dataSync|remoteMessaging"
56+
android:exported="false" />
3357
</application>
3458
<!-- Required to query activities that can process text, see:
3559
https://developer.android.com/training/package-visibility and

flutter_app/android/app/src/main/kotlin/com/example/flutter_app/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.enbop.fungi_app
1+
package rs.fungi.fungi_app
22

33
import io.flutter.embedding.android.FlutterActivity
44

67.9 KB
Loading

0 commit comments

Comments
 (0)