Skip to content

Commit

Permalink
Fix Android 14 broadcast receiver #194
Browse files Browse the repository at this point in the history
ref DEV-1513
  • Loading branch information
tung2744 authored Jul 10, 2024
2 parents 8607225 + 8b724a4 commit 59600e8
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 38 deletions.
34 changes: 11 additions & 23 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ on:

jobs:
gh-pages:
runs-on: macos-12
runs-on: macos-13
needs: ["app"]
steps:
# The default Java on macos-12 is 8, we need 17
# https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md#java
- name: Set java version
run: |
echo "JAVA_HOME=$JAVA_HOME_17_X64" >> $GITHUB_ENV
# The default Java on macos-13 is 17. So we no longer need to set it.
# https://github.com/actions/runner-images/blob/main/images/macos/macos-13-Readme.md#java
- uses: actions/checkout@v3
- run: make docs
- name: Deploy docs to gh-pages
Expand All @@ -29,31 +26,22 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./build/dokka/htmlMultiModule
test:
runs-on: macos-12
runs-on: macos-13
steps:
# The default Java on macos-12 is 8, we need 17
# https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md#java
- name: Set java version
run: |
echo "JAVA_HOME=$JAVA_HOME_17_X64" >> $GITHUB_ENV
# The default Java on macos-13 is 17. So we no longer need to set it.
# https://github.com/actions/runner-images/blob/main/images/macos/macos-13-Readme.md#java
- uses: actions/checkout@v3
- name: Build sdk
run: ./gradlew sdk:assembleRelease
- name: Build sdk-okhttp
run: ./gradlew sdk-okhttp:assembleRelease
app:
runs-on: macos-12
runs-on: macos-13
needs: ["test"]
if: github.ref == 'refs/heads/main'
env:
# The version depends on the Android Gradle Plugin version in /build.gradle.kts
BUILD_TOOLS_VERSION: "33.0.1"
steps:
# The default Java on macos-12 is 8, we need 17
# https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md#java
- name: Set java version
run: |
echo "JAVA_HOME=$JAVA_HOME_17_X64" >> $GITHUB_ENV
# The default Java on macos-13 is 17. So we no longer need to set it.
# https://github.com/actions/runner-images/blob/main/images/macos/macos-13-Readme.md#java
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
Expand All @@ -73,14 +61,14 @@ jobs:
echo -n "$ANDROID_KEYSTORE_BASE64" | base64 --decode -o $KEYSTORE_PATH
- name: Run zipalign
run: |
"$ANDROID_HOME/build-tools/$BUILD_TOOLS_VERSION/zipalign" -c -v 4 ./javasample/build/outputs/apk/release/javasample-release-unsigned.apk
"$ANDROID_HOME/build-tools/34.0.0/zipalign" -c -v 4 ./javasample/build/outputs/apk/release/javasample-release-unsigned.apk
- name: Run apksigner
env:
ANDROID_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
ANDROID_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
run: |
"$ANDROID_HOME/build-tools/$BUILD_TOOLS_VERSION/apksigner" sign \
"$ANDROID_HOME/build-tools/34.0.0/apksigner" sign \
--ks $RUNNER_TEMP/keystore.jks \
--ks-key-alias "$ANDROID_KEY_ALIAS" \
--ks-pass "pass:$ANDROID_KEYSTORE_PASSWORD" \
Expand Down
7 changes: 4 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ plugins {
// https://developer.android.com/build/releases/gradle-plugin#8-1-0
// If you ever update Android Gradle Plugin, please also update
// BUILD_TOOLS_VERSION in ./.github/workflows/ci.yaml
id("com.android.library") version "8.1.2" apply false
id("com.android.application") version "8.1.2" apply false
id("org.jetbrains.kotlin.android") version "1.9.0" apply false
id("com.android.library") version "8.5.0" apply false
id("com.android.application") version "8.5.0" apply false
id("org.jetbrains.kotlin.android") version "1.9.23" apply false
kotlin("plugin.serialization") version "1.9.20" apply false
id("org.jetbrains.dokka") version "1.9.10"
id("maven-publish")
}

subprojects {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Sep 17 15:50:04 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
10 changes: 7 additions & 3 deletions javasample/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import java.util.Properties

plugins {
id("com.android.application") version "8.1.2"
id("com.android.application")
}

val localProperties = Properties()
Expand All @@ -14,17 +14,19 @@ if (localPropertiesFile.exists()) {

android {
namespace = "com.oursky.authgeartest"
compileSdk = 33
compileSdk = 34
buildToolsVersion = "34.0.0"

buildFeatures {
buildConfig = true
}

defaultConfig {
multiDexEnabled = true
applicationId = "com.authgear.exampleapp.android"
// minSdk is set to 23 so that we do not need version check to use biometric and app2app.
minSdk = 23
targetSdk = 33
targetSdk = 34
versionCode = 1
versionName = "1.0"

Expand All @@ -45,12 +47,14 @@ android {
}

compileOptions {
isCoreLibraryDesugaringEnabled = true
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}

dependencies {
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.3")
implementation(project(mapOf("path" to ":sdk")))
implementation("androidx.appcompat:appcompat:1.2.0")
implementation("androidx.lifecycle:lifecycle-viewmodel:2.2.0")
Expand Down
2 changes: 2 additions & 0 deletions jitpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
jdk:
- openjdk17
22 changes: 20 additions & 2 deletions sdk-okhttp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
kotlin("plugin.serialization")
id("maven-publish")
}

android {
namespace = "com.oursky.authgear.okhttp"
compileSdk = 32
compileSdk = 34

defaultConfig {
minSdk = 21
multiDexEnabled = true
aarMetadata {
minCompileSdk = 21
}

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -50,3 +54,17 @@ dependencies {
androidTestImplementation("androidx.test.ext:junit:1.1.2")
androidTestImplementation("androidx.test.espresso:espresso-core:3.3.0")
}

publishing {
publications {
register<MavenPublication>("release") {
groupId = findProperty("group") as String
artifactId = "authgear-sdk-android-okhttp"
version = findProperty("version") as String

afterEvaluate {
from(components["release"])
}
}
}
}
22 changes: 20 additions & 2 deletions sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
kotlin("plugin.serialization")
id("maven-publish")
}

android {
namespace = "com.oursky.authgear"
compileSdk = 32
compileSdk = 34

defaultConfig {
minSdk = 21
multiDexEnabled = true
aarMetadata {
minCompileSdk = 21
}

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -57,3 +61,17 @@ dependencies {
androidTestImplementation("androidx.test.ext:junit:1.1.2")
androidTestImplementation("androidx.test.espresso:espresso-core:3.3.0")
}

publishing {
publications {
register<MavenPublication>("release") {
groupId = findProperty("group") as String
artifactId = "authgear-sdk-android"
version = findProperty("version") as String

afterEvaluate {
from(components["release"])
}
}
}
}
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 59600e8

Please sign in to comment.