Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat Kotlin compiler warnings as errors. #2455

Merged
merged 10 commits into from
Sep 1, 2023
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ android {

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
allWarningsAsErrors = true
freeCompilerArgs += "-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi"
freeCompilerArgs += "-Xjvm-default=all"
jvmTarget = "17"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ open class BrowserActivity : AppCompatActivity() {
}
}

super.onBackPressed()
super.onBackPressedDispatcher.onBackPressed()

removeSessionIfNeeded()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.core.text.HtmlCompat
import mozilla.components.feature.addons.Addon
import mozilla.components.feature.addons.ui.translateDescription
import mozilla.components.feature.addons.ui.translateName
import mozilla.components.support.utils.ext.getParcelableExtraCompat
import org.mozilla.reference.browser.R
import java.text.DateFormat
import java.text.SimpleDateFormat
Expand All @@ -28,7 +29,9 @@ class AddonDetailsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_add_on_details)
val addon = requireNotNull(intent.getParcelableExtra<Addon>("add_on"))
val addon = requireNotNull(
intent.getParcelableExtraCompat("add_on", Addon::class.java),
)
bind(addon)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import mozilla.components.concept.engine.EngineSession
import mozilla.components.concept.engine.EngineView
import mozilla.components.feature.addons.Addon
import mozilla.components.feature.addons.ui.translateName
import mozilla.components.support.utils.ext.getParcelableCompat
import mozilla.components.support.utils.ext.getParcelableExtraCompat
import org.mozilla.reference.browser.R
import org.mozilla.reference.browser.ext.components

Expand All @@ -28,7 +30,10 @@ class AddonSettingsActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_add_on_settings)

val addon = requireNotNull(intent.getParcelableExtra<Addon>("add_on"))
val addon = requireNotNull(
intent.getParcelableExtraCompat("add_on", Addon::class.java),
)

title = addon.translateName(this)

supportFragmentManager
Expand All @@ -51,7 +56,13 @@ class AddonSettingsActivity : AppCompatActivity() {
private lateinit var engineSession: EngineSession

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
optionsPageUrl = requireNotNull(arguments?.getParcelable<Addon>("add_on")?.installedState?.optionsPageUrl)
optionsPageUrl = requireNotNull(
arguments?.getParcelableCompat(
"add_on",
Addon::class.java,
)?.installedState?.optionsPageUrl,
)

engineSession = requireContext().components.core.engine.createSession()

return inflater.inflate(R.layout.fragment_add_on_settings, container, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import kotlinx.coroutines.launch
import mozilla.components.feature.addons.Addon
import mozilla.components.feature.addons.AddonManagerException
import mozilla.components.feature.addons.ui.translateName
import mozilla.components.support.utils.ext.getParcelableExtraCompat
import org.mozilla.reference.browser.R
import org.mozilla.reference.browser.ext.components

Expand All @@ -31,9 +32,12 @@ class InstalledAddonDetailsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_installed_add_on_details)
val addon = requireNotNull(intent.getParcelableExtra<Addon>("add_on")).also {
val addon = requireNotNull(
intent.getParcelableExtraCompat("add_on", Addon::class.java),
).also {
bindUI(it)
}

bindAddon(addon)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import mozilla.components.feature.addons.Addon
import mozilla.components.feature.addons.ui.translateName
import mozilla.components.support.utils.ext.getParcelableExtraCompat
import org.mozilla.reference.browser.R

private const val LEARN_MORE_URL =
Expand All @@ -28,7 +29,10 @@ class PermissionsDetailsActivity : AppCompatActivity(), View.OnClickListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_add_on_permissions)
val addon = requireNotNull(intent.getParcelableExtra<Addon>("add_on"))
val addon = requireNotNull(
intent.getParcelableExtraCompat("add_on", Addon::class.java),
)

title = addon.translateName(this)

bindPermissions(addon)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class WebExtensionActionPopupActivity : AppCompatActivity() {

override fun onWindowRequest(windowRequest: WindowRequest) {
if (windowRequest.type == WindowRequest.Type.CLOSE) {
activity?.onBackPressed()
activity?.onBackPressedDispatcher?.onBackPressed()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import androidx.core.content.ContextCompat
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import mozilla.components.lib.crash.Crash
import mozilla.components.lib.crash.CrashReporter
import mozilla.components.support.utils.ext.registerReceiverCompat
import org.mozilla.reference.browser.BrowserApplication.Companion.NON_FATAL_CRASH_BROADCAST
import org.mozilla.reference.browser.ext.isCrashReportActive

class CrashIntegration(
private val context: Context,
private val crashReporter: CrashReporter,
private val onCrash: (Crash) -> Unit,
) : LifecycleObserver {
) : DefaultLifecycleObserver {

private val receiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
Expand All @@ -36,15 +37,19 @@ class CrashIntegration(
}
}

@OnLifecycleEvent(Lifecycle.Event.ON_START)
fun start() {
override fun onStart(owner: LifecycleOwner) {
super.onStart(owner)
if (isCrashReportActive) {
context.registerReceiver(receiver, IntentFilter(NON_FATAL_CRASH_BROADCAST))
context.registerReceiverCompat(
receiver,
IntentFilter(NON_FATAL_CRASH_BROADCAST),
ContextCompat.RECEIVER_NOT_EXPORTED,
)
}
}

@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
fun stop() {
override fun onStop(owner: LifecycleOwner) {
super.onStop(owner)
if (isCrashReportActive) {
context.unregisterReceiver(receiver)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import mozilla.components.feature.pwa.feature.WebAppSiteControlsFeature
import mozilla.components.support.base.feature.UserInteractionHandler
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
import mozilla.components.support.ktx.android.arch.lifecycle.addObservers
import mozilla.components.support.utils.ext.getParcelableArrayListCompat
import org.mozilla.reference.browser.R
import org.mozilla.reference.browser.ext.requireComponents

Expand All @@ -41,7 +42,7 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), UserInteractionHandler
private val manifest: WebAppManifest?
get() = arguments?.getWebAppManifest()
private val trustedScopes: List<Uri>
get() = arguments?.getParcelableArrayList<Uri>(ARG_TRUSTED_SCOPES).orEmpty()
get() = arguments?.getParcelableArrayListCompat(ARG_TRUSTED_SCOPES, Uri::class.java).orEmpty()

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
return OnPreferenceClickListener {
CoroutineScope(Dispatchers.Main).launch {
requireComponents.backgroundServices.accountManager.logout()
activity?.onBackPressed()
activity?.onBackPressedDispatcher?.onBackPressed()
}
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class CustomColorPreference @JvmOverloads constructor(

override fun onBindViewHolder(holder: PreferenceViewHolder) {
super.onBindViewHolder(holder)
holder?.let {
val title = it.itemView.findViewById(android.R.id.title) as TextView
val summary = it.itemView.findViewById(android.R.id.summary) as TextView
holder.apply {
val title = this.itemView.findViewById(android.R.id.title) as TextView
val summary = this.itemView.findViewById(android.R.id.summary) as TextView
title.setTextColor(titleColor)
summary.setTextColor(summaryColor)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SettingsActivity : AppCompatActivity(), SettingsFragment.ActionBarUpdater

override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
android.R.id.home -> {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
true
}
else -> super.onOptionsItemSelected(item)
Expand All @@ -40,7 +40,7 @@ class SettingsActivity : AppCompatActivity(), SettingsFragment.ActionBarUpdater
if (it is UserInteractionHandler && it.onBackPressed()) {
return
} else {
super.onBackPressed()
super.onBackPressedDispatcher.onBackPressed()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.content.DialogInterface
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.provider.Settings
import android.view.View
import android.widget.EditText
Expand Down Expand Up @@ -219,7 +220,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
Toast.LENGTH_LONG,
).show()

Handler().postDelayed(
Handler(Looper.getMainLooper()).postDelayed(
{
exitProcess(0)
},
Expand Down