installer: Inject all installers using hilt
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -9,13 +9,16 @@ import com.aurora.Constants
|
||||
import com.aurora.store.data.installer.SessionInstaller
|
||||
import com.aurora.store.data.room.download.Download
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
class InstallActivity : AppCompatActivity() {
|
||||
|
||||
private val TAG = InstallActivity::class.java.simpleName
|
||||
|
||||
private lateinit var sessionInstaller: SessionInstaller
|
||||
@Inject
|
||||
lateinit var sessionInstaller: SessionInstaller
|
||||
|
||||
private lateinit var sessionCallback: SessionCallback
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@@ -55,7 +58,6 @@ class InstallActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun install(download: Download) {
|
||||
sessionInstaller = SessionInstaller(this)
|
||||
try {
|
||||
sessionInstaller.install(download)
|
||||
} catch (exception: Exception) {
|
||||
|
||||
@@ -8,11 +8,17 @@ import com.aurora.store.data.room.download.Download
|
||||
import com.aurora.store.util.Log
|
||||
import com.aurora.store.util.PackageUtil.isSharedLibraryInstalled
|
||||
import com.aurora.store.util.PathUtil
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import java.io.File
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipOutputStream
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
class AMInstaller(context: Context) : InstallerBase(context) {
|
||||
@Singleton
|
||||
class AMInstaller @Inject constructor(
|
||||
@ApplicationContext context: Context
|
||||
) : InstallerBase(context) {
|
||||
|
||||
companion object {
|
||||
const val AM_PACKAGE_NAME = "io.github.muntashirakon.AppManager"
|
||||
|
||||
@@ -42,8 +42,18 @@ import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import rikka.shizuku.Shizuku
|
||||
import rikka.sui.Sui
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
class AppInstaller @Inject constructor(@ApplicationContext private val context: Context) {
|
||||
@Singleton
|
||||
class AppInstaller @Inject constructor(
|
||||
@ApplicationContext private val context: Context,
|
||||
private val sessionInstaller: SessionInstaller,
|
||||
private val nativeInstaller: NativeInstaller,
|
||||
private val rootInstaller: RootInstaller,
|
||||
private val serviceInstaller: ServiceInstaller,
|
||||
private val amInstaller: AMInstaller,
|
||||
private val shizukuInstaller: ShizukuInstaller
|
||||
) {
|
||||
|
||||
companion object {
|
||||
const val EXTRA_DOWNLOAD = "com.aurora.store.data.installer.AppInstaller.EXTRA_DOWNLOAD"
|
||||
@@ -120,69 +130,24 @@ class AppInstaller @Inject constructor(@ApplicationContext private val context:
|
||||
}
|
||||
}
|
||||
|
||||
val choiceAndInstaller = HashMap<Int, IInstaller>()
|
||||
private val defaultInstaller: IInstaller
|
||||
get() = sessionInstaller
|
||||
|
||||
fun getPreferredInstaller(): IInstaller {
|
||||
val prefValue = Preferences.getInteger(
|
||||
context,
|
||||
PREFERENCE_INSTALLER_ID
|
||||
)
|
||||
|
||||
if (choiceAndInstaller.containsKey(prefValue)) {
|
||||
return choiceAndInstaller[prefValue]!!
|
||||
}
|
||||
|
||||
return when (prefValue) {
|
||||
1 -> {
|
||||
val installer = NativeInstaller(context)
|
||||
choiceAndInstaller[prefValue] = installer
|
||||
installer
|
||||
}
|
||||
2 -> {
|
||||
val installer = if (hasRootAccess()) {
|
||||
RootInstaller(context)
|
||||
} else {
|
||||
SessionInstaller(context)
|
||||
}
|
||||
choiceAndInstaller[prefValue] = installer
|
||||
installer
|
||||
}
|
||||
3 -> {
|
||||
val installer = if (hasAuroraService(context)) {
|
||||
ServiceInstaller(context)
|
||||
} else {
|
||||
SessionInstaller(context)
|
||||
}
|
||||
choiceAndInstaller[prefValue] = installer
|
||||
installer
|
||||
}
|
||||
4 -> {
|
||||
val installer = if (hasAppManager(context)) {
|
||||
AMInstaller(context)
|
||||
} else {
|
||||
SessionInstaller(context)
|
||||
}
|
||||
choiceAndInstaller[prefValue] = installer
|
||||
installer
|
||||
}
|
||||
return when (Preferences.getInteger(context, PREFERENCE_INSTALLER_ID)) {
|
||||
0 -> sessionInstaller
|
||||
1 -> nativeInstaller
|
||||
2 -> if (hasRootAccess()) rootInstaller else defaultInstaller
|
||||
3 -> if (hasAuroraService(context)) serviceInstaller else defaultInstaller
|
||||
4 -> if (hasAppManager(context)) amInstaller else defaultInstaller
|
||||
5 -> {
|
||||
if (isOAndAbove()) {
|
||||
val installer = if (hasShizukuOrSui(context) && hasShizukuPerm()) {
|
||||
ShizukuInstaller(context)
|
||||
} else {
|
||||
SessionInstaller(context)
|
||||
}
|
||||
choiceAndInstaller[prefValue] = installer
|
||||
installer
|
||||
if (isOAndAbove() && hasShizukuOrSui(context) && hasShizukuPerm()) {
|
||||
shizukuInstaller
|
||||
} else {
|
||||
SessionInstaller(context)
|
||||
defaultInstaller
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
val installer = SessionInstaller(context)
|
||||
choiceAndInstaller[prefValue] = installer
|
||||
installer
|
||||
}
|
||||
else -> defaultInstaller
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,10 +28,16 @@ import com.aurora.store.R
|
||||
import com.aurora.store.data.model.Installer
|
||||
import com.aurora.store.data.room.download.Download
|
||||
import com.aurora.store.util.Log
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
@Deprecated("Deprecated in favour of SessionInstaller")
|
||||
class NativeInstaller(context: Context) : InstallerBase(context) {
|
||||
class NativeInstaller @Inject constructor(
|
||||
@ApplicationContext context: Context
|
||||
) : InstallerBase(context) {
|
||||
|
||||
companion object {
|
||||
|
||||
|
||||
@@ -27,10 +27,16 @@ import com.aurora.store.data.room.download.Download
|
||||
import com.aurora.store.util.Log
|
||||
import com.aurora.store.util.PackageUtil.isSharedLibraryInstalled
|
||||
import com.topjohnwu.superuser.Shell
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import java.util.regex.Pattern
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
class RootInstaller(context: Context) : InstallerBase(context) {
|
||||
@Singleton
|
||||
class RootInstaller @Inject constructor(
|
||||
@ApplicationContext context: Context
|
||||
) : InstallerBase(context) {
|
||||
|
||||
companion object {
|
||||
|
||||
|
||||
@@ -41,15 +41,21 @@ import com.aurora.store.data.model.Installer
|
||||
import com.aurora.store.data.room.download.Download
|
||||
import com.aurora.store.util.Log
|
||||
import com.aurora.store.util.PackageUtil
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import java.io.File
|
||||
import java.util.concurrent.LinkedBlockingQueue
|
||||
import java.util.concurrent.ThreadPoolExecutor
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
@Deprecated("Deprecated in favour of RootInstaller")
|
||||
class ServiceInstaller(context: Context) : InstallerBase(context) {
|
||||
class ServiceInstaller @Inject constructor(
|
||||
@ApplicationContext context: Context
|
||||
) : InstallerBase(context) {
|
||||
|
||||
private lateinit var serviceConnection: ServiceConnection
|
||||
private val executor = ThreadPoolExecutor(0, 1, 30L, TimeUnit.SECONDS, LinkedBlockingQueue())
|
||||
|
||||
@@ -42,9 +42,15 @@ import com.aurora.store.data.receiver.InstallerStatusReceiver
|
||||
import com.aurora.store.data.room.download.Download
|
||||
import com.aurora.store.util.Log
|
||||
import com.aurora.store.util.PackageUtil.isSharedLibraryInstalled
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
class SessionInstaller(context: Context) : InstallerBase(context) {
|
||||
@Singleton
|
||||
class SessionInstaller @Inject constructor(
|
||||
@ApplicationContext context: Context
|
||||
) : InstallerBase(context) {
|
||||
|
||||
var parentSessionId by Delegates.notNull<Int>()
|
||||
|
||||
|
||||
@@ -37,12 +37,18 @@ import com.aurora.store.data.receiver.InstallerStatusReceiver
|
||||
import com.aurora.store.data.room.download.Download
|
||||
import com.aurora.store.util.Log
|
||||
import com.aurora.store.util.PackageUtil.isSharedLibraryInstalled
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dev.rikka.tools.refine.Refine
|
||||
import rikka.shizuku.ShizukuBinderWrapper
|
||||
import rikka.shizuku.SystemServiceHelper
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
class ShizukuInstaller(context: Context) : InstallerBase(context) {
|
||||
class ShizukuInstaller @Inject constructor(
|
||||
@ApplicationContext context: Context
|
||||
) : InstallerBase(context) {
|
||||
|
||||
companion object {
|
||||
const val SHIZUKU_PACKAGE_NAME = "moe.shizuku.privileged.api"
|
||||
|
||||
Reference in New Issue
Block a user