mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 19:32:16 +00:00
Simplify install prompt handling
Reverts most changes to MainActivity and uses handleSpecialIntent instead. handleSpecialIntent now defers installer prompt to InstallerService by starting it again. SpecialIntent has been modified to accommodate extra data needed to handle these callbacks.
This commit is contained in:
parent
73ac718ce2
commit
3e8e23e111
@ -1,15 +1,10 @@
|
||||
package com.looker.droidify
|
||||
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageInstaller
|
||||
import android.net.Uri
|
||||
import com.looker.droidify.ContextWrapperX.Companion.wrap
|
||||
import com.looker.droidify.installer.InstallerService
|
||||
import com.looker.droidify.screen.ScreenActivity
|
||||
import com.looker.droidify.utility.extension.android.Android
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class MainActivity : ScreenActivity() {
|
||||
companion object {
|
||||
@ -22,35 +17,13 @@ class MainActivity : ScreenActivity() {
|
||||
override fun handleIntent(intent: Intent?) {
|
||||
when (intent?.action) {
|
||||
ACTION_UPDATES -> handleSpecialIntent(SpecialIntent.Updates)
|
||||
ACTION_INSTALL -> {
|
||||
// continue install prompt
|
||||
val promptIntent: Intent? = intent.getParcelableExtra(Intent.EXTRA_INTENT)
|
||||
|
||||
promptIntent?.let {
|
||||
it.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true)
|
||||
it.putExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME, BuildConfig.APPLICATION_ID)
|
||||
it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK )
|
||||
|
||||
startActivity(it)
|
||||
}
|
||||
|
||||
// TODO: send this back to the InstallerService to free up the UI
|
||||
// prepare prompt intent
|
||||
// val name = intent.getStringExtra(PackageInstaller.EXTRA_PACKAGE_NAME)
|
||||
//
|
||||
// val pending = PendingIntent.getService(
|
||||
// this,
|
||||
// 0,
|
||||
// Intent(this, InstallerService::class.java)
|
||||
// .setData(Uri.parse("package:$name"))
|
||||
// .putExtra(Intent.EXTRA_INTENT, promptIntent)
|
||||
// .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
|
||||
// if (Android.sdk(23)) PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||
// else PendingIntent.FLAG_UPDATE_CURRENT
|
||||
// )
|
||||
//
|
||||
// pending.send()
|
||||
}
|
||||
ACTION_INSTALL -> handleSpecialIntent(
|
||||
SpecialIntent.Install(
|
||||
intent.packageName,
|
||||
intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -1),
|
||||
intent.getParcelableExtra(Intent.EXTRA_INTENT)
|
||||
)
|
||||
)
|
||||
else -> super.handleIntent(intent)
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.looker.droidify.screen
|
||||
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageInstaller
|
||||
import android.os.Bundle
|
||||
import android.os.Parcel
|
||||
import android.view.ViewGroup
|
||||
@ -13,7 +14,7 @@ import com.google.android.material.circularreveal.CircularRevealFrameLayout
|
||||
import com.looker.droidify.R
|
||||
import com.looker.droidify.content.Preferences
|
||||
import com.looker.droidify.database.CursorOwner
|
||||
import com.looker.droidify.installer.AppInstaller
|
||||
import com.looker.droidify.installer.InstallerService
|
||||
import com.looker.droidify.ui.fragments.AppDetailFragment
|
||||
import com.looker.droidify.utility.KParcelable
|
||||
import com.looker.droidify.utility.extension.resources.getDrawableFromAttr
|
||||
@ -27,7 +28,7 @@ abstract class ScreenActivity : AppCompatActivity() {
|
||||
|
||||
sealed class SpecialIntent {
|
||||
object Updates : SpecialIntent()
|
||||
class Install(val packageName: String?, val cacheFileName: String?) : SpecialIntent()
|
||||
class Install(val packageName: String?, val status: Int?, val promptIntent: Intent?) : SpecialIntent()
|
||||
}
|
||||
|
||||
private class FragmentStackItem(
|
||||
@ -217,14 +218,24 @@ abstract class ScreenActivity : AppCompatActivity() {
|
||||
}
|
||||
is SpecialIntent.Install -> {
|
||||
val packageName = specialIntent.packageName
|
||||
if (!packageName.isNullOrEmpty()) {
|
||||
val status = specialIntent.status
|
||||
val promptIntent = specialIntent.promptIntent
|
||||
if (!packageName.isNullOrEmpty() && status != null && promptIntent != null) {
|
||||
lifecycleScope.launch {
|
||||
specialIntent.cacheFileName?.let {
|
||||
AppInstaller.getInstance(this@ScreenActivity)
|
||||
?.defaultInstaller?.install(packageName, it)
|
||||
}
|
||||
startService(
|
||||
Intent(baseContext, InstallerService::class.java)
|
||||
.putExtra(PackageInstaller.EXTRA_STATUS, status)
|
||||
.putExtra(
|
||||
PackageInstaller.EXTRA_PACKAGE_NAME,
|
||||
packageName
|
||||
)
|
||||
.putExtra(Intent.EXTRA_INTENT, promptIntent)
|
||||
)
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw IllegalArgumentException("Missing parameters needed to relaunch InstallerService and trigger prompt.")
|
||||
}
|
||||
Unit
|
||||
}
|
||||
}::class
|
||||
|
Loading…
x
Reference in New Issue
Block a user