phrase / phrase-android

Phrase Over the Air Android SDK
https://phrase.com
Other
6 stars 1 forks source link

Min/Max version constraints behaviour #42

Open angelolloqui opened 2 years ago

angelolloqui commented 2 years ago

Hi, I am running into something similar to what I expressed in the iOS SDK some months ago regarding the behavior of min/max version constraints. Basically, this:

What I expected

Min/Max to be applied not only on downloading but also in future uses. So, if for example I am in app version 3.1.0, and there is an OTA for [3.0.0 - 3.2.0], then I expect OTA to download and use that file. However, when the user updates the app (without deleting) to 3.3.0, I was expecting the OTA to no longer apply and therefore serve strings from the app bundle rather than the outdated OTA file.

What I see happening

Min/Max is applied on download, so it only gets a new OTA file if the app version matches the range. However, once the OTA is downloaded, it seems to be used every time from now on, even if the app upgraded to a version that is no longer under the OTA range.

What is the problem?

The main issue I see with this behavior is that the translations are no longer consistent. So, if I update strings, users that downloaded some old OTA content are now seeing the old strings even if they have the app updated with newer texts, while new users downloading the app today see something newer (coming from the binary)

Can you confirm if the Android SDK is behaving this way on purpose? could you make an update like the one in iOS to make the versioning more consistent? otherwise, could it be possible to at least have a "clear cache" method or alike to reset the state after each app upgrade?

Thanks!

angelolloqui commented 2 years ago

For anyone interested on the same, I am for the time being executing this code just before doing the Phrase.setup:

private fun fixOTACache() {
        val preferences = getSharedPreferences("PREF_UNIQUE_ID", Context.MODE_PRIVATE)
        val currentVersion = BuildConfig.VERSION_NAME
        val lastClearVersion = preferences.getString("ota_cleared_cache_version", null)
        if (lastClearVersion != currentVersion) {
            File(filesDir, ".phrase_cache").deleteRecursively()
            val keys = preferences.all.keys.filter { it != "PREF_UNIQUE_ID" }
            preferences.edit().apply {
                keys.forEach(::remove)
                putString("ota_cleared_cache_version", currentVersion)
            }.commit()
        }
    }

What it does is to delete the previous cached data when there is an app version update, because the downloaded OTA for that new version might be no longer applicable.

theSoenke commented 2 years ago

Hey @angelolloqui, thanks for raising this for the Android SDK. Right now the SDK does not validate the version constraints once the translations have been downloaded. We have this also as an improvement in our backlog and I'll let you know when this has been solved in the SDK

angelolloqui commented 1 month ago

Hello @theSoenke , what is the status of this? have you implemented some kind of version control in the android sdk as mentioned here? thanks!

theSoenke commented 1 month ago

Hi @angelolloqui, unfortunately some other tasks have been taking priority for Android over this issue. But unless any unforeseen new tasks should take priority this will worked on as one of the next tasks