Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #5001: Set Up Firestore and Upload Free Form Responses #5098

Merged
merged 92 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
f81bdb1
Add show survey popup event log
adhiamboperes Jul 6, 2023
c51017f
Add begin survey event log
adhiamboperes Jul 6, 2023
1eadc30
Log survey response events
adhiamboperes Jul 7, 2023
b258164
Refactor tests
adhiamboperes Jul 9, 2023
50ac657
Add tests to verify the abandon survey event log
adhiamboperes Jul 9, 2023
6ad3a23
Add tests to verify the mandatory questions event logs
adhiamboperes Jul 9, 2023
913e2fe
Merge branch 'develop' of github.com:oppia/oppia-android into nps-sur…
adhiamboperes Jul 9, 2023
7ea7a13
Add test for begin survey event
adhiamboperes Jul 9, 2023
2558c0b
Add tests for SurveyEventsLogger
adhiamboperes Jul 9, 2023
4b2f8da
Add tests for Survey Events in OppiaLogger
adhiamboperes Jul 9, 2023
bb42456
Add bazel BUILD definition for SurveyEventsLogger
adhiamboperes Jul 9, 2023
277f3c9
Fix nits
adhiamboperes Jul 9, 2023
8e7f3f6
Remove large tests that can't run on either local or CI.
adhiamboperes Jul 9, 2023
bd844aa
Bazel BUILD dependency
adhiamboperes Jul 10, 2023
a264b3a
Refactor TODO and semantics
adhiamboperes Jul 10, 2023
f68e8ae
Update boolean naming
adhiamboperes Jul 11, 2023
9237c66
Merge branch 'develop' of github.com:oppia/oppia-android into nps-sur…
adhiamboperes Jul 11, 2023
cb22dfb
Log optional survey response
adhiamboperes Jul 21, 2023
110d96f
Add firebase Auth fore uploading to firestore
adhiamboperes Jul 21, 2023
c1d4c19
Add BUILD definitions for firestore loggers
adhiamboperes Jul 21, 2023
931019a
Add logic for syncing to firestore
adhiamboperes Jul 21, 2023
32566a6
update maven dependencies
adhiamboperes Jul 21, 2023
ba318eb
Fix import ordering
adhiamboperes Jul 21, 2023
f573158
pull develop and resolve conflicts
adhiamboperes Jul 21, 2023
6b4d488
Add new files to CODEOWNERS
adhiamboperes Jul 21, 2023
44e37b0
Fix prod bazel dependencies
adhiamboperes Jul 23, 2023
d1a11d3
Fix npe in domain/src/test/java/org/oppia/android/domain/oppialogger/…
adhiamboperes Jul 23, 2023
cb25e31
Remove redundant firestore/auth initialization
adhiamboperes Jul 25, 2023
b03011c
Introduce AuthenticationController
adhiamboperes Jul 26, 2023
d9a7fe5
Fix missing KDOc
adhiamboperes Jul 26, 2023
c0a48da
Add new files to CODEOWNERS
adhiamboperes Jul 26, 2023
e6c2568
Fix BUILD file formatting
adhiamboperes Jul 26, 2023
9ad162a
Merge branch 'develop' of github.com:oppia/oppia-android into nps-opt…
adhiamboperes Jul 26, 2023
0de4f3a
Fix failing log upload tests
adhiamboperes Jul 26, 2023
b7bafb5
Add more tests for FirestoreDataController
adhiamboperes Jul 26, 2023
7b13358
Add tests for FakeAuthenticationController.kt
adhiamboperes Jul 26, 2023
fe1dfdf
Add missing bazel dep for build flavors
adhiamboperes Jul 26, 2023
9d66b9f
Fix static check failures
adhiamboperes Jul 26, 2023
6f1fb2a
Add TestAuthenticationModule to test files.
adhiamboperes Jul 27, 2023
e3f1e84
Fix failing tests
adhiamboperes Jul 27, 2023
2996787
Rename variable in ViewEventLogsViewModel.kt
adhiamboperes Jul 28, 2023
ec2e3f8
Add missing dependency for e2e instrumentation module
adhiamboperes Jul 28, 2023
52c438a
Fix proguarding
adhiamboperes Jul 31, 2023
dc5dac3
Fix failing eventlog test
adhiamboperes Aug 1, 2023
93d3c6a
Fix failing tests
adhiamboperes Aug 3, 2023
a04caa9
Merge branch 'develop' of github.com:oppia/oppia-android into nps-opt…
adhiamboperes Aug 3, 2023
3e81132
Exempt AuthenticationModule from tests
adhiamboperes Aug 3, 2023
aeb213e
Ignore failing test
adhiamboperes Aug 3, 2023
781644f
Merge branch 'develop' of github.com:oppia/oppia-android into nps-opt…
adhiamboperes Aug 3, 2023
ca5cd8c
Reformat @Ignore
adhiamboperes Aug 3, 2023
6a0b78f
Refactor test
adhiamboperes Aug 3, 2023
bc05e0b
Refactor event logs viewmodel to use a fake in tests
adhiamboperes Sep 5, 2023
6bb7831
Merge branch 'develop' of github.com:oppia/oppia-android into nps-opt…
adhiamboperes Sep 6, 2023
64ad461
Add FakeAuthenticationControllerFactory
adhiamboperes Sep 7, 2023
8f5fc58
Add test for AuthenticationModule
adhiamboperes Sep 7, 2023
ccbc2e3
Fix static check test failures
adhiamboperes Sep 7, 2023
89a5bdf
Add newline after imports in OptionsActivityTest.kt
adhiamboperes Sep 21, 2023
d1c7240
Update file documentation
adhiamboperes Sep 21, 2023
78efadc
Update animal-sniffer-annotations license
adhiamboperes Sep 21, 2023
54d2538
Remove mockito from production deps
adhiamboperes Sep 26, 2023
d8d9d8c
Refactor auth tests build file comments
adhiamboperes Sep 26, 2023
4314ca0
Change firestore_logger_impl visibility to private
adhiamboperes Sep 26, 2023
e0bc397
Add test for TestAuthenticationModule
adhiamboperes Sep 27, 2023
ffb07d9
Refactor AuthenticationController and its bindings.
adhiamboperes Sep 29, 2023
64bb998
Renamed AuthenticationListener to AuthenticationWrapper.kt
adhiamboperes Sep 29, 2023
85115a6
Add TestAuthenticationModuleTest to CODEOWNERS
adhiamboperes Sep 29, 2023
7cccc8b
Create a debug interface for FirestoreEventLogger
adhiamboperes Oct 2, 2023
47921bd
Merge branch 'develop' of github.com:oppia/oppia-android into nps-opt…
adhiamboperes Oct 2, 2023
90cf929
Refactor DebugFirestoreEventLoggerImpl
adhiamboperes Oct 3, 2023
3e00d16
Fix failing tests
adhiamboperes Oct 3, 2023
022ef33
Merge branch 'develop' of github.com:oppia/oppia-android into nps-opt…
adhiamboperes Oct 18, 2023
35c0956
Fix DebugFirestoreEventLoggerImplTest tests
adhiamboperes Oct 23, 2023
ab161bf
Fix proguard failure.
adhiamboperes Oct 25, 2023
5848741
Merge branch 'develop' of github.com:oppia/oppia-android into nps-opt…
adhiamboperes Oct 26, 2023
8215c53
Fix failing tests
adhiamboperes Oct 26, 2023
99a15d3
Merge branch 'develop' into nps-optional-response-upload
adhiamboperes Nov 22, 2023
8336320
Merge branch 'develop' into nps-optional-response-upload
adhiamboperes Nov 29, 2023
e190fd9
Create firebase and firestore wrappers
adhiamboperes Jan 11, 2024
8a8d20d
Address review comments
adhiamboperes Jan 12, 2024
893f6e9
Merge branch 'develop' of github.com:oppia/oppia-android into nps-opt…
adhiamboperes Jan 12, 2024
a8e19df
Update maven install
adhiamboperes Jan 12, 2024
8fb5e6b
Add tests for prod impl of firebase auth
adhiamboperes Jan 15, 2024
06a999c
Remove singleton annotation from TestAuthenticationModule
adhiamboperes Jan 15, 2024
b5a1230
Add FakeFirebaseAuthInstanceWrapperImpl to CODEOWNERS
adhiamboperes Jan 15, 2024
4d3a893
Fix failing eventlogs tests
adhiamboperes Jan 15, 2024
e1776b8
Add test file exemption for FakeFirebaseAuthInstanceWrapperImpl
adhiamboperes Jan 16, 2024
2d4228c
Add withtimeout to authentication logic
adhiamboperes Jan 19, 2024
8a0088d
Resolve background dispatcher dependency
adhiamboperes Jan 23, 2024
dddbd98
Ensure debug firestore pushes events to the cloud
adhiamboperes Jan 23, 2024
d704240
Address PR feedback
adhiamboperes Jan 26, 2024
1f49d4a
Merge branch 'develop' into nps-optional-response-upload
adhiamboperes Jan 26, 2024
5e65643
Merge branch 'develop' into nps-optional-response-upload
adhiamboperes Jan 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@
# All domain and utility-specific shared test infrastructure.
/testing/src/main/java/org/oppia/android/testing/FakeAnalyticsEventLogger.kt @oppia/android-app-infrastructure-reviewers
/testing/src/main/java/org/oppia/android/testing/FakeExceptionLogger.kt @oppia/android-app-infrastructure-reviewers
/testing/src/main/java/org/oppia/android/testing/FakeFirebaseAuthInstanceWrapperImpl.kt @oppia/android-app-infrastructure-reviewers
/testing/src/main/java/org/oppia/android/testing/FakeFirebaseAuthWrapperImpl.kt @oppia/android-app-infrastructure-reviewers
/testing/src/main/java/org/oppia/android/testing/FakeFirestoreEventLogger.kt @oppia/android-app-infrastructure-reviewers
/testing/src/main/java/org/oppia/android/testing/FakeFirestoreInstanceWrapperImpl.kt @oppia/android-app-infrastructure-reviewers
/testing/src/main/java/org/oppia/android/testing/FakePerformanceMetricAssessor.kt @oppia/android-app-infrastructure-reviewers
/testing/src/main/java/org/oppia/android/testing/FakePerformanceMetricsEventLogger.kt @oppia/android-app-infrastructure-reviewers
/testing/src/main/java/org/oppia/android/testing/TestAuthenticationModule.kt @oppia/android-app-infrastructure-reviewers
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ dependencies {
'com.google.firebase:firebase-analytics-ktx:17.5.0',
'com.google.firebase:firebase-core:17.5.0',
'com.google.firebase:firebase-crashlytics:17.0.0',
'com.google.firebase:firebase-firestore-ktx:21.5.0',
'com.google.firebase:firebase-firestore-ktx:24.2.1',
'com.google.firebase:firebase-auth-ktx:19.3.1',
'com.google.guava:guava:28.1-android',
'com.google.protobuf:protobuf-javalite:3.17.3',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.oppia.android.app.devoptions.vieweventlogs

import org.oppia.android.app.fragment.FragmentScope
import org.oppia.android.app.model.EventLog
import org.oppia.android.app.translation.AppLanguageResourceHandler
import org.oppia.android.app.viewmodel.ObservableViewModel
import org.oppia.android.util.locale.OppiaLocale
Expand All @@ -25,7 +26,7 @@ class ViewEventLogsViewModel @Inject constructor(
// Retrieves events from cache that are meant to be uploaded to Firebase Analytics.
private val analyticsEvents = debugAnalyticsEventLogger.getEventList()

private val eventList = analyticsEvents + firestoreEvents
private val eventList = mutableListOf<EventLog>()

/**
* List of [EventLogItemViewModel] used to populate recyclerview of [ViewEventLogsFragment]
Expand All @@ -36,8 +37,14 @@ class ViewEventLogsViewModel @Inject constructor(
}

private fun processEventLogsList(): List<EventLogItemViewModel> {
return eventList.map {
EventLogItemViewModel(it, machineLocale, resourceHandler)
}.reversed()
return eventList
.apply {
addAll(analyticsEvents)
addAll(firestoreEvents)
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
}
.map {
EventLogItemViewModel(it, machineLocale, resourceHandler)
}
.sortedByDescending { it.eventLog.timestamp }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ class SurveyOutroDialogFragmentPresenter @Inject constructor(
private fun endSurveyWithCallback(callback: () -> Unit) {
surveyController.stopSurveySession(surveyCompleted = true).toLiveData().observe(
activity,
{
when (it) {
{ result ->
when (result) {
is AsyncResult.Pending -> oppiaLogger.d("SurveyActivity", "Stopping survey session")
is AsyncResult.Failure -> {
oppiaLogger.d("SurveyActivity", "Failed to stop the survey session, ${it.error}")
oppiaLogger.d("SurveyActivity", "Failed to stop the survey session", result.error)
activity.finish() // Can't recover from the session failing to stop.
}
is AsyncResult.Success -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ import org.oppia.android.domain.platformparameter.PlatformParameterSingletonModu
import org.oppia.android.domain.question.QuestionModule
import org.oppia.android.domain.topic.PrimeTopicAssetsControllerModule
import org.oppia.android.domain.workmanager.WorkManagerConfigurationModule
import org.oppia.android.testing.FakeFirestoreInstanceWrapperImpl
import org.oppia.android.testing.OppiaTestRule
import org.oppia.android.testing.RunOn
import org.oppia.android.testing.TestAuthenticationModule
import org.oppia.android.testing.TestPlatform
import org.oppia.android.testing.junit.InitializeDefaultLocaleRule
import org.oppia.android.testing.robolectric.RobolectricModule
import org.oppia.android.testing.threading.TestCoroutineDispatchers
Expand All @@ -108,7 +107,6 @@ import org.oppia.android.util.logging.firebase.FirebaseExceptionLogger
import org.oppia.android.util.logging.firebase.FirebaseLogUploaderModule
import org.oppia.android.util.logging.firebase.FirestoreEventLogger
import org.oppia.android.util.logging.firebase.FirestoreInstanceWrapper
import org.oppia.android.util.logging.firebase.FirestoreInstanceWrapperImpl
import org.oppia.android.util.logging.performancemetrics.PerformanceMetricsAssessorModule
import org.oppia.android.util.logging.performancemetrics.PerformanceMetricsConfigurationsModule
import org.oppia.android.util.logging.performancemetrics.PerformanceMetricsEventLogger
Expand Down Expand Up @@ -397,9 +395,7 @@ class ViewEventLogsFragmentTest {
}
}

@Test // TODO(#5143): On robolectric, there is a conflict between Firestore's Sqlite and
// robolectric's ShadowSQLiteConnection but this is resolved in newer versions of robolectric.
@RunOn(TestPlatform.ESPRESSO)
@Test
fun testViewEventLogsFragment_dateAndTimeIsDisplayedCorrectly() {
launch(ViewEventLogsTestActivity::class.java).use { scenario ->
testCoroutineDispatchers.runCurrent()
Expand Down Expand Up @@ -728,7 +724,7 @@ class ViewEventLogsFragmentTest {

@Provides
@Singleton
fun provideFirebaseFirestoreInstanceWrapper(wrapperImpl: FirestoreInstanceWrapperImpl):
fun provideFirebaseFirestoreInstanceWrapper(wrapperImpl: FakeFirestoreInstanceWrapperImpl):
FirestoreInstanceWrapper = wrapperImpl
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import org.oppia.android.domain.topic.PrimeTopicAssetsControllerModule
import org.oppia.android.domain.workmanager.WorkManagerConfigurationModule
import org.oppia.android.testing.DisableAccessibilityChecks
import org.oppia.android.testing.OppiaTestRule
import org.oppia.android.testing.TestAuthenticationModule
import org.oppia.android.testing.TestLogReportingModule
import org.oppia.android.testing.espresso.EditTextInputAction
import org.oppia.android.testing.junit.InitializeDefaultLocaleRule
Expand Down Expand Up @@ -578,7 +579,8 @@ class FractionInputInteractionViewTestActivityTest {
LoggingIdentifierModule::class, ApplicationLifecycleModule::class,
SyncStatusModule::class, MetricLogSchedulerModule::class, TestingBuildFlavorModule::class,
EventLoggingConfigurationModule::class, ActivityRouterModule::class,
CpuPerformanceSnapshotterModule::class, ExplorationProgressModule::class
CpuPerformanceSnapshotterModule::class, ExplorationProgressModule::class,
TestAuthenticationModule::class
]
)
interface TestApplicationComponent : ApplicationComponent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import org.oppia.android.domain.topic.PrimeTopicAssetsControllerModule
import org.oppia.android.domain.workmanager.WorkManagerConfigurationModule
import org.oppia.android.testing.DisableAccessibilityChecks
import org.oppia.android.testing.OppiaTestRule
import org.oppia.android.testing.TestAuthenticationModule
import org.oppia.android.testing.TestLogReportingModule
import org.oppia.android.testing.espresso.EditTextInputAction
import org.oppia.android.testing.junit.InitializeDefaultLocaleRule
Expand Down Expand Up @@ -446,7 +447,8 @@ class RatioInputInteractionViewTestActivityTest {
LoggingIdentifierModule::class, ApplicationLifecycleModule::class,
SyncStatusModule::class, MetricLogSchedulerModule::class, TestingBuildFlavorModule::class,
EventLoggingConfigurationModule::class, ActivityRouterModule::class,
CpuPerformanceSnapshotterModule::class, ExplorationProgressModule::class
CpuPerformanceSnapshotterModule::class, ExplorationProgressModule::class,
TestAuthenticationModule::class
]
)
interface TestApplicationComponent : ApplicationComponent {
Expand Down
3 changes: 1 addition & 2 deletions domain/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,11 @@ dependencies {
'com.google.dagger:dagger:2.24',
'com.google.firebase:firebase-analytics-ktx:17.5.0',
'com.google.firebase:firebase-crashlytics:17.0.0',
'com.google.firebase:firebase-firestore-ktx:21.5.0',
'com.google.firebase:firebase-firestore-ktx:24.2.1',
'com.google.firebase:firebase-auth-ktx:19.3.1',
'com.google.guava:guava:28.1-android',
'com.google.protobuf:protobuf-javalite:3.17.3',
"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version",
'org.mockito:mockito-core:2.19.0',
)
compileOnly(
'jakarta.xml.bind:jakarta.xml.bind-api:2.3.2',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,47 @@
package org.oppia.android.domain.auth

import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.TimeoutCancellationException
import kotlinx.coroutines.launch
import kotlinx.coroutines.withTimeout
import org.oppia.android.util.data.AsyncResult
import org.oppia.android.util.threading.BackgroundDispatcher
import java.util.concurrent.TimeoutException
import javax.inject.Inject
import javax.inject.Singleton

/** Controller for signing in and retrieving a Firebase user. */
@Singleton
class AuthenticationController @Inject constructor(
private val firebaseAuthWrapper: FirebaseAuthWrapper
private val firebaseAuthWrapper: FirebaseAuthWrapper,
@BackgroundDispatcher private val backgroundCoroutineDispatcher: CoroutineDispatcher
) {
/** Returns the current signed in user or null if there is no authenticated user. */
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
val currentFirebaseUser: FirebaseUserWrapper? = firebaseAuthWrapper.currentUser

/** Returns the result of an authentication task. */
fun signInAnonymouslyWithFirebase(): CompletableDeferred<AsyncResult<Any?>> {
val deferredResult = CompletableDeferred<AsyncResult<Any?>>()
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
firebaseAuthWrapper.signInAnonymously(
onSuccess = {
deferredResult.complete(AsyncResult.Success(null))
},
onFailure = { exception ->
deferredResult.complete(AsyncResult.Failure(exception))
val timeoutMillis = 3000L
CoroutineScope(backgroundCoroutineDispatcher).launch {
try {
withTimeout(timeoutMillis) {
firebaseAuthWrapper.signInAnonymously(
onSuccess = {
deferredResult.complete(AsyncResult.Success(null))
},
onFailure = { exception ->
deferredResult.complete(AsyncResult.Failure(exception))
}
)
}
} catch (e: TimeoutCancellationException) {
// Handle timeout exception
deferredResult.complete(
AsyncResult.Failure(TimeoutException("Authentication attempt timed out"))
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
)
}
)

}
return deferredResult
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import javax.inject.Singleton
class AuthenticationModule {
@Provides
@Singleton
fun provideFirebaseAuthWrapper(firebaseAuthInstanceWrapperImpl: FirebaseAuthInstanceWrapperImpl):
FirebaseAuthWrapper = FirebaseAuthWrapperImpl(firebaseAuthInstanceWrapperImpl)
fun provideFirebaseAuthWrapper(firebaseAuthInstanceWrapper: FirebaseAuthInstanceWrapper):
FirebaseAuthWrapper = FirebaseAuthWrapperImpl(firebaseAuthInstanceWrapper)

@Provides
@Singleton
fun provideFirebaseAuthInstanceWrapper(): FirebaseAuthInstanceWrapper =
FirebaseAuthInstanceWrapperImpl()
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ kt_android_library(
deps = [
":firebase_auth_wrapper",
"//third_party:javax_inject_javax_inject",
"//third_party:org_jetbrains_kotlinx_kotlinx-coroutines-core",
"//utility/src/main/java/org/oppia/android/util/threading:annotations",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package org.oppia.android.domain.auth
/** Interface for providing an implementation of [FirebaseAuthInstance]. */
interface FirebaseAuthInstanceWrapper {
/** Returns a wrapped instance of FirebaseAuth. */
val firebaseAuthInstance: FirebaseAuthInstance
val firebaseAuthInstance: FirebaseAuthInstance?
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import javax.inject.Singleton
/** Production implementation of FirebaseAuthWrapper. */
@Singleton
class FirebaseAuthWrapperImpl @Inject constructor(
private val firebaseWrapper: FirebaseAuthInstanceWrapperImpl
private val firebaseWrapper: FirebaseAuthInstanceWrapper
) : FirebaseAuthWrapper {
override val currentUser: FirebaseUserWrapper?
get() = firebaseWrapper.firebaseAuthInstance.firebaseAuth.currentUser?.let {
get() = firebaseWrapper.firebaseAuthInstance?.firebaseAuth?.currentUser?.let {
FirebaseUserWrapper(it.uid)
}

override fun signInAnonymously(onSuccess: () -> Unit, onFailure: (Throwable) -> Unit) {
firebaseWrapper.firebaseAuthInstance.firebaseAuth.signInAnonymously()
.addOnSuccessListener {
firebaseWrapper.firebaseAuthInstance?.firebaseAuth?.signInAnonymously()
?.addOnSuccessListener {
onSuccess.invoke()
}
.addOnFailureListener { task ->
?.addOnFailureListener { task ->
val exception = task.cause
if (exception != null) {
onFailure.invoke(exception)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,19 @@ class FirestoreDataController @Inject constructor(
* error will be thrown if something went wrong during upload.
*/
suspend fun uploadData() {
firestoreEventsStore.readDataAsync().await().eventLogsToUploadList.forEach { eventLog ->
authenticateAndUploadToFirestore(eventLog)
val eventLogsToUpload = firestoreEventsStore.readDataAsync().await().eventLogsToUploadList

if (eventLogsToUpload.isNotEmpty()) {
eventLogsToUpload.forEach { eventLog ->
authenticateAndUploadToFirestore(eventLog)
}.also {
removeFirstEventLogFromStore()
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

/**
* Logs a high priority event defined by [eventContext] corresponding to time [timestamp].
* Logs an event defined by [eventContext] corresponding to time [timestamp].
*
* This will schedule a background upload of the event if there's internet connectivity, otherwise
* it will cache the event for a later upload.
Expand Down Expand Up @@ -158,10 +164,13 @@ class FirestoreDataController @Inject constructor(
fun getEventLogStore(): DataProvider<OppiaEventLogs> = firestoreEventsStore

/** Removes the first log report that had been recorded for upload. */
fun removeFirstEventLogFromStore() {
println("removing first event log from store")
private fun removeFirstEventLogFromStore() {
firestoreEventsStore.storeDataAsync(updateInMemoryCache = true) { oppiaEventLogs ->
return@storeDataAsync oppiaEventLogs.toBuilder().removeEventLogsToUpload(0).build()
if (oppiaEventLogs.eventLogsToUploadCount > 0) {
return@storeDataAsync oppiaEventLogs.toBuilder().removeEventLogsToUpload(0).build()
} else {
return@storeDataAsync oppiaEventLogs // No event logs to remove
}
}.invokeOnCompletion {
it?.let {
consoleLogger.e("FirestoreDataController", "Failed to remove event log", it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ class LogUploadWorker private constructor(
private suspend fun uploadFirestoreData(): Result {
return try {
dataController.uploadData()
dataController.removeFirstEventLogFromStore()
Result.success()
} catch (e: Exception) {
consoleLogger.e(TAG, e.toString(), e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ import org.oppia.android.testing.TestAuthenticationModule
import org.oppia.android.testing.TestLogReportingModule
import org.oppia.android.testing.assertThrows
import org.oppia.android.testing.robolectric.RobolectricModule
import org.oppia.android.testing.threading.TestCoroutineDispatchers
import org.oppia.android.testing.threading.TestDispatcherModule
import org.oppia.android.testing.time.FakeOppiaClockModule
import org.oppia.android.util.data.DataProvidersInjector
import org.oppia.android.util.data.DataProvidersInjectorProvider
import org.oppia.android.util.threading.BackgroundDispatcher
import org.oppia.android.util.threading.DispatcherModule
import org.robolectric.annotation.Config
import org.robolectric.annotation.LooperMode
import javax.inject.Inject
Expand All @@ -46,9 +45,6 @@ class AuthenticationControllerTest {
@Inject
lateinit var authenticationController: AuthenticationController

@Inject
lateinit var testCoroutineDispatchers: TestCoroutineDispatchers

@field:[Inject BackgroundDispatcher]
lateinit var backgroundDispatcher: CoroutineDispatcher

Expand Down Expand Up @@ -116,7 +112,7 @@ class AuthenticationControllerTest {
@Component(
modules = [
TestModule::class, RobolectricModule::class, FakeOppiaClockModule::class,
ApplicationLifecycleModule::class, TestDispatcherModule::class,
ApplicationLifecycleModule::class, DispatcherModule::class,
TestLogReportingModule::class, TestAuthenticationModule::class,
]
)
Expand Down
Loading
Loading