Skip to content

Commit

Permalink
fix(deps): Update to Kotlin 1.8 + Awala dependencies (#582)
Browse files Browse the repository at this point in the history
Did some simple QA, planning to do more thorough QA with the 3 apps updated.
  • Loading branch information
sdsantos authored Mar 30, 2023
1 parent 8a09bf5 commit 117a8ae
Show file tree
Hide file tree
Showing 18 changed files with 303 additions and 254 deletions.
34 changes: 21 additions & 13 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ buildscript {

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.diffplug.spotless'
apply plugin: 'com.github.triplet.play'
Expand Down Expand Up @@ -74,6 +73,9 @@ android {
}
}
}
buildFeatures {
viewBinding true
}
compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility = JavaVersion.VERSION_1_8
Expand All @@ -83,13 +85,12 @@ android {
jvmTarget = JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'META-INF/*'
}
lintOptions {
checkAllWarnings true
warningsAsErrors true
abortOnError true
lintConfig file('lint.xml')
jniLibs {
excludes += ['META-INF/*']
}
resources {
excludes += ['META-INF/*']
}
}
sourceSets {
androidTest {
Expand All @@ -101,6 +102,13 @@ android {
resources.srcDirs += "src/sharedTest/resources"
}
}
lint {
abortOnError true
checkAllWarnings true
lintConfig file('lint.xml')
warningsAsErrors true
}
namespace 'tech.relaycorp.courier'
}

dependencies {
Expand All @@ -124,11 +132,11 @@ dependencies {
kapt 'com.google.dagger:dagger-compiler:2.43.2'

// Awala
implementation 'tech.relaycorp:awala:1.66.3'
implementation 'tech.relaycorp:cogrpc:1.1.27'
implementation 'tech.relaycorp:cogrpc-okhttp:1.1.15'
implementation 'tech.relaycorp:doh:1.0.13'
testImplementation "tech.relaycorp:awala-testing:1.5.8"
implementation 'tech.relaycorp:awala:1.66.4'
implementation 'tech.relaycorp:cogrpc:1.1.29'
implementation 'tech.relaycorp:cogrpc-okhttp:1.1.16'
implementation 'tech.relaycorp:doh:1.0.21'
testImplementation "tech.relaycorp:awala-testing:1.5.10"

// ORM
implementation "androidx.room:room-runtime:$roomVersion"
Expand Down
4 changes: 2 additions & 2 deletions app/firebase-test-lab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ spec:
test: app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk
timeout: 30m
device:
# Nexus 5X (virtual)
- model: Nexus5X
# Nexus 6 (virtual)
- model: Nexus6
version: 24 # Android 7.0
locale: en
orientation: portrait
Expand Down
2 changes: 2 additions & 0 deletions app/lint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<issue id="LockedOrientationActivity" severity="ignore"/>
<issue id="ConvertToWebp" severity="ignore"/>
<issue id="CheckResult" severity="informational"/>
<issue id="MonochromeLauncherIcon" severity="informational"/>
<issue id="InvalidPackage">
<!-- Ignore errors about BC importing javax.naming because we don't use those modules -->
<ignore path="**/bcpkix-*.jar" />
Expand All @@ -20,5 +21,6 @@
</issue>
<issue id="TrustAllX509TrustManager">
<ignore path="org/bouncycastle/est/jcajce/*.class" />
<ignore regexp="bcpkix-jdk15on" />
</issue>
</lint>
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="tech.relaycorp.courier">
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand Down
16 changes: 6 additions & 10 deletions app/src/main/java/tech/relaycorp/cogrpc/server/CogRPCServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ import java.net.InetSocketAddress
import java.security.Security
import java.util.concurrent.TimeUnit
import java.util.logging.Level
import kotlin.math.roundToLong
import kotlin.time.minutes
import kotlin.time.seconds
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds

class CogRPCServer
internal constructor(
Expand Down Expand Up @@ -54,12 +53,9 @@ internal constructor(
.maxInboundMessageSize(MAX_MESSAGE_SIZE)
.maxInboundMetadataSize(MAX_METADATA_SIZE)
.maxConcurrentCallsPerConnection(MAX_CONCURRENT_CALLS_PER_CONNECTION)
.maxConnectionAge(MAX_CONNECTION_AGE.inSeconds.roundToLong(), TimeUnit.SECONDS)
.maxConnectionAgeGrace(
MAX_CONNECTION_AGE_GRACE.inSeconds.roundToLong(),
TimeUnit.SECONDS
)
.maxConnectionIdle(MAX_CONNECTION_IDLE.inSeconds.roundToLong(), TimeUnit.SECONDS)
.maxConnectionAge(MAX_CONNECTION_AGE.inWholeSeconds, TimeUnit.SECONDS)
.maxConnectionAgeGrace(MAX_CONNECTION_AGE_GRACE.inWholeSeconds, TimeUnit.SECONDS)
.maxConnectionIdle(MAX_CONNECTION_IDLE.inWholeSeconds, TimeUnit.SECONDS)
.useTransportSecurity(
certGenerator.exportCertificate().inputStream(),
certGenerator.exportPrivateKey().inputStream()
Expand All @@ -83,7 +79,7 @@ internal constructor(
fun stop() {
server
?.shutdown()
?.awaitTermination(TERMINATION_TIMEOUT.inSeconds.toLong(), TimeUnit.SECONDS)
?.awaitTermination(TERMINATION_TIMEOUT.inWholeSeconds, TimeUnit.SECONDS)
server = null

job.cancel()
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/tech/relaycorp/courier/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AppModule(

@Provides
fun wifiApState(): WifiApStateAvailability =
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.TIRAMISU) {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.S_V2) {
WifiApStateAvailability.Available
} else {
WifiApStateAvailability.Unavailable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.withContext
import tech.relaycorp.courier.data.model.StorageSize
import javax.inject.Inject
import kotlin.time.seconds
import kotlin.time.Duration.Companion.seconds

class DiskStats
@Inject constructor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import tech.relaycorp.courier.domain.client.CargoDelivery
import tech.relaycorp.doh.DoHClient
import java.util.logging.Level
import javax.inject.Inject
import kotlin.time.seconds
import tech.relaycorp.courier.domain.client.InternetAddressResolver
import kotlin.time.Duration.Companion.seconds

class PublicSync
@Inject constructor(
Expand Down
14 changes: 9 additions & 5 deletions app/src/main/java/tech/relaycorp/courier/ui/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import android.widget.TextView
import androidx.annotation.DrawableRes
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.common_app_bar.appBar
import kotlinx.android.synthetic.main.common_app_bar.toolbar
import kotlinx.android.synthetic.main.common_app_bar.toolbarTitle
import androidx.appcompat.widget.Toolbar
import com.google.android.material.appbar.AppBarLayout
import tech.relaycorp.courier.App
import tech.relaycorp.courier.R
import tech.relaycorp.courier.ui.common.Insets.addSystemWindowInsetToPadding
Expand All @@ -21,6 +21,10 @@ abstract class BaseActivity : AppCompatActivity() {

protected val messageManager by lazy { MessageManager(this) }

private val appBar get() = findViewById<AppBarLayout?>(R.id.appBar)
private val toolbar get() = findViewById<Toolbar?>(R.id.toolbar)
private val toolbarTitle get() = findViewById<TextView?>(R.id.toolbarTitle)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Expand All @@ -35,8 +39,8 @@ abstract class BaseActivity : AppCompatActivity() {
}
}

override fun setContentView(layoutResID: Int) {
super.setContentView(layoutResID)
override fun setContentView(view: View?) {
super.setContentView(view)
toolbarTitle?.text = title
appBar?.addSystemWindowInsetToPadding(top = true)
}
Expand Down
61 changes: 25 additions & 36 deletions app/src/main/java/tech/relaycorp/courier/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,13 @@ import android.os.Bundle
import androidx.core.view.isVisible
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import kotlinx.android.synthetic.main.activity_main.hotspotIcon
import kotlinx.android.synthetic.main.activity_main.hotspotLabel
import kotlinx.android.synthetic.main.activity_main.innerContainer
import kotlinx.android.synthetic.main.activity_main.internetIcon
import kotlinx.android.synthetic.main.activity_main.internetLabel
import kotlinx.android.synthetic.main.activity_main.lowStorageMessage
import kotlinx.android.synthetic.main.activity_main.settings
import kotlinx.android.synthetic.main.activity_main.storageProgress
import kotlinx.android.synthetic.main.activity_main.storageValues
import kotlinx.android.synthetic.main.activity_main.syncInternetButton
import kotlinx.android.synthetic.main.activity_main.syncInternetLayout
import kotlinx.android.synthetic.main.activity_main.syncInternetMessage
import kotlinx.android.synthetic.main.activity_main.syncPeopleButton
import kotlinx.android.synthetic.main.activity_main.syncPeopleLayout
import kotlinx.android.synthetic.main.activity_main.syncPeopleMessage
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import tech.relaycorp.courier.R
import tech.relaycorp.courier.background.WifiHotspotState
import tech.relaycorp.courier.common.di.ViewModelFactory
import tech.relaycorp.courier.data.model.StorageUsage
import tech.relaycorp.courier.databinding.ActivityMainBinding
import tech.relaycorp.courier.ui.BaseActivity
import tech.relaycorp.courier.ui.common.Insets.addSystemWindowInsetToPadding
import tech.relaycorp.courier.ui.common.format
Expand All @@ -42,16 +28,19 @@ class MainActivity : BaseActivity() {
ViewModelProvider(this, viewModelFactory).get(MainViewModel::class.java)
}

private lateinit var binding: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
component.inject(this)
setTitle(R.string.main_title)
setContentView(R.layout.activity_main)
innerContainer.addSystemWindowInsetToPadding(bottom = true)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.innerContainer.addSystemWindowInsetToPadding(bottom = true)

settings.setOnClickListener { openSettings() }
syncPeopleButton.setOnClickListener { openSyncWithPeople() }
syncInternetButton.setOnClickListener { openSyncWithInternet() }
binding.settings.setOnClickListener { openSettings() }
binding.syncPeopleButton.setOnClickListener { openSyncWithPeople() }
binding.syncInternetButton.setOnClickListener { openSyncWithInternet() }

viewModel
.storageUsage()
Expand All @@ -60,7 +49,7 @@ class MainActivity : BaseActivity() {

viewModel
.lowStorageMessageIsVisible()
.onEach { lowStorageMessage.isVisible = it }
.onEach { binding.lowStorageMessage.isVisible = it }
.launchIn(lifecycleScope)

viewModel
Expand All @@ -84,8 +73,8 @@ class MainActivity : BaseActivity() {
}

private fun updateStorageUsage(usage: StorageUsage) {
storageProgress.progress = usage.percentage
storageValues.text = getString(
binding.storageProgress.progress = usage.percentage
binding.storageValues.text = getString(
R.string.main_storage_usage_values,
usage.usedByApp.format(this),
usage.actualMax.format(this)
Expand All @@ -94,28 +83,28 @@ class MainActivity : BaseActivity() {

private fun updateSyncPeopleState(state: MainViewModel.SyncPeopleState) {
val isEnabled = state is MainViewModel.SyncPeopleState.Enabled
syncPeopleLayout.isEnabled = isEnabled
syncPeopleButton.isEnabled = isEnabled
syncPeopleMessage.setText(
binding.syncPeopleLayout.isEnabled = isEnabled
binding.syncPeopleButton.isEnabled = isEnabled
binding.syncPeopleMessage.setText(
if (isEnabled) R.string.sync_people_enabled else R.string.sync_people_disabled
)

hotspotLabel.isVisible = isEnabled
hotspotIcon.isVisible = isEnabled
binding.hotspotLabel.isVisible = isEnabled
binding.hotspotIcon.isVisible = isEnabled
if (state is MainViewModel.SyncPeopleState.Enabled) {
val isHotspotEnabled = state.hotspotState == WifiHotspotState.Enabled
hotspotIcon.isActivated = isHotspotEnabled
hotspotLabel.setText(
binding.hotspotIcon.isActivated = isHotspotEnabled
binding.hotspotLabel.setText(
if (isHotspotEnabled) R.string.hotspot_on else R.string.hotspot_off
)
}
}

private fun updateSyncInternetState(state: MainViewModel.SyncInternetState) {
val isEnabled = state is MainViewModel.SyncInternetState.Enabled
syncInternetLayout.isEnabled = isEnabled
syncInternetButton.isEnabled = isEnabled
syncInternetMessage.setText(
binding.syncInternetLayout.isEnabled = isEnabled
binding.syncInternetButton.isEnabled = isEnabled
binding.syncInternetMessage.setText(
when (state) {
is MainViewModel.SyncInternetState.Enabled -> R.string.sync_internet_enabled
is MainViewModel.SyncInternetState.Disabled.Offline -> R.string.sync_internet_disabled_offline
Expand All @@ -124,9 +113,9 @@ class MainActivity : BaseActivity() {
}
)

internetLabel.isVisible = isEnabled
internetIcon.isVisible = isEnabled
internetIcon.isActivated = isEnabled
binding.internetLabel.isVisible = isEnabled
binding.internetIcon.isVisible = isEnabled
binding.internetIcon.isActivated = isEnabled
}

private fun openSettings() {
Expand Down
Loading

0 comments on commit 117a8ae

Please sign in to comment.