Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9df1f318 authored by Jonathan Klee's avatar Jonathan Klee
Browse files

refactor: remove useless InvalidAuthEvent

Reauth is done on-demand at the low-level app details implementation
parent c85eb023
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ sealed class AppEvent(val data: Any) {
    class SignatureMissMatchError(packageName: String) : AppEvent(packageName)
    class UpdateEvent(result: ResultSupreme.WorkError<ResultStatus>) : AppEvent(result)

    class InvalidAuthEvent(authName: String) : AppEvent(authName)
    class ErrorMessageEvent(stringResourceId: Int) : AppEvent(stringResourceId)
    class ErrorMessageDialogEvent(stringResourceId: Int) : AppEvent(stringResourceId)
    class AppPurchaseEvent(appInstall: AppInstall) : AppEvent(appInstall)
+0 −7
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import com.aurora.gplayapi.data.models.PlayResponse
import com.aurora.gplayapi.network.IHttpClient
import foundation.e.apps.data.event.AppEvent
import foundation.e.apps.data.event.EventBus
import foundation.e.apps.data.login.core.AuthObject
import foundation.e.apps.data.system.SystemInfoProvider
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.asContextElement
@@ -219,12 +218,6 @@ class GPlayHttpClient @Inject constructor(
        val responseBytes = response.body?.bytes() ?: byteArrayOf()

        when (code) {
            STATUS_CODE_UNAUTHORIZED -> MainScope().launch {
                EventBus.invokeEvent(
                    AppEvent.InvalidAuthEvent(AuthObject.GPlayAuth::class.java.simpleName)
                )
            }

            STATUS_CODE_TOO_MANY_REQUESTS -> MainScope().launch {
                if (url.toString().contains(SEARCH_SUGGEST)) {
                    return@launch
+0 −25
Original line number Diff line number Diff line
@@ -36,7 +36,6 @@ import foundation.e.apps.login.MicrogAccountFetchResult
import foundation.e.apps.login.MicrogAccountFetcher
import foundation.e.apps.login.StoreAuthCoordinator
import kotlinx.coroutines.launch
import okhttp3.Cache
import javax.inject.Inject

/**
@@ -53,7 +52,6 @@ class LoginViewModel @Inject constructor(
    private val googleLoginUseCase: GoogleLoginUseCase,
    private val noGoogleLoginUseCase: NoGoogleLoginUseCase,
    private val logoutUseCase: LogoutUseCase,
    private val cache: Cache,
    @ApplicationContext private val context: Context
) : ViewModel() {

@@ -163,29 +161,6 @@ class LoginViewModel @Inject constructor(
        }
    }

    /**
     * Once an AuthObject is marked as invalid, it will be refreshed
     * automatically by LoadingViewModel.
     * If GPlay auth is invalid, LoadingViewModel.onLoadData has a retry block,
     * this block will clear existing GPlay AuthData and freshly start the login flow.
     */
    fun markInvalidAuthObject(authObjectName: String) {
        val authObjectsLocal = authObjects.value?.toMutableList()
        val invalidObject = authObjectsLocal?.find { it::class.java.simpleName == authObjectName }

        val replacedObject = invalidObject?.createInvalidAuthObject()

        authObjectsLocal?.apply {
            if (invalidObject != null && replacedObject != null) {
                remove(invalidObject)
                add(replacedObject)
            }
        }

        authObjects.postValue(authObjectsLocal)
        cache.evictAll()
    }

    /**
     * Clears all saved data and logs out the user to the sign in screen.
     */
+0 −25
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import android.os.Build.VERSION
import android.os.Build.VERSION_CODES
import android.os.Bundle
import android.view.View
import android.widget.Toast
import android.window.OnBackInvokedDispatcher.PRIORITY_DEFAULT
import androidx.activity.OnBackPressedCallback
import androidx.activity.result.contract.ActivityResultContracts
@@ -261,10 +260,6 @@ class MainActivity : AppCompatActivity() {
    private fun observeEvents() {
        lifecycleScope.launch {
            repeatOnLifecycle(Lifecycle.State.STARTED) {
                launch {
                    observeInvalidAuth()
                }

                launch {
                    observeAppUnavailable()
                }
@@ -520,19 +515,6 @@ class MainActivity : AppCompatActivity() {
        }
    }

    private suspend fun observeInvalidAuth() {
        EventBus.events.filter { appEvent ->
            appEvent is AppEvent.InvalidAuthEvent
        }.distinctUntilChanged { old, new ->
            ((old.data is String) && (new.data is String) && old.data == new.data)
        }.collectLatest {
            if (BuildConfig.DEBUG) {
                Toast.makeText(this, "Refreshing token...", Toast.LENGTH_SHORT).show()
            }
            validatedAuthObject(it)
        }
    }

    private suspend fun observeAppUnavailable() {
        EventBus.events.filterIsInstance<AppEvent.AppRestrictedOrUnavailable>()
            .collectLatest { event ->
@@ -542,13 +524,6 @@ class MainActivity : AppCompatActivity() {
            }
    }

    private fun validatedAuthObject(appEvent: AppEvent) {
        val data = appEvent.data as String
        if (data.isNotBlank()) {
            loginViewModel.markInvalidAuthObject(data)
        }
    }

    private suspend fun observeTooManyRequests() {
        EventBus.events.filter { appEvent ->
            appEvent is AppEvent.TooManyRequests
+0 −6
Original line number Diff line number Diff line
@@ -148,12 +148,6 @@ class ApplicationViewModel @Inject constructor(

                updateShareVisibilityState(app.shareUri.toString())
                updateAppContentRatingState(packageName, app.contentRating)

                if (status != ResultStatus.OK) {
                    EventBus.invokeEvent(
                        AppEvent.InvalidAuthEvent(AuthObject.GPlayAuth::class.java.simpleName)
                    )
                }
            } catch (e: InternalException.AppNotFound) {
                _errorMessageLiveData.postValue(R.string.app_not_found)
                scheduleAutoRedirect()
Loading