mirror of
https://github.com/YTVanced/VancedManager
synced 2024-11-25 04:35:12 +00:00
crash fixes
This commit is contained in:
parent
835ede4de6
commit
66f2d70de5
4 changed files with 30 additions and 20 deletions
|
@ -23,7 +23,7 @@ open class ProgressModel {
|
|||
}
|
||||
|
||||
init {
|
||||
installing.value = false
|
||||
installing.postValue(false)
|
||||
reset()
|
||||
}
|
||||
|
||||
|
|
|
@ -117,7 +117,7 @@ object DownloadHelper : CoroutineScope by CoroutineScope(Dispatchers.IO) {
|
|||
|
||||
fun downloadManager(context: Context) {
|
||||
val url = "https://github.com/YTVanced/VancedManager/releases/latest/download/manager.apk"
|
||||
download(url,"https://github.com/YTVanced/VancedManager", "manager", "manager.apk", context, onDownloadComplete = {
|
||||
download(url,"https://github.com/YTVanced/VancedManager/", "manager", "manager.apk", context, onDownloadComplete = {
|
||||
val apk = File("${context.getExternalFilesDir("manager")?.path}/manager.apk")
|
||||
val uri =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
|
|
|
@ -161,23 +161,28 @@ object PackageHelper {
|
|||
}
|
||||
|
||||
fun install(path: String, context: Context) {
|
||||
val callbackIntent = Intent(context, AppInstallerService::class.java)
|
||||
val pendingIntent = PendingIntent.getService(context, 0, callbackIntent, 0)
|
||||
val packageInstaller = context.packageManager.packageInstaller
|
||||
val params = PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL)
|
||||
val sessionId = packageInstaller.createSession(params)
|
||||
val session = packageInstaller.openSession(sessionId)
|
||||
val inputStream: InputStream = FileInputStream(path)
|
||||
val outputStream = session.openWrite("install", 0, -1)
|
||||
val buffer = ByteArray(65536)
|
||||
var c: Int
|
||||
while (inputStream.read(buffer).also { c = it } != -1) {
|
||||
outputStream.write(buffer, 0, c)
|
||||
try {
|
||||
val callbackIntent = Intent(context, AppInstallerService::class.java)
|
||||
val pendingIntent = PendingIntent.getService(context, 0, callbackIntent, 0)
|
||||
val packageInstaller = context.packageManager.packageInstaller
|
||||
val params = PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL)
|
||||
val sessionId = packageInstaller.createSession(params)
|
||||
val session = packageInstaller.openSession(sessionId)
|
||||
val inputStream: InputStream = FileInputStream(path)
|
||||
val outputStream = session.openWrite("install", 0, -1)
|
||||
val buffer = ByteArray(65536)
|
||||
var c: Int
|
||||
while (inputStream.read(buffer).also { c = it } != -1) {
|
||||
outputStream.write(buffer, 0, c)
|
||||
}
|
||||
session.fsync(outputStream)
|
||||
inputStream.close()
|
||||
outputStream.close()
|
||||
session.commit(pendingIntent.intentSender)
|
||||
} catch (e: IOException) {
|
||||
Log.d(INSTALLER_TAG, e.stackTraceToString())
|
||||
}
|
||||
session.fsync(outputStream)
|
||||
inputStream.close()
|
||||
outputStream.close()
|
||||
session.commit(pendingIntent.intentSender)
|
||||
|
||||
}
|
||||
|
||||
private fun installRootMusic(files: ArrayList<FileInfo>, context: Context): Boolean {
|
||||
|
@ -338,7 +343,6 @@ object PackageHelper {
|
|||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
} finally {
|
||||
session?.close()
|
||||
}
|
||||
|
|
|
@ -1,10 +1,16 @@
|
|||
package com.vanced.manager.core.ui.ext
|
||||
|
||||
import android.util.Log
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.fragment.app.Fragment
|
||||
|
||||
fun Fragment.requireSupportFM() = requireActivity().supportFragmentManager
|
||||
|
||||
fun <D : DialogFragment> Fragment.showDialog(dialog: D) {
|
||||
dialog.show(requireSupportFM(), dialog::class.simpleName)
|
||||
try {
|
||||
dialog.show(requireSupportFM(), dialog::class.simpleName)
|
||||
} catch (e: IllegalStateException) {
|
||||
Log.d("VMUI", "Can not perform this action after onSaveInstanceState")
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue