Skip to content
Snippets Groups Projects
Unverified Commit 1672693e authored by Rituraj Sambherao's avatar Rituraj Sambherao Committed by GitHub
Browse files

Implement specific logs to analyse (EXPOSUREAPP-3440) (#1563)


* improved logging for Bakcground Worker

* loggin added in updateRiskLevelScore

Notification Permissions logged and notification sent is loggged

* merge conflict resolution

* uniformity in Log tags

Co-authored-by: default avatarharambasicluka <64483219+harambasicluka@users.noreply.github.com>
parent 50de7f17
No related branches found
No related tags found
No related merge requests found
package de.rki.coronawarnapp.risk package de.rki.coronawarnapp.risk
import androidx.annotation.VisibleForTesting import androidx.annotation.VisibleForTesting
import androidx.core.app.NotificationManagerCompat
import com.google.android.gms.nearby.exposurenotification.ExposureSummary import com.google.android.gms.nearby.exposurenotification.ExposureSummary
import de.rki.coronawarnapp.CoronaWarnApplication import de.rki.coronawarnapp.CoronaWarnApplication
import de.rki.coronawarnapp.R import de.rki.coronawarnapp.R
...@@ -195,18 +196,30 @@ class DefaultRiskLevels @Inject constructor( ...@@ -195,18 +196,30 @@ class DefaultRiskLevels @Inject constructor(
@VisibleForTesting @VisibleForTesting
internal fun updateRiskLevelScore(riskLevel: RiskLevel) { internal fun updateRiskLevelScore(riskLevel: RiskLevel) {
val lastCalculatedScore = RiskLevelRepository.getLastCalculatedScore() val lastCalculatedScore = RiskLevelRepository.getLastCalculatedScore()
Timber.d("last CalculatedS core is ${lastCalculatedScore.raw} and Current Risk Level is ${riskLevel.raw}")
if (RiskLevel.riskLevelChangedBetweenLowAndHigh( if (RiskLevel.riskLevelChangedBetweenLowAndHigh(
lastCalculatedScore, lastCalculatedScore,
riskLevel riskLevel
) && !LocalData.submissionWasSuccessful() ) && !LocalData.submissionWasSuccessful()
) { ) {
Timber.d(
"Notification Permission = ${
NotificationManagerCompat.from(CoronaWarnApplication.getAppContext()).areNotificationsEnabled()
}"
)
NotificationHelper.sendNotification( NotificationHelper.sendNotification(
CoronaWarnApplication.getAppContext().getString(R.string.notification_body) CoronaWarnApplication.getAppContext().getString(R.string.notification_body)
) )
Timber.d("Risk level changed and notification sent. Current Risk level is ${riskLevel.raw}")
} }
if (lastCalculatedScore.raw == RiskLevelConstants.INCREASED_RISK && if (lastCalculatedScore.raw == RiskLevelConstants.INCREASED_RISK &&
riskLevel.raw == RiskLevelConstants.LOW_LEVEL_RISK) { riskLevel.raw == RiskLevelConstants.LOW_LEVEL_RISK) {
LocalData.isUserToBeNotifiedOfLoweredRiskLevel = true LocalData.isUserToBeNotifiedOfLoweredRiskLevel = true
Timber.d("Risk level changed LocalData is updated. Current Risk level is ${riskLevel.raw}")
} }
RiskLevelRepository.setRiskLevelScore(riskLevel) RiskLevelRepository.setRiskLevelScore(riskLevel)
} }
......
...@@ -7,6 +7,7 @@ import com.squareup.inject.assisted.Assisted ...@@ -7,6 +7,7 @@ import com.squareup.inject.assisted.Assisted
import com.squareup.inject.assisted.AssistedInject import com.squareup.inject.assisted.AssistedInject
import de.rki.coronawarnapp.playbook.Playbook import de.rki.coronawarnapp.playbook.Playbook
import de.rki.coronawarnapp.util.worker.InjectedWorkerFactory import de.rki.coronawarnapp.util.worker.InjectedWorkerFactory
import timber.log.Timber
/** /**
* One time background noise worker * One time background noise worker
...@@ -25,6 +26,7 @@ class BackgroundNoiseOneTimeWorker @AssistedInject constructor( ...@@ -25,6 +26,7 @@ class BackgroundNoiseOneTimeWorker @AssistedInject constructor(
* @return Result * @return Result
*/ */
override suspend fun doWork(): Result { override suspend fun doWork(): Result {
Timber.d("$id: doWork() started. Run attempt: $runAttemptCount")
var result = Result.success() var result = Result.success()
try { try {
...@@ -38,6 +40,7 @@ class BackgroundNoiseOneTimeWorker @AssistedInject constructor( ...@@ -38,6 +40,7 @@ class BackgroundNoiseOneTimeWorker @AssistedInject constructor(
} }
} }
Timber.d("$id: doWork() finished with %s", result)
return result return result
} }
......
...@@ -34,7 +34,7 @@ class BackgroundNoisePeriodicWorker @AssistedInject constructor( ...@@ -34,7 +34,7 @@ class BackgroundNoisePeriodicWorker @AssistedInject constructor(
* @see BackgroundConstants.NUMBER_OF_DAYS_TO_RUN_PLAYBOOK * @see BackgroundConstants.NUMBER_OF_DAYS_TO_RUN_PLAYBOOK
*/ */
override suspend fun doWork(): Result { override suspend fun doWork(): Result {
Timber.d("Background job started. Run attempt: $runAttemptCount") Timber.d("$id: doWork() started. Run attempt: $runAttemptCount")
var result = Result.success() var result = Result.success()
try { try {
...@@ -57,11 +57,13 @@ class BackgroundNoisePeriodicWorker @AssistedInject constructor( ...@@ -57,11 +57,13 @@ class BackgroundNoisePeriodicWorker @AssistedInject constructor(
Result.retry() Result.retry()
} }
} }
Timber.d("$id: doWork() finished with %s", result)
return result return result
} }
private fun stopWorker() { private fun stopWorker() {
BackgroundWorkScheduler.WorkType.BACKGROUND_NOISE_PERIODIC_WORK.stop() BackgroundWorkScheduler.WorkType.BACKGROUND_NOISE_PERIODIC_WORK.stop()
Timber.d("$id: worker stopped")
} }
@AssistedInject.Factory @AssistedInject.Factory
......
...@@ -43,19 +43,20 @@ class DiagnosisTestResultRetrievalPeriodicWorker @AssistedInject constructor( ...@@ -43,19 +43,20 @@ class DiagnosisTestResultRetrievalPeriodicWorker @AssistedInject constructor(
*/ */
override suspend fun doWork(): Result { override suspend fun doWork(): Result {
Timber.d("Background job started. Run attempt: $runAttemptCount") Timber.d("$id: doWork() started. Run attempt: $runAttemptCount")
BackgroundWorkHelper.sendDebugNotification( BackgroundWorkHelper.sendDebugNotification(
"TestResult Executing: Start", "TestResult started. Run attempt: $runAttemptCount " "TestResult Executing: Start", "TestResult started. Run attempt: $runAttemptCount "
) )
if (runAttemptCount > BackgroundConstants.WORKER_RETRY_COUNT_THRESHOLD) { if (runAttemptCount > BackgroundConstants.WORKER_RETRY_COUNT_THRESHOLD) {
Timber.d("Background job failed after $runAttemptCount attempts. Rescheduling") Timber.d("$id doWork() failed after $runAttemptCount attempts. Rescheduling")
BackgroundWorkHelper.sendDebugNotification( BackgroundWorkHelper.sendDebugNotification(
"TestResult Executing: Failure", "TestResult failed with $runAttemptCount attempts" "TestResult Executing: Failure", "TestResult failed with $runAttemptCount attempts"
) )
BackgroundWorkScheduler.scheduleDiagnosisKeyPeriodicWork() BackgroundWorkScheduler.scheduleDiagnosisKeyPeriodicWork()
Timber.d("$id Rescheduled background worker")
return Result.failure() return Result.failure()
} }
var result = Result.success() var result = Result.success()
...@@ -65,10 +66,13 @@ class DiagnosisTestResultRetrievalPeriodicWorker @AssistedInject constructor( ...@@ -65,10 +66,13 @@ class DiagnosisTestResultRetrievalPeriodicWorker @AssistedInject constructor(
System.currentTimeMillis() System.currentTimeMillis()
) < BackgroundConstants.POLLING_VALIDITY_MAX_DAYS ) < BackgroundConstants.POLLING_VALIDITY_MAX_DAYS
) { ) {
Timber.d(" $id maximum days not exceeded")
val testResult = SubmissionService.asyncRequestTestResult() val testResult = SubmissionService.asyncRequestTestResult()
initiateNotification(testResult) initiateNotification(testResult)
Timber.d(" $id Test Result Notification Initiated")
} else { } else {
stopWorker() stopWorker()
Timber.d(" $id worker stopped")
} }
} catch (e: Exception) { } catch (e: Exception) {
result = Result.retry() result = Result.retry()
...@@ -77,6 +81,7 @@ class DiagnosisTestResultRetrievalPeriodicWorker @AssistedInject constructor( ...@@ -77,6 +81,7 @@ class DiagnosisTestResultRetrievalPeriodicWorker @AssistedInject constructor(
BackgroundWorkHelper.sendDebugNotification( BackgroundWorkHelper.sendDebugNotification(
"TestResult Executing: End", "TestResult result: $result " "TestResult Executing: End", "TestResult result: $result "
) )
Timber.d("$id: doWork() finished with %s", result)
return result return result
} }
...@@ -94,9 +99,10 @@ class DiagnosisTestResultRetrievalPeriodicWorker @AssistedInject constructor( ...@@ -94,9 +99,10 @@ class DiagnosisTestResultRetrievalPeriodicWorker @AssistedInject constructor(
*/ */
private fun initiateNotification(testResult: TestResult) { private fun initiateNotification(testResult: TestResult) {
if (LocalData.isTestResultNotificationSent() || LocalData.submissionWasSuccessful()) { if (LocalData.isTestResultNotificationSent() || LocalData.submissionWasSuccessful()) {
Timber.d("$id: Notification already sent or there was a successful submission")
return return
} }
Timber.d("$id: Test Result retried is $testResult")
if (testResult == TestResult.NEGATIVE || testResult == TestResult.POSITIVE || if (testResult == TestResult.NEGATIVE || testResult == TestResult.POSITIVE ||
testResult == TestResult.INVALID testResult == TestResult.INVALID
) { ) {
...@@ -107,6 +113,7 @@ class DiagnosisTestResultRetrievalPeriodicWorker @AssistedInject constructor( ...@@ -107,6 +113,7 @@ class DiagnosisTestResultRetrievalPeriodicWorker @AssistedInject constructor(
CoronaWarnApplication.getAppContext() CoronaWarnApplication.getAppContext()
.getString(R.string.notification_body) .getString(R.string.notification_body)
) )
Timber.d("$id: Test Result available and notification is initiated")
} }
LocalData.isTestResultNotificationSent(true) LocalData.isTestResultNotificationSent(true)
stopWorker() stopWorker()
...@@ -122,7 +129,7 @@ class DiagnosisTestResultRetrievalPeriodicWorker @AssistedInject constructor( ...@@ -122,7 +129,7 @@ class DiagnosisTestResultRetrievalPeriodicWorker @AssistedInject constructor(
private fun stopWorker() { private fun stopWorker() {
LocalData.initialPollingForTestResultTimeStamp(0L) LocalData.initialPollingForTestResultTimeStamp(0L)
BackgroundWorkScheduler.WorkType.DIAGNOSIS_TEST_RESULT_PERIODIC_WORKER.stop() BackgroundWorkScheduler.WorkType.DIAGNOSIS_TEST_RESULT_PERIODIC_WORKER.stop()
Timber.d("$id: Background worker stopped")
BackgroundWorkHelper.sendDebugNotification( BackgroundWorkHelper.sendDebugNotification(
"TestResult Stopped", "TestResult Stopped" "TestResult Stopped", "TestResult Stopped"
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment