Skip to content

Commit

Permalink
Issue mozilla-mobile#11864: Enable UnusedPrivateMember rule for detekt
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielluong committed Mar 22, 2022
1 parent a5f7201 commit 52ba006
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -796,17 +796,6 @@ class GeckoEngineSession(
}
}

private fun recoverGeckoSession() {
// Recover the GeckoSession after the process getting killed or crashing. We create a
// new underlying GeckoSession.
// Eventually we may be able to re-use the same GeckoSession by re-opening it. However
// that seems to have caused issues:
// https://github.com/mozilla-mobile/android-components/issues/3640

geckoSession.close()
createGeckoSession()
}

override fun onFullScreen(session: GeckoSession, fullScreen: Boolean) {
notifyObservers { onFullScreenChange(fullScreen) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,6 @@ private fun JsonReader.toBundle(): Bundle {
return bundle
}

private fun shouldSerialize(value: Any?): Boolean {
// For now we only persist primitive types
// https://github.com/mozilla-mobile/android-components/issues/279
return when (value) {
is Number -> true
is Boolean -> true
is String -> true
else -> false
}
}

private fun JSONObject.toBundle(): Bundle {
val bundle = Bundle()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ internal fun mozilla.appservices.places.uniffi.VisitTransition.into() = when (th
mozilla.appservices.places.uniffi.VisitTransition.FRAMED_LINK -> VisitType.FRAMED_LINK
}

private val intToVisitType: Map<Int, VisitType> = VisitType.values().associateBy(VisitType::type)

internal fun mozilla.appservices.places.uniffi.HistoryVisitInfo.into(): VisitInfo {
return VisitInfo(
url = this.url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package mozilla.components.feature.accounts

import android.content.Context
import androidx.annotation.VisibleForTesting
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -51,15 +50,13 @@ enum class FxaCapability {
* For more information https://github.com/mozilla/fxa/blob/master/packages/fxa-content-server/docs/relier-communication-protocols/fx-webchannel.md
* This feature uses a web extension to communicate with FxA Web Content.
*
* @property context a reference to the context.
* @property customTabSessionId optional custom tab session ID, if feature is being used with a custom tab.
* @property runtime the [WebExtensionRuntime] (e.g the browser engine) to use.
* @property store a reference to the application's [BrowserStore].
* @property accountManager a reference to application's [FxaAccountManager].
* @property fxaCapabilities a set of [FxaCapability] that client supports.
*/
class FxaWebChannelFeature(
private val context: Context,
private val customTabSessionId: String?,
private val runtime: WebExtensionRuntime,
private val store: BrowserStore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import mozilla.components.support.test.any
import mozilla.components.support.test.argumentCaptor
import mozilla.components.support.test.eq
import mozilla.components.support.test.mock
import mozilla.components.support.test.robolectric.testContext
import mozilla.components.support.test.whenever
import mozilla.components.support.webextensions.WebExtensionController
import org.json.JSONException
Expand Down Expand Up @@ -59,7 +58,7 @@ class FxaWebChannelFeatureTest {
val store: BrowserStore = mock()
val accountManager: FxaAccountManager = mock()
val serverConfig: ServerConfig = mock()
val webchannelFeature = FxaWebChannelFeature(testContext, null, engine, store, accountManager, serverConfig)
val webchannelFeature = FxaWebChannelFeature(null, engine, store, accountManager, serverConfig)
webchannelFeature.start()

val onSuccess = argumentCaptor<((WebExtension) -> Unit)>()
Expand Down Expand Up @@ -90,7 +89,7 @@ class FxaWebChannelFeatureTest {
val accountManager: FxaAccountManager = mock()
val serverConfig: ServerConfig = mock()
val controller: WebExtensionController = mock()
val webchannelFeature = FxaWebChannelFeature(testContext, null, engine, store, accountManager, serverConfig)
val webchannelFeature = FxaWebChannelFeature(null, engine, store, accountManager, serverConfig)

webchannelFeature.extensionController = controller

Expand All @@ -106,7 +105,7 @@ class FxaWebChannelFeatureTest {
val accountManager: FxaAccountManager = mock()
val serverConfig: ServerConfig = mock()
val controller: WebExtensionController = mock()
val webchannelFeature = FxaWebChannelFeature(testContext, null, engine, store, accountManager, serverConfig)
val webchannelFeature = FxaWebChannelFeature(null, engine, store, accountManager, serverConfig)

whenever(serverConfig.contentUrl).thenReturn("https://foo.bar")
webchannelFeature.extensionController = controller
Expand Down Expand Up @@ -134,7 +133,7 @@ class FxaWebChannelFeatureTest {
val accountManager: FxaAccountManager = mock()
val serverConfig: ServerConfig = mock()
val controller: WebExtensionController = mock()
val webchannelFeature = FxaWebChannelFeature(testContext, null, engine, store, accountManager, serverConfig)
val webchannelFeature = FxaWebChannelFeature(null, engine, store, accountManager, serverConfig)

whenever(serverConfig.contentUrl).thenReturn(Server.RELEASE.contentUrl)
webchannelFeature.extensionController = controller
Expand Down Expand Up @@ -163,7 +162,7 @@ class FxaWebChannelFeatureTest {
BrowserStore(initialState = BrowserState(tabs = listOf(tab), selectedTabId = tab.id))
)

val webchannelFeature = FxaWebChannelFeature(testContext, null, engine, store, accountManager, serverConfig)
val webchannelFeature = FxaWebChannelFeature(null, engine, store, accountManager, serverConfig)
webchannelFeature.extensionController = controller

webchannelFeature.start()
Expand Down Expand Up @@ -825,6 +824,6 @@ class FxaWebChannelFeatureTest {
whenever(port.senderUrl()).thenReturn("https://foo.bar/email")
whenever(serverConfig.contentUrl).thenReturn("https://foo.bar")

return spy(FxaWebChannelFeature(testContext, null, mock(), store, accountManager, serverConfig, fxaCapabilities))
return spy(FxaWebChannelFeature(null, mock(), store, accountManager, serverConfig, fxaCapabilities))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import mozilla.components.browser.state.state.SessionState
import mozilla.components.browser.state.state.externalPackage
import mozilla.components.concept.engine.EngineSession.LoadUrlFlags
import mozilla.components.feature.search.SearchUseCases
import mozilla.components.feature.session.SessionUseCases
import mozilla.components.feature.tabs.TabsUseCases
import mozilla.components.support.ktx.kotlin.isUrl
import mozilla.components.support.ktx.kotlin.toNormalizedUrl
Expand All @@ -28,14 +27,12 @@ import mozilla.components.support.utils.WebURLFinder
* Processor for intents which should trigger session-related actions.
*
* @property tabsUseCases An instance of [TabsUseCases] used to open new tabs.
* @property loadUrlUseCase A reference to [SessionUseCases.DefaultLoadUrlUseCase] used to load URLs.
* @property newTabSearchUseCase A reference to [SearchUseCases.NewTabSearchUseCase] to be used for
* ACTION_SEND intents if the provided text is not a URL.
* @property isPrivate Whether a processed intent should open a new tab as private
*/
class TabIntentProcessor(
private val tabsUseCases: TabsUseCases,
private val loadUrlUseCase: SessionUseCases.DefaultLoadUrlUseCase,
private val newTabSearchUseCase: SearchUseCases.NewTabSearchUseCase,
private val isPrivate: Boolean = false
) : IntentProcessor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ class TabIntentProcessorTest {

@Test
fun `open or select tab on ACTION_VIEW intent`() {
val useCases = SessionUseCases(store)
val handler = TabIntentProcessor(TabsUseCases(store), useCases.loadUrl, searchUseCases.newTabSearch)
val handler = TabIntentProcessor(TabsUseCases(store), searchUseCases.newTabSearch)
val intent: Intent = mock()
whenever(intent.action).thenReturn(Intent.ACTION_VIEW)
whenever(intent.dataString).thenReturn("http://mozilla.org")
Expand Down Expand Up @@ -140,8 +139,7 @@ class TabIntentProcessorTest {

@Test
fun `open or select tab on ACTION_MAIN intent`() {
val useCases = SessionUseCases(store)
val handler = TabIntentProcessor(TabsUseCases(store), useCases.loadUrl, searchUseCases.newTabSearch)
val handler = TabIntentProcessor(TabsUseCases(store), searchUseCases.newTabSearch)
val intent: Intent = mock()
whenever(intent.action).thenReturn(Intent.ACTION_MAIN)
whenever(intent.dataString).thenReturn("https://mozilla.org")
Expand Down Expand Up @@ -176,8 +174,7 @@ class TabIntentProcessorTest {

@Test
fun `open or select tab on ACTION_NDEF_DISCOVERED intent`() {
val useCases = SessionUseCases(store)
val handler = TabIntentProcessor(TabsUseCases(store), useCases.loadUrl, searchUseCases.newTabSearch)
val handler = TabIntentProcessor(TabsUseCases(store), searchUseCases.newTabSearch)
val intent: Intent = mock()
whenever(intent.action).thenReturn(ACTION_NDEF_DISCOVERED)
whenever(intent.dataString).thenReturn("https://mozilla.org")
Expand Down Expand Up @@ -211,7 +208,7 @@ class TabIntentProcessorTest {

@Test
fun `open tab on ACTION_SEND intent`() {
val handler = TabIntentProcessor(TabsUseCases(store), sessionUseCases.loadUrl, searchUseCases.newTabSearch)
val handler = TabIntentProcessor(TabsUseCases(store), searchUseCases.newTabSearch)

val intent: Intent = mock()
whenever(intent.action).thenReturn(Intent.ACTION_SEND)
Expand Down Expand Up @@ -263,7 +260,7 @@ class TabIntentProcessorTest {

@Test
fun `open tab and trigger search on ACTION_SEND if text is not a URL`() {
val handler = TabIntentProcessor(TabsUseCases(store), sessionUseCases.loadUrl, searchUseCases.newTabSearch)
val handler = TabIntentProcessor(TabsUseCases(store), searchUseCases.newTabSearch)

val searchTerms = "mozilla android"
val searchUrl = "https://localhost/?q=mozilla%20android"
Expand All @@ -284,7 +281,7 @@ class TabIntentProcessorTest {

@Test
fun `nothing happens on ACTION_SEND if no text is provided`() {
val handler = TabIntentProcessor(TabsUseCases(store), sessionUseCases.loadUrl, searchUseCases.newTabSearch)
val handler = TabIntentProcessor(TabsUseCases(store), searchUseCases.newTabSearch)

val intent: Intent = mock()
whenever(intent.action).thenReturn(Intent.ACTION_SEND)
Expand All @@ -296,7 +293,7 @@ class TabIntentProcessorTest {

@Test
fun `nothing happens on ACTION_SEARCH if text is empty`() {
val handler = TabIntentProcessor(TabsUseCases(store), sessionUseCases.loadUrl, searchUseCases.newTabSearch)
val handler = TabIntentProcessor(TabsUseCases(store), searchUseCases.newTabSearch)

val intent: Intent = mock()
whenever(intent.action).thenReturn(Intent.ACTION_SEARCH)
Expand All @@ -308,7 +305,7 @@ class TabIntentProcessorTest {

@Test
fun `open tab on ACTION_SEARCH intent`() {
val handler = TabIntentProcessor(TabsUseCases(store), sessionUseCases.loadUrl, searchUseCases.newTabSearch)
val handler = TabIntentProcessor(TabsUseCases(store), searchUseCases.newTabSearch)

val intent: Intent = mock()
whenever(intent.action).thenReturn(Intent.ACTION_SEARCH)
Expand All @@ -334,7 +331,7 @@ class TabIntentProcessorTest {

@Test
fun `open tab and trigger search on ACTION_SEARCH intent if text is not a URL`() {
val handler = TabIntentProcessor(TabsUseCases(store), sessionUseCases.loadUrl, searchUseCases.newTabSearch)
val handler = TabIntentProcessor(TabsUseCases(store), searchUseCases.newTabSearch)

val searchTerms = "mozilla android"
val searchUrl = "https://localhost/?q=mozilla%20android"
Expand All @@ -355,7 +352,7 @@ class TabIntentProcessorTest {

@Test
fun `nothing happens on ACTION_WEB_SEARCH if text is empty`() {
val handler = TabIntentProcessor(TabsUseCases(store), sessionUseCases.loadUrl, searchUseCases.newTabSearch)
val handler = TabIntentProcessor(TabsUseCases(store), searchUseCases.newTabSearch)

val intent: Intent = mock()
whenever(intent.action).thenReturn(Intent.ACTION_WEB_SEARCH)
Expand All @@ -367,7 +364,7 @@ class TabIntentProcessorTest {

@Test
fun `open tab on ACTION_WEB_SEARCH intent`() {
val handler = TabIntentProcessor(TabsUseCases(store), sessionUseCases.loadUrl, searchUseCases.newTabSearch)
val handler = TabIntentProcessor(TabsUseCases(store), searchUseCases.newTabSearch)

val intent: Intent = mock()
whenever(intent.action).thenReturn(Intent.ACTION_WEB_SEARCH)
Expand All @@ -392,7 +389,7 @@ class TabIntentProcessorTest {

@Test
fun `open tab and trigger search on ACTION_WEB_SEARCH intent if text is not a URL`() {
val handler = TabIntentProcessor(TabsUseCases(store), sessionUseCases.loadUrl, searchUseCases.newTabSearch)
val handler = TabIntentProcessor(TabsUseCases(store), searchUseCases.newTabSearch)

val searchTerms = "mozilla android"
val searchUrl = "https://localhost/?q=mozilla%20android"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import mozilla.components.concept.storage.Login
import mozilla.components.concept.storage.LoginEntry
import mozilla.components.concept.storage.LoginValidationDelegate.Result
import mozilla.components.feature.prompts.R
Expand All @@ -45,7 +44,6 @@ import mozilla.components.support.base.log.logger.Logger
import mozilla.components.support.ktx.android.content.res.resolveAttribute
import mozilla.components.support.ktx.android.view.hideKeyboard
import mozilla.components.support.ktx.android.view.toScope
import java.util.concurrent.CopyOnWriteArrayList
import kotlin.reflect.KProperty
import com.google.android.material.R as MaterialR

Expand Down Expand Up @@ -86,10 +84,6 @@ internal class SaveLoginDialogFragment : PromptDialogFragment() {

private var validateStateUpdate: Job? = null

// List of potential dupes ignoring username. We could potentially both read and write this list
// from different threads, so we are using a copy-on-write list.
private var potentialDupesList: CopyOnWriteArrayList<Login>? = null

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return BottomSheetDialog(requireContext(), R.style.MozDialogStyle).apply {
setCancelable(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ internal class MonthAndYearPicker @JvmOverloads constructor(

private const val SPEED_MONTH_SPINNER = 200L
private const val SPEED_YEAR_SPINNER = 100L
private const val DEFAULT_VALUE = -1

@VisibleForTesting
internal const val DEFAULT_MAX_YEAR = 9999
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.content.Context
import androidx.paging.DataSource
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import mozilla.components.browser.session.storage.serialize.BrowserStateReader
import mozilla.components.browser.session.storage.serialize.BrowserStateWriter
import mozilla.components.browser.state.state.TabSessionState
import mozilla.components.feature.tab.collections.adapter.TabAdapter
Expand All @@ -25,7 +24,6 @@ import java.util.UUID
*/
class TabCollectionStorage(
context: Context,
private val reader: BrowserStateReader = BrowserStateReader(),
private val writer: BrowserStateWriter = BrowserStateWriter(),
private val filesDir: File = context.filesDir
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ open class InlineAutocompleteEditText @JvmOverloads constructor(
data class AutocompleteResult(
val text: String,
val source: String,
val totalItems: Int,
private val textFormatter: TextFormatter? = null
val totalItems: Int
) {
fun startsWith(text: String): Boolean = this.text.startsWith(text)
}
Expand Down
2 changes: 1 addition & 1 deletion config/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ style:
UnusedPrivateClass:
active: true
UnusedPrivateMember:
active: false
active: true
allowedNames: '(_|ignored|expected|serialVersionUID)'
UseAnyOrNoneInsteadOfFind:
active: false
Expand Down
6 changes: 6 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ permalink: /changelog/
* [Gecko](https://github.com/mozilla-mobile/android-components/blob/main/buildSrc/src/main/java/Gecko.kt)
* [Configuration](https://github.com/mozilla-mobile/android-components/blob/main/.config.yml)

* **feature-autofill**
* ⚠️ **This is a breaking change**: Removed unused `context` parameter in `FxaWebChannelFeature`. [#11864](https://github.com/mozilla-mobile/android-components/pull/11864).

* **feature-autofill**
* 🚒 Bug fixed [issue #11869](https://github.com/mozilla-mobile/android-components/issues/11869) - Fix regression causing autofill to not work after unlocking the app doing the autofill or after accepting that the authenticity of the autofill target could not be verified.

* **feature-contextmenu**
* 🚒 Bug fixed [issue #11829](https://github.com/mozilla-mobile/android-components/pull/11830) - To make the additional note visible in landscape mode.

* **feature-intent**
* ⚠️ **This is a breaking change**: Removed unused `loadUrlUseCase` parameter in `TabIntentProcessor`. [#11864](https://github.com/mozilla-mobile/android-components/pull/11864).

* **browser-toolbar**
* Removed reflective access to non-public SDK APIs controlling the sensitivity of the gesture detector following which sparingly and for very short time a pinch/spread to zoom gesture might be identified first as a scroll gesture and move the toolbar a little before snapping to it's original position.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ open class DefaultComponents(private val applicationContext: Context) {

// Intent
val tabIntentProcessor by lazy {
TabIntentProcessor(tabsUseCases, sessionUseCases.loadUrl, searchUseCases.newTabSearch)
TabIntentProcessor(tabsUseCases, searchUseCases.newTabSearch)
}
val externalAppIntentProcessors by lazy {
listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ import org.mozilla.samples.sync.databinding.ActivityMainBinding
import java.lang.Exception
import kotlin.coroutines.CoroutineContext

private const val PASSWORDS_ENCRYPTION_KEY_STRENGTH = 256

class MainActivity :
AppCompatActivity(),
LoginFragment.OnLoginCompleteListener,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,13 +461,16 @@ class ToolbarActivity : AppCompatActivity() {
private var back = true

private fun canGoForward(): Boolean = forward
@Suppress("UnusedPrivateMember")
private fun canGoBack(): Boolean = back

@Suppress("UnusedPrivateMember")
private fun goBack() {
back = !(forward && back)
forward = true
}

@Suppress("UnusedPrivateMember")
private fun goForward() {
forward = !(back && forward)
back = true
Expand Down Expand Up @@ -522,7 +525,6 @@ class ToolbarActivity : AppCompatActivity() {

companion object {
private val PROGRESS_RANGE = 0..100
private const val SPACING_SIZE_DP = 128
private const val RELOAD_STEP_SIZE = 5
}
}

0 comments on commit 52ba006

Please sign in to comment.