Skip to content

Commit

Permalink
TECH: Make language features customization easier (#681)
Browse files Browse the repository at this point in the history
* TECH: Make language features customization easier

* TECH: Open SystemLanguage functions
  • Loading branch information
Nikitae57 authored Dec 12, 2024
1 parent fcbd7a6 commit ef31751
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import java.util.Locale
/**
* The implementation of [Language]
*/
internal class LanguageImpl(
open class LanguageImpl(
private val logger: UiTestLogger,
private val instrumentation: Instrumentation,
private val systemLanguage: SystemLanguage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.kaspersky.kaspresso.device.permissions.HackPermissions
import com.kaspersky.kaspresso.logger.UiTestLogger
import java.util.Locale

internal class SystemLanguage(
open class SystemLanguage(
private val context: Context,
private val logger: UiTestLogger,
private val hackPermissions: HackPermissions
Expand All @@ -24,7 +24,7 @@ internal class SystemLanguage(
* @throws Throwable if something went wrong
*/
@SuppressLint("PrivateApi", "DiscouragedPrivateApi")
fun switch(locale: Locale) {
open fun switch(locale: Locale) {
logger.i("SystemLanguage: Installing new system language=$locale started")
grantPermissionsIfNeed()
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,11 @@ data class Kaspresso(
*/
lateinit var exploit: Exploit

/**
* Holds an implementation of [SystemLanguage] interface. If it was not specified, the default implementation is used.
*/
lateinit var systemLanguage: SystemLanguage

/**
* Holds an implementation of [Language] interface. If it was not specified, the default implementation is used.
*/
Expand Down Expand Up @@ -743,10 +748,10 @@ data class Kaspresso(
instrumentalDependencyProviderFactory.getComponentProvider<ExploitImpl>(instrumentation),
adbServer
)
if (!::language.isInitialized) {
val systemLanguage = SystemLanguage(instrumentation.targetContext, testLogger, hackPermissions)
language = LanguageImpl(libLogger, instrumentation, systemLanguage)
}

if (!::systemLanguage.isInitialized) systemLanguage = SystemLanguage(instrumentation.targetContext, testLogger, hackPermissions)
if (!::language.isInitialized) language = LanguageImpl(libLogger, instrumentation, systemLanguage)

if (!::logcat.isInitialized) logcat = LogcatImpl(libLogger, adbServer)

if (!::flakySafetyParams.isInitialized) flakySafetyParams = FlakySafetyParams.default()
Expand Down

0 comments on commit ef31751

Please sign in to comment.