增加加密相关的实现

serial
Matthew 1 year ago
parent 36d5a2de2b
commit 350d08862c

@ -289,10 +289,10 @@ add_library( # Sets the name of the library.
MicroPhoto.cpp
TerminalDevice.cpp
PhoneDevice.cpp
PhoneDevice2.cpp
Camera.cpp
Camera2Reader.cpp
TextPaint.cpp
// PhoneDevice2.cpp
// Camera.cpp
// Camera2Reader.cpp
// TextPaint.cpp
CvText.cpp
SerialPort.cpp
@ -321,6 +321,8 @@ add_library( # Sets the name of the library.
${TERM_CORE_ROOT}/Template.cpp
${TERM_CORE_ROOT}/Utils.cpp
${TERM_CORE_ROOT}/md5.c
${TERM_CORE_ROOT}/Client/SpiPort.cpp
${TERM_CORE_ROOT}/Client/NrsecPort.cpp
${TERM_CORE_ROOT}/Client/TerminalService.cpp
${TERM_CORE_ROOT}/Client/Terminal.cpp
${TERM_CORE_ROOT}/Client/Terminal_HN.cpp

@ -268,7 +268,7 @@ Java_com_xypower_mpapp_MicroPhotoService_init(
JNIEnv* env,
jobject pThis, jstring appPath,
jstring ip, jint port, jstring cmdid, jint protocol,
jint networkProtocol, jlong netHandle, jint signalLevel, jint versionCode) {
jint networkProtocol, jint encryptData, jlong netHandle, jint signalLevel, jint versionCode) {
/*
google_breakpad::MinidumpDescriptor descriptor(".");
@ -310,7 +310,7 @@ Java_com_xypower_mpapp_MicroPhotoService_init(
device->SetListener(pTerminal);
device->UpdateSignalLevel(signalLevel);
pTerminal->InitServerInfo(appPathStr, cmdidStr, ipStr, port, udpOrTcp);
pTerminal->InitServerInfo(appPathStr, cmdidStr, ipStr, port, udpOrTcp, encryptData);
// pTerminal->SetPacketSize(1 * 1024); // 1K
bool res = pTerminal->Startup(device);

@ -168,8 +168,6 @@ CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPa
m_signalLevel = 0;
m_signalLevelUpdateTime = time(NULL);
m_sysApiClass = NULL;
RegisterHandlerForSignal(SIGUSR2);
m_vm = vm;
@ -199,16 +197,6 @@ CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPa
env->DeleteLocalRef(classService);
jclass classSysApi = env->FindClass("com/dev/devapi/api/SysApi");
if(classSysApi != NULL)
{
m_sysApiClass = (jclass)env->NewGlobalRef(classSysApi);
mTurnOtgMid = env->GetStaticMethodID(classSysApi, "setOtgState", "(Z)V");
mSetCam3V3EnableMid = env->GetStaticMethodID(classSysApi, "setCam3V3Enable", "(Z)V");
env->DeleteLocalRef(classSysApi);
}
if (didAttachThread)
{
vm->DetachCurrentThread();
@ -237,16 +225,11 @@ CPhoneDevice::~CPhoneDevice()
ALOGE("Failed to get JNI Env");
}
env->DeleteGlobalRef(m_javaService);
if (m_sysApiClass != NULL)
{
env->DeleteGlobalRef(m_sysApiClass);
}
if (didAttachThread)
{
m_vm->DetachCurrentThread();
}
m_javaService = NULL;
m_sysApiClass = NULL;
if (m_pRecognizationCfg != NULL)
{
@ -326,13 +309,13 @@ bool CPhoneDevice::UpdateSchedules()
}
return (ret == JNI_TRUE);
}
bool CPhoneDevice::QuerySystemProperties(std::map<std::string, std::string>& properties)
{
char value[PROP_VALUE_MAX] = { 0 };
std::map<std::string, std::string> powerInfo;
int res = 0;
for (std::map<std::string, std::string>::iterator it = properties.begin(); it != properties.end(); ++it)
{
@ -558,8 +541,6 @@ bool CPhoneDevice::InstallAPP(const std::string& path, unsigned int delayedTime)
}
return true;
}
bool CPhoneDevice::Reboot(int resetType)
@ -607,6 +588,45 @@ bool CPhoneDevice::EnableGPS(bool enabled)
return true;
}
float CPhoneDevice::QueryBattaryVoltage(int timesForAvg, bool* isCharging)
{
if (timesForAvg <= 0)
{
return 0.0f;
}
int val = 0;
int totalVals = 0;
float chargingBusVoltage = 0.0f;
for (int idx = 0; idx < timesForAvg; )
{
val = GpioControl::getChargingBusVoltage();
if (val > 0)
{
chargingBusVoltage = (float)val / 1000.0;
idx++;
break;
}
}
if (isCharging != NULL)
{
*isCharging = chargingBusVoltage > 10.0;
}
for (int idx = 0; idx < timesForAvg; )
{
val = GpioControl::getBatteryVoltage(); // // BatVol
if (val > 0)
{
totalVals += val > BATTARY_VOLTAGE_MAX ? BATTARY_VOLTAGE_MAX : val;
idx++;
}
}
return (float)totalVals / 1000.0 / timesForAvg;
}
bool CPhoneDevice::RequestPosition()
{
JNIEnv* env = NULL;
@ -858,8 +878,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
mOsds = osds;
NdkCamera::CAMERA_PARAMS params;
params.hdrMode = mPhotoInfo.hdrMode;
params.nightMode = mPhotoInfo.nightMode;
params.sceneMode = mPhotoInfo.sceneMode;
params.autoFocus = mPhotoInfo.autoFocus;
params.autoExposure = mPhotoInfo.autoExposure;
params.focusTimeout = mPhotoInfo.focusTimeout * 1000;
@ -1158,7 +1177,7 @@ bool CPhoneDevice::OnImageReady(cv::Mat& mat)
unsigned int extime = (captureResult.exposureTime >= 1000000) ? ((unsigned int)(captureResult.exposureTime / 1000000)) : ((unsigned int)(captureResult.exposureTime / 1000));
strcpy(extimeunit, (captureResult.exposureTime >= 1000000) ? "ms" : "ns");
char str[128] = { 0 };
snprintf(str, sizeof(str), "AE=%u EXPS=%u%s ISO=%d AF=%u LDR=%d AFS=%u AES=%u HDR=%d AWB=%u", captureResult.autoExposure,
snprintf(str, sizeof(str), "AE=%u EXPS=%u%s ISO=%d AF=%u LDR=%d AFS=%u AES=%u SCENE=%d AWB=%u", captureResult.autoExposure,
extime, extimeunit,
captureResult.sensitibity,
captureResult.autoFocus,
@ -1166,7 +1185,7 @@ bool CPhoneDevice::OnImageReady(cv::Mat& mat)
GpioControl::getLightAdc(),
(unsigned int)captureResult.afState,
(unsigned int)captureResult.aeState,
captureResult.hdrMode,
captureResult.sceneMode,
captureResult.awbState);
// cv::putText(mat, str, cv::Point(0, mat.rows - 20), cv::FONT_HERSHEY_COMPLEX, fontScale, scalar, thickness1, cv::LINE_AA);

@ -186,6 +186,7 @@ public:
virtual bool InstallAPP(const std::string& path, unsigned int delayedTime);
virtual bool Reboot(int resetType);
virtual bool EnableGPS(bool enabled);
virtual float QueryBattaryVoltage(int timesForAvg, bool* isCharging);
virtual bool RequestPosition();
virtual timer_uid_t RegisterHeartbeat(unsigned int timerType, unsigned int timeout);
virtual bool TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<OSD_INFO>& osds, const std::string& path);
@ -254,8 +255,7 @@ protected:
JavaVM* m_vm;
jobject m_javaService;
jclass m_sysApiClass;
std::string m_appPath;
std::string m_appPath;
jmethodID mRegisterHeartbeatMid;
jmethodID mUpdateCaptureScheduleMid;
@ -272,9 +272,6 @@ protected:
jmethodID mEnableGpsMid;
jmethodID mRequestPositionMid;
jmethodID mTurnOtgMid;
jmethodID mSetCam3V3EnableMid;
std::string mPath;
IDevice::PHOTO_INFO mPhotoInfo;
vector<IDevice::OSD_INFO> mOsds;

@ -30,6 +30,7 @@ import android.text.TextUtils;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.Toast;
import com.dev.devapi.api.SysApi;
@ -112,6 +113,7 @@ public class MainActivity extends AppCompatActivity {
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
// getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
// InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
// imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
@ -203,6 +205,9 @@ public class MainActivity extends AppCompatActivity {
if (appConfig.networkProtocol < binding.networkProtocol.getCount()) {
binding.networkProtocol.setSelection(appConfig.networkProtocol);
}
if (appConfig.encryption < binding.encryptions.getCount()) {
binding.encryptions.setSelection(appConfig.encryption);
}
binding.heartbeat.setText((appConfig.heartbeat > 0) ? Integer.toString(appConfig.heartbeat) : "");
binding.packetSize.setText((appConfig.packetSize > 0) ? Integer.toString(appConfig.packetSize) : "");
@ -517,6 +522,7 @@ public class MainActivity extends AppCompatActivity {
intent.putExtra("port", curAppConfig.port);
intent.putExtra("protocol", curAppConfig.protocol);
intent.putExtra("networkProtocol", curAppConfig.networkProtocol);
intent.putExtra("encryption", curAppConfig.encryption);
intent.putExtra("network", curAppConfig.network);
if (messenger != null) {
intent.putExtra("messenger", messenger);
@ -622,6 +628,7 @@ public class MainActivity extends AppCompatActivity {
appConfig.protocol = Integer.parseInt(parts[0]);
}
appConfig.networkProtocol = MainActivity.this.binding.networkProtocol.getSelectedItemPosition();
appConfig.encryption = MainActivity.this.binding.encryptions.getSelectedItemPosition();
appConfig.heartbeat = TextUtils.isEmpty(binding.heartbeat.getText().toString()) ? 0 : Integer.parseInt(binding.heartbeat.getText().toString());
appConfig.packetSize = TextUtils.isEmpty(binding.packetSize.getText().toString()) ? 0 : Integer.parseInt(binding.packetSize.getText().toString());
@ -634,11 +641,11 @@ public class MainActivity extends AppCompatActivity {
}
private MicroPhotoContext.AppConfig getAppConfig() {
return MicroPhotoContext.getAppConfig(this.getApplicationContext());
return MicroPhotoContext.getMpAppConfig(this.getApplicationContext());
}
private void saveAppConfig(MicroPhotoContext.AppConfig appConfig) {
MicroPhotoContext.saveAppConfig(getApplicationContext(), appConfig);
MicroPhotoContext.saveMpAppConfig(getApplicationContext(), appConfig);
}
private int getDefaultDataSubId() {

@ -266,56 +266,6 @@ public class MicroPhotoService extends Service {
super.onDestroy();
}
public boolean drawText(Bitmap bitmap, String[] osds, float[] x, float[] y, int fontSize, int strokeWidth, int quality, String path) {
Canvas canvas = new Canvas(bitmap);
TextPaint paint = new TextPaint();
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setColor(Color.WHITE);
paint.setStrokeWidth(0);
paint.setTextSize(fontSize);
paint.setAntiAlias(true);
for (int idx = 0; idx < osds.length; idx++) {
canvas.drawText(osds[idx], x[idx], y[idx], paint);
}
TextPaint paint2 = new TextPaint();
paint2.setColor(Color.BLACK);
paint2.setStyle(Paint.Style.STROKE);
paint2.setStrokeWidth(strokeWidth);
paint2.setTextSize(fontSize);
paint2.setAntiAlias(true);
for (int idx = 0; idx < osds.length; idx++) {
canvas.drawText(osds[idx], x[idx], y[idx], paint2);
}
FileOutputStream fileOutputStream = null;
try {
File file = new File(path);
if (file.exists()) {
file.delete();
}
fileOutputStream = new FileOutputStream(file);
return bitmap.compress(Bitmap.CompressFormat.JPEG, quality, fileOutputStream);
} catch (Exception ex) {
} finally {
if (fileOutputStream != null) {
try {
fileOutputStream.close();
} catch (Exception ex) {
}
}
}
return false;
}
public static class ServiceHandler extends Handler {
@Override
public void dispatchMessage(Message msg) {
@ -674,6 +624,7 @@ public class MicroPhotoService extends Service {
final String cmdid = intent.getStringExtra("cmdid");
final int protocol = intent.getIntExtra("protocol", 0);
final int networkProtocol = intent.getIntExtra("networkProtocol", 0);
final int encryptData = intent.getIntExtra("encryption", 0);
Runnable runnable = new Runnable() {
public void run() {
@ -698,7 +649,7 @@ public class MicroPhotoService extends Service {
int versionCode = MicroPhotoContext.getVersionCode(MicroPhotoService.this.getApplicationContext());
service.mNativeHandle = init(appPath, server, port, cmdid, protocol, networkProtocol, 0, service.getSignalLevel(), versionCode);
service.mNativeHandle = init(appPath, server, port, cmdid, protocol, networkProtocol, encryptData, 0, service.getSignalLevel(), versionCode);
if (service.mNativeHandle !=0) {
isRunning = true;
@ -1103,7 +1054,7 @@ CellSignalStrengthGsm cellSignalStrengthGsm = cellInfoGsm.getCellSignalStrength(
cellSignalStrengthGsm.getDbm();
*/
protected native long init(String appPath, String ip, int port, String cmdid, int protocol, int networkProtocl, long netHandle, int signalLevel, int versionCode);
protected native long init(String appPath, String ip, int port, String cmdid, int protocol, int networkProtocl, int encryptData, long netHandle, int signalLevel, int versionCode);
protected native long getHeartbeatDuration(long handler);
protected native long[] getPhotoTimeData(long handler, long startTime);
protected native long[] getPhotoTimeData2(long handler);

@ -53,7 +53,7 @@
<EditText
android:id="@+id/server"
android:layout_width="128dp"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:maxLines="1"
android:lines="1"
@ -87,6 +87,16 @@
app:layout_constraintLeft_toRightOf="@+id/port"
app:layout_constraintTop_toTopOf="@+id/port" />
<Spinner
android:id="@+id/encryptions"
style="@style/Widget.AppCompat.Spinner.Underlined"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:spinnerMode="dropdown"
android:entries="@array/encryptions"
app:layout_constraintLeft_toRightOf="@+id/networkProtocol"
app:layout_constraintTop_toTopOf="@+id/port" />
<TextView
android:id="@+id/textViewHeartbeat"
android:layout_width="wrap_content"
@ -353,8 +363,6 @@
app:layout_constraintStart_toEndOf="@+id/simchange"
app:layout_constraintTop_toBottomOf="@+id/btnStartServ" />
<Button
android:id="@+id/gps"
android:layout_width="wrap_content"
@ -417,7 +425,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="right"
app:constraint_referenced_ids="textViewCmdId,cmdid,protocol,networkProtocol,btnSaveCfg,btnTakePhoto4,btnChannels,network,takeVideoBtn4"
app:constraint_referenced_ids="textViewCmdId,cmdid,protocol,networkProtocol,encryptions,btnSaveCfg,btnTakePhoto4,btnChannels,network,takeVideoBtn4"
tools:layout_editor_absoluteX="46dp" />

@ -80,6 +80,16 @@
app:layout_constraintLeft_toRightOf="@+id/port"
app:layout_constraintTop_toTopOf="@+id/port" />
<Spinner
android:id="@+id/encryptions"
style="@style/Widget.AppCompat.Spinner.Underlined"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:spinnerMode="dropdown"
android:entries="@array/encryptions"
app:layout_constraintLeft_toRightOf="@+id/networkProtocol"
app:layout_constraintTop_toTopOf="@+id/port" />
<TextView
android:id="@+id/textViewHeartbeat"
android:layout_width="wrap_content"
@ -373,7 +383,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="right"
app:constraint_referenced_ids="textViewCmdId,cmdid,protocol,networkProtocol,btnSaveCfg,btnTakePhoto4,btnChannels"
app:constraint_referenced_ids="textViewCmdId,cmdid,protocol,networkProtocol,encryptions,btnSaveCfg,btnTakePhoto4,btnChannels"
tools:layout_editor_absoluteX="46dp" />
<TextView

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="encryptions">
<item>0 - 无</item>
<item>1 - 明文</item>
<item>2 - 加密</item>
</string-array>
</resources>

@ -37,6 +37,7 @@ public class MicroPhotoContext {
public int network; // 0: SIM1 1: SIM2 2: WIFI
public int heartbeat;
public int packetSize;
public int encryption;
}
public static class MasterConfig {
@ -140,34 +141,6 @@ public class MicroPhotoContext {
return path;
}
public static AppConfig getAppConfig(Context context) {
AppConfig appConfig = new AppConfig();
String appPath = buildAppDir(context);
try {
String content = readTextFile(appPath + "data/App.json");
JSONObject jsonObject = TextUtils.isEmpty(content) ? new JSONObject() : new JSONObject(content);
appConfig.cmdid = jsonObject.optString(jsonObject.has("cmdid") ? "cmdid" : "CMDID", "");
appConfig.server = jsonObject.optString(jsonObject.has("server") ? "server" : "Server", "");
appConfig.port = jsonObject.optInt(jsonObject.has("port") ? "port" : "Port", 0);
appConfig.protocol = jsonObject.optInt(jsonObject.has("protocol") ? "protocol" : "Protocol", DEFAULT_PROTOCOL);
appConfig.networkProtocol = jsonObject.optInt(jsonObject.has("networkProtocol") ? "networkProtocol" : "NetworkProtocol", 0);
appConfig.network = jsonObject.optInt(jsonObject.has("network") ? "network" : "Network", 0);
appConfig.heartbeat = jsonObject.optInt("heartbeat", 0);
appConfig.packetSize = jsonObject.optInt("packetSize", 0);
if (appConfig.protocol == 0) {
appConfig.protocol = DEFAULT_PROTOCOL;
}
} catch (JSONException e) {
e.printStackTrace();
}
return appConfig;
}
public static AppConfig getMpAppConfig(Context context) {
AppConfig appConfig = new AppConfig();
@ -186,6 +159,7 @@ public class MicroPhotoContext {
appConfig.network = jsonObject.optInt(jsonObject.has("network") ? "network" : "Network", 0);
appConfig.heartbeat = jsonObject.optInt("heartbeat", 0);
appConfig.packetSize = jsonObject.optInt("packetSize", 0);
appConfig.encryption = jsonObject.optInt("encryption", 0);
if (appConfig.protocol == 0) {
appConfig.protocol = DEFAULT_PROTOCOL;
@ -197,64 +171,6 @@ public class MicroPhotoContext {
return appConfig;
}
public static void saveAppConfig(Context context, AppConfig appConfig) {
String appPath = buildAppDir(context);
FileOutputStream fos = null;
OutputStreamWriter outputStreamWriter = null;
try {
File dataPath = new File(appPath + "data/");
if (!dataPath.exists()) {
dataPath.mkdirs();
}
String content = readTextFile(appPath + "data/App.json");
JSONObject jsonObject = TextUtils.isEmpty(content) ? new JSONObject() : new JSONObject(content);
jsonObject.put("CMDID", appConfig.cmdid);
jsonObject.put("server", appConfig.server);
jsonObject.put("port", appConfig.port);
jsonObject.put("protocol", appConfig.protocol);
jsonObject.put("networkProtocol", appConfig.networkProtocol);
jsonObject.put("network", appConfig.network);
if (appConfig.heartbeat > 0) {
jsonObject.put("heartbeat", appConfig.heartbeat);
} else {
jsonObject.remove("heartbeat");
}
if (appConfig.packetSize > 0) {
jsonObject.put("packetSize", appConfig.packetSize);
} else {
jsonObject.remove("packetSize");
}
fos = new FileOutputStream(new File(appPath + "data/App.json"));
outputStreamWriter = new OutputStreamWriter(fos, "UTF-8");
outputStreamWriter.write(jsonObject.toString());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} finally {
if (outputStreamWriter != null) {
try {
outputStreamWriter.close();
} catch (Exception ex) {
}
}
if (fos != null) {
try {
fos.close();
} catch (Exception ex) {
}
}
}
}
public static MasterConfig getMasterConfig(Context context) {
MasterConfig masterConfig = new MasterConfig();
@ -386,6 +302,7 @@ public class MicroPhotoContext {
jsonObject.put("protocol", appConfig.protocol);
jsonObject.put("networkProtocol", appConfig.networkProtocol);
jsonObject.put("network", appConfig.network);
jsonObject.put("encryption", appConfig.encryption);
if (appConfig.heartbeat > 0) {
jsonObject.put("heartbeat", appConfig.heartbeat);

Loading…
Cancel
Save