Skip to content

Commit 85af3bc

Browse files
committed
refactor: [1/n] Introduce the lpac project and lpac_jni
1 parent 87cdb24 commit 85af3bc

24 files changed

+429
-18
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "libs/lpac-jni/src/main/jni/lpac"]
2+
path = libs/lpac-jni/src/main/jni/lpac
3+
url = https://github.com/estkme/lpac

.idea/compiler.xml

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/kotlinc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

+7-6
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def keystoreProperties = new Properties()
3737
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
3838

3939
android {
40-
compileSdk 31
40+
compileSdk 34
4141

4242
defaultConfig {
4343
applicationId "im.angry.openeuicc"
@@ -81,11 +81,12 @@ dependencies {
8181
compileOnly project(':libs:hidden-apis-stub')
8282
implementation project(':libs:hidden-apis-shim')
8383
implementation project(":libs:lpad-sm-dp-plus-connector")
84-
implementation 'androidx.core:core-ktx:1.7.0'
85-
implementation 'androidx.appcompat:appcompat:1.4.1'
86-
implementation 'com.google.android.material:material:1.6.0'
87-
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
88-
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
84+
implementation project(":libs:lpac-jni")
85+
implementation 'androidx.core:core-ktx:1.12.0'
86+
implementation 'androidx.appcompat:appcompat:1.6.1'
87+
implementation 'com.google.android.material:material:1.10.0'
88+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
89+
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.2'
8990
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
9091
implementation "androidx.cardview:cardview:1.0.0"
9192
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
plugins {
33
id 'com.android.application' version '8.1.2' apply false
44
id 'com.android.library' version '8.1.2' apply false
5-
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
6-
id 'org.jetbrains.kotlin.multiplatform' version '1.6.21' apply false
5+
id 'org.jetbrains.kotlin.android' version '1.9.20' apply false
6+
id 'org.jetbrains.kotlin.multiplatform' version '1.9.20' apply false
77
}
88

99
task clean(type: Delete) {

libs/lpac-jni/build.gradle

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
plugins {
2+
id 'com.android.library'
3+
id 'org.jetbrains.kotlin.android'
4+
}
5+
6+
android {
7+
namespace 'net.typeblog.lpac_jni'
8+
compileSdk 33
9+
10+
defaultConfig {
11+
minSdk 27
12+
13+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
14+
consumerProguardFiles "consumer-rules.pro"
15+
}
16+
17+
buildTypes {
18+
release {
19+
minifyEnabled false
20+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21+
}
22+
}
23+
externalNativeBuild {
24+
ndkBuild {
25+
path "src/main/jni/Android.mk"
26+
}
27+
}
28+
compileOptions {
29+
sourceCompatibility JavaVersion.VERSION_1_8
30+
targetCompatibility JavaVersion.VERSION_1_8
31+
}
32+
kotlinOptions {
33+
jvmTarget = '1.8'
34+
}
35+
}
36+
37+
dependencies {
38+
39+
implementation 'androidx.core:core-ktx:1.12.0'
40+
implementation platform('org.jetbrains.kotlin:kotlin-bom:1.8.0')
41+
implementation 'androidx.appcompat:appcompat:1.6.1'
42+
implementation 'com.google.android.material:material:1.10.0'
43+
testImplementation 'junit:junit:4.13.2'
44+
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
45+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
46+
}

libs/lpac-jni/consumer-rules.pro

Whitespace-only changes.

libs/lpac-jni/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package net.typeblog.lpac_jni
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("net.typeblog.lpac_jni.test", appContext.packageName)
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package net.typeblog.lpac_jni
2+
3+
/*
4+
* Should reflect euicc_apdu_interface in lpac/euicc/interface.h
5+
*/
6+
sealed interface ApduInterface {
7+
fun connect()
8+
fun disconnect()
9+
fun logicalChannelOpen(aid: ByteArray): Int
10+
fun logicalChannelClose(handle: Int)
11+
fun transmit(tx: ByteArray): ByteArray
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package net.typeblog.lpac_jni
2+
3+
/*
4+
* Should reflect euicc_http_interface in lpac/euicc/interface.h
5+
*/
6+
sealed interface HttpInterface {
7+
data class HttpResponse(val rcode: Int, val data: ByteArray) {
8+
override fun equals(other: Any?): Boolean {
9+
if (this === other) return true
10+
if (javaClass != other?.javaClass) return false
11+
12+
other as HttpResponse
13+
14+
if (rcode != other.rcode) return false
15+
if (!data.contentEquals(other.data)) return false
16+
17+
return true
18+
}
19+
20+
override fun hashCode(): Int {
21+
var result = rcode
22+
result = 31 * result + data.contentHashCode()
23+
return result
24+
}
25+
}
26+
27+
fun transmit(url: String, tx: ByteArray): HttpResponse
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package net.typeblog.lpac_jni
2+
3+
private class LpacJni {
4+
init {
5+
System.loadLibrary("lpac-jni")
6+
}
7+
8+
external fun createContext(apduInterface: ApduInterface, httpInterface: HttpInterface): Long
9+
external fun destroyContext(handle: Long)
10+
external fun setCurrentContext(handle: Long)
11+
}

libs/lpac-jni/src/main/jni/Android.mk

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
LOCAL_PATH := $(call my-dir)
2+
3+
# function to find all *.c files under a directory
4+
define all-c-files-under
5+
$(patsubst ./%,%, \
6+
$(shell cd $(LOCAL_PATH) ; \
7+
find $(1) -name "*.c" -and -not -name ".*" -maxdepth 1) \
8+
)
9+
endef
10+
11+
include $(CLEAR_VARS)
12+
# libcjson
13+
LOCAL_MODULE := lpac-cjson
14+
LOCAL_SRC_FILES := \
15+
$(call all-c-files-under, lpac/cjson)
16+
include $(BUILD_STATIC_LIBRARY)
17+
18+
include $(CLEAR_VARS)
19+
# libasn1c, the ASN parser component from lpac
20+
LOCAL_MODULE := lpac-asn1c
21+
LOCAL_C_INCLUDES := \
22+
$(LOCAL_PATH)/lpac/euicc/asn1c
23+
LOCAL_SRC_FILES := \
24+
$(call all-c-files-under, lpac/euicc/asn1c/asn1)
25+
LOCAL_CFLAGS := -DHAVE_CONFIG_H
26+
include $(BUILD_STATIC_LIBRARY)
27+
28+
include $(CLEAR_VARS)
29+
# libeuicc component from lpac, which contains the actual implementation
30+
LOCAL_MODULE := lpac-euicc
31+
LOCAL_STATIC_LIBRARIES := lpac-asn1c lpac-cjson
32+
LOCAL_C_INCLUDES := \
33+
$(LOCAL_PATH)/lpac
34+
LOCAL_SRC_FILES := \
35+
$(call all-c-files-under, lpac/euicc)
36+
include $(BUILD_STATIC_LIBRARY)
37+
38+
include $(CLEAR_VARS)
39+
LOCAL_MODULE := lpac-jni
40+
LOCAL_STATIC_LIBRARIES := lpac-euicc
41+
LOCAL_C_INCLUDES := \
42+
$(LOCAL_PATH)/lpac
43+
LOCAL_SRC_FILES := \
44+
lpac-jni/lpac-jni.c \
45+
lpac-jni/interface-wrapper.c
46+
include $(BUILD_SHARED_LIBRARY)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
APP_ABI := all

libs/lpac-jni/src/main/jni/lpac

Submodule lpac added at 2eaefa6

0 commit comments

Comments
 (0)