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