Add back toggle for auto install post app download
This commit is contained in:
@@ -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,9 +181,11 @@ class UpdateService: LifecycleService() {
|
|||||||
private lateinit var authData: AuthData
|
private lateinit var authData: AuthData
|
||||||
|
|
||||||
|
|
||||||
data class AppDownloadStatus(val download: Download, val fetchGroup: FetchGroup,
|
data class AppDownloadStatus(
|
||||||
val isCancelled: Boolean = false,
|
val download: Download, val fetchGroup: FetchGroup,
|
||||||
val isComplete: Boolean = false)
|
val isCancelled: Boolean = false,
|
||||||
|
val isComplete: Boolean = false
|
||||||
|
)
|
||||||
|
|
||||||
data class AppMetadataStatus(val reason: String, val app: App)
|
data class AppMetadataStatus(val reason: String, val app: App)
|
||||||
|
|
||||||
@@ -252,17 +254,32 @@ class UpdateService: LifecycleService() {
|
|||||||
fetchGroup: FetchGroup
|
fetchGroup: FetchGroup
|
||||||
) {
|
) {
|
||||||
fetchListeners.forEach {
|
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 {
|
fetchListeners.forEach {
|
||||||
it.onProgress(download, etaInMilliSeconds, downloadedBytesPerSecond)
|
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 {
|
fetchListeners.forEach {
|
||||||
it.onQueued(groupId, download, waitingNetwork, fetchGroup)
|
it.onQueued(groupId, download, waitingNetwork, fetchGroup)
|
||||||
}
|
}
|
||||||
@@ -311,20 +328,30 @@ class UpdateService: LifecycleService() {
|
|||||||
download,
|
download,
|
||||||
downloadBlocks,
|
downloadBlocks,
|
||||||
totalBlocks,
|
totalBlocks,
|
||||||
fetchGroup)
|
fetchGroup
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStarted(download: Download, downloadBlocks: List<DownloadBlock>, totalBlocks: Int) {
|
override fun onStarted(
|
||||||
|
download: Download,
|
||||||
|
downloadBlocks: List<DownloadBlock>,
|
||||||
|
totalBlocks: Int
|
||||||
|
) {
|
||||||
fetchListeners.forEach {
|
fetchListeners.forEach {
|
||||||
it.onStarted(
|
it.onStarted(
|
||||||
download,
|
download,
|
||||||
downloadBlocks,
|
downloadBlocks,
|
||||||
totalBlocks)
|
totalBlocks
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onWaitingNetwork(groupId: Int, download: Download, fetchGroup: FetchGroup) {
|
override fun onWaitingNetwork(
|
||||||
|
groupId: Int,
|
||||||
|
download: Download,
|
||||||
|
fetchGroup: FetchGroup
|
||||||
|
) {
|
||||||
fetchListeners.forEach {
|
fetchListeners.forEach {
|
||||||
it.onWaitingNetwork(groupId, download, fetchGroup)
|
it.onWaitingNetwork(groupId, download, fetchGroup)
|
||||||
}
|
}
|
||||||
@@ -341,7 +368,8 @@ class UpdateService: LifecycleService() {
|
|||||||
it.onCompleted(groupId, download, fetchGroup)
|
it.onCompleted(groupId, download, fetchGroup)
|
||||||
}
|
}
|
||||||
if (fetchListeners.isEmpty()) {
|
if (fetchListeners.isEmpty()) {
|
||||||
fetchPendingEvents[groupId] = AppDownloadStatus(download, fetchGroup, isComplete = true)
|
fetchPendingEvents[groupId] =
|
||||||
|
AppDownloadStatus(download, fetchGroup, isComplete = true)
|
||||||
}
|
}
|
||||||
var packageDownloadFilesWhichCompleted = downloadsInCompletedGroup[download.tag!!]
|
var packageDownloadFilesWhichCompleted = downloadsInCompletedGroup[download.tag!!]
|
||||||
if (packageDownloadFilesWhichCompleted == null) {
|
if (packageDownloadFilesWhichCompleted == null) {
|
||||||
@@ -349,7 +377,11 @@ 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 { packageDownloadFilesWhichCompleted.contains(it.file) }) {
|
if (fetchGroup.groupDownloadProgress == 100 && fetchGroup.downloads.all {
|
||||||
|
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)
|
||||||
@@ -381,7 +413,8 @@ class UpdateService: LifecycleService() {
|
|||||||
it.onCancelled(groupId, download, fetchGroup)
|
it.onCancelled(groupId, download, fetchGroup)
|
||||||
}
|
}
|
||||||
if (fetchListeners.isEmpty()) {
|
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)
|
it.onDeleted(groupId, download, fetchGroup)
|
||||||
}
|
}
|
||||||
if (fetchListeners.isEmpty()) {
|
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 {
|
fetchListeners.forEach {
|
||||||
it.onDownloadBlockUpdated(
|
it.onDownloadBlockUpdated(
|
||||||
download,
|
download,
|
||||||
@@ -612,11 +650,19 @@ class UpdateService: LifecycleService() {
|
|||||||
if (downloads.all { File(it.file).exists() }) {
|
if (downloads.all { File(it.file).exists() }) {
|
||||||
serviceScope.launch {
|
serviceScope.launch {
|
||||||
try {
|
try {
|
||||||
AppInstaller.getInstance(this@UpdateService).getPreferredInstaller()
|
val autoInstall = Preferences.getBoolean(
|
||||||
.install(
|
this@UpdateService,
|
||||||
packageName,
|
Preferences.PREFERENCE_AUTO_INSTALL
|
||||||
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())
|
||||||
@@ -645,16 +691,16 @@ class UpdateService: LifecycleService() {
|
|||||||
removeFromInstalling(this)
|
removeFromInstalling(this)
|
||||||
}
|
}
|
||||||
synchronized(timerLock) {
|
synchronized(timerLock) {
|
||||||
if (timer != null) {
|
timer = if (timer != null) {
|
||||||
timer!!.cancel()
|
timer!!.cancel()
|
||||||
timer = null
|
null
|
||||||
}
|
} else {
|
||||||
if (timer == null) {
|
Timer()
|
||||||
timer = Timer()
|
|
||||||
}
|
}
|
||||||
timer!!.schedule(timerTask { timerTaskRun.run() }, 5 * 1000)
|
timer!!.schedule(timerTask { timerTaskRun.run() }, 5 * 1000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,7 +179,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 downloadOnly: Boolean = false
|
private var autoInstall: Boolean = true
|
||||||
private var uninstallActionEnabled = false
|
private var uninstallActionEnabled = false
|
||||||
|
|
||||||
val listOfActionsWhenServiceAttaches = ArrayList<Runnable>()
|
val listOfActionsWhenServiceAttaches = ArrayList<Runnable>()
|
||||||
@@ -441,7 +441,9 @@ class AppDetailsFragment : BaseFragment(R.layout.fragment_details) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun verifyAndInstall(files: List<Download>) {
|
private fun verifyAndInstall(files: List<Download>) {
|
||||||
if (downloadOnly)
|
autoInstall = Preferences.getBoolean(requireContext(), Preferences.PREFERENCE_AUTO_INSTALL)
|
||||||
|
|
||||||
|
if (!autoInstall)
|
||||||
return
|
return
|
||||||
|
|
||||||
var filesExist = true
|
var filesExist = true
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import com.aurora.store.data.work.UpdateWorker
|
|||||||
import com.aurora.store.databinding.FragmentOnboardingBinding
|
import com.aurora.store.databinding.FragmentOnboardingBinding
|
||||||
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
|
||||||
@@ -167,6 +168,7 @@ 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*/
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ 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
|
||||||
@@ -131,6 +132,12 @@ 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()
|
||||||
|
|||||||
@@ -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="false"
|
app:defaultValue="true"
|
||||||
app:iconSpaceReserved="false"
|
app:iconSpaceReserved="false"
|
||||||
app:isPreferenceVisible="false"
|
app:isPreferenceVisible="true"
|
||||||
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" />
|
||||||
|
|||||||
Reference in New Issue
Block a user