mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Add logic to manually install app updates if the package manager crashes
Because china phones (samsung too maybe?) cant handle the idea of self updating Also set popup notification for app updated to IMPORTANCE_HIGH
This commit is contained in:
parent
3243421892
commit
0844e624a0
3 changed files with 25 additions and 4 deletions
|
@ -208,7 +208,7 @@ object Notifications {
|
|||
NotificationChannel(
|
||||
CHANNEL_UPDATED,
|
||||
context.getString(R.string.update_completed),
|
||||
NotificationManager.IMPORTANCE_DEFAULT,
|
||||
NotificationManager.IMPORTANCE_HIGH,
|
||||
).apply {
|
||||
setShowBadge(false)
|
||||
},
|
||||
|
|
|
@ -230,6 +230,7 @@ internal class AppUpdateNotifier(private val context: Context) {
|
|||
|
||||
fun onInstallError(uri: Uri) {
|
||||
with(notificationBuilder) {
|
||||
setContentTitle(context.getString(R.string.app_name))
|
||||
setContentText(context.getString(R.string.could_not_install_update))
|
||||
setSmallIcon(android.R.drawable.stat_sys_warning)
|
||||
setOnlyAlertOnce(false)
|
||||
|
|
|
@ -22,12 +22,15 @@ import eu.kanade.tachiyomi.network.newCallWithProgress
|
|||
import eu.kanade.tachiyomi.util.storage.getUriCompat
|
||||
import eu.kanade.tachiyomi.util.storage.saveTo
|
||||
import eu.kanade.tachiyomi.util.system.acquireWakeLock
|
||||
import eu.kanade.tachiyomi.util.system.launchNow
|
||||
import eu.kanade.tachiyomi.util.system.localeContext
|
||||
import eu.kanade.tachiyomi.util.system.notificationManager
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.CoroutineExceptionHandler
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import okhttp3.Call
|
||||
import okhttp3.internal.http2.ErrorCode
|
||||
|
@ -184,8 +187,7 @@ class AppUpdateService : Service() {
|
|||
data.copyTo(packageInSession)
|
||||
}
|
||||
if (notifyOnInstall) {
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
prefs.edit {
|
||||
PreferenceManager.getDefaultSharedPreferences(this).edit {
|
||||
putBoolean(NOTIFY_ON_INSTALL_KEY, true)
|
||||
}
|
||||
}
|
||||
|
@ -199,10 +201,29 @@ class AppUpdateService : Service() {
|
|||
val statusReceiver = pendingIntent.intentSender
|
||||
session.commit(statusReceiver)
|
||||
data.close()
|
||||
|
||||
val hasNotification by lazy {
|
||||
notificationManager.activeNotifications.any { it.id == Notifications.ID_UPDATER }
|
||||
}
|
||||
launchNow {
|
||||
delay(5000)
|
||||
// If the package manager crashes for whatever reason (china phone) set a timeout
|
||||
// and let the user manually install
|
||||
if (packageInstaller.getSessionInfo(sessionId) == null && !hasNotification) {
|
||||
notifier.onDownloadFinished(file.getUriCompat(this@AppUpdateService))
|
||||
PreferenceManager.getDefaultSharedPreferences(this@AppUpdateService).edit {
|
||||
remove(NOTIFY_ON_INSTALL_KEY)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error: Exception) {
|
||||
// Either install package can't be found (probably bots) or there's a security exception
|
||||
// with the download manager. Nothing we can workaround.
|
||||
toast(error.message)
|
||||
notifier.onDownloadFinished(file.getUriCompat(this))
|
||||
PreferenceManager.getDefaultSharedPreferences(this).edit {
|
||||
remove(NOTIFY_ON_INSTALL_KEY)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -222,7 +243,6 @@ class AppUpdateService : Service() {
|
|||
/**
|
||||
* Returns the status of the service.
|
||||
*
|
||||
* @param context the application context.
|
||||
* @return true if the service is running, false otherwise.
|
||||
*/
|
||||
fun isRunning(): Boolean = instance != null
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue