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

(android) Split app into variants #620

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
16 changes: 13 additions & 3 deletions phoenix-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ android {
}
}

flavorDimensions += "main"
productFlavors {
create("google") {
versionNameSuffix = "-google"
}
create("foss") {
versionNameSuffix = "-foss"
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Expand Down Expand Up @@ -134,9 +144,9 @@ dependencies {
implementation("org.slf4j:slf4j-api:${Versions.slf4j}")
implementation("com.github.tony19:logback-android:${Versions.Android.logback}")

// firebase cloud messaging
implementation("com.google.firebase:firebase-messaging:${Versions.Android.fcm}")
implementation("com.google.android.gms:play-services-base:18.5.0")
// firebase cloud messaging -- only for the google flavor
"googleImplementation"("com.google.firebase:firebase-messaging:${Versions.Android.fcm}")
"googleImplementation"("com.google.android.gms:play-services-base:18.5.0")

implementation("com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava")

Expand Down
73 changes: 73 additions & 0 deletions phoenix-android/src/foss/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2024 ACINQ SAS
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.FOREGROUND_SERVICE_REMOTE_MESSAGING" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<application
android:name=".PhoenixApplicationFoss">

<activity
android:name=".MainActivityFoss"
android:exported="true"
android:launchMode="singleTask"
android:theme="@style/Theme.PhoenixAndroid.NoActionBar"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- support for lightning/bitcoin/lnurl schemes -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />

<!-- bitcoin & lightning schemes -->
<data android:scheme="bitcoin" />
<data android:scheme="lightning" />
<!-- lnurl schemes -->
<data android:scheme="lnurl" />
<data android:scheme="lnurlw" />
<data android:scheme="lnurlp" />
<data android:scheme="keyauth" />
<!-- phoenix specific scheme, for apps who specifically want to open phoenix -->
<data android:scheme="phoenix" />
</intent-filter>
</activity>

<!-- node service -->
<service
android:name="fr.acinq.phoenix.android.services.NodeServiceFoss"
android:foregroundServiceType="shortService|remoteMessaging"
android:exported="false"
android:stopWithTask="false" />

<!-- broadcast receivers -->
<receiver
android:name="fr.acinq.phoenix.android.services.BootReceiverFoss"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2024 ACINQ SAS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package fr.acinq.phoenix.android

import android.content.Context
import android.content.Intent
import fr.acinq.phoenix.android.services.HeadlessActions
import fr.acinq.phoenix.android.services.NodeService
import fr.acinq.phoenix.android.services.NodeServiceFoss

class MainActivityFoss : MainActivity() {

override fun bindService() {
Intent(this, NodeServiceFoss::class.java).let { intent ->
applicationContext.bindService(intent, appViewModel.serviceConnection, Context.BIND_AUTO_CREATE or Context.BIND_ADJUST_WITH_ACTIVITY)
}
}

fun headlessServiceAction(action: HeadlessActions) {
val intent = Intent(applicationContext, NodeServiceFoss::class.java).apply {
this.action = action.name
putExtra(NodeService.EXTRA_ORIGIN, NodeService.ORIGIN_HEADLESS)
}
applicationContext.startForegroundService(intent)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2020 ACINQ SAS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package fr.acinq.phoenix.android

import android.content.Intent
import fr.acinq.phoenix.android.services.NodeService
import fr.acinq.phoenix.android.services.NodeServiceFoss


class PhoenixApplicationFoss : PhoenixApplication() {

override val mainActivityClass: Class<out MainActivity> get() = MainActivityFoss::class.java
override val nodeServiceClass: Class<out NodeService> get() = NodeServiceFoss::class.java

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright 2024 ACINQ SAS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package fr.acinq.phoenix.android.home

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import fr.acinq.phoenix.android.AppViewModel
import fr.acinq.phoenix.android.R
import fr.acinq.phoenix.android.Screen
import fr.acinq.phoenix.android.components.Clickable
import fr.acinq.phoenix.android.components.Dialog
import fr.acinq.phoenix.android.components.TextWithIcon
import fr.acinq.phoenix.android.navController
import fr.acinq.phoenix.android.utils.warningColor

@Composable
fun BackgroundRestrictionBadge(
appViewModel: AppViewModel,
isPowerSaverMode: Boolean,
isTorEnabled: Boolean,
) {
val isHeadlessModeEnabled = appViewModel.service?.isHeadless == true

if (isTorEnabled || isPowerSaverMode || !isHeadlessModeEnabled) {
var showDialog by remember { mutableStateOf(false) }

TopBadgeButton(
text = null,
icon = R.drawable.ic_alert_triangle,
iconTint = warningColor,
onClick = { showDialog = true },
)
Spacer(modifier = Modifier.width(4.dp))

if (showDialog) {
Dialog(
onDismiss = { showDialog = false },
title = stringResource(id = R.string.home_background_restriction_title)
) {
Text(
text = stringResource(id = R.string.home_background_restriction_body_1),
modifier = Modifier.padding(horizontal = 24.dp),
)
Spacer(modifier = Modifier.height(16.dp))

if (isTorEnabled) {
TextWithIcon(
text = stringResource(id = R.string.home_background_restriction_tor),
textStyle = MaterialTheme.typography.body2,
icon = R.drawable.ic_tor_shield_ok,
modifier = Modifier.padding(horizontal = 24.dp, vertical = 6.dp),
)
}

if (isPowerSaverMode) {
TextWithIcon(
text = stringResource(id = R.string.home_background_restriction_powersaver),
textStyle = MaterialTheme.typography.body2,
icon = R.drawable.ic_battery_charging,
modifier = Modifier.padding(horizontal = 24.dp, vertical = 6.dp)
)
}

if (!isHeadlessModeEnabled) {
val nc = navController
Clickable(onClick = { nc.navigate(Screen.Experimental.route) }) {
Column(modifier = Modifier.padding(horizontal = 24.dp, vertical = 6.dp)) {
TextWithIcon(
text = stringResource(id = R.string.home_background_restriction_headless),
textStyle = MaterialTheme.typography.body2,
icon = R.drawable.ic_phone_tech,
)
Spacer(modifier = Modifier.height(4.dp))
Text(
text = stringResource(id = R.string.home_background_restriction_headless_desc),
style = MaterialTheme.typography.subtitle2,
modifier = Modifier.padding(start = 24.dp),
)
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2019 ACINQ SAS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package fr.acinq.phoenix.android.services

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import fr.acinq.phoenix.android.PhoenixApplication
import fr.acinq.phoenix.legacy.internalData
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import org.slf4j.LoggerFactory

/**
* This receiver is started when the device has booted, and schedules background jobs.
*/
class BootReceiverFoss : BroadcastReceiver() {

private val log = LoggerFactory.getLogger(this::class.java)

override fun onReceive(context: Context, intent: Intent) {
if (Intent.ACTION_BOOT_COMPLETED == intent.action) {
ChannelsWatcher.schedule(context)
InflightPaymentsWatcher.scheduleOnce(context)

val internalPrefs = (context as? PhoenixApplication)?.internalDataRepository
val scope = CoroutineScope(Dispatchers.Main.immediate + SupervisorJob())
scope.launch {
internalPrefs?.getBackgroundServiceMode?.first()?.let { (isEnabled, isWakelock) ->
if (isEnabled) {
val action = if (isWakelock) HeadlessActions.Start.WithWakeLock else HeadlessActions.Start.NoWakeLock
log.info("starting foreground service with action=$action")
Intent(context, NodeServiceFoss::class.java).apply {
this.action = action.name
putExtra(NodeService.EXTRA_ORIGIN, NodeService.ORIGIN_HEADLESS)
}
context.startForegroundService(intent)
}
}
}
}
}
}
Loading