| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | */ |
| | | 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(); |
| | |
| | | // 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 { |
| | |
| | | class StartNative implements Runnable { |
| | | @Override |
| | | public void run() { |
| | | startNative(); |
| | | startNative(mAyDevice); |
| | | } |
| | | } |
| | | |
| | |
| | | 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(); |
| | |
| | | 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) { |
| | |
| | | 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); |