From f8852e424896ad9de5c697013af48d693fe0b8b7 Mon Sep 17 00:00:00 2001 From: Gavin Whelan Date: Fri, 16 Jul 2021 20:50:30 +0000 Subject: [PATCH] Release 3.0.2 (#134) ## [3.0.2] - 2021-07-16 ### Fixed - Catch `SecurityException` when thrown on call to `getNetworkCapabilities` used to detect current network availability. ([#129](https://github.com/launchdarkly/android-client-sdk/issues/129)) - Explicitely flag `PendingIntent`s as `FLAG_IMMUTABLE` on Android SDK versions that support doing so. Explicitly specifying mutability is required when targeting Android S+. ([#133](https://github.com/launchdarkly/android-client-sdk/issues/133)) --- CHANGELOG.md | 5 ++ example/build.gradle | 2 +- gradle.properties | 2 +- .../com/launchdarkly/sdk/android/LDUtil.java | 50 ++++++++++--------- .../sdk/android/PollingUpdater.java | 9 +++- 5 files changed, 42 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61affddb..c6cc7751 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ All notable changes to the LaunchDarkly Android SDK will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org). +## [3.0.2] - 2021-07-16 +### Fixed +- Catch `SecurityException` when thrown on call to `getNetworkCapabilities` used to detect current network availability. ([#129](https://github.com/launchdarkly/android-client-sdk/issues/129)) +- Explicitely flag `PendingIntent`s as `FLAG_IMMUTABLE` on Android SDK versions that support doing so. Explicitly specifying mutability is required when targeting Android S+. ([#133](https://github.com/launchdarkly/android-client-sdk/issues/133)) + ## [3.0.1] - 2021-06-25 ### Fixed - The Android manifest has been updated to explicitly specify the `android:exported` attribute on declared `receiver` elements. This is to meet [new requirements](https://developer.android.com/about/versions/12/behavior-changes-12#exported) in the upcoming Android 12 release. diff --git a/example/build.gradle b/example/build.gradle index afded360..e6d2c8ab 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -29,5 +29,5 @@ dependencies { implementation(project(":launchdarkly-android-client-sdk")) // Comment the previous line and uncomment this one to depend on the published artifact: - //implementation("com.launchdarkly:launchdarkly-android-client-sdk:3.0.1") + //implementation("com.launchdarkly:launchdarkly-android-client-sdk:3.0.2") } diff --git a/gradle.properties b/gradle.properties index 512bb2cd..51d02d11 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,7 +16,7 @@ # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true -version=3.0.1 +version=3.0.2 sonatypeUsername= sonatypePassword= diff --git a/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/LDUtil.java b/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/LDUtil.java index 8e551e9c..7b530e6d 100644 --- a/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/LDUtil.java +++ b/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/LDUtil.java @@ -31,30 +31,34 @@ class LDUtil { * @param context Context for getting the ConnectivityManager * @return whether device is connected to the internet */ - @SuppressWarnings("deprecation") static boolean isInternetConnected(Context context) { - ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - // TODO: at the point our min version is >= 23 we can remove the old compat code - if (Build.VERSION.SDK_INT >= 23) { - Network net = cm.getActiveNetwork(); - if (net == null) - return false; - - NetworkCapabilities nwc = cm.getNetworkCapabilities(net); - - // the older solution was cleaner but android went and - // deprecated it :^) - // hasTransport(NET_CAPABILITY_INTERNET) always returns false on emulators - // so we check these instead - return nwc != null && ( - nwc.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) - || nwc.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) - || nwc.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET) - || nwc.hasTransport(NetworkCapabilities.TRANSPORT_BLUETOOTH) - ); - } else { - NetworkInfo active = cm.getActiveNetworkInfo(); - return active != null && active.isConnectedOrConnecting(); + try { + ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + if (Build.VERSION.SDK_INT >= 23) { + Network net = cm.getActiveNetwork(); + if (net == null) + return false; + + NetworkCapabilities nwc = cm.getNetworkCapabilities(net); + + // the older solution was cleaner but android went and + // deprecated it :^) + // hasTransport(NET_CAPABILITY_INTERNET) always returns false on emulators + // so we check these instead + return nwc != null && ( + nwc.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) + || nwc.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) + || nwc.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET) + || nwc.hasTransport(NetworkCapabilities.TRANSPORT_BLUETOOTH) + ); + } else { + NetworkInfo active = cm.getActiveNetworkInfo(); + return active != null && active.isConnectedOrConnecting(); + } + } catch (SecurityException ignored) { + // See https://issuetracker.google.com/issues/175055271 + // We should fallback to assuming network is available + return true; } } 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 222ff58d..7be3ae23 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 @@ -5,8 +5,11 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.os.Build; import android.os.SystemClock; +import static android.app.PendingIntent.FLAG_IMMUTABLE; + /** * Used internally by the SDK. */ @@ -58,7 +61,11 @@ private static Intent getAlarmIntent(Context context) { } private static PendingIntent getPendingIntent(Context context) { - return PendingIntent.getBroadcast(context, 0, getAlarmIntent(context), 0); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + return PendingIntent.getBroadcast(context, 0, getAlarmIntent(context), FLAG_IMMUTABLE); + } else { + return PendingIntent.getBroadcast(context, 0, getAlarmIntent(context), 0); + } } private static AlarmManager getAlarmManager(Context context) {