diff --git a/app/src/main/java/foundation/e/apps/data/exodus/repositories/AppPrivacyInfoRepositoryImpl.kt b/app/src/main/java/foundation/e/apps/data/exodus/repositories/AppPrivacyInfoRepositoryImpl.kt index 9900f6712266a2f3b47f4e7bf16fd0e3c75909b4..0584b8c8cdb4df8bfe416897bd5dd5563bec4780 100644 --- a/app/src/main/java/foundation/e/apps/data/exodus/repositories/AppPrivacyInfoRepositoryImpl.kt +++ b/app/src/main/java/foundation/e/apps/data/exodus/repositories/AppPrivacyInfoRepositoryImpl.kt @@ -33,6 +33,7 @@ import java.lang.reflect.Modifier import javax.inject.Inject import javax.inject.Singleton import foundation.e.apps.data.Result +import okio.IOException @Singleton class AppPrivacyInfoRepositoryImpl @Inject constructor( @@ -72,14 +73,20 @@ class AppPrivacyInfoRepositoryImpl @Inject constructor( .post(jsonBody.toRequestBody("application/json".toMediaType())) .build() - okHttpClient.newCall(request).execute().use { response -> - if (response.isSuccessful) { - val responseBody = response.body?.string() - return parseReports(responseBody ?: "") - } else { - throw IllegalStateException("Failed to fetch reports") + try { + okHttpClient.newCall(request).execute().use { response -> + if (response.isSuccessful) { + val responseBody = response.body?.string() + return parseReports(responseBody ?: "") + } else { + throw IllegalStateException("Failed to fetch reports") + } } + } catch (exception: IOException) { + exception.printStackTrace() } + + return emptyList() } private fun parseReports(response: String): List { diff --git a/app/src/main/java/foundation/e/apps/data/login/AuthenticatorRepository.kt b/app/src/main/java/foundation/e/apps/data/login/AuthenticatorRepository.kt index fccc0b15aec13f192dbe1d174224294152080b07..1aa297978cb88c6edad5194866db334d27aa6e1d 100644 --- a/app/src/main/java/foundation/e/apps/data/login/AuthenticatorRepository.kt +++ b/app/src/main/java/foundation/e/apps/data/login/AuthenticatorRepository.kt @@ -21,6 +21,7 @@ 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 @@ -29,16 +30,19 @@ import javax.inject.Singleton class AuthenticatorRepository @Inject constructor( private val loginCommon: LoginCommon, private val authenticators: List, + private val appLoungeDataStore: AppLoungeDataStore ) { - private var gPlayAuth: AuthData? = null - fun getGPlayAuthOrThrow(): AuthData { - return gPlayAuth ?: throw GPlayLoginException(false, "AuthData is not available!", getUserType()) + return kotlin.runCatching { + appLoungeDataStore.getAuthData() + }.getOrElse { + throw GPlayLoginException(false, "AuthData is not available", appLoungeDataStore.getUserType()) + } } - fun setGPlayAuth(auth: AuthData) { - gPlayAuth = auth + suspend fun setGPlayAuth(auth: AuthData) { + appLoungeDataStore.saveAuthData(auth) } suspend fun getAuthObjects(clearAuthTypes: List = listOf()): List { @@ -55,7 +59,7 @@ class AuthenticatorRepository @Inject constructor( authObjectsLocal.add(authObject) if (authObject is AuthObject.GPlayAuth) { - gPlayAuth = authObject.result.data + appLoungeDataStore.saveAuthData(authObject.result.data) } } @@ -81,7 +85,7 @@ class AuthenticatorRepository @Inject constructor( suspend fun getValidatedAuthData(): ResultSupreme { val authDataValidator = (authenticators.find { it is AuthDataValidator } as AuthDataValidator) val validateAuthData = authDataValidator.validateAuthData() - this.gPlayAuth = validateAuthData.data + appLoungeDataStore.saveAuthData(validateAuthData.data) return validateAuthData } diff --git a/app/src/main/java/foundation/e/apps/data/preference/AppLoungeDataStore.kt b/app/src/main/java/foundation/e/apps/data/preference/AppLoungeDataStore.kt index 5b22a91a14605a4f29cbf7ae5db72f083856b3e8..85fc326b4ae35a55ad8fcaa0bddd126110a56b96 100644 --- a/app/src/main/java/foundation/e/apps/data/preference/AppLoungeDataStore.kt +++ b/app/src/main/java/foundation/e/apps/data/preference/AppLoungeDataStore.kt @@ -89,6 +89,10 @@ class AppLoungeDataStore @Inject constructor( } } + fun getAuthData(): AuthData { + return gson.fromJson(authData.getSync(), AuthData::class.java) + } + /** * Destroy auth credentials if they are no longer valid. * diff --git a/app/src/main/java/foundation/e/apps/data/preference/DataStoreManager.kt b/app/src/main/java/foundation/e/apps/data/preference/DataStoreManager.kt deleted file mode 100644 index a3194625013b0b9cb5452879ab05ef240948eff6..0000000000000000000000000000000000000000 --- a/app/src/main/java/foundation/e/apps/data/preference/DataStoreManager.kt +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2022 Murena SAS - * - * 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 . - */ - -package foundation.e.apps.data.preference - -import com.aurora.gplayapi.data.models.AuthData -import com.google.gson.Gson -import foundation.e.apps.data.enums.User -import javax.inject.Inject -import javax.inject.Singleton - -@Singleton -class DataStoreManager @Inject constructor() { - @Inject - lateinit var appLoungeDataStore: AppLoungeDataStore - - @Inject - lateinit var gson: Gson - - fun getAuthData(): AuthData { - val authDataJson = appLoungeDataStore.authData.getSync() - return gson.fromJson(authDataJson, AuthData::class.java) ?: AuthData("", "") - } - - fun getUserType(): User { - return appLoungeDataStore.getUserType() - } -} diff --git a/app/src/main/java/foundation/e/apps/install/splitinstall/SplitInstallBinder.kt b/app/src/main/java/foundation/e/apps/install/splitinstall/SplitInstallBinder.kt index a3e0c76842ee4749e548469b7bf66982cdb582b2..557d5ba3d5fb90d01f1ba9fb84520029f08326dc 100644 --- a/app/src/main/java/foundation/e/apps/install/splitinstall/SplitInstallBinder.kt +++ b/app/src/main/java/foundation/e/apps/install/splitinstall/SplitInstallBinder.kt @@ -184,7 +184,7 @@ class SplitInstallBinder( val url = fetchModuleUrl(packageName, moduleName, versionCode) if (url == null) { - Timber.e("Could not find split module named $moduleName for $packageName package") + Timber.w("Could not find split module named $moduleName for $packageName package") return@withContext } diff --git a/app/src/main/java/foundation/e/apps/install/updates/UpdatesWorker.kt b/app/src/main/java/foundation/e/apps/install/updates/UpdatesWorker.kt index 65f78637e16d61cfe75b828f6e4e683ea286f023..776d6f0882a1ff28f9235be82d55426529efbcf3 100644 --- a/app/src/main/java/foundation/e/apps/install/updates/UpdatesWorker.kt +++ b/app/src/main/java/foundation/e/apps/install/updates/UpdatesWorker.kt @@ -22,7 +22,7 @@ import foundation.e.apps.data.enums.User import foundation.e.apps.data.application.data.Application import foundation.e.apps.data.gitlab.SystemAppsUpdatesRepository import foundation.e.apps.data.login.AuthenticatorRepository -import foundation.e.apps.data.preference.DataStoreManager +import foundation.e.apps.data.preference.AppLoungeDataStore import foundation.e.apps.data.updates.UpdatesManagerRepository import foundation.e.apps.install.workmanager.AppInstallProcessor import foundation.e.apps.utils.eventBus.AppEvent @@ -37,7 +37,7 @@ class UpdatesWorker @AssistedInject constructor( @Assisted private val context: Context, @Assisted private val params: WorkerParameters, private val updatesManagerRepository: UpdatesManagerRepository, - private val dataStoreManager: DataStoreManager, + private val appLoungeDataStore: AppLoungeDataStore, private val authenticatorRepository: AuthenticatorRepository, private val appInstallProcessor: AppInstallProcessor, private val blockedAppRepository: BlockedAppRepository, @@ -101,7 +101,7 @@ class UpdatesWorker @AssistedInject constructor( } private fun getUser(): User { - return dataStoreManager.getUserType() + return appLoungeDataStore.getUserType() } private suspend fun checkForUpdates() { diff --git a/app/src/main/java/foundation/e/apps/install/workmanager/AppInstallProcessor.kt b/app/src/main/java/foundation/e/apps/install/workmanager/AppInstallProcessor.kt index 8ba19b9c2d9cefce9e8a5f0e4e1541af4b48ec34..2c929ce8f64870b11d441fc880a25341f4433756 100644 --- a/app/src/main/java/foundation/e/apps/install/workmanager/AppInstallProcessor.kt +++ b/app/src/main/java/foundation/e/apps/install/workmanager/AppInstallProcessor.kt @@ -32,7 +32,7 @@ import foundation.e.apps.data.application.data.Application import foundation.e.apps.data.enums.Origin import foundation.e.apps.data.install.models.AppInstall import foundation.e.apps.data.playstore.utils.GplayHttpRequestException -import foundation.e.apps.data.preference.DataStoreManager +import foundation.e.apps.data.preference.AppLoungeDataStore import foundation.e.apps.domain.ValidateAppAgeLimitUseCase import foundation.e.apps.install.AppInstallComponents import foundation.e.apps.install.download.DownloadManagerUtils @@ -55,7 +55,7 @@ class AppInstallProcessor @Inject constructor( private val appInstallComponents: AppInstallComponents, private val applicationRepository: ApplicationRepository, private val validateAppAgeLimitUseCase: ValidateAppAgeLimitUseCase, - private val dataStoreManager: DataStoreManager, + private val appLoungeDataStore: AppLoungeDataStore, private val storageNotificationManager: StorageNotificationManager, ) { @@ -117,7 +117,7 @@ class AppInstallProcessor @Inject constructor( isAnUpdate: Boolean = false ) { try { - val authData = dataStoreManager.getAuthData() + val authData = appLoungeDataStore.getAuthData() if (!appInstall.isFree && authData.isAnonymous) { EventBus.invokeEvent(AppEvent.ErrorMessageEvent(R.string.paid_app_anonymous_message)) @@ -324,7 +324,7 @@ class AppInstallProcessor @Inject constructor( } private fun showNotificationOnUpdateEnded() { - val locale = dataStoreManager.getAuthData().locale + val locale = appLoungeDataStore.getAuthData().locale val date = Date().getFormattedString(DATE_FORMAT, locale) val numberOfUpdatedApps = NumberFormat.getNumberInstance(locale).format(UpdatesDao.successfulUpdatedApps.size) diff --git a/app/src/main/java/foundation/e/apps/microg/AuthDataProvider.kt b/app/src/main/java/foundation/e/apps/microg/AuthDataProvider.kt index 0e914479ffc7cc4e1feea1c0f318c70570d8b070..6632486dfb12d8552f56b6542a691c4fb534b281 100644 --- a/app/src/main/java/foundation/e/apps/microg/AuthDataProvider.kt +++ b/app/src/main/java/foundation/e/apps/microg/AuthDataProvider.kt @@ -29,7 +29,7 @@ import dagger.hilt.InstallIn import dagger.hilt.android.EntryPointAccessors import dagger.hilt.components.SingletonComponent import foundation.e.apps.authdata.AuthDataContract -import foundation.e.apps.data.preference.DataStoreManager +import foundation.e.apps.data.preference.AppLoungeDataStore /** * Content provider dedicated to share the Google auth data with @@ -40,21 +40,21 @@ class AuthDataProvider : ContentProvider() { @EntryPoint @InstallIn(SingletonComponent::class) - interface DataStoreManagerEntryPoint { - fun provideDataStoreManager(): DataStoreManager + interface DataStoreProvider { + fun provideAppLoungeDataStore(): AppLoungeDataStore } - private lateinit var dataStoreManager: DataStoreManager + private lateinit var appLoungeDataStore: AppLoungeDataStore override fun onCreate(): Boolean { val context = context ?: return false val dataStoreEntryPoint = EntryPointAccessors.fromApplication( context.applicationContext, - DataStoreManagerEntryPoint::class.java + DataStoreProvider::class.java ) - dataStoreManager = dataStoreEntryPoint.provideDataStoreManager() + appLoungeDataStore = dataStoreEntryPoint.provideAppLoungeDataStore() return true } @@ -80,7 +80,7 @@ class AuthDataProvider : ContentProvider() { ) val row = cursor.newRow() - dataStoreManager.getAuthData().let { + appLoungeDataStore.getAuthData().let { row.add(AuthDataContract.EMAIL_KEY, it.email) row.add(AuthDataContract.AUTH_TOKEN_KEY, it.authToken) row.add(AuthDataContract.GSF_ID_KEY, it.gsfId) diff --git a/app/src/main/java/foundation/e/apps/provider/AgeRatingProvider.kt b/app/src/main/java/foundation/e/apps/provider/AgeRatingProvider.kt index 0ed06df83d601b6acf738b76bc78e2b020aa88d8..38097b0a41ad810d7ca5d6f06d223bb2e4d0fdb1 100644 --- a/app/src/main/java/foundation/e/apps/provider/AgeRatingProvider.kt +++ b/app/src/main/java/foundation/e/apps/provider/AgeRatingProvider.kt @@ -26,7 +26,6 @@ import android.content.UriMatcher import android.database.Cursor import android.database.MatrixCursor import android.net.Uri -import android.os.Build import androidx.core.app.NotificationCompat import dagger.hilt.EntryPoint import dagger.hilt.InstallIn @@ -49,7 +48,7 @@ import foundation.e.apps.data.parentalcontrol.ContentRatingDao import foundation.e.apps.data.parentalcontrol.ContentRatingEntity import foundation.e.apps.data.parentalcontrol.fdroid.FDroidAntiFeatureRepository import foundation.e.apps.data.parentalcontrol.googleplay.GPlayContentRatingRepository -import foundation.e.apps.data.preference.DataStoreManager +import foundation.e.apps.data.preference.AppLoungeDataStore import foundation.e.apps.domain.ValidateAppAgeLimitUseCase import foundation.e.apps.domain.model.ContentRatingValidity import foundation.e.apps.install.pkg.AppLoungePackageManager @@ -71,7 +70,7 @@ class AgeRatingProvider : ContentProvider() { fun provideGPlayContentRatingsRepository(): GPlayContentRatingRepository fun provideFDroidAntiFeatureRepository(): FDroidAntiFeatureRepository fun provideValidateAppAgeLimitUseCase(): ValidateAppAgeLimitUseCase - fun provideDataStoreManager(): DataStoreManager + fun provideAppLoungeDataStore(): AppLoungeDataStore fun provideNotificationManager(): NotificationManager fun provideContentRatingDao(): ContentRatingDao fun provideBlockedAppRepository(): BlockedAppRepository @@ -87,7 +86,7 @@ class AgeRatingProvider : ContentProvider() { private lateinit var gPlayContentRatingRepository: GPlayContentRatingRepository private lateinit var fDroidAntiFeatureRepository: FDroidAntiFeatureRepository private lateinit var validateAppAgeLimitUseCase: ValidateAppAgeLimitUseCase - private lateinit var dataStoreManager: DataStoreManager + private lateinit var appLoungeDataStore: AppLoungeDataStore private lateinit var notificationManager: NotificationManager private lateinit var contentRatingDao: ContentRatingDao private lateinit var blockedAppRepository: BlockedAppRepository @@ -124,7 +123,7 @@ class AgeRatingProvider : ContentProvider() { private fun getLoginType(): Cursor { val cursor = MatrixCursor(arrayOf(COLUMN_LOGIN_TYPE)) - cursor.addRow(arrayOf(dataStoreManager.getUserType())) + cursor.addRow(arrayOf(appLoungeDataStore.getUserType())) return cursor } @@ -198,8 +197,8 @@ class AgeRatingProvider : ContentProvider() { * Setup AuthData for other APIs to access, * if user has logged in with Google or Anonymous mode. */ - private fun initAuthData() { - val authData = dataStoreManager.getAuthData() + private suspend fun initAuthData() { + val authData = appLoungeDataStore.getAuthData() if (authData.email.isNotBlank() && authData.authToken.isNotBlank()) { authenticatorRepository.setGPlayAuth(authData) } @@ -308,7 +307,7 @@ class AgeRatingProvider : ContentProvider() { gPlayContentRatingRepository = hiltEntryPoint.provideGPlayContentRatingsRepository() fDroidAntiFeatureRepository = hiltEntryPoint.provideFDroidAntiFeatureRepository() validateAppAgeLimitUseCase = hiltEntryPoint.provideValidateAppAgeLimitUseCase() - dataStoreManager = hiltEntryPoint.provideDataStoreManager() + appLoungeDataStore = hiltEntryPoint.provideAppLoungeDataStore() notificationManager = hiltEntryPoint.provideNotificationManager() contentRatingDao = hiltEntryPoint.provideContentRatingDao() blockedAppRepository = hiltEntryPoint.provideBlockedAppRepository() diff --git a/app/src/test/java/foundation/e/apps/installProcessor/AppInstallProcessorTest.kt b/app/src/test/java/foundation/e/apps/installProcessor/AppInstallProcessorTest.kt index 28d386f684653e3a890eca986011359a7e28515d..25edd4c73b4103957d2757983584795d419448ea 100644 --- a/app/src/test/java/foundation/e/apps/installProcessor/AppInstallProcessorTest.kt +++ b/app/src/test/java/foundation/e/apps/installProcessor/AppInstallProcessorTest.kt @@ -29,7 +29,7 @@ import foundation.e.apps.data.enums.ResultStatus import foundation.e.apps.data.install.AppInstallRepository import foundation.e.apps.data.install.AppManager import foundation.e.apps.data.install.models.AppInstall -import foundation.e.apps.data.preference.DataStoreManager +import foundation.e.apps.data.preference.AppLoungeDataStore import foundation.e.apps.domain.ValidateAppAgeLimitUseCase import foundation.e.apps.domain.model.ContentRatingValidity import foundation.e.apps.install.AppInstallComponents @@ -73,7 +73,7 @@ class AppInstallProcessorTest { private lateinit var context: Context @Mock - private lateinit var dataStoreManager: DataStoreManager + private lateinit var appLoungeDataStore: AppLoungeDataStore @Mock private lateinit var applicationRepository: ApplicationRepository @@ -101,7 +101,7 @@ class AppInstallProcessorTest { appInstallComponents, applicationRepository, validateAppAgeRatingUseCase, - dataStoreManager, + appLoungeDataStore, storageNotificationManager ) } @@ -120,7 +120,7 @@ class AppInstallProcessorTest { ): AppInstall { val fusedDownload = createFusedDownload(packageName, downloadUrlList) fakeFusedDownloadDAO.addDownload(fusedDownload) - Mockito.`when`(dataStoreManager.getAuthData()).thenReturn(AuthData("", "")) + Mockito.`when`(appLoungeDataStore.getAuthData()).thenReturn(AuthData("", "")) return fusedDownload }