Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakob Möller committed Jun 2, 2020
2 parents 90c49ae + 472f095 commit 36921e5
Show file tree
Hide file tree
Showing 90 changed files with 2,267 additions and 517 deletions.
5 changes: 2 additions & 3 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ Before submitting, please take the time to check the points below and provide so

* [ ] Test your changes as thoroughly as possible before you commit them. Preferably, automate your test by unit/integration tests.
* [ ] If this PR comes from a fork, please [Allow edits from maintainers](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/allowing-changes-to-a-pull-request-branch-created-from-a-fork)
* [ ] Set a speaking title. Format: {task_name} (closes #{issue_number}). For example: Use logger (closes #41)
* [ ] Set a speaking title. Format: {task_name} (closes #{issue_number}). For example: Use logger (closes # 41)
* [ ] [Link your Pull Request to an issue](https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue) (if applicable)
* [ ] Create Work In Progress [WIP] pull requests only if you need clarification or an explicit review before you can continue your work item.
* [ ] Make sure that your PR is not introducing _unncessary_ reformatting (e.g., introduced by on-save hooks in your IDE)
* [ ] Check our [Contribution Guidelines](https://github.com/corona-warn-app/cwa-app-android/blob/master/CONTRIBUTING.md)
* [ ] Make sure that your PR is not introducing _unnecessary_ reformatting (e.g., introduced by on-save hooks in your IDE)

## Description
<!-- Please be brief in describing which issue is solved by your PR or which enhancement it brings -->
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ The following rule governs documentation contributions:

## Pull Request Checklist

* Branch from the master branch and, if needed, rebase to the current master branch before submitting your pull request. If it doesn't merge cleanly with master, you may be asked to rebase your changes.
* Branch from the dev branch and ensure it is up to date with the current dev branch before submitting your pull request. If it doesn't merge cleanly with dev, you may be asked to resolve the conflicts. Pull requests to master will be closed.

* Commits should be as small as possible while ensuring that each commit is correct independently (i.e., each commit should compile and pass tests).

Expand Down
4 changes: 2 additions & 2 deletions Corona-Warn-App/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ android {
applicationId 'de.rki.coronawarnapp'
minSdkVersion 23
targetSdkVersion 29
versionCode 6
versionName "0.5.6"
versionCode 7
versionName "0.8.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

buildConfigField "String", "DOWNLOAD_CDN_URL", "\"$DOWNLOAD_CDN_URL\""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,52 @@ package de.rki.coronawarnapp

import android.app.Application
import android.content.Context
import android.util.Log
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import androidx.lifecycle.ProcessLifecycleOwner
import de.rki.coronawarnapp.notification.NotificationHelper

class CoronaWarnApplication : Application() {
class CoronaWarnApplication : Application(), LifecycleObserver {

companion object {
val TAG: String? = CoronaWarnApplication::class.simpleName
private lateinit var instance: CoronaWarnApplication

/* describes if the app is in foreground
* Initialized to false, because app could also be started by a background job.
* For the cases where the app is started via the launcher icon, the onAppForegrounded
* event will be called, setting it to true
*/
var isAppInForeground = false

fun getAppContext(): Context =
instance.applicationContext
}

override fun onCreate() {
instance = this
NotificationHelper.createNotificationChannel()
super.onCreate()
ProcessLifecycleOwner.get().lifecycle.addObserver(this)
}

/**
* Callback when the app is open but backgrounded
*/
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
fun onAppBackgrounded() {
isAppInForeground = false
Log.v(TAG, "App backgrounded")
}

/**
* Callback when the app is foregrounded
*/
@OnLifecycleEvent(Lifecycle.Event.ON_START)
fun onAppForegrounded() {
isAppInForeground = true
Log.v(TAG, "App foregrounded")
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.rki.coronawarnapp.exception

class RiskLevelCalculationException(cause: Throwable) :
Exception("an exception occured during risk level calculation", cause)
Exception("an exception occurred during risk level calculation", cause)
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ object WebRequestBuilder {
) =
suspendCoroutine<String> { cont ->
val requestID = UUID.randomUUID()
val getTestResultRequest =
val getTANRequest =
TanRequest(
url,
requestID,
Expand All @@ -209,7 +209,7 @@ object WebRequestBuilder {
},
RequestErrorListener(requestID, cont)
)
RequestQueueHolder.addToRequestQueue(getTestResultRequest)
RequestQueueHolder.addToRequestQueue(getTANRequest)
Log.d(TAG, "$requestID: Added $url to queue.")
}

Expand Down Expand Up @@ -254,7 +254,7 @@ object WebRequestBuilder {
Response.ErrorListener {
override fun onErrorResponse(error: VolleyError?) {
if (error != null) {
val webRequestException = WebRequestException("an error occured during a webrequest", error)
val webRequestException = WebRequestException("an error occurred during a webrequest", error)
webRequestException.report(de.rki.coronawarnapp.exception.ExceptionCategory.HTTP)
cont.resumeWithException(webRequestException)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object NotificationConstants {
/**
* Notification small icon String.xml path
*/
const val NOTIFICATION_SMALL_ICON = R.drawable.ic_app_launch_icon
const val NOTIFICATION_SMALL_ICON = R.drawable.ic_splash_logo

/**
* Notification channel name String.xml path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import kotlin.random.Random

/**
* Singleton class for notification handling
* Notifications should only be sent when the app is not in foreground.
* The helper uses externalised constants for readability.
*
* @see NotificationConstants
Expand Down Expand Up @@ -91,14 +92,23 @@ object NotificationHelper {
private fun buildNotification(title: String, content: String, visibility: Int): Notification? {
val builder = NotificationCompat.Builder(CoronaWarnApplication.getAppContext(), channelId)
.setSmallIcon(NotificationConstants.NOTIFICATION_SMALL_ICON)
.setContentTitle(title)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setVisibility(visibility)
.setContentIntent(createPendingIntentToMainActivity())
.setAutoCancel(true)

if (title.isNotEmpty()) {
builder.setContentTitle(title)
}

if (visibility == NotificationCompat.VISIBILITY_PRIVATE) {
builder.setPublicVersion(buildNotification(title, content, NotificationCompat.VISIBILITY_PUBLIC))
builder.setPublicVersion(
buildNotification(
title,
content,
NotificationCompat.VISIBILITY_PUBLIC
)
)
} else if (visibility == NotificationCompat.VISIBILITY_PUBLIC) {
builder.setContentText(content)
}
Expand Down Expand Up @@ -128,7 +138,6 @@ object NotificationHelper {
* @param visibility: Int
*/
fun sendNotification(title: String, content: String, visibility: Int) {
createNotificationChannel()
val notification = buildNotification(title, content, visibility) ?: return
with(NotificationManagerCompat.from(CoronaWarnApplication.getAppContext())) {
notify(Random.nextInt(), notification)
Expand All @@ -137,16 +146,16 @@ object NotificationHelper {

/**
* Send notification
* Build and send notification with predefined title and content.
* Visibility is auto set to NotificationCompat.VISIBILITY_PRIVATE
* Build and send notification with content and visibility.
* Notification is only sent if app is not in foreground.
*
* @param title: String
* @param content: String
*
* @see NotificationCompat.VISIBILITY_PRIVATE
* @param visibility: Int
*/
fun sendNotification(title: String, content: String) {
sendNotification(title, content, NotificationCompat.VISIBILITY_PRIVATE)
fun sendNotification(content: String, visibility: Int) {
if (!CoronaWarnApplication.isAppInForeground) {
sendNotification("", content, visibility)
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,41 @@ enum class RiskLevel(val raw: Int) {
else -> UNDETERMINED
}
}

// risk level categories
private val HIGH_RISK_LEVELS = arrayOf(INCREASED_RISK)
private val LOW_RISK_LEVELS = arrayOf(
UNKNOWN_RISK_INITIAL,
NO_CALCULATION_POSSIBLE_TRACING_OFF,
LOW_LEVEL_RISK,
UNKNOWN_RISK_OUTDATED_RESULTS,
UNDETERMINED
)

/**
* Checks if the RiskLevel has change from a high to low or from low to high
*
* @param previousRiskLevel previously persisted RiskLevel
* @param currentRiskLevel newly calculated RiskLevel
* @return
*/
fun riskLevelChangedBetweenLowAndHigh(
previousRiskLevel: RiskLevel,
currentRiskLevel: RiskLevel
): Boolean {
var riskLevelChangedBetweenLowAndHigh = false
if (HIGH_RISK_LEVELS.contains(previousRiskLevel) && LOW_RISK_LEVELS.contains(
currentRiskLevel
)
) {
riskLevelChangedBetweenLowAndHigh = true
} else if (LOW_RISK_LEVELS.contains(previousRiskLevel) && HIGH_RISK_LEVELS.contains(
currentRiskLevel
)
) {
riskLevelChangedBetweenLowAndHigh = true
}
return riskLevelChangedBetweenLowAndHigh
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ object SubmissionService {
testTAN != null -> asyncRegisterDeviceViaTAN(testTAN)
else -> throw NoGUIDOrTANSetException()
}
LocalData.devicePairingSuccessfulTimestamp(System.currentTimeMillis())
}

private suspend fun asyncRegisterDeviceViaGUID(guid: String) {
Expand Down Expand Up @@ -73,6 +74,7 @@ object SubmissionService {

fun deleteRegistrationToken() {
LocalData.registrationToken(null)
LocalData.devicePairingSuccessfulTimestamp(0L)
}

private fun deleteAuthCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import de.rki.coronawarnapp.storage.keycache.KeyCacheEntity
import de.rki.coronawarnapp.storage.tracing.TracingIntervalDao
import de.rki.coronawarnapp.storage.tracing.TracingIntervalEntity
import de.rki.coronawarnapp.util.Converters
import de.rki.coronawarnapp.util.security.SecurityHelper
import net.sqlcipher.database.SQLiteDatabase
import net.sqlcipher.database.SupportFactory
import java.util.UUID

@Database(
entities = [ExposureSummaryEntity::class, KeyCacheEntity::class, TracingIntervalEntity::class],
Expand All @@ -39,11 +39,8 @@ abstract class AppDatabase : RoomDatabase() {
fun resetInstance(context: Context) = { instance = null }.also { getInstance(context) }

private fun buildDatabase(context: Context): AppDatabase {
if (LocalData.databasePassword() == null) {
LocalData.databasePassword(UUID.randomUUID().toString().toCharArray())
}
return Room.databaseBuilder(context, AppDatabase::class.java, DATABASE_NAME)
.openHelperFactory(SupportFactory(SQLiteDatabase.getBytes(LocalData.databasePassword())))
.openHelperFactory(SupportFactory(SQLiteDatabase.getBytes(SecurityHelper.getDBPassword())))
.build()
}
}
Expand Down
Loading

0 comments on commit 36921e5

Please sign in to comment.