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

Commit dd53844b authored by Guillaume Jacquart's avatar Guillaume Jacquart
Browse files

refac:3870: remove AuthenticatorRepository.

parent 509bf227
Loading
Loading
Loading
Loading
+0 −36
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019-2022  E FOUNDATION
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package foundation.e.apps.data.login

import com.aurora.gplayapi.data.models.AuthData
import foundation.e.apps.data.ResultSupreme
import foundation.e.apps.data.enums.User
import foundation.e.apps.data.login.exceptions.GPlayLoginException
import foundation.e.apps.data.preference.AppLoungeDataStore
import javax.inject.Inject
import javax.inject.Singleton

@JvmSuppressWildcards
@Singleton
class AuthenticatorRepository @Inject constructor(
    private val appLoungeDataStore: AppLoungeDataStore
) {
    suspend fun setGPlayAuth(auth: AuthData) {
        appLoungeDataStore.saveAuthData(auth)
    }
}
+0 −3
Original line number Diff line number Diff line
@@ -21,8 +21,6 @@ import com.aurora.gplayapi.data.models.AuthData
import com.aurora.gplayapi.data.models.PlayResponse
import com.aurora.gplayapi.helpers.AuthHelper
import foundation.e.apps.data.playstore.utils.AC2DMTask
import foundation.e.apps.data.playstore.utils.CustomAuthValidator
import foundation.e.apps.data.playstore.utils.GPlayHttpClient
import foundation.e.apps.data.preference.AppLoungeDataStore
import foundation.e.apps.data.preference.getSync
import kotlinx.coroutines.Dispatchers
@@ -30,7 +28,6 @@ import kotlinx.coroutines.withContext
import java.util.Properties

class GoogleLoginManager(
    private val gPlayHttpClient: GPlayHttpClient,
    private val nativeDeviceProperty: Properties,
    private val aC2DMTask: AC2DMTask,
    private val appLoungeDataStore: AppLoungeDataStore,
+1 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ class PlayStoreLoginManagerFactory @Inject constructor(

    fun createLoginManager(user: User): PlayStoreLoginManager {
        return when (user) {
            User.GOOGLE -> GoogleLoginManager(gPlayHttpClient, nativeDeviceProperty, aC2DMTask, appLoungeDataStore)
            User.GOOGLE -> GoogleLoginManager(nativeDeviceProperty, aC2DMTask, appLoungeDataStore)
            else -> AnonymousLoginManager(gPlayHttpClient, nativeDeviceProperty, json)
        }
    }
+22 −5
Original line number Diff line number Diff line
@@ -19,11 +19,14 @@
package foundation.e.apps.data.playstore

import android.content.Context
import com.aurora.gplayapi.GooglePlayApi
import com.aurora.gplayapi.data.models.AuthData
import com.aurora.gplayapi.data.models.Category
import com.aurora.gplayapi.data.models.ContentRating
import com.aurora.gplayapi.data.models.PlayFile
import com.aurora.gplayapi.data.models.PlayResponse
import com.aurora.gplayapi.data.models.StreamCluster
import com.aurora.gplayapi.data.providers.HeaderProvider
import com.aurora.gplayapi.helpers.AppDetailsHelper
import com.aurora.gplayapi.helpers.ContentRatingHelper
import com.aurora.gplayapi.helpers.PurchaseHelper
@@ -35,6 +38,7 @@ import com.aurora.gplayapi.helpers.web.WebCategoryStreamHelper
import com.aurora.gplayapi.helpers.web.WebTopChartsHelper
import dagger.hilt.android.qualifiers.ApplicationContext
import foundation.e.apps.R
import foundation.e.apps.data.ResultSupreme
import foundation.e.apps.data.StoreRepository
import foundation.e.apps.data.application.ApplicationDataManager
import foundation.e.apps.data.application.data.Application
@@ -44,8 +48,7 @@ import foundation.e.apps.data.application.utils.CategoryType
import foundation.e.apps.data.application.utils.toApplication
import foundation.e.apps.data.enums.Source
import foundation.e.apps.data.handleNetworkResult
import foundation.e.apps.data.login.AuthenticatorRepository
import foundation.e.apps.data.login.PlayStoreAuthenticator
import foundation.e.apps.data.login.exceptions.GPlayLoginException
import foundation.e.apps.data.playstore.utils.GPlayHttpClient
import foundation.e.apps.data.playstore.utils.GplayHttpRequestException
import foundation.e.apps.data.preference.AppLoungeDataStore
@@ -62,7 +65,6 @@ import com.aurora.gplayapi.data.models.App as GplayApp
class PlayStoreRepository @Inject constructor(
    @ApplicationContext private val context: Context,
    private val gPlayHttpClient: GPlayHttpClient,
    private val authenticatorRepository: AuthenticatorRepository,
    private val gPlayAuthentication: GPlayAuthentication,
    private val applicationDataManager: ApplicationDataManager,
    private val playStoreSearchHelper: PlayStoreSearchHelper,
@@ -334,10 +336,25 @@ class PlayStoreRepository @Inject constructor(
        }
    }

    //inline fun <T> runSuspendCatching(block: () -> T): Result<T> {

    private suspend fun <T> doAuthenticatedRequest(request: suspend (AuthData) -> T): T {
        val authData = appLoungeDataStore.getAuthData()
        return request(authData)
    }

    // Helper function, to detect error not specific to the request
    // (authentication stale, network unreachable, ...)
    // This can be used to workaround Exception swallowing done by GPlayAPI library.
    private suspend fun sendCommonErrorsProbe() {
        withContext(Dispatchers.IO) {
            val endpoint: String = GooglePlayApi.URL_SYNC
            val headers = HeaderProvider.getDefaultHeaders(appLoungeDataStore.getAuthData())

            // No expectation for the response result, just look for the exceptions:
            // will send on EventBus error for 401, 429.
            // will throw GplayHttpRequestException for all response code "not 200 or 429".
            // will throw SocketTimeoutException as GplayHttpRequestException 408
            // will throw all other exceptions.
            gPlayHttpClient.post(endpoint, headers, hashMapOf())
        }
    }
}
+0 −39
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019-2022  E FOUNDATION
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package foundation.e.apps.di

import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import foundation.e.apps.data.login.CleanApkAuthenticator
import foundation.e.apps.data.login.PlayStoreAuthenticator
import foundation.e.apps.data.login.StoreAuthenticator

@InstallIn(SingletonComponent::class)
@Module
object LoginModule {

    @Provides
    fun providesAuthenticators(
        gPlay: PlayStoreAuthenticator,
        cleanApk: CleanApkAuthenticator,
    ): List<StoreAuthenticator> {
        return listOf(gPlay, cleanApk)
    }
}
Loading