mirror of
https://github.com/YTVanced/VancedManager
synced 2024-11-14 23:05:06 +00:00
service tests
This commit is contained in:
parent
464596e22e
commit
bc2bcb7253
4 changed files with 42 additions and 16 deletions
|
@ -4,12 +4,15 @@ import android.content.BroadcastReceiver
|
|||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import com.downloader.PRDownloader
|
||||
|
||||
class DownloadBroadcastReceiver: BroadcastReceiver() {
|
||||
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
PRDownloader.cancelAll()
|
||||
Log.d("VMNotification", "Canceled downloads")
|
||||
val type = intent?.getStringExtra("type")
|
||||
when (type) {
|
||||
"vanced" -> context?.stopService(Intent(context, VancedDownloadService::class.java))
|
||||
"microg" -> context?.stopService(Intent(context, MicrogDownloadService::class.java))
|
||||
}
|
||||
Log.d("VMNotification", "Canceled $type download")
|
||||
}
|
||||
}
|
|
@ -3,10 +3,14 @@ package com.vanced.manager.core.downloader
|
|||
import android.app.Service
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.IBinder
|
||||
import android.widget.Toast
|
||||
import com.dezlum.codelabs.getjson.GetJson
|
||||
import com.downloader.*
|
||||
import com.downloader.Error
|
||||
import com.downloader.OnDownloadListener
|
||||
import com.downloader.OnStartOrResumeListener
|
||||
import com.downloader.PRDownloader
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.core.installer.AppInstaller
|
||||
import com.vanced.manager.utils.InternetTools.getFileNameFromUrl
|
||||
|
@ -44,13 +48,11 @@ class MicrogDownloadService: Service() {
|
|||
NotificationHelper.displayDownloadNotif(
|
||||
channel,
|
||||
mProgress.toInt(),
|
||||
"microg",
|
||||
getFileNameFromUrl(dwnldUrl),
|
||||
this
|
||||
)
|
||||
}
|
||||
.setOnCancelListener { OnCancelListener {
|
||||
cancelNotif(channel, this)
|
||||
} }
|
||||
.start(object : OnDownloadListener {
|
||||
override fun onDownloadComplete() {
|
||||
prefs?.edit()?.putBoolean("isMicrogDownloading", false)?.apply()
|
||||
|
@ -58,7 +60,10 @@ class MicrogDownloadService: Service() {
|
|||
val intent = Intent(this@MicrogDownloadService, AppInstaller::class.java)
|
||||
intent.putExtra("path", "${filesDir.path}/microg.apk")
|
||||
intent.putExtra("pkg", "com.mgoogle.android.gms")
|
||||
startService(intent)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
startForegroundService(intent)
|
||||
else
|
||||
startService(intent)
|
||||
}
|
||||
override fun onError(error: Error) {
|
||||
prefs?.edit()?.putBoolean("isMicrogDownloading", false)?.apply()
|
||||
|
@ -67,6 +72,11 @@ class MicrogDownloadService: Service() {
|
|||
})
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
cancelNotif(420, this)
|
||||
}
|
||||
|
||||
override fun onBind(intent: Intent?): IBinder? {
|
||||
return null
|
||||
}
|
||||
|
|
|
@ -9,7 +9,10 @@ import android.widget.Toast
|
|||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.dezlum.codelabs.getjson.GetJson
|
||||
import com.downloader.*
|
||||
import com.downloader.Error
|
||||
import com.downloader.OnDownloadListener
|
||||
import com.downloader.OnStartOrResumeListener
|
||||
import com.downloader.PRDownloader
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.core.installer.RootSplitInstallerService
|
||||
import com.vanced.manager.core.installer.SplitInstaller
|
||||
|
@ -68,11 +71,8 @@ class VancedDownloadService: Service() {
|
|||
.setOnStartOrResumeListener { OnStartOrResumeListener { prefs?.edit()?.putBoolean("isVancedDownloading", true)?.apply() } }
|
||||
.setOnProgressListener { progress ->
|
||||
val mProgress = progress.currentBytes * 100 / progress.totalBytes
|
||||
displayDownloadNotif(channel, mProgress.toInt(), getFileNameFromUrl(url), this)
|
||||
displayDownloadNotif(channel, mProgress.toInt(), "vanced", getFileNameFromUrl(url), this)
|
||||
}
|
||||
.setOnCancelListener { OnCancelListener {
|
||||
cancelNotif(channel, this)
|
||||
} }
|
||||
.start(object : OnDownloadListener {
|
||||
override fun onDownloadComplete() {
|
||||
when (type) {
|
||||
|
@ -104,9 +104,21 @@ class VancedDownloadService: Service() {
|
|||
intent.action = HomeFragment.VANCED_DOWNLOADED
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(intent)
|
||||
if (variant == "root")
|
||||
startService(Intent(this, RootSplitInstallerService::class.java))
|
||||
startInstallService(Intent(this, RootSplitInstallerService::class.java))
|
||||
else
|
||||
startService(Intent(this, SplitInstaller::class.java))
|
||||
startInstallService(Intent(this, SplitInstaller::class.java))
|
||||
}
|
||||
|
||||
private fun startInstallService(intent: Intent) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
startForegroundService(intent)
|
||||
else
|
||||
startService(intent)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
cancelNotif(69, this)
|
||||
}
|
||||
|
||||
override fun onBind(intent: Intent?): IBinder? {
|
||||
|
|
|
@ -24,7 +24,7 @@ object NotificationHelper {
|
|||
}
|
||||
}
|
||||
|
||||
fun displayDownloadNotif(channel: Int, progress:Int, filename: String, context: Context) {
|
||||
fun displayDownloadNotif(channel: Int, progress:Int, type: String, filename: String, context: Context) {
|
||||
val notifBuilder =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
Notification.Builder(context, channel.toString()).setChannelId("69420")
|
||||
|
@ -32,6 +32,7 @@ object NotificationHelper {
|
|||
Notification.Builder(context).setPriority(Notification.PRIORITY_HIGH)
|
||||
|
||||
val cancelDownload = Intent(context, DownloadBroadcastReceiver::class.java)
|
||||
cancelDownload.putExtra("type", type)
|
||||
|
||||
val cancelPendingIntent = PendingIntent.getBroadcast(context, 0, cancelDownload, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
|
||||
|
|
Loading…
Reference in a new issue