Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Release 19-04-2023] Android stability improvements & developer compatibility enhancements #58

Merged
merged 31 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
15ae123
Merge pull request #50 from mosip/release/0.3.x
krishnakumar4a4 Mar 28, 2023
5917ad1
docs(#413): update ble capture steps for multiple android devices
krishnakumar4a4 Mar 28, 2023
89f2dff
docs(#413): add tuvali spec implementation document with technical fl…
krishnakumar4a4 Mar 28, 2023
696361b
feat(#583): [Shree] [iOS] added exception handler for wallet
shreethaanu Mar 29, 2023
dbe7301
feat(#583): [Shree] [iOS] added exception handler for wallet
shreethaanu Mar 30, 2023
68b7a26
feat(#583): [Shree] [iOS] added exception handler for verifier and re…
shreethaanu Mar 30, 2023
3d9521e
feat(#583): [Shree] [iOS] addressed PR Comments
shreethaanu Apr 3, 2023
f3dcb36
feat(#702): run Openid4vpBleModule public function under try and catch
tilak-puli Apr 3, 2023
1abfc0e
feat(#702): add root level exception handler at react native module
tilak-puli Apr 3, 2023
1e42858
feat(#583): [Shree] [iOS] addressed PR Comments
shreethaanu Apr 3, 2023
cc864ca
feat(#702): remove root level exception handler at react native module
tilak-puli Apr 3, 2023
3f0b407
feat(#583): [Shree] [iOS] changed info logs to error logs
shreethaanu Apr 4, 2023
17635b3
feat(#702): fix stop ble -> error handling cyclic issue
tilak-puli Apr 5, 2023
fff52f2
feat(#583): [Shree] [iOS] fixed pr comments
shreethaanu Apr 11, 2023
dbb7d74
refactor(#583): error handling and rename identifiers
krishnakumar4a4 Apr 12, 2023
f5a5777
chore: [iOS] fix compilation errors in Errorhandler
vharsh Apr 12, 2023
f7aea5b
chore: fix compilation errors
vharsh Apr 12, 2023
a8c9164
chore: [iOS] avoid force unwrap of identifier
vharsh Apr 13, 2023
e04c307
Merge pull request #43 from ravikp/add-exception-handling-to-android-…
krishnakumar4a4 Apr 13, 2023
d11c883
feat(#702): catch throwable instead of Exception
tilak-puli Apr 17, 2023
2821e25
refactor(mosip#696): [Kiruthika] Remove example folder and its relate…
KiruthikaJeyashankar Apr 17, 2023
ade32a1
feat(#702): catch throwable instead of Exception
tilak-puli Apr 17, 2023
d9912dd
chore: bump up tuvali version for 19-04-2023 release
vharsh Apr 19, 2023
c6a2231
Merge pull request #52 from tw-mosip/add-exception-handling-to-androi…
Alka1703 Apr 19, 2023
00e6d5d
refactor(#702): make wallet and verifier to leverage try execute sync…
krishnakumar4a4 Apr 17, 2023
7f3bebd
refactor(#702): handle causes of wrapped exceptions
krishnakumar4a4 Apr 18, 2023
8d60302
fix(#702): wallet and verifier exceptions are not caught by try execu…
krishnakumar4a4 Apr 19, 2023
73d989a
feat(#702): fix import issue
tilak-puli Apr 19, 2023
474e1ab
Merge pull request #53 from tw-mosip/add-exception-handling-to-androi…
krishnakumar4a4 Apr 19, 2023
e2b89bb
Merge pull request #54 from tw-mosip/handle-uncaught-exception
krishnakumar4a4 Apr 19, 2023
7a6ecdc
docs(#413): rename to markdown file
krishnakumar4a4 Apr 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ interface ICentralListener {
fun onSubscriptionFailure(charUUID: UUID, err: Int)
fun onNotificationReceived(charUUID: UUID, value: ByteArray?)
fun onClosed()
fun onException(exception: Throwable)
fun onException(exception: Exception)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ const val MTU_HEADER_SIZE = 3
const val REQUEST_MTU_TIME_OUT = -1

class Controller(val context: Context) {
private lateinit var scanner: Scanner
private val logTag = getLogTag(javaClass.simpleName)

private var gattClient: GattClient? = null
private var scanner: Scanner? = null
private lateinit var messageSender: IMessageSender
private var requestedMTUValue = -1
private lateinit var mtuValues : Array<Int>
Expand All @@ -34,7 +34,7 @@ class Controller(val context: Context) {

fun scan(scanStartMessage: ScanStartMessage) {
scanner = Scanner(context)
scanner.start(
scanner?.start(
scanStartMessage.serviceUUID,
scanStartMessage.advPayload,
this::onDeviceFound,
Expand All @@ -43,7 +43,7 @@ class Controller(val context: Context) {
}

fun stopScan() {
scanner.stopScan()
scanner?.stopScan()
}

@SuppressLint("MissingPermission")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class StateHandler(
override fun dispatchMessage(msg: Message) {
try {
super.dispatchMessage(msg)
} catch (e: Throwable) {
} catch (e: Exception) {
listener.onException(StateHandlerException("Exception in Central State Handler", e))
Log.d(logTag, "dispatchMessage " + e.message)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ interface IPeripheralListener {
fun onSendDataNotified(uuid: UUID, isSent: Boolean)
fun onClosed()
fun onMTUChanged(mtu: Int)
fun onException(exception: Throwable)
fun onException(exception: Exception)
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class StateHandler(
override fun dispatchMessage(msg: Message) {
try {
super.dispatchMessage(msg)
} catch (e: Throwable) {
} catch (e: Exception) {
peripheralListener.onException(StateHandlerException("Exception in Peripheral State Handler", e))
Log.d(logTag, "dispatchMessage " + e.message)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.mosip.tuvali.common.safeExecute

import io.mosip.tuvali.openid4vpble.exception.OpenIdBLEExceptionHandler

class TryExecuteSync(private val bleExceptionHandler: OpenIdBLEExceptionHandler) {
private val mutex = Object()

fun <T> run(fn: () -> T): T? {
var returnValue: T? = null;

synchronized(mutex) {
try {
returnValue = fn()
} catch (e: Exception) {
bleExceptionHandler.handleException(Exception("Unknown Exception", e))
}
}

return returnValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,20 @@ package io.mosip.tuvali.openid4vpble
import android.util.Log
import com.facebook.react.bridge.*
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter
import io.mosip.tuvali.verifier.Verifier
import io.mosip.tuvali.wallet.Wallet
import io.mosip.tuvali.common.safeExecute.TryExecuteSync
import io.mosip.tuvali.openid4vpble.exception.OpenIdBLEExceptionHandler
import org.json.JSONObject
import io.mosip.tuvali.transfer.Util.Companion.getLogTag
import io.mosip.tuvali.verifier.Verifier
import io.mosip.tuvali.wallet.Wallet

class Openid4vpBleModule(private val reactContext: ReactApplicationContext) :
ReactContextBaseJavaModule(reactContext) {
private val logTag = getLogTag(javaClass.simpleName)
private var verifier: Verifier? = null
private var wallet: Wallet? = null
private val mutex = Object()
private var walletExceptionHandler = OpenIdBLEExceptionHandler(this::emitNearbyErrorEvent, this::stopBLE)

init {
Thread.setDefaultUncaughtExceptionHandler { _, exception ->
walletExceptionHandler.handleException(exception)
}
}
private var bleExceptionHandler = OpenIdBLEExceptionHandler(this::emitNearbyErrorEvent, this::stopBLE)
private val tryExecuteSync = TryExecuteSync(bleExceptionHandler);

//Inji contract requires double quotes around the states.
enum class VCResponseStates(val value: String) {
Expand Down Expand Up @@ -49,27 +44,30 @@ class Openid4vpBleModule(private val reactContext: ReactApplicationContext) :
@ReactMethod(isBlockingSynchronousMethod = true)
fun getConnectionParameters(): String {
Log.d(logTag, "getConnectionParameters new verifier object at ${System.nanoTime()}")
synchronized(mutex) {

return tryExecuteSync.run {
if (verifier == null) {
Log.d(logTag, "synchronized getConnectionParameters new verifier object at ${System.nanoTime()}")
verifier = Verifier(reactContext, this::emitNearbyMessage, this::emitNearbyEvent, this::onException)
verifier?.generateKeyPair()
}

val payload = verifier?.getAdvIdentifier("OVPMOSIP")
Log.d(
logTag,
"synchronized getConnectionParameters called with adv identifier $payload at ${System.nanoTime()} and verifier hashcode: ${verifier.hashCode()}"
)
return "{\"cid\":\"ilB8l\",\"pk\":\"${payload}\"}"
}

return@run "{\"cid\":\"ilB8l\",\"pk\":\"${payload}\"}"
}.orEmpty()
}

private fun onException(exception: Throwable){
private fun onException(exception: Exception){
if(exception.cause != null){
Log.e(logTag, "Exception: ${exception.message}");
walletExceptionHandler.handleException(exception.cause!!)
bleExceptionHandler.handleException(exception.cause!!)
} else {
walletExceptionHandler.handleException(exception)
bleExceptionHandler.handleException(exception)
}
}

Expand All @@ -81,7 +79,8 @@ class Openid4vpBleModule(private val reactContext: ReactApplicationContext) :
@ReactMethod(isBlockingSynchronousMethod = true)
fun setConnectionParameters(params: String) {
Log.d(logTag, "setConnectionParameters at ${System.nanoTime()}")
synchronized(mutex) {

tryExecuteSync.run {
if (wallet == null) {
Log.d(logTag, "synchronized setConnectionParameters new wallet object at ${System.nanoTime()}")
wallet = Wallet(reactContext, this::emitNearbyMessage, this::emitNearbyEvent, this::onException)
Expand All @@ -99,8 +98,9 @@ class Openid4vpBleModule(private val reactContext: ReactApplicationContext) :
@ReactMethod
fun createConnection(mode: String, callback: Callback) {
Log.d(logTag, "createConnection: received request with mode $mode at ${System.nanoTime()}")
synchronized(mutex) {
Log.d(logTag, "synchronized createConnection: received request with mode $mode at ${System.nanoTime()}")

tryExecuteSync.run {
Log.d(logTag, "synchronized createConnection: received request with mode $mode at ${System.nanoTime()}")
when (mode) {
"advertiser" -> {
verifier?.startAdvertisement("OVPMOSIP", callback)
Expand All @@ -119,15 +119,15 @@ class Openid4vpBleModule(private val reactContext: ReactApplicationContext) :
fun destroyConnection(callback: Callback) {
//TODO: Make sure callback can be called only once[Can be done once wallet and verifier split into different modules]
Log.d(logTag, "destroyConnection called at ${System.nanoTime()}")

stopBLE(callback)
tryExecuteSync.run {
stopBLE(callback)
}
}

private fun stopBLE(callback: Callback) {
synchronized(mutex) {
if (wallet == null && verifier == null) {
if (wallet == null && verifier == null) {
callback()
} else {
} else {
if (wallet != null) {
Log.d(logTag, "synchronized destroyConnection called for wallet at ${System.nanoTime()}")
stopWallet { callback() }
Expand All @@ -137,7 +137,6 @@ class Openid4vpBleModule(private val reactContext: ReactApplicationContext) :
stopVerifier { callback() }
}
}
}
}

private fun stopVerifier(onDestroy: Callback) {
Expand Down Expand Up @@ -165,21 +164,27 @@ class Openid4vpBleModule(private val reactContext: ReactApplicationContext) :
@ReactMethod
fun send(message: String, callback: Callback) {
Log.d(logTag, "send: message $message at ${System.nanoTime()}")
val messageSplits = message.split("\n", limit = 2)
when (messageSplits[0]) {
NearbyEvents.EXCHANGE_RECEIVER_INFO.value -> {
callback()
}
NearbyEvents.EXCHANGE_SENDER_INFO.value -> {
callback()
wallet?.writeToIdentifyRequest()
}
NearbyEvents.SEND_VC.value -> {
callback()
wallet?.sendData(messageSplits[1])
}
NearbyEvents.SEND_VC_RESPONSE.value -> {
verifier?.notifyVerificationStatus(messageSplits[1] == VCResponseStates.ACCEPTED.value)

tryExecuteSync.run {
val messageSplits = message.split("\n", limit = 2)
when (messageSplits[0]) {
NearbyEvents.EXCHANGE_RECEIVER_INFO.value -> {
callback()
}
NearbyEvents.EXCHANGE_SENDER_INFO.value -> {
callback()
wallet?.writeToIdentifyRequest()
}
NearbyEvents.SEND_VC.value -> {
callback()
wallet?.sendData(messageSplits[1])
}
NearbyEvents.SEND_VC_RESPONSE.value -> {
verifier?.notifyVerificationStatus(messageSplits[1] == VCResponseStates.ACCEPTED.value)
}
else -> {
Log.d(logTag, "send: received send with unrecognized event")
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ class OpenIdBLEExceptionHandler(private val sendError: (String) -> Unit, private
}
}

stopBle {}
try{
stopBle {}
} catch (e: Exception) {
Log.d(logTag,"Failed to stop BLE connection while handling exception: $e")
}
}

private fun handleUnknownException(e: Throwable) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.mosip.tuvali.openid4vpble.exception.exception

class StateHandlerException(message: String, cause: Throwable): Throwable(message, cause) {
class StateHandlerException(message: String, cause: Throwable): Exception(message, cause) {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.mosip.tuvali.openid4vpble.exception.exception

class TransferHandlerException(message: String, cause: Throwable): Throwable(message, cause) {
class TransferHandlerException(message: String, cause: Throwable): Exception(message, cause) {
}
4 changes: 2 additions & 2 deletions android/src/main/java/io/mosip/tuvali/verifier/Verifier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Verifier(
context: Context,
private val messageResponseListener: (String, String) -> Unit,
private val eventResponseListener: (String) -> Unit,
private val onBLEException: (Throwable) -> Unit
private val onBLEException: (Exception) -> Unit
) :
IPeripheralListener, ITransferListener {
private var secretsTranslator: SecretsTranslator? = null;
Expand Down Expand Up @@ -200,7 +200,7 @@ class Verifier(
}
}

override fun onException(e: Throwable) {
override fun onException(e: Exception) {
onBLEException(e)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.mosip.tuvali.verifier.exception

class ReadFromRemoteException: Throwable() {
class ReadFromRemoteException: Exception() {
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package io.mosip.tuvali.verifier.exception

open class VerifierException(message: String): Throwable(message)
open class VerifierException(message: String): Exception(message)
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ interface ITransferListener {
fun sendDataOverNotification(charUUID: UUID, data: ByteArray)
fun onResponseReceived(data: ByteArray)
fun onResponseReceivedFailed(errorMsg: String)
fun onException(exception: Throwable )
fun onException(exception: Exception )
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class TransferHandler(looper: Looper, private val peripheral: Peripheral, privat
override fun dispatchMessage(msg: Message) {
try {
super.dispatchMessage(msg)
} catch (e: Throwable) {
} catch (e: Exception) {
transferListener.onException(TransferHandlerException("Exception in Verifier Transfer Handler", e))
Log.d(logTag, "dispatchMessage " + e.message)
}
Expand Down
5 changes: 3 additions & 2 deletions android/src/main/java/io/mosip/tuvali/wallet/Wallet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ import java.security.SecureRandom
import java.util.*
import io.mosip.tuvali.transfer.Util.Companion.getLogTag
import io.mosip.tuvali.wallet.exception.TransferFailedException
import java.lang.Thread.setDefaultUncaughtExceptionHandler

private const val MTU_REQUEST_RETRY_DELAY_TIME_IN_MILLIS = 500L

class Wallet(
context: Context,
private val messageResponseListener: (String, String) -> Unit,
private val eventResponseListener: (String) -> Unit,
private val onBLEException: (Throwable) -> Unit
private val onBLEException: (Exception) -> Unit
) : ICentralListener, ITransferListener {
private val logTag = getLogTag(javaClass.simpleName)

Expand Down Expand Up @@ -303,7 +304,7 @@ class Wallet(
}
}

override fun onException(exception: Throwable) {
override fun onException(exception: Exception) {
onBLEException(exception)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package io.mosip.tuvali.wallet.exception

open class WalletException(message: String): Throwable(message)
open class WalletException(message: String): Exception(message)
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package io.mosip.tuvali.wallet.transfer
interface ITransferListener {
fun onResponseSent()
fun onResponseSendFailure(errorMsg: String)
fun onException(exception: Throwable)
fun onException(exception: Exception)
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class TransferHandler(looper: Looper, private val central: Central, val serviceU
override fun dispatchMessage(msg: Message) {
try {
super.dispatchMessage(msg)
} catch (e: Throwable) {
} catch (e: Exception) {
transferListener.onException(TransferHandlerException("Exception in Central transfer Handler", e))
Log.d(logTag, "dispatchMessage " + e.message)
}
Expand Down
2 changes: 0 additions & 2 deletions example/.bundle/config

This file was deleted.

1 change: 0 additions & 1 deletion example/.node-version

This file was deleted.

1 change: 0 additions & 1 deletion example/.ruby-version

This file was deleted.

1 change: 0 additions & 1 deletion example/.watchmanconfig

This file was deleted.

6 changes: 0 additions & 6 deletions example/Gemfile

This file was deleted.

Loading