Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Merge #6159
Browse files Browse the repository at this point in the history
6159: Issue #6097: Remove IntentProcessor.matches(). r=psymoon a=pocmo

IntentProcessor.process() already checks whether the Intent matches and returns true or
false. Another call to matches() is not necessary. Fenix was already refactored and we
removed the matches() call.



Co-authored-by: Sebastian Kaspari <s.kaspari@gmail.com>
  • Loading branch information
MozLando and pocmo committed Mar 3, 2020
2 parents ba30cec + d6750d9 commit 945d1a4
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CustomTabIntentProcessor(
private val isPrivate: Boolean = false
) : IntentProcessor {

override fun matches(intent: Intent): Boolean {
private fun matches(intent: Intent): Boolean {
val safeIntent = intent.toSafeIntent()
return safeIntent.action == ACTION_VIEW && isCustomTabIntent(safeIntent)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ import android.content.Intent
* Processor for Android intents which should trigger session-related actions.
*/
interface IntentProcessor {

/**
* Returns true if this intent processor will handle the intent.
*/
fun matches(intent: Intent): Boolean

/**
* Processes the given [Intent].
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,6 @@ class TabIntentProcessor(
}
}

override fun matches(intent: Intent): Boolean {
val safeIntent = SafeIntent(intent)
return safeIntent.action == ACTION_VIEW ||
safeIntent.action == ACTION_SEND ||
safeIntent.action == ACTION_NDEF_DISCOVERED ||
safeIntent.action == ACTION_SEARCH ||
safeIntent.action == ACTION_WEB_SEARCH
}

/**
* Processes the given intent by invoking the registered handler.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class TrustedWebActivityIntentProcessor(
private val verifier = OriginVerifierFeature(httpClient, packageManager, apiKey) { store.dispatch(it) }
private val scope = MainScope()

override fun matches(intent: Intent): Boolean {
private fun matches(intent: Intent): Boolean {
val safeIntent = intent.toSafeIntent()
return safeIntent.action == ACTION_VIEW && isTrustedWebActivityIntent(safeIntent)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class WebAppIntentProcessor(
/**
* Returns true if this intent should launch a progressive web app.
*/
override fun matches(intent: Intent) =
private fun matches(intent: Intent) =
intent.toSafeIntent().action == ACTION_VIEW_PWA

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,6 @@ class TrustedWebActivityIntentProcessorTest {
sessionManager = SessionManager(mock(), store)
}

@Test
fun `matches checks if intent is a trusted web activity intent`() {
val processor = TrustedWebActivityIntentProcessor(mock(), mock(), mock(), mock(), apiKey, mock())

assertFalse(processor.matches(Intent(ACTION_VIEW_PWA)))
assertFalse(processor.matches(Intent(ACTION_VIEW)))
assertFalse(processor.matches(
Intent(ACTION_VIEW).apply { putExtra(EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY, true) }
))
assertFalse(processor.matches(
Intent(ACTION_VIEW).apply {
putExtra(EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY, false)
putExtra(EXTRA_SESSION, null as Bundle?)
}
))
assertTrue(processor.matches(
Intent(ACTION_VIEW).apply {
putExtra(EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY, true)
putExtra(EXTRA_SESSION, null as Bundle?)
}
))
}

@Test
fun `process checks if intent action is not valid`() = runBlockingTest {
val processor = TrustedWebActivityIntentProcessor(mock(), mock(), mock(), mock(), apiKey, mock())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ import org.mockito.Mockito.`when`
@RunWith(AndroidJUnit4::class)
@ExperimentalCoroutinesApi
class WebAppIntentProcessorTest {

@Test
fun `matches checks if intent action is ACTION_VIEW_PWA`() {
val processor = WebAppIntentProcessor(mock(), mock(), mock())

assertTrue(processor.matches(Intent(ACTION_VIEW_PWA)))
assertFalse(processor.matches(Intent(ACTION_VIEW)))
}

@Test
fun `process checks if intent action is not valid`() = runBlockingTest {
val processor = WebAppIntentProcessor(mock(), mock(), mock())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ import mozilla.components.support.migration.state.MigrationStore
* ⚠️ When using this processor, ensure this is the first processor to be invoked if there are multiple.
*/
class MigrationIntentProcessor(private val store: MigrationStore) : IntentProcessor {

/**
* Matches itself with all intents in order to ensure processing all of incoming intents.
*/
override fun matches(intent: Intent): Boolean = store.state.progress == MigrationProgress.MIGRATING

/**
* Processes all incoming intents if a migration is in progress.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@ import org.junit.Assert.assertTrue
import org.junit.Test

class MigrationIntentProcessorTest {
@Test
fun `matches against all view action intents`() = runBlockingTest {
val store = MigrationStore()
val processor = MigrationIntentProcessor(store)
val intent: Intent = mock()

assertFalse(processor.matches(intent))

store.dispatch(MigrationAction.Started).joinBlocking()

assertTrue(processor.matches(intent))
}

@Test
fun `process updates intent`() = runBlockingTest {
val store = MigrationStore()
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ permalink: /changelog/
* **feature-awesomebar**
* ⚠️ **This is a breaking change**: Refactored component to use `browser-state` instead of `browser-session`. Feature and `SuggestionProvider` implementations may require a `BrowserStore` instance instead of a `SessionManager` now.

* **feature-intent**
* ⚠️ **This is a breaking change**: Removed `IntentProcessor.matches()` method from interface. Calling `process()` and examining the boolean return value is enough to know whether an `Intent` matched.

* **feature-downloads**
* Fixed APK downloads not prompting to install when the notification is clicked.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,19 @@ class IntentReceiverActivity : Activity() {
// LauncherActivity is started with the "excludeFromRecents" flag (set in manifest). We
// do not want to propagate this flag from the launcher activity to the browser.
intent.flags = intent.flags and Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS.inv()
intentProcessors.any { it.process(intent) }

setBrowserActivity(intent)
val processor = intentProcessors.firstOrNull { it.process(intent) }

val activityClass = if (processor in components.externalAppIntentProcessors) {
ExternalAppBrowserActivity::class
} else {
BrowserActivity::class
}

intent.setClassName(applicationContext, activityClass.java.name)

finish()
startActivity(intent)
}
}

/**
* Sets the activity that this [intent] will launch.
*/
private fun setBrowserActivity(intent: Intent) {
val className = if (components.externalAppIntentProcessors.any { it.matches(intent) }) {
ExternalAppBrowserActivity::class
} else {
BrowserActivity::class
}

intent.setClassName(applicationContext, className.java.name)
}
}

0 comments on commit 945d1a4

Please sign in to comment.