diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index d735f8d5..cc427c14 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -18,7 +18,7 @@ jobs:
name: Build aw-server-rust
runs-on: ubicloud-standard-8
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Set RELEASE
@@ -26,7 +26,7 @@ jobs:
echo "RELEASE=${{ startsWith(github.ref_name, 'v') }}" >> $GITHUB_ENV
- name: Cache JNI libs
- uses: actions/cache@v3
+ uses: actions/cache@v4
id: cache-jniLibs
env:
cache-name: jniLibs
@@ -42,7 +42,7 @@ jobs:
# Android SDK & NDK
- name: Set up Android SDK
if: steps.cache-jniLibs.outputs.cache-hit != 'true'
- uses: android-actions/setup-android@v2
+ uses: android-actions/setup-android@v3
- name: Set up Android NDK
if: steps.cache-jniLibs.outputs.cache-hit != 'true'
run: |
@@ -63,7 +63,7 @@ jobs:
./aw-server-rust/install-ndk.sh
- name: Cache cargo build
- uses: actions/cache@v3
+ uses: actions/cache@v4
if: steps.cache-jniLibs.outputs.cache-hit != 'true'
env:
cache-name: cargo-build-target
@@ -83,6 +83,12 @@ jobs:
run: |
test -e mobile/src/main/jniLibs/x86_64/libaw_server.so
+ - name: Upload jniLibs artifact
+ uses: actions/upload-artifact@v4
+ with:
+ name: jniLibs
+ path: mobile/src/main/jniLibs/
+
# This needs to be a seperate job since fastlane update_version,
# fails if run concurrently (such as in build apk/aab matrix),
# thus we need to run it once and and reuse the results.
@@ -94,7 +100,7 @@ jobs:
versionCode: ${{ steps.versionCode.outputs.versionCode }}
steps:
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v4
with:
submodules: 'recursive'
@@ -121,7 +127,7 @@ jobs:
# Retry this, in case there are concurrent jobs, which may lead to the error:
# "Google Api Error: Invalid request - This Edit has been deleted."
- name: Update versionCode
- uses: Wandalen/wretry.action@master
+ uses: Wandalen/wretry.action@v3
with:
command: bundle exec fastlane update_version
attempt_limit: 3
@@ -142,7 +148,7 @@ jobs:
type: ['apk', 'aab']
steps:
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v4
with:
submodules: 'recursive'
@@ -161,13 +167,14 @@ jobs:
echo "RELEASE=${{ startsWith(github.ref_name, 'v') }}" >> $GITHUB_ENV
- name: Set up JDK
- uses: actions/setup-java@v1
+ uses: actions/setup-java@v4
with:
+ distribution: 'temurin'
java-version: ${{ env.JAVA_VERSION }}
# Android SDK & NDK
- name: Set up Android SDK
- uses: android-actions/setup-android@v2
+ uses: android-actions/setup-android@v3
- name: Set up Android NDK
run: |
sdkmanager "ndk;${{ env.NDK_VERSION }}"
@@ -177,14 +184,14 @@ jobs:
# Restores jniLibs from cache
# `actions/cache/restore` only restores, without saving back in a post-hook
- - uses: actions/cache/restore@v3
+ - uses: actions/cache/restore@v4
id: cache-jniLibs
env:
cache-name: jniLibs
with:
path: mobile/src/main/jniLibs/
key: ${{ env.cache-name }}-release-${{ env.RELEASE }}-ndk-${{ env.NDK_VERSION }}-${{ hashFiles('.git/modules/aw-server-rust/HEAD') }}
- fail-on-cache-miss: true
+ fail-on-cache-miss: false
- name: Check that jniLibs present
run: |
@@ -222,20 +229,20 @@ jobs:
make dist/aw-android.${{ matrix.type }}
- name: Upload
- uses: actions/upload-artifact@v3
+ uses: actions/upload-artifact@v4
with:
name: aw-android
path: dist/aw-android*.${{ matrix.type }}
test:
name: Test
- runs-on: ubuntu-20.04
+ runs-on: ubuntu-24.04
needs: [build-rust]
env:
SUPPLY_TRACK: production # used by fastlane to determine track to publish to
steps:
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v4
with:
submodules: 'recursive'
@@ -244,13 +251,14 @@ jobs:
echo "RELEASE=${{ startsWith(github.ref_name, 'v') }}" >> $GITHUB_ENV
- name: Set up JDK
- uses: actions/setup-java@v1
+ uses: actions/setup-java@v4
with:
+ distribution: 'temurin'
java-version: ${{ env.JAVA_VERSION }}
# Android SDK & NDK
- name: Set up Android SDK
- uses: android-actions/setup-android@v2
+ uses: android-actions/setup-android@v3
- name: Set up Android NDK
run: |
sdkmanager "ndk;${{ env.NDK_VERSION }}"
@@ -261,20 +269,22 @@ jobs:
# Restores jniLibs from cache
# `actions/cache/restore` only restores, without saving back in a post-hook
- - uses: actions/cache/restore@v3
+ - uses: actions/cache/restore@v4
id: cache-jniLibs
env:
cache-name: jniLibs
with:
path: mobile/src/main/jniLibs/
key: ${{ env.cache-name }}-release-${{ env.RELEASE }}-ndk-${{ env.NDK_VERSION }}-${{ hashFiles('.git/modules/aw-server-rust/HEAD') }}
- fail-on-cache-miss: true
+ fail-on-cache-miss: false
- name: Check that jniLibs present
+ if: steps.cache-jniLibs.outputs.cache-hit == 'true'
run: |
test -e mobile/src/main/jniLibs/x86_64/libaw_server.so
# Test
- name: Test
+ if: steps.cache-jniLibs.outputs.cache-hit == 'true'
run: |
make test
@@ -286,22 +296,14 @@ jobs:
#runs-on: "macos-12" # macOS-latest
runs-on: ubicloud-standard-8
env:
- MATRIX_E_SDK: ${{ matrix.android_emu_version }}
- MATRIX_AVD: ${{ matrix.android_avd }}
+ MATRIX_E_SDK: ${{ matrix.api-level }}
strategy:
fail-fast: false
- max-parallel: 1
matrix:
- android_avd: [Pixel_API_27_AOSP]
- include:
- - android_avd: Pixel_API_27_AOSP
- android_emu_version: 27
- # # # Cannot run > 27-emuLevel -_- https://github.com/actions/runner-images/issues/6527
- # - android_avd: Pixel_API_32_AOSP
- # android_emu_version: 32
+ api-level: [29]
steps:
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v4
with:
submodules: 'recursive'
@@ -309,177 +311,56 @@ jobs:
run: |
echo "RELEASE=${{ startsWith(github.ref_name, 'v') }}" >> $GITHUB_ENV
- # Restores jniLibs from cache
- # `actions/cache/restore` only restores, without saving back in a post-hook
- - uses: actions/cache/restore@v3
- id: cache-jniLibs
- env:
- cache-name: jniLibs
+ - name: Download jniLibs artifact
+ uses: actions/download-artifact@v4
with:
+ name: jniLibs
path: mobile/src/main/jniLibs/
- key: ${{ env.cache-name }}-release-${{ env.RELEASE }}-ndk-${{ env.NDK_VERSION }}-${{ hashFiles('.git/modules/aw-server-rust/HEAD') }}
- fail-on-cache-miss: true
- name: Display structure of downloaded files
run: |
pushd mobile/src/main/jniLibs && ls -R && popd
- - name: Install intel-haxm
- if: runner.os == 'macOS'
- run: brew install intel-haxm
-
- # # # Below code is majorly from https://github.com/actions/runner-images/issues/6152#issuecomment-1243718140
- - name: Create Android emulator
- run: |
- # Install AVD files
- echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;android-'$MATRIX_E_SDK';default;x86_64'
- echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --licenses
-
- # Create emulator
- $ANDROID_HOME/tools/bin/avdmanager create avd -n $MATRIX_AVD -d pixel --package 'system-images;android-'$MATRIX_E_SDK';default;x86_64'
- $ANDROID_HOME/emulator/emulator -list-avds
- if false; then
- emulator_config=~/.android/avd/$MATRIX_AVD.avd/config.ini
- # The following madness is to support empty OR populated config.ini files,
- # the state of which is dependant on the version of the emulator used (which we don't control),
- # so let's be defensive to be safe.
- # Replace existing config (NOTE we're on MacOS so sed works differently!)
- sed -i .bak 's/hw.lcd.density=.*/hw.lcd.density=420/' "$emulator_config"
- sed -i .bak 's/hw.lcd.height=.*/hw.lcd.height=1920/' "$emulator_config"
- sed -i .bak 's/hw.lcd.width=.*/hw.lcd.width=1080/' "$emulator_config"
- # Or, add new config
- if ! grep -q "hw.lcd.density" "$emulator_config"; then
- echo "hw.lcd.density=420" >> "$emulator_config"
- fi
- if ! grep -q "hw.lcd.height" "$emulator_config"; then
- echo "hw.lcd.height=1920" >> "$emulator_config"
- fi
- if ! grep -q "hw.lcd.width" "$emulator_config"; then
- echo "hw.lcd.width=1080" >> "$emulator_config"
- fi
- echo "Emulator settings ($emulator_config)"
- cat "$emulator_config"
- fi
-
- - name: Start Android emulator
- timeout-minutes: 30 # ~4min normal - 3x DOSafety
- env:
- SUFFIX: ${{ matrix.android_avd }}-eAPI-${{ matrix.android_emu_version }}
- HOMEBREW_NO_INSTALL_CLEANUP: 1
- run: |
- echo "Starting emulator and waiting for boot to complete...."
- ls -la $ANDROID_HOME/emulator
- $ANDROID_HOME/tools/emulator --accel-check # check for hardware acceleration
- nohup $ANDROID_HOME/tools/emulator -avd $MATRIX_AVD -gpu host -no-audio -no-boot-anim -camera-back none -camera-front none -qemu -m 2048 2>&1 &
- $ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do echo "wait..."; sleep 1; done; input keyevent 82'
- echo "Emulator has finished booting"
- $ANDROID_HOME/platform-tools/adb devices
- sleep 30
- mkdir -p screenshots
- screencapture screenshots/screenshot-$SUFFIX.jpg
- $ANDROID_HOME/platform-tools/adb exec-out screencap -p > screenshots/emulator-$SUFFIX.png
-
- # # # Have to re-setup everything since we need to run emulator for faster performance on masOS ? Other os'es emulator will not startup ?
- # TODO: Optimize the steps taking into consideration all software present by default on macOS runner image
-
- # # # Test # # reactiveCircus is giving a black screenshot not working
- # # # TODO: Take a screenshot of OS to confirm if its Emulator issue or testcode/androidsdk issue - or maybe the emulator is screen off ?
- # # # https://github.com/ReactiveCircus/android-emulator-runner
- # - name: Test Cache
- # uses: reactivecircus/android-emulator-runner@v2
- # with:
- # api-level: ${{ matrix.android_emu_version }}
- # arch: x86_64
- # profile: Nexus 6
- # target: google_apis
- # emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim
- # script: echo Meoooow !
- # - name: Test
- # id: test
- # uses: reactivecircus/android-emulator-runner@v2
- # with:
- # api-level: ${{ matrix.android_emu_version }}
- # arch: x86_64
- # profile: Nexus 6
- # target: google_apis
- # emulator-options: -gpu swiftshader_indirect -noaudio -no-boot-anim -no-snapshot-save
- # # Only running specific Instrumentation tests cause others are failing right now. TODO: Fix others
- # script: ./gradlew connectedCheck -Pandroid.testInstrumentationRunnerArguments.class=net.activitywatch.android.ScreenshotTest --stacktrace
-
- # - name: Install recorder and record session
- # env:
- # SUFFIX: ${{ matrix.android_avd }}-eAPI-${{ matrix.android_emu_version }}-${{ matrix.os }}
- # run: |
- # brew install ffmpeg
- # $ANDROID_HOME/tools/emulator -help-all
- # # -logcat *:v
- # # $ANDROID_HOME/tools/emulator -port 18725 -verbose -no-audio -gpu swiftshader_indirect -logcat *:v @$MATRIX_AVD &
- # ffmpeg -f avfoundation -i 0 -t 120 out$SUFFIX.mov &
-
- name: Set up JDK
- uses: actions/setup-java@v1
+ uses: actions/setup-java@v4
with:
+ distribution: 'temurin'
java-version: ${{ env.JAVA_VERSION }}
- # Android SDK & NDK
- - name: Set up Android SDK
- uses: android-actions/setup-android@v2
- - name: Set up Android NDK
- run: |
- sdkmanager "ndk;${{ env.NDK_VERSION }}"
- ANDROID_NDK_HOME="$ANDROID_SDK_ROOT/ndk/${{ env.NDK_VERSION }}"
- ls $ANDROID_NDK_HOME
- echo "ANDROID_NDK_HOME=$ANDROID_NDK_HOME" >> $GITHUB_ENV
-
- - name: Run E2E tests
- timeout-minutes: 20
+ - name: Run Emulator and E2E tests
+ uses: reactivecircus/android-emulator-runner@v2
+ timeout-minutes: 30
id: test
- run: |
- make test-e2e
-
- - name: Output and save logcat to file
- if: ${{ success() || steps.test.conclusion == 'failure'}}
- run: |
- mkdir -p mobile/build
- adb logcat -d > mobile/build/logcat.log
- adb logcat -v color &
-
- - name: Screenshot
- if: ${{ success() || steps.test.conclusion == 'failure'}}
- env:
- SUFFIX: ${{ matrix.android_avd }}-eAPI-${{ matrix.android_emu_version }}
- run: |
- adb shell monkey -p net.activitywatch.android.debug 1
- sleep 10
- screencapture screenshots/pscreenshot-$SUFFIX.jpg
- $ANDROID_HOME/platform-tools/adb exec-out screencap -p > screenshots/pemulator-$SUFFIX.png
- ls -alh screenshots/
+ with:
+ api-level: ${{ matrix.api-level }}
+ target: google_apis
+ arch: x86_64
+ ndk: ${{ env.NDK_VERSION }}
+ emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -no-snapshot-save
+ disable-animations: true
+ script: |
+ make test-e2e || true
+ adb install -r mobile/build/outputs/apk/debug/mobile-debug.apk
+ adb shell monkey -p net.activitywatch.android.debug -c android.intent.category.LAUNCHER 1
+ sleep 3
+ adb shell screencap -p /sdcard/screenshot.png
+ adb pull /sdcard/screenshot.png .
+ mkdir -p mobile/build
+ adb logcat -d > mobile/build/logcat.log
+
+ - name: Upload screenshot
+ uses: actions/upload-artifact@v4
+ if: ${{ success() || steps.test.conclusion == 'failure' }}
+ with:
+ name: emulator-screenshot
+ path: screenshot.png
- name: Upload logcat
- if: ${{ success() || steps.test.conclusion == 'failure'}}
- uses: actions/upload-artifact@v3
+ if: ${{ success() || steps.test.conclusion == 'failure' }}
+ uses: actions/upload-artifact@v4
with:
name: logcat
- # mobile\build\outputs\connected_android_test_additional_output\debugAndroidTest\connected\Pixel_XL_API_32(AVD) - 12\ScreenshotTest_saveDeviceScreenBitmap.png
- path: |
- mobile/build/logcat.log
- #mobile/build/reports/*
-
- # - name: Upload video
- # if: ${{ success() || steps.test.conclusion == 'failure'}}
- # uses: actions/upload-artifact@master
- # with:
- # name: video
- # path: ./*.mov # out.mov
-
- - name: Upload screenshots
- uses: actions/upload-artifact@v3
- if: ${{ success() || steps.test.conclusion == 'failure'}}
- with:
- name: screenshots
- path: |
- screenshots/*
- **/mobile/build/outputs/connected_android_test_additional_output/debugAndroidTest/connected/*
+ path: mobile/build/logcat.log
#- name: Publish Test Report
# # # uses: mikepenz/action-junit-report@v3
@@ -497,10 +378,10 @@ jobs:
if: startsWith(github.ref, 'refs/tags/v') # only on runs triggered from tag
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v4
- name: Download APK & AAB
- uses: actions/download-artifact@v3
+ uses: actions/download-artifact@v4
with:
name: aw-android
path: dist
@@ -517,7 +398,7 @@ jobs:
bundler-cache: true
# detect if version tag is stable/beta
- - uses: nowsprinting/check-version-format-action@v2
+ - uses: nowsprinting/check-version-format-action@v4
id: version
with:
prefix: 'v'
@@ -556,7 +437,7 @@ jobs:
# Will download all artifacts to path
- name: Download release APK & AAB
- uses: actions/download-artifact@v3
+ uses: actions/download-artifact@v4
with:
name: aw-android
path: dist
@@ -566,14 +447,14 @@ jobs:
run: ls -R
# detect if version tag is stable/beta
- - uses: nowsprinting/check-version-format-action@v2
+ - uses: nowsprinting/check-version-format-action@v4
id: version
with:
prefix: 'v'
# create a release
- name: Release
- uses: softprops/action-gh-release@v1
+ uses: softprops/action-gh-release@v2
with:
draft: true
prerelease: ${{ !(steps.version.outputs.is_stable == 'true') }} # must compare to true, since boolean outputs are actually just strings, and "false" is truthy since it's not empty: https://github.com/actions/runner/issues/1483#issuecomment-994986996
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index b589d56e..b86273d9 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 5480c98a..9a001de1 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,10 +1,11 @@
+
-
+
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index 35eb1ddf..2617fefd 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -2,5 +2,6 @@
+
\ No newline at end of file
diff --git a/Makefile b/Makefile
index e1648c5a..0d78d160 100644
--- a/Makefile
+++ b/Makefile
@@ -151,7 +151,8 @@ export ON_ANDROID := -- --android
aw-server-rust: $(JNILIBS)
.PHONY: $(JNILIBS)
-$(JNILIBS): $(JNI_arm7)/libaw_server.so $(JNI_arm8)/libaw_server.so $(JNI_x86)/libaw_server.so $(JNI_x64)/libaw_server.so
+$(JNILIBS): $(JNI_arm7)/libaw_server.so $(JNI_arm8)/libaw_server.so $(JNI_x86)/libaw_server.so $(JNI_x64)/libaw_server.so \
+ $(JNI_arm7)/libaw_sync.so $(JNI_arm8)/libaw_sync.so $(JNI_x86)/libaw_sync.so $(JNI_x64)/libaw_sync.so
@ls -lL $@/*/* # Check that symlinks are valid
# There must be a better way to do this without repeating almost the same rule over and over?
@@ -170,6 +171,20 @@ $(JNI_x64)/libaw_server.so: $(TARGETDIR_x64)/$(RELEASE_TYPE)/libaw_server.so
mkdir -p $$(dirname $@)
if [ -z "$(TARGET)" ] || [ "$(TARGET)" == "x86_64" ]; then ln -fnv $$(pwd)/$^ $@; fi
+$(JNI_arm7)/libaw_sync.so: $(TARGETDIR_arm7)/$(RELEASE_TYPE)/libaw_sync.so
+ mkdir -p $$(dirname $@)
+ # if target is empty, then create symlink
+ if [ -z "$(TARGET)" ] || [ "$(TARGET)" == "arm" ]; then ln -fnv $$(pwd)/$^ $@; fi
+$(JNI_arm8)/libaw_sync.so: $(TARGETDIR_arm8)/$(RELEASE_TYPE)/libaw_sync.so
+ mkdir -p $$(dirname $@)
+ if [ -z "$(TARGET)" ] || [ "$(TARGET)" == "arm64" ]; then ln -fnv $$(pwd)/$^ $@; fi
+$(JNI_x86)/libaw_sync.so: $(TARGETDIR_x86)/$(RELEASE_TYPE)/libaw_sync.so
+ mkdir -p $$(dirname $@)
+ if [ -z "$(TARGET)" ] || [ "$(TARGET)" == "x86" ]; then ln -fnv $$(pwd)/$^ $@; fi
+$(JNI_x64)/libaw_sync.so: $(TARGETDIR_x64)/$(RELEASE_TYPE)/libaw_sync.so
+ mkdir -p $$(dirname $@)
+ if [ -z "$(TARGET)" ] || [ "$(TARGET)" == "x86_64" ]; then ln -fnv $$(pwd)/$^ $@; fi
+
RUSTFLAGS_ANDROID="-C debuginfo=2 -Awarnings"
# Explanation of RUSTFLAGS:
# `-Awarnings` allows all warnings, for cleaner output (warnings should be detected in aw-server-rust CI anyway)
@@ -192,6 +207,17 @@ $(RS_SRCDIR)/target/%/$(RELEASE_TYPE)/libaw_server.so: $(RS_SOURCES) $(WEBUI_DIS
env RUSTFLAGS=$(RUSTFLAGS_ANDROID) make -C aw-server-rust android; \
fi
+# Same rule for libaw_sync.so (but without webui dependency)
+$(RS_SRCDIR)/target/%/$(RELEASE_TYPE)/libaw_sync.so: $(RS_SOURCES)
+ @echo $@
+ @echo "Release type: $(RELEASE_TYPE)"
+ @if [ "$$USE_PREBUILT" == "true" ] && [ -f $@ ]; then \
+ echo "Using prebuilt libaw_sync.so"; \
+ else \
+ echo "Building libaw_sync.so from aw-server-rust repo"; \
+ env RUSTFLAGS=$(RUSTFLAGS_ANDROID) make -C aw-server-rust android; \
+ fi
+
# aw-webui
.PHONY: $(WEBUI_DISTDIR)
$(WEBUI_DISTDIR):
@@ -210,4 +236,4 @@ clean:
.PHONY: fastlane/metadata/android/en-US/images/icon.png
fastlane/metadata/android/en-US/images/icon.png: aw-server-rust/aw-webui/media/logo/logo.png
- convert $< -resize 75% -gravity center -background white -extent 512x512 $@
+ magick $< -resize 75% -gravity center -background white -extent 512x512 $@
diff --git a/README.md b/README.md
index bbb62012..ee198191 100644
--- a/README.md
+++ b/README.md
@@ -38,7 +38,7 @@ If you haven't already, initialize the submodules with: `git submodule update --
To build aw-server-rust you need to have Rust nightly installed (with rustup). Then you can build it with:
-```
+```sh
export ANDROID_NDK_HOME=`pwd`/aw-server-rust/NDK # The path to your NDK
pushd aw-server-rust && ./install-ndk.sh; popd # This configures the NDK for use with Rust, and installs the NDK if missing
env RELEASE=false make aw-server-rust # Set RELEASE=true to build in release mode (slower build, harder to debug)
diff --git a/android.jks.age b/android.jks.age
index 7a1d3290..9d9b8d4f 100644
Binary files a/android.jks.age and b/android.jks.age differ
diff --git a/aw-server-rust b/aw-server-rust
index dc70318e..9a8802a3 160000
--- a/aw-server-rust
+++ b/aw-server-rust
@@ -1 +1 @@
-Subproject commit dc70318e819efc0d0535a5d7bd35a0c7ab8e9106
+Subproject commit 9a8802a374d8e9f587b343dfedf3859ec1a9bba2
diff --git a/build.gradle b/build.gradle
index 0d0482b8..98832fb5 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,10 +1,10 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
- ext.kotlin_version = '1.7.20'
- ext.androidXTestVersion = '1.5.0'
- ext.espressoVersion = '3.5.0'
- ext.extJUnitVersion = '1.1.4'
+ ext.kotlin_version = '1.9.0'
+ ext.androidXTestVersion = '1.7.0'
+ ext.espressoVersion = '3.7.0'
+ ext.extJUnitVersion = '1.3.0'
ext.servicesVersion = '1.4.2'
repositories {
google()
@@ -14,7 +14,7 @@ buildscript {
}
}
dependencies {
- classpath 'com.android.tools.build:gradle:8.1.1'
+ classpath 'com.android.tools.build:gradle:8.13.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'gradle.plugin.org.mozilla.rust-android-gradle:plugin:0.8.3'
diff --git a/fastlane/metadata/android/en-US/images/icon.png b/fastlane/metadata/android/en-US/images/icon.png
index ba02ea8a..b8e6422a 100644
Binary files a/fastlane/metadata/android/en-US/images/icon.png and b/fastlane/metadata/android/en-US/images/icon.png differ
diff --git a/gradle.properties b/gradle.properties
index 3d8ce0ca..ee656e91 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -15,3 +15,6 @@ org.gradle.jvmargs=-Xmx1536m
kotlin.code.style=official
android.useAndroidX=true
android.enableJetifier=true
+
+# Enable native symbol preservation for debugging
+# doNotStrip=true
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
index f6b961fd..d64cd491 100644
Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 59bc51a2..9f64451e 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,8 @@
+#Fri Sep 26 14:49:59 CEST 2025
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
+networkTimeout=10000
+validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
index cccdd3d5..1aa94a42 100755
--- a/gradlew
+++ b/gradlew
@@ -1,78 +1,127 @@
-#!/usr/bin/env sh
+#!/bin/sh
+
+#
+# Copyright © 2015-2021 the original authors.
+#
+# 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
+#
+# https://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.
+#
##############################################################################
-##
-## Gradle start up script for UN*X
-##
+#
+# Gradle start up script for POSIX generated by Gradle.
+#
+# Important for running:
+#
+# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
+# noncompliant, but you have some other compliant shell such as ksh or
+# bash, then to run this script, type that shell name before the whole
+# command line, like:
+#
+# ksh Gradle
+#
+# Busybox and similar reduced shells will NOT work, because this script
+# requires all of these POSIX shell features:
+# * functions;
+# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
+# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
+# * compound commands having a testable exit status, especially «case»;
+# * various built-in commands including «command», «set», and «ulimit».
+#
+# Important for patching:
+#
+# (2) This script targets any POSIX shell, so it avoids extensions provided
+# by Bash, Ksh, etc; in particular arrays are avoided.
+#
+# The "traditional" practice of packing multiple parameters into a
+# space-separated string is a well documented source of bugs and security
+# problems, so this is (mostly) avoided, by progressively accumulating
+# options in "$@", and eventually passing that to Java.
+#
+# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
+# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
+# see the in-line comments for details.
+#
+# There are tweaks for specific operating systems such as AIX, CygWin,
+# Darwin, MinGW, and NonStop.
+#
+# (3) This script is generated from the Groovy template
+# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+# within the Gradle project.
+#
+# You can find Gradle at https://github.com/gradle/gradle/.
+#
##############################################################################
# Attempt to set APP_HOME
+
# Resolve links: $0 may be a link
-PRG="$0"
-# Need this for relative symlinks.
-while [ -h "$PRG" ] ; do
- ls=`ls -ld "$PRG"`
- link=`expr "$ls" : '.*-> \(.*\)$'`
- if expr "$link" : '/.*' > /dev/null; then
- PRG="$link"
- else
- PRG=`dirname "$PRG"`"/$link"
- fi
+app_path=$0
+
+# Need this for daisy-chained symlinks.
+while
+ APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
+ [ -h "$app_path" ]
+do
+ ls=$( ls -ld "$app_path" )
+ link=${ls#*' -> '}
+ case $link in #(
+ /*) app_path=$link ;; #(
+ *) app_path=$APP_HOME$link ;;
+ esac
done
-SAVED="`pwd`"
-cd "`dirname \"$PRG\"`/" >/dev/null
-APP_HOME="`pwd -P`"
-cd "$SAVED" >/dev/null
-
-APP_NAME="Gradle"
-APP_BASE_NAME=`basename "$0"`
-# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-DEFAULT_JVM_OPTS=""
+# This is normally unused
+# shellcheck disable=SC2034
+APP_BASE_NAME=${0##*/}
+# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
+APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
-MAX_FD="maximum"
+MAX_FD=maximum
warn () {
echo "$*"
-}
+} >&2
die () {
echo
echo "$*"
echo
exit 1
-}
+} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
-case "`uname`" in
- CYGWIN* )
- cygwin=true
- ;;
- Darwin* )
- darwin=true
- ;;
- MINGW* )
- msys=true
- ;;
- NONSTOP* )
- nonstop=true
- ;;
+case "$( uname )" in #(
+ CYGWIN* ) cygwin=true ;; #(
+ Darwin* ) darwin=true ;; #(
+ MSYS* | MINGW* ) msys=true ;; #(
+ NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
- JAVACMD="$JAVA_HOME/jre/sh/java"
+ JAVACMD=$JAVA_HOME/jre/sh/java
else
- JAVACMD="$JAVA_HOME/bin/java"
+ JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
@@ -81,92 +130,120 @@ Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
- JAVACMD="java"
- which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+ JAVACMD=java
+ if ! command -v java >/dev/null 2>&1
+ then
+ die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
+ fi
fi
# Increase the maximum file descriptors if we can.
-if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
- MAX_FD_LIMIT=`ulimit -H -n`
- if [ $? -eq 0 ] ; then
- if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
- MAX_FD="$MAX_FD_LIMIT"
- fi
- ulimit -n $MAX_FD
- if [ $? -ne 0 ] ; then
- warn "Could not set maximum file descriptor limit: $MAX_FD"
- fi
- else
- warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
- fi
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
+ case $MAX_FD in #(
+ max*)
+ # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC2039,SC3045
+ MAX_FD=$( ulimit -H -n ) ||
+ warn "Could not query maximum file descriptor limit"
+ esac
+ case $MAX_FD in #(
+ '' | soft) :;; #(
+ *)
+ # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC2039,SC3045
+ ulimit -n "$MAX_FD" ||
+ warn "Could not set maximum file descriptor limit to $MAX_FD"
+ esac
fi
-# For Darwin, add options to specify how the application appears in the dock
-if $darwin; then
- GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
-fi
+# Collect all arguments for the java command, stacking in reverse order:
+# * args from the command line
+# * the main class name
+# * -classpath
+# * -D...appname settings
+# * --module-path (only if needed)
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if "$cygwin" || "$msys" ; then
+ APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
+ CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
+
+ JAVACMD=$( cygpath --unix "$JAVACMD" )
-# For Cygwin, switch paths to Windows format before running java
-if $cygwin ; then
- APP_HOME=`cygpath --path --mixed "$APP_HOME"`
- CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
- JAVACMD=`cygpath --unix "$JAVACMD"`
-
- # We build the pattern for arguments to be converted via cygpath
- ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
- SEP=""
- for dir in $ROOTDIRSRAW ; do
- ROOTDIRS="$ROOTDIRS$SEP$dir"
- SEP="|"
- done
- OURCYGPATTERN="(^($ROOTDIRS))"
- # Add a user-defined pattern to the cygpath arguments
- if [ "$GRADLE_CYGPATTERN" != "" ] ; then
- OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
- fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
- i=0
- for arg in "$@" ; do
- CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
- CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
-
- if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
- eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
- else
- eval `echo args$i`="\"$arg\""
+ for arg do
+ if
+ case $arg in #(
+ -*) false ;; # don't mess with options #(
+ /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
+ [ -e "$t" ] ;; #(
+ *) false ;;
+ esac
+ then
+ arg=$( cygpath --path --ignore --mixed "$arg" )
fi
- i=$((i+1))
+ # Roll the args list around exactly as many times as the number of
+ # args, so each arg winds up back in the position where it started, but
+ # possibly modified.
+ #
+ # NB: a `for` loop captures its iteration list before it begins, so
+ # changing the positional parameters here affects neither the number of
+ # iterations, nor the values presented in `arg`.
+ shift # remove old arg
+ set -- "$@" "$arg" # push replacement arg
done
- case $i in
- (0) set -- ;;
- (1) set -- "$args0" ;;
- (2) set -- "$args0" "$args1" ;;
- (3) set -- "$args0" "$args1" "$args2" ;;
- (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
- (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
- (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
- (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
- (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
- (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
- esac
fi
-# Escape application args
-save () {
- for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
- echo " "
-}
-APP_ARGS=$(save "$@")
-
-# Collect all arguments for the java command, following the shell quoting and substitution rules
-eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
-# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
-if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
- cd "$(dirname "$0")"
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Collect all arguments for the java command:
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
+# and any embedded shellness will be escaped.
+# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
+# treated as '${Hostname}' itself on the command line.
+
+set -- \
+ "-Dorg.gradle.appname=$APP_BASE_NAME" \
+ -classpath "$CLASSPATH" \
+ org.gradle.wrapper.GradleWrapperMain \
+ "$@"
+
+# Stop when "xargs" is not available.
+if ! command -v xargs >/dev/null 2>&1
+then
+ die "xargs is not available"
fi
+# Use "xargs" to parse quoted args.
+#
+# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
+#
+# In Bash we could simply go:
+#
+# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
+# set -- "${ARGS[@]}" "$@"
+#
+# but POSIX shell has neither arrays nor command substitution, so instead we
+# post-process each arg (as a line of input to sed) to backslash-escape any
+# character that might be a shell metacharacter, then use eval to reverse
+# that process (while maintaining the separation between arguments), and wrap
+# the whole thing up as a single "set" statement.
+#
+# This will of course break if any of these variables contains a newline or
+# an unmatched quote.
+#
+
+eval "set -- $(
+ printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
+ xargs -n1 |
+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
+ tr '\n' ' '
+ )" '"$@"'
+
exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
index f9553162..6689b85b 100644
--- a/gradlew.bat
+++ b/gradlew.bat
@@ -1,84 +1,92 @@
-@if "%DEBUG%" == "" @echo off
-@rem ##########################################################################
-@rem
-@rem Gradle startup script for Windows
-@rem
-@rem ##########################################################################
-
-@rem Set local scope for the variables with windows NT shell
-if "%OS%"=="Windows_NT" setlocal
-
-set DIRNAME=%~dp0
-if "%DIRNAME%" == "" set DIRNAME=.
-set APP_BASE_NAME=%~n0
-set APP_HOME=%DIRNAME%
-
-@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-set DEFAULT_JVM_OPTS=
-
-@rem Find java.exe
-if defined JAVA_HOME goto findJavaFromJavaHome
-
-set JAVA_EXE=java.exe
-%JAVA_EXE% -version >NUL 2>&1
-if "%ERRORLEVEL%" == "0" goto init
-
-echo.
-echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:findJavaFromJavaHome
-set JAVA_HOME=%JAVA_HOME:"=%
-set JAVA_EXE=%JAVA_HOME%/bin/java.exe
-
-if exist "%JAVA_EXE%" goto init
-
-echo.
-echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:init
-@rem Get command-line arguments, handling Windows variants
-
-if not "%OS%" == "Windows_NT" goto win9xME_args
-
-:win9xME_args
-@rem Slurp the command line arguments.
-set CMD_LINE_ARGS=
-set _SKIP=2
-
-:win9xME_args_slurp
-if "x%~1" == "x" goto execute
-
-set CMD_LINE_ARGS=%*
-
-:execute
-@rem Setup the command line
-
-set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
-
-@rem Execute Gradle
-"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
-
-:end
-@rem End local scope for the variables with windows NT shell
-if "%ERRORLEVEL%"=="0" goto mainEnd
-
-:fail
-rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
-rem the _cmd.exe /c_ return code!
-if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
-exit /b 1
-
-:mainEnd
-if "%OS%"=="Windows_NT" endlocal
-
-:omega
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+
+@if "%DEBUG%"=="" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%"=="" set DIRNAME=.
+@rem This is normally unused
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if %ERRORLEVEL% equ 0 goto execute
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto execute
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
+
+:end
+@rem End local scope for the variables with windows NT shell
+if %ERRORLEVEL% equ 0 goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+set EXIT_CODE=%ERRORLEVEL%
+if %EXIT_CODE% equ 0 set EXIT_CODE=1
+if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
+exit /b %EXIT_CODE%
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/mobile/build.gradle b/mobile/build.gradle
index 8476d85c..5045bc6b 100644
--- a/mobile/build.gradle
+++ b/mobile/build.gradle
@@ -7,7 +7,7 @@ android {
defaultConfig {
applicationId "net.activitywatch.android"
- minSdkVersion 24
+ minSdkVersion 26
targetSdkVersion 34
// Set in CI on tagged commit
@@ -29,6 +29,7 @@ android {
}
buildTypes {
release {
+ applicationIdSuffix ".debug"
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
ndk {
@@ -42,20 +43,29 @@ android {
}
}
compileOptions {
- sourceCompatibility = '1.8'
- targetCompatibility = '1.8'
+ sourceCompatibility = JavaVersion.VERSION_11
+ targetCompatibility = JavaVersion.VERSION_11
+ coreLibraryDesugaringEnabled true
}
kotlinOptions {
- jvmTarget = "1.8"
+ jvmTarget = "11"
+ }
+
+ lint {
+ baseline = file("lint-baseline.xml")
}
+
namespace 'net.activitywatch.android'
// Never got this to work...
- //if (project.hasProperty("doNotStrip")) {
- // packagingOptions {
- // doNotStrip '**/*.so'
- // }
- //}
+ if (project.hasProperty("doNotStrip")) {
+ println "Configuring doNotStrip for jniLibs"
+ packaging {
+ jniLibs {
+ keepDebugSymbols += "**/*.so"
+ }
+ }
+ }
// Creates a resource versionName with the full version
// https://stackoverflow.com/a/36468650/965332
@@ -69,19 +79,21 @@ android {
}
dependencies {
+ coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.5'
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
- implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
+ implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
- implementation 'androidx.appcompat:appcompat:1.5.1'
+ implementation 'androidx.appcompat:appcompat:1.7.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
- implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
+ implementation 'androidx.constraintlayout:constraintlayout:2.2.1'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
- implementation 'androidx.annotation:annotation:1.5.0'
+ implementation 'androidx.annotation:annotation:1.9.1'
- implementation 'com.google.android.material:material:1.7.0'
- implementation 'com.jakewharton.threetenabp:threetenabp:1.4.3'
+ implementation 'com.google.android.material:material:1.13.0'
+ implementation 'com.jakewharton.threetenabp:threetenabp:1.4.9'
testImplementation "junit:junit:4.13.2"
androidTestImplementation "androidx.test.ext:junit-ktx:$extJUnitVersion"
@@ -90,6 +102,15 @@ dependencies {
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
androidTestUtil "androidx.test.services:test-services:$servicesVersion"
androidTestImplementation "androidx.test.espresso:espresso-web:$espressoVersion"
+ androidTestImplementation "androidx.browser:browser:1.8.0"
+ androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.3.0'
+ androidTestImplementation('org.awaitility:awaitility:4.3.0') {
+ exclude group: 'org.hamcrest', module: 'hamcrest'
+ }
+
+ // WorkManager
+ implementation "androidx.work:work-runtime-ktx:2.9.1"
+ implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3'
}
// Can be used to build with: ./gradlew cargoBuild
diff --git a/mobile/lint-baseline.xml b/mobile/lint-baseline.xml
new file mode 100644
index 00000000..8f0cfe18
--- /dev/null
+++ b/mobile/lint-baseline.xml
@@ -0,0 +1,784 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/mobile/src/androidTest/java/net/activitywatch/android/ScreenshotTest.kt b/mobile/src/androidTest/java/net/activitywatch/android/ScreenshotTest.kt
index 4040f3c7..9fb01069 100644
--- a/mobile/src/androidTest/java/net/activitywatch/android/ScreenshotTest.kt
+++ b/mobile/src/androidTest/java/net/activitywatch/android/ScreenshotTest.kt
@@ -4,9 +4,8 @@ import android.content.Intent
import android.util.Log
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
-import androidx.test.core.app.takeScreenshot
import androidx.test.core.graphics.writeToTestStorage
-import androidx.test.espresso.matcher.ViewMatchers.*
+import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.GrantPermissionRule
import org.junit.Rule
import org.junit.Test
@@ -50,7 +49,7 @@ class ScreenshotTest {
Thread.sleep(5000)
Log.i(TAG, "Taking screenshot")
- val bitmap = takeScreenshot()
+ val bitmap = InstrumentationRegistry.getInstrumentation().uiAutomation.takeScreenshot()
// Only supported on API levels >=28
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
bitmap.writeToTestStorage("${javaClass.simpleName}_${nameRule.methodName}")
diff --git a/mobile/src/androidTest/java/net/activitywatch/android/watcher/WebWatcherTest.kt b/mobile/src/androidTest/java/net/activitywatch/android/watcher/WebWatcherTest.kt
new file mode 100644
index 00000000..5995d42b
--- /dev/null
+++ b/mobile/src/androidTest/java/net/activitywatch/android/watcher/WebWatcherTest.kt
@@ -0,0 +1,154 @@
+package net.activitywatch.android.watcher
+
+import android.app.UiAutomation.FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES
+import android.content.Context
+import android.content.Intent
+import android.content.pm.PackageManager
+import android.net.Uri
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.LargeTest
+import androidx.test.platform.app.InstrumentationRegistry
+import androidx.test.rule.ServiceTestRule
+import net.activitywatch.android.RustInterface
+import net.activitywatch.android.watcher.utils.MAX_CONDITION_WAIT_TIME_MILLIS
+import net.activitywatch.android.watcher.utils.PAGE_MAX_WAIT_TIME_MILLIS
+import net.activitywatch.android.watcher.utils.PAGE_VISIT_TIME_MILLIS
+import net.activitywatch.android.watcher.utils.createCustomTabsWrapper
+import org.awaitility.Awaitility.await
+import org.hamcrest.CoreMatchers.not
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.TypeSafeMatcher
+import org.json.JSONArray
+import org.json.JSONObject
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import java.util.concurrent.TimeUnit.MILLISECONDS
+import kotlin.time.Duration.Companion.milliseconds
+
+private const val BUCKET_NAME = "aw-watcher-android-web"
+
+@LargeTest
+@RunWith(AndroidJUnit4::class)
+class WebWatcherTest {
+
+ @get:Rule
+ val serviceTestRule: ServiceTestRule = ServiceTestRule()
+
+ private val context = InstrumentationRegistry.getInstrumentation().targetContext
+ private val applicationContext = ApplicationProvider.getApplicationContext()
+
+ private val testWebPages = listOf(
+ WebPage("https://example.com", "Example Domain"),
+ WebPage("https://example.org", "Example Domain"),
+ WebPage("https://example.net", "Example Domain"),
+ WebPage("https://w3.org", "W3C"),
+ )
+
+ @Test
+ fun registerWebActivities() {
+ val ri = RustInterface(context)
+
+ Intent(applicationContext, WebWatcher::class.java)
+ .also { serviceTestRule.bindService(it) }
+ .also { enableAccessibilityService(serviceName = it.component!!.flattenToString()) }
+
+ val browsers = getAvailableBrowsers()
+ .also { assertThat(it, not(emptyList())) }
+
+ browsers.forEach { browser ->
+ openUris(uris = testWebPages.map { it.url }, browser = browser)
+ openHome() // to commit last event
+
+ val matchers = testWebPages.map { it.toMatcher(browser) }
+
+ await("expected events for: $browser").atMost(MAX_CONDITION_WAIT_TIME_MILLIS, MILLISECONDS).until {
+ val rawEvents = ri.getEvents(BUCKET_NAME, 100)
+ val events = JSONArray(rawEvents).asListOfJsonObjects()
+ .filter { it.getJSONObject("data").getString("browser") == browser }
+
+ matchers.all { matcher -> events.any { matcher.matches(it) } }
+ }
+ }
+ }
+
+ private fun enableAccessibilityService(serviceName: String) {
+ executeShellCmd("settings put secure enabled_accessibility_services $serviceName")
+ executeShellCmd("settings put secure accessibility_enabled 1")
+ }
+
+ private fun executeShellCmd(cmd: String) {
+ InstrumentationRegistry.getInstrumentation()
+ .getUiAutomation(FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES)
+ .executeShellCommand(cmd)
+ }
+
+ private fun getAvailableBrowsers() : List {
+ val activityIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://"))
+ return context.packageManager
+ .queryIntentActivities(activityIntent, PackageManager.MATCH_ALL)
+ .map { it.activityInfo.packageName.toString() }
+ }
+
+ private fun openUris(uris: List, browser: String) {
+ val customTabs = createCustomTabsWrapper(browser, context)
+ uris.forEach { uri -> customTabs.openAndWait(
+ uri,
+ pageVisitTime = PAGE_VISIT_TIME_MILLIS.milliseconds,
+ maxWaitTime = PAGE_MAX_WAIT_TIME_MILLIS.milliseconds
+ )}
+ }
+
+ private fun openHome() {
+ val intent = Intent(Intent.ACTION_MAIN).apply {
+ addCategory(Intent.CATEGORY_HOME)
+ flags = Intent.FLAG_ACTIVITY_NEW_TASK
+ }
+
+ context.startActivity(intent)
+ }
+}
+
+private fun JSONArray.asListOfJsonObjects() = this.let {
+ jsonArray -> (0 until jsonArray.length()).map { jsonArray.get(it) as JSONObject }
+}
+
+data class WebPage(val url: String, val title: String) {
+ fun toMatcher(expectedBrowser: String): WebWatcherEventMatcher = WebWatcherEventMatcher(
+ expectedUrl = url.removePrefix("https://"),
+ expectedTitle = title.takeIf { shouldMatchTitle(expectedBrowser) },
+ expectedBrowser = expectedBrowser,
+ )
+
+ // Samsung Internet does not match title at all as no android.webkit.WebView node is present
+ private fun shouldMatchTitle(browser: String) = browser != "com.sec.android.app.sbrowser"
+}
+
+class WebWatcherEventMatcher(
+ private val expectedUrl: String,
+ private val expectedTitle: String?,
+ private val expectedBrowser: String
+) : TypeSafeMatcher() {
+
+ override fun describeTo(description: org.hamcrest.Description?) {
+ description?.appendText("event with url=$expectedUrl registered by: $expectedBrowser")
+ }
+
+ override fun matchesSafely(obj: JSONObject): Boolean {
+ val timestamp = obj.optString("timestamp", "")
+
+ val duration = obj.optLong("duration", -1)
+ val data = obj.optJSONObject("data")
+
+ val url = data?.optString("url")
+ val title = data?.optString("title")
+ val browser = data?.optString("browser")
+
+ return timestamp.isNotBlank()
+ && duration >= 0
+ && url?.startsWith(expectedUrl) ?: false
+ && expectedTitle?.let { it == title } ?: true
+ && browser == expectedBrowser
+ }
+}
\ No newline at end of file
diff --git a/mobile/src/androidTest/java/net/activitywatch/android/watcher/utils/CustomTabsWrapper.kt b/mobile/src/androidTest/java/net/activitywatch/android/watcher/utils/CustomTabsWrapper.kt
new file mode 100644
index 00000000..d829c6be
--- /dev/null
+++ b/mobile/src/androidTest/java/net/activitywatch/android/watcher/utils/CustomTabsWrapper.kt
@@ -0,0 +1,134 @@
+package net.activitywatch.android.watcher.utils
+
+import android.content.ComponentName
+import android.content.Context
+import android.content.Intent
+import android.net.Uri
+import android.os.Bundle
+import androidx.browser.customtabs.CustomTabsCallback
+import androidx.browser.customtabs.CustomTabsCallback.NAVIGATION_FINISHED
+import androidx.browser.customtabs.CustomTabsCallback.NAVIGATION_STARTED
+import androidx.browser.customtabs.CustomTabsClient
+import androidx.browser.customtabs.CustomTabsIntent
+import androidx.browser.customtabs.CustomTabsServiceConnection
+import org.awaitility.Awaitility.await
+import java.util.concurrent.CompletableFuture
+import java.util.concurrent.LinkedBlockingQueue
+import java.util.concurrent.TimeUnit
+import kotlin.time.Duration
+import kotlin.time.toJavaDuration
+
+private const val FLAGS = Intent.FLAG_ACTIVITY_NEW_TASK + Intent.FLAG_ACTIVITY_NO_HISTORY
+
+fun createCustomTabsWrapper(browser: String, context: Context) : CustomTabsWrapper {
+ val navigationEventsQueue = LinkedBlockingQueue()
+
+ val customTabsCallback = object : CustomTabsCallback() {
+ override fun onNavigationEvent(navigationEvent: Int, extras: Bundle?) {
+ if (navigationEvent == NAVIGATION_STARTED || navigationEvent == NAVIGATION_FINISHED) {
+ navigationEventsQueue.offer(navigationEvent)
+ }
+ }
+ }
+
+ val customTabsIntent =
+ createCustomTabsIntentWithCallback(context, browser, customTabsCallback)
+ ?: createFallbackCustomTabsIntent(browser)
+
+ return CustomTabsWrapper(customTabsIntent, context, navigationEventsQueue)
+}
+
+private fun createCustomTabsIntentWithCallback(context: Context, browser: String, callback: CustomTabsCallback) : CustomTabsIntent? {
+ val customTabsIntent: CompletableFuture = CompletableFuture()
+
+ return CustomTabsClient.bindCustomTabsService(context, browser, object : CustomTabsServiceConnection() {
+ override fun onCustomTabsServiceConnected(name: ComponentName, client: CustomTabsClient) {
+ val session = client.newSession(callback)
+ client.warmup(0)
+
+ customTabsIntent.complete(
+ CustomTabsIntent.Builder(session).build().also {
+ it.intent.setPackage(browser)
+ it.intent.addFlags(FLAGS)
+ }
+ )
+ }
+
+ override fun onServiceDisconnected(name: ComponentName) {}
+ }).takeIf { it }?.run {
+ customTabsIntent.get(CUSTOM_TABS_SERVICE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)
+ }
+}
+
+private fun createFallbackCustomTabsIntent(browser: String) = CustomTabsIntent.Builder().build()
+ .also {
+ it.intent.setPackage(browser)
+ it.intent.addFlags(FLAGS)
+ }
+
+class CustomTabsWrapper(
+ private val customTabsIntent: CustomTabsIntent,
+ private val context: Context,
+ navigationEventsQueue: LinkedBlockingQueue?
+) {
+
+ private val navigationCompletionAwaiter : NavigationCompletionAwaiter;
+
+ init {
+ val fallback = FallbackNavigationCompletionAwaiter()
+ navigationCompletionAwaiter = navigationEventsQueue?.let {
+ EventBasedNavigationCompletionAwaiter(it, fallback)
+ } ?: fallback
+ }
+
+ fun openAndWait(uri: String, pageVisitTime: Duration, maxWaitTime: Duration) {
+ customTabsIntent.launchUrl(context, Uri.parse(uri))
+ navigationCompletionAwaiter.waitForNavigationCompleted(pageVisitTime, maxWaitTime)
+ }
+}
+
+private interface NavigationCompletionAwaiter {
+ fun waitForNavigationCompleted(pageVisitTime: Duration, maxWaitTime: Duration)
+}
+
+private class EventBasedNavigationCompletionAwaiter(
+ private val navigationEventsQueue: LinkedBlockingQueue,
+ private val fallback: NavigationCompletionAwaiter,
+) : NavigationCompletionAwaiter {
+
+ private var useFallback = false
+
+ private fun waitForNavigationStarted() : Boolean {
+ val event = navigationEventsQueue.poll(NAVIGATION_STARTED_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)
+ return event == NAVIGATION_STARTED
+ }
+
+ override fun waitForNavigationCompleted(
+ pageVisitTime: Duration,
+ maxWaitTime: Duration
+ ) {
+ if (!useFallback && waitForNavigationStarted()) {
+ await()
+ .pollDelay(pageVisitTime.toJavaDuration())
+ .atMost(maxWaitTime.toJavaDuration())
+ .until { navigationEventsQueue.peek() == NAVIGATION_FINISHED }
+ navigationEventsQueue.peek()
+ } else {
+ useFallback = true
+ fallback.waitForNavigationCompleted(pageVisitTime, maxWaitTime)
+ }
+ }
+}
+
+private class FallbackNavigationCompletionAwaiter : NavigationCompletionAwaiter {
+ override fun waitForNavigationCompleted(
+ pageVisitTime: Duration,
+ maxWaitTime: Duration
+ ) {
+ await()
+ .pollDelay(pageVisitTime.toJavaDuration())
+ .atMost(maxWaitTime.toJavaDuration())
+ .until { true } // just wait page visit time as no callback is available
+ }
+
+}
\ No newline at end of file
diff --git a/mobile/src/androidTest/java/net/activitywatch/android/watcher/utils/TestTimeouts.kt b/mobile/src/androidTest/java/net/activitywatch/android/watcher/utils/TestTimeouts.kt
new file mode 100644
index 00000000..f185a95d
--- /dev/null
+++ b/mobile/src/androidTest/java/net/activitywatch/android/watcher/utils/TestTimeouts.kt
@@ -0,0 +1,8 @@
+package net.activitywatch.android.watcher.utils
+
+const val PAGE_VISIT_TIME_MILLIS = 5000L
+const val PAGE_MAX_WAIT_TIME_MILLIS = 10000L
+const val MAX_CONDITION_WAIT_TIME_MILLIS = 10000L
+
+const val CUSTOM_TABS_SERVICE_TIMEOUT_MILLIS = 30000L
+const val NAVIGATION_STARTED_TIMEOUT_MILLIS = 10000L
\ No newline at end of file
diff --git a/mobile/src/main/AndroidManifest.xml b/mobile/src/main/AndroidManifest.xml
index c983de3a..34728dcd 100644
--- a/mobile/src/main/AndroidManifest.xml
+++ b/mobile/src/main/AndroidManifest.xml
@@ -1,44 +1,45 @@
+ xmlns:tools="http://schemas.android.com/tools"
+ tools:ignore="MissingLeanbackLauncher">
-
-
-
-
+
+
+
-
+ android:name="android.permission.PACKAGE_USAGE_STATS"
+ tools:ignore="ProtectedPermissions" />
+
+
+
+ android:allowBackup="true"
+ android:label="@string/app_name"
+ android:roundIcon="@mipmap/aw_launcher_round"
+ android:icon="@mipmap/aw_launcher"
+ android:supportsRtl="true"
+ android:theme="@style/AppTheme"
+ android:networkSecurityConfig="@xml/network_security_config">
-
-
+
+
+
+ android:exported="true" />
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
\ No newline at end of file
diff --git a/mobile/src/main/java/net/activitywatch/android/BackgroundService.kt b/mobile/src/main/java/net/activitywatch/android/BackgroundService.kt
new file mode 100644
index 00000000..0980a49e
--- /dev/null
+++ b/mobile/src/main/java/net/activitywatch/android/BackgroundService.kt
@@ -0,0 +1,119 @@
+package net.activitywatch.android
+
+import android.app.Notification
+import android.app.NotificationChannel
+import android.app.NotificationManager
+import android.app.PendingIntent
+import android.app.Service
+import android.content.Context
+import android.content.Intent
+import android.os.Build
+import android.os.IBinder
+import android.util.Log
+import androidx.core.app.NotificationCompat
+
+private const val TAG = "BackgroundService"
+private const val CHANNEL_ID = "aw_background_channel"
+private const val NOTIFICATION_ID = 1
+
+class BackgroundService : Service() {
+
+ private lateinit var syncScheduler: SyncScheduler
+ private lateinit var rustInterface: RustInterface
+
+ override fun onCreate() {
+ super.onCreate()
+ Log.i(TAG, "BackgroundService created")
+ rustInterface = RustInterface(this)
+ syncScheduler = SyncScheduler(this)
+ }
+
+ override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
+ Log.i(TAG, "BackgroundService started")
+
+ createNotificationChannel()
+ val notification = createNotification()
+ startForeground(NOTIFICATION_ID, notification)
+
+ // Start the server
+ rustInterface.startServerTask()
+
+ // Start the sync scheduler
+ syncScheduler.start()
+
+ // Schedule event parsing
+ scheduleEventParsing()
+
+ return START_STICKY
+ }
+
+ private fun scheduleEventParsing() {
+ val currentDate = java.util.Calendar.getInstance()
+ val dueDate = java.util.Calendar.getInstance()
+ // Set to midnight
+ dueDate.set(java.util.Calendar.HOUR_OF_DAY, 0)
+ dueDate.set(java.util.Calendar.MINUTE, 0)
+ dueDate.set(java.util.Calendar.SECOND, 0)
+ if (dueDate.before(currentDate)) {
+ dueDate.add(java.util.Calendar.HOUR_OF_DAY, 24)
+ }
+ val timeDiff = dueDate.timeInMillis - currentDate.timeInMillis
+
+ val saveRequest = androidx.work.PeriodicWorkRequest.Builder(
+ net.activitywatch.android.workers.EventParsingWorker::class.java,
+ 24, java.util.concurrent.TimeUnit.HOURS
+ )
+ .setInitialDelay(timeDiff, java.util.concurrent.TimeUnit.MILLISECONDS)
+ .addTag("EventParsing")
+ .build()
+
+ androidx.work.WorkManager.getInstance(this).enqueueUniquePeriodicWork(
+ "EventParsingWorker",
+ androidx.work.ExistingPeriodicWorkPolicy.UPDATE,
+ saveRequest
+ )
+ Log.i(TAG, "Scheduled event parsing worker with initial delay: ${timeDiff}ms")
+ }
+
+ override fun onDestroy() {
+ Log.i(TAG, "BackgroundService destroyed")
+ syncScheduler.stop()
+ super.onDestroy()
+ }
+
+ override fun onBind(intent: Intent?): IBinder? {
+ return null
+ }
+
+ private fun createNotificationChannel() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ val name = "ActivityWatch Background Service"
+ val descriptionText = "Keeps ActivityWatch server and sync running in the background"
+ val importance = NotificationManager.IMPORTANCE_LOW
+ val channel = NotificationChannel(CHANNEL_ID, name, importance).apply {
+ description = descriptionText
+ }
+ val notificationManager: NotificationManager =
+ getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
+ notificationManager.createNotificationChannel(channel)
+ }
+ }
+
+ private fun createNotification(): Notification {
+ val pendingIntent: PendingIntent =
+ Intent(this, MainActivity::class.java).let { notificationIntent ->
+ PendingIntent.getActivity(
+ this, 0, notificationIntent,
+ PendingIntent.FLAG_IMMUTABLE
+ )
+ }
+
+ return NotificationCompat.Builder(this, CHANNEL_ID)
+ .setContentTitle("ActivityWatch Server")
+ .setContentText("Server and sync running in background")
+ .setSmallIcon(R.mipmap.aw_launcher_round) // Make sure this icon exists or use a fallback
+ .setContentIntent(pendingIntent)
+ .setPriority(NotificationCompat.PRIORITY_LOW)
+ .build()
+ }
+}
diff --git a/mobile/src/main/java/net/activitywatch/android/MainActivity.kt b/mobile/src/main/java/net/activitywatch/android/MainActivity.kt
index 0c439e0f..4281d1db 100644
--- a/mobile/src/main/java/net/activitywatch/android/MainActivity.kt
+++ b/mobile/src/main/java/net/activitywatch/android/MainActivity.kt
@@ -3,14 +3,15 @@ package net.activitywatch.android
import android.content.Intent
import android.net.Uri
import android.os.Bundle
-import com.google.android.material.snackbar.Snackbar
-import com.google.android.material.navigation.NavigationView
-import androidx.core.view.GravityCompat
-import androidx.appcompat.app.AppCompatActivity
+import android.util.Log
import android.view.Menu
import android.view.MenuItem
+import androidx.activity.OnBackPressedCallback
+import androidx.appcompat.app.AppCompatActivity
+import androidx.core.view.GravityCompat
import androidx.fragment.app.Fragment
-import android.util.Log
+import com.google.android.material.navigation.NavigationView
+import com.google.android.material.snackbar.Snackbar
import net.activitywatch.android.databinding.ActivityMainBinding
import net.activitywatch.android.fragments.TestFragment
import net.activitywatch.android.fragments.WebUIFragment
@@ -24,6 +25,7 @@ const val baseURL = "http://127.0.0.1:5600"
class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener, WebUIFragment.OnFragmentInteractionListener {
private lateinit var binding: ActivityMainBinding
+ private lateinit var syncScheduler: SyncScheduler
val version: String
get() {
@@ -56,8 +58,9 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
binding.navView.setNavigationItemSelectedListener(this)
- val ri = RustInterface(this)
- ri.startServerTask(this)
+ // Start background service to keep server and sync running
+ val serviceIntent = Intent(this, BackgroundService::class.java)
+ startForegroundService(serviceIntent)
if (savedInstanceState != null) {
return
@@ -65,6 +68,19 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
val firstFragment = WebUIFragment.newInstance(baseURL)
supportFragmentManager.beginTransaction()
.add(R.id.fragment_container, firstFragment).commit()
+
+ onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
+ override fun handleOnBackPressed() {
+ if (binding.drawerLayout.isDrawerOpen(GravityCompat.START)) {
+ binding.drawerLayout.closeDrawer(GravityCompat.START)
+ } else {
+ finish()
+ }
+ }
+ })
+
+ // Test RustInterface functions (remove after testing)
+ RustInterface(this).test()
}
override fun onResume() {
@@ -73,17 +89,11 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
// Ensures data is always fresh when app is opened,
// even if it was up to an hour since the last logging-alarm was triggered.
val usw = UsageStatsWatcher(this)
+ val mode = if (usw.isUsingDiscreteEvents()) "discrete event insertion" else "heartbeat merging"
+ Log.i("MainActivity", "Using $mode mode for event tracking")
usw.sendHeartbeats()
}
- override fun onBackPressed() {
- if (binding.drawerLayout.isDrawerOpen(GravityCompat.START)) {
- binding.drawerLayout.closeDrawer(GravityCompat.START)
- } else {
- super.onBackPressed()
- }
- }
-
override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.main, menu)
@@ -155,4 +165,9 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
binding.drawerLayout.closeDrawer(GravityCompat.START)
return true
}
+
+ override fun onDestroy() {
+ super.onDestroy()
+ // syncScheduler.stop() // Handled by BackgroundService
+ }
}
diff --git a/mobile/src/main/java/net/activitywatch/android/OnboardingActivity.kt b/mobile/src/main/java/net/activitywatch/android/OnboardingActivity.kt
index 76d05bf0..cfd556dc 100644
--- a/mobile/src/main/java/net/activitywatch/android/OnboardingActivity.kt
+++ b/mobile/src/main/java/net/activitywatch/android/OnboardingActivity.kt
@@ -8,6 +8,7 @@ import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
+import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
@@ -16,6 +17,7 @@ import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.snackbar.Snackbar
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
+import net.activitywatch.android.watcher.MediaWatcher
import net.activitywatch.android.watcher.UsageStatsWatcher
// enum for the onboarding pages
@@ -86,14 +88,16 @@ class OnboardingActivity : AppCompatActivity() {
updateButtons()
}
})
- }
- override fun onBackPressed() {
- // If back button is pressed, exit the app,
- // since we don't want to allow the user to accidentally skip onboarding.
- // (Google Play policy, due to sensitive permissions)
- // https://developer.android.com/distribute/best-practices/develop/restrictions-non-sdk-interfaces#back-button
- finishAffinity()
+ onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
+ override fun handleOnBackPressed() {
+ // If back button is pressed, exit the app,
+ // since we don't want to allow the user to accidentally skip onboarding.
+ // (Google Play policy, due to sensitive permissions)
+ // https://developer.android.com/distribute/best-practices/develop/restrictions-non-sdk-interfaces#back-button
+ finishAffinity()
+ }
+ })
}
}
@@ -143,6 +147,10 @@ class PermissionsFragment : Fragment() {
view.findViewById