Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
daedric7 committed Jan 17, 2025
2 parents 05c4c97 + d00bc30 commit a777e93
Show file tree
Hide file tree
Showing 60 changed files with 484 additions and 1,022 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,34 @@ package io.element.android.x.initializer

import android.content.Context
import android.system.Os
import androidx.preference.PreferenceManager
import androidx.startup.Initializer
import io.element.android.features.preferences.impl.developer.tracing.SharedPreferencesTracingConfigurationStore
import io.element.android.features.preferences.impl.developer.tracing.TargetLogLevelMapBuilder
import io.element.android.features.rageshake.api.reporter.BugReporter
import io.element.android.libraries.architecture.bindings
import io.element.android.libraries.core.meta.BuildType
import io.element.android.libraries.matrix.api.tracing.TracingConfiguration
import io.element.android.libraries.matrix.api.tracing.TracingFilterConfigurations
import io.element.android.libraries.matrix.api.tracing.WriteToFilesConfiguration
import io.element.android.x.BuildConfig
import io.element.android.x.di.AppBindings
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import timber.log.Timber

private const val ELEMENT_X_TARGET = "elementx"

class TracingInitializer : Initializer<Unit> {
override fun create(context: Context) {
val appBindings = context.bindings<AppBindings>()
val tracingService = appBindings.tracingService()
val bugReporter = appBindings.bugReporter()
Timber.plant(tracingService.createTimberTree())
val tracingConfiguration = if (BuildConfig.BUILD_TYPE == BuildType.RELEASE.name) {
TracingConfiguration(
filterConfiguration = TracingFilterConfigurations.release,
writesToLogcat = false,
writesToFilesConfiguration = defaultWriteToDiskConfiguration(bugReporter),
)
} else {
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
val store = SharedPreferencesTracingConfigurationStore(prefs)
val builder = TargetLogLevelMapBuilder(
tracingConfigurationStore = store,
defaultConfig = if (BuildConfig.BUILD_TYPE == BuildType.NIGHTLY.name) {
TracingFilterConfigurations.nightly
} else {
TracingFilterConfigurations.debug
}
)
TracingConfiguration(
filterConfiguration = TracingFilterConfigurations.custom(builder.getCurrentMap()),
writesToLogcat = BuildConfig.DEBUG,
writesToFilesConfiguration = defaultWriteToDiskConfiguration(bugReporter),
)
}
bugReporter.setCurrentTracingFilter(tracingConfiguration.filterConfiguration.filter)
Timber.plant(tracingService.createTimberTree(ELEMENT_X_TARGET))
val preferencesStore = appBindings.preferencesStore()
val logLevel = runBlocking { preferencesStore.getTracingLogLevelFlow().first() }
val tracingConfiguration = TracingConfiguration(
writesToLogcat = BuildConfig.DEBUG,
writesToFilesConfiguration = defaultWriteToDiskConfiguration(bugReporter),
logLevel = logLevel,
extraTargets = listOf(ELEMENT_X_TARGET),
)
bugReporter.setCurrentTracingLogLevel(logLevel.name)
tracingService.setupTracing(tracingConfiguration)
// Also set env variable for rust back trace
Os.setenv("RUST_BACKTRACE", "1", true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import io.element.android.anvilannotations.ContributesNode
import io.element.android.features.login.api.LoginEntryPoint
import io.element.android.features.login.api.LoginFlowType
import io.element.android.features.onboarding.api.OnBoardingEntryPoint
import io.element.android.features.preferences.api.ConfigureTracingEntryPoint
import io.element.android.libraries.architecture.BackstackView
import io.element.android.libraries.architecture.BaseFlowNode
import io.element.android.libraries.designsystem.utils.ForceOrientationInMobileDevices
Expand All @@ -38,7 +37,6 @@ class NotLoggedInFlowNode @AssistedInject constructor(
@Assisted buildContext: BuildContext,
@Assisted plugins: List<Plugin>,
private val onBoardingEntryPoint: OnBoardingEntryPoint,
private val configureTracingEntryPoint: ConfigureTracingEntryPoint,
private val loginEntryPoint: LoginEntryPoint,
private val notLoggedInImageLoaderFactory: NotLoggedInImageLoaderFactory,
) : BaseFlowNode<NotLoggedInFlowNode.NavTarget>(
Expand Down Expand Up @@ -68,9 +66,6 @@ class NotLoggedInFlowNode @AssistedInject constructor(

@Parcelize
data class LoginFlow(val type: LoginFlowType) : NavTarget

@Parcelize
data object ConfigureTracing : NavTarget
}

override fun resolve(navTarget: NavTarget, buildContext: BuildContext): Node {
Expand All @@ -89,10 +84,6 @@ class NotLoggedInFlowNode @AssistedInject constructor(
backstack.push(NavTarget.LoginFlow(type = LoginFlowType.SIGN_IN_QR_CODE))
}

override fun onOpenDeveloperSettings() {
backstack.push(NavTarget.ConfigureTracing)
}

override fun onReportProblem() {
plugins<Callback>().forEach { it.onOpenBugReport() }
}
Expand All @@ -107,9 +98,6 @@ class NotLoggedInFlowNode @AssistedInject constructor(
.params(LoginEntryPoint.Params(flowType = navTarget.type))
.build()
}
NavTarget.ConfigureTracing -> {
configureTracingEntryPoint.createNode(this, buildContext)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ interface OnBoardingEntryPoint : FeatureEntryPoint {
fun onSignUp()
fun onSignIn()
fun onSignInWithQrCode()
fun onOpenDeveloperSettings()
fun onReportProblem()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ class OnBoardingNode @AssistedInject constructor(
plugins<OnBoardingEntryPoint.Callback>().forEach { it.onSignInWithQrCode() }
}

private fun onOpenDeveloperSettings() {
plugins<OnBoardingEntryPoint.Callback>().forEach { it.onOpenDeveloperSettings() }
}

private fun onReportProblem() {
plugins<OnBoardingEntryPoint.Callback>().forEach { it.onReportProblem() }
}
Expand All @@ -57,7 +53,6 @@ class OnBoardingNode @AssistedInject constructor(
onSignIn = ::onSignIn,
onCreateAccount = ::onSignUp,
onSignInWithQrCode = ::onSignInWithQrCode,
onOpenDeveloperSettings = ::onOpenDeveloperSettings,
onReportProblem = ::onReportProblem,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import androidx.compose.runtime.produceState
import io.element.android.appconfig.OnBoardingConfig
import io.element.android.libraries.architecture.Presenter
import io.element.android.libraries.core.meta.BuildMeta
import io.element.android.libraries.core.meta.BuildType
import io.element.android.libraries.featureflag.api.FeatureFlagService
import io.element.android.libraries.featureflag.api.FeatureFlags
import javax.inject.Inject
Expand All @@ -31,8 +30,7 @@ class OnBoardingPresenter @Inject constructor(
val canLoginWithQrCode by produceState(initialValue = false) {
value = featureFlagService.isFeatureEnabled(FeatureFlags.QrCodeLogin)
}
return OnBoardingState(
isDebugBuild = buildMeta.buildType != BuildType.RELEASE,
return OnBoardingState(
productionApplicationName = buildMeta.productionApplicationName,
canLoginWithQrCode = canLoginWithQrCode,
canCreateAccount = OnBoardingConfig.CAN_CREATE_ACCOUNT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package io.element.android.features.onboarding.impl

data class OnBoardingState(
val isDebugBuild: Boolean,
val productionApplicationName: String,
val canLoginWithQrCode: Boolean,
val canCreateAccount: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@ open class OnBoardingStateProvider : PreviewParameterProvider<OnBoardingState> {
anOnBoardingState(canLoginWithQrCode = true),
anOnBoardingState(canCreateAccount = true),
anOnBoardingState(canLoginWithQrCode = true, canCreateAccount = true),
anOnBoardingState(isDebugBuild = true),
)
}

fun anOnBoardingState(
isDebugBuild: Boolean = false,
productionApplicationName: String = "Element",
canLoginWithQrCode: Boolean = false,
canCreateAccount: Boolean = false
) = OnBoardingState(
isDebugBuild = isDebugBuild,
productionApplicationName = productionApplicationName,
canLoginWithQrCode = canLoginWithQrCode,
canCreateAccount = canCreateAccount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.QrCode
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Alignment.Companion.CenterHorizontally
import androidx.compose.ui.BiasAlignment
import androidx.compose.ui.Modifier
Expand All @@ -28,16 +27,13 @@ import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import io.element.android.compound.theme.ElementTheme
import io.element.android.compound.tokens.generated.CompoundIcons
import io.element.android.libraries.designsystem.atomic.atoms.ElementLogoAtom
import io.element.android.libraries.designsystem.atomic.atoms.ElementLogoAtomSize
import io.element.android.libraries.designsystem.atomic.molecules.ButtonColumnMolecule
import io.element.android.libraries.designsystem.atomic.pages.OnBoardingPage
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.theme.components.Button
import io.element.android.libraries.designsystem.theme.components.Icon
import io.element.android.libraries.designsystem.theme.components.IconButton
import io.element.android.libraries.designsystem.theme.components.IconSource
import io.element.android.libraries.designsystem.theme.components.Text
import io.element.android.libraries.designsystem.theme.components.TextButton
Expand All @@ -56,17 +52,13 @@ fun OnBoardingView(
onSignInWithQrCode: () -> Unit,
onSignIn: () -> Unit,
onCreateAccount: () -> Unit,
onOpenDeveloperSettings: () -> Unit,
onReportProblem: () -> Unit,
modifier: Modifier = Modifier,
) {
OnBoardingPage(
modifier = modifier,
content = {
OnBoardingContent(
state = state,
onOpenDeveloperSettings = onOpenDeveloperSettings
)
OnBoardingContent(state = state)
},
footer = {
OnBoardingButtons(
Expand All @@ -81,10 +73,7 @@ fun OnBoardingView(
}

@Composable
private fun OnBoardingContent(
state: OnBoardingState,
onOpenDeveloperSettings: () -> Unit,
) {
private fun OnBoardingContent(state: OnBoardingState) {
Box(
modifier = Modifier.fillMaxSize(),
) {
Expand Down Expand Up @@ -127,17 +116,6 @@ private fun OnBoardingContent(
)
}
}
if (state.isDebugBuild) {
IconButton(
modifier = Modifier.align(Alignment.TopEnd),
onClick = onOpenDeveloperSettings,
) {
Icon(
imageVector = CompoundIcons.SettingsSolid(),
contentDescription = stringResource(CommonStrings.common_settings)
)
}
}
}
}

Expand Down Expand Up @@ -167,8 +145,8 @@ private fun OnBoardingButtons(
text = stringResource(id = signInButtonStringRes),
onClick = onSignIn,
modifier = Modifier
.fillMaxWidth()
.testTag(TestTags.onBoardingSignIn)
.fillMaxWidth()
.testTag(TestTags.onBoardingSignIn)
)
if (state.canCreateAccount) {
TextButton(
Expand All @@ -181,8 +159,8 @@ private fun OnBoardingButtons(
// Add a report problem text button. Use a Text since we need a special theme here.
Text(
modifier = Modifier
.padding(16.dp)
.clickable(onClick = onReportProblem),
.padding(16.dp)
.clickable(onClick = onReportProblem),
text = stringResource(id = CommonStrings.common_report_a_problem),
style = ElementTheme.typography.fontBodySmRegular,
color = ElementTheme.colors.textSecondary,
Expand All @@ -200,7 +178,6 @@ internal fun OnBoardingViewPreview(
onSignInWithQrCode = {},
onSignIn = {},
onCreateAccount = {},
onOpenDeveloperSettings = {},
onReportProblem = {},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import app.cash.molecule.moleculeFlow
import app.cash.turbine.test
import com.google.common.truth.Truth.assertThat
import io.element.android.appconfig.OnBoardingConfig
import io.element.android.libraries.core.meta.BuildType
import io.element.android.libraries.featureflag.api.FeatureFlags
import io.element.android.libraries.featureflag.test.FakeFeatureFlagService
import io.element.android.libraries.matrix.test.core.aBuildMeta
Expand Down Expand Up @@ -44,27 +43,10 @@ class OnBoardingPresenterTest {
presenter.present()
}.test {
val initialState = awaitItem()
assertThat(initialState.isDebugBuild).isTrue()
assertThat(initialState.canLoginWithQrCode).isFalse()
assertThat(initialState.productionApplicationName).isEqualTo("B")
assertThat(initialState.canCreateAccount).isEqualTo(OnBoardingConfig.CAN_CREATE_ACCOUNT)

assertThat(awaitItem().canLoginWithQrCode).isTrue()
}
}

@Test
fun `present - initial state release`() = runTest {
val presenter = OnBoardingPresenter(
buildMeta = aBuildMeta(buildType = BuildType.RELEASE),
featureFlagService = FakeFeatureFlagService(),
)
moleculeFlow(RecompositionMode.Immediate) {
presenter.present()
}.test {
val initialState = awaitItem()
assertThat(initialState.isDebugBuild).isFalse()
cancelAndIgnoreRemainingEvents()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
package io.element.android.features.onboarding.impl

import androidx.activity.ComponentActivity
import androidx.compose.ui.test.hasContentDescription
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.runners.AndroidJUnit4
import io.element.android.libraries.ui.strings.CommonStrings
import io.element.android.tests.testutils.EnsureNeverCalled
Expand Down Expand Up @@ -74,17 +72,6 @@ class OnboardingViewTest {
}
}

@Test
fun `when on debug build - clicking on the settings icon opens the developer settings`() {
ensureCalledOnce { callback ->
rule.setOnboardingView(
state = anOnBoardingState(isDebugBuild = true),
onOpenDeveloperSettings = callback
)
rule.onNode(hasContentDescription(rule.activity.getString(CommonStrings.common_settings))).performClick()
}
}

@Test
fun `clicking on report a problem calls the sign in callback`() {
ensureCalledOnce { callback ->
Expand All @@ -101,7 +88,6 @@ class OnboardingViewTest {
onSignInWithQrCode: () -> Unit = EnsureNeverCalled(),
onSignIn: () -> Unit = EnsureNeverCalled(),
onCreateAccount: () -> Unit = EnsureNeverCalled(),
onOpenDeveloperSettings: () -> Unit = EnsureNeverCalled(),
onReportProblem: () -> Unit = EnsureNeverCalled(),
) {
setContent {
Expand All @@ -110,7 +96,6 @@ class OnboardingViewTest {
onSignInWithQrCode = onSignInWithQrCode,
onSignIn = onSignIn,
onCreateAccount = onCreateAccount,
onOpenDeveloperSettings = onOpenDeveloperSettings,
onReportProblem = onReportProblem,
)
}
Expand Down

This file was deleted.

Loading

0 comments on commit a777e93

Please sign in to comment.