diff --git a/app/src/main/java/com/aurora/store/data/service/UpdateService.kt b/app/src/main/java/com/aurora/store/data/service/UpdateService.kt index f9766df01..a76c24b5f 100644 --- a/app/src/main/java/com/aurora/store/data/service/UpdateService.kt +++ b/app/src/main/java/com/aurora/store/data/service/UpdateService.kt @@ -45,7 +45,7 @@ import java.util.* import java.util.concurrent.locks.ReentrantLock import kotlin.concurrent.timerTask -class UpdateService: LifecycleService() { +class UpdateService : LifecycleService() { lateinit var fetch: Fetch lateinit var downloadManager: DownloadManager @@ -53,7 +53,7 @@ class UpdateService: LifecycleService() { private var fetchActiveDownloadObserver = object : FetchObserver { override fun onChanged(data: Boolean, reason: Reason) { if (!data && isEmptyInstalling() && fetchListeners.isEmpty() && appMetadataListeners.isEmpty()) { - Handler(Looper.getMainLooper()).postDelayed ({ + Handler(Looper.getMainLooper()).postDelayed({ if (isEmptyInstalling() && fetchListeners.isEmpty() && appMetadataListeners.isEmpty()) { stopSelf() } @@ -74,7 +74,7 @@ class UpdateService: LifecycleService() { var liveUpdateData: MutableLiveData> = MutableLiveData() inner class UpdateServiceBinder : Binder() { - fun getUpdateService() : UpdateService { + fun getUpdateService(): UpdateService { return this@UpdateService } } @@ -181,9 +181,11 @@ class UpdateService: LifecycleService() { private lateinit var authData: AuthData - data class AppDownloadStatus(val download: Download, val fetchGroup: FetchGroup, - val isCancelled: Boolean = false, - val isComplete: Boolean = false) + data class AppDownloadStatus( + val download: Download, val fetchGroup: FetchGroup, + val isCancelled: Boolean = false, + val isComplete: Boolean = false + ) data class AppMetadataStatus(val reason: String, val app: App) @@ -252,17 +254,32 @@ class UpdateService: LifecycleService() { fetchGroup: FetchGroup ) { fetchListeners.forEach { - it.onProgress(groupId, download, etaInMilliSeconds, downloadedBytesPerSecond, fetchGroup) + it.onProgress( + groupId, + download, + etaInMilliSeconds, + downloadedBytesPerSecond, + fetchGroup + ) } } - override fun onProgress(download: Download, etaInMilliSeconds: Long, downloadedBytesPerSecond: Long) { + override fun onProgress( + download: Download, + etaInMilliSeconds: Long, + downloadedBytesPerSecond: Long + ) { fetchListeners.forEach { it.onProgress(download, etaInMilliSeconds, downloadedBytesPerSecond) } } - override fun onQueued(groupId: Int, download: Download, waitingNetwork: Boolean, fetchGroup: FetchGroup) { + override fun onQueued( + groupId: Int, + download: Download, + waitingNetwork: Boolean, + fetchGroup: FetchGroup + ) { fetchListeners.forEach { it.onQueued(groupId, download, waitingNetwork, fetchGroup) } @@ -311,20 +328,30 @@ class UpdateService: LifecycleService() { download, downloadBlocks, totalBlocks, - fetchGroup) + fetchGroup + ) } } - override fun onStarted(download: Download, downloadBlocks: List, totalBlocks: Int) { + override fun onStarted( + download: Download, + downloadBlocks: List, + totalBlocks: Int + ) { fetchListeners.forEach { it.onStarted( download, downloadBlocks, - totalBlocks) + totalBlocks + ) } } - override fun onWaitingNetwork(groupId: Int, download: Download, fetchGroup: FetchGroup) { + override fun onWaitingNetwork( + groupId: Int, + download: Download, + fetchGroup: FetchGroup + ) { fetchListeners.forEach { it.onWaitingNetwork(groupId, download, fetchGroup) } @@ -341,7 +368,8 @@ class UpdateService: LifecycleService() { it.onCompleted(groupId, download, fetchGroup) } if (fetchListeners.isEmpty()) { - fetchPendingEvents[groupId] = AppDownloadStatus(download, fetchGroup, isComplete = true) + fetchPendingEvents[groupId] = + AppDownloadStatus(download, fetchGroup, isComplete = true) } var packageDownloadFilesWhichCompleted = downloadsInCompletedGroup[download.tag!!] if (packageDownloadFilesWhichCompleted == null) { @@ -349,7 +377,11 @@ class UpdateService: LifecycleService() { downloadsInCompletedGroup[download.tag!!] = packageDownloadFilesWhichCompleted } packageDownloadFilesWhichCompleted.add(download.file) - if (fetchGroup.groupDownloadProgress == 100 && fetchGroup.downloads.all { packageDownloadFilesWhichCompleted.contains(it.file) }) { + if (fetchGroup.groupDownloadProgress == 100 && fetchGroup.downloads.all { + packageDownloadFilesWhichCompleted.contains( + it.file + ) + }) { downloadsInCompletedGroup.remove(download.tag!!) if (download.tag != null) { removeFromInstalling(download.tag, runFromCurrentThread = true) @@ -381,7 +413,8 @@ class UpdateService: LifecycleService() { it.onCancelled(groupId, download, fetchGroup) } if (fetchListeners.isEmpty()) { - fetchPendingEvents[groupId] = AppDownloadStatus(download, fetchGroup, isCancelled = true) + fetchPendingEvents[groupId] = + AppDownloadStatus(download, fetchGroup, isCancelled = true) } } @@ -396,7 +429,8 @@ class UpdateService: LifecycleService() { it.onDeleted(groupId, download, fetchGroup) } if (fetchListeners.isEmpty()) { - fetchPendingEvents[groupId] = AppDownloadStatus(download, fetchGroup, isCancelled = true) + fetchPendingEvents[groupId] = + AppDownloadStatus(download, fetchGroup, isCancelled = true) } } @@ -424,7 +458,11 @@ class UpdateService: LifecycleService() { } } - override fun onDownloadBlockUpdated(download: Download, downloadBlock: DownloadBlock, totalBlocks: Int) { + override fun onDownloadBlockUpdated( + download: Download, + downloadBlock: DownloadBlock, + totalBlocks: Int + ) { fetchListeners.forEach { it.onDownloadBlockUpdated( download, @@ -612,11 +650,19 @@ class UpdateService: LifecycleService() { if (downloads.all { File(it.file).exists() }) { serviceScope.launch { try { - AppInstaller.getInstance(this@UpdateService).getPreferredInstaller() - .install( - packageName, - files.filter { it.file.endsWith(".apk") }.map { it.file }.toList() - ) + val autoInstall = Preferences.getBoolean( + this@UpdateService, + Preferences.PREFERENCE_AUTO_INSTALL + ) + + if (autoInstall) { + AppInstaller.getInstance(this@UpdateService).getPreferredInstaller() + .install( + packageName, + files.filter { it.file.endsWith(".apk") }.map { it.file } + .toList() + ) + } } catch (exception: Exception) { removeFromInstalling(packageName) Log.e(exception.stackTraceToString()) @@ -645,16 +691,16 @@ class UpdateService: LifecycleService() { removeFromInstalling(this) } synchronized(timerLock) { - if (timer != null) { + timer = if (timer != null) { timer!!.cancel() - timer = null - } - if (timer == null) { - timer = Timer() + null + } else { + Timer() } timer!!.schedule(timerTask { timerTaskRun.run() }, 5 * 1000) } } + else -> { } diff --git a/app/src/main/java/com/aurora/store/view/ui/details/AppDetailsFragment.kt b/app/src/main/java/com/aurora/store/view/ui/details/AppDetailsFragment.kt index 206a5e585..ebd4bc121 100644 --- a/app/src/main/java/com/aurora/store/view/ui/details/AppDetailsFragment.kt +++ b/app/src/main/java/com/aurora/store/view/ui/details/AppDetailsFragment.kt @@ -179,7 +179,7 @@ class AppDetailsFragment : BaseFragment(R.layout.fragment_details) { private var isInstalled: Boolean = false private var isUpdatable: Boolean = false private var autoDownload: Boolean = false - private var downloadOnly: Boolean = false + private var autoInstall: Boolean = true private var uninstallActionEnabled = false val listOfActionsWhenServiceAttaches = ArrayList() @@ -441,7 +441,9 @@ class AppDetailsFragment : BaseFragment(R.layout.fragment_details) { } private fun verifyAndInstall(files: List) { - if (downloadOnly) + autoInstall = Preferences.getBoolean(requireContext(), Preferences.PREFERENCE_AUTO_INSTALL) + + if (!autoInstall) return var filesExist = true diff --git a/app/src/main/java/com/aurora/store/view/ui/onboarding/OnboardingFragment.kt b/app/src/main/java/com/aurora/store/view/ui/onboarding/OnboardingFragment.kt index 1028c7e50..9ed150638 100644 --- a/app/src/main/java/com/aurora/store/view/ui/onboarding/OnboardingFragment.kt +++ b/app/src/main/java/com/aurora/store/view/ui/onboarding/OnboardingFragment.kt @@ -33,6 +33,7 @@ import com.aurora.store.data.work.UpdateWorker import com.aurora.store.databinding.FragmentOnboardingBinding import com.aurora.store.util.Preferences import com.aurora.store.util.Preferences.PREFERENCE_AUTO_DELETE +import com.aurora.store.util.Preferences.PREFERENCE_AUTO_INSTALL import com.aurora.store.util.Preferences.PREFERENCE_DEFAULT import com.aurora.store.util.Preferences.PREFERENCE_DEFAULT_SELECTED_TAB import com.aurora.store.util.Preferences.PREFERENCE_DOWNLOAD_ACTIVE @@ -167,6 +168,7 @@ class OnboardingFragment : Fragment(R.layout.fragment_onboarding) { /*Installer*/ save(PREFERENCE_AUTO_DELETE, true) + save(PREFERENCE_AUTO_INSTALL, true) save(PREFERENCE_INSTALLER_ID, 0) /*Updates*/ diff --git a/app/src/main/java/com/aurora/store/viewmodel/details/AppDetailsViewModel.kt b/app/src/main/java/com/aurora/store/viewmodel/details/AppDetailsViewModel.kt index 74951c9da..a3e126642 100644 --- a/app/src/main/java/com/aurora/store/viewmodel/details/AppDetailsViewModel.kt +++ b/app/src/main/java/com/aurora/store/viewmodel/details/AppDetailsViewModel.kt @@ -14,6 +14,7 @@ import com.aurora.store.data.model.ExodusReport import com.aurora.store.data.model.Report import com.aurora.store.data.network.HttpClient import com.aurora.store.data.providers.AuthProvider +import com.aurora.store.util.Preferences import com.google.gson.GsonBuilder import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableSharedFlow @@ -131,6 +132,12 @@ class AppDetailsViewModel : ViewModel() { @Synchronized fun install(context: Context, packageName: String, files: List) { + val autoInstall = Preferences.getBoolean(context, Preferences.PREFERENCE_AUTO_INSTALL) + + if (!autoInstall) { + return + } + try { viewModelScope.launch(Dispatchers.IO) { AppInstaller.getInstance(context).getPreferredInstaller() diff --git a/app/src/main/res/xml/preferences_installation.xml b/app/src/main/res/xml/preferences_installation.xml index ab19bcb5a..aea9b39cc 100644 --- a/app/src/main/res/xml/preferences_installation.xml +++ b/app/src/main/res/xml/preferences_installation.xml @@ -19,9 +19,9 @@