Skip to content

Commit

Permalink
Integrity check to identity (#800)
Browse files Browse the repository at this point in the history
* Move integrity check into identity module

* Add Push command for integrity check
  • Loading branch information
jraska authored Dec 20, 2022
1 parent 1c84171 commit 9375e08
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.jraska.github.client.identity

interface IntegrityTrigger {
fun executeIntegrityCheck()
}
16 changes: 13 additions & 3 deletions feature/identity/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
apply plugin: 'java-library'
apply plugin: 'com.android.lint'
apply plugin: 'kotlin'
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 33
defaultConfig {
minSdkVersion 26
}
}

dependencies {
implementation project(':core-api')
implementation project(':feature:identity-api')
implementation project(':feature:push-api')

implementation 'org.threeten:threetenbp:1.5.1:no-tzdb'
implementation 'com.jakewharton.timber:timber:5.0.1'
implementation okHttp
implementation coroutinesJvm

implementation 'com.google.android.play:integrity:1.0.2'

kapt daggerAnnotationProcessor
implementation dagger
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package com.jraska.github.client.identity

import com.jraska.github.client.identity.integrity.IntegrityCheck
import com.jraska.github.client.identity.integrity.IntegrityCheckPushCommand
import com.jraska.github.client.identity.internal.AddSessionIdInterceptor
import com.jraska.github.client.identity.internal.AnonymousIdentity
import com.jraska.github.client.identity.internal.SessionIdProvider
import com.jraska.github.client.push.PushActionCommand
import com.jraska.github.client.time.TimeProvider
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.multibindings.IntoMap
import dagger.multibindings.IntoSet
import dagger.multibindings.StringKey
import okhttp3.Interceptor
import javax.inject.Singleton

@Module
@Module(includes = [IdentityModule.Declarations::class])
object IdentityModule {

@Provides
Expand All @@ -33,4 +39,15 @@ object IdentityModule {
internal fun addSessionIdInterceptor(identityProvider: IdentityProvider): Interceptor {
return AddSessionIdInterceptor(identityProvider)
}

@Module
abstract class Declarations {
@Binds
abstract fun bindIntegrityCheckTrigger(integrityCheck: IntegrityCheck): IntegrityTrigger

@Binds
@IntoMap
@StringKey("integrity_check")
abstract fun bindIntegrityCheckCommand(integrityCheckTriggerCommand: IntegrityCheckPushCommand): PushActionCommand
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.jraska.github.client.settings
package com.jraska.github.client.identity.integrity

import android.content.Context
import com.google.android.gms.tasks.Tasks
import com.google.android.play.core.integrity.IntegrityManagerFactory
import com.google.android.play.core.integrity.IntegrityTokenRequest
import com.jraska.github.client.coroutines.AppDispatchers
import com.jraska.github.client.identity.IntegrityTrigger
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
Expand All @@ -15,9 +16,10 @@ import javax.inject.Inject
class IntegrityCheck @Inject constructor(
private val appDispatchers: AppDispatchers,
private val context: Context
) {
) : IntegrityTrigger {

@OptIn(DelicateCoroutinesApi::class)
fun run() {
override fun executeIntegrityCheck() {
GlobalScope.launch(appDispatchers.io) {
runInternal()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.jraska.github.client.identity.integrity

import com.jraska.github.client.identity.IntegrityTrigger
import com.jraska.github.client.push.PushAction
import com.jraska.github.client.push.PushActionCommand
import com.jraska.github.client.push.PushExecuteResult
import javax.inject.Inject

class IntegrityCheckPushCommand @Inject constructor(
private val integrityTrigger: IntegrityTrigger
) : PushActionCommand {
override fun execute(action: PushAction): PushExecuteResult {
integrityTrigger.executeIntegrityCheck()

return PushExecuteResult.SUCCESS
}
}
3 changes: 1 addition & 2 deletions feature/settings/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies {
implementation project(':core-api')
implementation project(':core-android-api')
implementation project(':feature:config-debug-api')
implementation project(':feature:identity-api')
implementation project(':navigation-api')
implementation project(':feature:ui-common-api')

Expand All @@ -30,8 +31,6 @@ dependencies {
implementation 'com.jakewharton.timber:timber:5.0.1'
implementation okHttp

implementation 'com.google.android.play:integrity:1.0.2'

implementation dagger
kapt daggerAnnotationProcessor

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import com.jraska.github.client.Owner
import com.jraska.github.client.analytics.AnalyticsEvent
import com.jraska.github.client.analytics.EventAnalytics
import com.jraska.github.client.config.debug.ui.ConfigRowModelProvider
import com.jraska.github.client.identity.IntegrityTrigger
import com.jraska.github.client.navigation.Urls
import javax.inject.Inject

internal class SettingsViewModel @Inject constructor(
private val eventAnalytics: EventAnalytics,
private val deepLinkLauncher: DeepLinkLauncher,
private val rowModelProvider: ConfigRowModelProvider,
private val integrityCheck: IntegrityCheck
private val integrityTrigger: IntegrityTrigger
) : ViewModel() {
fun onPurchaseSubmitted(value: String) {
val money = value.toDoubleOrNull() ?: return
Expand All @@ -33,7 +34,7 @@ internal class SettingsViewModel @Inject constructor(
}

fun onIntegrityCheckClicked() {
integrityCheck.run()
integrityTrigger.executeIntegrityCheck()
}

companion object {
Expand Down

0 comments on commit 9375e08

Please sign in to comment.