Skip to content

Commit 6343494

Browse files
authored
Merge pull request #80 from cafebazaar/fix-deadobjectexception-not-caught
Caught deadObjectException when calling isPurchaseTypeSupported
2 parents 9cde642 + b485105 commit 6343494

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

poolakey/src/main/java/ir/cafebazaar/poolakey/billing/connection/ServiceBillingConnection.kt

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.content.IntentSender
77
import android.content.ServiceConnection
88
import android.os.Bundle
99
import android.os.IBinder
10+
import android.os.RemoteException
1011
import androidx.activity.result.IntentSenderRequest
1112
import com.android.vending.billing.IInAppBillingService
1213
import ir.cafebazaar.poolakey.ConnectionState
@@ -97,27 +98,26 @@ internal class ServiceBillingConnection(
9798
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
9899
IInAppBillingService.Stub.asInterface(service)
99100
?.also { billingService = it }
100-
?.takeIf(
101-
thisIsTrue = {
102-
isPurchaseTypeSupported(
103-
purchaseType = PurchaseType.IN_APP
104-
)
105-
},
106-
andIfNot = {
107-
callbackReference?.get()?.connectionFailed?.invoke(IAPNotSupportedException())
108-
}
109-
)
110-
?.takeIf(
111-
thisIsTrue = {
112-
!paymentConfiguration.shouldSupportSubscription || isPurchaseTypeSupported(
113-
purchaseType = PurchaseType.SUBSCRIPTION
114-
)
115-
},
116-
andIfNot = {
117-
callbackReference?.get()?.connectionFailed?.invoke(SubsNotSupportedException())
101+
?.also {
102+
try {
103+
if (isPurchaseTypeSupported(purchaseType = PurchaseType.IN_APP)) {
104+
if (!paymentConfiguration.shouldSupportSubscription || isPurchaseTypeSupported(
105+
purchaseType = PurchaseType.SUBSCRIPTION
106+
)
107+
) {
108+
callbackReference?.get()?.connectionSucceed?.invoke()
109+
} else {
110+
callbackReference?.get()?.connectionFailed?.invoke(
111+
SubsNotSupportedException()
112+
)
113+
}
114+
} else {
115+
callbackReference?.get()?.connectionFailed?.invoke(IAPNotSupportedException())
116+
}
117+
} catch (exception: RemoteException) {
118+
callbackReference?.get()?.connectionFailed?.invoke(exception)
118119
}
119-
)
120-
?.also { callbackReference?.get()?.connectionSucceed?.invoke() }
120+
}
121121
}
122122

123123
private fun isPurchaseTypeSupported(purchaseType: PurchaseType): Boolean {

0 commit comments

Comments
 (0)