把生成密钥的结果记录在文件中,供调用方查询

main
Matthew 1 year ago
parent 3aef7c7641
commit 6990895b19

@ -9,8 +9,8 @@ android {
applicationId "com.xypower.secapp"
minSdk 28
targetSdk 28
versionCode 1
versionName "1.0"
versionCode 2
versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {

@ -0,0 +1,20 @@
{
"version": 3,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "com.xypower.secapp",
"variantName": "release",
"elements": [
{
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 2,
"versionName": "1.1",
"outputFile": "app-release.apk"
}
],
"elementType": "File"
}

@ -1,25 +0,0 @@
package com.xypower.secapp;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.xinyingpower.myapplication", appContext.getPackageName());
}
}

@ -16,6 +16,7 @@ import android.widget.TextView;
import com.dowse.devicesdk.DsDeviceSdk;
import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
@ -132,6 +133,25 @@ public class CertActivity extends AppCompatActivity {
//
}
protected static void writeTextFile(String path, String content) {
FileOutputStream fileOutputStream = null;
try {
fileOutputStream = new FileOutputStream(path);
byte[] bytes = content.getBytes();
fileOutputStream.write(bytes);
} catch (Exception ex) {
} finally {
if (fileOutputStream != null) {
try {
fileOutputStream.close();
} catch (Exception ex) {
}
}
}
}
protected void handleCommand(Intent intent) {
final String action = intent.getStringExtra("action");
@ -157,7 +177,10 @@ public class CertActivity extends AppCompatActivity {
}
} else if (TextUtils.equals(action, ACTION_GEN_KEYS)) {
int index = intent.getIntExtra("index", 0);
String path = intent.getStringExtra("path");
ensureDirectoryExisted(path);
boolean res = MicroPhotoService.genKeys(index);
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);

@ -1,17 +0,0 @@
package com.xypower.secapp;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
Loading…
Cancel
Save