diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/CoronaWarnApplication.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/CoronaWarnApplication.kt index 437e912613c02caa91cc8978a56cdd95edbaf4a7..d70277f32c949c3f619b8d854844d652dbd2170b 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/CoronaWarnApplication.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/CoronaWarnApplication.kt @@ -6,6 +6,7 @@ import android.app.Application import android.content.Context import android.content.IntentFilter import android.content.pm.ActivityInfo +import android.net.wifi.WifiManager import android.os.Bundle import android.os.PowerManager import androidx.lifecycle.Lifecycle @@ -21,10 +22,12 @@ import de.rki.coronawarnapp.notification.NotificationHelper import de.rki.coronawarnapp.transaction.RetrieveDiagnosisKeysTransaction import de.rki.coronawarnapp.util.ConnectivityHelper import de.rki.coronawarnapp.worker.BackgroundWorkHelper +import de.rki.coronawarnapp.worker.BackgroundWorkScheduler import kotlinx.coroutines.launch import org.conscrypt.Conscrypt import timber.log.Timber import java.security.Security +import java.util.UUID class CoronaWarnApplication : Application(), LifecycleObserver, Application.ActivityLifecycleCallbacks, Configuration.Provider { @@ -73,10 +76,25 @@ class CoronaWarnApplication : Application(), LifecycleObserver, // job execution val wakeLock: PowerManager.WakeLock = (getSystemService(Context.POWER_SERVICE) as PowerManager).run { - newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG).apply { + newWakeLock( + PowerManager.PARTIAL_WAKE_LOCK, + TAG + "-WAKE-" + UUID.randomUUID().toString() + ).apply { acquire(TEN_MINUTE_TIMEOUT_IN_MS) } } + + // we keep a wifi lock to wake up the wifi connection in case the device is dozing + val wifiLock: WifiManager.WifiLock = + (getSystemService(Context.WIFI_SERVICE) as WifiManager).run { + createWifiLock( + WifiManager.WIFI_MODE_FULL_HIGH_PERF, + TAG + "-WIFI-" + UUID.randomUUID().toString() + ).apply { + acquire() + } + } + try { BackgroundWorkHelper.sendDebugNotification( "Automatic mode is on", "Check if we have downloaded keys already today" @@ -85,12 +103,16 @@ class CoronaWarnApplication : Application(), LifecycleObserver, } catch (e: Exception) { BackgroundWorkHelper.sendDebugNotification( "RetrieveDiagnosisKeysTransaction failed", - e.localizedMessage ?: "Unknown exception occurred in onCreate" + (e.localizedMessage + ?: "Unknown exception occurred in onCreate") + "\n\n" + (e.cause + ?: "Cause is unknown").toString() ) - wakeLock.release() + // retry the key retrieval in case of an error with a scheduled work + BackgroundWorkScheduler.scheduleDiagnosisKeyOneTimeWork() } - wakeLock.release() + if (wifiLock.isHeld) wifiLock.release() + if (wakeLock.isHeld) wakeLock.release() } } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/notification/NotificationHelper.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/notification/NotificationHelper.kt index 32a87c0c443bb10510f1bb6eac039334338c54d2..c09cb0746f727e887d75b6e64156cf63e2d922ed 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/notification/NotificationHelper.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/notification/NotificationHelper.kt @@ -94,7 +94,12 @@ object NotificationHelper { * * @see NotificationCompat.VISIBILITY_PUBLIC */ - private fun buildNotification(title: String, content: String, visibility: Int): Notification? { + private fun buildNotification( + title: String, + content: String, + visibility: Int, + expandableLongText: Boolean = false + ): Notification? { val builder = NotificationCompat.Builder(CoronaWarnApplication.getAppContext(), channelId) .setSmallIcon(NotificationConstants.NOTIFICATION_SMALL_ICON) .setPriority(NotificationCompat.PRIORITY_MAX) @@ -102,6 +107,14 @@ object NotificationHelper { .setContentIntent(createPendingIntentToMainActivity()) .setAutoCancel(true) + if (expandableLongText) { + builder + .setStyle( + NotificationCompat.BigTextStyle() + .bigText(content) + ) + } + if (title.isNotEmpty()) { builder.setContentTitle(title) } @@ -142,8 +155,14 @@ object NotificationHelper { * @param content: String * @param visibility: Int */ - fun sendNotification(title: String, content: String, visibility: Int) { - val notification = buildNotification(title, content, visibility) ?: return + fun sendNotification( + title: String, + content: String, + visibility: Int, + expandableLongText: Boolean = false + ) { + val notification = + buildNotification(title, content, visibility, expandableLongText) ?: return with(NotificationManagerCompat.from(CoronaWarnApplication.getAppContext())) { notify(Random.nextInt(), notification) } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/transaction/RetrieveDiagnosisKeysTransaction.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/transaction/RetrieveDiagnosisKeysTransaction.kt index 31c57b5cb904d82a6d40499ea28bfd11d002acb0..37f736283fd6be6574b05560cf7dab98c6646e65 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/transaction/RetrieveDiagnosisKeysTransaction.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/transaction/RetrieveDiagnosisKeysTransaction.kt @@ -128,7 +128,8 @@ object RetrieveDiagnosisKeysTransaction : Transaction() { currentDate.withTimeAtStartOfDay() != lastFetch.withTimeAtStartOfDay() ) { BackgroundWorkHelper.sendDebugNotification( - "Start RetrieveDiagnosisKeysTransaction", "No keys fetched today yet" + "Start RetrieveDiagnosisKeysTransaction", + "No keys fetched today yet \n${DateTime.now()}\nUTC: $currentDate" ) start() } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/BackgroundWorkHelper.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/BackgroundWorkHelper.kt index 5683037268bd820f8cb2ecce4bd70ce585f755d1..ddaac2c8a35b93de0f6230c5bab730219c152dde 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/BackgroundWorkHelper.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/BackgroundWorkHelper.kt @@ -74,6 +74,6 @@ object BackgroundWorkHelper { */ fun sendDebugNotification(title: String, content: String) { if (!LocalData.backgroundNotification()) return - NotificationHelper.sendNotification(title, content, NotificationCompat.PRIORITY_HIGH) + NotificationHelper.sendNotification(title, content, NotificationCompat.PRIORITY_HIGH, true) } }