Skip to content

Commit

Permalink
Fix potential crash due to optional Google Play Services dependency
Browse files Browse the repository at this point in the history
GoogleApiAvailability will return true when any Google Play Services SDK
is included as a dependency and Google Play Services is available on the
device. However the Wallet component may not be present and would cause
a crash.
  • Loading branch information
lkorth committed Aug 24, 2017
1 parent 32b8886 commit 2c3d9ad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.braintreepayments.api.interfaces.BraintreeResponseListener;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.wallet.Wallet;

import org.json.JSONArray;
import org.json.JSONException;
Expand Down Expand Up @@ -71,9 +72,11 @@ public static AndroidPayConfiguration fromJson(JSONObject json) {
*/
public boolean isEnabled(Context context) {
try {
Class.forName(Wallet.class.getName());

return mEnabled && GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context) ==
ConnectionResult.SUCCESS;
} catch (NoClassDefFoundError e) {
} catch (ClassNotFoundException | NoClassDefFoundError e) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.braintreepayments.api.Json;
import com.visa.checkout.Profile.CardBrand;
import com.visa.checkout.VisaCheckoutSdk;

import org.json.JSONObject;

Expand All @@ -25,7 +26,7 @@ public class VisaCheckoutConfiguration {
*/
private static boolean isVisaCheckoutSDKAvailable() {
try {
Class.forName("com.visa.checkout.VisaCheckoutSdk");
Class.forName(VisaCheckoutSdk.class.getName());
return true;
} catch (ClassNotFoundException e) {
return false;
Expand Down

0 comments on commit 2c3d9ad

Please sign in to comment.