备用代码

hdrplus
Matthew 12 months ago
parent ba2b840cc8
commit 1b8bc084c4

@ -74,6 +74,7 @@
<application <application
android:dataExtractionRules="@xml/data_extraction_rules" android:dataExtractionRules="@xml/data_extraction_rules"
android:extractNativeLibs="true"
android:fullBackupContent="@xml/backup_rules" android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
@ -81,9 +82,12 @@
android:requestLegacyExternalStorage="true" android:requestLegacyExternalStorage="true"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.MicroPhoto" android:theme="@style/Theme.MicroPhoto"
android:extractNativeLibs="true"
tools:targetApi="28"> tools:targetApi="28">
<service
android:name=".BridgeService"
android:enabled="true"
android:exported="true"></service>
<activity <activity
android:name=".BridgeActivity" android:name=".BridgeActivity"
android:exported="true" /> android:exported="true" />
@ -94,17 +98,11 @@
<activity <activity
android:name=".v2.Camera2VideoActivityOld" android:name=".v2.Camera2VideoActivityOld"
android:exported="false" android:exported="false"
android:screenOrientation="landscape" android:screenOrientation="landscape" />
/>
<activity <activity
android:name=".v2.Camera2VideoActivity" android:name=".v2.Camera2VideoActivity"
android:exported="false" android:exported="false"
android:screenOrientation="landscape" android:screenOrientation="landscape" />
/>
<activity <activity
android:name=".ChannelActivity" android:name=".ChannelActivity"
android:exported="false" android:exported="false"

@ -1,16 +1,14 @@
package com.xypower.mpapp; package com.xypower.mpapp;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Base64; import android.util.Base64;
import android.util.Log;
import com.xypower.common.FileUtils; import com.xypower.common.FileUtils;
import com.xypower.common.JSONUtils; import com.xypower.common.JSONUtils;
@ -21,10 +19,11 @@ import org.json.JSONObject;
import java.io.File; import java.io.File;
import java.nio.file.Files;
public class BridgeActivity extends AppCompatActivity { public class BridgeActivity extends AppCompatActivity {
private final static String TAG = "MPLOG";
private final static String ACTION_IMP_PUBKEY = "imp_pubkey"; private final static String ACTION_IMP_PUBKEY = "imp_pubkey";
private final static String ACTION_GEN_KEYS = "gen_keys"; private final static String ACTION_GEN_KEYS = "gen_keys";
private final static String ACTION_CERT_REQ = "cert_req"; private final static String ACTION_CERT_REQ = "cert_req";
@ -201,6 +200,7 @@ public class BridgeActivity extends AppCompatActivity {
mHandler.postDelayed(new Runnable() { mHandler.postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
Log.i(TAG, "BridgeActivity will finish automatically");
activity.finish(); activity.finish();
} }
}, 2000); }, 2000);

@ -0,0 +1,236 @@
package com.xypower.mpapp;
import android.app.Service;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import androidx.annotation.Nullable;
import com.xypower.common.FileUtils;
import com.xypower.common.JSONUtils;
import com.xypower.common.MicroPhotoContext;
import com.xypower.mpapp.v2.Camera2VideoActivity;
import org.json.JSONObject;
import java.io.File;
public class BridgeService extends Service {
private final static String TAG = "MPLOG";
private final static String ACTION_IMP_PUBKEY = "imp_pubkey";
private final static String ACTION_GEN_KEYS = "gen_keys";
private final static String ACTION_CERT_REQ = "cert_req";
private final static String ACTION_BATTERY_VOLTAGE = "query_bv";
private final static String ACTION_RECORDING = "recording";
private final static String ACTION_TAKE_PHOTO = "take_photo";
private final static int REQUEST_CODE_RECORDING = Camera2VideoActivity.REQUEST_CODE_RECORDING;
private Handler mHandler = null;
private boolean m3V3TurnedOn = false;
private boolean mAutoClose = true;
private String mVideoFilePath = null;
public BridgeService() {
}
@Override
public void onCreate() {
super.onCreate();
mHandler = new Handler();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent == null) {
stopSelf();
return START_NOT_STICKY;
}
final String action = intent.getStringExtra("action");
if (!TextUtils.isEmpty(action)) {
if (TextUtils.equals(action, ACTION_IMP_PUBKEY)) {
String cert = intent.getStringExtra("cert");
String path = intent.getStringExtra("path");
int index = intent.getIntExtra("index", 1);
if (!TextUtils.isEmpty(cert)) {
// Import
// String cert = intent.getStringExtra("md5");
byte[] content = Base64.decode(cert, Base64.DEFAULT);
if (content != null) {
MicroPhotoService.importPublicKey(index, content);
}
} else if (TextUtils.isEmpty(path)) {
String md5 = intent.getStringExtra("md5");
File file = new File(path);
if (file.exists() && file.isFile()) {
MicroPhotoService.importPublicKeyFile(index, path, md5);
}
}
} else if (TextUtils.equals(action, ACTION_GEN_KEYS)) {
int index = intent.getIntExtra("index", 0);
boolean res = MicroPhotoService.genKeys(index);
String path = intent.getStringExtra("path");
if (!TextUtils.isEmpty(path)) {
FileUtils.ensureParentDirectoryExisted(path);
FileUtils.writeTextFile(path, res ? "1" : "0");
}
} else if (TextUtils.equals(action, ACTION_CERT_REQ)) {
int index = intent.getIntExtra("index", 0);
int type = intent.getIntExtra("type", 0);
String subject = intent.getStringExtra("subject");
String path = intent.getStringExtra("path");
MicroPhotoService.genCertRequest(index, type, subject, path);
} else if (TextUtils.equals(action, ACTION_BATTERY_VOLTAGE)) {
String path = intent.getStringExtra("path");
// #define CMD_GET_CHARGING_BUS_VOLTAGE_STATE 112
// #define CMD_GET_BAT_VOL_STATE 115
// #define CMD_GET_BAT_BUS_VOLTAGE_STATE 117
int bv = MicroPhotoService.getGpioInt(117);
int bcv = MicroPhotoService.getGpioInt(112);
if (!TextUtils.isEmpty(path)) {
FileUtils.ensureParentDirectoryExisted(path);
FileUtils.writeTextFile(path + ".tmp", Integer.toString(bv) + " " + Integer.toString(bcv));
File file = new File(path + ".tmp");
file.renameTo(new File(path));
}
} else if (TextUtils.equals(action, ACTION_TAKE_PHOTO)) {
String path = intent.getStringExtra("path");
int channel = intent.getIntExtra("channel", 1);
int preset = intent.getIntExtra("preset", 0xFF);
int width = intent.getIntExtra("width", 0);
int height = intent.getIntExtra("height", 0);
String leftTopOsd = intent.getStringExtra("leftTopOsd");
String rightTopOsd = intent.getStringExtra("rightTopOsd");
String rightBottomOsd = intent.getStringExtra("rightBottomOsd");
String leftBottomOsd = intent.getStringExtra("leftBottomOsd");
String appPath = MicroPhotoContext.buildMpAppDir(getApplicationContext());
File configFile = new File(appPath);
configFile = new File(configFile, "data/channels/" + Integer.toString(channel) + ".json");
File tmpConfigFile = new File(appPath);
tmpConfigFile = new File(tmpConfigFile, "tmp/" + Integer.toString(channel) + "-" + Long.toString(System.currentTimeMillis()) + ".json");
if (configFile.exists()) {
try {
FileUtils.copyFile(configFile, tmpConfigFile);
} catch (Exception ex) {
ex.printStackTrace();
}
}
JSONObject configJson = JSONUtils.loadJson(tmpConfigFile.getAbsolutePath());
try {
if (configJson == null) {
configJson = new JSONObject();
}
if (width > 0) {
configJson.put("resolutionCX", width);
}
if (height > 0) {
configJson.put("resolutionCY", height);
}
JSONObject osdJson = configJson.getJSONObject("osd");
if (osdJson == null) {
osdJson = configJson.put("osd", new JSONObject());
}
osdJson.put("leftTop", TextUtils.isEmpty(leftTopOsd) ? "" : leftTopOsd);
osdJson.put("rightTop", TextUtils.isEmpty(rightTopOsd) ? "" : rightTopOsd);
osdJson.put("rightBottom", TextUtils.isEmpty(rightBottomOsd) ? "" : rightBottomOsd);
osdJson.put("leftBottom", TextUtils.isEmpty(leftBottomOsd) ? "" : leftBottomOsd);
JSONUtils.saveJson(tmpConfigFile.getAbsolutePath(), configJson);
} catch (Exception ex) {
ex.printStackTrace();
}
File file = new File(path);
if (file.exists()) {
file.delete();
} else {
FileUtils.ensureParentDirectoryExisted(path);
}
MicroPhotoService.takePhoto(channel, preset, true, tmpConfigFile.getAbsolutePath(), path);
if (tmpConfigFile.exists()) {
tmpConfigFile.delete();
}
} else if (TextUtils.equals(action, ACTION_RECORDING)) {
String path = intent.getStringExtra("path");
int channel = intent.getIntExtra("channel", 1);
int cameraId = intent.getIntExtra("cameraId", -1);
int quality = intent.getIntExtra("quality", 0);
int width = intent.getIntExtra("width", 1280);
int height = intent.getIntExtra("height", 720);
int duration = intent.getIntExtra("duration", 15);
int orientation = intent.getIntExtra("orientation", 0);
long videoId = System.currentTimeMillis() / 1000;
String leftTopOsd = intent.getStringExtra("leftTopOsd");
String rightTopOsd = intent.getStringExtra("rightTopOsd");
String rightBottomOsd = intent.getStringExtra("rightBottomOsd");
String leftBottomOsd = intent.getStringExtra("leftBottomOsd");
if (cameraId == -1) {
cameraId = channel - 1;
}
Intent recordingIntent = MicroPhotoService.makeRecordingIntent(getApplicationContext(),
cameraId, videoId, duration, width, height, quality, orientation,
leftTopOsd, rightTopOsd, rightBottomOsd, leftBottomOsd);
mVideoFilePath = path;
mAutoClose = false;
recordingIntent.putExtra("ActivityResult", true);
// startActivityForResult(recordingIntent, REQUEST_CODE_RECORDING);
}
}
if (mAutoClose) {
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
Log.i(TAG, "BridgeActivity will finish automatically");
stopSelf();
}
}, 200);
}
return super.onStartCommand(intent, flags, startId);
}
/**
*
*/
@Override
public void onDestroy() {
super.onDestroy();
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
Loading…
Cancel
Save