Internal app update: clientVersionStalenessDays() returning null when testing with internal app sharing

1.8k Views Asked by At

Libraries:

implementation 'com.google.android.play:core:1.7.3' 
implementation 'com.google.android.play:core-ktx:1.7.0'

Additional information:

Everything else regarding app updates and internal app sharing works for me, I do get dialog with update mentioned, if I don't use condition for daysAvailable in my if statemants.

1.) I'm implementing in app updates according to documentation found here.

      // Returns an intent object that you use to check for an update.
      val appUpdateInfoTask = appUpdateManager.appUpdateInfo

       // Checks whether the platform allows the specified type of update,
      // and checks the update priority.
        appUpdateInfoTask.addOnSuccessListener { appUpdateInfo ->
            val daysAvailable = appUpdateInfo.clientVersionStalenessDays() ?: 0
            Toast.makeText(this, "Update availbable for $daysAvailable days", Toast.LENGTH_LONG).show()
            if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
                    && daysAvailable >= DAYS_FOR_FLEXIBLE_UPDATE
                    && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {
                startUpdate(appUpdateInfo, appUpdateManager, AppUpdateType.FLEXIBLE, REQUEST_CODE_UPDATE_FLEXIBLE)
            } else if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
                    && daysAvailable > DAYS_FOR_IMMEDIATE_UPDATE
                    && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
                startUpdate(appUpdateInfo, appUpdateManager, AppUpdateType.IMMEDIATE, REQUEST_CODE_UPDATE_IMMEDIATE)
            }
        }

To try this out through google play, i'm using internal app sharing method. So I have actually 3 version of the app uploaded on internal app sharing. So i click on first apk, which has version number v200, then i click on link for version 201 but as per guide, i don't click install. I wait 1 or 2 days, but appUpdateInfo.clientVersionStalenessDays() is still returning null, even after a couple of days since I clicked on second version apk link (v201). My first question is, why is this method always returning null for me, even though it knows that there is newer update available?

2.) My second question is regarding appUpdateInfo.clientVersionStalenessDays() itself. Lets say it's Monday and user has version 200 installed and we release version 201 and it's available to him on Tuesday. Theoretically, on Thursday appUpdateInfo.clientVersionStalenessDays() should return 2 (as in for 2 days this user have update available). But he still didn't choose to update. And then on friday we release version 202 and it's available to him on Saturday. On Sunday, what should above method return? 1 or 5? **So my second question is basically, does this method counter resets when there is newer version available to user, does it reset when we release version v202? (will this method check for how long was version 202 available for him, or just update in general?).

Let me know if I should provide any additional information regarding my issues.

2

There are 2 best solutions below

1
On

Its not working in the internal app sharing and returns null. You can check Build version, and if build version equal debug - use mocked value

0
On

The questions still aren't answered, so I wonder myself about behavior of appUpdateInfo.clientVersionStalenessDays() method. Also, I found a simpler way to do some testing. I didn't like internal app sharing method at a first glance, so I tried to figure out better method. I just decreased version code of my app to be smaller, than the one available in Play Market, and installed it onto emulator. But this way I received this error:

The app is not owned by any user on this device. An app is "owned" if it has been acquired from Play.

Which means, that the original app wasn't installed from Google Play Market. So, next thing I do, I uninstall existing app, go to Play Market and install current one. After that, I try again to build and install test app from Android Studio. But version of this build is smaller, that is already installed from Play Market, so AS asks me to uninstall existing version in order to install current build. After I agreed, I get no errors while retrieving appUpdateInfo and clientVersionStalenessDays() finally returns not null, but a number - zero (although, it might take some time to do so, maybe even emulator restart). Now this method returns 0, so in time I expect to see if it increases returned value on a testing device.