Migrate AppInstallTime logic to mail-events module

Removes duplicate implementation from spotlight, uses centralized mail-events version

ET-5812
This commit is contained in:
Niccolò Forlini
2026-02-16 16:08:03 +01:00
parent 5ffcb45b1c
commit 0e2d3858f0
7 changed files with 11 additions and 127 deletions
@@ -22,9 +22,7 @@ import android.content.Context
import ch.protonmail.android.mailspotlight.data.FeatureSpotlightDataStoreProvider
import ch.protonmail.android.mailspotlight.data.local.FeatureSpotlightLocalDataSource
import ch.protonmail.android.mailspotlight.data.local.FeatureSpotlightLocalDataSourceImpl
import ch.protonmail.android.mailspotlight.data.repository.AppInstallTimeRepositoryImpl
import ch.protonmail.android.mailspotlight.data.repository.FeatureSpotlightRepositoryImpl
import ch.protonmail.android.mailspotlight.domain.repository.AppInstallTimeRepository
import ch.protonmail.android.mailspotlight.domain.repository.FeatureSpotlightRepository
import dagger.Binds
import dagger.Module
@@ -57,9 +55,5 @@ object FeatureSpotlightModule {
@Binds
@Reusable
fun bindsFeatureSpotlightRepository(impl: FeatureSpotlightRepositoryImpl): FeatureSpotlightRepository
@Binds
@Reusable
fun bindsAppInstallTimeRepository(impl: AppInstallTimeRepositoryImpl): AppInstallTimeRepository
}
}
@@ -1,33 +0,0 @@
/*
* Copyright (c) 2025 Proton Technologies AG
* This file is part of Proton Technologies AG and Proton Mail.
*
* Proton Mail is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Proton Mail is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proton Mail. If not, see <https://www.gnu.org/licenses/>.
*/
package ch.protonmail.android.mailspotlight.data.repository
import android.content.Context
import ch.protonmail.android.mailspotlight.domain.repository.AppInstallTimeRepository
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
class AppInstallTimeRepositoryImpl @Inject constructor(
@ApplicationContext private val context: Context
) : AppInstallTimeRepository {
override fun getFirstInstallTime(): Long = context.packageManager
.getPackageInfo(context.packageName, 0)
.firstInstallTime
}
@@ -1,54 +0,0 @@
/*
* Copyright (c) 2025 Proton Technologies AG
* This file is part of Proton Technologies AG and Proton Mail.
*
* Proton Mail is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Proton Mail is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proton Mail. If not, see <https://www.gnu.org/licenses/>.
*/
package ch.protonmail.android.mailspotlight.data.repository
import android.content.Context
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import io.mockk.every
import io.mockk.mockk
import kotlin.test.Test
import kotlin.test.assertEquals
internal class AppInstallTimeRepositoryImplTest {
private val packageInfo = PackageInfo().apply {
firstInstallTime = 1_000_000_000_000L
}
private val packageManager = mockk<PackageManager> {
every { getPackageInfo("test.package", 0) } returns packageInfo
}
private val context = mockk<Context> {
every { packageManager } returns this@AppInstallTimeRepositoryImplTest.packageManager
every { packageName } returns "test.package"
}
private val repository = AppInstallTimeRepositoryImpl(context)
@Test
fun `should return first install time from package manager`() {
// When
val result = repository.getFirstInstallTime()
// Then
assertEquals(1_000_000_000_000L, result)
}
}
+1
View File
@@ -48,6 +48,7 @@ android {
dependencies {
implementation(libs.bundles.module.domain)
implementation(project(":mail-common:domain"))
implementation(project(":mail-events:domain"))
testImplementation(libs.bundles.test)
}
@@ -1,24 +0,0 @@
/*
* Copyright (c) 2025 Proton Technologies AG
* This file is part of Proton Technologies AG and Proton Mail.
*
* Proton Mail is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Proton Mail is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proton Mail. If not, see <https://www.gnu.org/licenses/>.
*/
package ch.protonmail.android.mailspotlight.domain.repository
interface AppInstallTimeRepository {
fun getFirstInstallTime(): Long
}
@@ -18,19 +18,19 @@
package ch.protonmail.android.mailspotlight.domain.usecase
import ch.protonmail.android.mailspotlight.domain.repository.AppInstallTimeRepository
import ch.protonmail.android.mailevents.domain.repository.AppInstallRepository
import javax.inject.Inject
import kotlin.time.Clock
import kotlin.time.Duration
import kotlin.time.Duration.Companion.days
class IsRecentAppInstall @Inject constructor(
private val appInstallTimeRepository: AppInstallTimeRepository,
private val appInstallRepository: AppInstallRepository,
private val clock: Clock
) {
operator fun invoke(threshold: Duration = 1.days): Boolean {
val installTime = appInstallTimeRepository.getFirstInstallTime()
val installTime = appInstallRepository.getFirstInstallTime()
val now = clock.now().toEpochMilliseconds()
return now - installTime < threshold.inWholeMilliseconds
}
@@ -18,7 +18,7 @@
package ch.protonmail.android.mailspotlight.domain.usecase
import ch.protonmail.android.mailspotlight.domain.repository.AppInstallTimeRepository
import ch.protonmail.android.mailevents.domain.repository.AppInstallRepository
import io.mockk.every
import io.mockk.mockk
import kotlin.test.Test
@@ -31,11 +31,11 @@ import kotlin.time.Instant
internal class IsRecentAppInstallTest {
private val appInstallTimeRepository = mockk<AppInstallTimeRepository>()
private val appInstallRepository = mockk<AppInstallRepository>()
private val clock = mockk<Clock>()
private val isRecentAppInstall = IsRecentAppInstall(
appInstallTimeRepository = appInstallTimeRepository,
appInstallRepository = appInstallRepository,
clock = clock
)
@@ -46,7 +46,7 @@ internal class IsRecentAppInstallTest {
val installTime = now.minus(12.hours).toEpochMilliseconds()
every { clock.now() } returns now
every { appInstallTimeRepository.getFirstInstallTime() } returns installTime
every { appInstallRepository.getFirstInstallTime() } returns installTime
// When
val result = isRecentAppInstall()
@@ -62,7 +62,7 @@ internal class IsRecentAppInstallTest {
val installTime = now.minus(2.days).toEpochMilliseconds()
every { clock.now() } returns now
every { appInstallTimeRepository.getFirstInstallTime() } returns installTime
every { appInstallRepository.getFirstInstallTime() } returns installTime
// When
val result = isRecentAppInstall()
@@ -78,7 +78,7 @@ internal class IsRecentAppInstallTest {
val installTime = now.minus(1.days).toEpochMilliseconds()
every { clock.now() } returns now
every { appInstallTimeRepository.getFirstInstallTime() } returns installTime
every { appInstallRepository.getFirstInstallTime() } returns installTime
// When
val result = isRecentAppInstall()
@@ -94,7 +94,7 @@ internal class IsRecentAppInstallTest {
val installTime = now.minus(6.hours).toEpochMilliseconds()
every { clock.now() } returns now
every { appInstallTimeRepository.getFirstInstallTime() } returns installTime
every { appInstallRepository.getFirstInstallTime() } returns installTime
// When
val result = isRecentAppInstall(threshold = 12.hours)