Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import android.content.pm.PackageInstaller
import android.content.pm.PackageManager
import android.os.Build
import androidx.core.content.ContextCompat
import app.revanced.library.installation.installer.Installer.Apk
import java.io.Closeable
import java.io.File

Expand Down Expand Up @@ -56,13 +55,13 @@ class LocalInstaller(
)
}

override suspend fun install(apk: Apk) {
logger.info("Installing ${apk.file.name}")
override suspend fun install(patchedApk: Apk, stockApk: Apk?) {
logger.info("Installing ${patchedApk.file.name}")

val packageInstaller = context.packageManager.packageInstaller

packageInstaller.openSession(packageInstaller.createSession(sessionParams)).use { session ->
session.writeApk(apk.file)
session.writeApk(patchedApk.file)
session.commit(intentSender)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ class AdbInstaller(
logger.fine("Connected to $deviceSerial")
}

override suspend fun install(apk: Apk): AdbInstallerResult {
override suspend fun install(patchedApk: Apk, stockApk: Apk?): AdbInstallerResult {
return runPackageManager {
val sdkVersion = shellCommandRunner(GET_SDK_VERSION).output.toInt()
if (sdkVersion < 34) install(apk.file)
else installWithOptions(apk.file, listOf(UPDATE_OWNERSHIP))
if (sdkVersion < 34) install(patchedApk.file)
else installWithOptions(patchedApk.file, listOf(UPDATE_OWNERSHIP))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ internal object Constants {
const val INSTALLED_APK_PATH = "pm path $PLACEHOLDER"
const val CREATE_INSTALLATION_PATH = "$CREATE_DIR $MOUNT_PATH"
const val GET_SDK_VERSION = "getprop ro.build.version.sdk"
const val UNINSTALL_KEEP_DATA = "pm uninstall -k --user 0 $PLACEHOLDER"
const val INSTALL_STOCK_APK = "pm install -r -d --user 0 $PLACEHOLDER"

const val MOUNT_APK =
"base_path=\"$MOUNTED_APK_PATH\" && " +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package app.revanced.library.installation.installer

import app.revanced.library.installation.installer.Installer.Apk
import java.io.File
import java.util.logging.Logger

Expand All @@ -19,11 +18,11 @@ abstract class Installer<TInstallerResult, TInstallation : Installation> interna
/**
* Installs the [Apk] file.
*
* @param apk The [Apk] file.
* @param patchedApk The [Apk] file.
*
* @return The result of the installation.
*/
abstract suspend fun install(apk: Apk): TInstallerResult
abstract suspend fun install(patchedApk: Apk, stockApk: Apk? = null): TInstallerResult
Comment thread
Ushie marked this conversation as resolved.
Outdated

/**
* Uninstalls the package.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import app.revanced.library.installation.installer.Constants.DELETE
import app.revanced.library.installation.installer.Constants.EXISTS
import app.revanced.library.installation.installer.Constants.INSTALLED_APK_PATH
import app.revanced.library.installation.installer.Constants.INSTALL_MOUNT_SCRIPT
import app.revanced.library.installation.installer.Constants.INSTALL_STOCK_APK
import app.revanced.library.installation.installer.Constants.KILL
import app.revanced.library.installation.installer.Constants.MOUNTED_APK_PATH
import app.revanced.library.installation.installer.Constants.MOUNT_APK
Expand All @@ -15,9 +16,8 @@ import app.revanced.library.installation.installer.Constants.MOUNT_SCRIPT_PATH
import app.revanced.library.installation.installer.Constants.RESTART
import app.revanced.library.installation.installer.Constants.TMP_FILE_PATH
import app.revanced.library.installation.installer.Constants.UMOUNT
import app.revanced.library.installation.installer.Constants.UNINSTALL_KEEP_DATA
import app.revanced.library.installation.installer.Constants.invoke
import app.revanced.library.installation.installer.Installer.Apk
import app.revanced.library.installation.installer.RootInstaller.NoRootPermissionException
import java.io.File

/**
Expand All @@ -43,19 +43,26 @@ abstract class RootInstaller internal constructor(
}

/**
* Installs the given [apk] by mounting.
* Installs the given [patchedApk] by mounting.
*
* @param apk The [Apk] to install.
* @param patchedApk The [Apk] to install.
*
* @throws PackageNameRequiredException If the [Apk] does not have a package name.
*/
override suspend fun install(apk: Apk): RootInstallerResult {
logger.info("Installing ${apk.packageName} by mounting")
override suspend fun install(patchedApk: Apk, stockApk: Apk?): RootInstallerResult {
logger.info("Installing ${patchedApk.packageName} by mounting")

val packageName = apk.packageName?.also { it.assertInstalled() } ?: throw PackageNameRequiredException()
val packageName = patchedApk.packageName ?: throw PackageNameRequiredException()
Comment thread
Ushie marked this conversation as resolved.
Outdated

// Ensure stock APK is installed
if (stockApk != null) {
Comment thread
Ushie marked this conversation as resolved.
Outdated
UNINSTALL_KEEP_DATA(packageName)().waitFor()
logger.info("Installing stock APK for $packageName")
INSTALL_STOCK_APK(stockApk.file.absolutePath)().waitFor()
Comment thread
Ushie marked this conversation as resolved.
Outdated
} else packageName.assertInstalled()

// Setup files.
apk.file.move(TMP_FILE_PATH)
patchedApk.file.move(TMP_FILE_PATH)
CREATE_INSTALLATION_PATH().waitFor()
MOUNT_APK(packageName)().waitFor()

Expand Down
Loading