ECR connect

This commit is contained in:
moon 2026-03-19 15:36:39 +06:30
parent dd265c1fa8
commit f7c4920297
6 changed files with 182 additions and 0 deletions

View File

@ -125,6 +125,7 @@ dependencies {
def testRunnerVersion = "1.5.2" def testRunnerVersion = "1.5.2"
def testRulesVersion = "1.5.0" def testRulesVersion = "1.5.0"
// def nav_version = "2.4.1" // def nav_version = "2.4.1"
implementation 'com.github.mik3y:usb-serial-for-android:3.9.0'
implementation 'com.android.support:multidex:1.0.3' implementation 'com.android.support:multidex:1.0.3'
// QR // QR

View File

@ -35,6 +35,9 @@
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" /> <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-feature android:name="android.hardware.usb.host" />
<uses-permission android:name="android.permission.USB_PERMISSION" />
<!-- android:noHistory="true"--> <!-- android:noHistory="true"-->
<!-- android:excludeFromRecents="true"--> <!-- android:excludeFromRecents="true"-->
@ -56,6 +59,7 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar"> android:theme="@style/AppTheme.NoActionBar">
<!-- android:manageSpaceActivity="com.utsmyanmar.upos.config.UTSManageSpaceActivity"--> <!-- android:manageSpaceActivity="com.utsmyanmar.upos.config.UTSManageSpaceActivity"-->
<!-- <activity--> <!-- <activity-->
<!-- android:screenOrientation="portrait"--> <!-- android:screenOrientation="portrait"-->
@ -69,6 +73,14 @@
<category android:name="android.intent.category.HOME"/> <category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
<!-- USB attach filter -->
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<meta-data
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter" />
</activity> </activity>

View File

@ -14,12 +14,17 @@ import androidx.navigation.ui.NavigationUI;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity; import android.view.Gravity;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.Toast; import android.widget.Toast;
@ -31,8 +36,14 @@ import com.nexgo.downloadkey.downloadflow.DownloadFlow;
import com.nexgo.downloadkey.downloadflow.DownloadFlowProcessListener; import com.nexgo.downloadkey.downloadflow.DownloadFlowProcessListener;
import com.nexgo.downloadkey.downloadflow.DownloadFlowResultEntity; import com.nexgo.downloadkey.downloadflow.DownloadFlowResultEntity;
import com.nexgo.downloadkey.downloadflow.DownloadResult; import com.nexgo.downloadkey.downloadflow.DownloadResult;
import com.nexgo.oaf.apiv3.APIProxy;
import com.nexgo.oaf.apiv3.DeviceEngine;
import com.nexgo.oaf.apiv3.device.pinpad.PinPad; import com.nexgo.oaf.apiv3.device.pinpad.PinPad;
import com.nexgo.oaf.apiv3.device.pinpad.WorkKeyTypeEnum; import com.nexgo.oaf.apiv3.device.pinpad.WorkKeyTypeEnum;
import com.nexgo.oaf.apiv3.device.serialport.SerialPortDriver;
import com.nexgo.oaf.apiv3.device.usbserial.OnUsbSerialReadListener;
import com.nexgo.oaf.apiv3.device.usbserial.UsbSerial;
import com.nexgo.oaf.apiv3.device.usbserial.UsbSerialCfgEntity;
import com.utsmyanmar.baselib.BaseApplication; import com.utsmyanmar.baselib.BaseApplication;
import com.utsmyanmar.baselib.repo.Repository; import com.utsmyanmar.baselib.repo.Repository;
import com.utsmyanmar.baselib.ui.AnimationDialog; import com.utsmyanmar.baselib.ui.AnimationDialog;
@ -59,6 +70,7 @@ import com.utsmm.kbz.util.ecr.CoreUtils;
import com.utsmm.kbz.util.tms.TMSUtil; import com.utsmm.kbz.util.tms.TMSUtil;
import java.util.Calendar; import java.util.Calendar;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -107,6 +119,7 @@ public class MainActivity extends AppCompatActivity implements
// Set of fragment IDs that should handle back press specially // Set of fragment IDs that should handle back press specially
private final Set<Integer> specialBackHandlingFragments = new HashSet<>(); private final Set<Integer> specialBackHandlingFragments = new HashSet<>();
@Inject @Inject
Repository repository; Repository repository;
@ -157,6 +170,8 @@ public class MainActivity extends AppCompatActivity implements
} }
private void initKey(){ private void initKey(){
// SystemParamsOperation.getInstance().setTmsAddress("https://api-tms-uat.kbzbank.com:8443/sirius"); // SystemParamsOperation.getInstance().setTmsAddress("https://api-tms-uat.kbzbank.com:8443/sirius");
SystemParamsOperation.getInstance().setTmsAddress("https://sirius-nest.utsmyanmar.com"); SystemParamsOperation.getInstance().setTmsAddress("https://sirius-nest.utsmyanmar.com");

View File

@ -20,6 +20,11 @@ import androidx.lifecycle.Observer;
import com.denzcoskun.imageslider.ImageSlider; import com.denzcoskun.imageslider.ImageSlider;
import com.denzcoskun.imageslider.constants.ScaleTypes; import com.denzcoskun.imageslider.constants.ScaleTypes;
import com.denzcoskun.imageslider.models.SlideModel; import com.denzcoskun.imageslider.models.SlideModel;
import com.nexgo.oaf.apiv3.APIProxy;
import com.nexgo.oaf.apiv3.DeviceEngine;
import com.nexgo.oaf.apiv3.SdkResult;
import com.nexgo.oaf.apiv3.device.serialport.SerialCfgEntity;
import com.nexgo.oaf.apiv3.device.serialport.SerialPortDriver;
import com.nexgo.oaf.apiv3.emv.AidEntity; import com.nexgo.oaf.apiv3.emv.AidEntity;
import com.nexgo.oaf.apiv3.emv.CapkEntity; import com.nexgo.oaf.apiv3.emv.CapkEntity;
//import com.pos.connection.bridge.binder.ECRConstant; //import com.pos.connection.bridge.binder.ECRConstant;
@ -191,6 +196,7 @@ public class MainFragment extends DataBindingFragment {
safeNavigateToRouteId(); safeNavigateToRouteId();
} }
} }
@Override @Override
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
@ -235,6 +241,9 @@ public class MainFragment extends DataBindingFragment {
// enableHomeButton(); // enableHomeButton();
} }
private SerialPortDriver port;
private boolean isRunning = false;
@Override @Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
@ -251,6 +260,64 @@ public class MainFragment extends DataBindingFragment {
// queryAidCAPKList(); // queryAidCAPKList();
queryAidCAPKList(); queryAidCAPKList();
// generateMockQR(); // generateMockQR();
DeviceEngine deviceEngine = APIProxy.getDeviceEngine(requireContext());
port = deviceEngine.getSerialPortDriver(0);
SerialCfgEntity entity = new SerialCfgEntity();
entity.setBaudRate(115200);
entity.setDataBits(8);
entity.setParity('n');
entity.setStopBits(1);
int result = port.connect(entity);
if (result == SdkResult.Success) {
LogUtil.d("USB", "USB Serial connected");
String echo = "Hello ECR";
byte[] data = echo.getBytes(StandardCharsets.UTF_8);
port.send(data, data.length);
port.clrBuffer();
isRunning = true;
startReceiveThread();
} else {
LogUtil.e("USB", "USB Serial connect failed");
}
}
private void startReceiveThread() {
new Thread(() -> {
byte[] buffer = new byte[2048];
while (isRunning) {
int len = port.recv(buffer, buffer.length, 3000);
if (len > 0) {
String msg = new String(buffer, 0, len);
LogUtil.d("USB", "Received: " + msg);
requireActivity().runOnUiThread(() -> {
// update UI here
// example:
// binding.txtResult.setText(msg);
});
}
}
}).start();
} }

View File

@ -0,0 +1,83 @@
package com.utsmm.kbz;
import android.content.Context;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbDeviceConnection;
import android.hardware.usb.UsbManager;
import com.utsmyanmar.paylibs.utils.LogUtil;
import com.xgd.android.usbserial.driver.CdcAcmSerialDriver;
import com.xgd.android.usbserial.driver.UsbSerialDriver;
import com.xgd.android.usbserial.driver.UsbSerialPort;
import com.xgd.android.usbserial.driver.UsbSerialProber;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
public class UsbSerialManager {
private UsbSerialPort port;
public boolean connect(Context context) {
UsbManager manager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
LogUtil.d("USB", "device list " + deviceList.values().toString());
for (UsbDevice device: deviceList.values()){
LogUtil.d("USB", "Device => " + device.getDeviceName());
LogUtil.d("USB", "VID => " + device.getVendorId());
LogUtil.d("USB", "PID => " + device.getProductId());
}
List<UsbSerialDriver> drivers =
UsbSerialProber.getDefaultProber().findAllDrivers(manager);
if (drivers.isEmpty()) return false;
UsbSerialDriver driver = drivers.get(0);
UsbDeviceConnection connection = manager.openDevice(driver.getDevice());
if (connection == null) return false;
port = driver.getPorts().get(0);
try {
port.open(connection);
port.setParameters(
9600,
8,
UsbSerialPort.STOPBITS_1,
UsbSerialPort.PARITY_NONE
);
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
public void send(byte[] data) throws IOException {
if (port != null) {
port.write(data, 1000);
}
}
public byte[] read() throws IOException {
byte[] buffer = new byte[64];
int len = port.read(buffer, 1000);
byte[] result = new byte[len];
System.arraycopy(buffer, 0, result, 0, len);
return result;
}
public void close() throws IOException {
if (port != null) {
port.close();
}
}
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<usb-device class="2" subclass="2" protocol="1" />
</resources>