mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 19:32:16 +00:00
Optimize Installer
This commit is contained in:
parent
b3a98ee093
commit
96d8c58a0a
@ -13,6 +13,18 @@ import java.io.File
|
||||
class DefaultInstaller(context: Context) : BaseInstaller(context) {
|
||||
|
||||
private val sessionInstaller = context.packageManager.packageInstaller
|
||||
private val intent = Intent(context, InstallerService::class.java)
|
||||
|
||||
companion object {
|
||||
val flags = if (Android.sdk(31)) PendingIntent.FLAG_MUTABLE else 0
|
||||
val sessionParams = SessionParams(SessionParams.MODE_FULL_INSTALL)
|
||||
}
|
||||
|
||||
init {
|
||||
if (Android.sdk(31)) {
|
||||
sessionParams.setRequireUserAction(SessionParams.USER_ACTION_NOT_REQUIRED)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun install(cacheFileName: String) {
|
||||
val cacheFile = Cache.getReleaseFile(context, cacheFileName)
|
||||
@ -30,11 +42,6 @@ class DefaultInstaller(context: Context) : BaseInstaller(context) {
|
||||
override suspend fun uninstall(packageName: String) = mDefaultUninstaller(packageName)
|
||||
|
||||
private fun mDefaultInstaller(cacheFile: File) {
|
||||
val sessionParams = SessionParams(SessionParams.MODE_FULL_INSTALL)
|
||||
|
||||
if (Android.sdk(31)) {
|
||||
sessionParams.setRequireUserAction(SessionParams.USER_ACTION_NOT_REQUIRED)
|
||||
}
|
||||
|
||||
val id = sessionInstaller.createSession(sessionParams)
|
||||
|
||||
@ -47,10 +54,6 @@ class DefaultInstaller(context: Context) : BaseInstaller(context) {
|
||||
}
|
||||
}
|
||||
|
||||
val intent = Intent(context, InstallerService::class.java)
|
||||
|
||||
val flags = if (Android.sdk(31)) PendingIntent.FLAG_MUTABLE else 0
|
||||
|
||||
val pendingIntent = PendingIntent.getService(context, id, intent, flags)
|
||||
|
||||
session.commit(pendingIntent.intentSender)
|
||||
@ -59,11 +62,8 @@ class DefaultInstaller(context: Context) : BaseInstaller(context) {
|
||||
}
|
||||
|
||||
private suspend fun mDefaultUninstaller(packageName: String) {
|
||||
val intent = Intent(context, InstallerService::class.java)
|
||||
intent.putExtra(InstallerService.KEY_ACTION, InstallerService.ACTION_UNINSTALL)
|
||||
|
||||
val flags = if (Android.sdk(31)) PendingIntent.FLAG_MUTABLE else 0
|
||||
|
||||
val pendingIntent = PendingIntent.getService(context, -1, intent, flags)
|
||||
|
||||
withContext(Dispatchers.Default) {
|
||||
|
@ -8,45 +8,8 @@ import kotlinx.coroutines.withContext
|
||||
import java.io.File
|
||||
|
||||
class RootInstaller(context: Context) : BaseInstaller(context) {
|
||||
override suspend fun install(cacheFileName: String) {
|
||||
val cacheFile = Cache.getReleaseFile(context, cacheFileName)
|
||||
mRootInstaller(cacheFile)
|
||||
}
|
||||
|
||||
override suspend fun install(packageName: String, cacheFileName: String) {
|
||||
val cacheFile = Cache.getReleaseFile(context, cacheFileName)
|
||||
mRootInstaller(cacheFile)
|
||||
}
|
||||
|
||||
override suspend fun install(packageName: String, cacheFile: File) = mRootInstaller(cacheFile)
|
||||
|
||||
override suspend fun uninstall(packageName: String) = mRootUninstaller(packageName)
|
||||
|
||||
private suspend fun mRootInstaller(cacheFile: File) {
|
||||
val installCommand =
|
||||
String.format(
|
||||
ROOT_INSTALL_PACKAGE,
|
||||
cacheFile.absolutePath,
|
||||
getCurrentUserState,
|
||||
cacheFile.length()
|
||||
)
|
||||
val deleteCommand =
|
||||
String.format(
|
||||
DELETE_PACKAGE,
|
||||
getUtilBoxPath,
|
||||
cacheFile.absolutePath.quote
|
||||
)
|
||||
withContext(Dispatchers.Default) {
|
||||
Shell.su(installCommand).submit { if (it.isSuccess) Shell.su(deleteCommand).submit() }
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun mRootUninstaller(packageName: String) {
|
||||
val uninstallCommand =
|
||||
String.format(ROOT_UNINSTALL_PACKAGE, getCurrentUserState, packageName)
|
||||
withContext(Dispatchers.Default) { Shell.su(uninstallCommand).submit() }
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val getCurrentUserState: String =
|
||||
Shell.su("dumpsys activity | grep -E \"mUserLru\"")
|
||||
.exec().out[0].trim()
|
||||
@ -66,4 +29,54 @@ class RootInstaller(context: Context) : BaseInstaller(context) {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
val File.install
|
||||
get() = String.format(
|
||||
ROOT_INSTALL_PACKAGE,
|
||||
absolutePath,
|
||||
getCurrentUserState,
|
||||
length()
|
||||
)
|
||||
|
||||
val String.uninstall
|
||||
get() = String.format(
|
||||
ROOT_UNINSTALL_PACKAGE,
|
||||
getCurrentUserState,
|
||||
this
|
||||
)
|
||||
|
||||
val File.deletePackage
|
||||
get() = String.format(
|
||||
DELETE_PACKAGE,
|
||||
getUtilBoxPath,
|
||||
absolutePath.quote
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun install(cacheFileName: String) {
|
||||
val cacheFile = Cache.getReleaseFile(context, cacheFileName)
|
||||
mRootInstaller(cacheFile)
|
||||
}
|
||||
|
||||
override suspend fun install(packageName: String, cacheFileName: String) {
|
||||
val cacheFile = Cache.getReleaseFile(context, cacheFileName)
|
||||
mRootInstaller(cacheFile)
|
||||
}
|
||||
|
||||
override suspend fun install(packageName: String, cacheFile: File) = mRootInstaller(cacheFile)
|
||||
|
||||
override suspend fun uninstall(packageName: String) = mRootUninstaller(packageName)
|
||||
|
||||
private suspend fun mRootInstaller(cacheFile: File) {
|
||||
withContext(Dispatchers.Default) {
|
||||
Shell.su(cacheFile.install)
|
||||
.submit { if (it.isSuccess) Shell.su(cacheFile.deletePackage).submit() }
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun mRootUninstaller(packageName: String) {
|
||||
withContext(Dispatchers.Default) {
|
||||
Shell.su(packageName.uninstall).submit()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user