通过ContentProvider提供接口
parent
af9c659ea5
commit
e5e3f4c57e
Binary file not shown.
@ -1,34 +1,37 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
package="com.xypower.secapp" >
|
package="com.xypower.secapp">
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
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"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.SecApp"
|
android:theme="@style/Theme.SecApp"
|
||||||
android:extractNativeLibs="true"
|
tools:targetApi="28">
|
||||||
tools:targetApi="28" >
|
<provider
|
||||||
|
android:name=".BridgeProvider"
|
||||||
|
android:authorities="com.xypower.mpapp.provider"
|
||||||
|
android:enabled="true"
|
||||||
|
android:exported="true"></provider>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:exported="true" >
|
android:exported="true"></activity>
|
||||||
</activity>
|
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".CertActivity"
|
android:name=".CertActivity"
|
||||||
android:exported="true">
|
android:exported="true">
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
@ -0,0 +1,205 @@
|
|||||||
|
package com.xypower.secapp;
|
||||||
|
|
||||||
|
import android.content.ContentProvider;
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.UriMatcher;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.MatrixCursor;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.util.Base64;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.xypower.common.FilesUtils;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class BridgeProvider extends ContentProvider {
|
||||||
|
|
||||||
|
private static String TAG = "CERTTAG";
|
||||||
|
|
||||||
|
private final static String AUTHORITY = "com.xypower.mpapp.provider";
|
||||||
|
private final static String PATH_QUERY_SEC_VERSION = "/querySecVersion";
|
||||||
|
private final static String PATH_IMP_PRI_KEY = "/importPriKey";
|
||||||
|
private final static String PATH_IMP_PUB_KEY = "/importPubKey";
|
||||||
|
private final static String PATH_GEN_KEYS = "/genKeys";
|
||||||
|
private final static String PATH_GEN_CERT_REQ = "/genCertReq";
|
||||||
|
|
||||||
|
public BridgeProvider() {
|
||||||
|
Log.i(TAG, "BridgeProvider");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int delete(Uri uri, String selection, String[] selectionArgs) {
|
||||||
|
// Implement this to handle requests to delete one or more rows.
|
||||||
|
throw new UnsupportedOperationException("Not yet implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType(Uri uri) {
|
||||||
|
// TODO: Implement this to handle requests for the MIME type of the data
|
||||||
|
// at the given URI.
|
||||||
|
throw new UnsupportedOperationException("Not yet implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Uri insert(Uri uri, ContentValues values) {
|
||||||
|
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreate() {
|
||||||
|
// TODO: Implement this to initialize your content provider on startup.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Cursor query(Uri uri, String[] projection, String selection,
|
||||||
|
String[] selectionArgs, String sortOrder) {
|
||||||
|
UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
|
||||||
|
|
||||||
|
Log.i(TAG, uri.toString());
|
||||||
|
matcher.addURI(AUTHORITY, PATH_QUERY_SEC_VERSION, 1);
|
||||||
|
|
||||||
|
Cursor cursor = null;
|
||||||
|
int matched = matcher.match(uri);
|
||||||
|
switch (matched) {
|
||||||
|
case 1:
|
||||||
|
cursor = querySecVersion();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int update(Uri uri, ContentValues values, String selection,
|
||||||
|
String[] selectionArgs) {
|
||||||
|
UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
|
||||||
|
|
||||||
|
matcher.addURI(AUTHORITY, PATH_IMP_PRI_KEY, 1);
|
||||||
|
matcher.addURI(AUTHORITY, PATH_IMP_PUB_KEY, 2);
|
||||||
|
matcher.addURI(AUTHORITY, PATH_GEN_KEYS, 3);
|
||||||
|
matcher.addURI(AUTHORITY, PATH_GEN_CERT_REQ, 4);
|
||||||
|
|
||||||
|
int res = 0;
|
||||||
|
int matched = matcher.match(uri);
|
||||||
|
switch (matched) {
|
||||||
|
case 1:
|
||||||
|
res = importPrivateKey(uri, values);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
res = importPublicKey(uri, values);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
res = genKeys(uri, values);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
res = genCertReq(uri, values);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Cursor querySecVersion() {
|
||||||
|
String version = MicroPhotoService.querySecVersion();
|
||||||
|
String[] columns = { "version" };
|
||||||
|
MatrixCursor matrixCursor = new MatrixCursor(columns, 1);
|
||||||
|
matrixCursor.addRow(new Object[] { version });
|
||||||
|
return matrixCursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int importPrivateKey(Uri uri, ContentValues values) {
|
||||||
|
String cert = values.containsKey("cert") ? values.getAsString("cert") : null;
|
||||||
|
String path = values.containsKey("path") ? values.getAsString("path") : null;
|
||||||
|
String resultFile = values.containsKey("resultFile") ? values.getAsString("resultFile") : null;
|
||||||
|
int index = values.containsKey("index") ? values.getAsInteger("index").intValue() : 0;
|
||||||
|
|
||||||
|
Log.i(TAG, "Start import private key");
|
||||||
|
boolean res = false;
|
||||||
|
if (!TextUtils.isEmpty(cert)) {
|
||||||
|
// Import
|
||||||
|
byte[] content = Base64.decode(cert, Base64.DEFAULT);
|
||||||
|
if (content != null) {
|
||||||
|
res = MicroPhotoService.importPrivateKey(index, content);
|
||||||
|
}
|
||||||
|
} else if (TextUtils.isEmpty(path)) {
|
||||||
|
String md5 = values.containsKey("md5") ? values.getAsString("md5") : null;
|
||||||
|
File file = new File(path);
|
||||||
|
if (file.exists() && file.isFile()) {
|
||||||
|
res = MicroPhotoService.importPrivateKeyFile(index, path, md5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.i(TAG, "Finish import private key");
|
||||||
|
|
||||||
|
if (!TextUtils.isEmpty(resultFile)) {
|
||||||
|
FilesUtils.ensureParentDirectoryExisted(resultFile);
|
||||||
|
FilesUtils.writeTextFile(resultFile, res ? "1" : "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
return res ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int importPublicKey(Uri uri, ContentValues values) {
|
||||||
|
String cert = values.containsKey("cert") ? values.getAsString("cert") : null;
|
||||||
|
String path = values.containsKey("path") ? values.getAsString("path") : null;
|
||||||
|
String resultFile = values.containsKey("resultFile") ? values.getAsString("resultFile") : null;
|
||||||
|
int index = values.containsKey("index") ? values.getAsInteger("index").intValue() : 0;
|
||||||
|
|
||||||
|
boolean res = false;
|
||||||
|
if (!TextUtils.isEmpty(cert)) {
|
||||||
|
// Import
|
||||||
|
byte[] content = Base64.decode(cert, Base64.DEFAULT);
|
||||||
|
if (content != null) {
|
||||||
|
res = MicroPhotoService.importPublicKey(index, content);
|
||||||
|
}
|
||||||
|
} else if (TextUtils.isEmpty(path)) {
|
||||||
|
String md5 = values.containsKey("md5") ? values.getAsString("md5") : null;
|
||||||
|
File file = new File(path);
|
||||||
|
if (file.exists() && file.isFile()) {
|
||||||
|
res = MicroPhotoService.importPublicKeyFile(index, path, md5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TextUtils.isEmpty(resultFile)) {
|
||||||
|
FilesUtils.ensureParentDirectoryExisted(resultFile);
|
||||||
|
FilesUtils.writeTextFile(resultFile, res ? "1" : "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
return res ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int genKeys(Uri uri, ContentValues values) {
|
||||||
|
int index = values.containsKey("index") ? values.getAsInteger("index").intValue() : 0;
|
||||||
|
boolean res = MicroPhotoService.genKeys(index);
|
||||||
|
return res ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int genCertReq(Uri uri, ContentValues values) {
|
||||||
|
int index = values.containsKey("index") ? values.getAsInteger("index").intValue() : 0;
|
||||||
|
int type = values.containsKey("type") ? values.getAsInteger("type").intValue() : 0;
|
||||||
|
String subject = values.containsKey("subject") ? values.getAsString("subject") : null;
|
||||||
|
String path = values.containsKey("path") ? values.getAsString("path") : null;
|
||||||
|
|
||||||
|
if (TextUtils.isEmpty(subject) || TextUtils.isEmpty(path)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean res = MicroPhotoService.genCertRequest(index, type, subject, path);
|
||||||
|
return res ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue