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

Commit 9e9837f8 authored by Nishant D's avatar Nishant D
Browse files

Merge branch '1430-anonymous-domain-layer' into 'epic103-improve_app_lounge'

1430 anonymous domain layer

See merge request !344
parents a49b2e73 cd30e5b2
Loading
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -133,6 +133,13 @@ android {
    kotlin.sourceSets.all {
        languageSettings.optIn("kotlin.RequiresOptIn")
    }

    testOptions {
        unitTests {
            includeAndroidResources = true
            returnDefaultValues = true
        }
    }
}

kapt {
@@ -147,6 +154,8 @@ allOpen {

dependencies {

    implementation project(':modules')

    // TODO: Add splitinstall-lib to a repo https://gitlab.e.foundation/e/os/backlog/-/issues/628
    api files('libs/splitinstall-lib.jar')

@@ -250,4 +259,9 @@ dependencies {

    // elib
    implementation 'foundation.e:elib:0.0.1-alpha11'

    testImplementation 'org.mockito:mockito-core:5.0.0'
    testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0'
    testImplementation 'org.robolectric:robolectric:4.9'
    testImplementation 'org.json:json:20180813' // Added to avoid SystemInfoProvider.getAppBuildInfo() mock error
}
+9 −0
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import dagger.hilt.components.SingletonComponent
import foundation.e.apps.data.login.LoginSourceCleanApk
import foundation.e.apps.data.login.LoginSourceGPlay
import foundation.e.apps.data.login.LoginSourceInterface
import foundation.e.apps.domain.login.repository.LoginRepositoryImpl
import foundation.e.apps.domain.login.usecase.UserLoginUseCase

@InstallIn(SingletonComponent::class)
@Module
@@ -36,4 +38,11 @@ object LoginModule {
    ): List<LoginSourceInterface> {
        return listOf(gPlay, cleanApk)
    }

    @Provides
    fun provideLoginUserCase(
        loginRepositoryImpl: LoginRepositoryImpl
    ): UserLoginUseCase {
        return UserLoginUseCase(loginRepositoryImpl)
    }
}
+26 −0
Original line number Diff line number Diff line
/*
 * Copyright MURENA SAS 2023
 * Apps  Quickly and easily install Android apps onto your device!
 *
 * 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.domain.login.repository

import com.aurora.gplayapi.data.models.AuthData

interface LoginRepository {

    suspend fun anonymousUser(): AuthData
}
+57 −0
Original line number Diff line number Diff line
/*
 * Copyright MURENA SAS 2023
 * Apps  Quickly and easily install Android apps onto your device!
 *
 * 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.domain.login.repository

import android.content.Context
import app.lounge.login.anonymous.AnonymousUser
import app.lounge.model.AnonymousAuthDataRequestBody
import app.lounge.networking.NetworkResult
import app.lounge.storage.cache.configurations
import com.aurora.gplayapi.data.models.AuthData
import dagger.hilt.android.qualifiers.ApplicationContext
import foundation.e.apps.utils.SystemInfoProvider
import java.util.Properties
import javax.inject.Inject

class LoginRepositoryImpl @Inject constructor(
    @ApplicationContext val applicationContext: Context,
    private val properties: Properties,
    private val anonymousUser: AnonymousUser,
) : LoginRepository {

    private val userAgent: String by lazy { SystemInfoProvider.getAppBuildInfo() }

    override suspend fun anonymousUser(): AuthData {
        val result = anonymousUser.requestAuthData(
            anonymousAuthDataRequestBody = AnonymousAuthDataRequestBody(
                properties = properties,
                userAgent = userAgent
            )
        )

        when (result) {
            is NetworkResult.Error ->
                throw Exception(result.errorMessage, result.exception)
            is NetworkResult.Success -> {
                applicationContext.configurations.authData = result.data.toString()
                return result.data
            }
        }
    }
}
+41 −0
Original line number Diff line number Diff line
/*
 * Copyright MURENA SAS 2023
 * Apps  Quickly and easily install Android apps onto your device!
 *
 * 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.domain.login.usecase

import com.aurora.gplayapi.data.models.AuthData
import foundation.e.apps.domain.login.repository.LoginRepository
import foundation.e.apps.utils.Resource
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

class UserLoginUseCase @Inject constructor(
    private val loginRepository: LoginRepository,
) {

    fun anonymousUser(): Flow<Resource<AuthData>> = flow {
        try {
            emit(Resource.Loading())
            val userResponse = loginRepository.anonymousUser()
            emit(Resource.Success(userResponse))
        } catch (e: Exception) {
            emit(Resource.Error(e.localizedMessage))
        }
    }
}
Loading