Skip to content

Commit

Permalink
Merge pull request #2950 from HenrikJannsen/refactor-for-android-support
Browse files Browse the repository at this point in the history
Refactor for android support
  • Loading branch information
HenrikJannsen authored Oct 24, 2024
2 parents 6cd71ad + 77c6cb1 commit 61f8d4b
Show file tree
Hide file tree
Showing 217 changed files with 1,569 additions and 696 deletions.
1 change: 0 additions & 1 deletion application/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ dependencies {
implementation("network:network")

implementation(libs.typesafe.config)
implementation(libs.bouncycastle.pg)
}
24 changes: 6 additions & 18 deletions application/src/main/java/bisq/application/ApplicationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package bisq.application;

import bisq.application.migration.MigrationService;
import bisq.common.application.ApplicationVersion;
import bisq.common.application.DevMode;
import bisq.common.application.OptionUtils;
Expand All @@ -29,8 +28,6 @@
import bisq.common.locale.LocaleRepository;
import bisq.common.logging.AsciiLogo;
import bisq.common.logging.LogSetup;
import bisq.common.platform.MemoryReport;
import bisq.common.platform.PlatformUtils;
import bisq.common.util.ExceptionUtil;
import bisq.i18n.Res;
import bisq.persistence.PersistenceService;
Expand Down Expand Up @@ -74,11 +71,11 @@ private static String resolveAppName(String[] args, com.typesafe.config.Config c
@ToString
@EqualsAndHashCode
public static final class Config {
private static Config from(com.typesafe.config.Config config, String[] args) {
private static Config from(com.typesafe.config.Config config, String[] args, Path userDataDir) {
String appName = resolveAppName(args, config);
Path appDataDir = OptionUtils.findOptionValue(args, "--data-dir")
.map(Path::of)
.orElse(PlatformUtils.getUserDataDir().resolve(appName));
.orElse(userDataDir.resolve(appName));
return new Config(appDataDir,
appName,
config.getBoolean("devMode"),
Expand Down Expand Up @@ -125,19 +122,16 @@ public Config(Path baseDir,
protected final Config config;
@Getter
protected final PersistenceService persistenceService;
private final MigrationService migrationService;
@SuppressWarnings("FieldCanBeLocal") // Pin it so that it does not get GC'ed
private final MemoryReport memoryReport;
private FileLock instanceLock;

public ApplicationService(String configFileName, String[] args) {
public ApplicationService(String configFileName, String[] args, Path userDataDir) {
com.typesafe.config.Config defaultTypesafeConfig = ConfigFactory.load(configFileName);
defaultTypesafeConfig.checkValid(ConfigFactory.defaultReference(), configFileName);

String appName = resolveAppName(args, defaultTypesafeConfig.getConfig("application"));
Path appDataDir = OptionUtils.findOptionValue(args, "--data-dir")
.map(Path::of)
.orElse(PlatformUtils.getUserDataDir().resolve(appName));
.orElse(userDataDir.resolve(appName));
File customConfigFile = Path.of(appDataDir.toString(), "bisq.conf").toFile();
com.typesafe.config.Config typesafeConfig;
boolean customConfigProvided = customConfigFile.exists();
Expand All @@ -153,7 +147,7 @@ public ApplicationService(String configFileName, String[] args) {
}

typesafeAppConfig = typesafeConfig.getConfig("application");
config = Config.from(typesafeAppConfig, args);
config = Config.from(typesafeAppConfig, args, userDataDir);

Path dataDir = config.getBaseDir();
try {
Expand All @@ -173,9 +167,6 @@ public ApplicationService(String configFileName, String[] args) {
log.info("Using custom config file");
}

memoryReport = MemoryReport.getINSTANCE();
memoryReport.printPeriodically(config.getMemoryReportIntervalSec(), config.isIncludeThreadListInMemoryReport());

DevMode.setDevMode(config.isDevMode());

Locale locale = LocaleRepository.getDefaultLocale();
Expand All @@ -187,7 +178,6 @@ public ApplicationService(String configFileName, String[] args) {

String absoluteDataDirPath = dataDir.toAbsolutePath().toString();
persistenceService = new PersistenceService(absoluteDataDirPath);
migrationService = new MigrationService(dataDir);
}

private void checkInstanceLock() {
Expand All @@ -214,9 +204,7 @@ public CompletableFuture<Boolean> readAllPersisted() {
return persistenceService.readAllPersisted();
}

public CompletableFuture<Boolean> initialize() {
return migrationService.runMigrations();
}
public abstract CompletableFuture<Boolean> initialize();

public abstract CompletableFuture<Boolean> shutdown();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.desktop;
package bisq.application;

public enum State {
INITIALIZE_APP,
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop/desktop-app-launcher/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ javafx {
dependencies {
implementation("bisq:common")
implementation("bisq:security")
implementation("bisq:java-se")
implementation("bisq:application")
implementation("bisq:evolution")

implementation(project(":desktop-app"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import bisq.common.threading.ThreadName;
import bisq.common.util.ExceptionUtil;
import bisq.desktop_app.DesktopApp;
import bisq.updater.DownloadedFilesVerification;
import bisq.updater.UpdaterUtils;
import bisq.evolution.updater.DownloadedFilesVerification;
import bisq.evolution.updater.UpdaterUtils;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
Expand All @@ -38,7 +38,7 @@
import java.util.List;
import java.util.Optional;

import static bisq.updater.UpdaterUtils.*;
import static bisq.evolution.updater.UpdaterUtils.*;

/**
* We ship the binary with the current version of the DesktopApp and with the JRE.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package bisq.desktop_app_launcher;

import bisq.common.jvm.JvmUtils;
import bisq.java_se.utils.JvmUtils;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

Expand Down
3 changes: 3 additions & 0 deletions apps/desktop/desktop-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ javafx {

dependencies {
implementation("bisq:persistence")
implementation("bisq:java-se")
implementation("bisq:i18n")
implementation("bisq:security")
implementation("bisq:identity")
Expand All @@ -50,6 +51,8 @@ dependencies {
implementation("bisq:presentation")
implementation("bisq:bisq-easy")
implementation("bisq:application")
implementation("bisq:evolution")
implementation("bisq:os-specific")

implementation(project(":desktop"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,37 @@
package bisq.desktop_app;

import bisq.account.AccountService;
import bisq.application.ApplicationService;
import bisq.application.ShutDownHandler;
import bisq.application.State;
import bisq.bisq_easy.BisqEasyService;
import bisq.bonded_roles.BondedRolesService;
import bisq.bonded_roles.security_manager.alert.AlertNotificationsService;
import bisq.chat.ChatService;
import bisq.common.application.Service;
import bisq.common.observable.Observable;
import bisq.common.platform.OS;
import bisq.common.util.CompletableFutureUtils;
import bisq.common.util.ExceptionUtil;
import bisq.contract.ContractService;
import bisq.desktop.ServiceProvider;
import bisq.desktop.State;
import bisq.desktop.webcam.WebcamAppService;
import bisq.evolution.updater.UpdaterService;
import bisq.identity.IdentityService;
import bisq.java_se.application.JavaSeApplicationService;
import bisq.network.NetworkService;
import bisq.network.NetworkServiceConfig;
import bisq.offer.OfferService;
import bisq.os_specific.notifications.linux.LinuxNotificationService;
import bisq.os_specific.notifications.osx.OsxNotificationService;
import bisq.os_specific.notifications.other.AwtNotificationService;
import bisq.presentation.notifications.OsSpecificNotificationService;
import bisq.presentation.notifications.SystemNotificationService;
import bisq.security.SecurityService;
import bisq.settings.DontShowAgainService;
import bisq.settings.FavouriteMarketsService;
import bisq.settings.SettingsService;
import bisq.support.SupportService;
import bisq.trade.TradeService;
import bisq.updater.UpdaterService;
import bisq.user.UserService;
import bisq.wallets.core.BitcoinWalletSelection;
import bisq.wallets.core.WalletService;
Expand All @@ -65,7 +70,7 @@
*/

@Slf4j
public class DesktopApplicationService extends ApplicationService {
public class DesktopApplicationService extends JavaSeApplicationService {
public static final long STARTUP_TIMEOUT_SEC = 300;
public static final long SHUTDOWN_TIMEOUT_SEC = 10;

Expand Down Expand Up @@ -103,6 +108,7 @@ public DesktopApplicationService(String[] args, ShutDownHandler shutDownHandler)
super("desktop", args);

securityService = new SecurityService(persistenceService, SecurityService.Config.from(getConfig("security")));

com.typesafe.config.Config bitcoinWalletConfig = getConfig("bitcoinWallet");
BitcoinWalletSelection bitcoinWalletSelection = bitcoinWalletConfig.getEnum(BitcoinWalletSelection.class, "bitcoinWalletSelection");
//noinspection SwitchStatementWithTooFewBranches
Expand All @@ -124,7 +130,8 @@ public DesktopApplicationService(String[] args, ShutDownHandler shutDownHandler)
persistenceService,
securityService.getKeyBundleService(),
securityService.getHashCashProofOfWorkService(),
securityService.getEquihashProofOfWorkService());
securityService.getEquihashProofOfWorkService(),
memoryReportService);

identityService = new IdentityService(persistenceService,
securityService.getKeyBundleService(),
Expand All @@ -146,7 +153,7 @@ public DesktopApplicationService(String[] args, ShutDownHandler shutDownHandler)

settingsService = new SettingsService(persistenceService);

systemNotificationService = new SystemNotificationService(config.getBaseDir(), settingsService);
systemNotificationService = new SystemNotificationService(findSystemNotificationDelegate());

offerService = new OfferService(networkService, identityService, persistenceService);

Expand All @@ -170,7 +177,6 @@ public DesktopApplicationService(String[] args, ShutDownHandler shutDownHandler)

bisqEasyService = new BisqEasyService(persistenceService,
securityService,
walletService,
networkService,
identityService,
bondedRolesService,
Expand Down Expand Up @@ -217,9 +223,29 @@ public DesktopApplicationService(String[] args, ShutDownHandler shutDownHandler)
webcamAppService);
}

private Optional<OsSpecificNotificationService> findSystemNotificationDelegate() {
try {
switch (OS.getOS()) {
case LINUX:
return Optional.of(new LinuxNotificationService(config.getBaseDir(), settingsService));
case MAC_OS:
return Optional.of(new OsxNotificationService());
case WINDOWS:
return Optional.of(new AwtNotificationService());
default:
case ANDROID:
return Optional.empty();
}
} catch (Exception e) {
log.warn("Could not create SystemNotificationDelegate for {}", OS.getOsName());
return Optional.empty();
}
}

@Override
public CompletableFuture<Boolean> initialize() {
return super.initialize()
return migrationService.initialize()
.thenCompose(result -> memoryReportService.initialize())
.thenCompose(result -> securityService.initialize())
.thenCompose(result -> {
setState(State.INITIALIZE_NETWORK);
Expand Down Expand Up @@ -311,6 +337,8 @@ public CompletableFuture<Boolean> shutdown() {
.thenCompose(result -> walletService.map(service -> service.shutdown().exceptionally(this::logError))
.orElse(CompletableFuture.completedFuture(true)))
.thenCompose(result -> securityService.shutdown().exceptionally(this::logError))
.thenCompose(result -> memoryReportService.shutdown().exceptionally(this::logError))
.thenCompose(result -> migrationService.shutdown().exceptionally(this::logError))
.orTimeout(SHUTDOWN_TIMEOUT_SEC, TimeUnit.SECONDS)
.handle((result, throwable) -> {
if (throwable == null) {
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/desktop-app/src/main/resources/desktop.conf
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ application {
devModeDelayInMs = 300
sendMessageThrottleTime = 200
receiveMessageThrottleTime = 200
connectTimeoutMs = 3000
}
tor {
bootstrapTimeout = 240
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/desktop/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ dependencies {
implementation("bisq:presentation")
implementation("bisq:bisq-easy")
implementation("bisq:application")
implementation("bisq:evolution")

implementation("network:network-common")
implementation("network:network")
implementation("network:network-identity")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package bisq.desktop;

import bisq.application.State;
import bisq.bisq_easy.NavigationTarget;
import bisq.chat.notifications.ChatNotificationService;
import bisq.common.observable.Observable;
Expand All @@ -29,6 +30,7 @@
import bisq.desktop.common.view.Navigation;
import bisq.desktop.common.view.NavigationController;
import bisq.desktop.components.cathash.CatHash;
import bisq.desktop.components.cathash.JavaFxCatHashService;
import bisq.desktop.components.overlay.Overlay;
import bisq.desktop.components.overlay.Popup;
import bisq.desktop.main.MainController;
Expand Down Expand Up @@ -115,7 +117,8 @@ public void init() {
Browser.initialize(applicationJavaFxApplicationData.getHostServices(), settingsService, dontShowAgainService);
Transitions.setSettingsService(settingsService);
AnchorPane viewRoot = view.getRoot();
CatHash.setBaseDir(serviceProvider.getConfig().getBaseDir());

CatHash.setDelegate(new JavaFxCatHashService(serviceProvider.getConfig().getBaseDir()));

Navigation.init(settingsService);
Overlay.init(serviceProvider, viewRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import bisq.settings.SettingsService;
import bisq.support.SupportService;
import bisq.trade.TradeService;
import bisq.updater.UpdaterService;
import bisq.evolution.updater.UpdaterService;
import bisq.user.UserService;
import bisq.wallets.core.WalletService;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public PreventStandbyModeService(ServiceProvider serviceProvider) {
}

public void initialize() {
if(OS.isAndroid()){
return;
}
settingsService.getPreventStandbyMode().addObserver(preventStandbyMode -> {
if (preventStandbyMode) {
this.preventStandbyMode.initialize();
Expand Down
Loading

0 comments on commit 61f8d4b

Please sign in to comment.