-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISSUE-646: Clean semantics flaky safety interceptor (#670)
* ISSUE-646: Clean semantics flaky safety interceptor * ISSUE-646: Docs * ISSUE-646: Add synchronized block * ISSUE-646: Make ComposeFlakySafetyScalper internal
- Loading branch information
Showing
6 changed files
with
103 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...ain/java/com/kaspersky/components/composesupport/flakysafety/ComposeFlakySafetyScalper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.kaspersky.components.composesupport.flakysafety | ||
|
||
import com.kaspersky.components.composesupport.config.ComposeInterceptorsInjector | ||
import com.kaspersky.components.composesupport.interceptors.behavior.SemanticsBehaviorInterceptor | ||
import com.kaspersky.components.composesupport.interceptors.behavior.impl.flakysafety.FlakySafeSemanticsBehaviorInterceptor | ||
import com.kaspersky.components.composesupport.interceptors.watcher.SemanticsWatcherInterceptor | ||
import com.kaspersky.kaspresso.flakysafety.scalpel.external.ExternalFlakySafetyScalper | ||
|
||
/** | ||
* Removes and restores compose flaky safety interceptor so the `flakySafely` expression works correctly | ||
* @see com.kaspersky.kaspresso.flakysafety.scalpel.FlakySafeInterceptorScalpel | ||
*/ | ||
internal class ComposeFlakySafetyScalper( | ||
private val semanticsBehaviorInterceptors: MutableList<SemanticsBehaviorInterceptor>, | ||
private val semanticsWatcherInterceptors: MutableList<SemanticsWatcherInterceptor>, | ||
) : ExternalFlakySafetyScalper { | ||
override fun isFlakySafetyInterceptorPresent(): Boolean { | ||
return semanticsBehaviorInterceptors.any { it is FlakySafeSemanticsBehaviorInterceptor } | ||
} | ||
|
||
override fun scalpFlakySafety() { | ||
val interceptors = semanticsBehaviorInterceptors.filter { it !is FlakySafeSemanticsBehaviorInterceptor } | ||
ComposeInterceptorsInjector.injectKaspressoInKakaoCompose(interceptors, semanticsWatcherInterceptors) | ||
} | ||
|
||
override fun restoreFlakySafety() { | ||
ComposeInterceptorsInjector.injectKaspressoInKakaoCompose(semanticsBehaviorInterceptors, semanticsWatcherInterceptors) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...kotlin/com/kaspersky/kaspresso/flakysafety/scalpel/external/ExternalFlakySafetyScalper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.kaspersky.kaspresso.flakysafety.scalpel.external | ||
|
||
interface ExternalFlakySafetyScalper { | ||
fun isFlakySafetyInterceptorPresent(): Boolean | ||
fun scalpFlakySafety() | ||
fun restoreFlakySafety() | ||
} |
33 changes: 33 additions & 0 deletions
33
...om/kaspersky/kaspresso/flakysafety/scalpel/external/ExternalFlakySafetyScalperNotifier.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.kaspersky.kaspresso.flakysafety.scalpel.external | ||
|
||
interface ExternalFlakySafetyScalperNotifier { | ||
fun addScalper(scalper: ExternalFlakySafetyScalper) | ||
|
||
fun isAnyExternalFlakySafetyInterceptorPresent(): Boolean | ||
fun scalpFlakySafety() | ||
fun restoreFlakySafety() | ||
} | ||
|
||
internal class ExternalFlakySafetyScalperNotifierImpl : ExternalFlakySafetyScalperNotifier { | ||
private val scalpers = mutableListOf<ExternalFlakySafetyScalper>() | ||
|
||
override fun addScalper(scalper: ExternalFlakySafetyScalper) { | ||
synchronized(this) { | ||
scalpers.add(scalper) | ||
} | ||
} | ||
|
||
override fun isAnyExternalFlakySafetyInterceptorPresent(): Boolean { | ||
synchronized(this) { | ||
return scalpers.any { it.isFlakySafetyInterceptorPresent() } | ||
} | ||
} | ||
|
||
override fun scalpFlakySafety() = scalpers.forEach { | ||
it.scalpFlakySafety() | ||
} | ||
|
||
override fun restoreFlakySafety() = scalpers.forEach { | ||
it.restoreFlakySafety() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters