forked from mosip/inji-wallet
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Revert "[INJIMOB-891] add tuvali native" This reverts commit d4a4e89bd64f2c753e22576aeff4840fcb1eb0ae. * [INJIMOB-891]: add a wrapper for tuvali to use native artifacts Signed-off-by: Alka Prasad <[email protected]> * [INJIMOB-891]: add a wrapper for tuvali in ios to consume ios native artifact Signed-off-by: Alka Prasad <[email protected]> * [INJIMOB-891]: add tuvali native dependency Signed-off-by: Alka Prasad <[email protected]> --------- Signed-off-by: Alka Prasad <[email protected]> Co-authored-by: Alka Prasad <[email protected]>
- Loading branch information
Showing
30 changed files
with
746 additions
and
92 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
9 changes: 9 additions & 0 deletions
9
android/app/src/main/java/io/mosip/residentapp/IRNEventEmitter.java
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,9 @@ | ||
package io.mosip.residentapp; | ||
|
||
import com.facebook.react.bridge.WritableMap; | ||
|
||
import kotlin.Unit; | ||
|
||
public interface IRNEventEmitter { | ||
Unit emitEvent(WritableMap eventMap); | ||
} |
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
24 changes: 24 additions & 0 deletions
24
android/app/src/main/java/io/mosip/residentapp/RNEventEmitter.java
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,24 @@ | ||
package io.mosip.residentapp; | ||
|
||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.WritableMap; | ||
import com.facebook.react.modules.core.DeviceEventManagerModule; | ||
|
||
import kotlin.Unit; | ||
import kotlin.jvm.functions.Function1; | ||
|
||
public class RNEventEmitter implements IRNEventEmitter { | ||
|
||
private static final String EVENT_NAME = "DATA_EVENT"; | ||
private final ReactApplicationContext reactContext; | ||
|
||
public RNEventEmitter(ReactApplicationContext reactContext) { | ||
this.reactContext = reactContext; | ||
} | ||
|
||
@Override | ||
public Unit emitEvent(WritableMap eventMap) { | ||
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(EVENT_NAME, eventMap); | ||
return null; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
android/app/src/main/java/io/mosip/residentapp/RNEventMapper.java
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,74 @@ | ||
package io.mosip.residentapp; | ||
|
||
import com.facebook.react.bridge.Arguments; | ||
import com.facebook.react.bridge.WritableMap; | ||
import io.mosip.tuvali.common.events.*; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.Map; | ||
import java.util.HashMap; | ||
|
||
public class RNEventMapper { | ||
|
||
public static WritableMap toMap(Event event) { | ||
WritableMap writableMap = Arguments.createMap(); | ||
writableMap.putString("type", getEventType(event)); | ||
populateProperties(event, writableMap); | ||
return writableMap; | ||
} | ||
|
||
private static String getEventType(Event event) { | ||
if (event instanceof DataReceivedEvent) { | ||
return "onDataReceived"; | ||
} else if (event instanceof ErrorEvent) { | ||
return "onError"; | ||
} else if (event instanceof VerificationStatusEvent) { | ||
return "onVerificationStatusReceived"; | ||
} else if (event instanceof ConnectedEvent) { | ||
return "onConnected"; | ||
} else if (event instanceof DataSentEvent) { | ||
return "onDataSent"; | ||
} else if (event instanceof DisconnectedEvent) { | ||
return "onDisconnected"; | ||
} else if (event instanceof SecureChannelEstablishedEvent) { | ||
return "onSecureChannelEstablished"; | ||
} else { | ||
System.out.println("Invalid event type"); | ||
return ""; | ||
} | ||
} | ||
|
||
private static void populateProperties(Event event, WritableMap writableMap) { | ||
for (Field field : event.getClass().getDeclaredFields()) { | ||
try { | ||
field.setAccessible(true); | ||
populateProperty(field, event, writableMap); | ||
field.setAccessible(false); | ||
} catch (Exception e) { | ||
System.out.println("Unable to populate RN event " + field.getName()); | ||
} | ||
} | ||
} | ||
|
||
private static void populateProperty(Field field, Event event, WritableMap writableMap) throws IllegalAccessException { | ||
Object propertyValue = field.get(event); | ||
if (propertyValue instanceof Enum) { | ||
propertyValue = readEnumValue((Enum<?>) propertyValue); | ||
} | ||
if (propertyValue instanceof Integer) { | ||
writableMap.putInt(field.getName(), (Integer) propertyValue); | ||
} else { | ||
writableMap.putString(field.getName(), propertyValue.toString()); | ||
} | ||
} | ||
|
||
private static Object readEnumValue(Enum<?> enumValue) { | ||
try { | ||
Field valueField = enumValue.getClass().getDeclaredField("value"); | ||
valueField.setAccessible(true); | ||
return valueField.get(enumValue); | ||
} catch (Exception e) { | ||
return enumValue.ordinal(); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
android/app/src/main/java/io/mosip/residentapp/RNVerifierModule.java
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,42 @@ | ||
package io.mosip.residentapp; | ||
|
||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
|
||
import io.mosip.tuvali.verifier.Verifier; | ||
|
||
public class RNVerifierModule extends ReactContextBaseJavaModule { | ||
|
||
private static final String NAME = "VerifierModule"; | ||
private final RNEventEmitter eventEmitter; | ||
private final Verifier verifier; | ||
|
||
|
||
public RNVerifierModule(RNEventEmitter eventEmitter, Verifier verifier, ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
this.eventEmitter = eventEmitter; | ||
this.verifier = verifier; | ||
verifier.subscribe(event -> eventEmitter.emitEvent(RNEventMapper.toMap(event))); | ||
} | ||
|
||
@ReactMethod(isBlockingSynchronousMethod = true) | ||
public String startAdvertisement(String advIdentifier) { | ||
return verifier.startAdvertisement(advIdentifier); | ||
} | ||
|
||
@ReactMethod(isBlockingSynchronousMethod = true) | ||
public void disconnect() { | ||
verifier.disconnect(); | ||
} | ||
|
||
@ReactMethod | ||
public void sendVerificationStatus(int status) { | ||
verifier.sendVerificationStatus(status); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return NAME; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
android/app/src/main/java/io/mosip/residentapp/RNVersionModule.java
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,25 @@ | ||
|
||
package io.mosip.residentapp; | ||
|
||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
import io.mosip.residentapp.BuildConfig; | ||
|
||
|
||
|
||
public class RNVersionModule extends ReactContextBaseJavaModule { | ||
|
||
private static final String NAME = "VersionModule"; | ||
|
||
@ReactMethod(isBlockingSynchronousMethod = true) | ||
public String getVersion() { | ||
return BuildConfig.TUVALI_LIB_VERSION; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return NAME; | ||
} | ||
} | ||
|
||
|
82 changes: 82 additions & 0 deletions
82
android/app/src/main/java/io/mosip/residentapp/RNWalletModule.java
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,82 @@ | ||
package io.mosip.residentapp; | ||
|
||
import android.bluetooth.BluetoothAdapter; | ||
import android.content.IntentFilter; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
import com.facebook.react.bridge.WritableMap; | ||
|
||
import io.mosip.residentapp.RNEventEmitter; | ||
import io.mosip.tuvali.common.BluetoothStateChangeReceiver; | ||
import io.mosip.tuvali.wallet.Wallet; | ||
import kotlin.Unit; | ||
import kotlin.jvm.functions.Function1; | ||
import kotlin.jvm.functions.Function2; | ||
|
||
public class RNWalletModule extends ReactContextBaseJavaModule { | ||
|
||
private static final String NAME = "WalletModule"; | ||
private final RNEventEmitter eventEmitter; | ||
private final Wallet wallet; | ||
private final IntentFilter bluetoothStateChangeIntentFilter; | ||
private final BluetoothStateChangeReceiver bluetoothStateChangeReceiver; | ||
|
||
public RNWalletModule(RNEventEmitter eventEmitter, Wallet wallet, ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
this.eventEmitter = eventEmitter; | ||
this.wallet = wallet; | ||
|
||
this.bluetoothStateChangeIntentFilter = new IntentFilter(); | ||
bluetoothStateChangeIntentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); | ||
|
||
this.bluetoothStateChangeReceiver = new BluetoothStateChangeReceiver(handleDisconnect); | ||
reactContext.registerReceiver(bluetoothStateChangeReceiver, bluetoothStateChangeIntentFilter); | ||
wallet.subscribe(event -> eventEmitter.emitEvent(RNEventMapper.toMap(event))); | ||
} | ||
|
||
Function2<Integer, Integer, Unit> handleDisconnect = new Function2<Integer, Integer, Unit>() { | ||
@Override | ||
public Unit invoke(Integer status, Integer state) { | ||
wallet.handleDisconnect(status, state); | ||
return Unit.INSTANCE; | ||
} | ||
}; | ||
|
||
public Function1<WritableMap, Unit> emitEventHandler = new Function1<WritableMap, Unit>() { | ||
@Override | ||
public Unit invoke(WritableMap eventMap) { | ||
eventEmitter.emitEvent(eventMap); | ||
return Unit.INSTANCE; | ||
} | ||
}; | ||
|
||
@ReactMethod(isBlockingSynchronousMethod = true) | ||
public void startConnection(String uri) { | ||
wallet.startConnection(uri); | ||
} | ||
|
||
@ReactMethod | ||
public void sendData(String payload) { | ||
wallet.sendData(payload); | ||
} | ||
|
||
@ReactMethod(isBlockingSynchronousMethod = true) | ||
public void disconnect() { | ||
wallet.disconnect(); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return NAME; | ||
} | ||
|
||
@Override | ||
protected void finalize() throws Throwable { | ||
try { | ||
getReactApplicationContext().unregisterReceiver(bluetoothStateChangeReceiver); | ||
} finally { | ||
super.finalize(); | ||
} | ||
} | ||
} |
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.