fix: refresh token before PlayStore app installation when a limited response is returned from GPlay
Description
When users try to install an app from the Home, Search or Categories screens, the API calling switches from web-based to auth-based. By that time, if the token expires in the background, Google returns a limited response (version code being 0) because of the stale token, which is inadequate to install the app.
To fix this, the token is refreshed and app details are fetched again with the refreshed token. Even after refreshing, if the version code is still 0, then it's not possible to further proceed to installation from there and an exception is thrown.
Besides, due to the caching implemented in OkHttp for GPlay, when a limited response is sent by GPlay API, it's cached and served for subsequent network calls. As such, we cannot ensure that the version code gets updated with a new response and the full details response couldn't be fetched to proceed with the installation.
Removing the cache forces the OkHttpClient to retrieve a new response every time a new request is made.
Here's a flow-chart of the process:
Tests
- Open App Lounge with anonymous login.
- From App Lounge Settings, ensure “Show common apps” is checked.
- Open either Home, Search or Category screen where you see a list of apps.
- In that state, put the device idle for at least 12 hours; best if you could put it idle over the night. The purpose is to let the token for anonymous login become stale. You can lock the screen but make sure that App Lounge is the first app you see when you unlock.
- Try to install a single Google Play app from those screens. Only the first app will initiate the token refresh flow, and the subsequent installs will use the refreshed token.
- Observe that App Lounge takes a bit of time to start the installation. It's expected because under the hood, App Lounge refreshes the token and gets the app details, which takes some extra time.
- Ensure app installation works without any issues.
Issues
https://gitlab.e.foundation/e/os/backlog/-/issues/3324