Skip to content

Commit 5bb47ba

Browse files
committed
feat: migrate from production console logging to full exportable app logs
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 1084546 commit 5bb47ba

18 files changed

Lines changed: 798 additions & 41 deletions

File tree

apps/flipcash/app/src/main/AndroidManifest.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,16 @@
245245
<meta-data android:name="photopicker_activity:0:required" android:value="" />
246246
</service>
247247

248+
<provider
249+
android:name="androidx.core.content.FileProvider"
250+
android:authorities="${applicationId}.fileprovider"
251+
android:exported="false"
252+
android:grantUriPermissions="true">
253+
<meta-data
254+
android:name="android.support.FILE_PROVIDER_PATHS"
255+
android:resource="@xml/file_paths" />
256+
</provider>
257+
248258
<provider
249259
android:name="androidx.startup.InitializationProvider"
250260
android:authorities="${applicationId}.androidx-startup"

apps/flipcash/app/src/main/kotlin/com/flipcash/app/internal/startup/TraceInitializer.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ import com.bugsnag.android.Configuration
77
import com.flipcash.app.android.BuildConfig
88
import com.flipcash.app.internal.debug.FlipcashDebugTree
99
import com.flipcash.app.internal.debug.FlipcashErrorCallback
10+
import com.getcode.utils.TraceManager
1011
import kotlinx.coroutines.CoroutineScope
1112
import kotlinx.coroutines.Dispatchers
1213
import kotlinx.coroutines.launch
1314
import timber.log.Timber
1415

1516
class TraceInitializer: Initializer<Unit> {
1617
override fun create(context: Context) {
18+
TraceManager.initialize(context)
19+
1720
if (BuildConfig.DEBUG) {
1821
Timber.plant(FlipcashDebugTree)
1922
} else {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<paths>
3+
<files-path name="traces" path="traces/" />
4+
</paths>

apps/flipcash/core/src/main/kotlin/com/flipcash/app/core/android/IntentUtils.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import android.content.pm.PackageManager
77
import android.net.Uri
88
import android.provider.MediaStore
99
import android.provider.Settings
10+
import androidx.core.content.FileProvider
1011
import androidx.core.net.toUri
1112
import com.flipcash.app.core.util.Linkify
13+
import java.io.File
1214

1315

1416
object IntentUtils {
@@ -56,4 +58,20 @@ object IntentUtils {
5658
setData(Uri.parse("https://play.google.com/store/apps/details?id=$packageName"))
5759
flags = Intent.FLAG_ACTIVITY_NEW_TASK
5860
}
61+
62+
fun shareFile(context: Context, file: File, mimeType: String): Intent {
63+
val uri = FileProvider.getUriForFile(
64+
context,
65+
"${context.packageName}.fileprovider",
66+
file
67+
)
68+
val sendIntent = Intent(Intent.ACTION_SEND).apply {
69+
putExtra(Intent.EXTRA_STREAM, uri)
70+
type = mimeType
71+
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
72+
}
73+
return Intent.createChooser(sendIntent, null).apply {
74+
flags = Intent.FLAG_ACTIVITY_NEW_TASK
75+
}
76+
}
5977
}

apps/flipcash/core/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@
364364
<string name="description_noTransactionHistory">Your recent activity will appear here when you send or receive money</string>
365365

366366
<string name="title_billCustomizer">Bill Creator</string>
367+
<string name="title_exportLogs">Export Logs</string>
367368

368369
<string name="error_title_CashReturnedToWallet">Something Went Wrong</string>
369370
<string name="error_description_CashReturnedToWallet">The cash was returned to your wallet</string>

apps/flipcash/features/advanced/src/main/kotlin/com/flipcash/app/advanced/AdvancedFeaturesScreen.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ import androidx.compose.runtime.Composable
66
import androidx.compose.runtime.LaunchedEffect
77
import androidx.compose.ui.Alignment
88
import androidx.compose.ui.Modifier
9+
import androidx.compose.ui.platform.LocalContext
910
import androidx.compose.ui.res.stringResource
1011
import androidx.hilt.navigation.compose.hiltViewModel
1112
import com.flipcash.app.advanced.internal.AdvancedFeaturesScreen
1213
import com.flipcash.app.advanced.internal.AdvancedFeaturesScreenViewModel
1314
import com.flipcash.app.bill.customization.LocalBillPlaygroundController
15+
import com.flipcash.app.core.android.IntentUtils
1416
import com.flipcash.core.R
1517
import com.getcode.navigation.core.LocalCodeNavigator
1618
import com.getcode.opencode.model.financial.Token
1719
import com.getcode.opencode.model.financial.usdf
1820
import com.getcode.ui.components.AppBarWithTitle
21+
import com.getcode.utils.TraceManager
1922
import kotlinx.coroutines.flow.filterIsInstance
2023
import kotlinx.coroutines.flow.launchIn
2124
import kotlinx.coroutines.flow.onEach
@@ -25,6 +28,7 @@ fun AdvancedFeaturesScreen() {
2528
val navigator = LocalCodeNavigator.current
2629
val billPlayground = LocalBillPlaygroundController.current
2730
val viewModel = hiltViewModel<AdvancedFeaturesScreenViewModel>()
31+
val context = LocalContext.current
2832

2933
Column(
3034
modifier = Modifier.fillMaxSize(),
@@ -57,4 +61,17 @@ fun AdvancedFeaturesScreen() {
5761
}
5862
.launchIn(this)
5963
}
64+
65+
LaunchedEffect(viewModel) {
66+
viewModel.eventFlow
67+
.filterIsInstance<AdvancedFeaturesScreenViewModel.Event.ExportLogs>()
68+
.onEach {
69+
val logFile = TraceManager.getLogFile()
70+
if (logFile != null) {
71+
val intent = IntentUtils.shareFile(context, logFile, "text/plain")
72+
context.startActivity(intent)
73+
}
74+
}
75+
.launchIn(this)
76+
}
6077
}

apps/flipcash/features/advanced/src/main/kotlin/com/flipcash/app/advanced/internal/AdvancedFeatureMenuItems.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.flipcash.app.advanced.internal
22

33
import androidx.compose.material.icons.Icons
44
import androidx.compose.material.icons.outlined.Palette
5+
import androidx.compose.material.icons.outlined.Share
56
import androidx.compose.runtime.Composable
67
import androidx.compose.ui.graphics.painter.Painter
78
import androidx.compose.ui.graphics.vector.rememberVectorPainter
@@ -28,4 +29,12 @@ internal data object Deposit : FullMenuItem<AdvancedFeaturesScreenViewModel.Even
2829
override val action: AdvancedFeaturesScreenViewModel.Event = AdvancedFeaturesScreenViewModel.Event.OpenScreen(
2930
AppRoute.Sheets.TokenSelection(purpose = TokenPurpose.Deposit)
3031
)
32+
}
33+
34+
internal data object ExportLogs : FullMenuItem<AdvancedFeaturesScreenViewModel.Event>() {
35+
override val icon: Painter
36+
@Composable get() = rememberVectorPainter(Icons.Outlined.Share)
37+
override val name: String
38+
@Composable get() = stringResource(R.string.title_exportLogs)
39+
override val action: AdvancedFeaturesScreenViewModel.Event = AdvancedFeaturesScreenViewModel.Event.ExportLogs
3140
}

apps/flipcash/features/advanced/src/main/kotlin/com/flipcash/app/advanced/internal/AdvancedFeaturesScreenViewModel.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import javax.inject.Inject
2020
private val FullMenuList = buildList {
2121
add(BillCustomizer)
2222
add(Deposit)
23+
add(ExportLogs)
2324
}
2425

2526
@HiltViewModel
@@ -44,6 +45,7 @@ internal class AdvancedFeaturesScreenViewModel @Inject constructor(
4445
data class OpenScreen(val screen: AppRoute) : Event
4546

4647
data object OpenBillPlayground: Event
48+
data object ExportLogs: Event
4749
}
4850

4951
init {
@@ -83,6 +85,7 @@ internal class AdvancedFeaturesScreenViewModel @Inject constructor(
8385

8486
is Event.OpenScreen -> { state -> state }
8587
is Event.OpenBillPlayground -> { state -> state }
88+
is Event.ExportLogs -> { state -> state }
8689
}
8790
}
8891
}

apps/flipcash/shared/featureflags/src/main/kotlin/com/flipcash/app/featureflags/FeatureFlag.kt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.flipcash.app.featureflags
22

33
import com.flipcash.app.ksp.annotations.FeatureFlagMarker
4-
import com.flipcash.shared.flags.BuildConfig
54

65
sealed interface FeatureFlag {
76
val key: String
@@ -73,15 +72,6 @@ sealed interface FeatureFlag {
7372
override val persistLogOut: Boolean = false
7473
}
7574

76-
@FeatureFlagMarker
77-
data object ProductionLogging: FeatureFlag {
78-
override val key: String = "production_logging_enabled"
79-
override val default: Boolean = false
80-
override val launched: Boolean = false
81-
override val visible: Boolean = !BuildConfig.DEBUG
82-
override val persistLogOut: Boolean = true
83-
}
84-
8575
@FeatureFlagMarker
8676
data object CashReservesEnabled: FeatureFlag {
8777
override val key: String = "cash_reserves_enabled"
@@ -156,7 +146,6 @@ val FeatureFlag.title: String
156146
FeatureFlag.Pools -> "Betting Pools"
157147
FeatureFlag.OnRamp -> "Onramp"
158148
FeatureFlag.BillCustomizer -> "Bill Customizer"
159-
FeatureFlag.ProductionLogging -> "Production Logging"
160149
FeatureFlag.CashReservesEnabled -> "Cash Reserves"
161150
FeatureFlag.MarketCapChart -> "Market Cap Chart"
162151
FeatureFlag.CoinbaseOnRamp -> "Coinbase Onramp"
@@ -174,7 +163,6 @@ val FeatureFlag.message: String
174163
FeatureFlag.Pools -> "When enabled, you'll be able to participate in and create betting pools with other users for a chance to win a share of the prize"
175164
FeatureFlag.OnRamp -> "When enabled, you'll gain the ability to fund your wallet from external sources via providers using a debit card or via another wallet (like Phantom)"
176165
FeatureFlag.BillCustomizer -> "When enabled, you'll gain access to the bill customization playground"
177-
FeatureFlag.ProductionLogging -> "When enabled, traces will print to log output"
178166
FeatureFlag.CashReservesEnabled -> "When enabled, USDC will be brandished as Cash Reserves throughout the app"
179167
FeatureFlag.MarketCapChart -> "When enabled, you'll gain access to the market cap chart in token info"
180168
FeatureFlag.CoinbaseOnRamp -> "When enabled, you'll gain access to the Coinbase onramp for token buys"

apps/flipcash/shared/featureflags/src/main/kotlin/com/flipcash/app/featureflags/internal/InternalFeatureFlagController.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ import androidx.datastore.preferences.preferencesDataStoreFile
1010
import com.flipcash.app.featureflags.BetaFeature
1111
import com.flipcash.app.featureflags.FeatureFlag
1212
import com.flipcash.app.featureflags.FeatureFlagController
13-
import com.getcode.utils.TraceManager
1413
import dagger.hilt.android.qualifiers.ApplicationContext
1514
import kotlinx.coroutines.CoroutineScope
1615
import kotlinx.coroutines.Dispatchers
1716
import kotlinx.coroutines.SupervisorJob
1817
import kotlinx.coroutines.flow.SharingStarted
1918
import kotlinx.coroutines.flow.StateFlow
2019
import kotlinx.coroutines.flow.firstOrNull
21-
import kotlinx.coroutines.flow.launchIn
2220
import kotlinx.coroutines.flow.map
2321
import kotlinx.coroutines.flow.onEach
2422
import kotlinx.coroutines.flow.stateIn
@@ -51,10 +49,6 @@ internal class InternalFeatureFlagController @Inject constructor(
5149
FeatureFlag.entries
5250
.filter { it.launched }
5351
.onEach { reset(it) }
54-
55-
observe(FeatureFlag.ProductionLogging)
56-
.onEach { TraceManager.enableProductionTraces(it) }
57-
.launchIn(dataScope)
5852
}
5953

6054
override fun enableBetaFeatures() {

0 commit comments

Comments
 (0)