1
0
Fork 0

For #3240 - Create AuthCustomTabActivity to fix dead end on auth

master
ekager 2019-07-03 21:17:16 -07:00 committed by Emily Kager
parent 42eb3ec977
commit c6c9818751
7 changed files with 113 additions and 43 deletions

View File

@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" package="org.mozilla.fenix"> xmlns:tools="http://schemas.android.com/tools"
package="org.mozilla.fenix">
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.RECORD_AUDIO" />
@ -14,53 +15,67 @@
<uses-permission-sdk-23 android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> <uses-permission-sdk-23 android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<application <application
android:allowBackup="true" android:name=".FenixApplication"
android:icon="@mipmap/ic_launcher" android:allowBackup="true"
android:label="@string/app_name" android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round" android:label="@string/app_name"
android:supportsRtl="true" android:roundIcon="@mipmap/ic_launcher_round"
android:name=".FenixApplication" android:supportsRtl="true"
android:theme="@style/NormalTheme" android:theme="@style/NormalTheme"
android:usesCleartextTraffic="true" android:usesCleartextTraffic="true"
tools:ignore="UnusedAttribute"> tools:ignore="UnusedAttribute">
<activity android:name=".HomeActivity" <activity
android:launchMode="singleTask" android:name=".HomeActivity"
android:windowSoftInputMode="adjustResize" 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:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".customtabs.CustomTabActivity" <activity
android:configChanges="keyboard|keyboardHidden|mcc|mnc|orientation|screenSize|locale|layoutDirection|smallestScreenSize|screenLayout" android:name=".customtabs.CustomTabActivity"
android:windowSoftInputMode="adjustResize|stateAlwaysHidden" android:autoRemoveFromRecents="false"
android:exported="false" android:configChanges="keyboard|keyboardHidden|mcc|mnc|orientation|screenSize|locale|layoutDirection|smallestScreenSize|screenLayout"
android:taskAffinity="" android:exported="false"
android:persistableMode="persistNever" android:label="@string/app_name"
android:autoRemoveFromRecents="false" android:persistableMode="persistNever"
android:label="@string/app_name" /> android:taskAffinity=""
android:windowSoftInputMode="adjustResize|stateAlwaysHidden" />
<activity
android:name=".customtabs.AuthCustomTabActivity"
android:autoRemoveFromRecents="false"
android:configChanges="keyboard|keyboardHidden|mcc|mnc|orientation|screenSize|locale|layoutDirection|smallestScreenSize|screenLayout"
android:exported="false"
android:taskAffinity=""
android:windowSoftInputMode="adjustResize|stateAlwaysHidden" />
<activity android:name=".IntentReceiverActivity"> <activity android:name=".IntentReceiverActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" /> <category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" /> <data android:scheme="http" />
<data android:scheme="https" /> <data android:scheme="https" />
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" /> <category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" /> <data android:scheme="http" />
<data android:scheme="https" /> <data android:scheme="https" />
<data android:mimeType="text/html"/> <data android:mimeType="text/html" />
<data android:mimeType="text/plain"/> <data android:mimeType="text/plain" />
<data android:mimeType="application/xhtml+xml"/> <data android:mimeType="application/xhtml+xml" />
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>
@ -76,17 +91,18 @@
<meta-data <meta-data
android:name="com.android.systemui.action_assist_icon" android:name="com.android.systemui.action_assist_icon"
android:resource="@mipmap/ic_launcher"/> android:resource="@mipmap/ic_launcher" />
</activity> </activity>
<activity android:name=".browser.BrowserPerformanceTestActivity" <activity
android:exported="${isRaptorEnabled}" android:name=".browser.BrowserPerformanceTestActivity"
android:enabled="${isRaptorEnabled}"/> android:enabled="${isRaptorEnabled}"
android:exported="${isRaptorEnabled}" />
<service <service
android:name=".customtabs.CustomTabsService" android:name=".customtabs.CustomTabsService"
android:exported="true" android:exported="true"
tools:ignore="ExportedService"> tools:ignore="ExportedService">
<intent-filter> <intent-filter>
<action android:name="android.support.customtabs.action.CustomTabsService" /> <action android:name="android.support.customtabs.action.CustomTabsService" />
</intent-filter> </intent-filter>

View File

@ -10,12 +10,14 @@ import android.os.Bundle
import mozilla.components.browser.session.tab.CustomTabConfig import mozilla.components.browser.session.tab.CustomTabConfig
import mozilla.components.support.utils.SafeIntent import mozilla.components.support.utils.SafeIntent
import org.mozilla.fenix.components.NotificationManager.Companion.RECEIVE_TABS_TAG import org.mozilla.fenix.components.NotificationManager.Companion.RECEIVE_TABS_TAG
import org.mozilla.fenix.customtabs.AuthCustomTabActivity
import org.mozilla.fenix.customtabs.CustomTabActivity import org.mozilla.fenix.customtabs.CustomTabActivity
import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.components
import org.mozilla.fenix.utils.Settings import org.mozilla.fenix.utils.Settings
class IntentReceiverActivity : Activity() { class IntentReceiverActivity : Activity() {
@Suppress("ComplexMethod")
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -34,7 +36,11 @@ class IntentReceiverActivity : Activity() {
val openToBrowser = when { val openToBrowser = when {
CustomTabConfig.isCustomTabIntent(SafeIntent(intent)) -> { CustomTabConfig.isCustomTabIntent(SafeIntent(intent)) -> {
intent.setClassName(applicationContext, CustomTabActivity::class.java.name) intent.setClassName(
applicationContext,
if (intent.hasExtra(getString(R.string.intent_extra_auth))) AuthCustomTabActivity::class.java.name
else CustomTabActivity::class.java.name
)
true true
} }
intent.action == Intent.ACTION_VIEW -> { intent.action == Intent.ACTION_VIEW -> {

View File

@ -46,7 +46,7 @@ class FirefoxAccountsAuthFeature(
// UI to the user. // UI to the user.
// It's possible that the underlying problem will go away by the time the tab actually // It's possible that the underlying problem will go away by the time the tab actually
// loads, resulting in a confusing experience. // loads, resulting in a confusing experience.
val intent = SupportUtils.createCustomTabIntent(context, authUrl) val intent = SupportUtils.createAuthCustomTabIntent(context, authUrl)
context.startActivity(intent) context.startActivity(intent)
} }
} }

View File

@ -0,0 +1,36 @@
package org.mozilla.fenix.customtabs
/* This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.concept.sync.Profile
import mozilla.components.service.fxa.manager.FxaAccountManager
import org.mozilla.fenix.ext.components
class AuthCustomTabActivity : CustomTabActivity() {
private lateinit var accountManager: FxaAccountManager
// Navigate away from this activity when we have successful authentication
private val accountStateObserver = object : AccountObserver {
override fun onAuthenticated(account: OAuthAccount) {
this@AuthCustomTabActivity.finish()
}
override fun onAuthenticationProblems() {}
override fun onError(error: Exception) {}
override fun onLoggedOut() {}
override fun onProfileUpdated(profile: Profile) {}
}
override fun onResume() {
super.onResume()
accountManager = this.components.backgroundServices.accountManager
accountManager.register(accountStateObserver, this, true)
}
}

View File

@ -6,6 +6,6 @@ package org.mozilla.fenix.customtabs
import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.HomeActivity
class CustomTabActivity : HomeActivity() { open class CustomTabActivity : HomeActivity() {
override val isCustomTab = true override val isCustomTab = true
} }

View File

@ -47,8 +47,17 @@ object SupportUtils {
} }
fun createCustomTabIntent(context: Context, url: String) = Intent(Intent.ACTION_VIEW).apply { fun createCustomTabIntent(context: Context, url: String) = Intent(Intent.ACTION_VIEW).apply {
putExtra("android.support.customtabs.extra.TOOLBAR_COLOR", R.attr.foundation.getColorFromAttr(context)) putExtra(context.getString(R.string.intent_extra_toolbar_color), R.attr.foundation.getColorFromAttr(context))
putExtra("android.support.customtabs.extra.SESSION", true) putExtra(context.getString(R.string.intent_extra_session), true)
setClassName(context.applicationContext, IntentReceiverActivity::class.java.name)
data = Uri.parse(url)
setPackage(context.packageName)
}
fun createAuthCustomTabIntent(context: Context, url: String) = Intent(Intent.ACTION_VIEW).apply {
putExtra(context.getString(R.string.intent_extra_toolbar_color), R.attr.foundation.getColorFromAttr(context))
putExtra(context.getString(R.string.intent_extra_session), true)
putExtra(context.getString(R.string.intent_extra_auth), true)
setClassName(context.applicationContext, IntentReceiverActivity::class.java.name) setClassName(context.applicationContext, IntentReceiverActivity::class.java.name)
data = Uri.parse(url) data = Uri.parse(url)
setPackage(context.packageName) setPackage(context.packageName)

View File

@ -14,6 +14,9 @@
%1$s is produced by Mozilla. %1$s is produced by Mozilla.
</string> </string>
<string name="intent_extra_toolbar_color" translatable="false">android.support.customtabs.extra.TOOLBAR_COLOR</string>
<string name="intent_extra_session" translatable="false">android.support.customtabs.extra.SESSION</string>
<string name="intent_extra_auth" translatable="false">support.customtabs.extra.AUTH</string>
<!-- 1.0.1 strings --> <!-- 1.0.1 strings -->
<!-- Bookmark deletion confirmation --> <!-- Bookmark deletion confirmation -->