-
Notifications
You must be signed in to change notification settings - Fork 592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wear os authentication #1691
Wear os authentication #1691
Changes from 12 commits
ac5adc5
d4bf2c0
61919d5
25dcf96
ea45350
c0e319b
b90ec4c
efd31ad
98f965a
ce87f89
6c09dfc
d1b2544
0add411
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ google-services.json | |
.idea/ | ||
.gradle/ | ||
build/ | ||
*.keystore |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.homeassistant.companion.android.onboarding | ||
|
||
import dagger.Component | ||
import io.homeassistant.companion.android.common.dagger.AppComponent | ||
|
||
@Component(dependencies = [AppComponent::class]) | ||
interface OnboardingListenerComponent { | ||
|
||
fun inject(listener: WearOnboardingListener) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.homeassistant.companion.android.onboarding | ||
|
||
import android.util.Log | ||
import com.google.android.gms.wearable.MessageEvent | ||
import com.google.android.gms.wearable.PutDataMapRequest | ||
import com.google.android.gms.wearable.PutDataRequest | ||
import com.google.android.gms.wearable.Wearable | ||
import com.google.android.gms.wearable.WearableListenerService | ||
import io.homeassistant.companion.android.common.dagger.GraphComponentAccessor | ||
import io.homeassistant.companion.android.common.data.authentication.AuthenticationRepository | ||
import io.homeassistant.companion.android.common.data.url.UrlRepository | ||
import kotlinx.coroutines.runBlocking | ||
import javax.inject.Inject | ||
|
||
class WearOnboardingListener : WearableListenerService() { | ||
|
||
@Inject | ||
lateinit var authenticationUseCase: AuthenticationRepository | ||
|
||
@Inject | ||
lateinit var urlUseCase: UrlRepository | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
DaggerOnboardingListenerComponent.builder() | ||
.appComponent((applicationContext.applicationContext as GraphComponentAccessor).appComponent) | ||
.build() | ||
.inject(this) | ||
} | ||
|
||
override fun onMessageReceived(event: MessageEvent) { | ||
Log.d("WearOnboardingListener", "onMessageReceived: $event") | ||
|
||
if (event.path == "/request_home_assistant_instance") { | ||
val nodeId = event.sourceNodeId | ||
sendHomeAssistantInstance(nodeId) | ||
} | ||
} | ||
|
||
private fun sendHomeAssistantInstance(nodeId: String) = runBlocking { | ||
Log.d("WearOnboardingListener", "sendHomeAssistantInstance: $nodeId") | ||
// Retrieve current instance | ||
val url = urlUseCase.getUrl() | ||
|
||
// Put as DataMap in data layer | ||
val putDataReq: PutDataRequest = PutDataMapRequest.create("/home_assistant_instance").run { | ||
dataMap.putString("name", url?.host.toString()) | ||
dataMap.putString("url", url.toString()) | ||
setUrgent() | ||
asPutDataRequest() | ||
} | ||
Wearable.getDataClient(this@WearOnboardingListener).putDataItem(putDataReq).apply { | ||
addOnSuccessListener { Log.d("WearOnboardingListener", "sendHomeAssistantInstance: success") } | ||
addOnFailureListener { Log.d("WearOnboardingListener", "sendHomeAssistantInstance: failed") } | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources xmlns:tools="http://schemas.android.com/tools" | ||
tools:keep="@array/android_wear_capabilities"> | ||
<string-array name="android_wear_capabilities"> | ||
<item>request_authentication_token</item> | ||
<item>request_home_assistant_instance</item> | ||
</string-array> | ||
</resources> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.homeassistant.companion.android.common.data.authentication.impl.entities | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
data class LoginFlowAuthentication( | ||
@JsonProperty("client_id") | ||
val clientId: String, | ||
@JsonProperty("username") | ||
val userName: String, | ||
@JsonProperty("password") | ||
val password: String | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.homeassistant.companion.android.common.data.authentication.impl.entities | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
data class LoginFlowCreateEntry( | ||
@JsonProperty("version") | ||
val version: Int, | ||
@JsonProperty("type") | ||
val type: String, | ||
@JsonProperty("flow_id") | ||
val flowId: String, | ||
@JsonProperty("result") | ||
val result: String | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.homeassistant.companion.android.common.data.authentication.impl.entities | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
data class LoginFlowInit( | ||
@JsonProperty("type") | ||
val type: String, | ||
@JsonProperty("flow_id") | ||
val flowId: String, | ||
@JsonProperty("step_id") | ||
val stepId: String, | ||
@JsonProperty("errors") | ||
val errors: Map<String, String> | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.homeassistant.companion.android.common.data.authentication.impl.entities | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
|
||
data class LoginFlowRequest( | ||
@JsonProperty("client_id") | ||
val clientId: String, | ||
@JsonProperty("redirect_uri") | ||
val redirectUri: String, | ||
@JsonProperty("handler") | ||
val handler: List<String?> | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,25 @@ android { | |
signingConfig = signingConfigs.getByName("release") | ||
} | ||
} | ||
flavorDimensions("version") | ||
productFlavors { | ||
create("minimal") { | ||
applicationIdSuffix = ".minimal" | ||
versionNameSuffix = "-minimal" | ||
} | ||
create("full") { | ||
applicationIdSuffix = "" | ||
versionNameSuffix = "-full" | ||
} | ||
|
||
// Generate a list of application ids into BuildConfig | ||
val values = productFlavors.joinToString { | ||
"\"${it.applicationId ?: defaultConfig.applicationId}${it.applicationIdSuffix}\"" | ||
} | ||
|
||
defaultConfig.buildConfigField("String[]", "APPLICATION_IDS", "{$values}") | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need multiple flavors since there aren't any de-googled wear os devices. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right indeed, removed product flavors |
||
|
||
kotlinOptions { | ||
jvmTarget = "11" | ||
} | ||
|
@@ -65,9 +84,15 @@ android { | |
dependencies { | ||
implementation(project(":common")) | ||
|
||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.1") | ||
|
||
implementation("com.google.android.material:material:1.4.0") | ||
|
||
implementation("androidx.wear:wear:1.1.0") | ||
implementation("com.google.android.support:wearable:2.8.1") | ||
implementation("com.google.android.gms:play-services-wearable:17.1.0") | ||
compileOnly("com.google.android.wearable:wearable:2.8.1") | ||
|
||
implementation("com.google.dagger:dagger:2.38.1") | ||
kapt("com.google.dagger:dagger-compiler:2.38.1") | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra logging I don't think we need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, I used this for debugging. Have removed it now