2019-01-29 20:20:29 +01:00
|
|
|
/* 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/. */
|
|
|
|
|
2019-01-29 21:46:11 +01:00
|
|
|
package org.mozilla.fenix
|
|
|
|
|
|
|
|
import android.app.Activity
|
|
|
|
import android.content.Intent
|
|
|
|
import android.os.Bundle
|
2019-02-28 18:25:37 +01:00
|
|
|
import android.preference.PreferenceManager
|
2019-01-29 21:46:11 +01:00
|
|
|
import mozilla.components.browser.session.tab.CustomTabConfig
|
|
|
|
import mozilla.components.support.utils.SafeIntent
|
2019-01-31 18:58:52 +01:00
|
|
|
import org.mozilla.fenix.customtabs.CustomTabActivity
|
2019-01-29 21:46:11 +01:00
|
|
|
import org.mozilla.fenix.ext.components
|
|
|
|
|
|
|
|
class IntentReceiverActivity : Activity() {
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
|
2019-04-18 17:32:56 +02:00
|
|
|
// 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()
|
|
|
|
|
2019-02-28 18:25:37 +01:00
|
|
|
val isPrivate = PreferenceManager
|
|
|
|
.getDefaultSharedPreferences(this).getBoolean(getString(R.string.pref_key_private_mode), false)
|
|
|
|
|
|
|
|
if (isPrivate) {
|
|
|
|
components.utils.privateIntentProcessor.process(intent)
|
|
|
|
} else {
|
|
|
|
components.utils.intentProcessor.process(intent)
|
|
|
|
}
|
|
|
|
|
2019-04-18 17:32:56 +02:00
|
|
|
val openToBrowser = when {
|
2019-02-06 23:31:39 +01:00
|
|
|
CustomTabConfig.isCustomTabIntent(SafeIntent(intent)) -> {
|
|
|
|
intent.setClassName(applicationContext, CustomTabActivity::class.java.name)
|
|
|
|
true
|
|
|
|
}
|
|
|
|
intent.action == Intent.ACTION_VIEW -> {
|
|
|
|
intent.setClassName(applicationContext, HomeActivity::class.java.name)
|
|
|
|
true
|
|
|
|
}
|
|
|
|
else -> {
|
|
|
|
intent.setClassName(applicationContext, HomeActivity::class.java.name)
|
|
|
|
false
|
|
|
|
}
|
2019-01-29 21:46:11 +01:00
|
|
|
}
|
|
|
|
|
2019-02-06 23:31:39 +01:00
|
|
|
intent.putExtra(HomeActivity.OPEN_TO_BROWSER, openToBrowser)
|
|
|
|
|
2019-01-29 21:46:11 +01:00
|
|
|
startActivity(intent)
|
2019-02-06 23:31:39 +01:00
|
|
|
|
2019-01-29 21:46:11 +01:00
|
|
|
finish()
|
|
|
|
}
|
2019-01-30 17:36:14 +01:00
|
|
|
}
|