FakeAppUpdateManager

public class FakeAppUpdateManager
extends Object implements AppUpdateManager

java.lang.Object
   ↳ com.google.android.play.core.appupdate.testing.FakeAppUpdateManager


A fake implementation of the AppUpdateManager.

This implementation is completely self-contained in the library and does not interact with the Play Store. For this reason, no UI is shown and no update is performed on the device. You can use this API to test your support for in-app updates, such as initiating update flows, checking download progress, and handling failure scenarios.

Keep in mind, you should use this API for only unit-tests and early development iterations. It is not intended for full stack integration tests, which you can conduct by uploading the latest version of your app to Play and sideloading an older version of your app that supports in-app updates onto your test device.

Summary

Public constructors

FakeAppUpdateManager(Context context)

Creates a fake instance of AppUpdateManager, which you can use for testing.

Public methods

Task<Void> completeUpdate()

For a flexible update flow, triggers the completion of the update.

void downloadCompletes()

Simulates the download completing.

void downloadFails()

Simulates a download failure.

void downloadStarts()

Simulates the download starting.

Task<AppUpdateInfo> getAppUpdateInfo()

Requests the update availability for the current app, an intent to start an update flow, and, if applicable, the state of updates currently in progress.

Integer getTypeForUpdateInProgress()

Returns the type of update that's currently in progress or null, if no update is in progress.

void installCompletes()

Simulates the download completing.

void installFails()

Simulates an update install failure.

boolean isConfirmationDialogVisible()

Returns whether the user confirmation dialog of the flexible update is visible to the user.

boolean isImmediateFlowVisible()

Returns whether the user confirmation screen of the immediate update is visible to the user.

boolean isInstallSplashScreenVisible()

Returns whether the splash screen is visible to the user.

void registerListener(InstallStateUpdatedListener listener)

Registers a listener for this app that receives state changes for self-update operations.

void setBytesDownloaded(long bytesDownloaded)

Simulates progress of the download by setting the number of bytes already downloaded.

void setClientVersionStalenessDays(Integer clientVersionStaleness)

Sets the staleness of the version installed on user's device.

void setInstallErrorCode(int installErrorCode)

Sets an error code which is returned by certain update flow API calls.

void setTotalBytesToDownload(long totalBytesToDownload)

Sets the size of an available update in bytes.

void setUpdateAvailable(int availableVersionCode)

Declares that an update is available and provides its version code.

void setUpdateNotAvailable()

Declares that no updates are available.

void setUpdatePriority(int updatePriority)

Sets the priority of the available update.

boolean startUpdateFlowForResult(AppUpdateInfo appUpdateInfo, int appUpdateType, IntentSenderForResultStarter starter, int requestCode)

Starts the desired update flow.

boolean startUpdateFlowForResult(AppUpdateInfo appUpdateInfo, int appUpdateType, Activity activity, int requestCode)

Starts the desired update flow.

void unregisterListener(InstallStateUpdatedListener listener)

Unregisters a listener you previously registered using registerListener(InstallStateUpdatedListener).

void userAcceptsUpdate()

Simulates that a user has accepted an update from the update confirmation dialog.

void userCancelsDownload()

Simulates the user canceling the download via the Play UI.

void userRejectsUpdate()

Simulates that a user has declined an update from the update confirmation dialog.

Inherited methods

From class java.lang.Object
From interface com.google.android.play.core.appupdate.AppUpdateManager

Public constructors

FakeAppUpdateManager

FakeAppUpdateManager (Context context)

Creates a fake instance of AppUpdateManager, which you can use for testing.

Note: This class should be used as a test-scoped singleton in unit tests and as an app-wide singleton during app development.

Parameters
context Context

Public methods

completeUpdate

Task<Void> completeUpdate ()

For a flexible update flow, triggers the completion of the update.

You should call this method to complete an update that has already been started via startUpdateFlowForResult(AppUpdateInfo, Activity, AppUpdateOptions, int) and is in the DOWNLOADED state.

Returns
Task<Void>

downloadCompletes

void downloadCompletes ()

Simulates the download completing.

This method call works only after downloadStarts().

downloadFails

void downloadFails ()

Simulates a download failure.

This method call works only if the download of an update is pending or downloading.

downloadStarts

void downloadStarts ()

Simulates the download starting.

This method call works only after calling userAcceptsUpdate().

getAppUpdateInfo

Task<AppUpdateInfo> getAppUpdateInfo ()

Requests the update availability for the current app, an intent to start an update flow, and, if applicable, the state of updates currently in progress.

To learn more, read Check for update availability.

Returns
Task<AppUpdateInfo>

getTypeForUpdateInProgress

Integer getTypeForUpdateInProgress ()

Returns the type of update that's currently in progress or null, if no update is in progress.

Returns
Integer

installCompletes

void installCompletes ()

Simulates the download completing.

This method call works only after completeUpdate() has been triggered by the application.

installFails

void installFails ()

Simulates an update install failure.

This method call works only if the update is already installing (after a call to completeUpdate()).

isConfirmationDialogVisible

boolean isConfirmationDialogVisible ()

Returns whether the user confirmation dialog of the flexible update is visible to the user.

Returns
boolean

isImmediateFlowVisible

boolean isImmediateFlowVisible ()

Returns whether the user confirmation screen of the immediate update is visible to the user.

Returns
boolean

isInstallSplashScreenVisible

boolean isInstallSplashScreenVisible ()

Returns whether the splash screen is visible to the user. This occurs during update completion. In the real implementation, your app is reloaded with the new version.

Returns
boolean

registerListener

void registerListener (InstallStateUpdatedListener listener)

Registers a listener for this app that receives state changes for self-update operations. Typically, you need to register a listener for only Flexible updates, and listeners should be unregistered using unregisterListener(InstallStateUpdatedListener) when you no longer need them.

To learn more, read Handle a flexible update.

Parameters
listener InstallStateUpdatedListener: The listener you want to register.

setBytesDownloaded

void setBytesDownloaded (long bytesDownloaded)

Simulates progress of the download by setting the number of bytes already downloaded.

This method call works only after calling setTotalBytesToDownload(long).

Parameters
bytesDownloaded long

setClientVersionStalenessDays

void setClientVersionStalenessDays (Integer clientVersionStaleness)

Sets the staleness of the version installed on user's device.

This method call only has effect if ERROR(/this#isUpdateAvailable) is true.

Parameters
clientVersionStaleness Integer: The number of days client has known about the fake update.

setInstallErrorCode

void setInstallErrorCode (int installErrorCode)

Sets an error code which is returned by certain update flow API calls.

The error code is returned calls to getAppUpdateInfo() and completeUpdate(). However, the error code might not be honored if a more severe workflow error occurs, such as if completeUpdate() you call before an update is downloaded.

The error code is persistent. So, you need reset the value by calling the same method and passing NO_ERROR.

Parameters
installErrorCode int: The error code you want to simulate.

setTotalBytesToDownload

void setTotalBytesToDownload (long totalBytesToDownload)

Sets the size of an available update in bytes.

This method call works only after calling downloadStarts().

Parameters
totalBytesToDownload long: Total size of the update in bytes.

setUpdateAvailable

void setUpdateAvailable (int availableVersionCode)

Declares that an update is available and provides its version code.

Parameters
availableVersionCode int: The version code of the fake update.

setUpdateNotAvailable

void setUpdateNotAvailable ()

Declares that no updates are available.

setUpdatePriority

void setUpdatePriority (int updatePriority)

Sets the priority of the available update.

This method call only has effect if ERROR(/this#isUpdateAvailable) is true.

Parameters
updatePriority int: Priority of the available update.

startUpdateFlowForResult

boolean startUpdateFlowForResult (AppUpdateInfo appUpdateInfo, 
                int appUpdateType, 
                IntentSenderForResultStarter starter, 
                int requestCode)

Starts the desired update flow.

This method should be called if you are starting the flow from a Component different from an Activity and you don't want to receive the onActivityResult call on the Activity.

This is identical to calling startUpdateFlowForResult(AppUpdateInfo, IntentSenderForResultStarter, AppUpdateOptions, int), with the defaultOptions(int) for the requested update flow. See its documentation for further information.

For a list of possible result values and parameter documentation, see startUpdateFlowForResult(AppUpdateInfo, IntentSenderForResultStarter, AppUpdateOptions, int).

Parameters
appUpdateInfo AppUpdateInfo

appUpdateType int

starter IntentSenderForResultStarter

requestCode int

Returns
boolean

startUpdateFlowForResult

boolean startUpdateFlowForResult (AppUpdateInfo appUpdateInfo, 
                int appUpdateType, 
                Activity activity, 
                int requestCode)

Starts the desired update flow.

Starts a flow of the provided AppUpdateType.

This is identical to calling startUpdateFlowForResult(AppUpdateInfo, Activity, AppUpdateOptions, int), with the defaultOptions(int) for the requested update flow. See its documentation for further information.

For a list of possible result values and parameter documentation, see startUpdateFlowForResult(AppUpdateInfo, Activity, AppUpdateOptions, int).

Parameters
appUpdateInfo AppUpdateInfo

appUpdateType int

activity Activity

requestCode int

Returns
boolean

unregisterListener

void unregisterListener (InstallStateUpdatedListener listener)

Unregisters a listener you previously registered using registerListener(InstallStateUpdatedListener).

To learn more, read Handle a flexible update.

Parameters
listener InstallStateUpdatedListener: The listener you want to unregister.

userAcceptsUpdate

void userAcceptsUpdate ()

Simulates that a user has accepted an update from the update confirmation dialog. The download is enqueued in PENDING status.

This method call works only if isConfirmationDialogVisible() or isImmediateFlowVisible() is true.

In the real implementation, a RESULT_OK is also received by the calling activity's ERROR(/android.app.Activity#onActivityResult).

userCancelsDownload

void userCancelsDownload ()

Simulates the user canceling the download via the Play UI.

This method call works only if the download of an update is pending or downloading.

userRejectsUpdate

void userRejectsUpdate ()

Simulates that a user has declined an update from the update confirmation dialog.

This method call works only if isConfirmationDialogVisible() or isImmediateFlowVisible() is true.

In the real implementation, a RESULT_CANCELED is also received by the calling activity's ERROR(/android.app.Activity#onActivityResult).