Merge #5613
5613: Fixes #5225 - Intent receiver cleanup r=rocketsroger a=NotWoods ### Pull Request checklist <!-- Before submitting the PR, please address each item --> - [x] **Quality**: This PR builds and passes detekt/ktlint checks (A pre-push hook is recommended) - [ ] **Tests**: This PR includes thorough tests or an explanation of why it does not - [ ] **Screenshots**: This PR includes screenshots or GIFs of the changes made or an explanation of why it does not - [x] **Accessibility**: The code in this PR follows [accessibility best practices](https://github.com/mozilla-mobile/shared-docs/blob/master/android/accessibility_guide.md) or does not include any user facing features ### After merge - [ ] **Milestone**: Make sure issues finished by this pull request are added to the [milestone](https://github.com/mozilla-mobile/fenix/milestones) of the version currently in development. ### To download an APK when reviewing a PR: 1. click on Show All Checks, 2. click Details next to "Taskcluster (pull_request)" after it appears and then finishes with a green checkmark, 3. click on the "Fenix - assemble" task, then click "Run Artifacts". 4. the APK links should be on the left side of the screen, named for each CPU architecture Co-authored-by: Tiger Oakes <toakes@mozilla.com>nightly-build-test
commit
3aa06000f9
@ -0,0 +1,39 @@
|
||||
/* 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/. */
|
||||
|
||||
package org.mozilla.fenix.settings.account
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.launch
|
||||
import org.mozilla.fenix.HomeActivity
|
||||
import org.mozilla.fenix.ext.components
|
||||
|
||||
/**
|
||||
* Processes incoming intents and sends them to the corresponding activity.
|
||||
*/
|
||||
class AuthIntentReceiverActivity : Activity() {
|
||||
|
||||
@VisibleForTesting
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
MainScope().launch {
|
||||
// The intent property is nullable, but the rest of the code below
|
||||
// assumes it is not. If it's null, then we make a new one and open
|
||||
// the HomeActivity.
|
||||
val intent = intent?.let { Intent(intent) } ?: Intent()
|
||||
components.intentProcessors.customTabIntentProcessor.process(intent)
|
||||
intent.setClassName(applicationContext, AuthCustomTabActivity::class.java.name)
|
||||
intent.putExtra(HomeActivity.OPEN_TO_BROWSER, true)
|
||||
|
||||
startActivity(intent)
|
||||
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/* 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/. */
|
||||
|
||||
package org.mozilla.fenix.shortcut
|
||||
|
||||
import android.content.Intent
|
||||
import android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
import mozilla.components.feature.intent.processing.IntentProcessor
|
||||
import mozilla.components.support.utils.SafeIntent
|
||||
import org.mozilla.fenix.HomeActivity
|
||||
import org.mozilla.fenix.home.intent.StartSearchIntentProcessor
|
||||
|
||||
class NewTabShortcutIntentProcessor : IntentProcessor {
|
||||
|
||||
/**
|
||||
* Returns true if this intent processor will handle the intent.
|
||||
*/
|
||||
override fun matches(intent: Intent): Boolean {
|
||||
val safeIntent = SafeIntent(intent)
|
||||
return safeIntent.action == ACTION_OPEN_TAB || safeIntent.action == ACTION_OPEN_PRIVATE_TAB
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the given [Intent].
|
||||
*
|
||||
* @param intent The intent to process.
|
||||
* @return True if the intent was processed, otherwise false.
|
||||
*/
|
||||
override suspend fun process(intent: Intent): Boolean {
|
||||
val safeIntent = SafeIntent(intent)
|
||||
val (searchExtra, startPrivateMode) = when (safeIntent.action) {
|
||||
ACTION_OPEN_TAB -> StartSearchIntentProcessor.STATIC_SHORTCUT_NEW_TAB to false
|
||||
ACTION_OPEN_PRIVATE_TAB -> StartSearchIntentProcessor.STATIC_SHORTCUT_NEW_PRIVATE_TAB to true
|
||||
else -> return false
|
||||
}
|
||||
|
||||
intent.putExtra(HomeActivity.OPEN_TO_SEARCH, searchExtra)
|
||||
intent.putExtra(HomeActivity.PRIVATE_BROWSING_MODE, startPrivateMode)
|
||||
intent.flags = intent.flags or FLAG_ACTIVITY_NEW_TASK or FLAG_ACTIVITY_CLEAR_TASK
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val ACTION_OPEN_TAB = "org.mozilla.fenix.OPEN_TAB"
|
||||
const val ACTION_OPEN_PRIVATE_TAB = "org.mozilla.fenix.OPEN_PRIVATE_TAB"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue