Skip to content

Commit 7fe866f

Browse files
authored
Merge pull request #87 from cafebazaar/fix-bazaar-deep-sleep-bug
Fix Bazaar not installed exception thrown when bazaar is in deep sleep on Samsung devices with checking disabled apps
2 parents 1e2c8de + afb6ba3 commit 7fe866f

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import android.content.Context
55
import android.content.Intent
66
import android.content.IntentSender
77
import android.content.ServiceConnection
8+
import android.content.pm.PackageManager.MATCH_DISABLED_COMPONENTS
9+
import android.os.Build
810
import android.os.Bundle
911
import android.os.IBinder
1012
import android.os.RemoteException
@@ -72,9 +74,7 @@ internal class ServiceBillingConnection(
7274
setClassName(BAZAAR_PACKAGE_NAME, BAZAAR_PAYMENT_SERVICE_CLASS_NAME)
7375
}
7476
.takeIf(
75-
thisIsTrue = {
76-
context.packageManager.queryIntentServices(it, 0).isNullOrEmpty().not()
77-
},
77+
thisIsTrue = ::isServiceAvailable,
7878
andIfNot = {
7979
callback.connectionFailed.invoke(BazaarNotFoundException())
8080
}
@@ -282,6 +282,18 @@ internal class ServiceBillingConnection(
282282
billingService = null
283283
}
284284

285+
private fun isServiceAvailable(intent: Intent): Boolean {
286+
return context.packageManager.queryIntentServices(intent, 0).isNotEmpty() ||
287+
isServiceAvailableInDeepSleep(intent)
288+
}
289+
290+
private fun isServiceAvailableInDeepSleep(intent: Intent): Boolean {
291+
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N &&
292+
context.packageManager
293+
.queryIntentServices(intent, MATCH_DISABLED_COMPONENTS)
294+
.isNotEmpty()
295+
}
296+
285297
companion object {
286298

287299
private const val BILLING_SERVICE_ACTION = "ir.cafebazaar.pardakht.InAppBillingService.BIND"

0 commit comments

Comments
 (0)