Skip to content

Commit

Permalink
[#168485266] Removed 'any' and typed enums (#7)
Browse files Browse the repository at this point in the history
* [#168485266] Removed 'any' and typed enums

Removed 'any' and typed enums

* [#168485266] Removed null params

Removed null params

* [#168485266] Catch exception on listening nfc

Catch exception on listening nfc

* [#168485266] Catch start and stop listening nfc

Catch start and stop listening nfc

* [#168485266] Fix no-void

Fix no-void

* [#168485266] Fixed promise and added comments

Fix promise and added comments

* [#168485266] Fixed promise constructor

Fixed promise constructor
  • Loading branch information
Edigio authored and fventola-ipzs committed Sep 24, 2019
1 parent 146682a commit 42c9731
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class MainActivity : AppCompatActivity(), Callback {
//configurazione cieidsdk
CieIDSdk.start(this, this)
//passare il pin inserito dall'utente
CieIDSdk.pin = "81813213"
CieIDSdk.pin = "12345678"
//settare la url caricata dalla webview su /OpenApp
CieIDSdk.setUrl(url)
//abilitare i log
Expand Down
23 changes: 11 additions & 12 deletions cieidsdk/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,32 +70,31 @@ class CieManager {
});
};

/**
* Return true if the nfc is enabled, on the device in Settings screen
* is possible enable or disable it.
*/
isNFCEnabled = () => {
if (Platform.OS === "ios") {
return Promise.reject("not implemented");
}
return new Promise((resolve, reject) => {
NativeCie.isNFCEnabled((err, result) => {
if (err) {
reject(err);
} else {
return new Promise(resolve => {
NativeCie.isNFCEnabled((result) => {
resolve(result);
}
});
});
};

/**
* Check if the hardware module nfc is installed (only for Android devices)
*/
hasNFCFeature = () => {
if (Platform.OS === "ios") {
return Promise.reject("not implemented");
}
return new Promise((resolve, reject) => {
NativeCie.hasNFCFeature((err, result) => {
if (err) {
reject(err);
} else {
return new Promise(resolve => {
NativeCie.hasNFCFeature((result) => {
resolve(result);
}
});
});
};
Expand Down
49 changes: 32 additions & 17 deletions cieidsdk/src/main/java/it/ipzs/cieidsdk/common/CieIDSdk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,39 @@ val CERTIFICATE_REVOKED: CharSequence = "SSLV3_ALERT_CERTIFICATE_REVOKED"

class Event {

enum class EventValue {
interface EventValue {
val nameEvent: String
}

enum class EventTag : EventValue {
//tag
ON_TAG_DISCOVERED_NOT_CIE,
ON_TAG_DISCOVERED,
ON_TAG_LOST,
ON_TAG_LOST;

override val nameEvent: String = name
}
enum class EventCard: EventValue {
//card
ON_CARD_PIN_LOCKED,
ON_PIN_ERROR,
ON_PIN_ERROR;

override val nameEvent: String = name

}
enum class EventCertificate : EventValue {
//certificate
CERTIFICATE_EXPIRED,
CERTIFICATE_REVOKED,
CERTIFICATE_REVOKED;

override val nameEvent: String = name
}
enum class EventError : EventValue {
//error
AUTHENTICATION_ERROR,
GENERAL_ERROR,
ON_NO_INTERNET_CONNECTION
ON_NO_INTERNET_CONNECTION;

override val nameEvent: String = name
}

private var tentativi: Int = 0
Expand All @@ -67,7 +82,7 @@ class Event {
}

override fun toString(): String {
return eventValue.name
return eventValue.nameEvent
}
}

Expand All @@ -87,7 +102,7 @@ object CieIDSdk : NfcAdapter.ReaderCallback {
internal var ias: Ias? = null
var enableLog: Boolean = false
var pin: String = ""
private const val isoDepTimeout: Int = 2000
private const val isoDepTimeout: Int = 4000


@SuppressLint("CheckResult")
Expand All @@ -114,7 +129,7 @@ object CieIDSdk : NfcAdapter.ReaderCallback {
callback?.onSuccess(url)

} else {
callback?.onEvent(Event(Event.EventValue.AUTHENTICATION_ERROR))
callback?.onEvent(Event(Event.EventError.AUTHENTICATION_ERROR))
}

}
Expand All @@ -125,16 +140,16 @@ object CieIDSdk : NfcAdapter.ReaderCallback {
when (e) {
is SocketTimeoutException , is UnknownHostException -> {
CieIDSdkLogger.log("SocketTimeoutException or UnknownHostException")
callback?.onEvent(Event(Event.EventValue.ON_NO_INTERNET_CONNECTION))
callback?.onEvent(Event(Event.EventError.ON_NO_INTERNET_CONNECTION))

}
is SSLProtocolException -> {

CieIDSdkLogger.log("SSLProtocolException")
e.message?.let {
when {
it.contains(CERTIFICATE_EXPIRED) -> callback?.onEvent(Event(Event.EventValue.CERTIFICATE_EXPIRED))
it.contains(CERTIFICATE_REVOKED) -> callback?.onEvent(Event(Event.EventValue.CERTIFICATE_REVOKED))
it.contains(CERTIFICATE_EXPIRED) -> callback?.onEvent(Event(Event.EventCertificate.CERTIFICATE_EXPIRED))
it.contains(CERTIFICATE_REVOKED) -> callback?.onEvent(Event(Event.EventCertificate.CERTIFICATE_REVOKED))
else -> callback?.onError(e)
}
}
Expand All @@ -149,7 +164,7 @@ object CieIDSdk : NfcAdapter.ReaderCallback {

override fun onTagDiscovered(tag: Tag?) {
try {
callback?.onEvent(Event(Event.EventValue.ON_TAG_DISCOVERED))
callback?.onEvent(Event(Event.EventTag.ON_TAG_DISCOVERED))
val isoDep = IsoDep.get(tag)
isoDep.timeout = isoDepTimeout
isoDep.connect()
Expand All @@ -163,10 +178,10 @@ object CieIDSdk : NfcAdapter.ReaderCallback {
} catch (throwable: Throwable) {
CieIDSdkLogger.log(throwable.toString())
when (throwable) {
is PinNotValidException -> callback?.onEvent(Event(Event.EventValue.ON_PIN_ERROR, throwable.tentativi))
is BlockedPinException -> callback?.onEvent(Event(Event.EventValue.ON_CARD_PIN_LOCKED))
is NoCieException -> callback?.onEvent(Event(Event.EventValue.ON_TAG_DISCOVERED_NOT_CIE))
is TagLostException -> callback?.onEvent(Event(Event.EventValue.ON_TAG_LOST))
is PinNotValidException -> callback?.onEvent(Event(Event.EventCard.ON_PIN_ERROR, throwable.tentativi))
is BlockedPinException -> callback?.onEvent(Event(Event.EventCard.ON_CARD_PIN_LOCKED))
is NoCieException -> callback?.onEvent(Event(Event.EventTag.ON_TAG_DISCOVERED_NOT_CIE))
is TagLostException -> callback?.onEvent(Event(Event.EventTag.ON_TAG_LOST))
else -> callback?.onError(throwable)
}
}
Expand Down
28 changes: 20 additions & 8 deletions cieidsdk/src/main/java/it/ipzs/cieidsdk/native_bridge/CieModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,22 @@ class CieModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod

@ReactMethod
fun start(callback: com.facebook.react.bridge.Callback){
CieIDSdk.start(getCurrentActivity()!!, this)
callback.invoke(null,null)
try {
CieIDSdk.start(getCurrentActivity()!!, this)
callback.invoke(null, null)
} catch (e: RuntimeException) {
callback.invoke(e.message,null)
}
}

@ReactMethod
fun isNFCEnabled(callback: com.facebook.react.bridge.Callback) {
callback.invoke(null,CieIDSdk.isNFCEnabled(getCurrentActivity()!!))
callback.invoke(CieIDSdk.isNFCEnabled(getCurrentActivity()!!))
}

@ReactMethod
fun hasNFCFeature(callback: com.facebook.react.bridge.Callback) {
callback.invoke(null,CieIDSdk.hasFeatureNFC(getCurrentActivity()!!))
callback.invoke(CieIDSdk.hasFeatureNFC(getCurrentActivity()!!))
}

@ReactMethod
Expand All @@ -70,14 +74,22 @@ class CieModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod

@ReactMethod
fun startListeningNFC(callback: com.facebook.react.bridge.Callback) {
CieIDSdk.startNFCListening(getCurrentActivity()!!)
callback.invoke(null,null)
try {
CieIDSdk.startNFCListening(getCurrentActivity()!!)
callback.invoke(null,null)
} catch (e: RuntimeException) {
callback.invoke(e.message,null)
}
}

@ReactMethod
fun stopListeningNFC(callback: com.facebook.react.bridge.Callback) {
CieIDSdk.stopNFCListening(getCurrentActivity()!!)
callback.invoke(null,null)
try {
CieIDSdk.stopNFCListening(getCurrentActivity()!!)
callback.invoke(null, null)
} catch (e: RuntimeException) {
callback.invoke(e.message,null)
}
}

@ReactMethod
Expand Down

0 comments on commit 42c9731

Please sign in to comment.