Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert VersionTracker to Kotlin and add RefreshAttributesJob.
- Loading branch information
1 parent
0a97156
commit d521a81
Showing
2 changed files
with
48 additions
and
51 deletions.
There are no files selected for viewing
51 changes: 0 additions & 51 deletions
51
app/src/main/java/org/thoughtcrime/securesms/util/VersionTracker.java
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
app/src/main/java/org/thoughtcrime/securesms/util/VersionTracker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.thoughtcrime.securesms.util | ||
|
||
import android.content.Context | ||
import android.content.pm.PackageManager | ||
import org.signal.core.util.logging.Log | ||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies | ||
import org.thoughtcrime.securesms.jobs.RefreshAttributesJob | ||
import org.thoughtcrime.securesms.jobs.RemoteConfigRefreshJob | ||
import org.thoughtcrime.securesms.jobs.RetrieveRemoteAnnouncementsJob | ||
import org.thoughtcrime.securesms.keyvalue.SignalStore | ||
import java.time.Duration | ||
|
||
object VersionTracker { | ||
private val TAG = Log.tag(VersionTracker::class.java) | ||
|
||
@JvmStatic | ||
fun getLastSeenVersion(context: Context): Int { | ||
return TextSecurePreferences.getLastVersionCode(context) | ||
} | ||
|
||
@JvmStatic | ||
fun updateLastSeenVersion(context: Context) { | ||
val currentVersionCode = Util.getCanonicalVersionCode() | ||
val lastVersionCode = TextSecurePreferences.getLastVersionCode(context) | ||
|
||
if (currentVersionCode != lastVersionCode) { | ||
Log.i(TAG, "Upgraded from $lastVersionCode to $currentVersionCode") | ||
SignalStore.misc().clearClientDeprecated() | ||
val jobChain = listOf(RemoteConfigRefreshJob(), RefreshAttributesJob()) | ||
ApplicationDependencies.getJobManager().startChain(jobChain).enqueue() | ||
RetrieveRemoteAnnouncementsJob.enqueue(true) | ||
LocalMetrics.getInstance().clear() | ||
} | ||
|
||
TextSecurePreferences.setLastVersionCode(context, currentVersionCode) | ||
} | ||
|
||
@JvmStatic | ||
fun getDaysSinceFirstInstalled(context: Context): Long { | ||
return try { | ||
val installTimestamp = context.packageManager.getPackageInfo(context.packageName, 0).firstInstallTime | ||
Duration.ofMillis(System.currentTimeMillis() - installTimestamp).toDays() | ||
} catch (e: PackageManager.NameNotFoundException) { | ||
Log.w(TAG, e) | ||
0 | ||
} | ||
} | ||
} |