mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 19:32:16 +00:00
Add old installer back for some devices
This commit is contained in:
parent
487a6ecc46
commit
8f2719c7aa
@ -23,7 +23,7 @@ class DefaultInstaller(context: Context) : BaseInstaller(context) {
|
|||||||
val flags = if (Android.sdk(31)) PendingIntent.FLAG_MUTABLE else 0
|
val flags = if (Android.sdk(31)) PendingIntent.FLAG_MUTABLE else 0
|
||||||
val sessionParams = SessionParams(SessionParams.MODE_FULL_INSTALL).apply {
|
val sessionParams = SessionParams(SessionParams.MODE_FULL_INSTALL).apply {
|
||||||
if (Android.sdk(31)) {
|
if (Android.sdk(31)) {
|
||||||
this.setRequireUserAction(SessionParams.USER_ACTION_NOT_REQUIRED)
|
setRequireUserAction(SessionParams.USER_ACTION_NOT_REQUIRED)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,65 @@
|
|||||||
|
package com.looker.droidify.installer
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import androidx.core.net.toUri
|
||||||
|
import com.looker.droidify.content.Cache
|
||||||
|
import com.looker.droidify.utility.extension.android.Android
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
// TODO: Use this for MIUI device instead of guiding new users
|
||||||
|
class DefaultInstallerOld(context: Context) : BaseInstaller(context) {
|
||||||
|
override suspend fun install(cacheFileName: String) {
|
||||||
|
val cacheFile = Cache.getReleaseFile(context, cacheFileName)
|
||||||
|
mOldDefaultInstaller(cacheFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun install(packageName: String, cacheFileName: String) {
|
||||||
|
val cacheFile = Cache.getReleaseFile(context, cacheFileName)
|
||||||
|
mOldDefaultInstaller(cacheFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun install(packageName: String, cacheFile: File) =
|
||||||
|
mOldDefaultInstaller(cacheFile)
|
||||||
|
|
||||||
|
override suspend fun uninstall(packageName: String) = mOldDefaultUninstaller(packageName)
|
||||||
|
|
||||||
|
private suspend fun mOldDefaultInstaller(cacheFile: File) {
|
||||||
|
val (uri, flags) = if (Android.sdk(24)) {
|
||||||
|
Pair(
|
||||||
|
Cache.getReleaseFile(context, cacheFile.name).toUri(),
|
||||||
|
Intent.FLAG_GRANT_READ_URI_PERMISSION
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Pair(Uri.fromFile(cacheFile), 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
context.startActivity(
|
||||||
|
Intent(Intent.ACTION_INSTALL_PACKAGE)
|
||||||
|
.setDataAndType(uri, "application/vnd.android.package-archive")
|
||||||
|
.setFlags(flags)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun mOldDefaultUninstaller(packageName: String) {
|
||||||
|
val uri = Uri.fromParts("package", packageName, null)
|
||||||
|
val intent = Intent()
|
||||||
|
intent.data = uri
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
if (Android.sdk(28)) {
|
||||||
|
intent.action = Intent.ACTION_DELETE
|
||||||
|
} else {
|
||||||
|
intent.action = Intent.ACTION_UNINSTALL_PACKAGE
|
||||||
|
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true)
|
||||||
|
}
|
||||||
|
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
withContext(Dispatchers.IO) { context.startActivity(intent) }
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user