-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: [1/n] Introduce the lpac project and lpac_jni
- Loading branch information
Showing
24 changed files
with
429 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
24 changes: 24 additions & 0 deletions
24
libs/lpac-jni/src/androidTest/java/net/typeblog/lpac_jni/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/ApduInterface.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
28
libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/HttpInterface.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
11
libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/LpacJni.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
APP_ABI := all |
Oops, something went wrong.