Skip to content

Commit

Permalink
refactor: [1/n] Introduce the lpac project and lpac_jni
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterCxy committed Nov 15, 2023
1 parent 87cdb24 commit 85af3bc
Show file tree
Hide file tree
Showing 24 changed files with 429 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "libs/lpac-jni/src/main/jni/lpac"]
path = libs/lpac-jni/src/main/jni/lpac
url = https://github.com/estkme/lpac
7 changes: 4 additions & 3 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {
compileSdk 31
compileSdk 34

defaultConfig {
applicationId "im.angry.openeuicc"
Expand Down Expand Up @@ -81,11 +81,12 @@ dependencies {
compileOnly project(':libs:hidden-apis-stub')
implementation project(':libs:hidden-apis-shim')
implementation project(":libs:lpad-sm-dp-plus-connector")
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
implementation project(":libs:lpac-jni")
implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.10.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.2'
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
implementation "androidx.cardview:cardview:1.0.0"
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
plugins {
id 'com.android.application' version '8.1.2' apply false
id 'com.android.library' version '8.1.2' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
id 'org.jetbrains.kotlin.multiplatform' version '1.6.21' apply false
id 'org.jetbrains.kotlin.android' version '1.9.20' apply false
id 'org.jetbrains.kotlin.multiplatform' version '1.9.20' apply false
}

task clean(type: Delete) {
Expand Down
46 changes: 46 additions & 0 deletions libs/lpac-jni/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}

android {
namespace 'net.typeblog.lpac_jni'
compileSdk 33

defaultConfig {
minSdk 27

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
ndkBuild {
path "src/main/jni/Android.mk"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {

implementation 'androidx.core:core-ktx:1.12.0'
implementation platform('org.jetbrains.kotlin:kotlin-bom:1.8.0')
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.10.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
Empty file.
21 changes: 21 additions & 0 deletions libs/lpac-jni/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package net.typeblog.lpac_jni

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("net.typeblog.lpac_jni.test", appContext.packageName)
}
}
4 changes: 4 additions & 0 deletions libs/lpac-jni/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
12 changes: 12 additions & 0 deletions libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/ApduInterface.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package net.typeblog.lpac_jni

/*
* Should reflect euicc_apdu_interface in lpac/euicc/interface.h
*/
sealed interface ApduInterface {
fun connect()
fun disconnect()
fun logicalChannelOpen(aid: ByteArray): Int
fun logicalChannelClose(handle: Int)
fun transmit(tx: ByteArray): ByteArray
}
28 changes: 28 additions & 0 deletions libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/HttpInterface.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package net.typeblog.lpac_jni

/*
* Should reflect euicc_http_interface in lpac/euicc/interface.h
*/
sealed interface HttpInterface {
data class HttpResponse(val rcode: Int, val data: ByteArray) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as HttpResponse

if (rcode != other.rcode) return false
if (!data.contentEquals(other.data)) return false

return true
}

override fun hashCode(): Int {
var result = rcode
result = 31 * result + data.contentHashCode()
return result
}
}

fun transmit(url: String, tx: ByteArray): HttpResponse
}
11 changes: 11 additions & 0 deletions libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/LpacJni.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package net.typeblog.lpac_jni

private class LpacJni {
init {
System.loadLibrary("lpac-jni")
}

external fun createContext(apduInterface: ApduInterface, httpInterface: HttpInterface): Long
external fun destroyContext(handle: Long)
external fun setCurrentContext(handle: Long)
}
46 changes: 46 additions & 0 deletions libs/lpac-jni/src/main/jni/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
LOCAL_PATH := $(call my-dir)

# function to find all *.c files under a directory
define all-c-files-under
$(patsubst ./%,%, \
$(shell cd $(LOCAL_PATH) ; \
find $(1) -name "*.c" -and -not -name ".*" -maxdepth 1) \
)
endef

include $(CLEAR_VARS)
# libcjson
LOCAL_MODULE := lpac-cjson
LOCAL_SRC_FILES := \
$(call all-c-files-under, lpac/cjson)
include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
# libasn1c, the ASN parser component from lpac
LOCAL_MODULE := lpac-asn1c
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/lpac/euicc/asn1c
LOCAL_SRC_FILES := \
$(call all-c-files-under, lpac/euicc/asn1c/asn1)
LOCAL_CFLAGS := -DHAVE_CONFIG_H
include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
# libeuicc component from lpac, which contains the actual implementation
LOCAL_MODULE := lpac-euicc
LOCAL_STATIC_LIBRARIES := lpac-asn1c lpac-cjson
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/lpac
LOCAL_SRC_FILES := \
$(call all-c-files-under, lpac/euicc)
include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := lpac-jni
LOCAL_STATIC_LIBRARIES := lpac-euicc
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/lpac
LOCAL_SRC_FILES := \
lpac-jni/lpac-jni.c \
lpac-jni/interface-wrapper.c
include $(BUILD_SHARED_LIBRARY)
1 change: 1 addition & 0 deletions libs/lpac-jni/src/main/jni/Application.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
APP_ABI := all
1 change: 1 addition & 0 deletions libs/lpac-jni/src/main/jni/lpac
Submodule lpac added at 2eaefa
Loading

0 comments on commit 85af3bc

Please sign in to comment.