From daf865b40097486eadb86f1d8cb809ac17bd7cc3 Mon Sep 17 00:00:00 2001 From: shisaiqun Date: Fri, 28 Oct 2022 18:39:04 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=B7=BB=E5=8A=A0=E5=9B=BD=E5=9C=9F?= =?UTF-8?q?=E8=B0=83=E6=9F=A5=E4=BA=91=E5=AE=89=E5=85=A8=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 4 +- .../survey/data/DataRepositories.java | 4 +- security/.gitignore | 1 + security/build.gradle | 47 ++++++++++++++++++ security/consumer-rules.pro | 0 security/proguard-rules.pro | 21 ++++++++ .../security/ExampleInstrumentedTest.java | 26 ++++++++++ security/src/main/AndroidManifest.xml | 4 ++ security/src/main/cpp/CMakeLists.txt | 48 +++++++++++++++++++ security/src/main/cpp/security.cpp | 23 +++++++++ .../kingoit/survey/security/JNIBridge.java | 13 +++++ .../survey/security/ExampleUnitTest.java | 17 +++++++ settings.gradle | 1 + 13 files changed, 206 insertions(+), 3 deletions(-) create mode 100644 security/.gitignore create mode 100644 security/build.gradle create mode 100644 security/consumer-rules.pro create mode 100644 security/proguard-rules.pro create mode 100644 security/src/androidTest/java/com/kingoit/survey/security/ExampleInstrumentedTest.java create mode 100644 security/src/main/AndroidManifest.xml create mode 100644 security/src/main/cpp/CMakeLists.txt create mode 100644 security/src/main/cpp/security.cpp create mode 100644 security/src/main/java/com/kingoit/survey/security/JNIBridge.java create mode 100644 security/src/test/java/com/kingoit/survey/security/ExampleUnitTest.java diff --git a/app/build.gradle b/app/build.gradle index 7142a73..4fabebe 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -29,7 +29,7 @@ android { } dependencies { - +// implementation fileTree(dir: "libs", include: ["*.jar"]) implementation 'androidx.appcompat:appcompat:1.5.1' implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' @@ -41,5 +41,7 @@ dependencies { annotationProcessor "androidx.room:room-compiler:2.4.3" implementation "androidx.exifinterface:exifinterface:1.3.2" +// implementation 'com.alibaba:fastjson:1.2.83' +// implementation 'org.bouncycastle:bcprov-jdk15on:1.63' } \ No newline at end of file diff --git a/app/src/main/java/cn/org/landcloud/survey/data/DataRepositories.java b/app/src/main/java/cn/org/landcloud/survey/data/DataRepositories.java index a3a644b..08d46bf 100644 --- a/app/src/main/java/cn/org/landcloud/survey/data/DataRepositories.java +++ b/app/src/main/java/cn/org/landcloud/survey/data/DataRepositories.java @@ -118,8 +118,8 @@ public class DataRepositories { tbjbxx.setTBBH("CS110101201600000100099"); tbjbxx.setTBMC("1"); tbjbxx.setTBMJ(9.43); - tbjbxx.setXZB(40498699.025); - tbjbxx.setYZB(3350604.784); + tbjbxx.setXZB(40498699.02); + tbjbxx.setYZB(3350604.78); tbjbxx.setBZ(""); HashMap jbxxMap = new HashMap<>(); diff --git a/security/.gitignore b/security/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/security/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/security/build.gradle b/security/build.gradle new file mode 100644 index 0000000..7cd44ad --- /dev/null +++ b/security/build.gradle @@ -0,0 +1,47 @@ +plugins { + id 'com.android.library' +} + +android { + namespace 'com.kingoit.survey.security' + compileSdk 32 + + defaultConfig { + minSdk 21 + targetSdk 32 + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles "consumer-rules.pro" + externalNativeBuild { + cmake { + cppFlags "" + } + } + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + externalNativeBuild { + cmake { + path "src/main/cpp/CMakeLists.txt" + version "3.18.1" + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + + implementation 'androidx.appcompat:appcompat:1.5.1' + implementation 'com.google.android.material:material:1.6.1' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' +} \ No newline at end of file diff --git a/security/consumer-rules.pro b/security/consumer-rules.pro new file mode 100644 index 0000000..e69de29 diff --git a/security/proguard-rules.pro b/security/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/security/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/security/src/androidTest/java/com/kingoit/survey/security/ExampleInstrumentedTest.java b/security/src/androidTest/java/com/kingoit/survey/security/ExampleInstrumentedTest.java new file mode 100644 index 0000000..16236cc --- /dev/null +++ b/security/src/androidTest/java/com/kingoit/survey/security/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.kingoit.survey.security; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.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 Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.kingoit.survey.security.test", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/security/src/main/AndroidManifest.xml b/security/src/main/AndroidManifest.xml new file mode 100644 index 0000000..a5918e6 --- /dev/null +++ b/security/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/security/src/main/cpp/CMakeLists.txt b/security/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000..148a4cc --- /dev/null +++ b/security/src/main/cpp/CMakeLists.txt @@ -0,0 +1,48 @@ +# For more information about using CMake with Android Studio, read the +# documentation: https://d.android.com/studio/projects/add-native-code.html + +# Sets the minimum version of CMake required to build the native library. + +cmake_minimum_required(VERSION 3.18.1) + +# Declares and names the project. + +project("security") + +# Creates and names a library, sets it as either STATIC +# or SHARED, and provides the relative paths to its source code. +# You can define multiple libraries, and CMake builds them for you. +# Gradle automatically packages shared libraries with your APK. + +add_library( # Sets the name of the library. + security + + # Sets the library as a shared library. + SHARED + + # Provides a relative path to your source file(s). + security.cpp) + +# Searches for a specified prebuilt library and stores the path as a +# variable. Because CMake includes system libraries in the search path by +# default, you only need to specify the name of the public NDK library +# you want to add. CMake verifies that the library exists before +# completing its build. + +find_library( # Sets the name of the path variable. + log-lib + + # Specifies the name of the NDK library that + # you want CMake to locate. + log) + +# Specifies libraries CMake should link to your target library. You +# can link multiple libraries, such as libraries you define in this +# build script, prebuilt third-party libraries, or system libraries. + +target_link_libraries( # Specifies the target library. + security + + # Links the target library to the log library + # included in the NDK. + ${log-lib}) \ No newline at end of file diff --git a/security/src/main/cpp/security.cpp b/security/src/main/cpp/security.cpp new file mode 100644 index 0000000..3f171fd --- /dev/null +++ b/security/src/main/cpp/security.cpp @@ -0,0 +1,23 @@ +#include +#include + +#define PROVIDER AndroidKeyStore + +extern "C" JNIEXPORT void JNICALL +Java_com_kingoit_survey_security_JNIBridge_init( + JNIEnv* env, + jobject /* this */) { + + + jclass keyStore_cls = env->FindClass("java/security/KeyStore");//获得ArrayList类引用 + jmethodID getInstance = env->GetStaticMethodID(keyStore_cls,"getInstance","(Ljava/lang/String;)Ljava/security/KeyStore;"); + jobject keyStore = env->CallStaticObjectMethod(keyStore_cls,getInstance,env->NewStringUTF("AndroidKeyStore")); + + + + jclass keyPairGenerator_cls = env->FindClass("java/security/KeyPairGenerator");//获得ArrayList类引用 + jmethodID getInstanceKeyPairGenerator = env->GetStaticMethodID(keyPairGenerator_cls,"getInstance","(Ljava/lang/String;Ljava/lang/String;)Ljava/security/KeyPairGenerator;"); + jobject keyPairGenerator = env->CallStaticObjectMethod(keyPairGenerator_cls,getInstanceKeyPairGenerator,env->NewStringUTF("RSA"),env->NewStringUTF("AndroidKeyStore")); + + +} \ No newline at end of file diff --git a/security/src/main/java/com/kingoit/survey/security/JNIBridge.java b/security/src/main/java/com/kingoit/survey/security/JNIBridge.java new file mode 100644 index 0000000..43e2545 --- /dev/null +++ b/security/src/main/java/com/kingoit/survey/security/JNIBridge.java @@ -0,0 +1,13 @@ +package com.kingoit.survey.security; + +public class JNIBridge { + + static { + System.loadLibrary("security"); + } + + /** + * + */ + public native void init(); +} \ No newline at end of file diff --git a/security/src/test/java/com/kingoit/survey/security/ExampleUnitTest.java b/security/src/test/java/com/kingoit/survey/security/ExampleUnitTest.java new file mode 100644 index 0000000..bf92d9e --- /dev/null +++ b/security/src/test/java/com/kingoit/survey/security/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.kingoit.survey.security; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index f02b3a1..29750ae 100644 --- a/settings.gradle +++ b/settings.gradle @@ -15,3 +15,4 @@ dependencyResolutionManagement { rootProject.name = "landsurvey" include ':app' include ':ssl' +include ':security'