1
0
mirror of synced 2024-11-23 23:01:00 +01:00

fix: unintended call enableService in onResume

This commit is contained in:
Juchan Roh 2023-02-04 23:05:11 +09:00
parent a307311f2b
commit ca9aa37257
2 changed files with 31 additions and 12 deletions

View File

@ -35,6 +35,7 @@ public class HcefModule extends ReactContextBaseJavaModule implements LifecycleE
ComponentName componentName = null;
Boolean isHceFEnabled = false;
Boolean isHceFSupport = false;
Boolean nowUsing = false;
HcefModule(ReactApplicationContext context) {
super(context);
@ -87,8 +88,13 @@ public class HcefModule extends ReactContextBaseJavaModule implements LifecycleE
if(sid.substring(0,4).contentEquals("02FE") == false)
promise.reject("PREFIX_ERROR", "SID must be start with 02FE");
boolean result = nfcFCardEmulation.setNfcid2ForService(componentName, sid);
promise.resolve(nfcFCardEmulation.setNfcid2ForService(componentName, sid));
if (result) {
promise.resolve(true);
} else {
promise.reject("FAIL", "setNfcid2ForService returned false");
}
}
@ReactMethod
@ -106,30 +112,44 @@ public class HcefModule extends ReactContextBaseJavaModule implements LifecycleE
if(cardId.substring(0,4).contentEquals("02FE") == false)
promise.reject("PREFIX_ERROR", "SID must be start with 02FE");
// Toast.makeText(getReactApplicationContext(), "Card Emulation Enabled!", Toast.LENGTH_SHORT).show();
promise.resolve(nfcFCardEmulation.enableService(getCurrentActivity(), componentName));
boolean result = nfcFCardEmulation.enableService(getCurrentActivity(), componentName);
if (result) {
nowUsing = true;
promise.resolve(true);
} else {
promise.reject("FAIL", "enableService returned false");
}
}
@ReactMethod
void disableService(Promise promise){
if(nfcFCardEmulation == null || componentName == null){
if(nfcFCardEmulation == null || componentName == null) {
promise.reject("NULL_ERROR", "nfcFCardEmulation or componentName is null");
}
// Toast.makeText(getReactApplicationContext(), "Card Emulation Disabled...", Toast.LENGTH_SHORT).show();
promise.resolve(nfcFCardEmulation.disableService(getCurrentActivity()));
boolean result = nfcFCardEmulation.disableService(getCurrentActivity());
if (result) {
nowUsing = false;
promise.resolve(true);
} else {
promise.reject("FAIL", "disableService returned false");
}
}
@Override
public void onHostResume(){
if(nfcFCardEmulation != null && componentName != null){
public void onHostResume() {
if (nfcFCardEmulation != null && componentName != null && nowUsing) {
Log.d("MainActivity onResume()", "enabled!");
nfcFCardEmulation.enableService(getCurrentActivity(), componentName);
}
}
@Override
public void onHostPause(){
if(nfcFCardEmulation != null && componentName != null){
if(nfcFCardEmulation != null && componentName != null && nowUsing){
Log.d("MainActivity onPause()", "disabled...");
nfcFCardEmulation.disableService(getCurrentActivity());
}
@ -137,6 +157,5 @@ public class HcefModule extends ReactContextBaseJavaModule implements LifecycleE
@Override
public void onHostDestroy(){
}
}

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<host-nfcf-service xmlns:android="http://schemas.android.com/apk/res/android">
<system-code-filter android:name="4000" />
<nfcid2-filter android:name="null" />
</host-nfcf-service>
<nfcid2-filter android:name="random" />
</host-nfcf-service>