mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 19:32:16 +00:00
Improve: Installer Cleanup
This commit is contained in:
parent
2158a7a102
commit
298c39c99a
@ -1,18 +1,11 @@
|
|||||||
package com.looker.droidify.installer
|
package com.looker.droidify.installer
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.Job
|
|
||||||
|
|
||||||
abstract class BaseInstaller(val context: Context) : InstallationEvents {
|
abstract class BaseInstaller(val context: Context) : InstallationEvents {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val ROOT_INSTALL_PACKAGE = "cat %s | pm install --user %s -t -r -S %s"
|
const val ROOT_INSTALL_PACKAGE = "cat %s | pm install --user %s -t -r -S %s"
|
||||||
const val ROOT_UNINSTALL_PACKAGE = "pm uninstall --user %s %s"
|
const val ROOT_UNINSTALL_PACKAGE = "pm uninstall --user %s %s"
|
||||||
const val DELETE_PACKAGE = "%s rm %s"
|
const val DELETE_PACKAGE = "%s rm %s"
|
||||||
}
|
}
|
||||||
|
|
||||||
private val job = Job()
|
|
||||||
val scope = CoroutineScope(Dispatchers.IO + job)
|
|
||||||
}
|
}
|
@ -12,18 +12,15 @@ import java.io.File
|
|||||||
|
|
||||||
class DefaultInstaller(context: Context) : BaseInstaller(context) {
|
class DefaultInstaller(context: Context) : BaseInstaller(context) {
|
||||||
|
|
||||||
override fun install(packageName: String, cacheFileName: String) {
|
override suspend fun install(packageName: String, cacheFileName: String) {
|
||||||
val cacheFile = Cache.getReleaseFile(context, cacheFileName)
|
val cacheFile = Cache.getReleaseFile(context, cacheFileName)
|
||||||
scope.launch { mDefaultInstaller(cacheFile) }
|
mDefaultInstaller(cacheFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun install(packageName: String, cacheFile: File) {
|
override suspend fun install(packageName: String, cacheFile: File) =
|
||||||
scope.launch { mDefaultInstaller(cacheFile) }
|
mDefaultInstaller(cacheFile)
|
||||||
}
|
|
||||||
|
|
||||||
override fun uninstall(packageName: String) {
|
override suspend fun uninstall(packageName: String) = mDefaultUninstaller(packageName)
|
||||||
scope.launch { mDefaultUninstaller(packageName) }
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun mDefaultInstaller(cacheFile: File) {
|
private suspend fun mDefaultInstaller(cacheFile: File) {
|
||||||
val (uri, flags) = if (Android.sdk(24)) {
|
val (uri, flags) = if (Android.sdk(24)) {
|
||||||
@ -37,17 +34,21 @@ class DefaultInstaller(context: Context) : BaseInstaller(context) {
|
|||||||
// TODO Handle deprecation
|
// TODO Handle deprecation
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
|
launch {
|
||||||
context.startActivity(
|
context.startActivity(
|
||||||
Intent(Intent.ACTION_INSTALL_PACKAGE)
|
Intent(Intent.ACTION_INSTALL_PACKAGE)
|
||||||
.setDataAndType(uri, "application/vnd.android.package-archive").setFlags(flags)
|
.setDataAndType(uri, "application/vnd.android.package-archive")
|
||||||
|
.setFlags(flags)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun mDefaultUninstaller(packageName: String) {
|
private suspend fun mDefaultUninstaller(packageName: String) {
|
||||||
val uri = Uri.fromParts("package", packageName, null)
|
val uri = Uri.fromParts("package", packageName, null)
|
||||||
val intent = Intent()
|
val intent = Intent()
|
||||||
intent.data = uri
|
intent.data = uri
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
if (Android.sdk(28)) {
|
if (Android.sdk(28)) {
|
||||||
intent.action = Intent.ACTION_DELETE
|
intent.action = Intent.ACTION_DELETE
|
||||||
} else {
|
} else {
|
||||||
@ -55,6 +56,6 @@ class DefaultInstaller(context: Context) : BaseInstaller(context) {
|
|||||||
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true)
|
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true)
|
||||||
}
|
}
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
context.startActivity(intent)
|
withContext(Dispatchers.IO) { launch { context.startActivity(intent) } }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,9 +3,9 @@ package com.looker.droidify.installer
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
interface InstallationEvents {
|
interface InstallationEvents {
|
||||||
fun install(packageName: String, cacheFileName: String)
|
suspend fun install(packageName: String, cacheFileName: String)
|
||||||
|
|
||||||
fun install(packageName: String, cacheFile: File)
|
suspend fun install(packageName: String, cacheFile: File)
|
||||||
|
|
||||||
fun uninstall(packageName: String)
|
suspend fun uninstall(packageName: String)
|
||||||
}
|
}
|
@ -13,20 +13,16 @@ import java.io.File
|
|||||||
|
|
||||||
class RootInstaller(context: Context) : BaseInstaller(context) {
|
class RootInstaller(context: Context) : BaseInstaller(context) {
|
||||||
|
|
||||||
override fun install(packageName: String, cacheFileName: String) {
|
override suspend fun install(packageName: String, cacheFileName: String) {
|
||||||
val cacheFile = Cache.getReleaseFile(context, cacheFileName)
|
val cacheFile = Cache.getReleaseFile(context, cacheFileName)
|
||||||
scope.launch { mRootInstaller(cacheFile) }
|
mRootInstaller(cacheFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun install(packageName: String, cacheFile: File) {
|
override suspend fun install(packageName: String, cacheFile: File) = mRootInstaller(cacheFile)
|
||||||
scope.launch { mRootInstaller(cacheFile) }
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun uninstall(packageName: String) {
|
override suspend fun uninstall(packageName: String) = mRootUninstaller(packageName)
|
||||||
scope.launch { mRootUninstaller(packageName) }
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun mRootInstaller(cacheFile: File) {
|
private suspend fun mRootInstaller(cacheFile: File) {
|
||||||
if (rootInstallerEnabled) {
|
if (rootInstallerEnabled) {
|
||||||
val installCommand =
|
val installCommand =
|
||||||
String.format(
|
String.format(
|
||||||
@ -41,7 +37,8 @@ class RootInstaller(context: Context) : BaseInstaller(context) {
|
|||||||
getUtilBoxPath,
|
getUtilBoxPath,
|
||||||
cacheFile.absolutePath.quote
|
cacheFile.absolutePath.quote
|
||||||
)
|
)
|
||||||
scope.launch {
|
withContext(Dispatchers.IO) {
|
||||||
|
launch {
|
||||||
Shell.su(installCommand).submit {
|
Shell.su(installCommand).submit {
|
||||||
if (it.isSuccess) {
|
if (it.isSuccess) {
|
||||||
Shell.su(deleteCommand).submit()
|
Shell.su(deleteCommand).submit()
|
||||||
@ -50,6 +47,7 @@ class RootInstaller(context: Context) : BaseInstaller(context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun mRootUninstaller(packageName: String) {
|
private suspend fun mRootUninstaller(packageName: String) {
|
||||||
if (rootInstallerEnabled) {
|
if (rootInstallerEnabled) {
|
||||||
|
@ -53,7 +53,7 @@ class ProductFragment() : ScreenFragment(), ProductAdapter.Callbacks {
|
|||||||
private enum class Action(
|
private enum class Action(
|
||||||
val id: Int,
|
val id: Int,
|
||||||
val adapterAction: ProductAdapter.Action,
|
val adapterAction: ProductAdapter.Action,
|
||||||
val iconResId: Int
|
val iconResId: Int,
|
||||||
) {
|
) {
|
||||||
INSTALL(1, ProductAdapter.Action.INSTALL, R.drawable.ic_download),
|
INSTALL(1, ProductAdapter.Action.INSTALL, R.drawable.ic_download),
|
||||||
UPDATE(2, ProductAdapter.Action.UPDATE, R.drawable.ic_download),
|
UPDATE(2, ProductAdapter.Action.UPDATE, R.drawable.ic_download),
|
||||||
@ -65,7 +65,7 @@ class ProductFragment() : ScreenFragment(), ProductAdapter.Callbacks {
|
|||||||
|
|
||||||
private class Installed(
|
private class Installed(
|
||||||
val installedItem: InstalledItem, val isSystem: Boolean,
|
val installedItem: InstalledItem, val isSystem: Boolean,
|
||||||
val launcherActivities: List<Pair<String, String>>
|
val launcherActivities: List<Pair<String, String>>,
|
||||||
)
|
)
|
||||||
|
|
||||||
val packageName: String
|
val packageName: String
|
||||||
@ -370,7 +370,6 @@ class ProductFragment() : ScreenFragment(), ProductAdapter.Callbacks {
|
|||||||
if (state is DownloadService.State.Success && isResumed) {
|
if (state is DownloadService.State.Success && isResumed) {
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
state.consume()
|
state.consume()
|
||||||
}
|
|
||||||
AppInstaller
|
AppInstaller
|
||||||
.getInstance(context)?.defaultInstaller?.install(
|
.getInstance(context)?.defaultInstaller?.install(
|
||||||
"",
|
"",
|
||||||
@ -378,6 +377,7 @@ class ProductFragment() : ScreenFragment(), ProductAdapter.Callbacks {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private val scrollListener = object : RecyclerView.OnScrollListener() {
|
private val scrollListener = object : RecyclerView.OnScrollListener() {
|
||||||
private var lastPosition = -1
|
private var lastPosition = -1
|
||||||
@ -397,7 +397,8 @@ class ProductFragment() : ScreenFragment(), ProductAdapter.Callbacks {
|
|||||||
override fun onActionClick(action: ProductAdapter.Action) {
|
override fun onActionClick(action: ProductAdapter.Action) {
|
||||||
when (action) {
|
when (action) {
|
||||||
ProductAdapter.Action.INSTALL,
|
ProductAdapter.Action.INSTALL,
|
||||||
ProductAdapter.Action.UPDATE -> {
|
ProductAdapter.Action.UPDATE,
|
||||||
|
-> {
|
||||||
val installedItem = installed?.installedItem
|
val installedItem = installed?.installedItem
|
||||||
startUpdate(packageName, installedItem, products, downloadConnection)
|
startUpdate(packageName, installedItem, products, downloadConnection)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user