Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds: delays for app restart in InAppUpdateManagerImpl #20936

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class InAppUpdateAnalyticsTracker @Inject constructor(
}

fun trackAppRestartToCompleteUpdate() {
tracker.track(AnalyticsTracker.Stat.IN_APP_UPDATE_COMPLETED_WITH_APP_RESTART)
tracker.track(AnalyticsTracker.Stat.IN_APP_UPDATE_COMPLETED_WITH_APP_RESTART_BY_USER)
}

private fun createPropertyMap(updateType: Int): Map<String, String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import com.google.android.play.core.install.model.UpdateAvailability.DEVELOPER_T
import com.google.android.play.core.install.model.UpdateAvailability.UPDATE_AVAILABLE
import com.google.android.play.core.install.model.UpdateAvailability.UPDATE_NOT_AVAILABLE
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.wordpress.android.inappupdate.IInAppUpdateManager.Companion.APP_UPDATE_FLEXIBLE_REQUEST_CODE
import org.wordpress.android.inappupdate.IInAppUpdateManager.Companion.APP_UPDATE_IMMEDIATE_REQUEST_CODE

Expand All @@ -33,6 +37,7 @@ import javax.inject.Singleton
@Suppress("TooManyFunctions")
class InAppUpdateManagerImpl(
@ApplicationContext private val applicationContext: Context,
private val coroutineScope: CoroutineScope,
private val appUpdateManager: AppUpdateManager,
private val remoteConfigWrapper: RemoteConfigWrapper,
private val buildConfigWrapper: BuildConfigWrapper,
Expand All @@ -51,8 +56,16 @@ class InAppUpdateManagerImpl(
}

override fun completeAppUpdate() {
inAppUpdateAnalyticsTracker.trackAppRestartToCompleteUpdate()
appUpdateManager.completeUpdate()
coroutineScope.launch(Dispatchers.Main) {
// Track the app restart to complete update
inAppUpdateAnalyticsTracker.trackAppRestartToCompleteUpdate()

// Delay so the event above can be logged
delay(RESTART_DELAY_IN_MILLIS)

// Complete the update
appUpdateManager.completeUpdate()
}
}

override fun cancelAppUpdate(updateType: Int) {
Expand Down Expand Up @@ -226,5 +239,6 @@ class InAppUpdateManagerImpl(
private const val TAG = "AppUpdateChecker"
private const val PREF_NAME = "in_app_update_prefs"
private const val KEY_LAST_APP_UPDATE_CHECK_VERSION = "last_app_update_check_version"
private const val RESTART_DELAY_IN_MILLIS = 500L
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@
import org.wordpress.android.viewmodel.helpers.ConnectionStatus;
import org.wordpress.android.viewmodel.helpers.ConnectionStatusLiveData;

import javax.inject.Named;

import dagger.Binds;
import dagger.Module;
import dagger.Provides;
import dagger.android.AndroidInjectionModule;
import dagger.hilt.InstallIn;
import dagger.hilt.android.qualifiers.ApplicationContext;
import dagger.hilt.components.SingletonComponent;
import kotlinx.coroutines.CoroutineScope;
import static org.wordpress.android.modules.ThreadModuleKt.APPLICATION_SCOPE;

@InstallIn(SingletonComponent.class)
@Module(includes = AndroidInjectionModule.class)
Expand Down Expand Up @@ -93,6 +97,7 @@ public static AppUpdateManager provideAppUpdateManager(@ApplicationContext Conte
@Provides
public static IInAppUpdateManager provideInAppUpdateManager(
@ApplicationContext Context context,
@Named(APPLICATION_SCOPE) CoroutineScope appScope,
AppUpdateManager appUpdateManager,
RemoteConfigWrapper remoteConfigWrapper,
BuildConfigWrapper buildConfigWrapper,
Expand All @@ -103,6 +108,7 @@ public static IInAppUpdateManager provideInAppUpdateManager(
return inAppUpdatesFeatureConfig.isEnabled()
? new InAppUpdateManagerImpl(
context,
appScope,
appUpdateManager,
remoteConfigWrapper,
buildConfigWrapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.google.android.play.core.appupdate.AppUpdateOptions
import com.google.android.play.core.install.model.AppUpdateType
import com.google.android.play.core.install.model.InstallStatus
import com.google.android.play.core.install.model.UpdateAvailability
import kotlinx.coroutines.test.TestScope
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
Expand Down Expand Up @@ -82,6 +83,7 @@ class InAppUpdateManagerImplTest {

inAppUpdateManager = InAppUpdateManagerImpl(
applicationContext,
TestScope(),
appUpdateManager,
remoteConfigWrapper,
buildConfigWrapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ public enum Stat {
IN_APP_UPDATE_SHOWN,
IN_APP_UPDATE_DISMISSED,
IN_APP_UPDATE_ACCEPTED,
IN_APP_UPDATE_COMPLETED_WITH_APP_RESTART;
IN_APP_UPDATE_COMPLETED_WITH_APP_RESTART_BY_USER;

/*
* Please set the event name in the enum only if the new Stat's name in lower case does not match it.
Expand Down
Loading