Skip to content

Commit 8c04a52

Browse files
author
Anatoly Rosencrantz
committed
1.2.3
1 parent 9770a8f commit 8c04a52

File tree

142 files changed

+2872
-838
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+2872
-838
lines changed

.gitlab-ci.yml

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ variables:
99
GCLOUD_BUCKET_URL: "gs://test-lab-u7cps962nd0a4-kx5m7jhd4pki6"
1010
FIREBASE_RESULT_ROOT: "${CI_BUILD_REF_NAME}/${CI_COMMIT_SHORT_SHA}"
1111
ATLAS_DEPLOY_ENV: "true"
12+
ATLAS_DEPLOY_PREP: "true"
1213

1314
workflow:
1415
rules:
@@ -31,6 +32,7 @@ cache:
3132
- config/detekt/config.yml
3233

3334
stages:
35+
- i18n
3436
- prepare
3537
- analyze
3638
- deploy
@@ -41,7 +43,7 @@ stages:
4143
- publish
4244
- cleanup
4345

44-
.prepare:
46+
prepare-build:
4547
stage: prepare
4648
artifacts:
4749
paths:
@@ -51,30 +53,6 @@ stages:
5153
dotenv: deploy.env
5254
expire_in: 1 week
5355
cache: []
54-
55-
prepare-environment:
56-
extends: .prepare
57-
image: $CI_REGISTRY/proton/devops/atlas-cli
58-
script:
59-
# DEBUG NS 500 error
60-
- echo
61-
-d "$ATLAS_BASE_DOMAIN"
62-
--release "$ATLAS_RELEASE_SUFFIX"
63-
"${ENV_TAG:?}"
64-
"${CI_PROJECT_PATH}"
65-
"$CI_COMMIT_REF_NAME"
66-
67-
# resulting variables will be stored in deploy.env
68-
- get_name.py -v
69-
-o deploy.env
70-
-d "$ATLAS_BASE_DOMAIN"
71-
--release "$ATLAS_RELEASE_SUFFIX" "${ENV_TAG:?}" "${CI_PROJECT_PATH}" "$CI_COMMIT_REF_NAME"
72-
environment:
73-
name: $CI_COMMIT_REF_SLUG/$ATLAS_DEPLOY_SCOPE
74-
action: prepare
75-
76-
prepare-build:
77-
extends: .prepare
7856
tags:
7957
- large
8058
script:
@@ -120,7 +98,7 @@ detekt analysis:
12098
build dev debug:
12199
extends: [.build]
122100
needs:
123-
- job: "prepare-environment"
101+
- job: "claim:review"
124102
- job: "prepare-build"
125103
- job: "prepare-gradle-build-scan"
126104
optional: true
@@ -133,7 +111,7 @@ build dev debug:
133111
build dynamic debug:
134112
extends: [.build]
135113
needs:
136-
- job: "prepare-environment"
114+
- job: "claim:review"
137115
- job: "prepare-build"
138116
- job: "prepare-gradle-build-scan"
139117
optional: true
@@ -357,9 +335,6 @@ testmo-upload:
357335

358336
publish to firebase app distribution:
359337
stage: publish
360-
needs:
361-
- job: "build dev debug"
362-
- job: "prepare-build"
363338
tags:
364339
- xlarge-k8s
365340
variables:
@@ -412,3 +387,27 @@ include:
412387
- project: 'tpe/testmo-reporter'
413388
ref: master
414389
file: '/scenarios/testmo-simple.yml'
390+
391+
- project: 'translations/generator'
392+
ref: master
393+
file: '/jobs/sync-crowdin.gitlab-ci.yml'
394+
395+
- project: 'translations/generator'
396+
ref: master
397+
file: '/jobs/commit-locales.gitlab-ci.yml'
398+
399+
i18n-sync-crowdin:
400+
stage: i18n
401+
variables:
402+
I18N_SYNC_BRANCH: develop
403+
I18N_SYNC_CROWDIN_PROJECT: 'android-drive'
404+
extends: .i18n-sync-crowdin-shared
405+
406+
i18n-commit-locales:
407+
stage: i18n
408+
variables:
409+
I18N_COMMIT_BRANCH_PUSH: develop
410+
I18N_COMMIT_BRANCH_ALLOWED: develop
411+
I18N_COMMIT_CROWDIN_PROJECT: 'android-drive'
412+
extends: .i18n-commit-locales-shared
413+

app/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
build/
22
release/
3-
play/
3+
!release/kotlin/me/proton/android/drive/usecase/GetFileLoggerTree.kt
4+
play/
5+

app/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ driveModule(
6666
implementation(libs.sentry)
6767
implementation(libs.timber)
6868

69+
debugImplementation(libs.treessence)
70+
6971
androidTestImplementation(libs.androidx.navigation.compose)
72+
androidTestImplementation(libs.androidx.test.espresso.contrib)
7073
androidTestImplementation(libs.bundles.core.test)
7174
androidTestImplementation(libs.fusion)
7275

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2023 Proton AG.
3+
* This file is part of Proton Drive.
4+
*
5+
* Proton Drive is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* Proton Drive is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with Proton Drive. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package me.proton.android.drive.usecase
20+
21+
import android.util.Log
22+
import fr.bipi.tressence.common.filters.Filter
23+
import fr.bipi.tressence.file.FileLoggerTree
24+
import me.proton.core.drive.base.domain.entity.Percentage
25+
import me.proton.core.drive.base.domain.extension.MiB
26+
import me.proton.core.drive.base.domain.extension.percentageOfAsciiChars
27+
import me.proton.core.drive.base.domain.util.coRunCatching
28+
import me.proton.core.util.kotlin.startsWith
29+
import timber.log.Timber
30+
import javax.inject.Inject
31+
32+
class GetFileLoggerTree @Inject constructor(
33+
private val getDebugLogFile: GetDebugLogFile,
34+
) {
35+
operator fun invoke(): Result<Timber.Tree> = coRunCatching {
36+
val debugLog = getDebugLogFile()
37+
FileLoggerTree.Builder()
38+
.withFileName(debugLog.name)
39+
.withDir(requireNotNull(debugLog.parentFile))
40+
.withSizeLimit(25.MiB.value.toInt())
41+
.withFileLimit(1)
42+
.withMinPriority(Log.DEBUG)
43+
.appendToFile(true)
44+
.withFilter(
45+
object : Filter {
46+
override fun isLoggable(priority: Int, tag: String?): Boolean = true
47+
48+
override fun skipLog(
49+
priority: Int,
50+
tag: String?,
51+
message: String,
52+
t: Throwable?
53+
): Boolean =
54+
tag != null &&
55+
tag.startsWith("core.network") &&
56+
message.percentageOfAsciiChars < Percentage(50)
57+
}
58+
)
59+
.build()
60+
}
61+
}

app/src/main/kotlin/me/proton/android/drive/extension/NavHostController.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,8 @@
1818

1919
package me.proton.android.drive.extension
2020

21-
import androidx.compose.runtime.Composable
2221
import androidx.navigation.NavHostController
2322

24-
@Suppress("ControlFlowWithEmptyBody")
25-
fun NavHostController.popAllBackStack() {
26-
do while (popBackStack())
27-
}
28-
2923
fun NavHostController.runFromRoute(route: String, block: () -> Unit) = takeIf {
3024
currentDestination?.route == route
3125
}?.let {

app/src/main/kotlin/me/proton/android/drive/initializer/LoggerInitializer.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ import me.proton.android.drive.log.DriveLogTag
3131
import me.proton.android.drive.log.DriveLogger
3232
import me.proton.android.drive.log.NoOpLogger
3333
import me.proton.android.drive.log.deviceInfo
34+
import me.proton.core.drive.base.domain.provider.ConfigurationProvider
3435
import me.proton.core.usersettings.domain.DeviceSettingsHandler
3536
import me.proton.core.usersettings.domain.onDeviceSettingsChanged
3637
import me.proton.core.util.kotlin.CoreLogger
3738
import timber.log.Timber
3839
import java.util.concurrent.Executors
40+
import me.proton.android.drive.usecase.GetFileLoggerTree
3941

4042
class LoggerInitializer : Initializer<Unit> {
4143

@@ -55,7 +57,14 @@ class LoggerInitializer : Initializer<Unit> {
5557

5658
if (BuildConfig.DEBUG) {
5759
Timber.plant(Timber.DebugTree())
58-
strictMode(logger)
60+
if (entryPoint.configurationProvider().logToFileInDebugEnabled) {
61+
entryPoint.getFileLoggerTree().invoke()
62+
.onSuccess { fileLoggerTree ->
63+
Timber.plant(fileLoggerTree)
64+
}
65+
} else {
66+
strictMode(logger)
67+
}
5968
}
6069
CoreLogger.set(logger)
6170
logger.deviceInfo()
@@ -88,5 +97,7 @@ class LoggerInitializer : Initializer<Unit> {
8897
interface LoggerInitializerEntryPoint {
8998
fun driveLogger(): DriveLogger
9099
fun deviceSettingsHandler(): DeviceSettingsHandler
100+
fun configurationProvider(): ConfigurationProvider
101+
fun getFileLoggerTree(): GetFileLoggerTree
91102
}
92103
}

app/src/main/kotlin/me/proton/android/drive/log/DriveLogger.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ import io.sentry.Sentry
2929
import io.sentry.SentryEvent
3030
import io.sentry.SentryLevel
3131
import io.sentry.protocol.Message
32+
import me.proton.android.drive.BuildConfig
33+
import me.proton.core.drive.base.domain.entity.Percentage
34+
import me.proton.core.drive.base.domain.extension.percentageOfAsciiChars
3235
import me.proton.core.drive.base.presentation.extension.getDefaultMessage
3336
import me.proton.core.util.kotlin.Logger
3437
import me.proton.core.util.kotlin.LoggerLogTag
@@ -79,11 +82,7 @@ class DriveLogger @Inject constructor(
7982

8083
private fun withoutUploadFileContent(tag: String, message: String, block: (tag: String, message: String) -> Unit) {
8184
val isCoreNetwork = tag.startsWith("core.network")
82-
var numAsciiChars = 0
83-
message.forEach { c ->
84-
if (c.code > 33 && c.code < 127) numAsciiChars += 1
85-
}
86-
if (isCoreNetwork && numAsciiChars < (message.length / 2)) {
85+
if (isCoreNetwork && message.percentageOfAsciiChars < Percentage(50)) {
8786
// upload file content detected, do nothing
8887
} else {
8988
block(tag, message)
@@ -181,5 +180,6 @@ fun Logger.deviceInfo() {
181180
} else {
182181
i("LOCALE: ${LocaleList.getDefault().toLanguageTags()}")
183182
}
183+
i("APP VERSION: ${BuildConfig.VERSION_NAME}")
184184
i("-----------------------------------------")
185185
}

app/src/main/kotlin/me/proton/android/drive/receiver/NotificationBroadcastReceiver.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import me.proton.android.drive.extension.log
2727
import me.proton.core.drive.base.domain.log.LogTag
2828
import me.proton.core.drive.base.domain.util.coRunCatching
2929
import me.proton.core.drive.notification.domain.entity.NotificationId
30+
import me.proton.core.drive.notification.domain.usecase.CancelAndRemoveNotification
3031
import me.proton.core.drive.notification.domain.usecase.RemoveNotification
3132
import me.proton.core.drive.upload.domain.usecase.CancelAllUpload
3233
import me.proton.core.util.kotlin.CoreLogger
@@ -37,6 +38,7 @@ import javax.inject.Inject
3738
class NotificationBroadcastReceiver : BroadcastReceiver() {
3839

3940
@Inject lateinit var removeNotification: RemoveNotification
41+
@Inject lateinit var cancelAndRemoveNotification: CancelAndRemoveNotification
4042
@Inject lateinit var cancelAllUpload: CancelAllUpload
4143

4244
override fun onReceive(context: Context?, intent: Intent?) = intent?.action?.let { action ->

app/src/main/kotlin/me/proton/android/drive/settings/DebugSettings.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class DebugSettings(
3939
private val prefsKeyBaseUrl = stringPreferencesKey(BASE_URL)
4040
private val prefsKeyAppVersionHeader = stringPreferencesKey(APP_VERSION_HEADER)
4141
private val prefsUseExceptionMessage = booleanPreferencesKey(USE_EXCEPTION_MESSAGE)
42+
private val prefsLogToFileEnabled = booleanPreferencesKey(LOG_TO_FILE_ENABLED)
4243
val baseUrlFlow: Flow<String> = prefsKeyBaseUrl.asFlow(
4344
dataStore = context.dataStore,
4445
default = buildConfig.baseUrl
@@ -55,6 +56,10 @@ class DebugSettings(
5556
dataStore = context.dataStore,
5657
default = buildConfig.useExceptionMessage,
5758
)
59+
val logToFileEnabledFlow: Flow<Boolean> = prefsLogToFileEnabled.asFlow(
60+
dataStore = context.dataStore,
61+
default = buildConfig.logToFileInDebugEnabled,
62+
)
5863

5964
override var baseUrl by Delegate(
6065
dataStore = context.dataStore,
@@ -76,6 +81,11 @@ class DebugSettings(
7681
key = prefsUseExceptionMessage,
7782
default = buildConfig.useExceptionMessage,
7883
)
84+
override var logToFileInDebugEnabled by Delegate(
85+
dataStore = context.dataStore,
86+
key = prefsLogToFileEnabled,
87+
default = buildConfig.logToFileInDebugEnabled,
88+
)
7989

8090
fun reset(coroutineScope: CoroutineScope) {
8191
coroutineScope.launch {
@@ -91,5 +101,6 @@ class DebugSettings(
91101
const val HOST = "host"
92102
const val APP_VERSION_HEADER = "app_version_header"
93103
const val USE_EXCEPTION_MESSAGE = "use_exception_message"
104+
const val LOG_TO_FILE_ENABLED = "log_to_file_enabled"
94105
}
95106
}

app/src/main/kotlin/me/proton/android/drive/ui/navigation/AppNavGraph.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import kotlinx.coroutines.flow.Flow
4747
import kotlinx.coroutines.flow.SharedFlow
4848
import kotlinx.coroutines.flow.collectLatest
4949
import me.proton.android.drive.extension.get
50-
import me.proton.android.drive.extension.popAllBackStack
5150
import me.proton.android.drive.extension.require
5251
import me.proton.android.drive.extension.requireArguments
5352
import me.proton.android.drive.extension.runFromRoute
@@ -132,8 +131,9 @@ fun AppNavGraph(
132131
LaunchedEffect(clearBackstackTrigger) {
133132
clearBackstackTrigger
134133
.collectLatest {
135-
navController.popAllBackStack()
136-
navController.navigate(Screen.Launcher.route)
134+
navController.navigate(Screen.Launcher.route) {
135+
popUpTo(0)
136+
}
137137
homeNavController = createNavController(localContext)
138138
}
139139
}

0 commit comments

Comments
 (0)