Skip to content

Commit

Permalink
Release 3.0.2 (#134)
Browse files Browse the repository at this point in the history
## [3.0.2] - 2021-07-16
### Fixed
- Catch `SecurityException` when thrown on call to `getNetworkCapabilities` used to detect current network availability. ([#129](#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](#133))
  • Loading branch information
gwhelanLD authored Jul 16, 2021
1 parent aa95877 commit f8852e4
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 26 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f8852e4

Please sign in to comment.