Skip to content

Commit

Permalink
COVIDSafe code from version 1.0.28 (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
covidsafe-support committed Jun 19, 2020
1 parent 05a2ca9 commit c16533a
Show file tree
Hide file tree
Showing 35 changed files with 1,649 additions and 409 deletions.
8 changes: 6 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ android {
Before you increase the targetSdkVersion make sure that all its usage are still working
*/
targetSdkVersion 28
versionCode 21
versionName "1.0.21"
versionCode 28
versionName "1.0.28"
buildConfigField "String", "GITHASH", "\"${getGitHash()}\""
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand Down Expand Up @@ -243,6 +243,10 @@ dependencies {
implementation "androidx.lifecycle:lifecycle-service:2.2.0"
implementation 'com.github.razir.progressbutton:progressbutton:2.0.1'

// flags
implementation 'com.michaelfotiadis:android-country-flags:1.0.3'

androidTestImplementation "androidx.room:room-testing:2.2.5"


}
21 changes: 14 additions & 7 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="au.gov.health.covidsafe">

<uses-feature
android:name="android.hardware.bluetooth_le"
android:required="true" />

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

Expand All @@ -19,13 +20,14 @@

<application
android:name="au.gov.health.covidsafe.TracerApp"
tools:replace="android:supportsRtl"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/MyTheme.DayNight"
android:networkSecurityConfig="@xml/network_security_config">
android:theme="@style/MyTheme.DayNight">

<activity
android:name="au.gov.health.covidsafe.SplashActivity"
Expand All @@ -38,16 +40,21 @@
</activity>
<activity
android:name="au.gov.health.covidsafe.ui.onboarding.OnboardingActivity"
android:windowSoftInputMode="adjustPan"
android:screenOrientation="portrait" />
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />

<activity
android:name="au.gov.health.covidsafe.ui.onboarding.CountryCodeSelectionActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />

<activity
android:name="au.gov.health.covidsafe.WebViewActivity"
android:screenOrientation="portrait" />
<activity
android:name="au.gov.health.covidsafe.HomeActivity"
android:windowSoftInputMode="adjustPan"
android:screenOrientation="portrait" />
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />

<receiver android:name="au.gov.health.covidsafe.boot.StartOnBootReceiver">
<intent-filter>
Expand Down
45 changes: 44 additions & 1 deletion app/src/main/java/au/gov/health/covidsafe/Preference.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import au.gov.health.covidsafe.security.crypto.AESEncryptionForPreAndroidM
object Preference {
private const val PREF_ID = "Tracer_pref"
private const val IS_ONBOARDED = "IS_ONBOARDED"
private const val CALLING_CODE = "CALLING_CODE"
private const val AUSTRALIA_CALLING_CODE = 61
private const val COUNTRY_NAME_RES_ID = "COUNTRY_NAME"
private const val AUSTRALIA_COUNTRY_NAME_RES_ID = R.string.country_au
private const val NATIONAL_FLAG_RES_ID = "NATIONAL_FLAG_RES_ID"
private const val AUSTRALIA_NATIONAL_FLAG_RES_ID = R.drawable.ic_list_country_au
private const val PHONE_NUMBER = "PHONE_NUMBER"
private const val HANDSHAKE_PIN = "HANDSHAKE_PIN"
private const val DEVICE_ID = "DEVICE_ID"
Expand Down Expand Up @@ -41,7 +47,7 @@ object Preference {
.edit().putString(AES_IV, value)?.apply()
}

fun getEncodedAESInitialisationVector(context: Context) : String? {
fun getEncodedAESInitialisationVector(context: Context): String? {
return context.getSharedPreferences(PREF_ID, Context.MODE_PRIVATE)
.getString(AES_IV, null)
}
Expand Down Expand Up @@ -119,6 +125,43 @@ object Preference {
.edit().putString(PHONE_NUMBER, value).apply()
}

fun getPhoneNumber(context: Context): String {
return context.getSharedPreferences(PREF_ID, Context.MODE_PRIVATE)
?.getString(PHONE_NUMBER, "") ?: ""
}

fun putCallingCode(context: Context, value: Int) {
context.getSharedPreferences(PREF_ID, Context.MODE_PRIVATE)
.edit().putInt(CALLING_CODE, value).apply()
}

fun getCallingCode(context: Context): Int {
return context.getSharedPreferences(PREF_ID, Context.MODE_PRIVATE)
?.getInt(CALLING_CODE, AUSTRALIA_CALLING_CODE) ?: AUSTRALIA_CALLING_CODE
}

fun putCountryNameResID(context: Context, value: Int) {
context.getSharedPreferences(PREF_ID, Context.MODE_PRIVATE)
.edit().putInt(COUNTRY_NAME_RES_ID, value).apply()
}

fun getCountryNameResID(context: Context): Int {
return context.getSharedPreferences(PREF_ID, Context.MODE_PRIVATE)
?.getInt(COUNTRY_NAME_RES_ID, AUSTRALIA_COUNTRY_NAME_RES_ID)
?: AUSTRALIA_COUNTRY_NAME_RES_ID
}

fun putNationalFlagResID(context: Context, value: Int) {
context.getSharedPreferences(PREF_ID, Context.MODE_PRIVATE)
.edit().putInt(NATIONAL_FLAG_RES_ID, value).apply()
}

fun getNationalFlagResID(context: Context): Int {
return context.getSharedPreferences(PREF_ID, Context.MODE_PRIVATE)
?.getInt(NATIONAL_FLAG_RES_ID, AUSTRALIA_NATIONAL_FLAG_RES_ID)
?: AUSTRALIA_NATIONAL_FLAG_RES_ID
}

fun putNextFetchTimeInMillis(context: Context, time: Long) {
context.getSharedPreferences(PREF_ID, Context.MODE_PRIVATE)
.edit().putLong(NEXT_FETCH_TIME, time).apply()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.PowerManager
import android.provider.Settings
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.NotificationManagerCompat
import androidx.fragment.app.Fragment
import au.gov.health.covidsafe.R
import au.gov.health.covidsafe.Utils
import pub.devrel.easypermissions.AppSettingsDialog
import pub.devrel.easypermissions.EasyPermissions
import pub.devrel.easypermissions.PermissionRequest
import au.gov.health.covidsafe.R
import au.gov.health.covidsafe.Utils

const val REQUEST_ENABLE_BT = 123
const val LOCATION = 345
Expand Down Expand Up @@ -85,6 +86,22 @@ fun Fragment.excludeFromBatteryOptimization(onEndCallback: (() -> Unit)? = null)

}

fun Fragment.gotoPushNotificationSettings() {
val context = requireContext()
val intent = Intent()

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
intent.action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName)
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
intent.action = "android.settings.APP_NOTIFICATION_SETTINGS"
intent.putExtra("app_package", context.packageName)
intent.putExtra("app_uid", context.applicationInfo.uid)
}

context.startActivity(intent)
}

fun Fragment.isBlueToothEnabled(): Boolean? {
val bluetoothManager = activity?.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager?
return bluetoothManager?.adapter?.isEnabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class GetOnboardingOtp(private val awsClient: AwsClient, lifecycle: Lifecycle) :
override suspend fun run(params: GetOtpParams): Either<Exception, OTPChallengeResponse> {
return try {
val response = awsClient.initiateAuth(
OTPChallengeRequest(params.phoneNumber,
OTPChallengeRequest(
params.countryCode,
params.phoneNumber,
params.deviceId,
params.postCode,
params.age,
Expand Down Expand Up @@ -48,11 +50,14 @@ class GetOnboardingOtp(private val awsClient: AwsClient, lifecycle: Lifecycle) :
}
}

data class GetOtpParams(internal val phoneNumber: String,
internal val deviceId: String,
internal val postCode: String?,
internal val age: String?,
internal val name: String?)
data class GetOtpParams(
internal val countryCode: String,
internal val phoneNumber: String,
internal val deviceId: String,
internal val postCode: String?,
internal val age: String?,
internal val name: String?
)

sealed class GetOnboardingOtpException : Exception() {
class GetOtpServiceException(val code: Int? = null) : GetOnboardingOtpException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package au.gov.health.covidsafe.networking.request
import androidx.annotation.Keep

@Keep
data class OTPChallengeRequest(val phone_number: String,
val device_id: String,
val postcode: String?,
val age: String?,
val name: String?)
data class OTPChallengeRequest(
val country_code: String,
val phone_number: String,
val device_id: String,
val postcode: String?,
val age: String?,
val name: String?
)
22 changes: 14 additions & 8 deletions app/src/main/java/au/gov/health/covidsafe/streetpass/Work.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ package au.gov.health.covidsafe.streetpass
import android.bluetooth.BluetoothDevice
import android.bluetooth.BluetoothGatt
import android.content.Context
import com.google.gson.Gson
import android.os.Build
import au.gov.health.covidsafe.logging.CentralLog
import com.google.gson.Gson
import kotlin.properties.Delegates

class Work constructor(
var device: BluetoothDevice,
var connectable: ConnectablePeripheral,
private val onWorkTimeoutListener: OnWorkTimeoutListener
var device: BluetoothDevice,
var connectable: ConnectablePeripheral,
private val onWorkTimeoutListener: OnWorkTimeoutListener
) : Comparable<Work> {
var timeStamp: Long by Delegates.notNull()
var checklist = WorkCheckList()
var gatt: BluetoothGatt? = null
var finished = false
var timeout : Long = 0
var timeout: Long = 0

private val TAG = "Work"

Expand All @@ -33,10 +34,15 @@ class Work constructor(
}

fun startWork(
context: Context,
gattCallback: StreetPassWorker.StreetPassGattCallback
context: Context,
gattCallback: StreetPassWorker.StreetPassGattCallback
) {
gatt = device.connectGatt(context, false, gattCallback)
gatt = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
device.connectGatt(context, false, gattCallback, BluetoothDevice.TRANSPORT_LE)
} else {
device.connectGatt(context, false, gattCallback)
}

if (gatt == null) {
CentralLog.e(TAG, "Unable to connect to ${device.address}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ object Encryption {

private val NONCE_PADDING = ByteArray(14) { 0x0E.toByte() }
private val serverPubKey: PublicKey = readKey()
private val symCipher: Cipher = makeSymCipher()

private var cachedEphPubKey: ByteArray? = null
private var cachedAesKey: SecretKey? = null
Expand Down Expand Up @@ -131,6 +130,7 @@ object Encryption {
// IV = AES(ctr, iv=null), AES(plaintext, iv=IV) === AES(ctr_with_padding || plaintext, iv=null)
// Using the latter construction to reduce key expansions
val ivParams = IvParameterSpec(ByteArray(16)) // null IV
val symCipher: Cipher = makeSymCipher()
symCipher.init(Cipher.ENCRYPT_MODE, keys.aesKey, ivParams)
val ciphertextWithIV: ByteArray = symCipher.doFinal(keys.nonce.plus(NONCE_PADDING).plus(data))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class HomeFragment : BaseFragment(), EasyPermissions.PermissionCallbacks {
bluetooth_card_view.setOnClickListener { requestBlueToothPermissionThenNextPermission() }
location_card_view.setOnClickListener { askForLocationPermission() }
battery_card_view.setOnClickListener { excludeFromBatteryOptimization() }
push_card_view.setOnClickListener { gotoPushNotificationSettings() }

home_been_tested_button.setOnClickListener {
navigateTo(R.id.action_home_to_selfIsolate)
}
Expand Down Expand Up @@ -264,7 +266,11 @@ class HomeFragment : BaseFragment(), EasyPermissions.PermissionCallbacks {
private fun updatePushNotificationStatus() {
isPushNotificationEnabled()?.let {
push_card_view.visibility = VISIBLE
push_card_view.render(formatPushNotificationTitle(it), it)
push_card_view.render(
formatPushNotificationTitle(it),
it,
getString(R.string.home_app_permission_push_notification_prompt)
)
} ?: run {
push_card_view.visibility = GONE
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import android.content.Context
import android.content.res.TypedArray
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.core.content.ContextCompat
import au.gov.health.covidsafe.R
import au.gov.health.covidsafe.TracerApp
import kotlinx.android.synthetic.main.view_card_permission_card.view.*

class PermissionStatusCard @JvmOverloads constructor(
Expand All @@ -28,10 +31,20 @@ class PermissionStatusCard @JvmOverloads constructor(
layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height)
}

fun render(text: String, correct: Boolean) {
fun render(title: String, correct: Boolean, body: String? = null) {
val errorTextColor = ContextCompat.getColor(TracerApp.AppContext, R.color.error)
val normalTextColor = ContextCompat.getColor(TracerApp.AppContext, R.color.slack_black)

permission_icon.isSelected = correct
permission_title.text = text
permission_title.text = title
permission_title.setTextColor(if (correct) normalTextColor else errorTextColor)

if (correct || body == null) {
permission_body.visibility = View.GONE
} else {
permission_body.visibility = View.VISIBLE
permission_body.text = body
permission_body.setTextColor(if (correct) normalTextColor else errorTextColor)
}
}


}
Loading

0 comments on commit c16533a

Please sign in to comment.