From 08556f4820419edd849b665dd53cb86d9c9cfa56 Mon Sep 17 00:00:00 2001 From: t-p-white Date: Thu, 25 Jan 2024 11:00:14 +0000 Subject: [PATCH] Bug 1876481 - Updated `HomeActivity` variables & funcs with the necessary visibility modifiers to enforce constraints. --- .../java/org/mozilla/fenix/HomeActivity.kt | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/fenix/app/src/main/java/org/mozilla/fenix/HomeActivity.kt b/fenix/app/src/main/java/org/mozilla/fenix/HomeActivity.kt index 773c4e95170e..547f83d040fc 100644 --- a/fenix/app/src/main/java/org/mozilla/fenix/HomeActivity.kt +++ b/fenix/app/src/main/java/org/mozilla/fenix/HomeActivity.kt @@ -524,7 +524,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { components.core.store.dispatch(SearchAction.RefreshSearchEnginesAction) } - override fun onStart() { + final override fun onStart() { // DO NOT MOVE ANYTHING ABOVE THIS getProfilerTime CALL. val startProfilerTime = components.core.engine.profiler?.getProfilerTime() @@ -544,7 +544,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { ) // DO NOT MOVE ANYTHING BELOW THIS addMarker CALL. } - override fun onStop() { + final override fun onStop() { super.onStop() // Diagnostic breadcrumb for "Display already aquired" crash: @@ -600,6 +600,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { outContent?.webUri = currentTabUrl?.let { Uri.parse(it) } } + @CallSuper override fun onDestroy() { super.onDestroy() @@ -623,7 +624,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { } } - override fun onConfigurationChanged(newConfig: Configuration) { + final override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newConfig) // Diagnostic breadcrumb for "Display already aquired" crash: @@ -633,7 +634,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { ) } - override fun recreate() { + final override fun recreate() { // Diagnostic breadcrumb for "Display already aquired" crash: // https://github.com/mozilla-mobile/android-components/issues/7960 breadcrumb( @@ -718,12 +719,12 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { else -> super.onCreateView(parent, name, context, attrs) } - override fun onActionModeStarted(mode: ActionMode?) { + final override fun onActionModeStarted(mode: ActionMode?) { actionMode = mode super.onActionModeStarted(mode) } - override fun onActionModeFinished(mode: ActionMode?) { + final override fun onActionModeFinished(mode: ActionMode?) { actionMode = null super.onActionModeFinished(mode) } @@ -790,7 +791,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { return false } - override fun dispatchTouchEvent(ev: MotionEvent?): Boolean { + final override fun dispatchTouchEvent(ev: MotionEvent?): Boolean { ProfilerMarkers.addForDispatchTouchEvent(components.core.engine.profiler, ev) return super.dispatchTouchEvent(ev) } @@ -851,6 +852,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { * private mode directly before the content view is created. Returns the mode set by the intent * otherwise falls back to the last known mode. */ + @VisibleForTesting internal fun getModeFromIntentOrLastKnown(intent: Intent?): BrowsingMode { intent?.toSafeIntent()?.let { if (it.hasExtra(PRIVATE_BROWSING_MODE)) { @@ -903,7 +905,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { * Returns the [supportActionBar], inflating it if necessary. * Everyone should call this instead of supportActionBar. */ - override fun getSupportActionBarAndInflateIfNecessary(): ActionBar { + final override fun getSupportActionBarAndInflateIfNecessary(): ActionBar { if (!isToolbarInflated) { navigationToolbar = binding.navigationToolbarStub.inflate() as Toolbar @@ -918,7 +920,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { } @Suppress("SpreadOperator") - fun setupNavigationToolbar(vararg topLevelDestinationIds: Int) { + private fun setupNavigationToolbar(vararg topLevelDestinationIds: Int) { NavigationUI.setupWithNavController( navigationToolbar, navHost.navController, @@ -1101,13 +1103,13 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { navController.navigate(NavGraphDirections.actionStartupHome()) } - override fun attachBaseContext(base: Context) { + final override fun attachBaseContext(base: Context) { base.components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) { super.attachBaseContext(base) } } - override fun getSystemService(name: String): Any? { + final override fun getSystemService(name: String): Any? { // Issue #17759 had a crash with the PerformanceInflater.kt on Android 5.0 and 5.1 // when using the TimePicker. Since the inflater was created for performance monitoring // purposes and that we test on new android versions, this means that any difference in @@ -1121,7 +1123,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { return super.getSystemService(name) } - protected open fun createBrowsingModeManager(initialMode: BrowsingMode): BrowsingModeManager { + private fun createBrowsingModeManager(initialMode: BrowsingMode): BrowsingModeManager { return DefaultBrowsingModeManager(initialMode, components.settings) { newMode -> updateSecureWindowFlags(newMode) themeManager.currentTheme = newMode @@ -1138,7 +1140,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { } } - protected open fun createThemeManager(): ThemeManager { + private fun createThemeManager(): ThemeManager { return DefaultThemeManager(browsingModeManager.mode, this) } @@ -1189,7 +1191,8 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { * Indicates if the user should be redirected to the [BrowserFragment] or to the [HomeFragment], * links from an external apps should always opened in the [BrowserFragment]. */ - fun shouldStartOnHome(intent: Intent? = this.intent): Boolean { + @VisibleForTesting + internal fun shouldStartOnHome(intent: Intent? = this.intent): Boolean { return components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) { // We only want to open on home when users tap the app, // we want to ignore other cases when the app gets open by users clicking on links. @@ -1269,6 +1272,6 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { // PWA must have been used within last 30 days to be considered "recently used" for the // telemetry purposes. - const val PWA_RECENTLY_USED_THRESHOLD = DateUtils.DAY_IN_MILLIS * 30L + private const val PWA_RECENTLY_USED_THRESHOLD = DateUtils.DAY_IN_MILLIS * 30L } }