mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-23 18:05:59 +03:00
Merge pull request #226 from vector-im/feature/notification_beta
Notification beta
This commit is contained in:
commit
9ec364b60e
23 changed files with 140 additions and 73 deletions
|
@ -36,12 +36,15 @@ internal class BingRuleWatcher(monarchy: Monarchy,
|
|||
override val query = Monarchy.Query<EventEntity> {
|
||||
|
||||
EventEntity.types(it, listOf(
|
||||
EventType.REDACTION, EventType.MESSAGE, EventType.REDACTION, EventType.ENCRYPTED)
|
||||
EventType.MESSAGE,
|
||||
EventType.REDACTION,
|
||||
EventType.ENCRYPTED)
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
override fun processChanges(inserted: List<EventEntity>, updated: List<EventEntity>, deleted: List<EventEntity>) {
|
||||
// TODO Use const for "global"
|
||||
val rules = defaultPushRuleService.getPushRules("global")
|
||||
inserted.map { it.asDomain() }
|
||||
.filter { it.senderId != sessionParams.credentials.userId }
|
||||
|
|
|
@ -33,7 +33,8 @@ internal class DefaultProcessEventForPushTask(
|
|||
|
||||
private fun fulfilledBingRule(event: Event, rules: List<PushRule>): PushRule? {
|
||||
val conditionResolver = DefaultConditionResolver(event)
|
||||
rules.filter { it.enabled }.forEach { rule ->
|
||||
rules.filter { it.enabled }
|
||||
.forEach { rule ->
|
||||
val isFullfilled = rule.conditions?.map {
|
||||
it.asExecutableCondition()?.isSatisfied(conditionResolver) ?: false
|
||||
}?.fold(true/*A rule with no conditions always matches*/, { acc, next ->
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
<application>
|
||||
|
||||
<receiver android:name=".receiver.OnApplicationUpgradeOrRebootReceiver">
|
||||
<receiver android:name="im.vector.riotredesign.fdroid.receiver.OnApplicationUpgradeOrRebootReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
|
@ -16,10 +16,14 @@
|
|||
</receiver>
|
||||
|
||||
<receiver
|
||||
android:name=".core.services.AlarmSyncBroadcastReceiver"
|
||||
android:name="im.vector.riotredesign.fdroid.receiver.AlarmSyncBroadcastReceiver"
|
||||
android:enabled="true"
|
||||
android:exported="false" />
|
||||
|
||||
<service
|
||||
android:name=".fdroid.receiver.service.VectorSyncService"
|
||||
android:exported="false" />
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package im.vector.riotredesign.push.fcm.troubleshoot
|
||||
package im.vector.riotredesign.fdroid.features.settings.troubleshoot
|
||||
|
||||
import androidx.fragment.app.Fragment
|
||||
import im.vector.riotredesign.R
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package im.vector.riotredesign.push.fcm.troubleshoot
|
||||
package im.vector.riotredesign.fdroid.features.settings.troubleshoot
|
||||
|
||||
import android.content.Context
|
||||
import android.net.ConnectivityManager
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package im.vector.riotredesign.push.fcm.troubleshoot
|
||||
package im.vector.riotredesign.fdroid.features.settings.troubleshoot
|
||||
|
||||
import androidx.fragment.app.Fragment
|
||||
import im.vector.riotredesign.R
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Copyright 2019 New Vector Ltd
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Code exclusively used by the FDroid build and not referenced on the main source code
|
||||
*/
|
||||
package im.vector.riotredesign.fdroid
|
|
@ -1,4 +1,20 @@
|
|||
package im.vector.riotredesign.core.services
|
||||
/*
|
||||
* Copyright 2019 New Vector Ltd
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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.
|
||||
*/
|
||||
|
||||
package im.vector.riotredesign.fdroid.receiver
|
||||
|
||||
import android.app.AlarmManager
|
||||
import android.app.PendingIntent
|
||||
|
@ -8,6 +24,7 @@ import android.content.Intent
|
|||
import android.os.Build
|
||||
import android.os.PowerManager
|
||||
import androidx.core.content.ContextCompat
|
||||
import im.vector.riotredesign.fdroid.service.VectorSyncService
|
||||
import timber.log.Timber
|
||||
|
||||
class AlarmSyncBroadcastReceiver : BroadcastReceiver() {
|
||||
|
@ -46,13 +63,12 @@ class AlarmSyncBroadcastReceiver : BroadcastReceiver() {
|
|||
}
|
||||
|
||||
companion object {
|
||||
const val REQUEST_CODE = 0
|
||||
private const val REQUEST_CODE = 0
|
||||
|
||||
fun scheduleAlarm(context: Context, delay: Long) {
|
||||
//Reschedule
|
||||
val intent = Intent(context, AlarmSyncBroadcastReceiver::class.java)
|
||||
val pIntent = PendingIntent.getBroadcast(context, AlarmSyncBroadcastReceiver.REQUEST_CODE,
|
||||
intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val pIntent = PendingIntent.getBroadcast(context, REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val firstMillis = System.currentTimeMillis() + delay
|
||||
val alarmMgr = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
|
@ -64,8 +80,7 @@ class AlarmSyncBroadcastReceiver : BroadcastReceiver() {
|
|||
|
||||
fun cancelAlarm(context: Context) {
|
||||
val intent = Intent(context, AlarmSyncBroadcastReceiver::class.java)
|
||||
val pIntent = PendingIntent.getBroadcast(context, AlarmSyncBroadcastReceiver.REQUEST_CODE,
|
||||
intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val pIntent = PendingIntent.getBroadcast(context, REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val alarmMgr = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
alarmMgr.cancel(pIntent)
|
||||
}
|
|
@ -15,12 +15,11 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.riotredesign.receiver
|
||||
package im.vector.riotredesign.fdroid.receiver
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import im.vector.riotredesign.core.services.AlarmSyncBroadcastReceiver
|
||||
import timber.log.Timber
|
||||
|
||||
class OnApplicationUpgradeOrRebootReceiver : BroadcastReceiver() {
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package im.vector.riotredesign.core.services
|
||||
package im.vector.riotredesign.fdroid.service
|
||||
|
||||
import android.app.NotificationManager
|
||||
import android.content.Context
|
||||
|
@ -57,7 +57,7 @@ class VectorSyncService : SyncService() {
|
|||
}
|
||||
|
||||
/**
|
||||
* If the service is bounded and the service was previously started we can remove foreground notif
|
||||
* 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 ")
|
|
@ -18,9 +18,14 @@ package im.vector.riotredesign.push.fcm
|
|||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
|
||||
import im.vector.riotredesign.core.pushers.PushersManager
|
||||
import im.vector.riotredesign.fdroid.receiver.AlarmSyncBroadcastReceiver
|
||||
import im.vector.riotredesign.features.settings.PreferencesManager
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
* This class has an alter ego in the gplay variant.
|
||||
*/
|
||||
object FcmHelper {
|
||||
|
||||
fun isPushSupported(): Boolean = false
|
||||
|
@ -52,4 +57,17 @@ object FcmHelper {
|
|||
fun ensureFcmTokenIsRetrieved(activity: Activity, pushersManager: PushersManager) {
|
||||
// No op
|
||||
}
|
||||
|
||||
fun onEnterForeground(context: Context) {
|
||||
AlarmSyncBroadcastReceiver.cancelAlarm(context)
|
||||
}
|
||||
|
||||
fun onEnterBackground(context: Context, hasSession: Boolean) {
|
||||
//We need to use alarm in this mode
|
||||
if (PreferencesManager.areNotificationEnabledForDevice(context)
|
||||
&& hasSession) {
|
||||
AlarmSyncBroadcastReceiver.scheduleAlarm(context, 4_000L)
|
||||
Timber.i("Alarm scheduled to restart service")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,9 +17,9 @@ package im.vector.riotredesign.push.fcm
|
|||
|
||||
import androidx.fragment.app.Fragment
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import im.vector.riotredesign.fdroid.features.settings.troubleshoot.TestAutoStartBoot
|
||||
import im.vector.riotredesign.fdroid.features.settings.troubleshoot.TestBackgroundRestrictions
|
||||
import im.vector.riotredesign.features.settings.troubleshoot.*
|
||||
import im.vector.riotredesign.push.fcm.troubleshoot.TestAutoStartBoot
|
||||
import im.vector.riotredesign.push.fcm.troubleshoot.TestBackgroundRestrictions
|
||||
|
||||
class NotificationTroubleshootTestManagerFactory {
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
android:name="firebase_analytics_collection_deactivated"
|
||||
android:value="true" />
|
||||
|
||||
<service android:name=".push.fcm.VectorFirebaseMessagingService">
|
||||
<service android:name=".gplay.push.fcm.VectorFirebaseMessagingService">
|
||||
<intent-filter>
|
||||
<action android:name="com.google.firebase.MESSAGING_EVENT" />
|
||||
</intent-filter>
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package im.vector.riotredesign.push.fcm.troubleshoot
|
||||
package im.vector.riotredesign.gplay.features.settings.troubleshoot
|
||||
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.google.firebase.iid.FirebaseInstanceId
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package im.vector.riotredesign.push.fcm.troubleshoot
|
||||
package im.vector.riotredesign.gplay.features.settings.troubleshoot
|
||||
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.google.android.gms.common.ConnectionResult
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package im.vector.riotredesign.push.fcm.troubleshoot
|
||||
package im.vector.riotredesign.gplay.features.settings.troubleshoot
|
||||
|
||||
import androidx.fragment.app.Fragment
|
||||
import im.vector.riotredesign.R
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright 2019 New Vector Ltd
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Code exclusively used by the GPlay build and not referenced on the main source code
|
||||
*/
|
||||
package im.vector.riotredesign.gplay
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.riotredesign.push.fcm
|
||||
package im.vector.riotredesign.gplay.push.fcm
|
||||
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
|
@ -39,6 +39,7 @@ import im.vector.riotredesign.features.notifications.NotifiableMessageEvent
|
|||
import im.vector.riotredesign.features.notifications.NotificationDrawerManager
|
||||
import im.vector.riotredesign.features.notifications.SimpleNotifiableEvent
|
||||
import im.vector.riotredesign.features.settings.PreferencesManager
|
||||
import im.vector.riotredesign.push.fcm.FcmHelper
|
||||
import org.koin.android.ext.android.inject
|
||||
import timber.log.Timber
|
||||
|
|
@ -99,4 +99,12 @@ object FcmHelper {
|
|||
val resultCode = apiAvailability.isGooglePlayServicesAvailable(activity)
|
||||
return resultCode == ConnectionResult.SUCCESS
|
||||
}
|
||||
|
||||
fun onEnterForeground(context: Context) {
|
||||
// No op
|
||||
}
|
||||
|
||||
fun onEnterBackground(context: Context, hasSession: Boolean) {
|
||||
// TODO FCM fallback
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,9 @@ package im.vector.riotredesign.push.fcm
|
|||
import androidx.fragment.app.Fragment
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import im.vector.riotredesign.features.settings.troubleshoot.*
|
||||
import im.vector.riotredesign.push.fcm.troubleshoot.TestFirebaseToken
|
||||
import im.vector.riotredesign.push.fcm.troubleshoot.TestPlayServices
|
||||
import im.vector.riotredesign.push.fcm.troubleshoot.TestTokenRegistration
|
||||
import im.vector.riotredesign.gplay.features.settings.troubleshoot.TestFirebaseToken
|
||||
import im.vector.riotredesign.gplay.features.settings.troubleshoot.TestPlayServices
|
||||
import im.vector.riotredesign.gplay.features.settings.troubleshoot.TestTokenRegistration
|
||||
|
||||
class NotificationTroubleshootTestManagerFactory {
|
||||
|
||||
|
|
|
@ -68,15 +68,6 @@
|
|||
<service
|
||||
android:name=".core.services.CallService"
|
||||
android:exported="false" />
|
||||
<!--<service-->
|
||||
<!--android:name="im.vector.matrix.android.internal.session.sync.job.SyncService"-->
|
||||
<!--android:exported="false" />-->
|
||||
|
||||
<service
|
||||
android:name=".core.services.VectorSyncService"
|
||||
android:exported="false">
|
||||
|
||||
</service>
|
||||
|
||||
<!-- Receivers -->
|
||||
|
||||
|
|
|
@ -36,7 +36,6 @@ import com.github.piasy.biv.loader.glide.GlideImageLoader
|
|||
import com.jakewharton.threetenabp.AndroidThreeTen
|
||||
import im.vector.matrix.android.api.Matrix
|
||||
import im.vector.riotredesign.core.di.AppModule
|
||||
import im.vector.riotredesign.core.services.AlarmSyncBroadcastReceiver
|
||||
import im.vector.riotredesign.features.configuration.VectorConfiguration
|
||||
import im.vector.riotredesign.features.crypto.keysbackup.KeysBackupModule
|
||||
import im.vector.riotredesign.features.home.HomeModule
|
||||
|
@ -47,7 +46,6 @@ import im.vector.riotredesign.features.notifications.PushRuleTriggerListener
|
|||
import im.vector.riotredesign.features.rageshake.VectorFileLogger
|
||||
import im.vector.riotredesign.features.rageshake.VectorUncaughtExceptionHandler
|
||||
import im.vector.riotredesign.features.roomdirectory.RoomDirectoryModule
|
||||
import im.vector.riotredesign.features.settings.PreferencesManager
|
||||
import im.vector.riotredesign.features.version.getVersion
|
||||
import im.vector.riotredesign.push.fcm.FcmHelper
|
||||
import org.koin.android.ext.android.get
|
||||
|
@ -117,7 +115,7 @@ class VectorApplication : Application() {
|
|||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||
fun entersForeground() {
|
||||
AlarmSyncBroadcastReceiver.cancelAlarm(appContext)
|
||||
FcmHelper.onEnterForeground(appContext)
|
||||
Matrix.getInstance().currentSession?.also {
|
||||
it.stopAnyBackgroundSync()
|
||||
}
|
||||
|
@ -129,20 +127,8 @@ class VectorApplication : Application() {
|
|||
|
||||
notificationDrawerManager.persistInfo()
|
||||
|
||||
if (FcmHelper.isPushSupported()) {
|
||||
//TODO FCM fallback
|
||||
} else {
|
||||
//TODO check if notifications are enabled for this device
|
||||
//We need to use alarm in this mode
|
||||
if (PreferencesManager.areNotificationEnabledForDevice(applicationContext)) {
|
||||
if (Matrix.getInstance().currentSession != null) {
|
||||
AlarmSyncBroadcastReceiver.scheduleAlarm(applicationContext, 4_000L)
|
||||
Timber.i("Alarm scheduled to restart service")
|
||||
FcmHelper.onEnterBackground(appContext, Matrix.getInstance().currentSession != null)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ import timber.log.Timber
|
|||
|
||||
class PushRuleTriggerListener(
|
||||
private val resolver: NotifiableEventResolver,
|
||||
private val drawerManager: NotificationDrawerManager
|
||||
private val notificationDrawerManager: NotificationDrawerManager
|
||||
) : PushRuleService.PushRuleListener {
|
||||
|
||||
|
||||
|
@ -39,14 +39,14 @@ class PushRuleTriggerListener(
|
|||
}
|
||||
val notificationAction = NotificationAction.extractFrom(actions)
|
||||
if (notificationAction.shouldNotify) {
|
||||
val resolveEvent = resolver.resolveEvent(event, session!!)
|
||||
if (resolveEvent == null) {
|
||||
val notifiableEvent = resolver.resolveEvent(event, session!!)
|
||||
if (notifiableEvent == null) {
|
||||
Timber.v("## Failed to resolve event")
|
||||
//TODO
|
||||
} else {
|
||||
resolveEvent.noisy = !notificationAction.soundName.isNullOrBlank()
|
||||
Timber.v("New event to notify $resolveEvent tweaks:$notificationAction")
|
||||
drawerManager.onNotifiableEventReceived(resolveEvent)
|
||||
notifiableEvent.noisy = !notificationAction.soundName.isNullOrBlank()
|
||||
Timber.v("New event to notify $notifiableEvent tweaks:$notificationAction")
|
||||
notificationDrawerManager.onNotifiableEventReceived(notifiableEvent)
|
||||
}
|
||||
} else {
|
||||
Timber.v("Matched push rule is set to not notify")
|
||||
|
@ -54,7 +54,7 @@ class PushRuleTriggerListener(
|
|||
}
|
||||
|
||||
override fun batchFinish() {
|
||||
drawerManager.refreshNotificationDrawer()
|
||||
notificationDrawerManager.refreshNotificationDrawer()
|
||||
}
|
||||
|
||||
fun startWithSession(session: Session) {
|
||||
|
@ -68,7 +68,7 @@ class PushRuleTriggerListener(
|
|||
fun stop() {
|
||||
session?.removePushRuleListener(this)
|
||||
session = null
|
||||
drawerManager.clearAllEvents()
|
||||
notificationDrawerManager.clearAllEvents()
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue