yy1717
2021-01-12 683b1595260e638d1d3c6cc0d6543a72f6d6f925
lib/src/main/java/com/anyun/exam/lib/RemoteService.java
@@ -13,6 +13,7 @@
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
@@ -36,6 +37,7 @@
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
@@ -55,6 +57,9 @@
 */
public class RemoteService extends Service {
    private static final String TAG = "RemoteService";
    public static final boolean mAyDevice = true;
    /**服务是否销毁标志*/
    private AtomicBoolean mIsServiceDestroyed = new AtomicBoolean(false);
    private RemoteCallbackList<IListenerInterface> mListenerList = new RemoteCallbackList();
@@ -134,14 +139,31 @@
//        PlayRing(this, ringUri);
        LimitMaxMinVolume();
        if (mAyDevice == false) {
            mBluetooth = Bluetooth.getInstance(getApplicationContext(), mHandler);
            mBluetooth.OpenBluetooth();
            // Initialize the BluetoothChatService to perform mBluetooth connections
            mChatService = new BluetoothChatService(this, mHandler);
        }
        Log.d(TAG, "基带版本 " + getBaseband_Ver());
        String ver = getBaseband_Ver();
        mBluetooth = Bluetooth.getInstance(getApplicationContext(), mHandler);
        mBluetooth.OpenBluetooth();
        // Initialize the BluetoothChatService to perform mBluetooth connections
        mChatService = new BluetoothChatService(this, mHandler);
        new Thread(new TestCls()).start();
    }
    class TestCls implements Runnable {
        @Override
        public void run() {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
            }
            upgrade.ManualUpgrade(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "/Download/aks3b.apk");
        }
    }
    class AutoUpdateMcuThread implements Runnable {
@@ -273,7 +295,7 @@
    class StartNative implements Runnable {
        @Override
        public void run() {
            startNative();
            startNative(mAyDevice);
        }
    }
@@ -296,10 +318,10 @@
        Process.killProcess(Process.myPid());
    }
    private void onMessageArrived(int cmd, String json) {
    private int onMessageArrived(int cmd, String json) {
        Log.d(TAG, "SendMsgToMainProc cmd = " + String.format("%04X", cmd) + " json = " + json);
        int N = mListenerList.getRegisteredCallbackCount();
        int ret = -1;
        synchronized(this) {
            mListenerList.beginBroadcast();
@@ -308,19 +330,24 @@
                if (mListener != null) {
                    try {
                        mListener.onMessageArrived(cmd, json);
                        ret = 0;
                    } catch (RemoteException e) {
                        e.printStackTrace();
                    }
                }else{
                }
            }
            mListenerList.finishBroadcast();
        }
        return ret;
    }
    public void SendMsgToMainProc(int cmd, String value) {
    public int SendMsgToMainProc(int cmd, String value) {
        if (!mIsServiceDestroyed.get()){
            onMessageArrived(cmd, value);
            return onMessageArrived(cmd, value);
        }
        return -2;
    }
    public String javaDESEncrypt(String plaintext, String key) {
@@ -539,7 +566,7 @@
        System.loadLibrary("native-lib");
    }
    public native void startNative();
    public native void startNative(boolean ayDevice);
    public native void MainProcMsgEntry(int cmd, String value);
    public native void MainProcBinMsgEntry(int cmd, byte []data, int length);
    public native void UpgradeMcu(String vercode, byte []rom);