AppInstaller: Use hilt to manage instance
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -33,13 +33,14 @@ import com.aurora.store.util.PackageUtil
|
||||
import com.aurora.store.util.Preferences
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_INSTALLER_ID
|
||||
import com.topjohnwu.superuser.Shell
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import rikka.shizuku.Shizuku
|
||||
import rikka.sui.Sui
|
||||
import javax.inject.Inject
|
||||
|
||||
open class AppInstaller private constructor(var context: Context) {
|
||||
class AppInstaller @Inject constructor(@ApplicationContext private val context: Context) {
|
||||
|
||||
companion object {
|
||||
private var instance: AppInstaller? = null
|
||||
fun getErrorString(context: Context, status: Int): String {
|
||||
return when (status) {
|
||||
PackageInstaller.STATUS_FAILURE_ABORTED -> context.getString(R.string.installer_status_user_action)
|
||||
@@ -51,12 +52,6 @@ open class AppInstaller private constructor(var context: Context) {
|
||||
else -> context.getString(R.string.installer_status_failure)
|
||||
}
|
||||
}
|
||||
fun getInstance(context: Context): AppInstaller {
|
||||
if (instance == null) {
|
||||
instance = AppInstaller(context.applicationContext)
|
||||
}
|
||||
return instance!!
|
||||
}
|
||||
|
||||
fun hasRootAccess(): Boolean {
|
||||
return Shell.getShell().isRoot
|
||||
|
||||
@@ -49,6 +49,9 @@ open class PackageManagerReceiver : BroadcastReceiver() {
|
||||
@Inject
|
||||
lateinit var downloadWorkerUtil: DownloadWorkerUtil
|
||||
|
||||
@Inject
|
||||
lateinit var appInstaller: AppInstaller
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) = goAsync {
|
||||
if (intent.action != null && intent.data != null) {
|
||||
val packageName = intent.data!!.encodedSchemeSpecificPart
|
||||
@@ -74,9 +77,7 @@ open class PackageManagerReceiver : BroadcastReceiver() {
|
||||
}
|
||||
|
||||
//Clear installation queue
|
||||
AppInstaller.getInstance(context)
|
||||
.getPreferredInstaller()
|
||||
.removeFromInstallQueue(packageName)
|
||||
appInstaller.getPreferredInstaller().removeFromInstallQueue(packageName)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ import com.aurora.gplayapi.data.models.File as GPlayFile
|
||||
class DownloadWorker @AssistedInject constructor(
|
||||
private val downloadDao: DownloadDao,
|
||||
private val gson: Gson,
|
||||
private val appInstaller: AppInstaller,
|
||||
@Assisted private val appContext: Context,
|
||||
@Assisted workerParams: WorkerParameters
|
||||
) : CoroutineWorker(appContext, workerParams) {
|
||||
@@ -161,16 +162,12 @@ class DownloadWorker @AssistedInject constructor(
|
||||
withContext(NonCancellable) {
|
||||
try {
|
||||
val downloadDir = PathUtil.getAppDownloadDir(
|
||||
appContext,
|
||||
download.packageName,
|
||||
download.versionCode
|
||||
appContext, download.packageName, download.versionCode
|
||||
)
|
||||
appInstaller.getPreferredInstaller().install(
|
||||
download.packageName,
|
||||
downloadDir.listFiles()!!.filter { it.path.endsWith(".apk") }
|
||||
)
|
||||
AppInstaller.getInstance(appContext)
|
||||
.getPreferredInstaller()
|
||||
.install(
|
||||
download.packageName,
|
||||
downloadDir.listFiles()!!.filter { it.path.endsWith(".apk") }
|
||||
)
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, "Failed to install ${download.packageName}", exception)
|
||||
}
|
||||
|
||||
@@ -54,6 +54,9 @@ class DownloadMenuSheet : BaseBottomSheet() {
|
||||
@Inject
|
||||
lateinit var downloadWorkerUtil: DownloadWorkerUtil
|
||||
|
||||
@Inject
|
||||
lateinit var appInstaller: AppInstaller
|
||||
|
||||
override fun onCreateContentView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup,
|
||||
@@ -113,12 +116,10 @@ class DownloadMenuSheet : BaseBottomSheet() {
|
||||
args.download.packageName,
|
||||
args.download.versionCode
|
||||
)
|
||||
AppInstaller.getInstance(requireContext())
|
||||
.getPreferredInstaller()
|
||||
.install(
|
||||
args.download.packageName,
|
||||
downloadDir.listFiles()!!.filter { it.path.endsWith(".apk") }
|
||||
)
|
||||
appInstaller.getPreferredInstaller().install(
|
||||
args.download.packageName,
|
||||
downloadDir.listFiles()!!.filter { it.path.endsWith(".apk") }
|
||||
)
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, "Failed to install ${args.download.packageName}", exception)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user