onepf / OpenIAB

Open In-App Billing for Google Play, SlideMe, Amazon Store, Nokia Store, Samsung Apps, Yandex.Store, Appland, Aptoide, AppMall and Fortumo.
http://onepf.org/openiab/
Apache License 2.0
476 stars 171 forks source link

explicit intent exception : Android 5.0 with Google play with openIAB 0.9.8.3.1 #449

Closed Lakedaemon closed 9 years ago

Lakedaemon commented 9 years ago

Today, I got this crash report :

java.lang.IllegalArgumentException :Service Intent must be explicit :Intent { act=com.android.vending.billing.InAppBillingService.BIND } at android.app.ContextImpl.validateServiceIntent (ContextImpl.java : 2039) at android.app.ContextImpl.bindServiceCommon (ContextImpl.java : 2147) at android.app.ContextImpl.bindService (ContextImpl.java : 2125) at android.content.ContextWrapper.bindService (ContextWrapper.java : 559) at org.onepf.oms.appstore.GooglePlay.isBillingAvailable (GooglePlay.java : 134) at org.onepf.oms.OpenIabHelper$12.run (OpenIabHelper.java : 815) at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java : 1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java : 587) at java.lang.Thread.run (Thread.java : 818)

The user was on Android 5.0 Device : Samsung SM-N9005 hltezh

I'm building with compile files('libs/openiab-0.9.8.3.1.jar') (this looks like a google issue as openiab is supposed to only wrap Google iAP api)

RomanZhilich commented 9 years ago

Duplicate #415

akarimova commented 9 years ago

@Lakedaemon we already have a similar issue, but no idea how to fix it.. in the library we use only explicit intents

Tolriq commented 9 years ago

It's a bug in code :) Even if all my previous patches were not merged and discussed the cause is simple.

https://github.com/onepf/OpenIAB/blob/master/library/src/main/java/org/onepf/oms/appstore/GooglePlay.java#L100

You check for the non presence of both ANDROID_INSTALLER and GOOGLE_INSTALLER then in code the explicit intent is forced to ANDROID_INSTALLER.

Meaning that if GOOGLE_INSTALLER is present and not ANDROID_INSTALLER you have the crash ....

RomanZhilich commented 9 years ago

I don't see how it can cause crash. Before sending intent we check that there's a service to handle it: https://github.com/onepf/OpenIAB/blob/master/library/src/main/java/org/onepf/oms/appstore/GooglePlay.java#L109 Intent with package considered explicit: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.0.2_r1/android/app/ContextImpl.java#1672

Moreover, I've tried to change this part to use Intent with ComponentInfo constructed from ResolveInfo with no luck.

Tolriq commented 9 years ago

Well surely one of the many Android bugs that needs adjustment from code that should work, to workaround or try catch so that it really works :)

Tolriq commented 9 years ago

Simple example of things that does not work as the docs says : https://github.com/onepf/OpenIAB/commit/0ca10de1eed039aaf81c198b0a817b28a829ebfd

final List<ResolveInfo> infos = getPackageManager().queryIntentServices(intent, 0);
if (infos.isEmpty()) {

Despite the docs that says that queryIntentServices returns empty list on many devices 2.X and some other it will return null meaning crash.

RomanZhilich commented 9 years ago

We do not call isEmpty() directly, we use NPE safe util method:

CollectionUtils.isEmpty(infoList)

UPD: Oh, sorry, I get it. We'll fix this one just to be safe.

RomanZhilich commented 9 years ago

Potential NPE you've mentioned should be fixed now. I'm closing this as a duplicate of #415