fixed l02 voice chat issues.
authorTrillGates <williamtrillgates@gmail.com>
Tue, 16 Mar 2021 03:25:51 +0000 (11:25 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Tue, 16 Mar 2021 03:25:51 +0000 (11:25 +0800)
app/src/main/java/com/enqualcomm/support/CoreService.java
app/src/main/java/com/enqualcomm/support/service/SendChatMessage.java

index c101e0e..f72b0c2 100644 (file)
@@ -12,6 +12,8 @@ import android.media.AudioManager;
 import android.os.Handler;
 import android.os.HandlerThread;
 import android.os.IBinder;
+import android.os.Message;
+import android.os.Messenger;
 import android.os.PowerManager;
 import android.os.SystemClock;
 import android.support.annotation.Nullable;
@@ -113,6 +115,8 @@ public class CoreService extends Service {
 
     public static final int interval = 60000;
 
+    final Messenger mMessenger = new Messenger(new RequestHandler(this));
+
     public static boolean needLocateInAfterHeartBeat = false;
     private static int is_allowed_in_sleep_mode = 1;
 
@@ -155,6 +159,23 @@ public class CoreService extends Service {
         }
     };
 
+    private static class RequestHandler extends Handler {
+        private final WeakReference<CoreService> mReference;
+
+        RequestHandler(CoreService param1CoreService) {
+            this.mReference = new WeakReference(param1CoreService);
+        }
+
+        public void handleMessage(Message param1Message) {
+            CoreService coreService = (CoreService) this.mReference.get();
+            if (coreService == null) {
+                return;
+            }
+            coreService.invokeHandlerServiceChain.processUserRequest(param1Message,
+                    coreService.connection, coreService.runtime);
+        }
+    }
+
     private BroadcastReceiver TimeChangeBroadcastReceiver = new BroadcastReceiver() {
         public void onReceive(Context param1Context, Intent param1Intent) {
             StringBuilder stringBuilder2 = new StringBuilder();
@@ -1647,7 +1668,7 @@ public class CoreService extends Service {
             }
             return mFZDService;
         }
-        return null;
+        return this.mMessenger.getBinder();
     }
 
     public void disconnect_server() {
index 436070a..f92e308 100644 (file)
@@ -7,13 +7,11 @@ import android.os.Bundle;
 import android.os.Message;\r
 import android.os.Messenger;\r
 \r
-import com.enqualcomm.support.CoreService;\r
 import com.enqualcomm.support.bean.Runtime;\r
 import com.enqualcomm.support.bean.VoiceContent;\r
 import com.enqualcomm.support.service.base.AbstractInvokeHandlerService;\r
 import com.enqualcomm.support.utils.Connection;\r
 import com.enqualcomm.support.utils.ICLogger;\r
-import com.enqualcomm.support.utils.NettyConnection;\r
 import com.enqualcomm.support.utils.SimSignalUtil;\r
 import com.enqualcomm.support.utils.TimeUtil;\r
 import com.enqualcomm.support.utils.Util;\r
@@ -21,27 +19,27 @@ import com.enqualcomm.support.utils.Util;
 import static com.enqualcomm.support.bean.Content.CONTACT_CATEGORY_GROUP;\r
 \r
 public class SendChatMessage extends AbstractInvokeHandlerService {\r
-  private static final int LOCATION_TYPE = 7;\r
-  \r
-  private int mNetworkType;\r
-  \r
-  private SimSignalUtil mSignalUtil;\r
-  \r
-  static  {\r
-  \r
-  }\r
-  \r
-  private void callback(Messenger paramMessenger, int paramInt) {\r
-    if (paramMessenger != null)\r
-      try {\r
-        paramMessenger.send(Message.obtain(null, paramInt));\r
-        return;\r
-      } catch (Exception e) {\r
-        e.printStackTrace();\r
-      }  \r
-  }\r
-  \r
-  private void deleteImage(String paramString, Context paramContext) {\r
+    private static final int LOCATION_TYPE = 7;\r
+\r
+    private int mNetworkType;\r
+\r
+    private SimSignalUtil mSignalUtil;\r
+\r
+    static {\r
+\r
+    }\r
+\r
+    private void callback(Messenger paramMessenger, int paramInt) {\r
+        if (paramMessenger != null)\r
+            try {\r
+                paramMessenger.send(Message.obtain(null, paramInt));\r
+                return;\r
+            } catch (Exception e) {\r
+                e.printStackTrace();\r
+            }\r
+    }\r
+\r
+    private void deleteImage(String paramString, Context paramContext) {\r
 //    Uri uri1;\r
 //    ContentResolver contentResolver = paramContext.getContentResolver();\r
 //    Uri uri2 = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;\r
@@ -60,29 +58,34 @@ public class SendChatMessage extends AbstractInvokeHandlerService {
 //      return;\r
 //    }\r
 //    ICLogger.i("删除失败");\r
-  }\r
-  \r
-  public void onAlarmClock(Connection paramConnection, Runtime paramRuntime) {}\r
-  \r
-  public void onAttach(Connection paramConnection, Runtime paramRuntime) { this.mSignalUtil = SimSignalUtil.getInstance((paramRuntime.getContextProxy()).context); }\r
-  \r
-  public void onDetach(Connection paramConnection, Runtime paramRuntime) {}\r
-  \r
-  public boolean onUserRequest(Intent paramIntent, Connection paramConnection, final Runtime runtime) {\r
-    String str = paramIntent.getAction();\r
-    if ("com.enqualcomm.support.ACTION_REMOTE_CAMERA".equals(str)) {\r
-      this.mSignalUtil = SimSignalUtil.getInstance((runtime.getContextProxy()).context);\r
-      str = paramIntent.getStringExtra("filepath");\r
-      String str1 = paramIntent.getStringExtra("number");\r
-      if (str != null) {\r
-        if (str1 == null)\r
-          return true; \r
-        StringBuilder stringBuilder = new StringBuilder();\r
-        stringBuilder.append("filepath == ");\r
-        stringBuilder.append(str);\r
-        stringBuilder.append("number == ");\r
-        stringBuilder.append(str1);\r
-        ICLogger.i(stringBuilder.toString());\r
+    }\r
+\r
+    public void onAlarmClock(Connection paramConnection, Runtime paramRuntime) {\r
+    }\r
+\r
+    public void onAttach(Connection paramConnection, Runtime paramRuntime) {\r
+        this.mSignalUtil = SimSignalUtil.getInstance((paramRuntime.getContextProxy()).context);\r
+    }\r
+\r
+    public void onDetach(Connection paramConnection, Runtime paramRuntime) {\r
+    }\r
+\r
+    public boolean onUserRequest(Intent paramIntent, Connection paramConnection, final Runtime runtime) {\r
+        String action = paramIntent.getAction();\r
+        ICLogger.d("str == > action ===> " + action);\r
+        if ("com.enqualcomm.support.ACTION_REMOTE_CAMERA".equals(action)) {\r
+            this.mSignalUtil = SimSignalUtil.getInstance((runtime.getContextProxy()).context);\r
+            action = paramIntent.getStringExtra("filepath");\r
+            String str1 = paramIntent.getStringExtra("number");\r
+            if (action != null) {\r
+                if (str1 == null)\r
+                    return true;\r
+                StringBuilder stringBuilder = new StringBuilder();\r
+                stringBuilder.append("filepath == ");\r
+                stringBuilder.append(action);\r
+                stringBuilder.append("number == ");\r
+                stringBuilder.append(str1);\r
+                ICLogger.i(stringBuilder.toString());\r
 //        final PictureContent pictureContent = PictureContent.placeHolderOut(1, str1, str);\r
 //        final Uri uri = runtime.getDbHelper().insertOrUpdate(pictureContent, 0L);\r
 //        Observable.create(new SendFileMessage(API.H30(paramRuntime, str1, "2", new File(str)), paramRuntime)).subscribeOn(Schedulers.io()).subscribe(new Subscriber<String>() {\r
@@ -105,58 +108,56 @@ public class SendChatMessage extends AbstractInvokeHandlerService {
 //                runtime.getDbHelper().updateMessage(pictureContent, uri);\r
 //              }\r
 //            });\r
-      } else {\r
-        return true;\r
-      } \r
-    } else if (!"SYNC".equals(str) && "com.enqualcomm.imessage.ACTION_ADDTEST_CONTACTS".equals(str)) {\r
-      ICLogger.i("添加测试人员名单");\r
-    } \r
-    return false;\r
-  }\r
-  \r
-  public boolean onUserRequest(Message paramMessage, Connection paramConnection, final Runtime runtime) {\r
-\r
-    ICLogger.i("=============received Message What="+paramMessage.what);\r
-    int i = 1;\r
-    switch (paramMessage.what) {\r
-      default:\r
+            } else {\r
+                return true;\r
+            }\r
+        } else if (!"SYNC".equals(action) && "com.enqualcomm.imessage.ACTION_ADDTEST_CONTACTS".equals(action)) {\r
+            ICLogger.i("添加测试人员名单");\r
+        }\r
         return false;\r
-      case 1001:\r
-        this.mSignalUtil = SimSignalUtil.getInstance((runtime.getContextProxy()).context);\r
-        this.mNetworkType = this.mSignalUtil.getNetworkType();\r
-        Bundle bundle = paramMessage.getData();\r
-        String filepath = bundle.getString("filepath");\r
-        String number = bundle.getString("number");\r
-        int category = bundle.getInt("category", -1);\r
-        ICLogger.i(" msg.what 101 category="+category+", filepath="+filepath+",number="+number);\r
-\r
-\r
-          if (filepath == null || number == null || category == -1)\r
-            return true;\r
-\r
-            //创建voiceConent并添加到数据\r
-            final VoiceContent voiceContent = VoiceContent.placeHolderOut(CONTACT_CATEGORY_GROUP, number, filepath,1,3);\r
-            final Uri uri2 = runtime.getDbHelper().insertOrUpdate(voiceContent, bundle.getLong("id"));\r
-\r
-            //回复UI消息,表示已经接收到\r
-            Messenger messenger = paramMessage.replyTo;\r
-            callback(messenger, 200);\r
-          voiceContent.status = 3;\r
-          voiceContent.serverTime = TimeUtil.getSystemTime3();\r
-//          voiceContent.content = Util.cutFile(voiceContent.content, runtime.getCacheDir());\r
-          voiceContent.preview = String.valueOf(Util.getDuration(voiceContent.content));\r
-          runtime.getDbHelper().updateMessage(voiceContent, uri2);\r
+    }\r
 \r
+    public boolean onUserRequest(Message paramMessage, Connection paramConnection, final Runtime runtime) {\r
 \r
+        ICLogger.i("=============received Message What=" + paramMessage.what);\r
+        switch (paramMessage.what) {\r
+            default:\r
+                return false;\r
+            case 1001:\r
+                this.mSignalUtil = SimSignalUtil.getInstance((runtime.getContextProxy()).context);\r
+                this.mNetworkType = this.mSignalUtil.getNetworkType();\r
+                Bundle bundle = paramMessage.getData();\r
+                String filepath = bundle.getString("filepath");\r
+                String number = bundle.getString("number");\r
+                int category = bundle.getInt("category", -1);\r
+                ICLogger.i(" msg.what 101 category=" + category + ", filepath=" + filepath + ",number=" + number);\r
 \r
-          // 把voiceContent拆解成1024的分包\r
-            Util.parseToVoicePacketSent(voiceContent);\r
-            //trigger 分包发送\r
-            paramConnection.DeliverCMDMessageToSystem("SentVoicePacket", "");\r
 \r
-      case 1000:\r
-        break;\r
-    }\r
+                if (filepath == null || number == null || category == -1)\r
+                    return true;\r
+\r
+                //创建voiceConent并添加到数据\r
+                final VoiceContent voiceContent = VoiceContent.placeHolderOut(CONTACT_CATEGORY_GROUP, number, filepath, 1, 3);\r
+                final Uri uri2 = runtime.getDbHelper().insertOrUpdate(voiceContent, bundle.getLong("id"));\r
+\r
+                //回复UI消息,表示已经接收到\r
+                Messenger messenger = paramMessage.replyTo;\r
+                callback(messenger, 200);\r
+                voiceContent.status = 3;\r
+                voiceContent.serverTime = TimeUtil.getSystemTime3();\r
+//          voiceContent.content = Util.cutFile(voiceContent.content, runtime.getCacheDir());\r
+                voiceContent.preview = String.valueOf(Util.getDuration(voiceContent.content));\r
+                runtime.getDbHelper().updateMessage(voiceContent, uri2);\r
+\r
+\r
+                // 把voiceContent拆解成1024的分包\r
+                Util.parseToVoicePacketSent(voiceContent);\r
+                //trigger 分包发送\r
+                paramConnection.DeliverCMDMessageToSystem("SentVoicePacket", "");\r
+\r
+            case 1000:\r
+                break;\r
+        }\r
 //    Bundle bundle1 = paramMessage.getData();\r
 //    i = bundle1.getInt("category");\r
 //    Observable.create(new GetVoice(String.valueOf(i), bundle1.getString("number"), bundle1.getString("filepath"), String.valueOf(i), paramRuntime)).subscribeOn(Schedulers.io()).subscribe(new Subscriber<VoiceContent>() {\r
@@ -174,7 +175,7 @@ public class SendChatMessage extends AbstractInvokeHandlerService {
 //            runtime.getDbHelper().updateMessage(param1VoiceContent, this.uri);\r
 //          }\r
 //        });\r
-    return true;\r
-  }\r
+        return true;\r
+    }\r
 }\r
 \r