From: TrillGates Date: Wed, 7 Apr 2021 07:42:19 +0000 (+0800) Subject: add pciture into database for fzd. X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=fb689b6204e9a210c42efd06af31a3e70a7b8ed6;p=protocol_srv.git add pciture into database for fzd. --- diff --git a/app/src/main/java/com/enqualcomm/support/CoreService.java b/app/src/main/java/com/enqualcomm/support/CoreService.java index 63505d4c..d03d73a8 100644 --- a/app/src/main/java/com/enqualcomm/support/CoreService.java +++ b/app/src/main/java/com/enqualcomm/support/CoreService.java @@ -348,8 +348,7 @@ public class CoreService extends Service { } public void onReceive(StringMessage param1StringMessage) { - - CoreService coreService = (CoreService) this.mReference.get(); + CoreService coreService = this.mReference.get(); ICLogger.i("onReceive " + param1StringMessage.cmd() + " coreService " + coreService); if (coreService == null) return; diff --git a/app/src/main/java/com/enqualcomm/support/ICSmsManager.java b/app/src/main/java/com/enqualcomm/support/ICSmsManager.java index 2f9da84f..c6fcb061 100644 --- a/app/src/main/java/com/enqualcomm/support/ICSmsManager.java +++ b/app/src/main/java/com/enqualcomm/support/ICSmsManager.java @@ -1091,7 +1091,7 @@ public class ICSmsManager extends BroadcastReceiver { mHandler.post(new Runnable() { @Override public void run() { - (new CameraUtil(mContext)).getPictur("capture" + TimeUtil.getSystemTime3()); + (new CameraUtil(mContext)).getPicture("capture" + TimeUtil.getSystemTime3()); } }); diff --git a/app/src/main/java/com/enqualcomm/support/service/Deliver.java b/app/src/main/java/com/enqualcomm/support/service/Deliver.java index 88531f5c..0fef380b 100644 --- a/app/src/main/java/com/enqualcomm/support/service/Deliver.java +++ b/app/src/main/java/com/enqualcomm/support/service/Deliver.java @@ -3,9 +3,11 @@ package com.enqualcomm.support.service; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; +import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.net.ConnectivityManager; +import android.net.Uri; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.os.Build; @@ -24,6 +26,8 @@ import com.enqualcomm.support.bean.Runtime; import com.enqualcomm.support.bean.StringMessage; import com.enqualcomm.support.bean.VoiceContent; import com.enqualcomm.support.bean.voicePacket; +import com.enqualcomm.support.provider.FZDDatabaseHelper; +import com.enqualcomm.support.provider.FZDMessageProvider; import com.enqualcomm.support.service.base.AbstractConnectionService; import com.enqualcomm.support.utils.Connection; import com.enqualcomm.support.utils.FileCache; @@ -444,11 +448,35 @@ public class Deliver extends AbstractConnectionService { return true; } else if ("PhotoRemoteTaken".equals(paramStringMessage.cmd())) { //接收到拍照完毕命令,发送照片 - + //TODO:这里要使用新的数据库了,保存到新的数据库上 + //通过群聊,把图片发送给手机端口 + //TODO:目前修改先不删除原来的代码,但是会保存到份到新的数据库里 + //监听数据库的变化来发送数据给到手机端的 + //storage/emulated/0/Pictures/TakePhoto_815cac71-396b-4359-93ea-dc12105a6173.jpg String msgUrl = paramStringMessage.isFromCache(); + ContentValues contentValues = new ContentValues(); + //路径 + contentValues.put("content", msgUrl); + //类型为声音 + contentValues.put("type", FZDDatabaseHelper.MessageType.PIC); + //状态:0表示未读 + contentValues.put("state", 0); + //文件时长 + contentValues.put("duration", 0); + //接受还是发送,1表示来信 + contentValues.put("in_or_out", 1); + //对方号码是没有的 + contentValues.put("remote_num", ""); + contentValues.put("create_time", System.currentTimeMillis()); + contentValues.put("update_time", System.currentTimeMillis()); + mRuntime.getContextProxy().getResolver().insert(Uri.parse(FZDMessageProvider.MESSAGES), + contentValues); ICLogger.i("receive taken photo to send " + msgUrl); + //保存到防走丢的数据库里 + //创建voiceConent并添加到数据 - final VoiceContent voiceContent = VoiceContent.placeHolderOut(CONTACT_CATEGORY_GROUP, "123", msgUrl, 2, 2); + final VoiceContent voiceContent = VoiceContent.placeHolderOut(CONTACT_CATEGORY_GROUP, + "123", msgUrl, 2, 2); // 把voiceContent拆解成1024的分包 Util.parseToVoicePacketSent(voiceContent); diff --git a/app/src/main/java/com/enqualcomm/support/utils/CameraUtil.java b/app/src/main/java/com/enqualcomm/support/utils/CameraUtil.java index 6b10f6ee..f2ff1fa4 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/CameraUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/CameraUtil.java @@ -1,7 +1,6 @@ package com.enqualcomm.support.utils; import android.content.Context; -import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; @@ -11,7 +10,6 @@ import android.hardware.Camera; import android.media.ToneGenerator; import android.os.Environment; import android.os.StatFs; -import android.text.TextUtils; import android.view.SurfaceView; import android.view.WindowManager; @@ -22,254 +20,249 @@ import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; -import static com.enqualcomm.support.Constants.ACTION_REMOTE_CAMERA; - public class CameraUtil implements SurfaceTexture.OnFrameAvailableListener { - Context context; - - private Camera.PictureCallback jpegCallback = new Camera.PictureCallback() { - public void onPictureTaken(byte[] param1ArrayOfByte, Camera param1Camera) { + Context context; + + private Camera.PictureCallback jpegCallback = (param1ArrayOfByte, param1Camera) -> { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("camera format="); stringBuilder.append(CameraUtil.this.mPs.getPictureFormat()); ICLogger.i(stringBuilder.toString()); if (CameraUtil.this.mPs.getPictureFormat() == 256) { - String str = CameraUtil.this.savePicture(param1ArrayOfByte); - if (str != null) { -// Intent intent = new Intent(CameraUtil.this.context, com.enqualcomm.support.CoreService.class); -//// intent.setAction(ACTION_REMOTE_CAMERA); -//// intent.putExtra("filepath", str); -//// intent.putExtra("number", CameraUtil.this.mNumber); -//// CameraUtil.this.context.startService(intent); - - if (CoreService.getInstance()!=null){ - CoreService.getInstance().DevliverStringMessage("PhotoRemoteTaken",str); + String str = CameraUtil.this.savePicture(param1ArrayOfByte); + if (str != null) { + if (CoreService.getInstance() != null) { + //str就是path. + CoreService.DevliverStringMessage("PhotoRemoteTaken", str); + } + } else { + ICLogger.i("camera 空间不足,保存失败"); } - } else { - ICLogger.i("camera 空间不足,保存失败"); - } - } + } CameraUtil.this.releaseCamera(); - } }; - - private Camera mCamera; - - String mNumber; - - private int mOrientation; - private int custom_camera_orientation=0; - private int custom_camera_mirror=0; - private Camera.Parameters mPs; - - private Camera.ShutterCallback shutterCallback = new Camera.ShutterCallback() { - public void onShutter() { ICLogger.i("camera shutterCallback"); } + + private Camera mCamera; + + String mNumber; + + private int mOrientation; + private int custom_camera_orientation = 0; + private int custom_camera_mirror = 0; + private Camera.Parameters mPs; + + private Camera.ShutterCallback shutterCallback = new Camera.ShutterCallback() { + public void onShutter() { + ICLogger.i("camera shutterCallback"); + } }; - - private SurfaceTexture surfaceTexture; - - private ToneGenerator tone; - - public CameraUtil(Context paramContext) { this.context = paramContext; } - - private Camera openFacingBackCamera() { - Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); - int i = Camera.getNumberOfCameras(); - Camera camera = null; - byte b = 0; - while (b < i) { - Camera.getCameraInfo(b, cameraInfo); - - if (cameraInfo.facing == 0) { - try { - camera = Camera.open(b); - } catch (RuntimeException e) { - e.printStackTrace(); + + private SurfaceTexture surfaceTexture; + + private ToneGenerator tone; + + public CameraUtil(Context paramContext) { + this.context = paramContext; + } + + private Camera openFacingBackCamera() { + Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); + int i = Camera.getNumberOfCameras(); + Camera camera = null; + byte b = 0; + while (b < i) { + Camera.getCameraInfo(b, cameraInfo); + + if (cameraInfo.facing == 0) { + try { + camera = Camera.open(b); + } catch (RuntimeException e) { + e.printStackTrace(); + } + } + b++; } - } - b++; - } - return camera; - } - - private void releaseCamera() { - if (this.mCamera != null) - try { - if (this.surfaceTexture != null) - this.surfaceTexture.setOnFrameAvailableListener(null); - this.mCamera.setPreviewTexture(null); - this.mCamera.stopPreview(); - } catch (Exception exception) { - exception.printStackTrace(); - } - this.mCamera.release(); - } - - private String savePicture(byte[] paramArrayOfByte) { - - int jpg_quality=Util.getSystemPropertiesInt("persist.sys.capture_quality",50); - String str = null; - try { - if (Environment.getExternalStorageState().equals("mounted")) { - if ((new StatFs(Environment.getExternalStorageDirectory().toString())).getAvailableBytes() < paramArrayOfByte.length) - return null; - str = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath(); - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(str); - stringBuilder.append("/TakePhoto_"); - stringBuilder.append(this.mNumber); - stringBuilder.append(".jpg"); - str = stringBuilder.toString(); - Bitmap bitmap1 = BitmapFactory.decodeByteArray(paramArrayOfByte, 0, paramArrayOfByte.length); - Bitmap bitmap2 = bitmap1; + return camera; + } + + private void releaseCamera() { + if (this.mCamera != null) + try { + if (this.surfaceTexture != null) + this.surfaceTexture.setOnFrameAvailableListener(null); + this.mCamera.setPreviewTexture(null); + this.mCamera.stopPreview(); + } catch (Exception exception) { + exception.printStackTrace(); + } + this.mCamera.release(); + } + + private String savePicture(byte[] paramArrayOfByte) { + + int jpg_quality = Util.getSystemPropertiesInt("persist.sys.capture_quality", 50); + String str = null; + try { + if (Environment.getExternalStorageState().equals("mounted")) { + if ((new StatFs(Environment.getExternalStorageDirectory().toString())).getAvailableBytes() < paramArrayOfByte.length) + return null; + str = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath(); + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(str); + stringBuilder.append("/TakePhoto_"); + stringBuilder.append(this.mNumber); + stringBuilder.append(".jpg"); + str = stringBuilder.toString(); + Bitmap bitmap1 = BitmapFactory.decodeByteArray(paramArrayOfByte, 0, paramArrayOfByte.length); + Bitmap bitmap2 = bitmap1; // if ((this.context.getResources().getConfiguration()).orientation == 1) { - custom_camera_mirror = Util.getSystemPropertiesInt("persist.sys.camera_cap_mirror",0); - Matrix matrix = new Matrix(); - matrix.reset(); - switch(custom_camera_orientation) - { - case 90: - case 270: - matrix.postRotate(custom_camera_orientation); - if(custom_camera_mirror==-1) - matrix.postScale(-1, 1); - else if(custom_camera_mirror==-2) - matrix.postScale(1,-1); - - bitmap2 = Bitmap.createBitmap(bitmap1, 0, 0, bitmap1.getWidth(), bitmap1.getHeight(), matrix, true); - break; - case 0: - case 180: - if(custom_camera_mirror<0) { - if (custom_camera_mirror == -1) - matrix.postScale(-1, 1); - else if (custom_camera_mirror == -2) - matrix.postScale(1, -1); - bitmap2 = Bitmap.createBitmap(bitmap1, 0, 0, bitmap1.getWidth(), bitmap1.getHeight(), matrix, true); + custom_camera_mirror = Util.getSystemPropertiesInt("persist.sys.camera_cap_mirror", 0); + Matrix matrix = new Matrix(); + matrix.reset(); + switch (custom_camera_orientation) { + case 90: + case 270: + matrix.postRotate(custom_camera_orientation); + if (custom_camera_mirror == -1) + matrix.postScale(-1, 1); + else if (custom_camera_mirror == -2) + matrix.postScale(1, -1); + + bitmap2 = Bitmap.createBitmap(bitmap1, 0, 0, bitmap1.getWidth(), bitmap1.getHeight(), matrix, true); + break; + case 0: + case 180: + if (custom_camera_mirror < 0) { + if (custom_camera_mirror == -1) + matrix.postScale(-1, 1); + else if (custom_camera_mirror == -2) + matrix.postScale(1, -1); + bitmap2 = Bitmap.createBitmap(bitmap1, 0, 0, bitmap1.getWidth(), bitmap1.getHeight(), matrix, true); + } + default: + break; + } + + Bitmap bitmap3 = bitmap2; + if (Config.needWaterMark()) { + bitmap3 = ImageUtil.drawTextToLeftTop(this.context, bitmap2, TimeUtil.getSystemTimeForCameraMark(), 50, Color.RED, 25, 25); + } + File file = new File(str); + if (!file.exists()) + file.createNewFile(); + BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file)); + bitmap3.compress(Bitmap.CompressFormat.JPEG, jpg_quality, bufferedOutputStream); + bufferedOutputStream.flush(); + bufferedOutputStream.close(); + + ICLogger.i("camera Take Photo and Save to " + str); } - default: - break; + return str; + } catch (Exception e) { + e.printStackTrace(); + return null; } + } - Bitmap bitmap3 = bitmap2; - if(Config.needWaterMark()) { - bitmap3 = ImageUtil.drawTextToLeftTop(this.context, bitmap2, TimeUtil.getSystemTimeForCameraMark(), 50, Color.RED, 25, 25); - } - File file = new File(str); - if (!file.exists()) - file.createNewFile(); - BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file)); - bitmap3.compress(Bitmap.CompressFormat.JPEG, jpg_quality, bufferedOutputStream); - bufferedOutputStream.flush(); - bufferedOutputStream.close(); - - ICLogger.i("camera Take Photo and Save to "+str); - } - return str; - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - private void takePicture(Context paramContext) { - if (this.mCamera != null) { - SurfaceView surfaceView = new SurfaceView(paramContext); - int width=640; - int height=480; - try { - this.mCamera.setPreviewDisplay(surfaceView.getHolder()); - this.mPs = this.mCamera.getParameters(); - String picsize=Util.getSystemProperties("persist.sys.camera_capsize","640x480"); - - if (!picsize.trim().isEmpty() ){ - String sizes[]= picsize.toLowerCase().split("x"); - if(sizes.length==2){ - try{ - int tmpw=Integer.parseInt(sizes[0]); - int tmph=Integer.parseInt(sizes[1]); - width=tmpw; - height=tmph; - }catch (Exception e){} - } + private void takePicture(Context paramContext) { + if (this.mCamera != null) { + SurfaceView surfaceView = new SurfaceView(paramContext); + int width = 640; + int height = 480; + try { + this.mCamera.setPreviewDisplay(surfaceView.getHolder()); + this.mPs = this.mCamera.getParameters(); + String picsize = Util.getSystemProperties("persist.sys.camera_capsize", "640x480"); + + if (!picsize.trim().isEmpty()) { + String sizes[] = picsize.toLowerCase().split("x"); + if (sizes.length == 2) { + try { + int tmpw = Integer.parseInt(sizes[0]); + int tmph = Integer.parseInt(sizes[1]); + width = tmpw; + height = tmph; + } catch (Exception e) { + } + } + } + + ICLogger.i("CameraUtil---setCamera capture size " + width + "x" + height); + this.mPs.setPictureSize(width, height); + setCameraDisplayOrientation(paramContext, 0, this.mCamera); + this.mCamera.setParameters(this.mPs); + ICLogger.i("CameraUtil---startPreview"); + this.surfaceTexture = new SurfaceTexture(10); + this.surfaceTexture.setOnFrameAvailableListener(this); + this.mCamera.setPreviewTexture(this.surfaceTexture); + this.mCamera.startPreview(); + this.mCamera.enableShutterSound(false); + (new Thread(() -> { + try { + CameraUtil.this.mCamera.takePicture(CameraUtil.this.shutterCallback, null, CameraUtil.this.jpegCallback); + Util.mSleep(5000); + return; + } catch (Exception exception) { + exception.printStackTrace(); + CameraUtil.this.releaseCamera(); + return; + } + })).start(); + return; + } catch (Exception e) { + e.printStackTrace(); + releaseCamera(); + } } + } - ICLogger.i("CameraUtil---setCamera capture size "+ width+"x"+height ); - this.mPs.setPictureSize(width, height); - setCameraDisplayOrientation(paramContext, 0, this.mCamera); - this.mCamera.setParameters(this.mPs); - ICLogger.i("CameraUtil---startPreview"); - this.surfaceTexture = new SurfaceTexture(10); - this.surfaceTexture.setOnFrameAvailableListener(this); - this.mCamera.setPreviewTexture(this.surfaceTexture); - this.mCamera.startPreview(); - this.mCamera.enableShutterSound(false); - (new Thread(new Runnable() { - public void run() { - try { - CameraUtil.this.mCamera.takePicture(CameraUtil.this.shutterCallback, null, CameraUtil.this.jpegCallback); - Util.mSleep(5000); - return; - } catch (Exception exception) { - exception.printStackTrace(); - CameraUtil.this.releaseCamera(); - return; - } - } - })).start(); - return; - } catch (Exception e) { - e.printStackTrace(); - releaseCamera(); - } - } - } - - public int getDisplayRotation(Context paramContext) { - int i = ((WindowManager)paramContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation(); - - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("camera getDisplayRotation rotation="); - stringBuilder.append(i); - ICLogger.i(stringBuilder.toString()); - - switch (i) { - default: + public int getDisplayRotation(Context paramContext) { + int i = ((WindowManager) paramContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation(); + + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("camera getDisplayRotation rotation="); + stringBuilder.append(i); + ICLogger.i(stringBuilder.toString()); + + switch (i) { + default: + return 0; + case 3: + return 270; + case 2: + return 180; + case 1: + return 90; + case 0: + break; + } return 0; - case 3: - return 270; - case 2: - return 180; - case 1: - return 90; - case 0: - break; - } - return 0; - } - - public void getPictur(String paramString) { - this.mCamera = openFacingBackCamera(); - takePicture(this.context); - this.mNumber = paramString; - } - - public void onFrameAvailable(SurfaceTexture paramSurfaceTexture) { ICLogger.i("camera onFrameAvailable"); } - - public void setCameraDisplayOrientation(Context paramContext, int paramInt, Camera paramCamera) { - Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); - Camera.getCameraInfo(paramInt, cameraInfo); - paramInt = getDisplayRotation(paramContext); - custom_camera_orientation=Util.getSystemPropertiesInt("persist.sys.camera_orientation",0); - ICLogger.i("camera getDisplayRotation1 "+paramInt+" cameraInfo.orientation "+cameraInfo.orientation+ " custom_camera_orientation "+custom_camera_orientation); + } - if (cameraInfo.facing == 1) { - paramInt = (360 - (custom_camera_orientation + paramInt) % 360) % 360; - } else { - paramInt = (custom_camera_orientation - paramInt + 360) % 360; + public void getPicture(String paramString) { + this.mCamera = openFacingBackCamera(); + takePicture(this.context); + this.mNumber = paramString; } + + public void onFrameAvailable(SurfaceTexture paramSurfaceTexture) { + ICLogger.i("camera onFrameAvailable"); + } + + public void setCameraDisplayOrientation(Context paramContext, int paramInt, Camera paramCamera) { + Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); + Camera.getCameraInfo(paramInt, cameraInfo); + paramInt = getDisplayRotation(paramContext); + custom_camera_orientation = Util.getSystemPropertiesInt("persist.sys.camera_orientation", 0); + ICLogger.i("camera getDisplayRotation1 " + paramInt + " cameraInfo.orientation " + cameraInfo.orientation + " custom_camera_orientation " + custom_camera_orientation); + + if (cameraInfo.facing == 1) { + paramInt = (360 - (custom_camera_orientation + paramInt) % 360) % 360; + } else { + paramInt = (custom_camera_orientation - paramInt + 360) % 360; + } /* if (cameraInfo.facing == 1) { paramInt = (360 - (cameraInfo.orientation + paramInt) % 360) % 360; @@ -277,10 +270,10 @@ public class CameraUtil implements SurfaceTexture.OnFrameAvailableListener { paramInt = (cameraInfo.orientation - paramInt + 360) % 360; }*/ - ICLogger.i("camera final display orientation "+paramInt); + ICLogger.i("camera final display orientation " + paramInt); - paramCamera.setDisplayOrientation(paramInt); - this.mOrientation = paramInt; - } + paramCamera.setDisplayOrientation(paramInt); + this.mOrientation = paramInt; + } } diff --git a/app/src/main/java/com/enqualcomm/support/utils/ProcessReceiver.java b/app/src/main/java/com/enqualcomm/support/utils/ProcessReceiver.java index 25de2ec2..f767ee11 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/ProcessReceiver.java +++ b/app/src/main/java/com/enqualcomm/support/utils/ProcessReceiver.java @@ -369,7 +369,7 @@ public class ProcessReceiver extends BroadcastReceiver { mHandler.post(new Runnable() { @Override public void run() { - (new CameraUtil(paramContext)).getPictur(str1); + (new CameraUtil(paramContext)).getPicture(str1); } }); } else { diff --git a/app/src/main/java/com/ic/protocols/protocol_fzd.java b/app/src/main/java/com/ic/protocols/protocol_fzd.java index 07f340ca..08f83a56 100644 --- a/app/src/main/java/com/ic/protocols/protocol_fzd.java +++ b/app/src/main/java/com/ic/protocols/protocol_fzd.java @@ -11,6 +11,8 @@ import android.media.Ringtone; import android.media.RingtoneManager; import android.net.Uri; import android.os.Environment; +import android.os.Handler; +import android.os.HandlerThread; import android.os.RemoteCallbackList; import android.text.TextUtils; @@ -26,6 +28,7 @@ import com.enqualcomm.support.provider.FZDDatabaseHelper; import com.enqualcomm.support.provider.FZDMembersProvider; import com.enqualcomm.support.provider.FZDMessageProvider; import com.enqualcomm.support.service.HeartRateManager; +import com.enqualcomm.support.utils.CameraUtil; import com.enqualcomm.support.utils.Connection; import com.enqualcomm.support.utils.ICLogger; import com.enqualcomm.support.utils.MD5; @@ -41,6 +44,7 @@ import java.io.RandomAccessFile; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; +import java.util.UUID; import static com.enqualcomm.support.Constants.FROM_SERVER; import static com.enqualcomm.support.Constants.contact; @@ -67,9 +71,10 @@ public class protocol_fzd { private static final String CMDHEADERSPLIT = "*"; private static final String CMDSPLIT = ","; private static final boolean doEncryption = Util.getSystemProperties("persist.sys.encrypt_fzd", "true").equals("true"); - public static final String defaultServerIP = "fzd.xcloudtech.com"; + public static final String defaultServerIP = "api.xcloudtech.com"; public static final int defaultServerPort = 9000; private final SharedPreferences sharedPreferences; + private final Handler mHandler; /** * 发送语音消息,微聊的,注意转码 @@ -235,6 +240,7 @@ public class protocol_fzd { public enum CMD_TYPE { /*终端发起*/ //链路保持数据 + rcapture, LK,//登录 PING,//绑定查询 KA,//心跳包 @@ -296,6 +302,7 @@ public class protocol_fzd { cmdMap = new HashMap<>(); cmdMap.put(CMD_TYPE.LK, "LK"); cmdMap.put(CMD_TYPE.PING, "PING"); + cmdMap.put(CMD_TYPE.rcapture, "rcapture"); cmdMap.put(CMD_TYPE.KA, "KA"); cmdMap.put(CMD_TYPE.UD, "UD"); cmdMap.put(CMD_TYPE.UD2, "UD2"); @@ -357,6 +364,9 @@ public class protocol_fzd { mRuntime = runtime; //创建一个sp,用于保存佰锐通讯相关的临时数据 sharedPreferences = runtime.getContextProxy().context.getSharedPreferences(FZD_SP, Context.MODE_PRIVATE); + HandlerThread handlerThread = new HandlerThread("ic:fzd-handler"); + handlerThread.start(); + mHandler = new Handler(handlerThread.getLooper()); } @@ -1245,8 +1255,8 @@ public class protocol_fzd { case LK: //登录包 ICLogger.i("服务器收到登录包LK"); mConnection.DeliverCMDMessageToSystem("login", cmd);//通知下面线程状态变化 - //测试一下获取天气消息 - //mConnection.send(WT2(mRuntime)); + //测试一下 + mConnection.send(WG(mRuntime)); break; case KA: ICLogger.i("服务器收到心跳包KA"); @@ -1361,12 +1371,54 @@ public class protocol_fzd { handleWT2(data); mConnection.DeliverCMDMessageToSystem("WT2", cmd); break; - + case WG: + ICLogger.d("收到请求的地理位置详细信息...WG"); + handleWG(data); + break; + case rcapture: + ICLogger.d("收到远程拍照的指令...rcapture"); + handleCapture(mRuntime); + mConnection.DeliverCMDMessageToSystem("rcapture", cmd); + break; } return ret; } + /** + * 处理远程拍照 + */ + private void handleCapture(Runtime runtime) { + UUID uuid = UUID.randomUUID(); + String idStr = uuid.toString(); + ICLogger.d("do picture get..."); + mHandler.post(() -> + (new CameraUtil(runtime.getContextProxy().context)).getPicture(idStr)); + } + + /** + * 处理地理位置请求的数据 + * + * @param data + */ + private void handleWG(String data) { + //先切割,再解码 + String[] split = data.split(CMDSPLIT); + if (split.length == 4) { + String latitude = split[0]; + String longitude = split[1]; + String precision = split[2]; + String address = Util.decodeUnicode2Utf8(split[3]); + ICLogger.d("latitude == > " + latitude); + ICLogger.d("longitude == > " + longitude); + ICLogger.d("precision == > " + precision); + ICLogger.d("address == > " + address); + } else { + //数据长度不对 + ICLogger.d("WG data len is not right..." + data); + } + } + /** * 处理天气结果,WT2,与WT格式不一样 * [XT*334588000000156*009F*WT2,深圳市,多云,-27 度,西风,1 级,2016-11-14,10:00:00] @@ -1454,6 +1506,15 @@ public class protocol_fzd { return genFZDCMD(cmdMap.get(CMD_TYPE.TK), result); } + /** + * 详细解释地理位置信息 + */ + private StringMessage WG(Runtime runtime) { + String locationData = getLocationData(runtime); + String cmd = cmdMap.get(CMD_TYPE.WG); + return genFZDCMD(cmd, locationData); + } + private StringMessage MESSAGE() { return genFZDCMD(cmdMap.get(CMD_TYPE.MESSAGE)); } diff --git a/app/src/main/java/com/ic/protocols/protocol_ic.java b/app/src/main/java/com/ic/protocols/protocol_ic.java index 1e3e65fa..c8ca426a 100644 --- a/app/src/main/java/com/ic/protocols/protocol_ic.java +++ b/app/src/main/java/com/ic/protocols/protocol_ic.java @@ -2328,10 +2328,11 @@ public class protocol_ic { } public static StringMessage AP46(String id, String cmd) { - return genStringMessage(cmdMap.get(CMD_TYPE.AP46), new StringBuffer(CMDHEADER).append(cmdMap.get(CMD_TYPE.AP46)) - .append(CMDSPLIT).append(id) - .append(CMDSPLIT).append(cmd) - .append(CMDEND).toString()); + return genStringMessage(cmdMap.get(CMD_TYPE.AP46), + new StringBuffer(CMDHEADER).append(cmdMap.get(CMD_TYPE.AP46)) + .append(CMDSPLIT).append(id) + .append(CMDSPLIT).append(cmd) + .append(CMDEND).toString()); } public void handleBP46(String cmd, Connection connection, Runtime runtime) { @@ -2372,7 +2373,7 @@ public class protocol_ic { mHandler.post(new Runnable() { @Override public void run() { - (new CameraUtil(context)).getPictur(id); + (new CameraUtil(context)).getPicture(id); } });