|
|
@@ -1,30 +1,27 @@
|
|
|
package com.example.uicceditor
|
|
|
|
|
|
import android.app.PendingIntent
|
|
|
+import android.content.Context
|
|
|
import android.content.Intent
|
|
|
+import android.net.Uri
|
|
|
import android.os.Bundle
|
|
|
import android.os.Handler
|
|
|
import android.os.Looper
|
|
|
-import android.telephony.AccessNetworkConstants
|
|
|
-import android.telephony.CarrierConfigManager
|
|
|
-import android.telephony.CellInfo
|
|
|
-import android.telephony.NetworkScanRequest
|
|
|
-import android.telephony.RadioAccessSpecifier
|
|
|
import android.telephony.SmsManager
|
|
|
import android.telephony.SmsMessage
|
|
|
+import android.telephony.SubscriptionManager
|
|
|
import android.telephony.TelephonyManager
|
|
|
-import android.telephony.TelephonyManager.INCLUDE_LOCATION_DATA_NONE
|
|
|
-import android.telephony.TelephonyScanManager.NetworkScanCallback
|
|
|
import android.util.Log
|
|
|
import android.widget.Toast
|
|
|
import androidx.activity.enableEdgeToEdge
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
-import androidx.arch.core.executor.TaskExecutor
|
|
|
-import androidx.core.os.ExecutorCompat
|
|
|
import androidx.core.view.ViewCompat
|
|
|
import androidx.core.view.WindowInsetsCompat
|
|
|
+import com.example.uicceditor.ApduChannel.Companion.INS_SEL
|
|
|
+import com.example.uicceditor.ApduChannel.Companion.INS_WR
|
|
|
import com.example.uicceditor.databinding.ActivityMainBinding
|
|
|
|
|
|
+
|
|
|
class MainActivity : AppCompatActivity() {
|
|
|
private val TAG = "APDU"
|
|
|
|
|
|
@@ -66,6 +63,10 @@ class MainActivity : AppCompatActivity() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ binding.tlIccid.setEndIconOnClickListener {
|
|
|
+ binding.etIccid.setText(genICCID("310", "1"))
|
|
|
+ }
|
|
|
+
|
|
|
binding.btnReadImsi.setOnClickListener {
|
|
|
val apduChannel = ApduChannel(telephonyManager, AID)
|
|
|
val imsi = apduChannel.readIMSI()
|
|
|
@@ -90,6 +91,10 @@ class MainActivity : AppCompatActivity() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ binding.tlImsi.setEndIconOnClickListener {
|
|
|
+ binding.etImsi.setText(genIMSI("310210"))
|
|
|
+ }
|
|
|
+
|
|
|
binding.btnReadMsisdn.setOnClickListener {
|
|
|
val apduChannel = ApduChannel(telephonyManager, AID)
|
|
|
apduChannel.select(SIMView.FID_MF)
|
|
|
@@ -109,6 +114,24 @@ class MainActivity : AppCompatActivity() {
|
|
|
apduChannel.select(SIMView.FID_EF_MSISDN)
|
|
|
apduChannel.writeRecord(1, encMSISDN(msisdn).padStart(56, 'F'))
|
|
|
apduChannel.close()
|
|
|
+
|
|
|
+// val subscriptionManager =
|
|
|
+// getSystemService("telephony_subscription_service") as SubscriptionManager
|
|
|
+// val simCount = subscriptionManager.getActiveSubscriptionInfoCountMax();
|
|
|
+// telephonyManager.setLine1NumberForDisplay(null, msisdn)
|
|
|
+
|
|
|
+
|
|
|
+ val apduChannel1 = ApduChannel(telephonyManager, "a0000000871002ff86ffff89ffffffff00")
|
|
|
+ apduChannel1.execute(0x00, INS_SEL, 0x00, 0x04, 0x02, SIMView.FID_EF_MSISDN)
|
|
|
+ apduChannel1.execute(
|
|
|
+ 0x00,
|
|
|
+ INS_WR,
|
|
|
+ 0x01,
|
|
|
+ 0x04,
|
|
|
+ 0x1C,
|
|
|
+ encMSISDN(msisdn).padStart(56, 'F')
|
|
|
+ )
|
|
|
+ apduChannel.close()
|
|
|
}
|
|
|
|
|
|
binding.btnReadPlmn.setOnClickListener {
|
|
|
@@ -120,6 +143,69 @@ class MainActivity : AppCompatActivity() {
|
|
|
apduChannel.close()
|
|
|
}
|
|
|
|
|
|
+ binding.btnWritePlmn.setOnClickListener {
|
|
|
+ val plmn = encPLMN(binding.etPlmn.text.toString())
|
|
|
+ Log.i(TAG, "btnWritePlmn: $plmn")
|
|
|
+ val apduChannel = ApduChannel(telephonyManager, AID)
|
|
|
+ apduChannel.select(SIMView.FID_MF)
|
|
|
+ apduChannel.select(SIMView.FID_DF_GSM)
|
|
|
+ apduChannel.select(SIMView.FID_EF_PLMNSEL)
|
|
|
+ apduChannel.writeBinary(plmn.padEnd(30, 'f'))
|
|
|
+ apduChannel.close()
|
|
|
+ }
|
|
|
+
|
|
|
+ binding.btnWritePlmnAll.setOnClickListener {
|
|
|
+ val plmn = binding.etPlmn.text.toString().split(",", ",").map { it.trim() }
|
|
|
+ .filter { it.matches(Regex("\\d{5,6}")) }
|
|
|
+ if (plmn.isEmpty()) {
|
|
|
+ Toast.makeText(this, "Invalid PLMN", Toast.LENGTH_SHORT).show()
|
|
|
+ return@setOnClickListener
|
|
|
+ }
|
|
|
+ val plmnHex = encPLMN(plmn.joinToString(","))
|
|
|
+ Log.i(TAG, "plmnHex: $plmnHex")
|
|
|
+
|
|
|
+ val plmnwactHex = encPLMNwAcT(plmn.flatMap {
|
|
|
+ listOf("${it}:4000,$it:8000,$it:0080")
|
|
|
+ }.joinToString(","))
|
|
|
+ Log.i(TAG, "plmnwactHex: $plmnwactHex")
|
|
|
+
|
|
|
+ val fplmn =
|
|
|
+ encPLMN("46000,46001,46002,46006,46007,46011,46012,46015,46020")
|
|
|
+
|
|
|
+ val apduChannel = ApduChannel(telephonyManager, AID)
|
|
|
+ apduChannel.select(SIMView.FID_MF)
|
|
|
+ apduChannel.select(SIMView.FID_DF_GSM)
|
|
|
+ apduChannel.select(SIMView.FID_EF_PLMNSEL)
|
|
|
+ apduChannel.writeBinary(plmnHex.padEnd(120, 'f'))
|
|
|
+
|
|
|
+ apduChannel.select(SIMView.FID_EF_EHPLMN)
|
|
|
+ apduChannel.writeBinary(plmnHex.padEnd(24, 'f'))
|
|
|
+
|
|
|
+ apduChannel.select(SIMView.FID_EF_PLMNWACT)
|
|
|
+ apduChannel.writeBinary(plmnwactHex.padEnd(240, 'f'))
|
|
|
+
|
|
|
+ apduChannel.select(SIMView.FID_EF_OPLMNWACT)
|
|
|
+ apduChannel.writeBinary(plmnwactHex.padEnd(120, 'f'))
|
|
|
+
|
|
|
+ apduChannel.select(SIMView.FID_EF_HPLMNWACT)
|
|
|
+ apduChannel.writeBinary(plmnwactHex.padEnd(40, 'f'))
|
|
|
+
|
|
|
+ apduChannel.select(SIMView.FID_EF_FPLMN)
|
|
|
+ apduChannel.writeBinary(fplmn.padEnd(60, 'f'))
|
|
|
+
|
|
|
+ if (plmn.isNotEmpty()) {
|
|
|
+ if (plmn[0].length == 5) {
|
|
|
+ apduChannel.select(SIMView.FID_EF_AD)
|
|
|
+ apduChannel.writeBinary("00000102")
|
|
|
+ } else if (plmn[0].length == 6) {
|
|
|
+ apduChannel.select(SIMView.FID_EF_AD)
|
|
|
+ apduChannel.writeBinary("00000103")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ apduChannel.close()
|
|
|
+ }
|
|
|
+
|
|
|
binding.btnReadEhplmn.setOnClickListener {
|
|
|
val apduChannel = ApduChannel(telephonyManager, AID)
|
|
|
apduChannel.select(SIMView.FID_MF)
|
|
|
@@ -138,6 +224,17 @@ class MainActivity : AppCompatActivity() {
|
|
|
apduChannel.close()
|
|
|
}
|
|
|
|
|
|
+ binding.btnWriteFplmn.setOnClickListener {
|
|
|
+ val plmn = encPLMN(binding.etFplmn.text.toString())
|
|
|
+ Log.i(TAG, "btnWritePlmn: $plmn")
|
|
|
+ val apduChannel = ApduChannel(telephonyManager, AID)
|
|
|
+ apduChannel.select(SIMView.FID_MF)
|
|
|
+ apduChannel.select(SIMView.FID_DF_GSM)
|
|
|
+ apduChannel.select(SIMView.FID_EF_FPLMN)
|
|
|
+ apduChannel.writeBinary(plmn.padEnd(60, 'f'))
|
|
|
+ apduChannel.close()
|
|
|
+ }
|
|
|
+
|
|
|
binding.btnReadPlmnwact.setOnClickListener {
|
|
|
val apduChannel = ApduChannel(telephonyManager, AID)
|
|
|
apduChannel.select(SIMView.FID_MF)
|
|
|
@@ -166,26 +263,28 @@ class MainActivity : AppCompatActivity() {
|
|
|
}
|
|
|
|
|
|
binding.btnReset.setOnClickListener {
|
|
|
- val apduChannel = ApduChannel(telephonyManager, AID)
|
|
|
- apduChannel.reset()
|
|
|
- apduChannel.close()
|
|
|
+ telephonyManager.rebootModem()
|
|
|
}
|
|
|
|
|
|
binding.btnSms.setOnClickListener {
|
|
|
-
|
|
|
- val smsManager = getSystemService("sms") as SmsManager
|
|
|
- val pendingIntent = PendingIntent.getBroadcast(
|
|
|
- this,
|
|
|
- 1,
|
|
|
- Intent("${packageName}.MyReceiver"),
|
|
|
- PendingIntent.FLAG_IMMUTABLE
|
|
|
- )
|
|
|
- smsManager.injectSmsPdu(
|
|
|
- SmsUtils.createFakeSms("123", "hello"),
|
|
|
- SmsMessage.FORMAT_3GPP,
|
|
|
- pendingIntent
|
|
|
- )
|
|
|
-
|
|
|
+ val sender = binding.etSender.text.toString()
|
|
|
+ val body = binding.etSms.text.toString()
|
|
|
+ if (sender.isNotEmpty() && body.isNotEmpty()) {
|
|
|
+ val smsManager = (getSystemService("sms") as SmsManager).createForSubscriptionId(12)
|
|
|
+ val pendingIntent = PendingIntent.getBroadcast(
|
|
|
+ this,
|
|
|
+ 1,
|
|
|
+ Intent("${packageName}.MyReceiver"),
|
|
|
+ PendingIntent.FLAG_IMMUTABLE
|
|
|
+ )
|
|
|
+ smsManager.injectSmsPdu(
|
|
|
+ SmsUtils.createFakeSms(sender, body),
|
|
|
+ SmsMessage.FORMAT_3GPP,
|
|
|
+ pendingIntent
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ Toast.makeText(this, "Sender or body is empty", Toast.LENGTH_SHORT).show()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -195,4 +294,16 @@ class MainActivity : AppCompatActivity() {
|
|
|
.map { allowedChars.random() }
|
|
|
.joinToString("")
|
|
|
}
|
|
|
+
|
|
|
+ override fun onRequestPermissionsResult(
|
|
|
+ requestCode: Int,
|
|
|
+ permissions: Array<out String>,
|
|
|
+ grantResults: IntArray
|
|
|
+ ) {
|
|
|
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
|
|
+ Log.i(
|
|
|
+ TAG,
|
|
|
+ "requestCode: $requestCode, permissions: $permissions, grantResults: $grantResults"
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|