mirror of
https://github.com/YTVanced/VancedManager
synced 2025-01-06 23:41:00 +00:00
Added loggers for root installer
This commit is contained in:
parent
7ab45bec22
commit
141a99d64c
1 changed files with 20 additions and 12 deletions
|
@ -34,6 +34,7 @@ import kotlin.collections.HashMap
|
|||
object PackageHelper {
|
||||
|
||||
const val apkInstallPath = "/data/adb"
|
||||
const val INSTALLER_TAG = "VMInstall"
|
||||
private val vancedThemes = arrayOf("black", "dark", "pink", "blue")
|
||||
|
||||
init {
|
||||
|
@ -243,7 +244,7 @@ object PackageHelper {
|
|||
try {
|
||||
for (listOfFile in listOfFiles!!) {
|
||||
if (listOfFile.isFile) {
|
||||
Log.d("AppLog", "installApk: " + listOfFile.name)
|
||||
Log.d(INSTALLER_TAG, "installApk: " + listOfFile.name)
|
||||
nameSizeMap[listOfFile.name] = listOfFile.length()
|
||||
totalSize += listOfFile.length()
|
||||
}
|
||||
|
@ -256,12 +257,12 @@ object PackageHelper {
|
|||
installParams.setSize(totalSize)
|
||||
try {
|
||||
sessionId = context.packageManager.packageInstaller.createSession(installParams)
|
||||
Log.d("AppLog","Success: created install session [$sessionId]")
|
||||
Log.d(INSTALLER_TAG,"Success: created install session [$sessionId]")
|
||||
for ((key, value) in nameSizeMap) {
|
||||
doWriteSession(sessionId, apkFolderPath + key, value, key, context)
|
||||
}
|
||||
doCommitSession(sessionId, context)
|
||||
Log.d("AppLog","Success")
|
||||
Log.d(INSTALLER_TAG,"Success")
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
@ -298,10 +299,10 @@ object PackageHelper {
|
|||
out.write(buffer, 0, c)
|
||||
}
|
||||
session.fsync(out)
|
||||
Log.d("AppLog", "Success: streamed $total bytes")
|
||||
Log.d(INSTALLER_TAG, "Success: streamed $total bytes")
|
||||
return PackageInstaller.STATUS_SUCCESS
|
||||
} catch (e: IOException) {
|
||||
Log.e("AppLog", "Error: failed to write; " + e.message)
|
||||
Log.e(INSTALLER_TAG, "Error: failed to write; " + e.message)
|
||||
return PackageInstaller.STATUS_FAILURE
|
||||
} finally {
|
||||
try {
|
||||
|
@ -323,9 +324,9 @@ object PackageHelper {
|
|||
val pendingIntent = PendingIntent.getService(context, 0, callbackIntent, 0)
|
||||
session.commit(pendingIntent.intentSender)
|
||||
session.close()
|
||||
Log.d("AppLog", "install request sent")
|
||||
Log.d("AppLog", "doCommitSession: " + context.packageManager.packageInstaller.mySessions)
|
||||
Log.d("AppLog", "doCommitSession: after session commit ")
|
||||
Log.d(INSTALLER_TAG, "install request sent")
|
||||
Log.d(INSTALLER_TAG, "doCommitSession: " + context.packageManager.packageInstaller.mySessions)
|
||||
Log.d(INSTALLER_TAG, "doCommitSession: after session commit ")
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
@ -338,7 +339,7 @@ object PackageHelper {
|
|||
private fun installSplitApkFiles(apkFiles: ArrayList<FileInfo>, context: Context) : Boolean {
|
||||
var sessionId: Int?
|
||||
val filenames = arrayOf("black.apk", "dark.apk", "blue.apk", "pink.apk", "hash.json")
|
||||
Log.d("AppLog", "installing split apk files: $apkFiles")
|
||||
Log.d(INSTALLER_TAG, "installing split apk files: $apkFiles")
|
||||
run {
|
||||
val sessionIdResult = Shell.su("pm install-create -r -t").exec().out
|
||||
val sessionIdPattern = Pattern.compile("(\\d+)")
|
||||
|
@ -348,7 +349,7 @@ object PackageHelper {
|
|||
}
|
||||
apkFiles.forEach { apkFile ->
|
||||
if (!filenames.any { apkFile.name == it }) {
|
||||
Log.d("AppLog", "installing APK: ${apkFile.name} ${apkFile.fileSize}")
|
||||
Log.d(INSTALLER_TAG, "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,7 +366,7 @@ object PackageHelper {
|
|||
process.waitFor()
|
||||
}
|
||||
}
|
||||
Log.d("AppLog", "committing...")
|
||||
Log.d(INSTALLER_TAG, "committing...")
|
||||
val installResult = Shell.su("pm install-commit $sessionId").exec()
|
||||
if (installResult.isSuccess) {
|
||||
return true
|
||||
|
@ -453,6 +454,7 @@ object PackageHelper {
|
|||
private fun setupScript(apkFPath: String, path: String, app: String, pkg: String, context: Context): Boolean
|
||||
{
|
||||
try {
|
||||
Log.d(INSTALLER_TAG, "Setting up script")
|
||||
context.writeServiceDScript(apkFPath, path, app)
|
||||
Shell.su("""echo "#!/system/bin/sh\nwhile read line; do echo \${"$"}{line} | grep $pkg | awk '{print \${'$'}2}' | xargs umount -l; done< /proc/mounts" > /data/adb/post-fs-data.d/$app.sh""").exec()
|
||||
return Shell.su("chmod 744 /data/adb/service.d/$app.sh").exec().isSuccess
|
||||
|
@ -463,6 +465,7 @@ object PackageHelper {
|
|||
}
|
||||
|
||||
private fun linkApp(apkFPath: String, pkg:String, path: String): Boolean {
|
||||
Log.d(INSTALLER_TAG, "Linking app")
|
||||
Shell.su("am force-stop $pkg").exec()
|
||||
Shell.su("""for i in ${'$'}(ls /data/app/ | grep $pkg | tr " "); do umount -l "/data/app/${"$"}i/base.apk"; done """).exec()
|
||||
val response = Shell.su("""su -mm -c "mount -o bind $apkFPath $path"""").exec()
|
||||
|
@ -477,6 +480,7 @@ object PackageHelper {
|
|||
|
||||
//check version and perform action based on result
|
||||
private fun checkVersion(versionCode: Int, baseApkFiles: ArrayList<FileInfo>, pkg: String, context: Context): Boolean {
|
||||
Log.d(INSTALLER_TAG, "Checking stock version")
|
||||
val path = getPackageDir(context, pkg)
|
||||
if (path != null) {
|
||||
if (path.contains("/data/app/")) {
|
||||
|
@ -495,7 +499,7 @@ object PackageHelper {
|
|||
return try {
|
||||
context.packageManager.getPackageInfo(pkg, 0)
|
||||
} catch (e:Exception) {
|
||||
Log.d("VMpm", "Unable to get package info")
|
||||
Log.d(INSTALLER_TAG, "Unable to get package info")
|
||||
null
|
||||
}
|
||||
}
|
||||
|
@ -510,6 +514,7 @@ object PackageHelper {
|
|||
|
||||
//uninstall current update and install base that works with patch
|
||||
private fun fixHigherVer(apkFiles: ArrayList<FileInfo>, pkg: String, context: Context) : Boolean {
|
||||
Log.d(INSTALLER_TAG, "Downgrading stock")
|
||||
if (uninstallRootApk(pkg)) {
|
||||
return if (pkg == vancedRootPkg) installSplitApkFiles(apkFiles, context) else installRootMusic(apkFiles, context)
|
||||
}
|
||||
|
@ -520,11 +525,13 @@ object PackageHelper {
|
|||
|
||||
//install stock youtube matching vanced version
|
||||
private fun installStock(baseApkFiles: ArrayList<FileInfo>, pkg: String, context: Context): Boolean {
|
||||
Log.d(INSTALLER_TAG, "Installing stock")
|
||||
return if (pkg == vancedRootPkg) installSplitApkFiles(baseApkFiles, context) else installRootMusic(baseApkFiles, context)
|
||||
}
|
||||
|
||||
//set chcon to apk_data_file
|
||||
private fun chConV(apkFPath: String, context: Context): Boolean {
|
||||
Log.d(INSTALLER_TAG, "Running chcon")
|
||||
val response = Shell.su("chcon u:object_r:apk_data_file:s0 $apkFPath").exec()
|
||||
//val response = Shell.su("chcon -R u:object_r:system_file:s0 $path").exec()
|
||||
return if (response.isSuccess) {
|
||||
|
@ -538,6 +545,7 @@ object PackageHelper {
|
|||
|
||||
//move patch to data/app
|
||||
private fun moveAPK(apkFile: String, path: String, pkg: String, context: Context) : Boolean {
|
||||
Log.d(INSTALLER_TAG, "Moving app")
|
||||
val apkinF = SuFile.open(apkFile)
|
||||
val apkoutF = SuFile.open(path)
|
||||
|
||||
|
|
Loading…
Reference in a new issue