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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.gradle.api.JavaVersion
object SdkVersions {

const val MIN = 23
const val TARGET = 34
const val TARGET = 35

val JAVA_TARGET = JavaVersion.VERSION_17
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<androidx.fragment.app.FragmentContainerView
android:id="@+id/orchestrationHost"
Expand Down
2 changes: 1 addition & 1 deletion id/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<service
android:name=".services.sync.events.down.EventDownSyncResetService"
android:foregroundServiceType="dataSync"
android:foregroundServiceType="shortService|dataSync"
android:exported="false" />

<service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.content.pm.ServiceInfo
import android.os.Build
import android.os.IBinder
import androidx.core.app.NotificationCompat
import androidx.core.app.ServiceCompat
import com.simprints.core.ExcludedFromGeneratedTestCoverageReports
import com.simprints.core.ExternalScope
import com.simprints.infra.eventsync.EventSyncManager
Expand All @@ -18,6 +19,8 @@ import com.simprints.infra.logging.Simber
import com.simprints.infra.sync.SyncOrchestrator
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import javax.inject.Inject

Expand All @@ -33,20 +36,23 @@ class EventDownSyncResetService : Service() {
@Inject
lateinit var syncOrchestrator: SyncOrchestrator

private var resetJob: Job? = null

@Inject
@ExternalScope
lateinit var externalScope: CoroutineScope

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
Simber.tag(SYNC.name).i("Reset downSync")
externalScope.launch {
resetJob = externalScope.launch {
startForegroundIfNeeded()
// Reset current downsync state
eventSyncManager.resetDownSyncInfo()
// Trigger a new sync
syncOrchestrator.startEventSync()
stopSelf()

}
resetJob?.invokeOnCompletion { stopSelf() }

return START_REDELIVER_INTENT
}
Expand All @@ -55,6 +61,11 @@ class EventDownSyncResetService : Service() {
return null
}

override fun onTimeout(startId: Int, fgsType: Int) {
resetJob?.cancel()
super.onTimeout(startId, fgsType)
}

private fun startForegroundIfNeeded() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val chan = NotificationChannel(
Expand All @@ -69,11 +80,17 @@ class EventDownSyncResetService : Service() {
.setPriority(NotificationManager.IMPORTANCE_LOW)
.setCategory(Notification.CATEGORY_SERVICE)
.build()
// if runtime >= Q then use FOREGROUND_SERVICE_TYPE_DATA_SYNC
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
startForeground(1, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC)
} else {
startForeground(1, notification)

when {
// In Android 15 dataSync type might be timed out/restricted
// while shortService ensures that it will always be executed
Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE ->
startForeground(1, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_SHORT_SERVICE)
// Starting from Android 10 foreground services must declare type
Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q ->
startForeground(1, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC)

else -> startForeground(1, notification)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ val Context.deviceHardwareId: String
@ExcludedFromGeneratedTestCoverageReports("UI code")
val Context.packageVersionName: String
get() = try {
packageManager.getPackageInfo(packageName, 0).versionName
packageManager.getPackageInfo(packageName, 0).versionName ?: ""
} catch (e: PackageManager.NameNotFoundException) {
"Version Name Not Found"
}