1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2025-01-31 13:18:20 +01:00

Set buildTimestamp through manifest meta (#1556)

This commit is contained in:
Mikołaj Pich 2021-10-03 14:13:42 +02:00 committed by GitHub
parent 8e607d48f7
commit 60501fcd72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 19 deletions

View File

@ -27,10 +27,10 @@ android {
vectorDrawables.useSupportLibrary = true
resValue "string", "app_name", "Wulkanowy"
buildConfigField "long", "BUILD_TIMESTAMP", String.valueOf(System.currentTimeMillis())
manifestPlaceholders = [
firebase_enabled: project.hasProperty("enableFirebase")
firebase_enabled: project.hasProperty("enableFirebase"),
buildTimestamp: String.valueOf(System.currentTimeMillis())
]
javaCompileOptions {
annotationProcessorOptions {

View File

@ -106,7 +106,8 @@
</service>
<service
android:name=".services.messaging.AppMessagingService"
android:exported="false">
android:exported="false"
tools:ignore="MissingClass">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
@ -152,6 +153,10 @@
android:resource="@xml/provider_paths" />
</provider>
<meta-data
android:name="buildTimestamp"
android:value="${buildTimestamp}" />
<meta-data
android:name="install_channel"
android:value="${install_channel}" />
@ -162,7 +167,8 @@
android:name="com.google.firebase.provider.FirebaseInitProvider"
android:authorities="${applicationId}.firebaseinitprovider"
android:enabled="${firebase_enabled}"
android:exported="false" />
android:exported="false"
tools:ignore="MissingClass" />
<meta-data
android:name="firebase_analytics_collection_enabled"

View File

@ -1,10 +1,12 @@
package io.github.wulkanowy.utils
import android.content.Context
import android.content.pm.PackageManager
import android.content.res.Resources
import android.os.Build.MANUFACTURER
import android.os.Build.MODEL
import android.os.Build.VERSION.SDK_INT
import io.github.wulkanowy.BuildConfig.BUILD_TIMESTAMP
import dagger.hilt.android.qualifiers.ApplicationContext
import io.github.wulkanowy.BuildConfig.DEBUG
import io.github.wulkanowy.BuildConfig.FLAVOR
import io.github.wulkanowy.BuildConfig.VERSION_CODE
@ -13,13 +15,21 @@ import javax.inject.Inject
import javax.inject.Singleton
@Singleton
open class AppInfo @Inject constructor() {
open class AppInfo @Inject constructor(
@ApplicationContext private val context: Context,
) {
open val isDebug get() = DEBUG
open val versionCode get() = VERSION_CODE
open val buildTimestamp get() = BUILD_TIMESTAMP
open val buildTimestamp: Long
get() {
val info = context.packageManager.getApplicationInfo(
context.packageName, PackageManager.GET_META_DATA,
)
return info.metaData?.getFloat("buildTimestamp")?.toLong() ?: 0
}
open val buildFlavor get() = FLAVOR

View File

@ -16,6 +16,8 @@ abstract class AbstractMigrationTest {
val dbName = "migration-test"
val context: Context get() = ApplicationProvider.getApplicationContext<Context>()
@get:Rule
val helper: MigrationTestHelper = MigrationTestHelper(
InstrumentationRegistry.getInstrumentation(),
@ -24,7 +26,6 @@ abstract class AbstractMigrationTest {
)
fun getMigratedRoomDatabase(): AppDatabase {
val context = ApplicationProvider.getApplicationContext<Context>()
val database = Room.databaseBuilder(
ApplicationProvider.getApplicationContext(),
AppDatabase::class.java,
@ -32,7 +33,7 @@ abstract class AbstractMigrationTest {
).addMigrations(
*AppDatabase.getMigrations(
SharedPrefProvider(PreferenceManager.getDefaultSharedPreferences(context)),
AppInfo()
AppInfo(context)
)
).build()
// close the database and release any stream resources when the test finishes

View File

@ -29,15 +29,15 @@ class Migration35Test : AbstractMigrationTest() {
close()
}
helper.runMigrationsAndValidate(dbName, 35, true, Migration35(AppInfo()))
helper.runMigrationsAndValidate(dbName, 35, true, Migration35(AppInfo(context)))
val db = getMigratedRoomDatabase()
val students = runBlocking { db.studentDao.loadAll() }
assertEquals(2, students.size)
assertTrue { students[0].avatarColor in AppInfo().defaultColorsForAvatar }
assertTrue { students[1].avatarColor in AppInfo().defaultColorsForAvatar }
assertTrue { students[0].avatarColor in AppInfo(context).defaultColorsForAvatar }
assertTrue { students[1].avatarColor in AppInfo(context).defaultColorsForAvatar }
}
private fun createStudent(db: SupportSQLiteDatabase, id: Long) {

View File

@ -32,13 +32,13 @@ class StudentTest {
fun initApi() {
MockKAnnotations.init(this)
studentRepository = StudentRepository(
mockk(),
TestDispatchersProvider(),
studentDb,
semesterDb,
mockSdk,
AppInfo(),
mockk()
context = mockk(),
dispatchers = TestDispatchersProvider(),
studentDb = studentDb,
semesterDb = semesterDb,
sdk = mockSdk,
appInfo = AppInfo(mockk()),
appDatabase = mockk()
)
}