Skip to content

Commit

Permalink
chore(app): add logging level
Browse files Browse the repository at this point in the history
  • Loading branch information
gitmp01 committed Aug 9, 2024
1 parent 00a98d1 commit e732585
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def verifyStateHash = config.getProperty('build.verifyStateHash', 'false')
def writeStateHash = config.getProperty('build.writeStateHash', 'false')
def buildType = gradle.startParameter.taskNames.any { it.contains("Debug") } ? "debug" : "release"

def ksPath = config.getProperty('ks.path')
def ksPath = config.getProperty('ks.path', './')
def ksPassword = config.getProperty('ks.password')
def ksAlias = config.getProperty('ks.alias')

Expand Down Expand Up @@ -130,11 +130,12 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation "io.ktor:ktor-client-core:$ktorVersion"
implementation "io.ktor:ktor-client-cio:$ktorVersion"
implementation "io.ktor:ktor-client-logging:$ktorVersion"
implementation "io.ktor:ktor-client-websockets:$ktorVersion"
implementation "io.ktor:ktor-client-okhttp:$ktorVersion"
implementation 'commons-codec:commons-codec:1.17.0'
implementation 'org.web3j:core:4.8.7-android'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
}
24 changes: 16 additions & 8 deletions app/src/main/java/proofcastlabs/tee/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
package proofcastlabs.tee

import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.Bundle
import android.util.Log
import kotlinx.coroutines.runBlocking
import androidx.appcompat.app.AppCompatActivity
import io.ktor.client.*
import io.ktor.client.engine.okhttp.*
import io.ktor.client.plugins.logging.ANDROID
import io.ktor.client.plugins.logging.LogLevel
import io.ktor.client.plugins.logging.Logger
import io.ktor.client.plugins.logging.Logging
import io.ktor.client.plugins.websocket.*
import io.ktor.http.*
import io.ktor.websocket.*
Expand All @@ -33,12 +35,15 @@ class MainActivity : AppCompatActivity() {
private val WS_PING_INTERVAL = 55_000L
private val WS_DEFAULT_PORT = "3000"
private val WS_DEFAULT_HOST = "localhost"
private val WS_DEFAULT_TIMEOUT = 10_000L

private val INTENT_KEY_WS_HOST = "wsHost"
private val INTENT_KEY_WS_PORT = "wsPort"
private val INTENT_KEY_WS_TIMEOUT = "wsTimeout"

private var wsHost = "localhost"
private var wsPort = 3000
private var wsTimeout = WS_DEFAULT_TIMEOUT
private val verifyStateHash = BuildConfig.VERIFY_STATE_HASH.toBoolean()
private val writeStateHash = BuildConfig.WRITE_STATE_HASH.toBoolean()
private val isStrongboxBacked = BuildConfig.STRONGBOX_ENABLED.toBoolean()
Expand All @@ -56,10 +61,11 @@ class MainActivity : AppCompatActivity() {

suspend fun receiveWebsocketData(context: Context) {
client!!.webSocket(
method = HttpMethod.Get,
path = "/ws",
host = wsHost,
port = wsPort
// method = HttpMethod.Get,
// path = "/ws",
// host = wsHost,
// port = wsPort
"ws://$wsHost:$wsPort/ws"
) {
Log.i(TAG, "Websocket connected")
strongbox = Strongbox(context)
Expand Down Expand Up @@ -118,10 +124,12 @@ class MainActivity : AppCompatActivity() {
if (intent.extras != null) {
wsHost = intent.extras!!.getString(INTENT_KEY_WS_HOST, WS_DEFAULT_HOST)
wsPort = intent.extras!!.getString(INTENT_KEY_WS_PORT, WS_DEFAULT_PORT).toInt()
wsTimeout = intent.extras!!.getString(INTENT_KEY_WS_TIMEOUT, WS_DEFAULT_TIMEOUT.toString()).toLong()
}

Log.d(TAG, "Host: $wsHost")
Log.d(TAG, "Port: $wsPort")
Log.d(TAG, "Timeout: $wsTimeout")

val dns = object : Dns {
override fun lookup(hostname: String): List<InetAddress> {
Expand All @@ -132,15 +140,15 @@ class MainActivity : AppCompatActivity() {
}

val context = this
val timeout = Duration.ofSeconds(100L)
val timeout = Duration.ofMillis(wsTimeout)
client = HttpClient(OkHttp) {
engine { config {
dns(dns)
writeTimeout(timeout)
readTimeout(timeout)
connectTimeout(timeout)
} }

install(Logging) { level = LogLevel.ALL; logger = Logger.ANDROID }
install(WebSockets) { pingInterval = WS_PING_INTERVAL }
}

Expand Down

0 comments on commit e732585

Please sign in to comment.