fctom1215
2020-02-11 3ce7d9cbccabf7f94d8203a98796599cd9dd5411
lib/src/main/java/com/anyun/exam/lib/RemoteService.java
@@ -16,6 +16,7 @@
import androidx.annotation.Nullable;
import java.io.UnsupportedEncodingException;
import java.util.concurrent.atomic.AtomicBoolean;
/**
@@ -52,8 +53,18 @@
        @Override
        public void SendCmd(int cmd, String value) throws RemoteException {
            Log.d(TAG, "Process " + Process.myPid() + " Thread " + Thread.currentThread().getId() + " RecvMsgFromMainProc cmd = " + String.format(" %04X ", cmd) + " length " + value.length() + " value " + value.trim());
            MainProcMsgEntry(cmd, value.trim());
            if (cmd == 0x8100) {
                try {
                    byte [] file = value.getBytes("ISO-8859-1");
                    Log.d(TAG, byte2hex(file));
                    MainProcBinMsgEntry(cmd, file, file.length);
                } catch (UnsupportedEncodingException e) {
                    Log.d(TAG, "UnsupportedEncodingException");
                }
            } else {
                Log.d(TAG, "Process " + Process.myPid() + " Thread " + Thread.currentThread().getId() + " RecvMsgFromMainProc cmd = " + String.format(" %04X ", cmd) + " length " + value.length() + " value " + value.trim());
                MainProcMsgEntry(cmd, value.trim());
            }
        }
    };
    @Nullable
@@ -108,6 +119,9 @@
        if (!mIsServiceDestroyed.get()){
            onMessageArrived(cmd, value);
        }
        Log.d(TAG, "SendMsgToMainProc cmd = " + String.format("%04X", cmd) + " json = " + value);
    }
@@ -136,6 +150,23 @@
        }
    }
    private String byte2hex(byte [] buffer){
        StringBuilder h = new StringBuilder();
        Log.d(TAG, "byte buffer length = " + buffer.length);
        for(int i = 0; i < buffer.length; i++){
            String temp = Integer.toHexString(buffer[i] & 0xFF);
            if(temp.length() == 1){
                temp = "0" + temp;
            }
            h.append(temp);
            h.append(" ");
        }
        return h.toString();
    }
    // Used to load the 'native-lib' library on application startup.
    static {
        System.loadLibrary("native-lib");
@@ -143,4 +174,5 @@
    public native void startNative();
    public native void MainProcMsgEntry(int cmd, String value);
    public native void MainProcBinMsgEntry(int cmd, byte []data, int length);
}