add ApduService

master
wlt233 1 year ago
parent c084950eb1
commit 9d2a167c0c

@ -1,6 +1,6 @@
<?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">
<uses-permission android:name="android.permission.NFC" /> <uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.NFC_TRANSACTION_EVENT" /> <uses-permission android:name="android.permission.NFC_TRANSACTION_EVENT" />
@ -8,52 +8,65 @@
<application <application
android:name=".GlobalVar" android:name=".GlobalVar"
android:allowBackup="true" android:allowBackup="true"
android:extractNativeLibs="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="@drawable/aic_fill" android:icon="@drawable/aic_fill"
android:label="@string/app_name" android:label="@string/app_name"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.AICEmu" android:theme="@style/Theme.AICEmu"
tools:targetApi="31" > tools:targetApi="31">
<meta-data
android:name="xposedmodule"
android:value="true" />
<meta-data
android:name="xposedminversion"
android:value="30" />
<meta-data
android:name="xposeddescription"
android:value="Emulate Every AIC Card" />
<meta-data
android:name="xposedscope"
android:resource="@array/xposed_scope" />
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:exported="true" android:exported="true"
android:theme="@style/Theme.AICEmu" > android:theme="@style/Theme.AICEmu">
<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>
<activity <activity
android:name=".ReadCard" android:name=".ReadCard"
android:theme="@style/CardActivityTheme" /> android:theme="@style/CardActivityTheme" />
<activity <activity
android:name=".SettingActivity" android:name=".SettingActivity"
android:exported="false" android:exported="false"
android:label="@string/title_activity_setting" android:label="@string/title_activity_setting"
android:theme="@style/Theme.AICEmuActionBar" /> android:theme="@style/Theme.AICEmuActionBar" />
<meta-data
android:name="xposedscope"
android:resource="@array/xposed_scope" />
<meta-data
android:name="xposedmodule"
android:value="true" />
<meta-data
android:name="xposedminversion"
android:value="93" />
<meta-data
android:name="xposeddescription"
android:value="Emulate Every AIC Card" />
<meta-data
android:name="xposedsharedprefs"
android:value="true" />
<service
android:name=".ApduService"
android:exported="true"
android:permission="android.permission.BIND_NFC_SERVICE">
<intent-filter>
<action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE" />
</intent-filter>
<meta-data
android:name="android.nfc.cardemulation.host_apdu_service"
android:resource="@xml/apdu_service" />
</service>
<service <service
android:name=".EmuCard" android:name=".EmuCard"
android:exported="true" android:exported="true"
android:permission="android.permission.BIND_NFC_SERVICE" > android:permission="android.permission.BIND_NFC_SERVICE">
<intent-filter> <intent-filter>
<action android:name="android.nfc.cardemulation.action.HOST_NFCF_SERVICE" /> <action android:name="android.nfc.cardemulation.action.HOST_NFCF_SERVICE" />
</intent-filter> </intent-filter>
@ -61,6 +74,5 @@
android:name="android.nfc.cardemulation.host_nfcf_service" android:name="android.nfc.cardemulation.host_nfcf_service"
android:resource="@xml/host_nfcf_service" /> android:resource="@xml/host_nfcf_service" />
</service> </service>
</application> </application>
</manifest> </manifest>

@ -0,0 +1,16 @@
package moe.tqlwsl.aicemu
import android.nfc.cardemulation.HostApduService
import android.os.Bundle
class ApduService : HostApduService() {
override fun onDeactivated(reason: Int) {
// placeholder
}
override fun processCommandApdu(commandApdu: ByteArray, extras: Bundle): ByteArray {
// placeholder
return ByteArray(0)
}
}

@ -4,6 +4,7 @@ import android.app.AlertDialog
import android.app.PendingIntent import android.app.PendingIntent
import android.content.* import android.content.*
import android.nfc.NfcAdapter import android.nfc.NfcAdapter
import android.nfc.cardemulation.CardEmulation
import android.nfc.cardemulation.NfcFCardEmulation import android.nfc.cardemulation.NfcFCardEmulation
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
@ -12,16 +13,14 @@ import android.widget.*
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.cardview.widget.CardView import androidx.cardview.widget.CardView
import androidx.core.content.edit
import androidx.core.view.WindowCompat import androidx.core.view.WindowCompat
import com.google.android.material.floatingactionbutton.FloatingActionButton import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.JsonSyntaxException import com.google.gson.JsonSyntaxException
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import moe.tqlwsl.aicemu.databinding.ActivityMainBinding
import java.io.File import java.io.File
import java.io.IOException import java.io.IOException
import moe.tqlwsl.aicemu.databinding.ActivityMainBinding
internal data class Card(val name: String, val idm: String) internal data class Card(val name: String, val idm: String)
@ -83,6 +82,18 @@ class MainActivity : AppCompatActivity() {
return return
} }
// set default payment app
var cardEmulation = CardEmulation.getInstance(nfcAdapter)
val componentName = ComponentName(applicationContext, ApduService::class.java)
val isDefault =
cardEmulation.isDefaultServiceForCategory(componentName, CardEmulation.CATEGORY_PAYMENT)
if (!isDefault) {
val intent = Intent(CardEmulation.ACTION_CHANGE_DEFAULT)
intent.putExtra(CardEmulation.EXTRA_CATEGORY, CardEmulation.CATEGORY_PAYMENT)
intent.putExtra(CardEmulation.EXTRA_SERVICE_COMPONENT, componentName)
startActivity(intent)
}
// add pendingintent in order not to read tag at home // add pendingintent in order not to read tag at home
val intent = Intent(this, javaClass).apply { val intent = Intent(this, javaClass).apply {
addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP) addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
@ -98,7 +109,7 @@ class MainActivity : AppCompatActivity() {
) )
// setting prefs // setting prefs
prefs = applicationContext.getSharedPreferences("AICEmu", MODE_PRIVATE) prefs = applicationContext.getSharedPreferences("AICEmu", Context.MODE_WORLD_READABLE)
currentCardId = prefs.getInt("currentCardId", -1) currentCardId = prefs.getInt("currentCardId", -1)
compatibleID = prefs.getBoolean("compatibleID", false) compatibleID = prefs.getBoolean("compatibleID", false)
val compatibleButton: Button = findViewById(R.id.button_compatible) val compatibleButton: Button = findViewById(R.id.button_compatible)
@ -176,7 +187,7 @@ class MainActivity : AppCompatActivity() {
true true
} }
R.id.toolbar_menu_settings -> { R.id.toolbar_menu_settings -> {
Toast.makeText(applicationContext, "还没做完()\nUnder constuction...", Toast.LENGTH_LONG).show() // Toast.makeText(applicationContext, "还没做完()\nUnder constuction...", Toast.LENGTH_LONG).show()
val settingIntent = Intent(this, SettingActivity::class.java) val settingIntent = Intent(this, SettingActivity::class.java)
startActivity(settingIntent) startActivity(settingIntent)
true true

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
android:apduServiceBanner="@drawable/aic_fill"
android:description="@string/apdu_service_desc"
android:requireDeviceUnlock="false" >
<aid-group
android:category="payment"
android:description="@string/apdu_service_desc" >
<aid-filter android:name="F0010203040506" />
</aid-group>
</host-apdu-service>
Loading…
Cancel
Save