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
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ modules/**/ios/build/

# Rust
native/rust-core/target/
native/rust-core/Cargo.lock
*.so
*.dylib
*.dll
Expand All @@ -86,7 +85,9 @@ tests/fixtures/test_account.json
.env.test
*.aax
*.aaxc
/native/rust-core/test_fixtures/
/native/rust-core/test_fixtures/*
!/native/rust-core/test_fixtures/
!/native/rust-core/test_fixtures/registration_response.json

# Development/testing tools
test-workers.sh
Expand Down
3 changes: 2 additions & 1 deletion app.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export default {
permissions: [
"POST_NOTIFICATIONS",
"FOREGROUND_SERVICE",
"FOREGROUND_SERVICE_DATA_SYNC"
"FOREGROUND_SERVICE_DATA_SYNC",
"RECEIVE_BOOT_COMPLETED"
]
},
web: {
Expand Down
1 change: 1 addition & 0 deletions modules/expo-rust-bridge/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ repositories {
}

android {
namespace 'expo.modules.rustbridge'
compileSdkVersion 34

defaultConfig {
Expand Down
21 changes: 19 additions & 2 deletions modules/expo-rust-bridge/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="expo.modules.rustbridge">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

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

<application>
<!-- Download Service -->
Expand All @@ -8,6 +9,12 @@
android:exported="false"
android:foregroundServiceType="dataSync" />

<!-- Background Task Service -->
<service
android:name=".tasks.BackgroundTaskService"
android:exported="false"
android:foregroundServiceType="dataSync" />

<!-- Download Action Receiver (for notification buttons) -->
<receiver
android:name=".DownloadActionReceiver"
Expand All @@ -18,5 +25,15 @@
<action android:name="expo.modules.rustbridge.CANCEL_DOWNLOAD" />
</intent-filter>
</receiver>

<!-- Boot Receiver (restores background tasks after reboot/update) -->
<receiver
android:name=".tasks.BootReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
</receiver>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package expo.modules.rustbridge

import android.content.Context
import java.io.File

object AppPaths {
private const val DATABASE_FILE_NAME = "audible.db"

fun databasePath(context: Context): String {
return File(context.filesDir, DATABASE_FILE_NAME).absolutePath
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.content.Intent
import android.util.Log
import org.json.JSONArray
import org.json.JSONObject
import java.io.File

/**
* BroadcastReceiver for handling notification action buttons
Expand All @@ -32,7 +31,7 @@ class DownloadActionReceiver : BroadcastReceiver() {
return
}

val dbPath = File(context.cacheDir, "audible.db").absolutePath
val dbPath = AppPaths.databasePath(context)

Log.d(TAG, "Received action: ${intent.action} for ASIN: $asin")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,16 +486,16 @@ class DownloadOrchestrator(
progressCallback?.invoke(asin, "copying", 0.0, 0, 0)

// Copy to final destination
copyToFinalDestination(asin, title, decryptedCachePath, outputDirectory, coverArtPath)
val finalPath = copyToFinalDestination(asin, title, decryptedCachePath, outputDirectory, coverArtPath)

// Cleanup encrypted file
File(encryptedPath).delete()

// Cleanup cover art temp file
coverArtPath?.let { File(it).delete() }

// Mark as completed in DB
resolvedTaskId?.let { updateTaskStatusInDb(it, "completed") }
// Mark as completed in DB with the final SAF/file path
resolvedTaskId?.let { updateTaskStatusInDb(it, "completed", finalPath) }

} catch (e: Exception) {
Log.e(TAG, "Conversion failed for $asin", e)
Expand All @@ -514,7 +514,7 @@ class DownloadOrchestrator(
decryptedCachePath: String,
outputDirectory: String,
coverArtPath: String?
) = withContext(Dispatchers.IO) {
): String = withContext(Dispatchers.IO) {
val cachedFile = File(decryptedCachePath)
var finalPath = decryptedCachePath

Expand Down Expand Up @@ -594,6 +594,8 @@ class DownloadOrchestrator(
clearManuallyPaused(asin)

completionCallback?.invoke(asin, title, finalPath)

finalPath
}

/**
Expand Down Expand Up @@ -1239,12 +1241,13 @@ class DownloadOrchestrator(
/**
* Update task status in the database via JNI
*/
private fun updateTaskStatusInDb(taskId: String, status: String) {
private fun updateTaskStatusInDb(taskId: String, status: String, outputPath: String? = null) {
try {
val params = JSONObject().apply {
put("db_path", dbPath)
put("task_id", taskId)
put("status", status)
outputPath?.let { put("output_path", it) }
}
ExpoRustBridgeModule.nativeUpdateDownloadTaskStatus(params.toString())
Log.d(TAG, "Updated task $taskId status to $status in DB")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.os.IBinder
import android.util.Log
import androidx.core.app.NotificationCompat
import org.json.JSONObject
import java.io.File
import kotlinx.coroutines.*

/**
Expand Down Expand Up @@ -145,8 +144,7 @@ class DownloadService : Service() {
Log.d(TAG, "Service created")

// Get database path from intent or use default
val cacheDir = applicationContext.cacheDir
dbPath = File(cacheDir, "audible.db").absolutePath
dbPath = AppPaths.databasePath(applicationContext)

orchestrator = DownloadOrchestrator(applicationContext, dbPath)
notificationManager = DownloadNotificationManager(applicationContext)
Expand Down
Loading