Skip to content

Commit

Permalink
Fix broadcast receiver on Android 14
Browse files Browse the repository at this point in the history
  • Loading branch information
louischan-oursky committed Jul 8, 2024
1 parent c52e588 commit 34a1a5d
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 4 deletions.
6 changes: 5 additions & 1 deletion sdk/src/main/java/com/oursky/authgear/AuthgearCore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,11 @@ internal class AuthgearCore(
}
}
}
application.registerReceiver(br, intentFilter)
if (Build.VERSION.SDK_INT >= 33) {
application.registerReceiver(br, intentFilter, Context.RECEIVER_NOT_EXPORTED)
} else {
application.registerReceiver(br, intentFilter)
}
application.startActivity(
WebViewActivity.createIntent(application, action, authorizeUrl)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.net.Uri
import android.os.Build
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine
Expand Down Expand Up @@ -54,7 +55,11 @@ class CustomTabsUIImplementation : UIImplementation {
}
}
}
context.registerReceiver(br, intentFilter)
if (Build.VERSION.SDK_INT >= 33) {
context.registerReceiver(br, intentFilter, Context.RECEIVER_NOT_EXPORTED)
} else {
context.registerReceiver(br, intentFilter)
}
context.startActivity(
OAuthActivity.createAuthorizationIntent(
context,
Expand Down
1 change: 1 addition & 0 deletions sdk/src/main/java/com/oursky/authgear/OAuthActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ internal class OAuthActivity : AppCompatActivity() {

intent.getStringExtra(KEY_BROADCAST_ACTION)?.let { broadcastAction ->
val broadcastIntent = Intent(broadcastAction)
broadcastIntent.setPackage(this.applicationContext.packageName)
broadcastIntent.putExtra(AuthgearCore.KEY_OAUTH_BOARDCAST_TYPE, OAuthBroadcastType.REDIRECT_URL.name)
this.intent.data?.toString()?.let {
broadcastIntent.putExtra(AuthgearCore.KEY_REDIRECT_URL, it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ internal open class OAuthWebViewBaseActivity : AppCompatActivity() {
private fun sendRedirectURLBroadcast() {
intent.getStringExtra(KEY_BROADCAST_ACTION)?.let { broadcastAction ->
val broadcastIntent = Intent(broadcastAction)
broadcastIntent.setPackage(this.applicationContext.packageName)
broadcastIntent.putExtra(AuthgearCore.KEY_OAUTH_BOARDCAST_TYPE, OAuthBroadcastType.REDIRECT_URL.name)
mResult?.data?.toString()?.let {
broadcastIntent.putExtra(AuthgearCore.KEY_REDIRECT_URL, it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ class WebKitWebViewActivity: AppCompatActivity() {

this.intent.getStringExtra(KEY_BROADCAST_ACTION)?.let { broadcastAction ->
val broadcastIntent = Intent(broadcastAction)
broadcastIntent.setPackage(this.applicationContext.packageName)
broadcastIntent.putExtra(AuthgearCore.KEY_OAUTH_BOARDCAST_TYPE, OAuthBroadcastType.REDIRECT_URL.name)
if (this.result != null) {
broadcastIntent.putExtra(AuthgearCore.KEY_REDIRECT_URL, this.result.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.net.Uri
import android.os.Build
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine
Expand Down Expand Up @@ -55,7 +56,11 @@ class WebKitWebViewUIImplementation(val actionBarBackgroundColor: Int? = null, v
}
}
}
context.registerReceiver(br, intentFilter)
if (Build.VERSION.SDK_INT >= 33) {
context.registerReceiver(br, intentFilter, Context.RECEIVER_NOT_EXPORTED)
} else {
context.registerReceiver(br, intentFilter)
}
val webViewOptions = WebKitWebViewActivity.Options(options.url, options.redirectURI)
webViewOptions.actionBarBackgroundColor = this@WebKitWebViewUIImplementation.actionBarBackgroundColor
webViewOptions.actionBarButtonTintColor = this@WebKitWebViewUIImplementation.actionBarButtonTintColor
Expand Down
1 change: 1 addition & 0 deletions sdk/src/main/java/com/oursky/authgear/WebViewActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ internal class WebViewActivity : AppCompatActivity() {
private fun sendEndBroadcast() {
this.intent.getStringExtra(KEY_BROADCAST_ACTION)?.let { broadcastAction ->
val broadcastIntent = Intent(broadcastAction)
broadcastIntent.setPackage(this.applicationContext.packageName)
broadcastIntent.putExtra(KEY_BROADCAST_TYPE, BroadcastType.END.name)
this.sendBroadcast(broadcastIntent)
}
Expand Down
6 changes: 5 additions & 1 deletion sdk/src/main/java/com/oursky/authgear/app2app/App2App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ internal class App2App(
k.resume(Uri.parse(resultUri))
}
}
application.registerReceiver(br, intentFilter)
if (Build.VERSION.SDK_INT >= 33) {
application.registerReceiver(br, intentFilter, Context.RECEIVER_NOT_EXPORTED)
} else {
application.registerReceiver(br, intentFilter)
}
application.startActivity(intent)
}
}
Expand Down

0 comments on commit 34a1a5d

Please sign in to comment.