Commit abced935 authored by Tiger Oakes's avatar Tiger Oakes
Browse files

mozilla-mobile/fenix#4233 - Add NFC tag support

parent 79636afc
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ The following metrics are added to the ping:

| Name | Type | Description | Data reviews | Extras | Expiration |
| --- | --- | --- | --- | --- | --- |
| test.glean.geckoview.streaming |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |A test-only, disabled metric. This is required to guarantee that a `GleanGeckoHistogramMapping` is always generated, even though the GeckoView AAR exports no metric. Please note that the data-review field below contains no review, since this metric is disabled and not allowed to collect any data.  |[1](https://bugzilla.mozilla.org/show_bug.cgi?id=1566374)||never |
| test.glean.geckoview.streaming |[timing_distribution](https://mozilla.github.io/glean/book/user/metrics/timing_distribution.html) |A test-only, disabled metric. This is required to guarantee that a `GleanGeckoHistogramMapping` is always generated, even though the GeckoView AAR exports no metric. Please note that the data-review field below contains no review, since this metric is disabled and not allowed to collect any data.  |[1](https://bugzilla.mozilla.org/1566374)||never |


<!-- AUTOGENERATED BY glean_parser.  DO NOT EDIT. -->
+5 −2
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ import android.content.Intent
import android.content.Intent.ACTION_SEND
import android.content.Intent.ACTION_VIEW
import android.content.Intent.EXTRA_TEXT
import android.nfc.NfcAdapter.ACTION_NDEF_DISCOVERED
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.Session.Source
import mozilla.components.browser.session.SessionManager
@@ -82,7 +83,9 @@ class TabIntentProcessor(

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

    /**
@@ -94,7 +97,7 @@ class TabIntentProcessor(
    override suspend fun process(intent: Intent): Boolean {
        val safeIntent = SafeIntent(intent)
        return when (safeIntent.action) {
            ACTION_VIEW -> processViewIntent(safeIntent)
            ACTION_VIEW, ACTION_NDEF_DISCOVERED -> processViewIntent(safeIntent)
            ACTION_SEND -> processSendIntent(safeIntent)
            else -> false
        }
+63 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
package mozilla.components.feature.intent.processing

import android.content.Intent
import android.nfc.NfcAdapter.ACTION_NDEF_DISCOVERED
import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runBlockingTest
@@ -112,6 +113,68 @@ class TabIntentProcessorTest {
        verify(engineSession).loadUrl("http://mozilla.org", LoadUrlFlags.external())
    }

    @Test
    fun processNfcIntent() = runBlockingTest {
        val engine = mock<Engine>()
        val sessionManager = spy(SessionManager(engine))
        val useCases = SessionUseCases(sessionManager)
        val handler =
            TabIntentProcessor(sessionManager, useCases.loadUrl, searchUseCases.newTabSearch)
        val intent = mock<Intent>()
        whenever(intent.action).thenReturn(ACTION_NDEF_DISCOVERED)

        val engineSession = mock<EngineSession>()
        doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession())

        whenever(intent.dataString).thenReturn("")
        handler.process(intent)
        verify(engineSession, never()).loadUrl("")

        whenever(intent.dataString).thenReturn("http://mozilla.org")
        handler.process(intent)
        verify(engineSession).loadUrl("http://mozilla.org", LoadUrlFlags.external())

        val session = sessionManager.all[0]
        assertNotNull(session)
        assertEquals("http://mozilla.org", session.url)
        assertEquals(Source.ACTION_VIEW, session.source)
    }

    @Test
    fun processNfcIntentUsingSelectedSession() = runBlockingTest {
        val handler = TabIntentProcessor(
            sessionManager,
            sessionUseCases.loadUrl,
            searchUseCases.newTabSearch,
            openNewTab = false
        )
        val intent = mock<Intent>()
        whenever(intent.action).thenReturn(ACTION_NDEF_DISCOVERED)
        whenever(intent.dataString).thenReturn("http://mozilla.org")

        handler.process(intent)
        verify(engineSession).loadUrl("http://mozilla.org", LoadUrlFlags.external())
    }

    @Test
    fun processNfcIntentHavingNoSelectedSession() = runBlockingTest {
        whenever(sessionManager.selectedSession).thenReturn(null)
        doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession())

        val handler = TabIntentProcessor(
            sessionManager,
            sessionUseCases.loadUrl,
            searchUseCases.newTabSearch,
            openNewTab = false
        )
        val intent = mock<Intent>()
        whenever(intent.action).thenReturn(ACTION_NDEF_DISCOVERED)
        whenever(intent.dataString).thenReturn("http://mozilla.org")

        handler.process(intent)
        verify(engineSession).loadUrl("http://mozilla.org", LoadUrlFlags.external())
    }

    @Test
    fun `load URL on ACTION_SEND if text contains URL`() = runBlockingTest {
        doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession())
+3 −0
Original line number Diff line number Diff line
@@ -21,6 +21,9 @@ permalink: /changelog/
* **tooling-detekt**
  * Published detekt rules for internal use. Check module documentation for detailed ruleset description.

* **feature-intent**
  * Added support for NFC tag intents to `TabIntentProcessor`.

# 15.0.0

* [Commits](https://github.com/mozilla-mobile/android-components/compare/v14.0.0...v15.0.0)
+7 −0
Original line number Diff line number Diff line
@@ -57,6 +57,13 @@
                <data android:mimeType="text/plain" />
            </intent-filter>

            <intent-filter>
                <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="http" />
                <data android:scheme="https" />
            </intent-filter>

            <intent-filter>
                <action android:name="mozilla.components.feature.pwa.VIEW_PWA" />
                <category android:name="android.intent.category.DEFAULT" />