forked from github/wulkanowy-mirror
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"
|
resValue "string", "app_name", "Wulkanowy"
|
||||||
|
|
||||||
manifestPlaceholders = [
|
manifestPlaceholders = [firebase_enabled: project.hasProperty("enableFirebase")]
|
||||||
firebase_enabled: project.hasProperty("enableFirebase"),
|
|
||||||
buildTimestamp: String.valueOf(System.currentTimeMillis())
|
|
||||||
]
|
|
||||||
javaCompileOptions {
|
javaCompileOptions {
|
||||||
annotationProcessorOptions {
|
annotationProcessorOptions {
|
||||||
arguments += [
|
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 {
|
sourceSets {
|
||||||
|
@ -153,14 +153,6 @@
|
|||||||
android:resource="@xml/provider_paths" />
|
android:resource="@xml/provider_paths" />
|
||||||
</provider>
|
</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 -->
|
<!-- 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 -->
|
<!-- https://firebase.googleblog.com/2017/03/take-control-of-your-firebase-init-on.html -->
|
||||||
<provider
|
<provider
|
||||||
@ -170,6 +162,10 @@
|
|||||||
android:exported="false"
|
android:exported="false"
|
||||||
tools:ignore="MissingClass" />
|
tools:ignore="MissingClass" />
|
||||||
|
|
||||||
|
<meta-data
|
||||||
|
android:name="install_channel"
|
||||||
|
android:value="${install_channel}" />
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="firebase_analytics_collection_enabled"
|
android:name="firebase_analytics_collection_enabled"
|
||||||
android:value="${firebase_enabled}" />
|
android:value="${firebase_enabled}" />
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
package io.github.wulkanowy.utils
|
package io.github.wulkanowy.utils
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.pm.PackageManager
|
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
import android.os.Build.MANUFACTURER
|
import android.os.Build.MANUFACTURER
|
||||||
import android.os.Build.MODEL
|
import android.os.Build.MODEL
|
||||||
import android.os.Build.VERSION.SDK_INT
|
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.DEBUG
|
||||||
import io.github.wulkanowy.BuildConfig.FLAVOR
|
import io.github.wulkanowy.BuildConfig.FLAVOR
|
||||||
import io.github.wulkanowy.BuildConfig.VERSION_CODE
|
import io.github.wulkanowy.BuildConfig.VERSION_CODE
|
||||||
@ -15,21 +13,13 @@ import javax.inject.Inject
|
|||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
open class AppInfo @Inject constructor(
|
open class AppInfo @Inject constructor() {
|
||||||
@ApplicationContext private val context: Context,
|
|
||||||
) {
|
|
||||||
|
|
||||||
open val isDebug get() = DEBUG
|
open val isDebug get() = DEBUG
|
||||||
|
|
||||||
open val versionCode get() = VERSION_CODE
|
open val versionCode get() = VERSION_CODE
|
||||||
|
|
||||||
open val buildTimestamp: Long
|
open val buildTimestamp get() = BUILD_TIMESTAMP
|
||||||
get() {
|
|
||||||
val info = context.packageManager.getApplicationInfo(
|
|
||||||
context.packageName, PackageManager.GET_META_DATA,
|
|
||||||
)
|
|
||||||
return info.metaData?.getFloat("buildTimestamp")?.toLong() ?: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
open val buildFlavor get() = FLAVOR
|
open val buildFlavor get() = FLAVOR
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ abstract class AbstractMigrationTest {
|
|||||||
|
|
||||||
val dbName = "migration-test"
|
val dbName = "migration-test"
|
||||||
|
|
||||||
val context: Context get() = ApplicationProvider.getApplicationContext<Context>()
|
val context: Context get() = ApplicationProvider.getApplicationContext()
|
||||||
|
|
||||||
@get:Rule
|
@get:Rule
|
||||||
val helper: MigrationTestHelper = MigrationTestHelper(
|
val helper: MigrationTestHelper = MigrationTestHelper(
|
||||||
@ -33,7 +33,7 @@ abstract class AbstractMigrationTest {
|
|||||||
).addMigrations(
|
).addMigrations(
|
||||||
*AppDatabase.getMigrations(
|
*AppDatabase.getMigrations(
|
||||||
SharedPrefProvider(PreferenceManager.getDefaultSharedPreferences(context)),
|
SharedPrefProvider(PreferenceManager.getDefaultSharedPreferences(context)),
|
||||||
AppInfo(context)
|
AppInfo()
|
||||||
)
|
)
|
||||||
).build()
|
).build()
|
||||||
// close the database and release any stream resources when the test finishes
|
// close the database and release any stream resources when the test finishes
|
||||||
|
@ -29,15 +29,15 @@ class Migration35Test : AbstractMigrationTest() {
|
|||||||
close()
|
close()
|
||||||
}
|
}
|
||||||
|
|
||||||
helper.runMigrationsAndValidate(dbName, 35, true, Migration35(AppInfo(context)))
|
helper.runMigrationsAndValidate(dbName, 35, true, Migration35(AppInfo()))
|
||||||
|
|
||||||
val db = getMigratedRoomDatabase()
|
val db = getMigratedRoomDatabase()
|
||||||
val students = runBlocking { db.studentDao.loadAll() }
|
val students = runBlocking { db.studentDao.loadAll() }
|
||||||
|
|
||||||
assertEquals(2, students.size)
|
assertEquals(2, students.size)
|
||||||
|
|
||||||
assertTrue { students[0].avatarColor in AppInfo(context).defaultColorsForAvatar }
|
assertTrue { students[0].avatarColor in AppInfo().defaultColorsForAvatar }
|
||||||
assertTrue { students[1].avatarColor in AppInfo(context).defaultColorsForAvatar }
|
assertTrue { students[1].avatarColor in AppInfo().defaultColorsForAvatar }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createStudent(db: SupportSQLiteDatabase, id: Long) {
|
private fun createStudent(db: SupportSQLiteDatabase, id: Long) {
|
||||||
|
@ -37,7 +37,7 @@ class StudentTest {
|
|||||||
studentDb = studentDb,
|
studentDb = studentDb,
|
||||||
semesterDb = semesterDb,
|
semesterDb = semesterDb,
|
||||||
sdk = mockSdk,
|
sdk = mockSdk,
|
||||||
appInfo = AppInfo(mockk()),
|
appInfo = AppInfo(),
|
||||||
appDatabase = mockk()
|
appDatabase = mockk()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user