Skip to content

Commit

Permalink
Reduce code
Browse files Browse the repository at this point in the history
  • Loading branch information
Iamlooker committed Sep 26, 2023
1 parent 509bbb7 commit 8c36c8c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ internal class SessionInstaller(private val context: Context) : Installer {
@SuppressLint("MissingPermission")
override suspend fun uninstall(packageName: PackageName) =
suspendCancellableCoroutine { cont ->
intent.putExtra(
SessionInstallerService.KEY_ACTION,
SessionInstallerService.ACTION_UNINSTALL
)
intent.putExtra(SessionInstallerService.ACTION_UNINSTALL, true)
val pendingIntent = PendingIntent.getService(context, -1, intent, flags)

sessionInstaller.uninstall(packageName.name, pendingIntent.intentSender)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import com.looker.core.common.R as CommonR

class SessionInstallerService : Service() {
companion object {
const val KEY_ACTION = "installerAction"
const val ACTION_UNINSTALL = "uninstall"
const val ACTION_UNINSTALL = "action_uninstall"
}

override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
Expand Down Expand Up @@ -50,7 +49,7 @@ class SessionInstallerService : Service() {
val status = intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -1)
val name = intent.getStringExtra(PackageInstaller.EXTRA_PACKAGE_NAME)
val message = intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE)
val installerAction = intent.getStringExtra(KEY_ACTION)
val isUninstall = intent.getBooleanExtra(ACTION_UNINSTALL, false)

// get application name for notifications
val appLabel = try {
Expand All @@ -73,7 +72,7 @@ class SessionInstallerService : Service() {

when (status) {
PackageInstaller.STATUS_SUCCESS -> {
if (installerAction == ACTION_UNINSTALL)
if (isUninstall)
// remove any notification for this app
notificationManager.cancel(notificationTag, NOTIFICATION_ID_DOWNLOADING)
else {
Expand Down

0 comments on commit 8c36c8c

Please sign in to comment.