Revert "Add back toggle for auto install post app download"

This reverts commit 24496b1405.
This commit is contained in:
Rahul Patel
2023-10-17 05:59:52 +05:30
parent 4fe7d453f5
commit 1ce09c5c35
5 changed files with 32 additions and 89 deletions

View File

@@ -45,7 +45,7 @@ import java.util.*
import java.util.concurrent.locks.ReentrantLock import java.util.concurrent.locks.ReentrantLock
import kotlin.concurrent.timerTask import kotlin.concurrent.timerTask
class UpdateService : LifecycleService() { class UpdateService: LifecycleService() {
lateinit var fetch: Fetch lateinit var fetch: Fetch
lateinit var downloadManager: DownloadManager lateinit var downloadManager: DownloadManager
@@ -53,7 +53,7 @@ class UpdateService : LifecycleService() {
private var fetchActiveDownloadObserver = object : FetchObserver<Boolean> { private var fetchActiveDownloadObserver = object : FetchObserver<Boolean> {
override fun onChanged(data: Boolean, reason: Reason) { override fun onChanged(data: Boolean, reason: Reason) {
if (!data && isEmptyInstalling() && fetchListeners.isEmpty() && appMetadataListeners.isEmpty()) { if (!data && isEmptyInstalling() && fetchListeners.isEmpty() && appMetadataListeners.isEmpty()) {
Handler(Looper.getMainLooper()).postDelayed({ Handler(Looper.getMainLooper()).postDelayed ({
if (isEmptyInstalling() && fetchListeners.isEmpty() && appMetadataListeners.isEmpty()) { if (isEmptyInstalling() && fetchListeners.isEmpty() && appMetadataListeners.isEmpty()) {
stopSelf() stopSelf()
} }
@@ -74,7 +74,7 @@ class UpdateService : LifecycleService() {
var liveUpdateData: MutableLiveData<MutableMap<Int, UpdateFile>> = MutableLiveData() var liveUpdateData: MutableLiveData<MutableMap<Int, UpdateFile>> = MutableLiveData()
inner class UpdateServiceBinder : Binder() { inner class UpdateServiceBinder : Binder() {
fun getUpdateService(): UpdateService { fun getUpdateService() : UpdateService {
return this@UpdateService return this@UpdateService
} }
} }
@@ -181,11 +181,9 @@ class UpdateService : LifecycleService() {
private lateinit var authData: AuthData private lateinit var authData: AuthData
data class AppDownloadStatus( data class AppDownloadStatus(val download: Download, val fetchGroup: FetchGroup,
val download: Download, val fetchGroup: FetchGroup, val isCancelled: Boolean = false,
val isCancelled: Boolean = false, val isComplete: Boolean = false)
val isComplete: Boolean = false
)
data class AppMetadataStatus(val reason: String, val app: App) data class AppMetadataStatus(val reason: String, val app: App)
@@ -254,32 +252,17 @@ class UpdateService : LifecycleService() {
fetchGroup: FetchGroup fetchGroup: FetchGroup
) { ) {
fetchListeners.forEach { fetchListeners.forEach {
it.onProgress( it.onProgress(groupId, download, etaInMilliSeconds, downloadedBytesPerSecond, fetchGroup)
groupId,
download,
etaInMilliSeconds,
downloadedBytesPerSecond,
fetchGroup
)
} }
} }
override fun onProgress( override fun onProgress(download: Download, etaInMilliSeconds: Long, downloadedBytesPerSecond: Long) {
download: Download,
etaInMilliSeconds: Long,
downloadedBytesPerSecond: Long
) {
fetchListeners.forEach { fetchListeners.forEach {
it.onProgress(download, etaInMilliSeconds, downloadedBytesPerSecond) it.onProgress(download, etaInMilliSeconds, downloadedBytesPerSecond)
} }
} }
override fun onQueued( override fun onQueued(groupId: Int, download: Download, waitingNetwork: Boolean, fetchGroup: FetchGroup) {
groupId: Int,
download: Download,
waitingNetwork: Boolean,
fetchGroup: FetchGroup
) {
fetchListeners.forEach { fetchListeners.forEach {
it.onQueued(groupId, download, waitingNetwork, fetchGroup) it.onQueued(groupId, download, waitingNetwork, fetchGroup)
} }
@@ -328,30 +311,20 @@ class UpdateService : LifecycleService() {
download, download,
downloadBlocks, downloadBlocks,
totalBlocks, totalBlocks,
fetchGroup fetchGroup)
)
} }
} }
override fun onStarted( override fun onStarted(download: Download, downloadBlocks: List<DownloadBlock>, totalBlocks: Int) {
download: Download,
downloadBlocks: List<DownloadBlock>,
totalBlocks: Int
) {
fetchListeners.forEach { fetchListeners.forEach {
it.onStarted( it.onStarted(
download, download,
downloadBlocks, downloadBlocks,
totalBlocks totalBlocks)
)
} }
} }
override fun onWaitingNetwork( override fun onWaitingNetwork(groupId: Int, download: Download, fetchGroup: FetchGroup) {
groupId: Int,
download: Download,
fetchGroup: FetchGroup
) {
fetchListeners.forEach { fetchListeners.forEach {
it.onWaitingNetwork(groupId, download, fetchGroup) it.onWaitingNetwork(groupId, download, fetchGroup)
} }
@@ -368,8 +341,7 @@ class UpdateService : LifecycleService() {
it.onCompleted(groupId, download, fetchGroup) it.onCompleted(groupId, download, fetchGroup)
} }
if (fetchListeners.isEmpty()) { if (fetchListeners.isEmpty()) {
fetchPendingEvents[groupId] = fetchPendingEvents[groupId] = AppDownloadStatus(download, fetchGroup, isComplete = true)
AppDownloadStatus(download, fetchGroup, isComplete = true)
} }
var packageDownloadFilesWhichCompleted = downloadsInCompletedGroup[download.tag!!] var packageDownloadFilesWhichCompleted = downloadsInCompletedGroup[download.tag!!]
if (packageDownloadFilesWhichCompleted == null) { if (packageDownloadFilesWhichCompleted == null) {
@@ -377,11 +349,7 @@ class UpdateService : LifecycleService() {
downloadsInCompletedGroup[download.tag!!] = packageDownloadFilesWhichCompleted downloadsInCompletedGroup[download.tag!!] = packageDownloadFilesWhichCompleted
} }
packageDownloadFilesWhichCompleted.add(download.file) packageDownloadFilesWhichCompleted.add(download.file)
if (fetchGroup.groupDownloadProgress == 100 && fetchGroup.downloads.all { if (fetchGroup.groupDownloadProgress == 100 && fetchGroup.downloads.all { packageDownloadFilesWhichCompleted.contains(it.file) }) {
packageDownloadFilesWhichCompleted.contains(
it.file
)
}) {
downloadsInCompletedGroup.remove(download.tag!!) downloadsInCompletedGroup.remove(download.tag!!)
if (download.tag != null) { if (download.tag != null) {
removeFromInstalling(download.tag, runFromCurrentThread = true) removeFromInstalling(download.tag, runFromCurrentThread = true)
@@ -413,8 +381,7 @@ class UpdateService : LifecycleService() {
it.onCancelled(groupId, download, fetchGroup) it.onCancelled(groupId, download, fetchGroup)
} }
if (fetchListeners.isEmpty()) { if (fetchListeners.isEmpty()) {
fetchPendingEvents[groupId] = fetchPendingEvents[groupId] = AppDownloadStatus(download, fetchGroup, isCancelled = true)
AppDownloadStatus(download, fetchGroup, isCancelled = true)
} }
} }
@@ -429,8 +396,7 @@ class UpdateService : LifecycleService() {
it.onDeleted(groupId, download, fetchGroup) it.onDeleted(groupId, download, fetchGroup)
} }
if (fetchListeners.isEmpty()) { if (fetchListeners.isEmpty()) {
fetchPendingEvents[groupId] = fetchPendingEvents[groupId] = AppDownloadStatus(download, fetchGroup, isCancelled = true)
AppDownloadStatus(download, fetchGroup, isCancelled = true)
} }
} }
@@ -458,11 +424,7 @@ class UpdateService : LifecycleService() {
} }
} }
override fun onDownloadBlockUpdated( override fun onDownloadBlockUpdated(download: Download, downloadBlock: DownloadBlock, totalBlocks: Int) {
download: Download,
downloadBlock: DownloadBlock,
totalBlocks: Int
) {
fetchListeners.forEach { fetchListeners.forEach {
it.onDownloadBlockUpdated( it.onDownloadBlockUpdated(
download, download,
@@ -650,19 +612,11 @@ class UpdateService : LifecycleService() {
if (downloads.all { File(it.file).exists() }) { if (downloads.all { File(it.file).exists() }) {
serviceScope.launch { serviceScope.launch {
try { try {
val autoInstall = Preferences.getBoolean( AppInstaller.getInstance(this@UpdateService).getPreferredInstaller()
this@UpdateService, .install(
Preferences.PREFERENCE_AUTO_INSTALL packageName,
) files.filter { it.file.endsWith(".apk") }.map { it.file }.toList()
)
if (autoInstall) {
AppInstaller.getInstance(this@UpdateService).getPreferredInstaller()
.install(
packageName,
files.filter { it.file.endsWith(".apk") }.map { it.file }
.toList()
)
}
} catch (exception: Exception) { } catch (exception: Exception) {
removeFromInstalling(packageName) removeFromInstalling(packageName)
Log.e(exception.stackTraceToString()) Log.e(exception.stackTraceToString())
@@ -691,16 +645,16 @@ class UpdateService : LifecycleService() {
removeFromInstalling(this) removeFromInstalling(this)
} }
synchronized(timerLock) { synchronized(timerLock) {
timer = if (timer != null) { if (timer != null) {
timer!!.cancel() timer!!.cancel()
null timer = null
} else { }
Timer() if (timer == null) {
timer = Timer()
} }
timer!!.schedule(timerTask { timerTaskRun.run() }, 5 * 1000) timer!!.schedule(timerTask { timerTaskRun.run() }, 5 * 1000)
} }
} }
else -> { else -> {
} }

View File

@@ -182,7 +182,7 @@ class AppDetailsFragment : BaseFragment(R.layout.fragment_details) {
private var isInstalled: Boolean = false private var isInstalled: Boolean = false
private var isUpdatable: Boolean = false private var isUpdatable: Boolean = false
private var autoDownload: Boolean = false private var autoDownload: Boolean = false
private var autoInstall: Boolean = true private var downloadOnly: Boolean = false
private var uninstallActionEnabled = false private var uninstallActionEnabled = false
val listOfActionsWhenServiceAttaches = ArrayList<Runnable>() val listOfActionsWhenServiceAttaches = ArrayList<Runnable>()
@@ -445,9 +445,7 @@ class AppDetailsFragment : BaseFragment(R.layout.fragment_details) {
} }
private fun verifyAndInstall(files: List<Download>) { private fun verifyAndInstall(files: List<Download>) {
autoInstall = Preferences.getBoolean(requireContext(), Preferences.PREFERENCE_AUTO_INSTALL) if (downloadOnly)
if (!autoInstall)
return return
var filesExist = true var filesExist = true

View File

@@ -35,7 +35,6 @@ import com.aurora.store.databinding.FragmentOnboardingBinding
import com.aurora.store.util.PathUtil import com.aurora.store.util.PathUtil
import com.aurora.store.util.Preferences import com.aurora.store.util.Preferences
import com.aurora.store.util.Preferences.PREFERENCE_AUTO_DELETE 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
import com.aurora.store.util.Preferences.PREFERENCE_DEFAULT_SELECTED_TAB import com.aurora.store.util.Preferences.PREFERENCE_DEFAULT_SELECTED_TAB
import com.aurora.store.util.Preferences.PREFERENCE_DOWNLOAD_ACTIVE import com.aurora.store.util.Preferences.PREFERENCE_DOWNLOAD_ACTIVE
@@ -172,7 +171,6 @@ class OnboardingFragment : Fragment(R.layout.fragment_onboarding) {
/*Installer*/ /*Installer*/
save(PREFERENCE_AUTO_DELETE, true) save(PREFERENCE_AUTO_DELETE, true)
save(PREFERENCE_AUTO_INSTALL, true)
save(PREFERENCE_INSTALLER_ID, 0) save(PREFERENCE_INSTALLER_ID, 0)
/*Updates*/ /*Updates*/

View File

@@ -14,7 +14,6 @@ import com.aurora.store.data.model.ExodusReport
import com.aurora.store.data.model.Report import com.aurora.store.data.model.Report
import com.aurora.store.data.network.HttpClient import com.aurora.store.data.network.HttpClient
import com.aurora.store.data.providers.AuthProvider import com.aurora.store.data.providers.AuthProvider
import com.aurora.store.util.Preferences
import com.google.gson.GsonBuilder import com.google.gson.GsonBuilder
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableSharedFlow
@@ -132,12 +131,6 @@ class AppDetailsViewModel : ViewModel() {
@Synchronized @Synchronized
fun install(context: Context, packageName: String, files: List<Any>) { fun install(context: Context, packageName: String, files: List<Any>) {
val autoInstall = Preferences.getBoolean(context, Preferences.PREFERENCE_AUTO_INSTALL)
if (!autoInstall) {
return
}
try { try {
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
AppInstaller.getInstance(context).getPreferredInstaller() AppInstaller.getInstance(context).getPreferredInstaller()

View File

@@ -19,9 +19,9 @@
<androidx.preference.PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"> <androidx.preference.PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
<SwitchPreferenceCompat <SwitchPreferenceCompat
app:defaultValue="true" app:defaultValue="false"
app:iconSpaceReserved="false" app:iconSpaceReserved="false"
app:isPreferenceVisible="true" app:isPreferenceVisible="false"
app:key="PREFERENCE_AUTO_INSTALL" app:key="PREFERENCE_AUTO_INSTALL"
app:summary="@string/pref_install_auto_summary" app:summary="@string/pref_install_auto_summary"
app:title="@string/pref_install_auto_title" /> app:title="@string/pref_install_auto_title" />