-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02bed6f
commit c1e8e80
Showing
16 changed files
with
842 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.descope.flutter"> | ||
<application> | ||
<activity | ||
android:name=".DescopeHelperActivity" | ||
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden" | ||
android:enabled="true" | ||
android:exported="false" | ||
android:fitsSystemWindows="true" | ||
android:theme="@style/Theme.Hidden" /> | ||
</application> | ||
</manifest> |
63 changes: 63 additions & 0 deletions
63
android/src/main/kotlin/com/descope/flutter/DescopeHelperActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.descope.flutter | ||
|
||
import android.app.Activity | ||
import android.app.PendingIntent | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Bundle | ||
|
||
const val PENDING_INTENT_KEY = "pendingIntent" | ||
const val REQUEST_CODE = 4327 | ||
|
||
class DescopeHelperActivity : Activity() { | ||
private var resultPending = false | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
@Suppress("DEPRECATION") | ||
val pendingIntent: PendingIntent? = intent?.getParcelableExtra(PENDING_INTENT_KEY) | ||
if (pendingIntent == null) { | ||
finish() | ||
return | ||
} | ||
|
||
if (resultPending) { | ||
finish() | ||
return | ||
} | ||
|
||
resultPending = true | ||
startIntentSenderForResult(pendingIntent.intentSender, REQUEST_CODE, null, 0, 0, 0, null) | ||
} | ||
|
||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | ||
super.onActivityResult(requestCode, resultCode, data) | ||
resultPending = false | ||
activityHelper.onActivityResult(resultCode, data) | ||
finish() | ||
} | ||
} | ||
|
||
// Helper | ||
|
||
interface ActivityHelper { | ||
fun startHelperActivity(context: Context, pendingIntent: PendingIntent, callback: (Int, Intent?) -> Unit) | ||
fun onActivityResult(resultCode: Int, intent: Intent?) | ||
} | ||
|
||
internal val activityHelper = object : ActivityHelper { | ||
private var callback: (Int, Intent?) -> Unit = { _, _ -> } | ||
|
||
override fun startHelperActivity(context: Context, pendingIntent: PendingIntent, callback: (Int, Intent?) -> Unit) { | ||
this.callback = callback | ||
(context as? Activity)?.let { activity -> | ||
activity.startActivity(Intent(activity, DescopeHelperActivity::class.java).apply { putExtra(PENDING_INTENT_KEY, pendingIntent) }) | ||
return | ||
} | ||
throw Exception("Passkeys require the given context to be an Activity") | ||
} | ||
|
||
override fun onActivityResult(resultCode: Int, intent: Intent?) { | ||
callback(resultCode, intent) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.