Skip to content

Commit

Permalink
Merge pull request #42 from tasomaniac/remove-duplicate-vr-activities
Browse files Browse the repository at this point in the history
resolve VR activities and remove them.
  • Loading branch information
tasomaniac authored Aug 20, 2018
2 parents e9fbf6d + 1bf9bbc commit e05c397
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal class IntentResolver @Inject constructor(
private val callerPackage: CallerPackage,
private val resolveListGrouper: ResolveListGrouper,
private val browserHandlerFactory: BrowserHandler.Factory,
private val resolveListDuplicateRemover: ResolveListDuplicateRemover,
val sourceIntent: Intent
) {

Expand Down Expand Up @@ -66,6 +67,7 @@ internal class IntentResolver @Inject constructor(
browserHandlerFactory.create(currentResolveList).handleBrowsers()
}

resolveListDuplicateRemover.process(currentResolveList)
callerPackage.removeFrom(currentResolveList)

val resolved = groupResolveList(currentResolveList)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.tasomaniac.openwith.resolver

import android.content.Intent
import android.content.pm.PackageManager
import android.content.pm.ResolveInfo
import android.os.Build.VERSION.SDK_INT
import android.os.Build.VERSION_CODES.M
import com.tasomaniac.openwith.util.isEqualTo
import javax.inject.Inject

class ResolveListDuplicateRemover @Inject constructor(
private val packageManager: PackageManager
) {

fun process(currentResolveList: MutableList<ResolveInfo>) {
val flag = if (SDK_INT >= M) PackageManager.MATCH_ALL else PackageManager.MATCH_DEFAULT_ONLY
val vr = Intent(Intent.ACTION_MAIN).addCategory("com.google.intent.category.DAYDREAM")
val vrList = packageManager.queryIntentActivities(vr, flag)

currentResolveList.removeAll { info ->
vrList.any { vr ->
vr.activityInfo isEqualTo info.activityInfo
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import android.content.pm.ActivityInfo

fun ActivityInfo.componentName() = ComponentName(applicationInfo.packageName, name)

fun ActivityInfo.isEqualTo(other: ActivityInfo) = componentName() == other.componentName()
infix fun ActivityInfo.isEqualTo(other: ActivityInfo) = componentName() == other.componentName()

0 comments on commit e05c397

Please sign in to comment.