0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-11-23 03:35:11 +00:00

fixed music installer

This commit is contained in:
Xinto 2020-11-12 23:00:10 +04:00
parent 31885da059
commit a6048b4df0
5 changed files with 40 additions and 15 deletions

View file

@ -52,7 +52,7 @@ object MusicDownloader {
else
"$baseurl/$variant.apk"
downloadProgress.get()?.currentDownload = PRDownloader.download(url, downloadPath, "music.apk")
downloadProgress.get()?.currentDownload = PRDownloader.download(url, downloadPath, getFileNameFromUrl(url))
.build()
.setOnStartOrResumeListener {
downloadProgress.get()?.downloadingFile?.set(context.getString(R.string.downloading_file, getFileNameFromUrl(url)))

View file

@ -69,7 +69,7 @@ object DialogContainer {
prefs.edit { putBoolean("statement", true) }
}
fun installAlertBuilder(msg: String, context: Context) {
fun installAlertBuilder(msg: String, fullMsg: String?, context: Context) {
MaterialAlertDialogBuilder(context).apply {
setTitle(context.getString(R.string.error))
setMessage(msg)
@ -79,25 +79,33 @@ object DialogContainer {
openUrl("https://lmgtfy.com/?q=andnixsh+apk+verification+disable", R.color.Twitter, context)
}
setNeutralButton(context.getString(R.string.close)) { dialog, _ -> dialog.dismiss() }
if (fullMsg != null)
setNegativeButton("Advanced") { _, _ -> basicDialog("Advanced", fullMsg, context) }
}
context.getString(R.string.installation_miui) -> {
setPositiveButton(context.getString(R.string.guide)) { _, _ ->
openUrl("https://telegra.ph/How-to-install-v15-on-MIUI-02-11", R.color.Telegram, context)
}
setNeutralButton(context.getString(R.string.close)) { dialog, _ -> dialog.dismiss() }
if (fullMsg != null)
setNegativeButton("Advanced") { _, _ -> basicDialog("Advanced", fullMsg, context) }
}
else -> {
setPositiveButton(context.getString(R.string.close)) { dialog, _ -> dialog.dismiss() }
if (fullMsg != null)
setNegativeButton("Advanced") { _, _ -> basicDialog("Advanced", fullMsg, context) }
}
else -> setPositiveButton(context.getString(R.string.close)) { dialog, _ -> dialog.dismiss() }
}
create()
show()
}
}
fun basicDialog(title: String, msg: String, activity: Activity) {
MaterialAlertDialogBuilder(activity).apply {
fun basicDialog(title: String, msg: String, context: Context) {
MaterialAlertDialogBuilder(context).apply {
setTitle(title)
setMessage(msg)
setPositiveButton(activity.getString(R.string.close)) { dialog, _ -> dialog.dismiss() }
setPositiveButton(context.getString(R.string.close)) { dialog, _ -> dialog.dismiss() }
create()
show()
}

View file

@ -110,7 +110,7 @@ open class HomeFragment : Fragment() {
private val broadcastReceiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
when (intent.action) {
INSTALL_FAILED -> installAlertBuilder(intent.getStringExtra("errorMsg") as String, requireActivity())
INSTALL_FAILED -> installAlertBuilder(intent.getStringExtra("errorMsg").toString(), intent.getStringExtra("fullErrorMsg"), requireActivity())
REFRESH_HOME -> viewModel.fetchData()
}
}

View file

@ -52,9 +52,12 @@ object AppUtils {
}
fun sendFailure(error: MutableList<String>, context: Context) {
downloadProgress.get()?.installing?.set(false)
CoroutineScope(Dispatchers.IO).launch {
delay(700)
val intent = Intent(HomeFragment.INSTALL_FAILED)
intent.putExtra("errorMsg", getErrorMessage(error.joinToString(), context))
intent.putExtra("fullErrorMsg", error.joinToString(" "))
LocalBroadcastManager.getInstance(context).sendBroadcast(intent)
}
}

View file

@ -149,8 +149,19 @@ object PackageHelper {
session.commit(pendingIntent.intentSender)
}
private fun installRootApk(apkPath: String): Boolean {
return Shell.su("pm install -r $apkPath").exec().isSuccess
private fun installRootMusic(files: ArrayList<FileInfo>, context: Context): Boolean {
files.forEach { apk ->
if (apk.name != "root.apk") {
val command = Shell.su("cat ${apk.file?.path} | pm install -S ${apk.fileSize}").exec()
if (command.isSuccess)
return true
else {
sendFailure(command.out, context)
sendCloseDialog(context)
}
}
}
return false
}
fun installMusicRoot(context: Context) {
@ -167,7 +178,7 @@ object PackageHelper {
val apkFilesPath = context.getExternalFilesDir("music/root")?.path
val fileInfoList = apkFilesPath?.let { it1 -> getFileInfoList(it1) }
if (fileInfoList != null) {
val modApk: FileInfo? = fileInfoList.lastOrNull { it.name == "music.apk" }
val modApk: FileInfo? = fileInfoList.lastOrNull { it.name == "root.apk" }
if (modApk != null) {
if (overwriteBase(modApk, fileInfoList, musicVersionCode!!, musicRootPkg, "music", context)) {
sendRefresh(context)
@ -332,7 +343,8 @@ object PackageHelper {
private fun installSplitApkFiles(apkFiles: ArrayList<FileInfo>, context: Context) : Boolean {
var sessionId: Int?
Log.d("AppLog", "installing split apk files:$apkFiles")
val filenames = arrayOf("black.apk", "dark.apk", "blue.apk", "pink.apk", "hash.json")
Log.d("AppLog", "installing split apk files: $apkFiles")
run {
val sessionIdResult = Shell.su("pm install-create -r -t").exec().out
val sessionIdPattern = Pattern.compile("(\\d+)")
@ -341,8 +353,8 @@ object PackageHelper {
sessionId = Integer.parseInt(sessionIdMatcher.group(1)!!)
}
apkFiles.forEach { apkFile ->
if (apkFile.name != "black.apk" && apkFile.name != "dark.apk" && apkFile.name != "hash.json") {
Log.d("AppLog", "installing APK : ${apkFile.name} ${apkFile.fileSize} ")
if (!filenames.any { apkFile.name == it }) {
Log.d("AppLog", "installing APK: ${apkFile.name} ${apkFile.fileSize}")
val command = arrayOf("su", "-c", "pm", "install-write", "-S", "${apkFile.fileSize}", "$sessionId", apkFile.name)
val process: Process = Runtime.getRuntime().exec(command)
val inputPipe = apkFile.getInputStream()
@ -365,6 +377,7 @@ object PackageHelper {
return true
}
sendFailure(installResult.out, context)
sendCloseDialog(context)
return false
}
@ -505,7 +518,7 @@ object PackageHelper {
//uninstall current update and install base that works with patch
private fun fixHigherVer(apkFiles: ArrayList<FileInfo>, pkg: String, context: Context) : Boolean {
if (uninstallRootApk(pkg)) {
return if (pkg == vancedRootPkg) installSplitApkFiles(apkFiles, context) else installRootApk(apkFiles[0].file?.path!!)
return if (pkg == vancedRootPkg) installSplitApkFiles(apkFiles, context) else installRootMusic(apkFiles, context)
}
sendFailure(listOf("Failed_Uninstall").toMutableList(), context)
sendCloseDialog(context)
@ -514,7 +527,7 @@ object PackageHelper {
//install stock youtube matching vanced version
private fun installStock(baseApkFiles: ArrayList<FileInfo>, pkg: String, context: Context): Boolean {
return if (pkg == vancedRootPkg) installSplitApkFiles(baseApkFiles, context) else installRootApk(baseApkFiles[0].file?.path!!)
return if (pkg == vancedRootPkg) installSplitApkFiles(baseApkFiles, context) else installRootMusic(baseApkFiles, context)
}
//set chcon to apk_data_file
@ -525,6 +538,7 @@ object PackageHelper {
true
} else {
sendFailure(response.out, context)
sendCloseDialog(context)
false
}
}