From bc08760ec920ca891d4b43ebd6b2e9512fc927f5 Mon Sep 17 00:00:00 2001 From: Simon Hagen Date: Wed, 3 Apr 2024 10:22:47 +0200 Subject: [PATCH] =?UTF-8?q?[MWA-3546]=20Integration=20Demo=20f=C3=BCr=20Pr?= =?UTF-8?q?oductCatalog=20erstellen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit { add initial project } --- README.md | 70 +++++++ app/.gitignore | 1 + app/build.gradle | 83 ++++++++ app/proguard-rules.pro | 21 ++ app/src/LICENSE | 1 + app/src/main/AndroidManifest.xml | 23 +++ .../metaplugindemo/EWebIdEnv.kt | 62 ++++++ .../metaplugindemo/MainActivity.kt | 195 ++++++++++++++++++ .../metaplugindemo/tasks/AsyncTaskResult.java | 27 +++ .../metaplugindemo/tasks/EApiResult.kt | 107 ++++++++++ .../tasks/IOnPostExecuteCallback.java | 15 ++ .../tasks/MetaPluginVerifyTask.kt | 92 +++++++++ .../tasks/VerifyActionIdTask.java | 70 +++++++ .../drawable-v24/ic_launcher_foreground.xml | 15 ++ app/src/main/res/layout/activity_main.xml | 110 ++++++++++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 4 + app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 2025 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 3785 bytes app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 1302 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2334 bytes app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 2766 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 5307 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 4127 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 8398 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 5523 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 11922 bytes app/src/main/res/values-night/themes.xml | 13 ++ app/src/main/res/values/colors.xml | 12 ++ app/src/main/res/values/dimens.xml | 6 + .../res/values/ic_launcher_background.xml | 4 + app/src/main/res/values/strings.xml | 6 + app/src/main/res/values/themes.xml | 13 ++ build.gradle | 10 + gradle.properties | 34 +++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 59203 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 185 +++++++++++++++++ gradlew.bat | 89 ++++++++ settings.gradle | 22 ++ 40 files changed, 1301 insertions(+) create mode 100644 README.md create mode 100644 app/.gitignore create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/LICENSE create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/de/webidsolutions/metaplugindemo/EWebIdEnv.kt create mode 100644 app/src/main/java/de/webidsolutions/metaplugindemo/MainActivity.kt create mode 100644 app/src/main/java/de/webidsolutions/metaplugindemo/tasks/AsyncTaskResult.java create mode 100644 app/src/main/java/de/webidsolutions/metaplugindemo/tasks/EApiResult.kt create mode 100644 app/src/main/java/de/webidsolutions/metaplugindemo/tasks/IOnPostExecuteCallback.java create mode 100644 app/src/main/java/de/webidsolutions/metaplugindemo/tasks/MetaPluginVerifyTask.kt create mode 100644 app/src/main/java/de/webidsolutions/metaplugindemo/tasks/VerifyActionIdTask.java create mode 100644 app/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/values-night/themes.xml create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/dimens.xml create mode 100644 app/src/main/res/values/ic_launcher_background.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/themes.xml create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle diff --git a/README.md b/README.md new file mode 100644 index 0000000..7e0d4e3 --- /dev/null +++ b/README.md @@ -0,0 +1,70 @@ +# MetaPlugin Demo Android + +This project demonstrates how to embed the WebID Meta Plugin into an Android App. +The code of the project is described with comments on how to use it. + +## Tutorial + +To start the plugin in this example project, open the gradle.properties file. +You will find empty credential properties at the bottom.
+You should have been given a username and a password to access your environment.
+Navigate to the ~/.gradle/gradle.properties file on your system.. +If it does not exist, create it.
+Enter the properties for your preferred platform. + +To begin the identification process, you will need to create it outside the app.
+From the process creation request to the server, you should have received an action-id, consisting of 9 numbers. + +After that, open the MainActivity.kt file and finish the three TODOs at the top. +
    +
  1. choose video call configs
  2. +
  3. insert your 9-digit action id
  4. +
  5. choose an environment to use
  6. +
+ +After that, start the demo app on an android device.
+Press the main button to start the plugin at runtime. + + +## Fastened Tutorial + +
    +
  1. Add usernames and passwords in your ~/.gradle/gradle.properties file
  2. +
  3. Create a transaction via backend API
  4. +
  5. Set video-call configs in MainActivity.kt
  6. +
  7. Replace placeholder string of action-id in MainActivity.kt with action-id from process-creation response
  8. +
  9. Choose environment in MainActivity.kt
  10. +
  11. Start this app on a test device
  12. +
  13. Click main button to start the plugin at runtime
  14. +
+ + +## Additional Notes + +On Samsung Devices, configurations should be changed. +In MainActivity.kt, go to +
private val config = VideoOptionsConfig(true, false, false)
+and set the booleans according to the chapter + +>The VideoOptionsConfig object + +in the Integration Guide. + + +## Theming (Optional) + +The plugin implemented in this project supports customized theming.
+To try out different themes, go to the file src/main/res/values/themes.xml and add items to the following element: + +``` + +``` + +Consult the theming guide to see what items can be changed.
+To change the Dark mode theming, navigate to the file src/main/res/values-night/themes.xml and add items to the following element: + +``` + +``` \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..bdc8e32 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,83 @@ +plugins { + id 'com.android.application' + id 'org.jetbrains.kotlin.android' +} + +android { + compileSdk 34 + + namespace "de.webidsolutions.metaplugindemo" + + defaultConfig { + applicationId "de.webidsolutions.metaplugindemo" + minSdkVersion 24 + targetSdkVersion 34 + versionCode 1 + versionName "1.0.0" + + buildConfigField "String", "WEBID_DEMO_USERNAME_TEST", "\"${WEBID_DEMO_USERNAME_TEST}\"" + buildConfigField "String", "WEBID_DEMO_APIKEY_TEST", "\"${WEBID_DEMO_APIKEY_TEST}\"" + buildConfigField "String", "WEBID_DEMO_USERNAME_PROD", "\"${WEBID_DEMO_USERNAME_PROD}\"" + buildConfigField "String", "WEBID_DEMO_APIKEY_PROD", "\"${WEBID_DEMO_APIKEY_PROD}\"" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } + buildFeatures { + buildConfig true + } + + packagingOptions { + pickFirst 'lib/x86/libc++_shared.so' + pickFirst 'lib/arm64-v8a/libc++_shared.so' + pickFirst 'lib/x86_64/libc++_shared.so' + pickFirst 'lib/armeabi-v7a/libc++_shared.so' + jniLibs { useLegacyPackaging = true } + } +} + +dependencies { + + // android dependencies from demo app + implementation 'androidx.core:core-ktx:1.12.0' + implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.5' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' + + // webid product-plugin + //noinspection GradleDependency + + def product_catalog_version = "12.0.0" + implementation ("de.webid-solutions:android_meta_plugin:$product_catalog_version") { + changing = true + } + + implementation ("de.webid-solutions:android_auto_ident_on_server_product_plugin:$product_catalog_version") { + changing = true + } + implementation ("de.webid-solutions:android_pay_on_server_product_plugin:$product_catalog_version") { + changing = true + } + implementation ("de.webid-solutions:android_video_ident_product_plugin:$product_catalog_version") { + changing = true + } + implementation ("de.webid-solutions:android_eid_on_server_product_plugin:$product_catalog_version") { + changing = true + } + +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/LICENSE b/app/src/LICENSE new file mode 100644 index 0000000..989eb08 --- /dev/null +++ b/app/src/LICENSE @@ -0,0 +1 @@ +Copyright (C) 2013 - 2024 WebID Solutions GmbH | www.webid-solutions.de. All Rights Reserved diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..6790534 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/de/webidsolutions/metaplugindemo/EWebIdEnv.kt b/app/src/main/java/de/webidsolutions/metaplugindemo/EWebIdEnv.kt new file mode 100644 index 0000000..3bc7f25 --- /dev/null +++ b/app/src/main/java/de/webidsolutions/metaplugindemo/EWebIdEnv.kt @@ -0,0 +1,62 @@ +/* + * Created by WebID Solutions GmbH | www.webid-solutions.de. + * See the file "LICENSE" for the full license governing this code. + */ +package de.webidsolutions.metaplugindemo + +import java.net.URI + +/** + * Environment configuration for WebID endpoints for test usage. + */ +enum class EWebIDEnv( + + /** + * Username of the client + * Used for authentication of the client. + */ + internal val username: String, + + /** + * API Key of the client + * Used for authentication of the client. + */ + internal val apiKey: String, + + /** + * The uri of the environment. + * Used to determine the backend. + */ + internal val uri: URI, + + /** + * Sha pins of the environment. + * Used for authentication + */ + internal val shaPins: Array +) { + + /** + * WebID TEST environment. + */ + TEST( + BuildConfig.WEBID_DEMO_USERNAME_TEST, + BuildConfig.WEBID_DEMO_APIKEY_TEST, + URI.create("https://test.webid-solutions.de/"), + arrayOf( + "sha256/WcFCbp232usb2PlWzs2PYdr5K7pm21EG6kBms5LUDfY=" // expires 2025.02.22 + ) + ), + + /** + * WebID PRODUCTION environment. + */ + PRODUCTION( + BuildConfig.WEBID_DEMO_USERNAME_PROD, + BuildConfig.WEBID_DEMO_APIKEY_PROD, + URI.create("https://webid-gateway.de/"), + arrayOf( + "sha256/FJ8bpW+Zzu86wDBFYA6GygAhw7DbpY10oDmtJl46Hdw=" // expires 2024.11.02 + ) + ); +} \ No newline at end of file diff --git a/app/src/main/java/de/webidsolutions/metaplugindemo/MainActivity.kt b/app/src/main/java/de/webidsolutions/metaplugindemo/MainActivity.kt new file mode 100644 index 0000000..d599c70 --- /dev/null +++ b/app/src/main/java/de/webidsolutions/metaplugindemo/MainActivity.kt @@ -0,0 +1,195 @@ +/* + * Created by WebID Solutions GmbH | www.webid-solutions.de. + * See the file "LICENSE" for the full license governing this code. + */ +package de.webidsolutions.metaplugindemo + +import android.annotation.SuppressLint +import android.os.Bundle +import android.widget.Button +import android.widget.CheckBox +import android.widget.TextView +import androidx.activity.result.ActivityResult +import androidx.activity.result.contract.ActivityResultContracts +import androidx.appcompat.app.AppCompatActivity +import de.webidsolutions.auto_ident_on_server_product_plugin.AutoIdentOnServerProductPlugin +import de.webidsolutions.eid_on_server_product_plugin.EIdOnServerProductPlugin +import de.webidsolutions.meta_plugin.WebIdMetaPlugin +import de.webidsolutions.mobile_app.sdk.WebIdMobileAppSdkException +import de.webidsolutions.mobile_app.sdk.WebIdSdkEnvironment +import de.webidsolutions.mobile_app.sdk.domain.VerifyActionIdResult +import de.webidsolutions.mobile_app.sdk.impl.AsyncTaskResultGeneric +import de.webidsolutions.pay_on_server_product_plugin.PayOnServerProductPlugin +import de.webidsolutions.plugin_core.IProductPluginWebId +import de.webidsolutions.video_ident.plugin.videocall.VideoOptionsConfig +import de.webidsolutions.video_ident_product_plugin.VideoIdentProductPlugin +import de.webidsolutions.metaplugindemo.tasks.EApiResult +import de.webidsolutions.metaplugindemo.tasks.MetaPluginVerifyTask +import java.lang.Integer.parseInt +import java.net.URI + +// TODO set your configs +private val config = VideoOptionsConfig( + true, + false, + false +) + +// TODO insert your Action id +private const val actionId = "136249502" + +// TODO choose your environment +private val chosenEnvironment: EWebIDEnv = EWebIDEnv.TEST +// private val chosenEnvironment: EWebIDEnv = EWebIDEnv.PRODUCTION + +/** + * Demo App which starts the [MetaPlugin] and handles its result. + */ +internal class MainActivity : AppCompatActivity() { + + private lateinit var videoPluginCb: CheckBox + private lateinit var eidOnServerPluginCb: CheckBox + private lateinit var payOnServerPluginCb: CheckBox + private lateinit var autoIdOnServerPluginCb: CheckBox + private lateinit var textLog: TextView + private lateinit var startButton: Button + +// private lateinit var coreSdk: IWebIdMobileAppSdk + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + textLog = findViewById(R.id.log) + + autoIdOnServerPluginCb = findViewById(R.id.cb_plugin_auto_id_on_server) + payOnServerPluginCb = findViewById(R.id.cb_plugin_pay_on_server) + eidOnServerPluginCb = findViewById(R.id.cb_plugin_eid_on_server) + videoPluginCb = findViewById(R.id.cb_plugin_video) + + startButton = findViewById(R.id.startButton) + startButton.setOnClickListener { + clearLog() + writeLog("Starting…") + createCoreSdk() + } + } + + /* CORE SDK */ + + /** + * Creates the Core SDK from the existing credentials. + */ + private fun createCoreSdk() { + writeLog("Creating the Core SDK…") + + // should be provided to you -> currently just using demo credentials + val selectedUri: URI = chosenEnvironment.uri + val username: String = chosenEnvironment.username + val apiKey: String = chosenEnvironment.apiKey + + // actual creation of the core SDK + val environment = WebIdSdkEnvironment( + selectedUri, + *chosenEnvironment.shaPins + ) + + writeLog("Core SDK creation successful") + validateActionId() + + val selectProductPlugins = getSelectedPlugins() + + val metaPlugin = WebIdMetaPlugin( + environment, + username, + apiKey, + this.applicationContext, + selectProductPlugins + ) + metaPlugin.setVideoConfig(config) + MetaPluginVerifyTask(metaPlugin) + .setOnPostExecuteCallback(metaPluginVerifyCallback(metaPlugin)) + .execute(actionId) + } + + /** + * Validates the WebID actionID + */ + private fun validateActionId() { + writeLog("Validate Action-ID…") + + try { + parseInt(actionId) + if (actionId.length != 9) { + throw NumberFormatException() + } + } catch (e: NumberFormatException) { + writeLog("Failure: action id was not set to 9-digit number string in MainActivity.kt file") + } + } + + // add result launcher for intent + private val activityResultLauncher = registerForActivityResult( + ActivityResultContracts.StartActivityForResult(), + this::onPluginResultCallback + ) + + private fun getSelectedPlugins(): ArrayList { + return ArrayList( + listOfNotNull( + if (autoIdOnServerPluginCb.isChecked) AutoIdentOnServerProductPlugin() else null, + if (payOnServerPluginCb.isChecked) PayOnServerProductPlugin() else null, + if (eidOnServerPluginCb.isChecked) EIdOnServerProductPlugin() else null, + if (videoPluginCb.isChecked) VideoIdentProductPlugin(VideoOptionsConfig()) else null + ) + ) + } + + private fun metaPluginVerifyCallback(metaPlugin: WebIdMetaPlugin): (AsyncTaskResultGeneric) -> Unit { + return { result -> + if (result.errorResult == EApiResult.SUCCESS) { + var verifyActionIdResult = result.result + try { + metaPlugin.startPlugin( + this, + activityResultLauncher, + R.style.CustomizedPluginTheme, + ) + } catch (e: WebIdMobileAppSdkException) { + e.printStackTrace() + writeLog(e.message.toString()) + } + } else { + val metaPluginVerifyError = result.errorResult + writeLog(metaPluginVerifyError.toString()) + } + } + } + + private fun onPluginResultCallback(result: ActivityResult?) { + var metaPluginActivityResult = result + + } + + + + + /* MISC */ + + /** + * Add an entry to the log. + * + * @param + */ + @SuppressLint("SetTextI18n") + private fun writeLog(entry: String) { + textLog.text = "${textLog.text} $entry\n" + } + + /** + * Resets the text log of this activity. + */ + private fun clearLog() { + textLog.text = "" + } +} \ No newline at end of file diff --git a/app/src/main/java/de/webidsolutions/metaplugindemo/tasks/AsyncTaskResult.java b/app/src/main/java/de/webidsolutions/metaplugindemo/tasks/AsyncTaskResult.java new file mode 100644 index 0000000..680a30b --- /dev/null +++ b/app/src/main/java/de/webidsolutions/metaplugindemo/tasks/AsyncTaskResult.java @@ -0,0 +1,27 @@ +/* + * Created by WebId Solutions GmbH | www.webid-solutions.de. + * See the file "LICENSE" for the full license governing this code. + */ +package de.webidsolutions.metaplugindemo.tasks; + +/** + * A simple structure for transporting the response of the AsyncTask + */ +public class AsyncTaskResult { + private final T result; + private final String apiResult; + + public T getResult() { + return result; + } + + public String getApiResult() { + return apiResult; + } + + public AsyncTaskResult(T result, String apiResult) { + + this.result = result; + this.apiResult = apiResult; + } +} diff --git a/app/src/main/java/de/webidsolutions/metaplugindemo/tasks/EApiResult.kt b/app/src/main/java/de/webidsolutions/metaplugindemo/tasks/EApiResult.kt new file mode 100644 index 0000000..6719b6c --- /dev/null +++ b/app/src/main/java/de/webidsolutions/metaplugindemo/tasks/EApiResult.kt @@ -0,0 +1,107 @@ +/* +* Created by WebID Solutions GmbH | www.webid-solutions.de. +* See the file "LICENSE" for the full license governing this code. +*/ +package de.webidsolutions.metaplugindemo.tasks + +enum class EApiResult(val messageKey: String, val messageID: Int, val fatal: Boolean) { + SUCCESS( + "api_success", + 0, + false + ), + ACTIONID_NOT_FOUND( + "apierror_actionid_not_found", + 0, + false + ), + ACTIONID_NOT_VALID( + "apierror_actionid_not_valid", + 0, + false + ), + ACCESS_DENIED( + "apierror_access_denied", + 0, + true + ), + IO_FAILURE( + "apierror_io_failure", + 0, + false + ), + ILLEGAL_ARGUMENT( + "apierror_illegal_argument", + 0, + true + ), + ILLEGAL_STATE( + "apierror_illegal_state", + 0, + true + ), + TAN_INCORRECT( + "apierror_tan_incorrect", + 0, + false + ), + TAN_ILLEGAL_STATE( + "apierror_tan_illegal_state", + 0, + false + ), + PRECHECK_REQUIRED( + "apierror_precheck_required", + 0, + true + ), + ECHECK_REQUIRED( + "apierror_echeck_required", + 0, + true + ), + LEGALNOTICES_CONFIRMATION_MISSING( + "apierror_legalnotices_confirmation_missing", + 0, + true + ), + AUTOIDENT_REQUIRED( + "apierror_autoident_required", + 0, + true + ), + SHOW_ENDUSERDIALOG( + "apierror_show_enduserdialog", + 0, + true + ), + EID_AUTHADA_REQUIRED( + "apierror_eid_authada_required", + 0, + true + ), + IDENT_NOT_SUPPORTED( + "apierror_ident_not_supported", + 0, + true + ), + USER_ACTION_NOT_FINISHED( + "apierror_user_action_not_finished", + 0, + false + ), //497 + SERVICE_UNAVAILABLE( + "apierror_service_unavailable", + 0, + true + ), + SESSION_EXPIRED( + "apierror_session_expired", + 0, + true + ); + + var extInfo = "" + var extInfo2 = "" + +} diff --git a/app/src/main/java/de/webidsolutions/metaplugindemo/tasks/IOnPostExecuteCallback.java b/app/src/main/java/de/webidsolutions/metaplugindemo/tasks/IOnPostExecuteCallback.java new file mode 100644 index 0000000..85acf11 --- /dev/null +++ b/app/src/main/java/de/webidsolutions/metaplugindemo/tasks/IOnPostExecuteCallback.java @@ -0,0 +1,15 @@ +/* + * Created by WebId Solutions GmbH | www.webid-solutions.de. + * See the file "LICENSE" for the full license governing this code. + */ +package de.webidsolutions.metaplugindemo.tasks; + +/** + * Callback interface for the demo verify api-call. + * Is executed after AsyncTask callback. + * + * @param the type of the callback response + */ +public interface IOnPostExecuteCallback { + void onPostExecute(T result); +} diff --git a/app/src/main/java/de/webidsolutions/metaplugindemo/tasks/MetaPluginVerifyTask.kt b/app/src/main/java/de/webidsolutions/metaplugindemo/tasks/MetaPluginVerifyTask.kt new file mode 100644 index 0000000..2a40547 --- /dev/null +++ b/app/src/main/java/de/webidsolutions/metaplugindemo/tasks/MetaPluginVerifyTask.kt @@ -0,0 +1,92 @@ +/* +* Created by WebID Solutions GmbH | www.webid-solutions.de. +* See the file "LICENSE" for the full license governing this code. +*/ +package de.webidsolutions.metaplugindemo.tasks + +import de.webidsolutions.meta_plugin.WebIdMetaPlugin +import de.webidsolutions.mobile_app.sdk.EidIdentRequiredException +import de.webidsolutions.mobile_app.sdk.IdentNotSupportedException +import de.webidsolutions.mobile_app.sdk.LegalTermsConfirmationMissingException +import de.webidsolutions.mobile_app.sdk.ServiceUnavailableException +import de.webidsolutions.mobile_app.sdk.UserActionNotFinishedException +import de.webidsolutions.mobile_app.sdk.UserActionNotFoundException +import de.webidsolutions.mobile_app.sdk.domain.VerifyActionIdResult +import de.webidsolutions.mobile_app.sdk.impl.AsyncTaskResultGeneric +import de.webidsolutions.mobile_app.sdk.impl.IOnPostExecuteCallback +import de.webidsolutions.mobile_app.sdk.impl.WebIdAsyncTask +import java.io.IOException + +internal class MetaPluginVerifyTask( + private val metaPlugin: WebIdMetaPlugin +) : WebIdAsyncTask>() { + + private var metaPluginVerifyOnPostExecuteCallback: IOnPostExecuteCallback>? = + null + + override fun doInBackground(vararg params: String): AsyncTaskResultGeneric { + val apiResult = try { + return AsyncTaskResultGeneric(metaPlugin.verify(params[0]), EApiResult.SUCCESS) + } catch (e: IllegalArgumentException) { + e.printStackTrace() + if (e.message!!.startsWith("actionId")) { + EApiResult.ACTIONID_NOT_VALID + } else { + EApiResult.ILLEGAL_ARGUMENT + } + } catch (e: LegalTermsConfirmationMissingException) { + e.printStackTrace() + if (e.message!!.startsWith("actionId")) { + EApiResult.ACTIONID_NOT_VALID + } else { + EApiResult.ILLEGAL_ARGUMENT + } + } catch (e: UserActionNotFinishedException) { + e.printStackTrace() + if (e.message!!.startsWith("actionId")) { + EApiResult.ACTIONID_NOT_VALID + } else { + EApiResult.ILLEGAL_ARGUMENT + } + } catch (e: IdentNotSupportedException) { + e.printStackTrace() + if (e.message!!.startsWith("actionId")) { + EApiResult.ACTIONID_NOT_VALID + } else { + EApiResult.ILLEGAL_ARGUMENT + } + } catch (e: EidIdentRequiredException) { + e.printStackTrace() + if (e.message!!.startsWith("actionId")) { + EApiResult.ACTIONID_NOT_VALID + } else { + EApiResult.ILLEGAL_ARGUMENT + } + } catch (e: AccessDeniedException) { + e.printStackTrace() + EApiResult.ACCESS_DENIED.apply { extInfo = e.message!! } + } catch (e: UserActionNotFoundException) { + e.printStackTrace() + EApiResult.ACTIONID_NOT_FOUND + } catch (e: IOException) { + e.printStackTrace() + EApiResult.IO_FAILURE.apply { extInfo = e.message!! } + } catch (e: IllegalStateException) { + e.printStackTrace() + EApiResult.ILLEGAL_STATE + } catch (e: ServiceUnavailableException) { + e.printStackTrace() + EApiResult.SERVICE_UNAVAILABLE + } + return AsyncTaskResultGeneric(null, apiResult) + } + + override fun onPostExecute(result: AsyncTaskResultGeneric?) { + metaPluginVerifyOnPostExecuteCallback?.let { clb -> result?.let { clb.onPostExecute(it) } } + } + + fun setOnPostExecuteCallback(onPostExecuteCallback: IOnPostExecuteCallback>): MetaPluginVerifyTask { + metaPluginVerifyOnPostExecuteCallback = onPostExecuteCallback + return this + } +} diff --git a/app/src/main/java/de/webidsolutions/metaplugindemo/tasks/VerifyActionIdTask.java b/app/src/main/java/de/webidsolutions/metaplugindemo/tasks/VerifyActionIdTask.java new file mode 100644 index 0000000..6babcfd --- /dev/null +++ b/app/src/main/java/de/webidsolutions/metaplugindemo/tasks/VerifyActionIdTask.java @@ -0,0 +1,70 @@ +/* + * Created by WebId Solutions GmbH | www.webid-solutions.de. + * See the file "LICENSE" for the full license governing this code. + */ +package de.webidsolutions.metaplugindemo.tasks; + +import android.os.AsyncTask; + +import java.io.IOException; + +import de.webidsolutions.mobile_app.sdk.AccessDeniedException; +import de.webidsolutions.mobile_app.sdk.EidIdentRequiredException; +import de.webidsolutions.mobile_app.sdk.IWebIdMobileAppSdk; +import de.webidsolutions.mobile_app.sdk.IdentNotSupportedException; +import de.webidsolutions.mobile_app.sdk.LegalTermsConfirmationMissingException; +import de.webidsolutions.mobile_app.sdk.ServiceUnavailableException; +import de.webidsolutions.mobile_app.sdk.UserActionNotFinishedException; +import de.webidsolutions.mobile_app.sdk.UserActionNotFoundException; +import de.webidsolutions.mobile_app.sdk.domain.VerifyActionIdResult; + +/** + * A asynchronous call for sdkInstance.verifyActionId(params[0]). + * Only implemented inside an AsyncTask for demo purposes. + * Can be also be done via other means, e.g. coroutines. + */ +public class VerifyActionIdTask extends AsyncTask> { + private IOnPostExecuteCallback> iVerifyActionIdInternalOnPostExecuteCallback; + private final IWebIdMobileAppSdk sdkInstance; + + @Override + protected AsyncTaskResult doInBackground(String... params) { + + String apiResult; + + try { + + return new AsyncTaskResult<>(sdkInstance.verifyActionId(params[0]), "success"); + + } catch ( + IdentNotSupportedException | + UserActionNotFinishedException | + AccessDeniedException | + EidIdentRequiredException | + LegalTermsConfirmationMissingException | + IOException | + ServiceUnavailableException | + UserActionNotFoundException e + ) { + apiResult = e.getClass().getSimpleName(); + } + + return new AsyncTaskResult<>(null, apiResult); + } + + public VerifyActionIdTask(IWebIdMobileAppSdk sdkInstance) { + this.sdkInstance = sdkInstance; + } + + @Override + protected void onPostExecute(AsyncTaskResult data) { + if (iVerifyActionIdInternalOnPostExecuteCallback != null) { + iVerifyActionIdInternalOnPostExecuteCallback.onPostExecute(data); + } + } + + public VerifyActionIdTask setOnPostExecuteCallback(IOnPostExecuteCallback> onPostExecuteCallback) { + this.iVerifyActionIdInternalOnPostExecuteCallback = onPostExecuteCallback; + return this; + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..7ec9b21 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,15 @@ + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..d6727bd --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +