diff --git a/bin/app/Cargo.toml b/bin/app/Cargo.toml index 5d3c73a62..5f276a32c 100644 --- a/bin/app/Cargo.toml +++ b/bin/app/Cargo.toml @@ -113,3 +113,12 @@ assets = "assets" name = "android.permission.INTERNET" [[package.metadata.android.permission]] name = "android.permission.ACCESS_NETWORK_STATE" +[[package.metadata.android.permission]] +name = "android.permission.FOREGROUND_SERVICE" +[[package.metadata.android.permission]] +name = "android.permission.FOREGROUND_SERVICE_REMOTE_MESSAGING" + +[[package.metadata.android.service]] +name = ".ForegroundService" +foreground_service_type = "remoteMessaging" +exported = false diff --git a/bin/app/Dockerfile b/bin/app/Dockerfile index 1bcd48231..35465a8ae 100644 --- a/bin/app/Dockerfile +++ b/bin/app/Dockerfile @@ -1,7 +1,7 @@ FROM docker.io/archlinux RUN pacman -Syu --noconfirm -RUN pacman -S --noconfirm jdk8-openjdk unzip wget cmake openssl pkgconf gcc git +RUN pacman -S --noconfirm jdk17-openjdk unzip wget cmake openssl pkgconf gcc git zip # github override HOME, so here we are ENV RUSTUP_HOME=/usr/local/rustup \ @@ -23,14 +23,17 @@ ENV ANDROID_HOME /opt/android-sdk-linux ENV JAVA_HOME /usr/lib/jvm/default RUN mkdir ${ANDROID_HOME} && \ cd ${ANDROID_HOME} && \ - wget -q https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip && \ - unzip -q sdk-tools-linux-4333796.zip && \ - rm sdk-tools-linux-4333796.zip && \ + wget -q https://dl.google.com/android/repository/commandlinetools-linux-13114758_latest.zip && \ + unzip -q commandlinetools-linux-13114758_latest.zip && \ + rm commandlinetools-linux-13114758_latest.zip && \ + mv cmdline-tools latest && \ + mkdir cmdline-tools/ && \ + mv latest cmdline-tools/ && \ chown -R root:root /opt RUN mkdir -p ~/.android && touch ~/.android/repositories.cfg -RUN yes | ${ANDROID_HOME}/tools/bin/sdkmanager "platform-tools" | grep -v = || true -RUN yes | ${ANDROID_HOME}/tools/bin/sdkmanager "platforms;android-31" | grep -v = || true -RUN yes | ${ANDROID_HOME}/tools/bin/sdkmanager "build-tools;31.0.0" | grep -v = || true +RUN yes | ${ANDROID_HOME}/cmdline-tools/latest/bin/sdkmanager "platform-tools" | grep -v = || true +RUN yes | ${ANDROID_HOME}/cmdline-tools/latest/bin/sdkmanager "platforms;android-36" | grep -v = || true +RUN yes | ${ANDROID_HOME}/cmdline-tools/latest/bin/sdkmanager "build-tools;36.0.0-rc5" | grep -v = || true RUN ${ANDROID_HOME}/tools/bin/sdkmanager --update | grep -v = || true # Install Android NDK @@ -42,15 +45,16 @@ ENV NDK_HOME /usr/local/android-ndk-r25 # Copy contents to container. Should only use this on a clean directory WORKDIR /root/ -RUN git clone https://github.com/not-fl3/cargo-quad-apk cargo-apk +RUN git clone https://github.com/narodnik/cargo-quad-apk cargo-apk +#RUN git clone https://github.com/not-fl3/cargo-quad-apk cargo-apk # For deterministic builds, we want a deterministic toolchain -RUN cd /root/cargo-apk && git checkout f3b865610b79a2b1b9d2b90600c36390a9e19569 +#RUN cd /root/cargo-apk && git checkout f3b865610b79a2b1b9d2b90600c36390a9e19569 # Install binary RUN cargo install --path /root/cargo-apk # Add build-tools to PATH, for apksigner -ENV PATH="/opt/android-sdk-linux/build-tools/31.0.0/:${PATH}" +ENV PATH="/opt/android-sdk-linux/build-tools/36.0.0-rc5/:${PATH}" # Lets cache packages for faster builds RUN git clone --depth=1 https://codeberg.org/darkrenaissance/darkfi diff --git a/bin/app/Makefile b/bin/app/Makefile index 50cd9f75c..35a282784 100644 --- a/bin/app/Makefile +++ b/bin/app/Makefile @@ -88,7 +88,7 @@ install-apk: # Useful for dev cli: - podman run -v $(shell pwd)/../../:/root/darkfi -w /root/darkfi/bin/app/ -it apk bash + podman run -v /home/narodnik/src/stuff/cargo-quad-apk:/root/capk -v $(shell pwd)/../../:/root/darkfi -w /root/darkfi/bin/app/ -it apk bash fmt: $(CARGO) +nightly fmt diff --git a/bin/app/java/ForegroundService.java b/bin/app/java/ForegroundService.java new file mode 100644 index 000000000..76eeafd59 --- /dev/null +++ b/bin/app/java/ForegroundService.java @@ -0,0 +1,76 @@ +/* This file is part of DarkFi (https://dark.fi) + * + * Copyright (C) 2020-2025 Dyne.org foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package TARGET_PACKAGE_NAME; + +import android.app.Service; +import android.content.pm.ServiceInfo; +import android.app.Notification; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.content.Intent; +import android.os.Build; +import android.os.IBinder; +import android.util.Log; + +public class ForegroundService extends Service { + + @Override + public void onCreate() { + super.onCreate(); + createNotificationChannel(); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + //Log.d("darkfi", "ForegroundService::onStartCommand()"); + Notification.Builder builder = + new Notification.Builder(this, "darkfi_service"); + + Notification notification = builder + .setContentTitle("DarkFi") + .setContentText("Running p2p network...") + .setSmallIcon(android.R.drawable.ic_dialog_info) + .build(); + + startForeground( + 100, + notification, + ServiceInfo.FOREGROUND_SERVICE_TYPE_REMOTE_MESSAGING + ); + + return START_STICKY; + } + + @Override + public IBinder onBind(Intent intent) { + return null; + } + + private void createNotificationChannel() { + //Log.d("darkfi", "ForegroundService::createNotificationChannel()"); + NotificationChannel channel = new NotificationChannel( + "darkfi_service", + "DarkFi Foreground Service", + NotificationManager.IMPORTANCE_DEFAULT + ); + NotificationManager manager = getSystemService(NotificationManager.class); + manager.createNotificationChannel(channel); + } +} + diff --git a/bin/app/java/MainActivity.java b/bin/app/java/MainActivity.java index 076a4cab5..ca0e1414b 100644 --- a/bin/app/java/MainActivity.java +++ b/bin/app/java/MainActivity.java @@ -169,5 +169,9 @@ view.setFocusable(false); view.setFocusableInTouchMode(false); view.clearFocus(); +// Start a foreground service so the app stays awake +Intent serviceIntent = new Intent(this, ForegroundService.class); +startForegroundService(serviceIntent); + //% END diff --git a/bin/app/quad.toml b/bin/app/quad.toml index d610ff5ac..eb1dbc51b 100644 --- a/bin/app/quad.toml +++ b/bin/app/quad.toml @@ -3,5 +3,6 @@ java_files = [ "java/autosuggest/CustomInputConnection.java", "java/autosuggest/InvisibleInputView.java", #"java/autosuggest/InvisibleInputManager.java", + "java/ForegroundService.java", ]