# FaceRecognitionDemo **Repository Path**: stone1206/FaceRecognitionDemo ## Basic Information - **Project Name**: FaceRecognitionDemo - **Description**: 定制的 Android 系统硬件特定功能调用的演示项目 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 7 - **Created**: 2025-02-27 - **Last Updated**: 2025-02-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ### **System functions** ##### **Auto Start on Boot** - **Parameter 1**: Represents the application package name, corresponding to the application ID on the Android platform. - **Parameter 2**: Represents the time interval (in seconds) to monitor whether the application is in the foreground. It cannot be less than 15 seconds. - **Parameter 3**: Indicates whether the app should auto-start on boot. (true/false) ```java ESSystem.instance().getsystemManager().startHonitorAppRK( pkgName: "xxx.xx.xx", seconds: 30, islauncher: true); ``` ##### **Status Bar and Navigation Bar** - **Parameter 1**: Whether to enable or disable (true to enable, false to disable) - **Parameter 2**: Whether to disable the status bar (true to disable, false to not disable) - **Parameter 3**: Whether to disable the navigation bar (true to disable, false to not disable) ```java ESSystem.instance().getSystemManager().disableStatusBarRK(true, true, true); ``` ##### **Silent Installation** - **Parameter 1**: APK file path ```java ESSystem.instance().getSystemManager().installApk(file.getAbsolutePath()); ``` ##### **Restart** - **Parameter 1**: Restart reason ```java ESFaceUtils.reboot(reason) ``` ### **Network Management** ##### **Get Network Connection Information** ```java FaceSdkApplication.instance().getSystemHelper().getNetwork().getEthernetNetworkConfig() ``` ##### Set Ethernet IP ```java FaceSdkApplication.instance().getSystemHelper().getNetwork().setEthernetStaticIp(ip, mask, gateway, dns1, dns2) ``` ##### Set Ethernet Dhcp ```java FaceSdkApplication.instance().getSystemHelper().getNetwork().setEthernetStaticDhcp() ``` ##### Set wifi ip ```java FaceSdkApplication.instance().getSystemHelper().getNetwork().setWifiStaticIp(ssid, ip, mask, gateway, dns1, dns2) ``` ##### Set wifi dhcp ```java FaceSdkApplication.instance().getSystemHelper().getNetwork().setWifiDhcp(ssid) ``` ### **Camera** ##### **Bind Camera to LifecycleOwner** - **Parameter 1**: `lifecycleOwner` [LifecycleOwner] - **Parameter 2**: `textureView` Camera preview object - **Parameter 3**: `openCameraParams` Camera opening parameters - **Parameter 4**: `iCameraCallback` Camera state callback @return [ICamera] ```java mCamera = CameraHelper.bindCommonCameraToLifecycle(getViewLifecycleOwner(), mViewBinding.textureView, new ICameraCallback() { @Override public void onCameraOpenSuccess() { Log.i(TAG, "Camera opened successfully"); } @Override public void onCameraError() { Log.i(TAG, "Camera opening error, needs to be restarted"); // todo In this case, a restart is usually required because before calling this callback, // the SDK has already tried to reopen the camera 5 times without success. // ESFaceUtils.reboot("Camera opening error"); } @Override public void onCameraPreview(@Nullable byte[] bytes) { } }, CameraSizeHelper.getInstance().getVLOpenParams()); ``` ##### **No Preview Needed** If preview is not required, you can use `bindCommonCamera2ToLifecycle`, and the `textureView` (camera preview object) can be null. ```java mCamera = CameraHelper.bindCommonCamera2ToLifecycle(getViewLifecycleOwner(), mViewBinding.tvOne, new ICameraCallback() { @Override public void onCameraOpenSuccess() { Log.i(TAG, "Camera opened successfully"); } @Override public void onCameraError() { Log.i(TAG, "Camera opening error, needs to be restarted"); // todo In this case, a restart is usually required because before calling this callback, // the SDK has already tried to reopen the camera 5 times without success. // ESFaceUtils.reboot("Camera opening error"); } @Override public void onCameraPreview(@Nullable byte[] bytes) { } }, p); ``` ### **Door and Lighting Control** ##### **Get Light and Relay Operation Instance** ``` GpioHelper gpioHelper = GpioHelper.getInstance(); ``` ##### **Operate Relay to Open Door** ``` gpioHelper.openDoor(); ``` ##### **Operate Relay to Close Door** ``` gpioHelper.closeDoor(); ``` ##### **Turn on Green Light and Open Door** ``` gpioHelper.setPassStatus(true); ``` ##### **Turn on Infrared Light** ``` gpioHelper.setPassStatus(false); ``` ##### **Turn on White Supplementary Light** ``` gpioHelper.setWhiteLedStatus(true); ``` ##### **Turn off Other Lights and Trigger Door Closing Signal** - **Parameter 1**: Whether to turn on the white light ``` gpioHelper.ledDismiss(false); ``` ### **Card Swiping** ##### **Simple Card Number Reading** ``` SerialPortManager.instance().getCardRead(getActivity()).startRead(new IReadCardCallback() { @Override public void onReadResult(@NonNull ReadCardResult readCardResult) { SoundPoolHelper.getInstance().playDi(); requireActivity().runOnUiThread(() -> mViewBinding.tvCard.setText("Card Number: " + readCardResult.getCardNumber())); Log.e(TAG, "Card Number: " + readCardResult.getCardNumber()); } @Override public void onReadFailure(int i, @NonNull String s) { Log.e(TAG, "onReadFailure code: " + i + " msg: " + s); } }); ``` ### **ID Card Swiping** ##### **Get ID Card Operation Class Instance** ``` private final IDCardManager mIDCardManager = new IDCardManager(); ``` ##### **Read ID Card** ``` mIDCardManager.getIDCardRead(requireActivity()).startReadIDCard(new IReadIDCardCallback() { @Override public void onReadResult(@Nullable IDCardInfo idCardInfo) { SoundPoolHelper.getInstance().playDi(); requireActivity().runOnUiThread(() -> { String idCardStr = "Name: " + idCardInfo.getUsername() + "\n" + "Gender: " + idCardInfo.getGender() + "\n" + "Ethnicity: " + idCardInfo.getEthnic() + "\n" + "Address: " + idCardInfo.getAddress() + "\n" + "Birthday: " + idCardInfo.getBirthday() + "\n" + "Valid Period: " + idCardInfo.getIdValidStart() + " - " + idCardInfo.getIdValid() + "\n" + "Issuing Authority: " + idCardInfo.getIdDepartment() + "\n" + "ID Number: " + idCardInfo.getIdNumber(); }); } @Override public void onReadFailure(int i, @NonNull String s) { Log.e(TAG, "onReadFailure code: " + i + " msg: " + s); } @Override public void onInitSuccess(@NonNull String samId) { Log.e(TAG, "onInitSuccess samId: " + samId); } }); ``` ### **Qualcomm NFC Card Swiping & ID Card Swiping** ##### **Start Reading Regular IC Card** ``` NFCReadHelper.INSTANCE.startReadICCard(result -> { SoundPoolHelper.getInstance().playDi(); mViewBinding.tvText.setText("Card Number: " + result.getCardNumber()); }); ``` ##### **Stop Reading Card** ``` NFCReadHelper.INSTANCE.stopReadICCard(); ``` ##### **Start Reading ID Card** ``` NFCReadHelper.INSTANCE.startReadIDCard(idCardInfo -> { SoundPoolHelper.getInstance().playDi(); runOnUiThread(() -> { String idCardStr = "Name: " + idCardInfo.getUsername() + "\n" + "Gender: " + idCardInfo.getGender() + "\n" + "Ethnicity: " + idCardInfo.getEthnic() + "\n" + "Address: " + idCardInfo.getAddress() + "\n" + "Birthday: " + idCardInfo.getBirthday() + "\n" + "Valid Period: " + idCardInfo.getIdValidStart() + " - " + idCardInfo.getIdValid() + "\n" + "Issuing Authority: " + idCardInfo.getIdDepartment() + "\n" + "ID Number: " + idCardInfo.getIdNumber(); Log.i("TAG", "ID Card Read Successful " + mReadCount); }); }); ``` ##### **Stop Reading ID Card** ``` NFCReadHelper.INSTANCE.stopReadIDCard(); ``` ### **Barcode Scanning** ##### **Get Barcode Scanning Operation Instance** ``` private final HIDManager mHidManager = new HIDManager(); ``` ##### **Start Scanning** ``` mHidManager.init(new IHIDResultListener() { @Override public void onCompleteData(@NonNull String value) { Log.e(TAG, "HID Data: " + count + "\n" + value); } @Override public void onInitFailure(int code, @NonNull String msg) { // Currently only code 1 indicates initialization failure Log.e(TAG, "onInitFailure: code: " + code + " msg: " + msg); } @Override public void onLog(int code, @NonNull String msg) { Log.e(TAG, "onLog ----- : code: " + code + " msg: " + msg); } }); ``` ### **Serial Communication** ##### **Get Serial Port Builder Object** ``` MySerial.Builder serialBuilder = new MySerial.Builder(); ``` ##### **Set Serial Port Address** ``` serialBuilder.setSerialPath(path); ``` ##### **Set Baud Rate** ``` serialBuilder.setBaudRate(baudRate); ``` ##### **Set Receive Message Callback** ``` serialBuilder.setCallback(new ISerialDataCallback() { @Override public void onSimpleData(@Nullable byte[] bytes, int offset, int length) { if (bytes == null) { return; } StringBuilder str = new StringBuilder(); String[] hexStr = SerialPortUtilsKt.bytesArrayToHexStr(bytes, offset, length).split(" "); for (String s : hexStr) { if (!s.isEmpty()) { str.append(s); } } requireActivity().runOnUiThread(() -> { Log.i(TAG, "Data start ------ " + str); mViewBinding.tvReceive.append(str + "\n"); Log.i(TAG, "Data end ------"); }); } }); ``` ##### **Serial Port Operation Instance** ``` private MySerial mSerial = serialBuilder.build(); ``` ##### **Open Serial Port** ``` mSerial.openPort(); ``` ##### **Close Serial Port** ``` mSerial.closePort(); ``` ##### **Send Message** ``` mSerial.writePort(data); ``` ### **Wiegand** ##### **Listen for Wiegand Input Data** ``` ESWeigandManager.instance().getCardRead().startRead(new IReadCardCallback() { @Override public void onReadFailure(int code, @NonNull String msg) { mViewBinding.tvReceive.append("Wiegand Input Error: " + code + " msg: " + msg); } @Override public void onReadResult(@NonNull ReadCardResult result) { String cardNumber = result.getCardNumber(); mViewBinding.tvReceive.append("Wiegand Input: " + cardNumber + " Type: " + result.getType()); } }); ``` ##### **Wiegand 26 Output** ``` boolean result = ESWeigandManager.instance().getWiegandWrite().writeString(value, IWiegand.WIEGAND_TYPE_26); ``` ##### **Wiegand 34 Output** ``` boolean result = ESWeigandManager.instance().getWiegandWrite().writeString(value, IWiegand.WIEGAND_TYPE_34); ``` ### **Fingerprint** ##### **Get Fingerprint Operation Instance** ``` private Fingerprint mFingerprint = Fingerprint.instance(); ``` ##### **Initialize Fingerprint Module** ``` mFingerprint.init(); ``` ##### **Release Fingerprint Module** ``` mFingerprint.release(); ``` ##### **Start Fingerprint Enrollment** ``` mFingerprint.startEntry(true, new OnFingerprintEntryListener() { @Override public void onExtractSuccess(@NonNull byte[] fingerprint) { // key is the unique identifier for the enrolled fingerprint mFingerprint.addFingerprintTemplate(key, fingerprint); updateState("Enrollment Successful"); } @Override public void onUpdateState(int action, @NonNull String msg, int result) { if (action != Fingerprint.ACTION_GEN_CHAR || result != 0) { updateState("Enrollment: " + msg); } Log.i("FingerprintFragment", "Entry onUpdateState: " + action + " msg: " + msg + " result: " + result); } @Override public void onFingerprintImage(@NonNull byte[] image) { Log.i("FingerprintFragment", "onFingerprintImage: "); } }); ``` ##### **Stop Fingerprint Enrollment** ``` mFingerprint.stopEntry(); ``` ##### **Start Fingerprint Matching** ``` mFingerprint.startMatch(new OnFingerprintMatchListener() { @Override public void onUpdateState(int action, @NonNull String msg, int result) { updateState("Matching: " + msg); Log.i("FingerprintFragment", "Match onUpdateState: " + action + " msg: " + msg + " result: " + result); } @Override public void onMatchComplete(@NonNull List result) { FingerprintMatchResult fingerprint = result.get(0); int score = fingerprint.getScore(); if (score > 50) { updateState("Match Successful: " + fingerprint.getFingerprintKey() + " Similarity: " + score); } else { updateState("Match Failed: " + fingerprint.getFingerprintKey() + " Similarity: " + score); } } }); ``` ##### **Stop Fingerprint Matching** ``` mFingerprint.stopMatch(); ``` ### **Alcohol Detection** ##### **Get Alcohol Detection Operation Instance** ``` Alcohol alcohol = Alcohol.instance(); ``` ##### **Alcohol Detection Callback** ``` private IAlcoholCallBack alcoholCallBack = new IAlcoholCallBack() { @Override public void onReadResult(@NonNull AlcoholResult result) { int type = result.getType(); switch (type) { case 2: { // Prepare countdown break; } case 3: { // Start detection, please blow showLog("Alcohol Test: Start blowing"); break; } case 4: { // Blowing in progress showLog("Alcohol Test: Blowing in progress"); break; } case 5: { // Blowing interrupted error showLog("Alcohol Test: Blowing interrupted error"); break; } case 6: { // Blowing finished showLog("Alcohol Test: Blowing finished"); break; } case 7: { // Alcohol test result received showLog("Alcohol Test: Received result: " + result.getResult()); break; } case 8: { // Test stopped break; } case 48: { // Get reset value break; } case 160: { // Set blowing duration response showLog("Alcohol Test: Modified blowing duration"); break; } } } }; ``` ##### **Initialize Alcohol Detection Module** ``` alcohol.init(alcoholCallBack); ``` ##### **Release Resources** ``` alcohol.release(); ``` ##### **Start Detection** ``` alcohol.stopDetection(); ``` ##### **Stop Detection** ``` alcohol.stopDetection(); ``` ##### **Set Blowing Duration (Recommended 3 seconds)** ``` alcohol.changTestTime(3); ``` ### **Modbus Communication** ##### **Get Modbus Communication Instance** ``` private ModbusMasterWrapper modbusRtuMaster = new ModbusMasterWrapper(); ``` ##### **Initialize Communication** ```java ModbusSerialPortParam param = new ModbusSerialPortParam(); modbusRtuMaster.init(param, new OnRequestBack() { @Override public void onSuccess(String s) { Log.i(TAG, "modbus rtu init onSuccess: " + s); } @Override public void onFailed(String s) { Log.i(TAG, "modbus rtu init onFailed: " + s); } }); ``` ##### **End Communication** ``` modbusRtuMaster.destory(); ``` ##### **Write Holding Registers (16)** ``` short[] shortArray = {Short.parseShort("ff",16), Short.parseShort("0B",16), Short.parseShort("0C",16), Short.parseShort("0D",16)}; modbusRtuMaster.writeRegisters(new OnRequestBack() { @Override public void onSuccess(String s) { // Success callback } @Override public void onFailed(String s) { // Failure callback } }, 1, 1, shortArray); ``` ##### **Read Coil** ``` modbusRtuMaster.readCoil(new OnRequestBack() { @Override public void onSuccess(boolean[] booleen) { Log.d(TAG, "readCoil onSuccess " + Arrays.toString(booleen)); } @Override public void onFailed(String msg) { Log.e(TAG, "readCoil onFailed " + msg); } }, 1, 200, 1); ``` ##### **Read Discrete Input** ``` modbusRtuMaster.readDiscreteInput(new OnRequestBack() { @Override public void onSuccess(boolean[] booleen) { Log.d(TAG, "readDiscreteInput onSuccess " + Arrays.toString(booleen)); } @Override public void onFailed(String msg) { Log.e(TAG, "readDiscreteInput onFailed " + msg); } }, 1, 200, 1); ``` ##### **Read Input Registers** ``` modbusRtuMaster.readInputRegisters(new OnRequestBack() { @Override public void onSuccess(short[] data) { Log.d(TAG, "readInputRegisters onSuccess " + Arrays.toString(data)); } @Override public void onFailed(String msg) { Log.e(TAG, "readInputRegisters onFailed " + msg); } }, 1, 2, 8); ``` ##### **Write Coil** ``` getModbusMaster().writeCoil(new OnRequestBack() { @Override public void onSuccess(String s) { Log.e(TAG, "writeCoil onSuccess " + s); } @Override public void onFailed(String msg) { Log.e(TAG, "writeCoil onFailed " + msg); } }, 1, 1, true); ``` ##### **Write Register** ``` getModbusMaster().writeRegister(new OnRequestBack() { @Override public void onSuccess(String s) { Log.e(TAG, "writeRegister onSuccess " + s); } @Override public void onFailed(String msg) { Log.e(TAG, "writeRegister onFailed " + msg); } }, 1, 1, 234); ``` ### **Dual-Screen Display** ##### **Start Service and Connect to Secondary Screen** ``` PresentationServiceManager.INSTANCE.startService(() -> { Log.i(TAG,"Secondary screen connected successfully"); return Unit.INSTANCE; }); ``` ##### **Disconnect Screen** ``` PresentationServiceManager.INSTANCE.dismiss(); ``` ##### **Stop Service** ``` PresentationServiceManager.INSTANCE.stopService(); ``` ##### **Refresh Secondary Screen Content** ``` screenView: Secondary screen view PresentationServiceManager.INSTANCE.drawView(screenView); ``` ### **USB Drive Update** ##### **USB Drive Mount Listener** ``` private ExternalMountHelper.OnUDiskMountStateListener listener = new ExternalMountHelper.OnUDiskMountStateListener() { @Override public void mounted(String path) { // USB mounted callback } @Override public void eject(String path) { // USB ejected callback } }; UDiskFileSelectorApplication.getExternalMount().addMountStateListener(listener); ``` ##### **Get USB Root Path** ``` HashSet mRootPath = UDiskFileSelectorApplication.getExternalMount().getMountRootPaths(); ``` ##### **Install APK File** ``` ESSystem.instance().getSystemManager().installApk(file.getAbsolutePath()); ``` ### **USB Drive File Operations** ##### **USB Drive File Selection** ``` private ISelectorResultCallback mCallback = new ISelectorResultCallback() { @Override public boolean canDismiss() { return true; } @Override public void onExceedCountLimit(int limit) { Toast.makeText(requireContext(), "You can only select " + limit + " files at a time", Toast.LENGTH_SHORT).show(); } @Override public void onNoPreviousLevel() { Toast.makeText(requireContext(), "There is no previous directory", Toast.LENGTH_SHORT).show(); } @Override public boolean onOpenUsb() { return false; } @Override public void onResult(@NonNull List file) { for (File file1 : file) { if (file1 != null) { Log.i("FileSelectorFragment", "onResult: " + file1.getAbsolutePath()); } } } }; // Title is "Select Images" // Regular expression file filter rule, the rule here is "[^\\.].*\\.(jpg|png|jpeg)$" // Number of files that can be selected new UDiskFileSelectorFragment.Builder(mCallback) .setTitle("Select Images") .setFileRegex(UDiskFileSelectorFragment.REGEX_IMAGE_FILE) .setCount(9) .create() .show(getChildFragmentManager(), ""); ```