diff --git a/build.gradle b/build.gradle index 36100328..25219e41 100644 --- a/build.gradle +++ b/build.gradle @@ -8,11 +8,11 @@ buildscript { google() } dependencies { - classpath("com.android.tools.build:gradle:4.1.3") + classpath('com.android.tools.build:gradle:7.1.1') // For displaying method/field counts when building with Gradle: // https://github.com/KeepSafe/dexcount-gradle-plugin - classpath("com.getkeepsafe.dexcount:dexcount-gradle-plugin:2.0.0") + classpath("com.getkeepsafe.dexcount:dexcount-gradle-plugin:3.1.0") // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e336581f..ad81be16 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip diff --git a/launchdarkly-android-client-sdk/build.gradle b/launchdarkly-android-client-sdk/build.gradle index 6c0c2385..49da14cd 100644 --- a/launchdarkly-android-client-sdk/build.gradle +++ b/launchdarkly-android-client-sdk/build.gradle @@ -2,7 +2,6 @@ plugins { id("com.android.library") id("signing") id("maven-publish") - id("org.ajoberstar.git-publish") version "3.0.1" id("com.getkeepsafe.dexcount") } @@ -153,14 +152,6 @@ artifacts { archives sourcesJar, javadocJar } -gitPublish { - repoUri = "https://github.com/launchdarkly/android-client-sdk.git" - branch = "gh-pages" - contents { - from(javadoc) - } -} - afterEvaluate { publishing { publications { diff --git a/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/LDClient.java b/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/LDClient.java index 0430bb2b..32c74dc1 100644 --- a/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/LDClient.java +++ b/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/LDClient.java @@ -105,6 +105,9 @@ public static Future init(@NonNull Application application, initSharedLogger(config); + // Clear any obsolete polling alarm that might exist; we'll start a new one if appropriate. + PollingUpdater.stop(application); + // Acquire the `initLock` to ensure that if `init()` is called multiple times, we will only // initialize the client(s) once. synchronized (initLock) { diff --git a/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/PollingUpdater.java b/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/PollingUpdater.java index 962434bb..1fe17d4f 100644 --- a/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/PollingUpdater.java +++ b/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/PollingUpdater.java @@ -12,6 +12,10 @@ import com.launchdarkly.logging.LogValues; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; + /** * Used internally by the SDK. */ @@ -19,13 +23,25 @@ public class PollingUpdater extends BroadcastReceiver { private static int backgroundPollingIntervalMillis = LDConfig.DEFAULT_BACKGROUND_POLLING_INTERVAL_MILLIS; + private static AtomicBoolean pollingActive = new AtomicBoolean(false); + private static AtomicInteger pollingInterval = new AtomicInteger(); + synchronized static void setBackgroundPollingIntervalMillis(int backgroundPollingInterval) { backgroundPollingIntervalMillis = backgroundPollingInterval; } @Override public void onReceive(Context context, Intent intent) { - LDClient.triggerPollInstances(); + if (pollingActive.get()) { + LDClient.triggerPollInstances(); + } else { + // We received an alarm notification, but we had not set an alarm-- at least, not during + // the current lifetime of the app. So this must be a leftover alarm from a previous run + // of the app, which may have crashed or forgotten to shut down the SDK. If so, + // AlarmManager might have restarted the app just for this alarm. That's unfortunate but + // at least we can stop it from happening again, by cancelling the alarm now. + stop(context); + } } synchronized static void startBackgroundPolling(Context context) { @@ -34,11 +50,18 @@ synchronized static void startBackgroundPolling(Context context) { } synchronized static void startPolling(Context context, int initialDelayMillis, int intervalMillis) { + if (pollingActive.get()) { + if (pollingInterval.get() == intervalMillis) { + return; + } + } stop(context); LDClient.getSharedLogger().debug("startPolling with initialDelayMillis: %d and intervalMillis: %d", initialDelayMillis, intervalMillis); PendingIntent pendingIntent = getPendingIntent(context); AlarmManager alarmMgr = getAlarmManager(context); + pollingActive.set(true); + pollingInterval.set(intervalMillis); try { alarmMgr.setInexactRepeating( AlarmManager.ELAPSED_REALTIME, @@ -48,15 +71,22 @@ synchronized static void startPolling(Context context, int initialDelayMillis, i } catch (Exception ex) { LDUtil.logExceptionAtWarnLevel(LDClient.getSharedLogger(), ex, "Exception occurred when creating [background] polling alarm, likely due to the host application having too many existing alarms"); + pollingActive.set(false); } } synchronized static void stop(Context context) { - LDClient.getSharedLogger().debug("Stopping pollingUpdater"); + if (pollingActive.get()) { + // We may have been called even if pollingActive wasn't true, just to stop any obsolete + // alarm that may have been set in the past. But there's no point in logging a message + // in that case. + LDClient.getSharedLogger().debug("Stopping pollingUpdater"); + } PendingIntent pendingIntent = getPendingIntent(context); AlarmManager alarmMgr = getAlarmManager(context); alarmMgr.cancel(pendingIntent); + pollingActive.set(false); } private static Intent getAlarmIntent(Context context) {