mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-01-31 13:18:20 +01:00
Add build timestamp as build config field (#1567)
This commit is contained in:
parent
4e69cfe23c
commit
a240fd5d5f
@ -29,10 +29,7 @@ android {
|
||||
|
||||
resValue "string", "app_name", "Wulkanowy"
|
||||
|
||||
manifestPlaceholders = [
|
||||
firebase_enabled: project.hasProperty("enableFirebase"),
|
||||
buildTimestamp: String.valueOf(System.currentTimeMillis())
|
||||
]
|
||||
manifestPlaceholders = [firebase_enabled: project.hasProperty("enableFirebase")]
|
||||
javaCompileOptions {
|
||||
annotationProcessorOptions {
|
||||
arguments += [
|
||||
@ -41,6 +38,12 @@ android {
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
if (System.env.SET_BUILD_TIMESTAMP) {
|
||||
buildConfigField "long", "BUILD_TIMESTAMP", String.valueOf(System.currentTimeMillis())
|
||||
} else {
|
||||
buildConfigField "long", "BUILD_TIMESTAMP", "1486235849000"
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
|
@ -153,14 +153,6 @@
|
||||
android:resource="@xml/provider_paths" />
|
||||
</provider>
|
||||
|
||||
<meta-data
|
||||
android:name="buildTimestamp"
|
||||
android:value="${buildTimestamp}" />
|
||||
|
||||
<meta-data
|
||||
android:name="install_channel"
|
||||
android:value="${install_channel}" />
|
||||
|
||||
<!-- workaround for https://github.com/firebase/firebase-android-sdk/issues/473 enabled:false -->
|
||||
<!-- https://firebase.googleblog.com/2017/03/take-control-of-your-firebase-init-on.html -->
|
||||
<provider
|
||||
@ -170,6 +162,10 @@
|
||||
android:exported="false"
|
||||
tools:ignore="MissingClass" />
|
||||
|
||||
<meta-data
|
||||
android:name="install_channel"
|
||||
android:value="${install_channel}" />
|
||||
|
||||
<meta-data
|
||||
android:name="firebase_analytics_collection_enabled"
|
||||
android:value="${firebase_enabled}" />
|
||||
|
@ -1,12 +1,10 @@
|
||||
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 dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import io.github.wulkanowy.BuildConfig.BUILD_TIMESTAMP
|
||||
import io.github.wulkanowy.BuildConfig.DEBUG
|
||||
import io.github.wulkanowy.BuildConfig.FLAVOR
|
||||
import io.github.wulkanowy.BuildConfig.VERSION_CODE
|
||||
@ -15,21 +13,13 @@ import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
open class AppInfo @Inject constructor(
|
||||
@ApplicationContext private val context: Context,
|
||||
) {
|
||||
open class AppInfo @Inject constructor() {
|
||||
|
||||
open val isDebug get() = DEBUG
|
||||
|
||||
open val versionCode get() = VERSION_CODE
|
||||
|
||||
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 buildTimestamp get() = BUILD_TIMESTAMP
|
||||
|
||||
open val buildFlavor get() = FLAVOR
|
||||
|
||||
|
@ -16,7 +16,7 @@ abstract class AbstractMigrationTest {
|
||||
|
||||
val dbName = "migration-test"
|
||||
|
||||
val context: Context get() = ApplicationProvider.getApplicationContext<Context>()
|
||||
val context: Context get() = ApplicationProvider.getApplicationContext()
|
||||
|
||||
@get:Rule
|
||||
val helper: MigrationTestHelper = MigrationTestHelper(
|
||||
@ -33,7 +33,7 @@ abstract class AbstractMigrationTest {
|
||||
).addMigrations(
|
||||
*AppDatabase.getMigrations(
|
||||
SharedPrefProvider(PreferenceManager.getDefaultSharedPreferences(context)),
|
||||
AppInfo(context)
|
||||
AppInfo()
|
||||
)
|
||||
).build()
|
||||
// close the database and release any stream resources when the test finishes
|
||||
|
@ -29,15 +29,15 @@ class Migration35Test : AbstractMigrationTest() {
|
||||
close()
|
||||
}
|
||||
|
||||
helper.runMigrationsAndValidate(dbName, 35, true, Migration35(AppInfo(context)))
|
||||
helper.runMigrationsAndValidate(dbName, 35, true, Migration35(AppInfo()))
|
||||
|
||||
val db = getMigratedRoomDatabase()
|
||||
val students = runBlocking { db.studentDao.loadAll() }
|
||||
|
||||
assertEquals(2, students.size)
|
||||
|
||||
assertTrue { students[0].avatarColor in AppInfo(context).defaultColorsForAvatar }
|
||||
assertTrue { students[1].avatarColor in AppInfo(context).defaultColorsForAvatar }
|
||||
assertTrue { students[0].avatarColor in AppInfo().defaultColorsForAvatar }
|
||||
assertTrue { students[1].avatarColor in AppInfo().defaultColorsForAvatar }
|
||||
}
|
||||
|
||||
private fun createStudent(db: SupportSQLiteDatabase, id: Long) {
|
||||
|
@ -37,7 +37,7 @@ class StudentTest {
|
||||
studentDb = studentDb,
|
||||
semesterDb = semesterDb,
|
||||
sdk = mockSdk,
|
||||
appInfo = AppInfo(mockk()),
|
||||
appInfo = AppInfo(),
|
||||
appDatabase = mockk()
|
||||
)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user