Loading app/src/main/java/foundation/e/apps/domain/install/GetAppDetailsUseCase.kt +1 −1 Original line number Diff line number Diff line Loading @@ -44,7 +44,7 @@ class GetAppDetailsUseCase @Inject constructor( suspend operator fun invoke(packageName: String, source: Source? = null): Application { if (blockedAppRepository.isBlockedApp(packageName)) { throw UninstallableApp("Can't install $packageName, it is in NotWorkingApps list.").let { Timber.i(it) Timber.w(it) it } } Loading app/src/main/java/foundation/e/apps/domain/install/GetEnabledSearchSourcesUseCase.kt 0 → 100644 +13 −0 Original line number Diff line number Diff line package foundation.e.apps.domain.install import foundation.e.apps.data.Stores import foundation.e.apps.data.enums.Source import javax.inject.Inject class GetEnabledSearchSourcesUseCase @Inject constructor( private val stores: Stores, ) { operator fun invoke(): List<Source> { return stores.getEnabledSearchSources() } } app/src/main/java/foundation/e/apps/domain/install/GetGPlayAccountTypeUseCase.kt 0 → 100644 +16 −0 Original line number Diff line number Diff line package foundation.e.apps.domain.install import foundation.e.apps.data.enums.User import foundation.e.apps.data.preference.AppLoungeDataStore import kotlinx.coroutines.flow.first import javax.inject.Inject class GetGPlayAccountTypeUseCase @Inject constructor( private val appLoungeDataStore: AppLoungeDataStore, ) { suspend operator fun invoke(): User? { return runCatching { User.valueOf(appLoungeDataStore.userType.first()) }.getOrNull() } } app/src/main/java/foundation/e/apps/services/InstallAppService.kt +46 −1 Original line number Diff line number Diff line Loading @@ -23,16 +23,23 @@ import android.os.IBinder import androidx.lifecycle.LifecycleService import androidx.lifecycle.lifecycleScope import dagger.hilt.android.AndroidEntryPoint import foundation.e.apps.data.enums.Source import foundation.e.apps.data.enums.Status import foundation.e.apps.data.enums.User import foundation.e.apps.domain.install.GetEnabledSearchSourcesUseCase import foundation.e.apps.domain.install.GetGPlayAccountTypeUseCase import foundation.e.apps.domain.install.InstallAppByIdUseCase import foundation.e.apps.installapp.AppInstallationStatus import foundation.e.apps.installapp.GPlayAccountTypes import foundation.e.apps.installapp.IInstallAppCallback import foundation.e.apps.installapp.IInstallAppService import foundation.e.apps.installapp.SearchableSources import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import javax.inject.Inject @AndroidEntryPoint Loading @@ -41,10 +48,26 @@ class InstallAppService : LifecycleService() { @Inject lateinit var installAppByIdUseCase: InstallAppByIdUseCase @Inject lateinit var getGPlayAccountTypeUseCase: GetGPlayAccountTypeUseCase @Inject lateinit var getEnabledSearchSourcesUseCase: GetEnabledSearchSourcesUseCase private val binder = object : IInstallAppService.Stub() { private var installAppJob: Job? = null override fun installAppId(packageName: String, callback: IInstallAppCallback) { override fun getGPlayAccountType(): String { return runBlocking { serializeUserForInstallAppLib(getGPlayAccountTypeUseCase()) } } override fun getEnabledSearchSources(): List<String> { return serializeSourcesForInstallAppLib(getEnabledSearchSourcesUseCase()) } override fun installApp(packageName: String, callback: IInstallAppCallback) { if (installAppJob?.isActive == true) { callback.onDone(AppInstallationStatus.SERVICE_BUSY.name) return Loading Loading @@ -73,6 +96,8 @@ class InstallAppService : LifecycleService() { } } // Mapper from apps.domain to install-app-lib. fun Status?.toAppInstallationStatus(): AppInstallationStatus { return when (this) { Status.UPDATABLE, Loading @@ -93,3 +118,23 @@ fun Status?.toAppInstallationStatus(): AppInstallationStatus { null -> AppInstallationStatus.UNKNOWN } } fun serializeUserForInstallAppLib(userType: User?): String { return when (userType) { User.NO_GOOGLE -> GPlayAccountTypes.NO_GOOGLE User.ANONYMOUS -> GPlayAccountTypes.ANONYMOUS User.GOOGLE -> GPlayAccountTypes.GOOGLE null -> GPlayAccountTypes.NOT_CONFIGURED }.name } fun serializeSourcesForInstallAppLib(sources: List<Source>): List<String> { return sources.mapNotNull { source -> when (source) { Source.OPEN_SOURCE -> SearchableSources.OPEN_SOURCE Source.PWA -> SearchableSources.PWA Source.SYSTEM_APP -> null Source.PLAY_STORE -> SearchableSources.PLAY_STORE }?.name } } install-app-lib/src/main/aidl/foundation/e/apps/installapp/IInstallAppService.aidl +3 −1 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ package foundation.e.apps.installapp; import foundation.e.apps.installapp.IInstallAppCallback; interface IInstallAppService { void installAppId(String packageName, IInstallAppCallback callback); List<String> getEnabledSearchSources(); String getGPlayAccountType(); void installApp(String packageName, IInstallAppCallback callback); void cancelCurrentInstallation(); } Loading
app/src/main/java/foundation/e/apps/domain/install/GetAppDetailsUseCase.kt +1 −1 Original line number Diff line number Diff line Loading @@ -44,7 +44,7 @@ class GetAppDetailsUseCase @Inject constructor( suspend operator fun invoke(packageName: String, source: Source? = null): Application { if (blockedAppRepository.isBlockedApp(packageName)) { throw UninstallableApp("Can't install $packageName, it is in NotWorkingApps list.").let { Timber.i(it) Timber.w(it) it } } Loading
app/src/main/java/foundation/e/apps/domain/install/GetEnabledSearchSourcesUseCase.kt 0 → 100644 +13 −0 Original line number Diff line number Diff line package foundation.e.apps.domain.install import foundation.e.apps.data.Stores import foundation.e.apps.data.enums.Source import javax.inject.Inject class GetEnabledSearchSourcesUseCase @Inject constructor( private val stores: Stores, ) { operator fun invoke(): List<Source> { return stores.getEnabledSearchSources() } }
app/src/main/java/foundation/e/apps/domain/install/GetGPlayAccountTypeUseCase.kt 0 → 100644 +16 −0 Original line number Diff line number Diff line package foundation.e.apps.domain.install import foundation.e.apps.data.enums.User import foundation.e.apps.data.preference.AppLoungeDataStore import kotlinx.coroutines.flow.first import javax.inject.Inject class GetGPlayAccountTypeUseCase @Inject constructor( private val appLoungeDataStore: AppLoungeDataStore, ) { suspend operator fun invoke(): User? { return runCatching { User.valueOf(appLoungeDataStore.userType.first()) }.getOrNull() } }
app/src/main/java/foundation/e/apps/services/InstallAppService.kt +46 −1 Original line number Diff line number Diff line Loading @@ -23,16 +23,23 @@ import android.os.IBinder import androidx.lifecycle.LifecycleService import androidx.lifecycle.lifecycleScope import dagger.hilt.android.AndroidEntryPoint import foundation.e.apps.data.enums.Source import foundation.e.apps.data.enums.Status import foundation.e.apps.data.enums.User import foundation.e.apps.domain.install.GetEnabledSearchSourcesUseCase import foundation.e.apps.domain.install.GetGPlayAccountTypeUseCase import foundation.e.apps.domain.install.InstallAppByIdUseCase import foundation.e.apps.installapp.AppInstallationStatus import foundation.e.apps.installapp.GPlayAccountTypes import foundation.e.apps.installapp.IInstallAppCallback import foundation.e.apps.installapp.IInstallAppService import foundation.e.apps.installapp.SearchableSources import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import javax.inject.Inject @AndroidEntryPoint Loading @@ -41,10 +48,26 @@ class InstallAppService : LifecycleService() { @Inject lateinit var installAppByIdUseCase: InstallAppByIdUseCase @Inject lateinit var getGPlayAccountTypeUseCase: GetGPlayAccountTypeUseCase @Inject lateinit var getEnabledSearchSourcesUseCase: GetEnabledSearchSourcesUseCase private val binder = object : IInstallAppService.Stub() { private var installAppJob: Job? = null override fun installAppId(packageName: String, callback: IInstallAppCallback) { override fun getGPlayAccountType(): String { return runBlocking { serializeUserForInstallAppLib(getGPlayAccountTypeUseCase()) } } override fun getEnabledSearchSources(): List<String> { return serializeSourcesForInstallAppLib(getEnabledSearchSourcesUseCase()) } override fun installApp(packageName: String, callback: IInstallAppCallback) { if (installAppJob?.isActive == true) { callback.onDone(AppInstallationStatus.SERVICE_BUSY.name) return Loading Loading @@ -73,6 +96,8 @@ class InstallAppService : LifecycleService() { } } // Mapper from apps.domain to install-app-lib. fun Status?.toAppInstallationStatus(): AppInstallationStatus { return when (this) { Status.UPDATABLE, Loading @@ -93,3 +118,23 @@ fun Status?.toAppInstallationStatus(): AppInstallationStatus { null -> AppInstallationStatus.UNKNOWN } } fun serializeUserForInstallAppLib(userType: User?): String { return when (userType) { User.NO_GOOGLE -> GPlayAccountTypes.NO_GOOGLE User.ANONYMOUS -> GPlayAccountTypes.ANONYMOUS User.GOOGLE -> GPlayAccountTypes.GOOGLE null -> GPlayAccountTypes.NOT_CONFIGURED }.name } fun serializeSourcesForInstallAppLib(sources: List<Source>): List<String> { return sources.mapNotNull { source -> when (source) { Source.OPEN_SOURCE -> SearchableSources.OPEN_SOURCE Source.PWA -> SearchableSources.PWA Source.SYSTEM_APP -> null Source.PLAY_STORE -> SearchableSources.PLAY_STORE }?.name } }
install-app-lib/src/main/aidl/foundation/e/apps/installapp/IInstallAppService.aidl +3 −1 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ package foundation.e.apps.installapp; import foundation.e.apps.installapp.IInstallAppCallback; interface IInstallAppService { void installAppId(String packageName, IInstallAppCallback callback); List<String> getEnabledSearchSources(); String getGPlayAccountType(); void installApp(String packageName, IInstallAppCallback callback); void cancelCurrentInstallation(); }