Skip to content
Merged
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
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI

on:
push:
branches: [main]
pull_request:

permissions:
contents: read

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
verify:
runs-on: ubuntu-latest
env:
GRADLE_OPTS: -Dorg.gradle.jvmargs="-Xmx4g -XX:MaxMetaspaceSize=1g -XX:+HeapDumpOnOutOfMemoryError"
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Check string resources
run: python3 scripts/check_strings.py

- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'
cache: 'gradle'

- name: Make Gradle Wrapper Executable
run: chmod +x gradlew

- name: Unit tests
run: ./gradlew test

- name: Lint (fails on errors only)
run: ./gradlew lintDebug

- name: Build debug APK
run: ./gradlew assembleDebug
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,14 @@ GEMINI.md
.antigravitycli/
.antigravityignore
CLAUDE.md
CLAUDE.local.md
.claude/
.claudeignore
.mcp.json
.kilocode/
.trae/
.zed/
.android/
.cline/
.clinerules
.clinerules/
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ You can download the latest release from the [Play Store](https://play.google.co

<table>
<tr>
<td><img src="docs/images/1.png" height="400" alt="Screenshot 1"/></td>
<td><img src="docs/images/2.png" height="400" alt="Screenshot 2"/></td>
<td><img src="docs/images/3.png" height="400" alt="Screenshot 3"/></td>
<td><img src="docs/images/4.png" height="400" alt="Screenshot 4"/></td>
<td><img src="https://raw.githubusercontent.com/LeanBitLab/Lwidget/main/fastlane/metadata/android/en-US/images/phoneScreenshots/1.png" height="400" alt="Screenshot 1"/></td>
<td><img src="https://raw.githubusercontent.com/LeanBitLab/Lwidget/main/fastlane/metadata/android/en-US/images/phoneScreenshots/2.png" height="400" alt="Screenshot 2"/></td>
<td><img src="https://raw.githubusercontent.com/LeanBitLab/Lwidget/main/fastlane/metadata/android/en-US/images/phoneScreenshots/3.png" height="400" alt="Screenshot 3"/></td>
<td><img src="https://raw.githubusercontent.com/LeanBitLab/Lwidget/main/fastlane/metadata/android/en-US/images/phoneScreenshots/4.png" height="400" alt="Screenshot 4"/></td>
</tr>
<tr>
<td><img src="docs/images/5.png" height="400" alt="Screenshot 5"/></td>
<td><img src="docs/images/6.png" height="400" alt="Screenshot 6"/></td>
<td><img src="docs/images/7.png" height="400" alt="Screenshot 7"/></td>
<td><img src="docs/images/8.png" height="400" alt="Screenshot 8"/></td>
<td><img src="https://raw.githubusercontent.com/LeanBitLab/Lwidget/main/fastlane/metadata/android/en-US/images/phoneScreenshots/5.png" height="400" alt="Screenshot 5"/></td>
<td><img src="https://raw.githubusercontent.com/LeanBitLab/Lwidget/main/fastlane/metadata/android/en-US/images/phoneScreenshots/6.png" height="400" alt="Screenshot 6"/></td>
<td><img src="https://raw.githubusercontent.com/LeanBitLab/Lwidget/main/fastlane/metadata/android/en-US/images/phoneScreenshots/7.png" height="400" alt="Screenshot 7"/></td>
<td><img src="https://raw.githubusercontent.com/LeanBitLab/Lwidget/main/fastlane/metadata/android/en-US/images/phoneScreenshots/8.png" height="400" alt="Screenshot 8"/></td>
</tr>
</table>

Expand Down
5 changes: 4 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ android {

testOptions {
unitTests.isReturnDefaultValues = true
unitTests.isIncludeAndroidResources = true
}

signingConfigs {
Expand Down Expand Up @@ -76,7 +77,9 @@ android {
}
lint {
disable += "MissingTranslation"
abortOnError = false
// Lint currently has 0 errors; keep it that way. Warnings stay informational.
// checkReleaseBuilds stays off so release/F-Droid assemble never runs lint.
abortOnError = true
checkReleaseBuilds = false
}
}
Expand Down
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.ALARM_LISTENER" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" tools:ignore="ProtectedPermissions" />
Expand Down
107 changes: 60 additions & 47 deletions app/src/main/java/com/leanbitlab/lwidget/AwidgetProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ import com.leanbitlab.lwidget.calendar.CalendarFetcher
import com.leanbitlab.lwidget.render.WidgetRenderer
import com.leanbitlab.lwidget.stats.SystemStatsFetcher
import com.leanbitlab.lwidget.tasks.TasksFetcher
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import kotlinx.coroutines.withTimeoutOrNull
import java.time.LocalDate
import java.util.concurrent.atomic.AtomicBoolean

enum class UpdateMode {
FULL, TICK, CALENDAR_ONLY, TASKS_ONLY, ALARM_ONLY, STEPS_ONLY
Expand All @@ -30,17 +33,38 @@ class AwidgetProvider : AppWidgetProvider() {

override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
StepCounterService.startServiceIfEnabled(context)
runAsync("onUpdate") {
for (appWidgetId in appWidgetIds) {
updateAppWidget(context, appWidgetManager, appWidgetId, UpdateMode.FULL)
}
}
}

/**
* Runs [block] off the main thread while holding the broadcast open via goAsync().
* The broadcast is always released within [ASYNC_BUDGET_MS], even if a data source hangs,
* so a slow calendar/tasks provider can never push the receiver past the system limit.
*/
private fun runAsync(tag: String, block: suspend () -> Unit) {
val pendingResult = goAsync()
val finished = AtomicBoolean(false)
fun finishOnce() {
if (finished.compareAndSet(false, true)) pendingResult.finish()
}
receiverScope.launch {
try {
for (appWidgetId in appWidgetIds) {
updateAppWidget(context, appWidgetManager, appWidgetId, UpdateMode.FULL)
val work = launch {
try {
block()
} catch (e: CancellationException) {
throw e
} catch (e: Throwable) {
Log.e(TAG, "Error during $tag", e)
}
} catch (e: Throwable) {
Log.e(TAG, "Error during onUpdate", e)
} finally {
pendingResult.finish()
}
if (withTimeoutOrNull(ASYNC_BUDGET_MS) { work.join() } == null) {
Log.w(TAG, "$tag exceeded ${ASYNC_BUDGET_MS}ms; releasing broadcast")
}
finishOnce()
}
}

Expand All @@ -52,15 +76,8 @@ class AwidgetProvider : AppWidgetProvider() {
) {
super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions)
StepCounterService.startServiceIfEnabled(context)
val pendingResult = goAsync()
receiverScope.launch {
try {
updateAppWidget(context, appWidgetManager, appWidgetId, UpdateMode.FULL)
} catch (e: Throwable) {
Log.e(TAG, "Error during onAppWidgetOptionsChanged", e)
} finally {
pendingResult.finish()
}
runAsync("onAppWidgetOptionsChanged") {
updateAppWidget(context, appWidgetManager, appWidgetId, UpdateMode.FULL)
}
}

Expand Down Expand Up @@ -112,39 +129,32 @@ class AwidgetProvider : AppWidgetProvider() {
AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED,
"nodomain.freeyourgadget.gadgetbridge.ACTION_GENERIC_WEATHER"
)) {
val pendingResult = goAsync()
receiverScope.launch {
try {
when {
isBootOrReplaced || intent.action == Intent.ACTION_CONFIGURATION_CHANGED -> {
scheduleWork(context)
appWidgetIds.forEach { updateAppWidget(context, appWidgetManager, it, UpdateMode.FULL) }
}
intent.action == ACTION_BATTERY_UPDATE -> {
appWidgetIds.forEach { updateAppWidget(context, appWidgetManager, it, UpdateMode.TICK) }
}
intent.action == StepCounterService.ACTION_STEP_UPDATE -> {
appWidgetIds.forEach { updateAppWidget(context, appWidgetManager, it, UpdateMode.STEPS_ONLY) }
}
intent.action == AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED -> {
appWidgetIds.forEach { updateAppWidget(context, appWidgetManager, it, UpdateMode.ALARM_ONLY) }
}
intent.action == Intent.ACTION_PROVIDER_CHANGED -> {
val uri = intent.data
if (uri != null && uri.authority == "org.tasks") {
appWidgetIds.forEach { updateAppWidget(context, appWidgetManager, it, UpdateMode.TASKS_ONLY) }
} else {
appWidgetIds.forEach { updateAppWidget(context, appWidgetManager, it, UpdateMode.CALENDAR_ONLY) }
}
}
intent.action == "nodomain.freeyourgadget.gadgetbridge.ACTION_GENERIC_WEATHER" -> {
appWidgetIds.forEach { updateAppWidget(context, appWidgetManager, it, UpdateMode.FULL) }
runAsync("broadcast ${intent.action}") {
when {
isBootOrReplaced || intent.action == Intent.ACTION_CONFIGURATION_CHANGED -> {
scheduleWork(context)
appWidgetIds.forEach { updateAppWidget(context, appWidgetManager, it, UpdateMode.FULL) }
}
intent.action == ACTION_BATTERY_UPDATE -> {
appWidgetIds.forEach { updateAppWidget(context, appWidgetManager, it, UpdateMode.TICK) }
}
intent.action == StepCounterService.ACTION_STEP_UPDATE -> {
appWidgetIds.forEach { updateAppWidget(context, appWidgetManager, it, UpdateMode.STEPS_ONLY) }
}
intent.action == AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED -> {
appWidgetIds.forEach { updateAppWidget(context, appWidgetManager, it, UpdateMode.ALARM_ONLY) }
}
intent.action == Intent.ACTION_PROVIDER_CHANGED -> {
val uri = intent.data
if (uri != null && uri.authority == "org.tasks") {
appWidgetIds.forEach { updateAppWidget(context, appWidgetManager, it, UpdateMode.TASKS_ONLY) }
} else {
appWidgetIds.forEach { updateAppWidget(context, appWidgetManager, it, UpdateMode.CALENDAR_ONLY) }
}
}
} catch (e: Throwable) {
Log.e(TAG, "Error handling broadcast ${intent.action}", e)
} finally {
pendingResult.finish()
intent.action == "nodomain.freeyourgadget.gadgetbridge.ACTION_GENERIC_WEATHER" -> {
appWidgetIds.forEach { updateAppWidget(context, appWidgetManager, it, UpdateMode.FULL) }
}
}
}
}
Expand Down Expand Up @@ -192,6 +202,9 @@ class AwidgetProvider : AppWidgetProvider() {

private const val TAG = "WidgetLife"

/** goAsync() broadcasts must finish well inside the ~10s system limit. */
private const val ASYNC_BUDGET_MS = 8_000L

const val ACTION_NOOP = "com.leanbitlab.lwidget.ACTION_NOOP"
const val ACTION_BATTERY_UPDATE = SystemStatsFetcher.ACTION_BATTERY_UPDATE
const val PERMISSION_READ_TASKS_ORG = TasksFetcher.PERMISSION_READ_TASKS_ORG
Expand Down
Loading
Loading