Matthew Crossman 3e8e23e111
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.
2022-01-03 14:51:31 +11:00

35 lines
1.2 KiB
Kotlin

package com.looker.droidify
import android.content.Context
import android.content.Intent
import android.content.pm.PackageInstaller
import com.looker.droidify.ContextWrapperX.Companion.wrap
import com.looker.droidify.screen.ScreenActivity
class MainActivity : ScreenActivity() {
companion object {
const val ACTION_UPDATES = "${BuildConfig.APPLICATION_ID}.intent.action.UPDATES"
const val ACTION_INSTALL = "${BuildConfig.APPLICATION_ID}.intent.action.INSTALL"
const val EXTRA_CACHE_FILE_NAME =
"${BuildConfig.APPLICATION_ID}.intent.extra.CACHE_FILE_NAME"
}
override fun handleIntent(intent: Intent?) {
when (intent?.action) {
ACTION_UPDATES -> handleSpecialIntent(SpecialIntent.Updates)
ACTION_INSTALL -> handleSpecialIntent(
SpecialIntent.Install(
intent.packageName,
intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -1),
intent.getParcelableExtra(Intent.EXTRA_INTENT)
)
)
else -> super.handleIntent(intent)
}
}
override fun attachBaseContext(newBase: Context) {
super.attachBaseContext(wrap(newBase))
}
}