Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
f3a0f45
Convert sample to kt + androidx
Jawnnypoo Apr 12, 2019
6b77436
Convert rx class to kt
Jawnnypoo Apr 12, 2019
e28e515
Convert main library module to kt
Jawnnypoo Apr 12, 2019
9837d29
Binary compatibility cleanup
Jawnnypoo Apr 12, 2019
2e5b035
Java compat
Jawnnypoo Apr 12, 2019
b674f8e
Remove Collections references
Jawnnypoo Apr 12, 2019
cab1e02
Neat app icon
Jawnnypoo Apr 12, 2019
eee0134
Add way to view base implementation from Rx implementation
Jawnnypoo Apr 12, 2019
a560af3
chore: upgrade kotlin + gradle versions
kaushikgopal Nov 25, 2020
12c0457
dep: add coroutines
kaushikgopal Nov 25, 2020
59d2d9d
skip build config generation
kaushikgopal Nov 25, 2020
43b3525
fix: update non Rx activity title
kaushikgopal Nov 25, 2020
5a43240
add TrueTime2 interface
kaushikgopal Nov 25, 2020
843f9cc
simplify Rx in TrueTimeRx
kaushikgopal Nov 25, 2020
d330482
wip: write out algorithm for coroutine implementation
kaushikgopal Nov 25, 2020
28d0f47
wip: ntp algo with todo methods
kaushikgopal Nov 25, 2020
7e9683c
reogranize sntip client package
kaushikgopal Nov 25, 2020
9cf3f45
inject sntp client into TrueTime
kaushikgopal Nov 25, 2020
90ad99a
implementation logic
kaushikgopal Nov 25, 2020
fcd3857
feat: flush out implementation for TrueTimeImpl
kaushikgopal Nov 26, 2020
94b15cc
test figures for TrueTimeImpl
kaushikgopal Nov 26, 2020
de1045d
hack to test coroutines TT
kaushikgopal Nov 26, 2020
26a3260
app example : initialize TrueTime2
kaushikgopal Nov 26, 2020
2b8cd73
fix: revert TrueTime.kt -> .java
kaushikgopal Nov 26, 2020
dda83ef
ref: reorganize packages
kaushikgopal Nov 26, 2020
be815e1
--wip: sntp duplicate
kaushikgopal Nov 26, 2020
38449d4
upgrade kotlin + coroutines gradle
kaushikgopal Dec 28, 2020
43fab29
ref: move to legacy package
kaushikgopal Dec 29, 2020
6d19a1b
feat: Sntp add devicetime api
kaushikgopal Dec 29, 2020
6036da1
feat: TrueTime2 add more usable apis
kaushikgopal Dec 29, 2020
13342c3
feat: cleanup sample app
kaushikgopal Dec 29, 2020
c60ccaa
feat: add repeat count parameter
kaushikgopal Dec 29, 2020
ef8c0fe
fix: add equals + hashcode for TruetimeResult
kaushikgopal Dec 29, 2020
9243133
store and reuse ntpResult
kaushikgopal Dec 29, 2020
053875c
ref: extract TimeKeeper logic
kaushikgopal Dec 29, 2020
7e32a99
fix: cleanup SntpImpl
kaushikgopal Dec 29, 2020
0c028a6
feat: add logger interface
kaushikgopal Dec 29, 2020
dd37470
fix: logging levels
kaushikgopal Dec 30, 2020
61a307a
ref: remove TrueTime dependencies from Sntp
kaushikgopal Dec 30, 2020
e78471e
feat: add sync through coroutines
kaushikgopal Dec 31, 2020
0a3c94c
ref: clean up api given sync present
kaushikgopal Dec 31, 2020
f1c9150
fix: truetime failure shouldn't crash
kaushikgopal Dec 31, 2020
c78f9eb
wip
kaushikgopal Nov 1, 2021
b18f9ea
package rename
kaushikgopal Aug 14, 2022
742506c
api changes
kaushikgopal Aug 14, 2022
a33593f
wip: upgrade gradle plugin
kaushikgopal Aug 14, 2022
bedee05
refactor(sntp): move from logger to event listener
kaushikgopal Aug 14, 2022
567af93
SntpImpl: move from logger → EventListener
kaushikgopal Aug 23, 2022
04dcfa2
move from logging → event listener
kaushikgopal Aug 23, 2022
2f0c346
ref: move TrueTimeParameters from data class → Builder pattern
kaushikgopal Aug 24, 2022
e5517b6
ref: remove initialize method; sync is the way to go
kaushikgopal Aug 24, 2022
a515b93
ref: event listener + sample app log listener
kaushikgopal Aug 24, 2022
051b53e
fix app based on changes
kaushikgopal Aug 24, 2022
7ec3ade
app tweaks
kaushikgopal Aug 24, 2022
0900ee6
update README
kaushikgopal Aug 24, 2022
6cd1516
update README
kaushikgopal Aug 24, 2022
03e24b5
update REAME
kaushikgopal Aug 24, 2022
b0f16e6
update REAME
kaushikgopal Aug 24, 2022
44b5772
update REAME
kaushikgopal Aug 24, 2022
fe1be4a
cleanup
kaushikgopal Aug 24, 2022
51767b9
prepare for release
kaushikgopal Aug 24, 2022
6b452d3
update jitpack instructions
kaushikgopal Aug 24, 2022
80f0a4d
fix: compileSdkVersion to 33
kaushikgopal Aug 24, 2022
dd1207a
fix: compiler warning for resolveNtpHostToIPs
kaushikgopal Aug 24, 2022
bd113cd
fix: sample app using actual truetime
kaushikgopal Aug 24, 2022
abde7e2
ref: move from String → InetAddress object
kaushikgopal Aug 24, 2022
8a0a04b
ref: change SNTP call to address vs ntphost
kaushikgopal Aug 25, 2022
8c7dcf5
feat: keep device on when using TrueTime app
kaushikgopal Aug 25, 2022
3a07875
feat: add feature to filter ipv6 addresses
kaushikgopal Aug 25, 2022
0d13df9
feat: add strict mode flag
kaushikgopal Aug 25, 2022
369e428
fix: sample app api
kaushikgopal Aug 25, 2022
5b7d498
ref: improve TrueTime Parameters naming
kaushikgopal Aug 25, 2022
e1145a6
update gitignore
kaushikgopal Feb 25, 2023
b08dc3c
rename serverResponseDelayMax → InMillis
kaushikgopal Feb 25, 2023
296ef71
improve docs
kaushikgopal Feb 25, 2023
f9174e7
use lifecyclescope in sample app
kaushikgopal Feb 25, 2023
aaadff8
fix glaring documentation bug on strictNtpMode
kaushikgopal Feb 25, 2023
72e790d
dispose activity syncer
kaushikgopal Feb 25, 2023
fe2f761
upgrade gradle
kaushikgopal Feb 25, 2023
4b115c8
reorder todos based on priority
kaushikgopal Feb 25, 2023
1b44fed
upgrade kotlin 1.8.0 coroutines 1.6.4
kaushikgopal Feb 25, 2023
3e581be
increase server response delay
kaushikgopal Feb 25, 2023
024cac8
switching to time.apple for example
kaushikgopal Feb 25, 2023
d7a1490
truetime will one day be pure kotlin, so this is pointless
kaushikgopal Feb 25, 2023
c1a5d38
agp 8 warning
kaushikgopal Feb 25, 2023
464d93d
target sdk 33 + move sample app out of instacart.library package
kaushikgopal Feb 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Convert main library module to kt
  • Loading branch information
Jawnnypoo committed Apr 12, 2019
commit e28e5151f213b2c48e0236fba9b09a23e0f4bc21
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ class SampleActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_sample)
refreshBtn.isEnabled = TrueTime.isInitialized()
refreshBtn.isEnabled = TrueTime.isInitialized
refreshBtn.setOnClickListener {
updateTime()
}
}

private fun updateTime() {
if (!TrueTime.isInitialized()) {
if (!TrueTime.isInitialized) {
Toast.makeText(this, "Sorry TrueTime not yet initialized. Trying again.", Toast.LENGTH_SHORT)
.show()
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,19 @@ package com.instacart.library.truetime
import android.content.Context
import io.reactivex.BackpressureStrategy
import io.reactivex.Flowable
import io.reactivex.FlowableEmitter
import io.reactivex.FlowableOnSubscribe
import io.reactivex.FlowableTransformer
import io.reactivex.Single
import io.reactivex.annotations.NonNull
import io.reactivex.functions.Consumer
import io.reactivex.functions.Function
import io.reactivex.functions.Predicate
import io.reactivex.schedulers.Schedulers
import java.io.IOException
import java.net.InetAddress
import java.net.UnknownHostException
import java.util.Arrays
import java.util.Collections
import java.util.Comparator
import java.util.Date
import org.reactivestreams.Publisher

@Suppress("MemberVisibilityCanBePrivate")
@Suppress("MemberVisibilityCanBePrivate", "unused")
class TrueTimeRx : TrueTime() {

companion object {
Expand All @@ -34,7 +28,7 @@ class TrueTimeRx : TrueTime() {
}

fun isInitialized(): Boolean {
return TrueTime.isInitialized()
return TrueTime.isInitialized
}

fun build(): TrueTimeRx {
Expand All @@ -58,18 +52,18 @@ class TrueTimeRx : TrueTime() {
return this
}

override fun withConnectionTimeout(timeout: Int): TrueTimeRx {
super.withConnectionTimeout(timeout)
override fun withConnectionTimeout(timeoutInMillis: Int): TrueTimeRx {
super.withConnectionTimeout(timeoutInMillis)
return this
}

override fun withRootDelayMax(rootDelay: Float): TrueTimeRx {
super.withRootDelayMax(rootDelay)
override fun withRootDelayMax(rootDelayMax: Float): TrueTimeRx {
super.withRootDelayMax(rootDelayMax)
return this
}

override fun withRootDispersionMax(rootDispersion: Float): TrueTimeRx {
super.withRootDispersionMax(rootDispersion)
override fun withRootDispersionMax(rootDispersionMax: Float): TrueTimeRx {
super.withRootDispersionMax(rootDispersionMax)
return this
}

Expand All @@ -95,7 +89,7 @@ class TrueTimeRx : TrueTime() {
* @return accurate NTP Date
*/
fun initializeRx(ntpPoolAddress: String): Single<Date> {
return if (TrueTime.isInitialized())
return if (TrueTime.isInitialized)
Single.just(TrueTime.now())
else
initializeNtp(ntpPoolAddress).map { TrueTime.now() }
Expand Down
3 changes: 2 additions & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'com.github.dcendents.android-maven'

android {
Expand Down Expand Up @@ -27,7 +28,7 @@ android {
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be needed, since its specified in allProjects

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as #129 (comment)


dependencies {

api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

group='com.github.instacart'

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.instacart.library.truetime

import android.content.BroadcastReceiver
import android.content.ContentValues.TAG
import android.content.Context
import android.content.Intent

class BootCompletedBroadcastReceiver : BroadcastReceiver() {

companion object {
private val TAG = BootCompletedBroadcastReceiver::class.java.simpleName
}

override fun onReceive(context: Context, intent: Intent) {
TrueLog.i(TAG, "---- clearing TrueTime disk cache as we've detected a boot")
if (Intent.ACTION_BOOT_COMPLETED == intent.action) {
TrueTime.clearCachedInfo()
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.instacart.library.truetime

interface CacheInterface {

companion object {
const val KEY_CACHED_BOOT_TIME = "com.instacart.library.truetime.cached_boot_time"
const val KEY_CACHED_DEVICE_UPTIME = "com.instacart.library.truetime.cached_device_uptime"
const val KEY_CACHED_SNTP_TIME = "com.instacart.library.truetime.cached_sntp_time"
}

fun put(key: String, value: Long)

fun get(key: String, defaultValue: Long): Long

fun clear()
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.instacart.library.truetime

import android.os.SystemClock

internal class DiskCacheClient {

companion object {
private val TAG = DiskCacheClient::class.java.simpleName
}

private var _cacheInterface: CacheInterface? = null

// has boot time changed (simple check)
fun isTrueTimeCachedFromAPreviousBoot(): Boolean {
if (cacheUnavailable()) {
return false
}

val cachedBootTime = _cacheInterface?.get(CacheInterface.KEY_CACHED_BOOT_TIME, 0L) ?: 0L
if (cachedBootTime == 0L) {
return false
}
val bootTimeChanged = SystemClock.elapsedRealtime() < getCachedDeviceUptime()
TrueLog.i(TAG, "---- boot time changed $bootTimeChanged")
return !bootTimeChanged
}

fun getCachedDeviceUptime(): Long = if (cacheUnavailable()) {
0L
} else _cacheInterface?.get(CacheInterface.KEY_CACHED_DEVICE_UPTIME, 0L) ?: 0L

fun getCachedSntpTime(): Long = if (cacheUnavailable()) {
0L
} else _cacheInterface?.get(CacheInterface.KEY_CACHED_SNTP_TIME, 0L) ?: 0L

/**
* Provide your own cache interface to cache the true time information.
* @param cacheInterface the customized cache interface to save the true time data.
*/
fun enableCacheInterface(cacheInterface: CacheInterface) {
this._cacheInterface = cacheInterface
}

/**
* Clear the cache cache when the device is rebooted.
* @param cacheInterface the customized cache interface to save the true time data.
*/
@JvmOverloads fun clearCachedInfo(cacheInterface: CacheInterface? = this._cacheInterface) {
cacheInterface?.clear()
}

fun cacheTrueTimeInfo(sntpClient: SntpClient) {
if (cacheUnavailable()) {
return
}

val cachedSntpTime = sntpClient.cachedSntpTime
val cachedDeviceUptime = sntpClient.cachedDeviceUptime
val bootTime = cachedSntpTime - cachedDeviceUptime

TrueLog.d(
TAG,
String.format(
"Caching true time info to disk sntp [%s] device [%s] boot [%s]",
cachedSntpTime,
cachedDeviceUptime,
bootTime
)
)

_cacheInterface?.put(CacheInterface.KEY_CACHED_BOOT_TIME, bootTime)
_cacheInterface?.put(CacheInterface.KEY_CACHED_DEVICE_UPTIME, cachedDeviceUptime)
_cacheInterface?.put(CacheInterface.KEY_CACHED_SNTP_TIME, cachedSntpTime)
}

// -----------------------------------------------------------------------------------

private fun cacheUnavailable(): Boolean {
if (_cacheInterface == null) {
TrueLog.w(TAG, "Cannot use disk caching strategy for TrueTime. CacheInterface unavailable")
return true
}
return false
}
}
Loading