mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-27 12:00:03 +03:00
Fix / fdroid notif was broken due to merge
This commit is contained in:
parent
4739aea793
commit
b0ad568df0
4 changed files with 8 additions and 96 deletions
|
@ -17,9 +17,7 @@ package im.vector.matrix.android.internal.session.sync.job
|
||||||
|
|
||||||
import android.app.Service
|
import android.app.Service
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Binder
|
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import androidx.work.ListenableWorker
|
|
||||||
import com.squareup.moshi.JsonEncodingException
|
import com.squareup.moshi.JsonEncodingException
|
||||||
import im.vector.matrix.android.api.Matrix
|
import im.vector.matrix.android.api.Matrix
|
||||||
import im.vector.matrix.android.api.MatrixCallback
|
import im.vector.matrix.android.api.MatrixCallback
|
||||||
|
@ -33,12 +31,9 @@ import im.vector.matrix.android.internal.session.sync.model.SyncResponse
|
||||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||||
import im.vector.matrix.android.internal.task.TaskThread
|
import im.vector.matrix.android.internal.task.TaskThread
|
||||||
import im.vector.matrix.android.internal.task.configureWith
|
import im.vector.matrix.android.internal.task.configureWith
|
||||||
import im.vector.matrix.android.internal.worker.getSessionComponent
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.net.SocketTimeoutException
|
import java.net.SocketTimeoutException
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlin.collections.ArrayList
|
|
||||||
|
|
||||||
private const val DEFAULT_LONG_POOL_TIMEOUT = 10_000L
|
private const val DEFAULT_LONG_POOL_TIMEOUT = 10_000L
|
||||||
private const val BACKGROUND_LONG_POOL_TIMEOUT = 0L
|
private const val BACKGROUND_LONG_POOL_TIMEOUT = 0L
|
||||||
|
@ -59,7 +54,6 @@ open class SyncService : Service() {
|
||||||
private lateinit var networkConnectivityChecker: NetworkConnectivityChecker
|
private lateinit var networkConnectivityChecker: NetworkConnectivityChecker
|
||||||
private lateinit var taskExecutor: TaskExecutor
|
private lateinit var taskExecutor: TaskExecutor
|
||||||
|
|
||||||
private var localBinder = LocalBinder()
|
|
||||||
|
|
||||||
var timer = Timer()
|
var timer = Timer()
|
||||||
|
|
||||||
|
@ -72,7 +66,8 @@ open class SyncService : Service() {
|
||||||
timeout = 0
|
timeout = 0
|
||||||
intent?.let {
|
intent?.let {
|
||||||
val userId = it.getStringExtra(EXTRA_USER_ID)
|
val userId = it.getStringExtra(EXTRA_USER_ID)
|
||||||
val sessionComponent = Matrix.getInstance(applicationContext).sessionManager.getSessionComponent(userId) ?: return@let
|
val sessionComponent = Matrix.getInstance(applicationContext).sessionManager.getSessionComponent(userId)
|
||||||
|
?: return@let
|
||||||
syncTokenStore = sessionComponent.syncTokenStore()
|
syncTokenStore = sessionComponent.syncTokenStore()
|
||||||
syncTask = sessionComponent.syncTask()
|
syncTask = sessionComponent.syncTask()
|
||||||
networkConnectivityChecker = sessionComponent.networkConnectivityChecker()
|
networkConnectivityChecker = sessionComponent.networkConnectivityChecker()
|
||||||
|
@ -130,7 +125,6 @@ open class SyncService : Service() {
|
||||||
cancelableTask = null
|
cancelableTask = null
|
||||||
nextBatch = data.nextBatch
|
nextBatch = data.nextBatch
|
||||||
syncTokenStore.saveToken(nextBatch)
|
syncTokenStore.saveToken(nextBatch)
|
||||||
localBinder.notifySyncFinish()
|
|
||||||
if (!once) {
|
if (!once) {
|
||||||
timer.schedule(object : TimerTask() {
|
timer.schedule(object : TimerTask() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
|
@ -146,7 +140,6 @@ open class SyncService : Service() {
|
||||||
override fun onFailure(failure: Throwable) {
|
override fun onFailure(failure: Throwable) {
|
||||||
Timber.e(failure)
|
Timber.e(failure)
|
||||||
cancelableTask = null
|
cancelableTask = null
|
||||||
localBinder.notifyFailure(failure)
|
|
||||||
if (failure is Failure.NetworkConnection
|
if (failure is Failure.NetworkConnection
|
||||||
&& failure.cause is SocketTimeoutException) {
|
&& failure.cause is SocketTimeoutException) {
|
||||||
// Timeout are not critical
|
// Timeout are not critical
|
||||||
|
@ -181,72 +174,12 @@ open class SyncService : Service() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBind(intent: Intent?): IBinder {
|
override fun onBind(intent: Intent?): IBinder? {
|
||||||
return localBinder
|
return null
|
||||||
}
|
|
||||||
|
|
||||||
inner class LocalBinder : Binder() {
|
|
||||||
|
|
||||||
private var listeners = ArrayList<SyncListener>()
|
|
||||||
|
|
||||||
fun addListener(listener: SyncListener) {
|
|
||||||
if (!listeners.contains(listener)) {
|
|
||||||
listeners.add(listener)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun removeListener(listener: SyncListener) {
|
|
||||||
listeners.remove(listener)
|
|
||||||
}
|
|
||||||
|
|
||||||
internal fun notifySyncFinish() {
|
|
||||||
listeners.forEach {
|
|
||||||
try {
|
|
||||||
it.onSyncFinsh()
|
|
||||||
} catch (t: Throwable) {
|
|
||||||
Timber.e("Failed to notify listener $it")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal fun notifyNetworkNotAvailable() {
|
|
||||||
listeners.forEach {
|
|
||||||
try {
|
|
||||||
it.networkNotAvailable()
|
|
||||||
} catch (t: Throwable) {
|
|
||||||
Timber.e("Failed to notify listener $it")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal fun notifyFailure(throwable: Throwable) {
|
|
||||||
|
|
||||||
listeners.forEach {
|
|
||||||
try {
|
|
||||||
it.onFailed(throwable)
|
|
||||||
} catch (t: Throwable) {
|
|
||||||
Timber.e("Failed to notify listener $it")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getService(): SyncService = this@SyncService
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
interface SyncListener {
|
|
||||||
fun onSyncFinsh()
|
|
||||||
fun networkNotAvailable()
|
|
||||||
fun onFailed(throwable: Throwable)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
const val EXTRA_USER_ID = "EXTRA_USER_ID"
|
const val EXTRA_USER_ID = "EXTRA_USER_ID"
|
||||||
|
|
||||||
fun startLongPool(delay: Long) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -21,7 +21,7 @@
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".fdroid.receiver.service.VectorSyncService"
|
android:name=".fdroid.service.VectorSyncService"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
|
@ -44,14 +44,12 @@ class AlarmSyncBroadcastReceiver : BroadcastReceiver() {
|
||||||
// This method is called when the BroadcastReceiver is receiving an Intent broadcast.
|
// This method is called when the BroadcastReceiver is receiving an Intent broadcast.
|
||||||
Timber.d("RestartBroadcastReceiver received intent")
|
Timber.d("RestartBroadcastReceiver received intent")
|
||||||
Intent(context, VectorSyncService::class.java).also {
|
Intent(context, VectorSyncService::class.java).also {
|
||||||
it.action = "SLOW"
|
|
||||||
it.putExtra(SyncService.EXTRA_USER_ID, userId)
|
it.putExtra(SyncService.EXTRA_USER_ID, userId)
|
||||||
context.startService(it)
|
|
||||||
try {
|
try {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
ContextCompat.startForegroundService(context, intent)
|
ContextCompat.startForegroundService(context, it)
|
||||||
} else {
|
} else {
|
||||||
context.startService(intent)
|
context.startService(it)
|
||||||
}
|
}
|
||||||
} catch (ex: Throwable) {
|
} catch (ex: Throwable) {
|
||||||
//TODO
|
//TODO
|
||||||
|
|
|
@ -27,13 +27,7 @@ import timber.log.Timber
|
||||||
|
|
||||||
class VectorSyncService : SyncService() {
|
class VectorSyncService : SyncService() {
|
||||||
|
|
||||||
override fun onCreate() {
|
|
||||||
Timber.v("VectorSyncService - onCreate")
|
|
||||||
super.onCreate()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
Timber.v("VectorSyncService - onDestroy")
|
|
||||||
removeForegroundNotif()
|
removeForegroundNotif()
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
@ -56,17 +50,4 @@ class VectorSyncService : SyncService() {
|
||||||
return super.onStartCommand(intent, flags, startId)
|
return super.onStartCommand(intent, flags, startId)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* If the service is bounded and the service was previously started we can remove foreground notification
|
|
||||||
*/
|
|
||||||
override fun onBind(intent: Intent?): IBinder {
|
|
||||||
Timber.v("VectorSyncService - onBind ")
|
|
||||||
stopForeground(true)
|
|
||||||
return super.onBind(intent)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onUnbind(intent: Intent?): Boolean {
|
|
||||||
Timber.v("VectorSyncService - onUnbind ")
|
|
||||||
return super.onUnbind(intent)
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue