exception test 3
This commit is contained in:
parent
2f191bbb7e
commit
a9da78ff71
|
@ -3,7 +3,6 @@ package com.vanced.manager.core.downloader
|
||||||
import android.app.Service
|
import android.app.Service
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Build
|
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||||
|
@ -19,17 +18,11 @@ import com.vanced.manager.utils.InternetTools.getFileNameFromUrl
|
||||||
import com.vanced.manager.utils.NotificationHelper
|
import com.vanced.manager.utils.NotificationHelper
|
||||||
import com.vanced.manager.utils.NotificationHelper.cancelNotif
|
import com.vanced.manager.utils.NotificationHelper.cancelNotif
|
||||||
import com.vanced.manager.utils.NotificationHelper.createBasicNotif
|
import com.vanced.manager.utils.NotificationHelper.createBasicNotif
|
||||||
import java.lang.IllegalStateException
|
|
||||||
import java.util.concurrent.ExecutionException
|
|
||||||
|
|
||||||
class MicrogDownloadService: Service() {
|
class MicrogDownloadService: Service() {
|
||||||
|
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
try {
|
downloadMicrog()
|
||||||
downloadMicrog()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Toast.makeText(this, "Unable to download MicroG", Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
stopSelf()
|
stopSelf()
|
||||||
return START_NOT_STICKY
|
return START_NOT_STICKY
|
||||||
}
|
}
|
||||||
|
@ -37,10 +30,18 @@ class MicrogDownloadService: Service() {
|
||||||
private fun downloadMicrog() {
|
private fun downloadMicrog() {
|
||||||
val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
|
val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
|
||||||
|
|
||||||
val apkUrl = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/microg.json")
|
val apkUrl =
|
||||||
val dwnldUrl = apkUrl.get("url").asString
|
if(GetJson().isConnected(this))
|
||||||
|
try {
|
||||||
|
GetJson().AsJSONObject("https://vanced.app/api/v1/microg.json").get("url").asString
|
||||||
|
} catch (e: Exception) {
|
||||||
|
GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/microg.json").get("url").asString
|
||||||
|
}
|
||||||
|
else
|
||||||
|
""
|
||||||
|
|
||||||
val channel = 420
|
val channel = 420
|
||||||
PRDownloader.download(dwnldUrl, filesDir.path, "microg.apk")
|
PRDownloader.download(apkUrl, filesDir.path, "microg.apk")
|
||||||
.build()
|
.build()
|
||||||
.setOnStartOrResumeListener { OnStartOrResumeListener { prefs?.edit()?.putBoolean("isMicrogDownloading", true)?.apply() } }
|
.setOnStartOrResumeListener { OnStartOrResumeListener { prefs?.edit()?.putBoolean("isMicrogDownloading", true)?.apply() } }
|
||||||
.setOnProgressListener { progress ->
|
.setOnProgressListener { progress ->
|
||||||
|
@ -48,7 +49,7 @@ class MicrogDownloadService: Service() {
|
||||||
NotificationHelper.displayDownloadNotif(
|
NotificationHelper.displayDownloadNotif(
|
||||||
channel,
|
channel,
|
||||||
mProgress.toInt(),
|
mProgress.toInt(),
|
||||||
getFileNameFromUrl(dwnldUrl),
|
getFileNameFromUrl(apkUrl),
|
||||||
this
|
this
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,15 @@ class VancedDownloadService: Service() {
|
||||||
type: String = "arch"
|
type: String = "arch"
|
||||||
) {
|
) {
|
||||||
val baseUrl = PreferenceManager.getDefaultSharedPreferences(this).getString("install_url", baseUrl)
|
val baseUrl = PreferenceManager.getDefaultSharedPreferences(this).getString("install_url", baseUrl)
|
||||||
val vancedVer = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/vanced.json").get("version").asString
|
val vancedVer =
|
||||||
|
if(GetJson().isConnected(this))
|
||||||
|
try {
|
||||||
|
GetJson().AsJSONObject("https://vanced.app/api/v1/vanced.json").get("vanced").asString
|
||||||
|
} catch (e: Exception) {
|
||||||
|
GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/vanced.json").get("vanced").asString
|
||||||
|
}
|
||||||
|
else
|
||||||
|
""
|
||||||
val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
|
val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
|
||||||
val variant = PreferenceManager.getDefaultSharedPreferences(this).getString("vanced_variant", "nonroot")
|
val variant = PreferenceManager.getDefaultSharedPreferences(this).getString("vanced_variant", "nonroot")
|
||||||
val lang = prefs?.getString("lang", "en")
|
val lang = prefs?.getString("lang", "en")
|
||||||
|
|
|
@ -26,14 +26,10 @@ object InternetTools {
|
||||||
fun displayJsonString(json: String, obj: String, context: Context): String {
|
fun displayJsonString(json: String, obj: String, context: Context): String {
|
||||||
val installUrl = PreferenceManager.getDefaultSharedPreferences(context).getString("install_url", baseUrl)
|
val installUrl = PreferenceManager.getDefaultSharedPreferences(context).getString("install_url", baseUrl)
|
||||||
return if (GetJson().isConnected(context)) {
|
return if (GetJson().isConnected(context)) {
|
||||||
try {
|
return try {
|
||||||
GetJson().AsJSONObject("$installUrl/$json").get(obj).asString
|
GetJson().AsJSONObject("$installUrl/$json").get(obj).asString
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
when (e) {
|
GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/$json").get(obj).asString
|
||||||
is InterruptedException, is ExecutionException -> GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/$json").get(obj).asString
|
|
||||||
else -> throw e
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
context.getString(R.string.unavailable)
|
context.getString(R.string.unavailable)
|
||||||
|
@ -43,7 +39,7 @@ object InternetTools {
|
||||||
fun displayJsonInt(json: String, obj: String, context: Context): Int {
|
fun displayJsonInt(json: String, obj: String, context: Context): Int {
|
||||||
val installUrl = PreferenceManager.getDefaultSharedPreferences(context).getString("install_url", baseUrl)
|
val installUrl = PreferenceManager.getDefaultSharedPreferences(context).getString("install_url", baseUrl)
|
||||||
return if (GetJson().isConnected(context)) {
|
return if (GetJson().isConnected(context)) {
|
||||||
try {
|
return try {
|
||||||
GetJson().AsJSONObject("$installUrl/$json").get(obj).asInt
|
GetJson().AsJSONObject("$installUrl/$json").get(obj).asInt
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/$json").get(obj).asInt
|
GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/$json").get(obj).asInt
|
||||||
|
@ -60,6 +56,4 @@ object InternetTools {
|
||||||
|
|
||||||
const val baseUrl = "https://vanced.app/api/v1"
|
const val baseUrl = "https://vanced.app/api/v1"
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue