add thread to avoid main thread freezing

This commit is contained in:
WoosangKim 2019-10-23 02:43:23 +09:00 committed by Dima Novotochinov
parent c97d629a7d
commit 2d5893d562
1 changed files with 119 additions and 76 deletions

View File

@ -148,6 +148,8 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
@ReactMethod
public void saveMnemonic(final String mnemonic, final String pairing, final String pin, final Promise promise) {
new Thread(new Runnable() {
public void run() {
try {
smartCard.saveMnemonic(mnemonic, pairing, pin);
promise.resolve(true);
@ -156,6 +158,8 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
promise.reject(e);
}
}
}).start();
}
@ReactMethod
public void getApplicationInfo(final String pairingBase64, final Promise promise) {
@ -173,6 +177,8 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
@ReactMethod
public void deriveKey(final String path, final String pairing, final String pin, final Promise promise) {
new Thread(new Runnable() {
public void run() {
try {
smartCard.deriveKey(path, pairing, pin);
promise.resolve(path);
@ -181,9 +187,13 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
promise.reject(e);
}
}
}).start();
}
@ReactMethod
public void exportKey(final String pairing, final String pin, final Promise promise) {
new Thread(new Runnable() {
public void run() {
try {
promise.resolve(smartCard.exportKey(pairing, pin));
} catch (IOException | APDUException e) {
@ -191,6 +201,8 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
promise.reject(e);
}
}
}).start();
}
@ReactMethod
public void getKeys(final String pairing, final String pin, final Promise promise) {
@ -254,13 +266,14 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
Log.d(TAG, e.getMessage());
promise.reject(e);
}
}
}).start();
}
@ReactMethod
public void verifyPin(final String pairing, final String pin, final Promise promise) {
new Thread(new Runnable() {
public void run() {
try {
promise.resolve(smartCard.verifyPin(pairing, pin));
} catch (IOException | APDUException e) {
@ -268,9 +281,13 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
promise.reject(e);
}
}
}).start();
}
@ReactMethod
public void changePin(final String pairing, final String currentPin, final String newPin, final Promise promise) {
new Thread(new Runnable() {
public void run() {
try {
smartCard.changePin(pairing, currentPin, newPin);
promise.resolve(true);
@ -279,9 +296,13 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
promise.reject(e);
}
}
}).start();
}
@ReactMethod
public void unblockPin(final String pairing, final String puk, final String newPin, final Promise promise) {
new Thread(new Runnable() {
public void run() {
try {
smartCard.unblockPin(pairing, puk, newPin);
promise.resolve(true);
@ -290,9 +311,13 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
promise.reject(e);
}
}
}).start();
}
@ReactMethod
public void unpair(final String pairing, final String pin, final Promise promise) {
new Thread(new Runnable() {
public void run() {
try {
smartCard.unpair(pairing, pin);
promise.resolve(true);
@ -301,9 +326,13 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
promise.reject(e);
}
}
}).start();
}
@ReactMethod
public void delete(final Promise promise) {
new Thread(new Runnable() {
public void run() {
try {
smartCard.delete();
promise.resolve(true);
@ -312,9 +341,13 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
promise.reject(e);
}
}
}).start();
}
@ReactMethod
public void removeKey(final String pairing, final String pin, final Promise promise) {
new Thread(new Runnable() {
public void run() {
try {
smartCard.removeKey(pairing, pin);
promise.resolve(true);
@ -323,9 +356,13 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
promise.reject(e);
}
}
}).start();
}
@ReactMethod
public void removeKeyWithUnpair(final String pairing, final String pin, final Promise promise) {
new Thread(new Runnable() {
public void run() {
try {
smartCard.removeKeyWithUnpair(pairing, pin);
promise.resolve(true);
@ -334,9 +371,13 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
promise.reject(e);
}
}
}).start();
}
@ReactMethod
public void unpairAndDelete(final String pairing, final String pin, final Promise promise) {
new Thread(new Runnable() {
public void run() {
try {
smartCard.unpairAndDelete(pairing, pin);
promise.resolve(true);
@ -345,5 +386,7 @@ public class RNStatusKeycardModule extends ReactContextBaseJavaModule implements
promise.reject(e);
}
}
}).start();
}
}