-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
614 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
android/app/src/main/java/app/covidshield/extensions/ConfigurationExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
14 changes: 14 additions & 0 deletions
14
android/app/src/main/java/app/covidshield/extensions/ExposureInformationExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} |
12 changes: 12 additions & 0 deletions
12
android/app/src/main/java/app/covidshield/extensions/ExposureSummaryExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
android/app/src/main/java/app/covidshield/extensions/PromiseExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
126 changes: 122 additions & 4 deletions
126
android/app/src/main/java/app/covidshield/extensions/ReactNativeExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
26 changes: 26 additions & 0 deletions
26
android/app/src/main/java/app/covidshield/extensions/TaskExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
android/app/src/main/java/app/covidshield/extensions/TemporaryExposureKeyExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
android/app/src/main/java/app/covidshield/models/Configuration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
10
android/app/src/main/java/app/covidshield/models/ExposureKey.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
11
android/app/src/main/java/app/covidshield/models/Information.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
Oops, something went wrong.