From cf15469947491ac61cdf857f22cadc21e57c38a7 Mon Sep 17 00:00:00 2001 From: TheScarastic Date: Thu, 16 Jun 2022 18:02:37 +0530 Subject: advanced-privacy: fix leaks found via leakcanary --- .../features/dashboard/DashboardFragment.kt | 21 +++++++++++----- .../internetprivacy/InternetPrivacyFragment.kt | 11 +++++++-- .../features/location/FakeLocationFragment.kt | 10 ++++++-- .../features/trackers/TrackersFragment.kt | 28 +++++++++++++++------- .../trackers/apptrackers/AppTrackersFragment.kt | 11 +++++++-- 5 files changed, 61 insertions(+), 20 deletions(-) (limited to 'app/src/main/java/foundation/e/privacycentralapp') diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt index 398a594..323f1bb 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/dashboard/DashboardFragment.kt @@ -73,8 +73,10 @@ class DashboardFragment : viewModelProviderFactoryOf { dependencyContainer.dashBoardViewModelFactory.create() } } - private lateinit var graphHolder: GraphHolder - private lateinit var binding: FragmentDashboardBinding + private var graphHolder: GraphHolder? = null + + private var _binding: FragmentDashboardBinding? = null + private val binding get() = _binding!! private var qpDisabledSnackbar: Snackbar? = null @@ -142,7 +144,7 @@ class DashboardFragment : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - binding = FragmentDashboardBinding.bind(view) + _binding = FragmentDashboardBinding.bind(view) graphHolder = GraphHolder(binding.graph, requireContext()) @@ -265,8 +267,8 @@ class DashboardFragment : binding.graphLegend.isVisible = true binding.leakingAppButton.isVisible = true binding.graphEmpty.isVisible = false - state.dayStatistics?.let { graphHolder.data = it } - state.dayLabels?.let { graphHolder.labels = it } + state.dayStatistics?.let { graphHolder?.data = it } + state.dayLabels?.let { graphHolder?.labels = it } binding.graphLegend.text = Html.fromHtml( getString( @@ -278,7 +280,7 @@ class DashboardFragment : highlightIndexOnStart?.let { binding.graph.post { - graphHolder.highlightIndex(it) + graphHolder?.highlightIndex(it) } highlightIndexOnStart = null } @@ -307,4 +309,11 @@ class DashboardFragment : } override fun actions(): Flow = viewModel.actions + + override fun onDestroyView() { + super.onDestroyView() + qpDisabledSnackbar = null + graphHolder = null + _binding = null + } } diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyFragment.kt index 2452d33..59d30c8 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyFragment.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/internetprivacy/InternetPrivacyFragment.kt @@ -56,7 +56,8 @@ class InternetPrivacyFragment : viewModelProviderFactoryOf { dependencyContainer.internetPrivacyViewModelFactory.create() } } - private lateinit var binding: FragmentInternetActivityPolicyBinding + private var _binding: FragmentInternetActivityPolicyBinding? = null + private val binding get() = _binding!! private var qpDisabledSnackbar: Snackbar? = null @@ -93,7 +94,7 @@ class InternetPrivacyFragment : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - binding = FragmentInternetActivityPolicyBinding.bind(view) + _binding = FragmentInternetActivityPolicyBinding.bind(view) binding.apps.apply { layoutManager = LinearLayoutManager(requireContext()) @@ -200,4 +201,10 @@ class InternetPrivacyFragment : } override fun actions(): Flow = viewModel.actions + + override fun onDestroyView() { + super.onDestroyView() + qpDisabledSnackbar = null + _binding = null + } } diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationFragment.kt index fa26dd0..284a223 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationFragment.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/location/FakeLocationFragment.kt @@ -75,7 +75,8 @@ class FakeLocationFragment : viewModelProviderFactoryOf { dependencyContainer.fakeLocationViewModelFactory.create() } } - private lateinit var binding: FragmentFakeLocationBinding + private var _binding: FragmentFakeLocationBinding? = null + private val binding get() = _binding!! private var mapboxMap: MapboxMap? = null private var locationComponent: LocationComponent? = null @@ -122,7 +123,7 @@ class FakeLocationFragment : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - binding = FragmentFakeLocationBinding.bind(view) + _binding = FragmentFakeLocationBinding.bind(view) binding.mapView.setup(savedInstanceState) { mapboxMap -> this.mapboxMap = mapboxMap @@ -346,5 +347,10 @@ class FakeLocationFragment : override fun onDestroyView() { super.onDestroyView() binding.mapView.onDestroy() + qpDisabledSnackbar = null + mapboxMap = null + locationComponent = null + inputJob = null + _binding = null } } diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFragment.kt index 21a90bc..f6a031b 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFragment.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/TrackersFragment.kt @@ -55,10 +55,12 @@ class TrackersFragment : viewModelProviderFactoryOf { dependencyContainer.trackersViewModelFactory.create() } } - private lateinit var binding: FragmentTrackersBinding - private lateinit var dayGraphHolder: GraphHolder - private lateinit var monthGraphHolder: GraphHolder - private lateinit var yearGraphHolder: GraphHolder + private var _binding: FragmentTrackersBinding? = null + private val binding get() = _binding!! + + private var dayGraphHolder: GraphHolder? = null + private var monthGraphHolder: GraphHolder? = null + private var yearGraphHolder: GraphHolder? = null private var qpDisabledSnackbar: Snackbar? = null override fun onCreate(savedInstanceState: Bundle?) { @@ -99,7 +101,7 @@ class TrackersFragment : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - binding = FragmentTrackersBinding.bind(view) + _binding = FragmentTrackersBinding.bind(view) dayGraphHolder = GraphHolder(binding.graphDay.graph, requireContext(), false) monthGraphHolder = GraphHolder(binding.graphMonth.graph, requireContext(), false) @@ -131,9 +133,9 @@ class TrackersFragment : if (state.showQuickPrivacyDisabledMessage) qpDisabledSnackbar?.show() else qpDisabledSnackbar?.dismiss() - state.dayStatistics?.let { renderGraph(it, dayGraphHolder, binding.graphDay) } - state.monthStatistics?.let { renderGraph(it, monthGraphHolder, binding.graphMonth) } - state.yearStatistics?.let { renderGraph(it, yearGraphHolder, binding.graphYear) } + state.dayStatistics?.let { renderGraph(it, dayGraphHolder!!, binding.graphDay) } + state.monthStatistics?.let { renderGraph(it, monthGraphHolder!!, binding.graphMonth) } + state.yearStatistics?.let { renderGraph(it, yearGraphHolder!!, binding.graphYear) } state.apps?.let { binding.apps.post { @@ -161,4 +163,14 @@ class TrackersFragment : } override fun actions(): Flow = viewModel.actions + + override fun onDestroyView() { + super.onDestroyView() + qpDisabledSnackbar = null + dayGraphHolder = null + monthGraphHolder = null + yearGraphHolder = null + _binding = null + + } } diff --git a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFragment.kt b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFragment.kt index 406d26c..efce9ff 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFragment.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/features/trackers/apptrackers/AppTrackersFragment.kt @@ -65,7 +65,8 @@ class AppTrackersFragment : } } - private lateinit var binding: ApptrackersFragmentBinding + private var _binding: ApptrackersFragmentBinding? = null + private val binding get() = _binding!! private var qpDisabledSnackbar: Snackbar? = null @@ -107,7 +108,7 @@ class AppTrackersFragment : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - binding = ApptrackersFragmentBinding.bind(view) + _binding = ApptrackersFragmentBinding.bind(view) binding.blockAllToggle.setOnClickListener { viewModel.submitAction(Action.BlockAllToggleAction(binding.blockAllToggle.isChecked)) @@ -174,4 +175,10 @@ class AppTrackersFragment : } override fun actions(): Flow = viewModel.actions + + override fun onDestroyView() { + super.onDestroyView() + qpDisabledSnackbar = null + _binding = null + } } -- cgit v1.2.1