public void handleInit(final String callback, final String funcName, final CLRemoteResultReceiver receiver, final Promise promise, final String... args) {
try {
initialiseNPCICL(new Promise() {
@Override
public void resolve(@Nullable Object value) {
switch (funcName) {
case "getChallenge":
String challenge = npciClServices.getChallenge(args[0], args[1]);
if(promise!=null) promise.resolve(challenge);
break;
case "registerApp":
Boolean registrationFlag = npciClServices.registerApp(args[0], args[1], args[2], args[3], args[4]);
if(promise!=null) promise.resolve(registrationFlag);
break;
case GET_CREDENTIAL:
onResumeCallback = callback;
npciClServices.getCredential(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], receiver);
break;
case "unbindService":
try {
npciClServices.unbindService();
} catch (Exception ex) {
Logger.e(TAG, "Exception in unbind npci Service", ex);
}
break;
case "execute":
npciClServices.execute(args[0]);
break;
case "isUpiLiteSupported":
if (npciClServices != null) {
boolean isSupported = npciClServices.isDeviceSupported();
promise.resolve(isSupported);
} else promise.resolve("");
if (promise != null) promise.resolve("");
break;
case "isUpiLiteBound":
String isBound = npciClServices.isBound(args[0], args[1], args[2]);
if (promise != null) promise.resolve(isBound);
break;
case "unBindDevice":
boolean isUnbound = npciClServices.unBindDevice(args[0], args[1], args[2]);
if (promise != null) promise.resolve(isUnbound);
break;
case "registerUPILiteOnboarding":
boolean isRegistered = npciClServices.registerVaultOnboarding(args[0], args[1], args[2], args[3]);
if (promise != null) promise.resolve(isRegistered);
break;
case "registerUPILiteState":
boolean isStateUpdated = npciClServices.registerState(args[0], args[1], args[2], args[3]);
if (promise != null) promise.resolve(isStateUpdated);
break;
case "getUPILiteBalance":
String balance = npciClServices.getBalance(args[0], args[1], args[2]);
if (promise != null) promise.resolve(balance);
code
Assistant
break;
case "offlineTxnFlow":
String liteOfflineTxnFlow = npciClServices.offlineTxnFlow(args[0], args[1], args[2], args[3], args[4]);
if (promise != null) promise.resolve(liteOfflineTxnFlow);
break;
case "listKeysVersion":
String listKeysVersion = npciClServices.getClVersion();
if(promise!=null) promise.resolve(listKeysVersion);
break;
default:
break;
}
}
@Override
public void reject(String code, String message) {
throw new UnsupportedOperationException(message);
}
@Override
public void reject(String code, Throwable throwable) {
throw new UnsupportedOperationException(throwable);
}
@Override
public void reject(String code, String message, Throwable throwable) {
throw new UnsupportedOperationException(message);
}
@Override
public void reject(Throwable throwable) {
throw new UnsupportedOperationException(throwable);
}
@Override
public void reject(Throwable throwable, WritableMap userInfo) {
throw new UnsupportedOperationException(throwable);
}
@Override
public void reject(String code, @NonNull WritableMap userInfo) {
throw new UnsupportedOperationException(code);
}
@Override
public void reject(String code, Throwable throwable, WritableMap userInfo) {
throw new UnsupportedOperationException(throwable);
}
@Override
public void reject(String code, String message, @NonNull WritableMap userInfo) {
throw new UnsupportedOperationException(message);
}
@Override
public void reject(String code, String message, Throwable throwable, WritableMap userInfo) {
throw new UnsupportedOperationException(throwable);
}
@Override
public void reject(String message) {
throw new UnsupportedOperationException(message);
}
});
} catch (Exception e) {
Logger.e(TAG, "Description : NPCI Service serviceConnected : RuntimeException : " + e);
}
}
add logger.d with input and output of each api req and response
tag, req/res
To add Logger.d statements for logging the input and output of each API request and response, I'll insert log statements at the beginning and end of each case in the switch block. This will help in tracking the input parameters being passed and the resulting output or reaction of the function. Here's how you could achieve this:
java
public void handleInit(final String callback, final String funcName, final CLRemoteResultReceiver receiver, final Promise promise, final String... args) {
try {
Logger.d(TAG, "handleInit - Request: funcName = " + funcName + ", args = " + Arrays.toString(args));
initialiseNPCICL(new Promise() {
@Override
public void resolve(@Nullable Object value) {
switch (funcName) {
case "getChallenge":
String challenge = npciClServices.getChallenge(args[0], args[1]);
Logger.d(TAG, "getChallenge - Response: " + challenge);
if(promise!=null) promise.resolve(challenge);
break;
case "registerApp":
Boolean registrationFlag = npciClServices.registerApp(args[0], args[1], args[2], args[3], args[4]);
Logger.d(TAG, "registerApp - Response: " + registrationFlag);
if(promise!=null) promise.resolve(registrationFlag);
break;
case GET_CREDENTIAL:
onResumeCallback = callback;
npciClServices.getCredential(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], receiver);
Logger.d(TAG, "getCredential - Request sent");
break;
case "unbindService":
try {
npciClServices.unbindService();
Logger.d(TAG, "unbindService - Service unbound");
} catch (Exception ex) {
Logger.e(TAG, "Exception in unbind npci Service", ex);
}
break;
case "execute":
npciClServices.execute(args[0]);
Logger.d(TAG, "execute - Request: " + args[0]);
break;
case "isUpiLiteSupported":
if (npciClServices != null) {
boolean isSupported = npciClServices.isDeviceSupported();
Logger.d(TAG, "isUpiLiteSupported - Response: " + isSupported);
promise.resolve(isSupported);
} else {
Logger.d(TAG, "isUpiLiteSupported - Response: (npciClServices is null)");
promise.resolve("");
}
if (promise != null) promise.resolve("");
break;
case "isUpiLiteBound":
String isBound = npciClServices.isBound(args[0], args[1], args[2]);
Logger.d(TAG, "isUpiLiteBound - Response: " + isBound);
if (promise != null) promise.resolve(isBound);
break;
case "unBindDevice":
boolean isUnbound = npciClServices.unBindDevice(args[0], args[1], args[2]);
Logger.d(TAG, "unBindDevice - Response: " + isUnbound);
if (promise != null) promise.resolve(isUnbound);
break;
case "registerUPILiteOnboarding":
boolean isRegistered = npciClServices.registerVaultOnboarding(args[0], args[1], args[2], args[3]);
Logger.d(TAG, "registerUPILiteOnboarding - Response: " + isRegistered);
if (promise != null) promise.resolve(isRegistered);
break;
case "registerUPILiteState":
boolean isStateUpdated = npciClServices.registerState(args[0], args[1], args[2], args[3]);
Logger.d(TAG, "registerUPILiteState - Response: " + isStateUpdated);
if (promise != null) promise.resolve(isStateUpdated);
break;
case "getUPILiteBalance":
String balance = npciClServices.getBalance(args[0], args[1], args[2]);
Logger.d(TAG, "getUPILiteBalance - Response: " + balance);
if (promise != null) promise.resolve(balance);
break;
case "offlineTxnFlow":
String liteOfflineTxnFlow = npciClServices.offlineTxnFlow(args[0], args[1], args[2], args[3], args[4]);
Logger.d(TAG, "offlineTxnFlow - Response: " + liteOfflineTxnFlow);
if (promise != null) promise.resolve(liteOfflineTxnFlow);
break;
case "listKeysVersion":
String listKeysVersion = npciClServices.getClVersion();
Logger.d(TAG, "listKeysVersion - Response: " + listKeysVersion);
if(promise!=null) promise.resolve(listKeysVersion);
break;
default:
Logger.d(TAG, "Unknown function call: " + funcName);
break;
}
}
@Override
public void reject(String code, String message) {
throw new UnsupportedOperationException(message);
}
@Override
public void reject(String code, Throwable throwable) {
throw new UnsupportedOperationException(throwable);
}
@Override
public void reject(String code, String message, Throwable throwable) {
throw new UnsupportedOperationException(message);
}
@Override
public void reject(Throwable throwable) {
throw new UnsupportedOperationException(throwable);
}
@Override
public void reject(Throwable throwable, WritableMap userInfo) {
throw new UnsupportedOperationException(throwable);
}
@Override
public void reject(String code, @NonNull WritableMap userInfo) {
throw new UnsupportedOperationException(code);
}
@Override
public void reject(String code, Throwable throwable, WritableMap userInfo) {
throw new UnsupportedOperationException(throwable);
}
@Override
public void reject(String code, String message, @NonNull WritableMap userInfo) {
throw new UnsupportedOperationException(message);
}
@Override
public void reject(String code, String message, Throwable throwable, WritableMap userInfo) {
throw new UnsupportedOperationException(throwable);
}
@Override
public void reject(String message) {
throw new UnsupportedOperationException(message);
}
});
} catch (Exception e) {
Logger.e(TAG, "Description : NPCI Service serviceConnected : RuntimeException : " + e);
}
}
In this version, Logger.d is used to log both the function being executed (funcName) along with its input parameters before the function is invoked, and to log the output or effect of the function after it executes. This will provide a detailed trace of the flow through handleInit, aiding in debugging and understanding the sequence of operations.