1
0
Fork 0

For #778 - Rename CustomTabActivity

master
Tiger Oakes 2019-09-19 09:12:42 -07:00 committed by Emily Kager
parent e9fd6892ba
commit 699eacab39
6 changed files with 34 additions and 21 deletions

View File

@ -66,7 +66,7 @@
</activity>
<activity
android:name=".customtabs.CustomTabActivity"
android:name=".customtabs.ExternalAppBrowserActivity"
android:autoRemoveFromRecents="false"
android:configChanges="keyboard|keyboardHidden|mcc|mnc|orientation|screenSize|locale|layoutDirection|smallestScreenSize|screenLayout"
android:exported="false"

View File

@ -11,22 +11,25 @@ import android.speech.RecognizerIntent
import androidx.annotation.VisibleForTesting
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
import mozilla.components.feature.intent.processing.TabIntentProcessor
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.customtabs.AuthCustomTabActivity
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.metrics
import org.mozilla.fenix.ext.settings
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() {
// Holds the intent that initially started this activity
// so that it can persist through the speech activity.
private var previousIntent: Intent? = null
@Suppress("ComplexMethod")
@VisibleForTesting
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -42,20 +45,21 @@ class IntentReceiverActivity : Activity() {
// the HomeActivity.
val intent = intent?.let { Intent(intent) } ?: Intent()
val intentProcessor = if (Settings.getInstance(applicationContext).alwaysOpenInPrivateMode)
components.intentProcessors.privateIntentProcessor else components.intentProcessors.intentProcessor
val tabIntentProcessor = if (settings().alwaysOpenInPrivateMode) {
components.intentProcessors.privateIntentProcessor
} else {
components.intentProcessors.intentProcessor
}
val intentProcessors = listOf(
components.intentProcessors.customTabIntentProcessor,
intentProcessor
)
val intentProcessors =
components.intentProcessors.externalAppIntentProcessors + tabIntentProcessor
if (intent.getBooleanExtra(SPEECH_PROCESSING, false)) {
previousIntent = intent
displaySpeechRecognizer()
} else {
intentProcessors.any { it.process(intent) }
setIntentActivity(intent)
setIntentActivity(intent, tabIntentProcessor)
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 {
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
val activityClass = if (intent.hasExtra(EXTRA_AUTH_CUSTOM_TAB)) {
AuthCustomTabActivity::class
} else {
CustomTabActivity::class
ExternalAppBrowserActivity::class
}
intent.setClassName(applicationContext, activityClass.java.name)
true
}
intent.action == Intent.ACTION_VIEW || intent.action == Intent.ACTION_SEND -> {
tabIntentProcessor.matches(intent) -> {
intent.setClassName(applicationContext, HomeActivity::class.java.name)
// 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

View File

@ -36,7 +36,9 @@ class IntentProcessors(
TabIntentProcessor(sessionManager, sessionUseCases.loadUrl, searchUseCases.newTabSearch, isPrivate = true)
}
val customTabIntentProcessor by lazy {
CustomTabIntentProcessor(sessionManager, sessionUseCases.loadUrl, context.resources)
val externalAppIntentProcessors by lazy {
listOf(
CustomTabIntentProcessor(sessionManager, sessionUseCases.loadUrl, context.resources)
)
}
}

View File

@ -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.
*/
class AuthCustomTabActivity : CustomTabActivity() {
class AuthCustomTabActivity : ExternalAppBrowserActivity() {
private val accountStateObserver = object : AccountObserver {
/**

View File

@ -17,7 +17,11 @@ import org.mozilla.fenix.ext.components
import org.mozilla.fenix.theme.CustomTabThemeManager
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 {
val fragmentName = resources.getResourceEntryName(destination.id)
return "Changing to fragment $fragmentName, isCustomTab: true"

View File

@ -18,11 +18,11 @@ import org.robolectric.annotation.Config
@ObsoleteCoroutinesApi
@RunWith(RobolectricTestRunner::class)
@Config(application = TestApplication::class)
class CustomTabActivityTest {
class ExternalAppBrowserActivityTest {
@Test
fun getIntentSource() {
val activity = CustomTabActivity()
val activity = ExternalAppBrowserActivity()
val launcherIntent = Intent(Intent.ACTION_MAIN).apply {
addCategory(Intent.CATEGORY_LAUNCHER)