-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from tw-mosip/develop
[Release 30-05-2023] Android & iOS Stability Changes, Spec Implementations & Exception Handling
- Loading branch information
Showing
72 changed files
with
793 additions
and
397 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
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
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
8 changes: 8 additions & 0 deletions
8
android/src/main/java/io/mosip/tuvali/ble/exception/CentralStateHandlerException.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,8 @@ | ||
package io.mosip.tuvali.ble.exception | ||
|
||
import io.mosip.tuvali.exception.BLEException | ||
import io.mosip.tuvali.exception.ErrorCode | ||
|
||
class CentralStateHandlerException(message: String, cause: Exception): BLEException(message, cause, | ||
ErrorCode.CentralStateHandlerException | ||
) |
8 changes: 8 additions & 0 deletions
8
android/src/main/java/io/mosip/tuvali/ble/exception/PeripheralStateHandlerException.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,8 @@ | ||
package io.mosip.tuvali.ble.exception | ||
|
||
import io.mosip.tuvali.exception.BLEException | ||
import io.mosip.tuvali.exception.ErrorCode | ||
|
||
class PeripheralStateHandlerException(message: String, cause: Exception): BLEException(message, cause, | ||
ErrorCode.PeripheralStateHandlerException | ||
) |
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
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
21 changes: 21 additions & 0 deletions
21
android/src/main/java/io/mosip/tuvali/common/safeExecute/TryExecuteSync.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,21 @@ | ||
package io.mosip.tuvali.common.safeExecute | ||
|
||
import io.mosip.tuvali.exception.handlers.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(e) | ||
} | ||
} | ||
|
||
return returnValue | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
android/src/main/java/io/mosip/tuvali/exception/BLEException.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,4 @@ | ||
package io.mosip.tuvali.exception | ||
|
||
open class BLEException(message: String, cause: Exception?, val errorCode: ErrorCode): RuntimeException(message, cause) { | ||
} |
29 changes: 29 additions & 0 deletions
29
android/src/main/java/io/mosip/tuvali/exception/ErrorCode.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,29 @@ | ||
package io.mosip.tuvali.exception | ||
|
||
// Error Code format | ||
// <Component(2)+Role(1)>(3char)_<Stage>(3char)_<Number>(3char) Eg: TVW-CON-001 | ||
// Stage --> CON(Connection) | KEX(Key Exchange) | ENC(Encryption) | TRA(Transfer) | REP(Report) | DEC(Decryption) | ||
// Component+ROLE --> TVW(Tuvali+Wallet) | TVV(Tuvali+Verifier) | TUV(Tuvali where role is unknown) | ||
// UNK --> If stage is not known | ||
|
||
enum class ErrorCode(val code: String) { | ||
UnknownException("TUV_UNK_001"), | ||
|
||
WalletUnknownException("TVW_UNK_001"), | ||
CentralStateHandlerException("TVW_UNK_002"), | ||
WalletTransferHandlerException("TVW_UNK_003"), | ||
|
||
VerifierUnknownException("TVV_UNK_001"), | ||
PeripheralStateHandlerException("TVV_UNK_002"), | ||
VerifierTransferHandlerException("TVV_UNK_003"), | ||
|
||
MTUNegotiationException("TVW_CON_001"), | ||
//TODO: Create specific error codes for the below exception | ||
TransferFailedException("TVW_REP_001"), | ||
|
||
UnsupportedMTUSizeException("TVV_CON_001"), | ||
CorruptedChunkReceivedException("TVV_TRA_001"), | ||
TooManyFailureChunksException("TVV_TRA_002"), | ||
} | ||
|
||
|
13 changes: 13 additions & 0 deletions
13
android/src/main/java/io/mosip/tuvali/exception/ExceptionUtils.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,13 @@ | ||
package io.mosip.tuvali.exception | ||
|
||
class ExceptionUtils { | ||
companion object { | ||
fun getRootBLECause(e: BLEException): BLEException { | ||
var cause: BLEException = e | ||
while (cause.cause != null && cause.cause is BLEException) { | ||
cause = cause.cause as BLEException | ||
} | ||
return cause | ||
} | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
android/src/main/java/io/mosip/tuvali/exception/UnknownException.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,4 @@ | ||
package io.mosip.tuvali.exception | ||
|
||
class UnknownException(message: String, cause: Exception): BLEException(message, cause, ErrorCode.UnknownException) { | ||
} |
53 changes: 53 additions & 0 deletions
53
android/src/main/java/io/mosip/tuvali/exception/handlers/OpenIdBLEExceptionHandler.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,53 @@ | ||
package io.mosip.tuvali.exception.handlers | ||
|
||
import android.util.Log | ||
import com.facebook.react.bridge.Callback | ||
import io.mosip.tuvali.exception.BLEException | ||
import io.mosip.tuvali.exception.ErrorCode | ||
import io.mosip.tuvali.exception.ExceptionUtils | ||
import io.mosip.tuvali.exception.UnknownException | ||
|
||
import io.mosip.tuvali.transfer.Util | ||
import io.mosip.tuvali.verifier.exception.VerifierException | ||
import io.mosip.tuvali.wallet.exception.WalletException | ||
|
||
class OpenIdBLEExceptionHandler(private val sendError: (String, ErrorCode) -> Unit, private val stopBle: (Callback) -> Unit) { | ||
private val logTag = Util.getLogTag(javaClass.simpleName) | ||
private var walletExceptionHandler: WalletExceptionHandler = WalletExceptionHandler(sendError) | ||
private var verifierExceptionHandler: VerifierExceptionHandler = VerifierExceptionHandler(sendError) | ||
|
||
private fun handleWalletException(e: WalletException) { | ||
walletExceptionHandler.handleException(e) | ||
} | ||
|
||
private fun handleVerifierException(e: VerifierException) { | ||
verifierExceptionHandler.handleException(e) | ||
} | ||
|
||
fun handleException(e: Exception) { | ||
when (e) { | ||
is WalletException -> { | ||
handleWalletException(e) | ||
} | ||
is VerifierException -> { | ||
handleVerifierException(e) | ||
} | ||
else -> { | ||
handleUnknownException(UnknownException("Unknown Exception in Tuvali", e)) | ||
} | ||
} | ||
|
||
try{ | ||
stopBle {} | ||
} catch (e: Exception) { | ||
Log.d(logTag,"Failed to stop BLE connection while handling exception: $e") | ||
} | ||
} | ||
|
||
private fun handleUnknownException(e: BLEException) { | ||
val rootCause = ExceptionUtils.getRootBLECause(e) | ||
|
||
Log.e(logTag, "Handling Unknown Exception: ", e) | ||
sendError(e.message ?: "Something went wrong in BLE: $rootCause", rootCause.errorCode) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
android/src/main/java/io/mosip/tuvali/exception/handlers/VerifierExceptionHandler.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,18 @@ | ||
package io.mosip.tuvali.exception.handlers | ||
|
||
import android.util.Log | ||
import io.mosip.tuvali.exception.ErrorCode | ||
import io.mosip.tuvali.exception.ExceptionUtils | ||
import io.mosip.tuvali.transfer.Util | ||
import io.mosip.tuvali.verifier.exception.VerifierException | ||
|
||
class VerifierExceptionHandler(val sendError: (String, ErrorCode) -> Unit) { | ||
private val logTag = Util.getLogTag(javaClass.simpleName) | ||
|
||
fun handleException(e: VerifierException){ | ||
val rootCause = ExceptionUtils.getRootBLECause(e) | ||
|
||
Log.e(logTag, "Handling Verifier Exception: ", e) | ||
sendError(e.message ?: "Something went wrong in Verifier: $rootCause", rootCause.errorCode) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
android/src/main/java/io/mosip/tuvali/exception/handlers/WalletExceptionHandler.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,18 @@ | ||
package io.mosip.tuvali.exception.handlers | ||
|
||
import android.util.Log | ||
import io.mosip.tuvali.exception.ErrorCode | ||
import io.mosip.tuvali.exception.ExceptionUtils | ||
import io.mosip.tuvali.transfer.Util | ||
import io.mosip.tuvali.wallet.exception.WalletException | ||
|
||
class WalletExceptionHandler(val sendError: (String, ErrorCode) -> Unit) { | ||
private val logTag = Util.getLogTag(javaClass.simpleName) | ||
|
||
fun handleException(e: WalletException) { | ||
val rootCause = ExceptionUtils.getRootBLECause(e) | ||
|
||
Log.e(logTag, "Handling Wallet Exception: ", e) | ||
sendError(e.message ?: "Something went wrong in Wallet: $rootCause", rootCause.errorCode) | ||
} | ||
} |
Oops, something went wrong.