Loading app/src/main/java/foundation/e/apps/MainActivityViewModel.kt +1 −1 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ import foundation.e.apps.api.gplay.utils.AC2DMUtil import foundation.e.apps.manager.database.fusedDownload.FusedDownload import foundation.e.apps.manager.fused.FusedManagerRepository import foundation.e.apps.manager.pkg.PkgManagerModule import foundation.e.apps.utils.Constants.timeoutDurationInMillis import foundation.e.apps.utils.enums.Origin import foundation.e.apps.utils.enums.Status import foundation.e.apps.utils.enums.Type Loading @@ -55,7 +56,6 @@ import foundation.e.apps.utils.enums.User import foundation.e.apps.utils.enums.isInitialized import foundation.e.apps.utils.enums.isUnFiltered import foundation.e.apps.utils.modules.CommonUtilsModule.NETWORK_CODE_SUCCESS import foundation.e.apps.utils.modules.CommonUtilsModule.timeoutDurationInMillis import foundation.e.apps.utils.modules.DataStoreModule import foundation.e.apps.utils.modules.PWAManagerModule import kotlinx.coroutines.Dispatchers Loading app/src/main/java/foundation/e/apps/api/ResultSupreme.kt +8 −3 Original line number Diff line number Diff line Loading @@ -70,7 +70,7 @@ sealed class ResultSupreme<T> { * @param message A String message to log or display to the user. * @param exception Optional exception from try-catch block. */ constructor(message: String, exception: Exception = Exception()) : this() { constructor(message: String, exception: Exception? = null) : this() { this.message = message this.exception = exception } Loading @@ -91,6 +91,11 @@ sealed class ResultSupreme<T> { var data: T? = null private set /** * Any other information that needs to be transmitted. */ var otherPayload: Any? = null /** * A custom string message for logging or displaying to the user. */ Loading @@ -99,7 +104,7 @@ sealed class ResultSupreme<T> { /** * Exception from try-catch block for error cases. */ var exception: Exception = Exception() var exception: Exception? = null fun isValidData() = data != null Loading @@ -121,7 +126,7 @@ sealed class ResultSupreme<T> { status: ResultStatus, data: T? = null, message: String = "", exception: Exception = Exception(), exception: Exception? = null, ): ResultSupreme<T> { val resultObject = when { status == ResultStatus.OK && data != null -> Success<T>(data) Loading app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt +1 −1 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ import foundation.e.apps.api.gplay.GPlayAPIRepository import foundation.e.apps.home.model.HomeChildFusedAppDiffUtil import foundation.e.apps.manager.database.fusedDownload.FusedDownload import foundation.e.apps.manager.pkg.PkgManagerModule import foundation.e.apps.utils.Constants.timeoutDurationInMillis import foundation.e.apps.utils.enums.AppTag import foundation.e.apps.utils.enums.FilterLevel import foundation.e.apps.utils.enums.Origin Loading @@ -57,7 +58,6 @@ import foundation.e.apps.utils.enums.ResultStatus import foundation.e.apps.utils.enums.Status import foundation.e.apps.utils.enums.Type import foundation.e.apps.utils.enums.isUnFiltered import foundation.e.apps.utils.modules.CommonUtilsModule.timeoutDurationInMillis import foundation.e.apps.utils.modules.PWAManagerModule import foundation.e.apps.utils.modules.PreferenceManagerModule import kotlinx.coroutines.TimeoutCancellationException Loading app/src/main/java/foundation/e/apps/api/gplay/utils/GPlayHttpClient.kt +4 −2 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ package foundation.e.apps.api.gplay.utils import com.aurora.gplayapi.data.models.PlayResponse import com.aurora.gplayapi.network.IHttpClient import foundation.e.apps.utils.modules.CommonUtilsModule.timeoutDurationInMillis import foundation.e.apps.utils.Constants.timeoutDurationInMillis import okhttp3.Cache import okhttp3.Headers.Companion.toHeaders import okhttp3.HttpUrl Loading Loading @@ -161,7 +161,9 @@ class GPlayHttpClient @Inject constructor( private fun handleExceptionOnGooglePlayRequest(e: Exception): PlayResponse { Timber.e("processRequest: ${e.localizedMessage}") return PlayResponse() return PlayResponse().apply { errorString = "${this@GPlayHttpClient::class.java.simpleName}: ${e.localizedMessage}" } } private fun buildUrl(url: String, params: Map<String, String>): HttpUrl { Loading app/src/main/java/foundation/e/apps/login/api/AnonymousLoginApi.kt 0 → 100644 +84 −0 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.login.api import com.aurora.gplayapi.data.models.AuthData import com.aurora.gplayapi.data.models.PlayResponse import com.google.gson.Gson import foundation.e.apps.BuildConfig import foundation.e.apps.api.gplay.utils.CustomAuthValidator import foundation.e.apps.api.gplay.utils.GPlayHttpClient import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import java.util.Properties import javax.inject.Inject import javax.inject.Singleton @Singleton class AnonymousLoginApi @Inject constructor( private val gPlayHttpClient: GPlayHttpClient, private val nativeDeviceProperty: Properties, private val gson: Gson, ) : GPlayLoginInterface { private val tokenUrl: String get() { return if (BuildConfig.DEBUG) "https://eu.gtoken.eeo.one" else "https://eu.gtoken.ecloud.global" } /** * Fetches AuthData for Anonymous login. * @param email Keep it blank (""). * @param aasToken Keep it blank (""). */ override suspend fun fetchAuthData(email: String, aasToken: String): AuthData? { var authData: AuthData? = null withContext(Dispatchers.IO) { val response = gPlayHttpClient.postAuth(tokenUrl, gson.toJson(nativeDeviceProperty).toByteArray()) if (response.code != 200 || !response.isSuccessful) { throw Exception("Error fetching Anonymous credentials: ${response.errorString}") } else { authData = gson.fromJson( String(response.responseBytes), AuthData::class.java ) } } return authData } /** * Check if an AuthData is valid. Returns a [PlayResponse]. * Check [PlayResponse.isSuccessful] to see if the validation was successful. */ override suspend fun login(authData: AuthData): PlayResponse { var result = PlayResponse() withContext(Dispatchers.IO) { try { val authValidator = CustomAuthValidator(authData).using(gPlayHttpClient) result = authValidator.getValidityResponse() } catch (e: Exception) { e.printStackTrace() throw e } } return result } } Loading
app/src/main/java/foundation/e/apps/MainActivityViewModel.kt +1 −1 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ import foundation.e.apps.api.gplay.utils.AC2DMUtil import foundation.e.apps.manager.database.fusedDownload.FusedDownload import foundation.e.apps.manager.fused.FusedManagerRepository import foundation.e.apps.manager.pkg.PkgManagerModule import foundation.e.apps.utils.Constants.timeoutDurationInMillis import foundation.e.apps.utils.enums.Origin import foundation.e.apps.utils.enums.Status import foundation.e.apps.utils.enums.Type Loading @@ -55,7 +56,6 @@ import foundation.e.apps.utils.enums.User import foundation.e.apps.utils.enums.isInitialized import foundation.e.apps.utils.enums.isUnFiltered import foundation.e.apps.utils.modules.CommonUtilsModule.NETWORK_CODE_SUCCESS import foundation.e.apps.utils.modules.CommonUtilsModule.timeoutDurationInMillis import foundation.e.apps.utils.modules.DataStoreModule import foundation.e.apps.utils.modules.PWAManagerModule import kotlinx.coroutines.Dispatchers Loading
app/src/main/java/foundation/e/apps/api/ResultSupreme.kt +8 −3 Original line number Diff line number Diff line Loading @@ -70,7 +70,7 @@ sealed class ResultSupreme<T> { * @param message A String message to log or display to the user. * @param exception Optional exception from try-catch block. */ constructor(message: String, exception: Exception = Exception()) : this() { constructor(message: String, exception: Exception? = null) : this() { this.message = message this.exception = exception } Loading @@ -91,6 +91,11 @@ sealed class ResultSupreme<T> { var data: T? = null private set /** * Any other information that needs to be transmitted. */ var otherPayload: Any? = null /** * A custom string message for logging or displaying to the user. */ Loading @@ -99,7 +104,7 @@ sealed class ResultSupreme<T> { /** * Exception from try-catch block for error cases. */ var exception: Exception = Exception() var exception: Exception? = null fun isValidData() = data != null Loading @@ -121,7 +126,7 @@ sealed class ResultSupreme<T> { status: ResultStatus, data: T? = null, message: String = "", exception: Exception = Exception(), exception: Exception? = null, ): ResultSupreme<T> { val resultObject = when { status == ResultStatus.OK && data != null -> Success<T>(data) Loading
app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt +1 −1 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ import foundation.e.apps.api.gplay.GPlayAPIRepository import foundation.e.apps.home.model.HomeChildFusedAppDiffUtil import foundation.e.apps.manager.database.fusedDownload.FusedDownload import foundation.e.apps.manager.pkg.PkgManagerModule import foundation.e.apps.utils.Constants.timeoutDurationInMillis import foundation.e.apps.utils.enums.AppTag import foundation.e.apps.utils.enums.FilterLevel import foundation.e.apps.utils.enums.Origin Loading @@ -57,7 +58,6 @@ import foundation.e.apps.utils.enums.ResultStatus import foundation.e.apps.utils.enums.Status import foundation.e.apps.utils.enums.Type import foundation.e.apps.utils.enums.isUnFiltered import foundation.e.apps.utils.modules.CommonUtilsModule.timeoutDurationInMillis import foundation.e.apps.utils.modules.PWAManagerModule import foundation.e.apps.utils.modules.PreferenceManagerModule import kotlinx.coroutines.TimeoutCancellationException Loading
app/src/main/java/foundation/e/apps/api/gplay/utils/GPlayHttpClient.kt +4 −2 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ package foundation.e.apps.api.gplay.utils import com.aurora.gplayapi.data.models.PlayResponse import com.aurora.gplayapi.network.IHttpClient import foundation.e.apps.utils.modules.CommonUtilsModule.timeoutDurationInMillis import foundation.e.apps.utils.Constants.timeoutDurationInMillis import okhttp3.Cache import okhttp3.Headers.Companion.toHeaders import okhttp3.HttpUrl Loading Loading @@ -161,7 +161,9 @@ class GPlayHttpClient @Inject constructor( private fun handleExceptionOnGooglePlayRequest(e: Exception): PlayResponse { Timber.e("processRequest: ${e.localizedMessage}") return PlayResponse() return PlayResponse().apply { errorString = "${this@GPlayHttpClient::class.java.simpleName}: ${e.localizedMessage}" } } private fun buildUrl(url: String, params: Map<String, String>): HttpUrl { Loading
app/src/main/java/foundation/e/apps/login/api/AnonymousLoginApi.kt 0 → 100644 +84 −0 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.login.api import com.aurora.gplayapi.data.models.AuthData import com.aurora.gplayapi.data.models.PlayResponse import com.google.gson.Gson import foundation.e.apps.BuildConfig import foundation.e.apps.api.gplay.utils.CustomAuthValidator import foundation.e.apps.api.gplay.utils.GPlayHttpClient import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import java.util.Properties import javax.inject.Inject import javax.inject.Singleton @Singleton class AnonymousLoginApi @Inject constructor( private val gPlayHttpClient: GPlayHttpClient, private val nativeDeviceProperty: Properties, private val gson: Gson, ) : GPlayLoginInterface { private val tokenUrl: String get() { return if (BuildConfig.DEBUG) "https://eu.gtoken.eeo.one" else "https://eu.gtoken.ecloud.global" } /** * Fetches AuthData for Anonymous login. * @param email Keep it blank (""). * @param aasToken Keep it blank (""). */ override suspend fun fetchAuthData(email: String, aasToken: String): AuthData? { var authData: AuthData? = null withContext(Dispatchers.IO) { val response = gPlayHttpClient.postAuth(tokenUrl, gson.toJson(nativeDeviceProperty).toByteArray()) if (response.code != 200 || !response.isSuccessful) { throw Exception("Error fetching Anonymous credentials: ${response.errorString}") } else { authData = gson.fromJson( String(response.responseBytes), AuthData::class.java ) } } return authData } /** * Check if an AuthData is valid. Returns a [PlayResponse]. * Check [PlayResponse.isSuccessful] to see if the validation was successful. */ override suspend fun login(authData: AuthData): PlayResponse { var result = PlayResponse() withContext(Dispatchers.IO) { try { val authValidator = CustomAuthValidator(authData).using(gPlayHttpClient) result = authValidator.getValidityResponse() } catch (e: Exception) { e.printStackTrace() throw e } } return result } }