Skip to content

Commit

Permalink
Better Wear Check (#4024)
Browse files Browse the repository at this point in the history
  • Loading branch information
yschimke authored Nov 25, 2023
1 parent 07dc72b commit da43981
Showing 1 changed file with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package io.homeassistant.companion.android.common.data

import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import android.webkit.CookieManager
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import dagger.hilt.android.qualifiers.ApplicationContext
import io.homeassistant.companion.android.common.BuildConfig
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
Expand All @@ -15,7 +18,8 @@ import java.util.concurrent.TimeUnit
import javax.inject.Inject

class HomeAssistantApis @Inject constructor(
private val tlsHelper: TLSHelper
private val tlsHelper: TLSHelper,
@ApplicationContext private val appContext: Context
) {
companion object {
private const val LOCAL_HOST = "http://localhost/"
Expand All @@ -41,18 +45,20 @@ class HomeAssistantApis @Inject constructor(
.build()
)
}
// Only deal with cookies when on non wear device and for now I don't have a better
// way to determine if we are really on wear os....
// TODO: Please fix me.
var cookieManager: CookieManager? = null
try {
cookieManager = CookieManager.getInstance()
} catch (e: Exception) {
// Noop
}
if (cookieManager != null) {
builder.cookieJar(CookieJarCookieManagerShim())

val isWear = appContext.packageManager.hasSystemFeature(PackageManager.FEATURE_WATCH)
if (!isWear) {
var cookieManager: CookieManager? = null
try {
cookieManager = CookieManager.getInstance()
} catch (e: Exception) {
// Noop
}
if (cookieManager != null) {
builder.cookieJar(CookieJarCookieManagerShim())
}
}

builder.callTimeout(CALL_TIMEOUT, TimeUnit.SECONDS)
builder.readTimeout(READ_TIMEOUT, TimeUnit.SECONDS)

Expand Down

0 comments on commit da43981

Please sign in to comment.