Skip to content

Commit

Permalink
Add more null checks around Connect #75
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmontemagno committed Jan 25, 2018
1 parent 5f4f739 commit 9a97e3b
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Plugin.InAppBilling.Android/InAppBillingImplementation.cs
Expand Up @@ -613,12 +613,15 @@ public Task<bool> ConnectAsync()
tcsConnect = new TaskCompletionSource<bool>();
var serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");

serviceIntent.SetPackage("com.android.vending");
if(serviceIntent == null)
return Task.FromResult(false);

serviceIntent.SetPackage("com.android.vending");

if (Context.PackageManager.QueryIntentServices(serviceIntent, 0).Any())
{
Context.BindService(serviceIntent, this, Bind.AutoCreate);
return tcsConnect.Task;
return tcsConnect?.Task ?? Task.FromResult(false);
}

return Task.FromResult(false);
Expand All @@ -633,7 +636,7 @@ public Task DisconnectAsync()
if (!IsConnected)
return Task.CompletedTask;

Context.UnbindService(this);
Context?.UnbindService(this);

IsConnected = false;
Service = null;
Expand All @@ -644,16 +647,19 @@ public void OnServiceConnected(ComponentName name, IBinder service)
{
Service = IInAppBillingServiceStub.AsInterface(service);

var pkgName = Context.PackageName;
if (Service == null || Context == null)
tcsConnect?.TrySetResult(false);

This comment has been minimized.

Copy link
@singingspaniel

singingspaniel Jan 26, 2018

Should you return after this? You get in here because the Service or Context are null... then continue eventually using the Context then Service eventhough you know at least one of them is null.

This comment has been minimized.

Copy link
@jamesmontemagno

jamesmontemagno Jan 26, 2018

Author Owner

good catch :)


var pkgName = Context.PackageName;

if (Service.IsBillingSupported(3, pkgName, ITEM_TYPE_SUBSCRIPTION) == 0)
{
IsConnected = true;
tcsConnect.TrySetResult(true);
tcsConnect?.TrySetResult(true);
return;
}

tcsConnect.TrySetResult(false);
tcsConnect?.TrySetResult(false);
}

public void OnServiceDisconnected(ComponentName name)
Expand Down

0 comments on commit 9a97e3b

Please sign in to comment.