For #778 - Rename CustomTabActivity
parent
e9fd6892ba
commit
699eacab39
|
@ -66,7 +66,7 @@
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".customtabs.CustomTabActivity"
|
android:name=".customtabs.ExternalAppBrowserActivity"
|
||||||
android:autoRemoveFromRecents="false"
|
android:autoRemoveFromRecents="false"
|
||||||
android:configChanges="keyboard|keyboardHidden|mcc|mnc|orientation|screenSize|locale|layoutDirection|smallestScreenSize|screenLayout"
|
android:configChanges="keyboard|keyboardHidden|mcc|mnc|orientation|screenSize|locale|layoutDirection|smallestScreenSize|screenLayout"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
|
|
|
@ -11,22 +11,25 @@ import android.speech.RecognizerIntent
|
||||||
import androidx.annotation.VisibleForTesting
|
import androidx.annotation.VisibleForTesting
|
||||||
import kotlinx.coroutines.MainScope
|
import kotlinx.coroutines.MainScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import mozilla.components.feature.intent.processing.TabIntentProcessor
|
||||||
import org.mozilla.fenix.components.metrics.Event
|
import org.mozilla.fenix.components.metrics.Event
|
||||||
import org.mozilla.fenix.customtabs.AuthCustomTabActivity
|
import org.mozilla.fenix.customtabs.AuthCustomTabActivity
|
||||||
import org.mozilla.fenix.customtabs.AuthCustomTabActivity.Companion.EXTRA_AUTH_CUSTOM_TAB
|
import org.mozilla.fenix.customtabs.AuthCustomTabActivity.Companion.EXTRA_AUTH_CUSTOM_TAB
|
||||||
import org.mozilla.fenix.customtabs.CustomTabActivity
|
import org.mozilla.fenix.customtabs.ExternalAppBrowserActivity
|
||||||
import org.mozilla.fenix.ext.components
|
import org.mozilla.fenix.ext.components
|
||||||
import org.mozilla.fenix.ext.metrics
|
import org.mozilla.fenix.ext.metrics
|
||||||
|
import org.mozilla.fenix.ext.settings
|
||||||
import org.mozilla.fenix.home.intent.StartSearchIntentProcessor
|
import org.mozilla.fenix.home.intent.StartSearchIntentProcessor
|
||||||
import org.mozilla.fenix.utils.Settings
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes incoming intents and sends them to the corresponding activity.
|
||||||
|
*/
|
||||||
class IntentReceiverActivity : Activity() {
|
class IntentReceiverActivity : Activity() {
|
||||||
|
|
||||||
// Holds the intent that initially started this activity
|
// Holds the intent that initially started this activity
|
||||||
// so that it can persist through the speech activity.
|
// so that it can persist through the speech activity.
|
||||||
private var previousIntent: Intent? = null
|
private var previousIntent: Intent? = null
|
||||||
|
|
||||||
@Suppress("ComplexMethod")
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
@ -42,20 +45,21 @@ class IntentReceiverActivity : Activity() {
|
||||||
// the HomeActivity.
|
// the HomeActivity.
|
||||||
val intent = intent?.let { Intent(intent) } ?: Intent()
|
val intent = intent?.let { Intent(intent) } ?: Intent()
|
||||||
|
|
||||||
val intentProcessor = if (Settings.getInstance(applicationContext).alwaysOpenInPrivateMode)
|
val tabIntentProcessor = if (settings().alwaysOpenInPrivateMode) {
|
||||||
components.intentProcessors.privateIntentProcessor else components.intentProcessors.intentProcessor
|
components.intentProcessors.privateIntentProcessor
|
||||||
|
} else {
|
||||||
|
components.intentProcessors.intentProcessor
|
||||||
|
}
|
||||||
|
|
||||||
val intentProcessors = listOf(
|
val intentProcessors =
|
||||||
components.intentProcessors.customTabIntentProcessor,
|
components.intentProcessors.externalAppIntentProcessors + tabIntentProcessor
|
||||||
intentProcessor
|
|
||||||
)
|
|
||||||
|
|
||||||
if (intent.getBooleanExtra(SPEECH_PROCESSING, false)) {
|
if (intent.getBooleanExtra(SPEECH_PROCESSING, false)) {
|
||||||
previousIntent = intent
|
previousIntent = intent
|
||||||
displaySpeechRecognizer()
|
displaySpeechRecognizer()
|
||||||
} else {
|
} else {
|
||||||
intentProcessors.any { it.process(intent) }
|
intentProcessors.any { it.process(intent) }
|
||||||
setIntentActivity(intent)
|
setIntentActivity(intent, tabIntentProcessor)
|
||||||
|
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
|
|
||||||
|
@ -64,19 +68,22 @@ class IntentReceiverActivity : Activity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setIntentActivity(intent: Intent) {
|
/**
|
||||||
|
* Sets the activity that this [intent] will launch.
|
||||||
|
*/
|
||||||
|
private fun setIntentActivity(intent: Intent, tabIntentProcessor: TabIntentProcessor) {
|
||||||
val openToBrowser = when {
|
val openToBrowser = when {
|
||||||
components.intentProcessors.customTabIntentProcessor.matches(intent) -> {
|
components.intentProcessors.externalAppIntentProcessors.any { it.matches(intent) } -> {
|
||||||
// TODO this needs to change: https://github.com/mozilla-mobile/fenix/issues/5225
|
// TODO this needs to change: https://github.com/mozilla-mobile/fenix/issues/5225
|
||||||
val activityClass = if (intent.hasExtra(EXTRA_AUTH_CUSTOM_TAB)) {
|
val activityClass = if (intent.hasExtra(EXTRA_AUTH_CUSTOM_TAB)) {
|
||||||
AuthCustomTabActivity::class
|
AuthCustomTabActivity::class
|
||||||
} else {
|
} else {
|
||||||
CustomTabActivity::class
|
ExternalAppBrowserActivity::class
|
||||||
}
|
}
|
||||||
intent.setClassName(applicationContext, activityClass.java.name)
|
intent.setClassName(applicationContext, activityClass.java.name)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
intent.action == Intent.ACTION_VIEW || intent.action == Intent.ACTION_SEND -> {
|
tabIntentProcessor.matches(intent) -> {
|
||||||
intent.setClassName(applicationContext, HomeActivity::class.java.name)
|
intent.setClassName(applicationContext, HomeActivity::class.java.name)
|
||||||
// This Intent was launched from history (recent apps). Android will redeliver the
|
// This Intent was launched from history (recent apps). Android will redeliver the
|
||||||
// original Intent (which might be a VIEW intent). However if there's no active browsing
|
// original Intent (which might be a VIEW intent). However if there's no active browsing
|
||||||
|
|
|
@ -36,7 +36,9 @@ class IntentProcessors(
|
||||||
TabIntentProcessor(sessionManager, sessionUseCases.loadUrl, searchUseCases.newTabSearch, isPrivate = true)
|
TabIntentProcessor(sessionManager, sessionUseCases.loadUrl, searchUseCases.newTabSearch, isPrivate = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
val customTabIntentProcessor by lazy {
|
val externalAppIntentProcessors by lazy {
|
||||||
CustomTabIntentProcessor(sessionManager, sessionUseCases.loadUrl, context.resources)
|
listOf(
|
||||||
|
CustomTabIntentProcessor(sessionManager, sessionUseCases.loadUrl, context.resources)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import org.mozilla.fenix.ext.components
|
||||||
/**
|
/**
|
||||||
* A special custom tab for signing into a Firefox Account. The activity is closed once the user is signed in.
|
* A special custom tab for signing into a Firefox Account. The activity is closed once the user is signed in.
|
||||||
*/
|
*/
|
||||||
class AuthCustomTabActivity : CustomTabActivity() {
|
class AuthCustomTabActivity : ExternalAppBrowserActivity() {
|
||||||
|
|
||||||
private val accountStateObserver = object : AccountObserver {
|
private val accountStateObserver = object : AccountObserver {
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -17,7 +17,11 @@ import org.mozilla.fenix.ext.components
|
||||||
import org.mozilla.fenix.theme.CustomTabThemeManager
|
import org.mozilla.fenix.theme.CustomTabThemeManager
|
||||||
import java.security.InvalidParameterException
|
import java.security.InvalidParameterException
|
||||||
|
|
||||||
open class CustomTabActivity : HomeActivity() {
|
/**
|
||||||
|
* Activity that holds the [ExternalAppBrowserFragment] that is launched within an external app,
|
||||||
|
* such as custom tabs and progressive web apps.
|
||||||
|
*/
|
||||||
|
open class ExternalAppBrowserActivity : HomeActivity() {
|
||||||
final override fun getBreadcrumbMessage(destination: NavDestination): String {
|
final override fun getBreadcrumbMessage(destination: NavDestination): String {
|
||||||
val fragmentName = resources.getResourceEntryName(destination.id)
|
val fragmentName = resources.getResourceEntryName(destination.id)
|
||||||
return "Changing to fragment $fragmentName, isCustomTab: true"
|
return "Changing to fragment $fragmentName, isCustomTab: true"
|
|
@ -18,11 +18,11 @@ import org.robolectric.annotation.Config
|
||||||
@ObsoleteCoroutinesApi
|
@ObsoleteCoroutinesApi
|
||||||
@RunWith(RobolectricTestRunner::class)
|
@RunWith(RobolectricTestRunner::class)
|
||||||
@Config(application = TestApplication::class)
|
@Config(application = TestApplication::class)
|
||||||
class CustomTabActivityTest {
|
class ExternalAppBrowserActivityTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun getIntentSource() {
|
fun getIntentSource() {
|
||||||
val activity = CustomTabActivity()
|
val activity = ExternalAppBrowserActivity()
|
||||||
|
|
||||||
val launcherIntent = Intent(Intent.ACTION_MAIN).apply {
|
val launcherIntent = Intent(Intent.ACTION_MAIN).apply {
|
||||||
addCategory(Intent.CATEGORY_LAUNCHER)
|
addCategory(Intent.CATEGORY_LAUNCHER)
|
Loading…
Reference in New Issue