Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/com/example/android/trivialdrivesample/util/IabHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
Expand Down Expand Up @@ -218,7 +220,12 @@ public void onServiceDisconnected(ComponentName name) {
public void onServiceConnected(ComponentName name, IBinder service) {
if (mDisposed) return;
logDebug("Billing service connected.");
mService = IInAppBillingService.Stub.asInterface(service);
if (!"com.farsitel.bazaar".equals(name.getPackageName())) {
logDebug("can't find bazaar app!");
return;
} else {
mService = IInAppBillingService.Stub.asInterface(service);
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the part that we check for the authenticity of target app.

String packageName = mContext.getPackageName();
try {
logDebug("Checking for in-app billing 3 support.");
Expand Down Expand Up @@ -264,7 +271,9 @@ public void onServiceConnected(ComponentName name, IBinder service) {

Intent serviceIntent = new Intent("ir.cafebazaar.pardakht.InAppBillingService.BIND");
serviceIntent.setPackage("com.farsitel.bazaar");
if (!mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) {
Copy link
Author

@ranjbarhadi ranjbarhadi Apr 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line will cause a null pointer exception to be thrown if bazaar client is not installed

PackageManager pm=mContext.getPackageManager();
List<ResolveInfo> intentServices = pm.queryIntentServices(serviceIntent, 0);
if (intentServices != null && !intentServices.isEmpty()) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this new approach will fix the app crashing issue

// service available to handle that Intent
mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
}
Expand All @@ -287,7 +296,7 @@ public void onServiceConnected(ComponentName name, IBinder service) {
public void dispose() {
logDebug("Disposing.");
mSetupDone = false;
if (mServiceConn != null) {
if (mServiceConn != null && mService!=null) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, we should check if the service is not null

logDebug("Unbinding from service.");
if (mContext != null) mContext.unbindService(mServiceConn);
}
Expand Down