Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanAtShopify committed Jun 1, 2020
2 parents e7437fc + 676abad commit 6b59e65
Show file tree
Hide file tree
Showing 30 changed files with 614 additions and 141 deletions.
8 changes: 6 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
APP_ID=app.covidshield
APP_ID_IOS=app.covidshield
APP_ID_ANDROID=app.covidshield
APP_VERSION_CODE=1
APP_VERSION_NAME=1.0
TEST_MODE=true

SUBMIT_URL=https://submission.covidshield.app
RETRIEVE_URL=https://retrieval.covidshield.app
HMAC_KEY=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

TEST_MODE=true
MOCK_SERVER=false
12 changes: 8 additions & 4 deletions .env.production
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
APP_ID=app.covidshield
APP_ID_IOS=app.covidshield
APP_ID_ANDROID=app.covidshield
APP_VERSION_CODE=1
APP_VERSION_NAME=1.0
TEST_MODE=false
SUBMIT_URL=https://submit.covidshield.app
RETRIEVE_URL=https://retrieve.covidshield.app

SUBMIT_URL=https://submission.covidshield.app
RETRIEVE_URL=https://retrieval.covidshield.app
HMAC_KEY=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

TEST_MODE=false
MOCK_SERVER=false
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ android {
}

defaultConfig {
applicationId project.env.get("APP_ID")
applicationId project.env.get("APP_ID_ANDROID")
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode project.env.get("APP_VERSION_CODE") as Integer
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package app.covidshield.extensions

import app.covidshield.models.Configuration
import com.google.android.gms.nearby.exposurenotification.ExposureConfiguration

fun Configuration.toExposureConfiguration(): ExposureConfiguration {
return ExposureConfiguration.ExposureConfigurationBuilder()
.setMinimumRiskScore(minimumRiskScore)
.setAttenuationScores(*attenuationLevelValues.toIntArray())
.setAttenuationWeight(attenuationWeight)
.setDaysSinceLastExposureScores(*daysSinceLastExposureLevelValues.toIntArray())
.setDaysSinceLastExposureWeight(daysSinceLastExposureWeight)
.setDurationScores(*durationLevelValues.toIntArray())
.setDurationWeight(durationWeight)
.setTransmissionRiskScores(*transmissionRiskLevelValues.toIntArray())
.setTransmissionRiskWeight(transmissionRiskWeight)
.build()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package app.covidshield.extensions

import app.covidshield.models.Information
import com.google.android.gms.nearby.exposurenotification.ExposureInformation

fun ExposureInformation.toInformation(): Information {
return Information(
attenuationValue = attenuationValue,
date = dateMillisSinceEpoch,
duration = durationMinutes,
totalRiskScore = totalRiskScore,
transmissionRiskLevel = transmissionRiskLevel
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package app.covidshield.extensions

import app.covidshield.models.Summary
import com.google.android.gms.nearby.exposurenotification.ExposureSummary

fun ExposureSummary.toSummary(): Summary {
return Summary(
daysSinceLastExposure = daysSinceLastExposure,
matchedKeyCount = matchedKeyCount,
maximumRiskScore = maximumRiskScore
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@ package app.covidshield.extensions

import com.google.gson.GsonBuilder

private val GSON = GsonBuilder()
.create()
private val GSON by lazy {
GsonBuilder().create()
}

fun <T> String?.parse(classOfT: Class<T>): T? {
return try {
GSON.fromJson(this, classOfT)
} catch (e: Exception) {
null
}
fun <T> String.parse(classOfT: Class<T>): T {
return GSON.fromJson(this, classOfT)
}

fun Any?.toJson(): String? {
return try {
GSON.toJson(this)
} catch (e: Exception) {
null
}
fun Any.toJson(): String {
return GSON.toJson(this)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package app.covidshield.extensions

import com.facebook.react.bridge.Promise

fun Promise.rejectOnException(block: () -> Unit) {
return try {
block.invoke()
} catch (e: Exception) {
reject(e)
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,132 @@
package app.covidshield.extensions

import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.bridge.ReadableType
import com.facebook.react.bridge.WritableArray
import com.facebook.react.bridge.WritableMap
import com.facebook.react.bridge.WritableNativeArray
import com.facebook.react.bridge.WritableNativeMap
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject

fun List<Any>.toWritableArray(): WritableArray {
return Arguments.fromList(this.toJson().parse(List::class.java))
return convertJsonToArray(this.toJson().parse(JSONArray::class.java))
}

fun Any.toWritableMap(): WritableMap {
// TODO: convert to map
return Arguments.createMap()
return convertJsonToMap(JSONObject(toJson()))
}

fun <T> ReadableMap.parse(classOfT: Class<T>): T {
return convertMapToJson(this)!!.toJson().parse(classOfT)
}

fun <T> ReadableArray.parse(classOfT: Class<T>): List<T> {
return toArrayList().map { it.toJson().parse(classOfT) }
}

@Throws(JSONException::class)
private fun convertJsonToMap(jsonObject: JSONObject): WritableMap {
val map: WritableMap = WritableNativeMap()
val iterator = jsonObject.keys()
while (iterator.hasNext()) {
val key = iterator.next()
when (val value = jsonObject[key]) {
is JSONObject -> {
map.putMap(key, convertJsonToMap(value))
}
is JSONArray -> {
map.putArray(key, convertJsonToArray(value))
}
is Boolean -> {
map.putBoolean(key, value)
}
is Int -> {
map.putInt(key, value)
}
is Double -> {
map.putDouble(key, value)
}
is String -> {
map.putString(key, value)
}
else -> {
map.putString(key, value.toString())
}
}
}
return map
}

@Throws(JSONException::class)
private fun convertJsonToArray(jsonArray: JSONArray): WritableArray {
val array: WritableArray = WritableNativeArray()
for (i in 0 until jsonArray.length()) {
when (val value = jsonArray[i]) {
is JSONObject -> {
array.pushMap(convertJsonToMap(value))
}
is JSONArray -> {
array.pushArray(convertJsonToArray(value))
}
is Boolean -> {
array.pushBoolean(value)
}
is Int -> {
array.pushInt(value)
}
is Double -> {
array.pushDouble(value)
}
is String -> {
array.pushString(value)
}
else -> {
array.pushString(value.toString())
}
}
}
return array
}

@Throws(JSONException::class)
private fun convertMapToJson(readableMap: ReadableMap?): JSONObject? {
if (readableMap == null) {
return null
}
val jsonObject = JSONObject()
val iterator = readableMap.keySetIterator()
while (iterator.hasNextKey()) {
val key = iterator.nextKey()
when (readableMap.getType(key)) {
ReadableType.Null -> jsonObject.put(key, JSONObject.NULL)
ReadableType.Boolean -> jsonObject.put(key, readableMap.getBoolean(key))
ReadableType.Number -> jsonObject.put(key, readableMap.getDouble(key))
ReadableType.String -> jsonObject.put(key, readableMap.getString(key))
ReadableType.Map -> jsonObject.put(key, convertMapToJson(readableMap.getMap(key)))
ReadableType.Array -> jsonObject.put(key, convertArrayToJson(readableMap.getArray(key)))
}
}
return jsonObject
}

@Throws(JSONException::class)
private fun convertArrayToJson(readableArray: ReadableArray?): JSONArray? {
if (readableArray == null) {
return null
}
val array = JSONArray()
for (i in 0 until readableArray.size()) {
when (readableArray.getType(i)) {
ReadableType.Null -> Unit
ReadableType.Boolean -> array.put(readableArray.getBoolean(i))
ReadableType.Number -> array.put(readableArray.getDouble(i))
ReadableType.String -> array.put(readableArray.getString(i))
ReadableType.Map -> array.put(convertMapToJson(readableArray.getMap(i)))
ReadableType.Array -> array.put(convertArrayToJson(readableArray.getArray(i)))
}
}
return array
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package app.covidshield.extensions

import com.facebook.react.bridge.Promise
import com.google.android.gms.tasks.Task

fun <T> Task<T>.bindPromise(promise: Promise, successBlock: Promise.(T) -> Unit) {
this.addOnFailureListener { promise.reject(it) }
.addOnSuccessListener {
try {
successBlock.invoke(promise, it)
} catch (exception: Exception) {
promise.reject(exception)
}
}
}

fun <T, R> Task<T>.bindPromise(promise: Promise, failureValue: R, successBlock: Promise.(T) -> Unit) {
this.addOnFailureListener { promise.resolve(failureValue) }
.addOnSuccessListener {
try {
successBlock.invoke(promise, it)
} catch (exception: Exception) {
promise.reject(exception)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package app.covidshield.extensions

import app.covidshield.models.ExposureKey
import com.google.android.gms.common.util.Hex
import com.google.android.gms.nearby.exposurenotification.TemporaryExposureKey

fun TemporaryExposureKey.toExposureKey(): ExposureKey {
return ExposureKey(
transmissionRiskLevel = transmissionRiskLevel,
keyData = Hex.bytesToStringLowercase(keyData),
rollingStartNumber = rollingStartIntervalNumber,
rollingStartIntervalNumber = rollingStartIntervalNumber
)
}
15 changes: 15 additions & 0 deletions android/app/src/main/java/app/covidshield/models/Configuration.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package app.covidshield.models

import com.google.gson.annotations.SerializedName

data class Configuration(
@SerializedName("minimumRiskScore") val minimumRiskScore: Int,
@SerializedName("attenuationLevelValues") val attenuationLevelValues: List<Int>,
@SerializedName("attenuationWeight") val attenuationWeight: Int,
@SerializedName("daysSinceLastExposureLevelValues") val daysSinceLastExposureLevelValues: List<Int>,
@SerializedName("daysSinceLastExposureWeight") val daysSinceLastExposureWeight: Int,
@SerializedName("durationLevelValues") val durationLevelValues: List<Int>,
@SerializedName("durationWeight") val durationWeight: Int,
@SerializedName("transmissionRiskLevelValues") val transmissionRiskLevelValues: List<Int>,
@SerializedName("transmissionRiskWeight") val transmissionRiskWeight: Int
)
10 changes: 10 additions & 0 deletions android/app/src/main/java/app/covidshield/models/ExposureKey.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package app.covidshield.models

import com.google.gson.annotations.SerializedName

data class ExposureKey(
@SerializedName("transmissionRiskLevel") val transmissionRiskLevel: Int,
@SerializedName("keyData") val keyData: String,
@SerializedName("rollingStartNumber") val rollingStartNumber: Int,
@SerializedName("rollingStartIntervalNumber") val rollingStartIntervalNumber: Int
)
11 changes: 11 additions & 0 deletions android/app/src/main/java/app/covidshield/models/Information.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package app.covidshield.models

import com.google.gson.annotations.SerializedName

data class Information(
@SerializedName("attenuationValue") val attenuationValue: Int,
@SerializedName("date") val date: Long,
@SerializedName("duration") val duration: Int,
@SerializedName("totalRiskScore") val totalRiskScore: Int,
@SerializedName("transmissionRiskLevel") val transmissionRiskLevel: Int
)
9 changes: 9 additions & 0 deletions android/app/src/main/java/app/covidshield/models/Summary.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package app.covidshield.models

import com.google.gson.annotations.SerializedName

data class Summary(
@SerializedName("daysSinceLastExposure") val daysSinceLastExposure: Int,
@SerializedName("matchedKeyCount") val matchedKeyCount: Int,
@SerializedName("maximumRiskScore") val maximumRiskScore: Int
)
Loading

0 comments on commit 6b59e65

Please sign in to comment.