Skip to content

Commit

Permalink
add api to check if url is PPro url
Browse files Browse the repository at this point in the history
  • Loading branch information
lmac012 committed Aug 28, 2024
1 parent 64f274e commit 3473f26
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ interface Subscriptions {
* Launches Privacy Pro with Settings as the parent activity
*/
fun launchPrivacyPro(context: Context, uri: Uri?)

/**
* @return `true` if the given URL leads to the Privacy Pro page. or `false` otherwise
*/
fun isPrivacyProUrl(url: String): Boolean
}

enum class Product(val value: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ class SubscriptionsDummy @Inject constructor() : Subscriptions {
) {
// no-op
}

override fun isPrivacyProUrl(url: String): Boolean = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,22 @@ class RealSubscriptions @Inject constructor(
}

override fun shouldLaunchPrivacyProForUrl(url: String): Boolean {
val uri = url.toUri()
val eTld = uri.host?.toTldPlusOne() ?: return false
val size = uri.pathSegments.size
val path = uri.pathSegments.firstOrNull()
return if (eTld == PRIVACY_PRO_ETLD && size == 1 && path == PRIVACY_PRO_PATH) {
return if (isPrivacyProUrl(url)) {
runBlocking {
isEligible()
}
} else {
false
}
}

override fun isPrivacyProUrl(url: String): Boolean {
val uri = url.toUri()
val eTld = uri.host?.toTldPlusOne() ?: return false
val size = uri.pathSegments.size
val path = uri.pathSegments.firstOrNull()
return eTld == PRIVACY_PRO_ETLD && size == 1 && path == PRIVACY_PRO_PATH
}
}

@ContributesRemoteFeature(
Expand Down

0 comments on commit 3473f26

Please sign in to comment.