ソースを参照

refactor: always use the little-endian iccid

Peter Cai 3 年 前
コミット
d6a3cc820c

+ 5 - 8
app/src/main/java/im/angry/openeuicc/service/OpenEuiccService.kt

@@ -5,7 +5,6 @@ import android.telephony.euicc.DownloadableSubscription
 import android.telephony.euicc.EuiccInfo
 import com.truphone.lpa.LocalProfileInfo
 import com.truphone.lpad.progress.Progress
-import com.truphone.util.TextUtil
 import im.angry.openeuicc.OpenEuiccApplication
 import im.angry.openeuicc.core.EuiccChannel
 import im.angry.openeuicc.util.*
@@ -54,7 +53,7 @@ class OpenEuiccService : EuiccService() {
     override fun onGetEuiccProfileInfoList(slotId: Int): GetEuiccProfileInfoListResult? {
         val channel = findChannel(slotId) ?: return null
         val profiles = channel.lpa.profiles.operational.map {
-            EuiccProfileInfo.Builder(it.iccidLittleEndian).apply {
+            EuiccProfileInfo.Builder(it.iccid).apply {
                 setProfileName(it.name)
                 setNickname(it.displayName)
                 setServiceProviderName(it.providerName)
@@ -84,10 +83,9 @@ class OpenEuiccService : EuiccService() {
     override fun onDeleteSubscription(slotId: Int, iccid: String): Int {
         try {
             val channel = findChannel(slotId) ?: return RESULT_FIRST_USER
-            val iccidBig = TextUtil.iccidLittleToBig(iccid)
 
             val profile = channel.lpa.profiles.find {
-                it.iccid == iccidBig
+                it.iccid == iccid
             } ?: return RESULT_FIRST_USER
 
             if (profile.state == LocalProfileInfo.State.Enabled) {
@@ -95,7 +93,7 @@ class OpenEuiccService : EuiccService() {
                 return RESULT_FIRST_USER
             }
 
-            return if (channel.lpa.deleteProfile(iccidBig, Progress()) == "0") {
+            return if (channel.lpa.deleteProfile(iccid, Progress()) == "0") {
                 RESULT_OK
             } else {
                 RESULT_FIRST_USER
@@ -128,8 +126,7 @@ class OpenEuiccService : EuiccService() {
                     RESULT_FIRST_USER
                 }
             } else {
-                val iccidBig = TextUtil.iccidLittleToBig(iccid)
-                return if (channel.lpa.enableProfile(iccidBig, Progress()) == "0") {
+                return if (channel.lpa.enableProfile(iccid, Progress()) == "0") {
                     RESULT_OK
                 } else {
                     RESULT_FIRST_USER
@@ -145,7 +142,7 @@ class OpenEuiccService : EuiccService() {
     override fun onUpdateSubscriptionNickname(slotId: Int, iccid: String, nickname: String?): Int {
         val channel = findChannel(slotId) ?: return RESULT_FIRST_USER
         val success = channel.lpa
-            .setNickname(TextUtil.iccidLittleToBig(iccid), nickname)
+            .setNickname(iccid, nickname)
         openEuiccApplication.subscriptionManager.tryRefreshCachedEuiccInfo(channel.cardId)
         return if (success) {
             RESULT_OK

+ 1 - 1
app/src/main/java/im/angry/openeuicc/ui/EuiccManagementFragment.kt

@@ -150,7 +150,7 @@ class EuiccManagementFragment : Fragment(), EuiccFragmentMarker, EuiccProfilesCh
                 }
             )
             binding.provider.text = profile.providerName
-            binding.iccid.text = profile.iccidLittleEndian
+            binding.iccid.text = profile.iccid
             binding.iccid.transformationMethod = PasswordTransformationMethod.getInstance()
         }
 

+ 0 - 5
libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/LocalProfileInfo.kt

@@ -14,7 +14,6 @@
 
 package com.truphone.lpa
 
-import com.truphone.util.TextUtil.iccidBigToLittle
 import java.lang.IllegalArgumentException
 
 data class LocalProfileInfo(
@@ -26,10 +25,6 @@ data class LocalProfileInfo(
     val isdpAID: String,
     val profileClass: Clazz
 ) {
-    val iccidLittleEndian by lazy {
-        iccidBigToLittle(iccid)
-    }
-
     enum class State {
         Enabled,
         Disabled

+ 2 - 1
libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/ListProfilesWorker.kt

@@ -21,6 +21,7 @@ import com.truphone.util.LogStub
 import org.apache.commons.codec.DecoderException
 import org.apache.commons.codec.binary.Hex
 import com.truphone.lpa.apdu.ApduUtils
+import com.truphone.util.TextUtil.iccidBigToLittle
 import java.io.ByteArrayInputStream
 import java.io.IOException
 import java.io.InputStream
@@ -38,7 +39,7 @@ internal class ListProfilesWorker(private val apduChannel: ApduChannel) {
             for (info in profiles.profileInfoListOk.profileInfo) {
                 profileList.add(
                     LocalProfileInfo(
-                        iccid = info.iccid.toString(),
+                        iccid = iccidBigToLittle(info.iccid.toString()),
                         state = LocalProfileInfo.stateFromString(info.profileState?.toString()),
                         name = info.profileName?.toString() ?: "",
                         nickName = info.profileNickname?.toString() ?: "",

+ 6 - 19
libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/LocalProfileAssistantImpl.java

@@ -13,6 +13,8 @@ import com.truphone.lpad.worker.DeleteProfileWorker;
 import com.truphone.lpad.worker.GetEidLpadWorker;
 import com.truphone.lpad.worker.LpadWorkerExchange;
 import com.truphone.util.LogStub;
+import com.truphone.util.TextUtil;
+
 import org.apache.commons.lang3.StringUtils;
 
 import java.util.List;
@@ -30,24 +32,9 @@ public class LocalProfileAssistantImpl implements LocalProfileAssistant {
     private final ApduChannel apduChannel;
     private Es9PlusImpl es9Module;
 
-//    public LocalProfileAssistantImpl(final ApduChannel apduChannel,
-//                                     final String rspServerUrl) {
     public LocalProfileAssistantImpl(final ApduChannel apduChannel){
         this.apduChannel = apduChannel;
         es9Module = new Es9PlusImpl();
-
-        //LOG.info(LogStub.getInstance().getTag() + " - Init SM-DP connection - " + rspServerUrl);
-
-//        if (!StringUtils.isNotBlank(rspServerUrl) || !checkRspServerURL(rspServerUrl)) {
-//            if (LogStub.getInstance().isDebugEnabled()) {
-//                LogStub.getInstance().logDebug(LOG, LogStub.getInstance().getTag() + " - Fixing RSP Server URL to default - " + rspServerUrl);
-//            }
-//
-//            throw new IllegalArgumentException("RSP Server URL is invalid: " + rspServerUrl);
-//        }
-
-//        es9Module.configure(rspServerUrl);
-        //es9Module.configure();
         LOG.log(Level.INFO, LogStub.getInstance().getTag() + " - SM-DP connection initiated.");
     }
 
@@ -60,14 +47,14 @@ public class LocalProfileAssistantImpl implements LocalProfileAssistant {
     public String enableProfile(final String iccid,
                                 final Progress progress) {
 
-        return new EnableProfileWorker(iccid, progress, apduChannel).run();
+        return new EnableProfileWorker(TextUtil.iccidLittleToBig(iccid), progress, apduChannel).run();
     }
 
     @Override
     public String disableProfile(final String iccid,
                                  final Progress progress) {
 
-        return new DisableProfileWorker(iccid, progress, apduChannel).run();
+        return new DisableProfileWorker(TextUtil.iccidLittleToBig(iccid), progress, apduChannel).run();
     }
 
     @Override
@@ -77,7 +64,7 @@ public class LocalProfileAssistantImpl implements LocalProfileAssistant {
         DeleteProfileWorker deleteProfileWorker = new DeleteProfileWorker(progress, apduChannel);
 
         LpadWorkerExchange<DeleteProfileWorker.DeleteProfileInputParams> exchange =
-                new LpadWorkerExchange<>(deleteProfileWorker.new DeleteProfileInputParams(iccid));
+                new LpadWorkerExchange<>(deleteProfileWorker.new DeleteProfileInputParams(TextUtil.iccidLittleToBig(iccid)));
 
         return deleteProfileWorker.run(exchange);
 
@@ -138,7 +125,7 @@ public class LocalProfileAssistantImpl implements LocalProfileAssistant {
 
     @Override
     public boolean setNickname(String iccid, String nickname) {
-        return new SetNicknameWorker(iccid, nickname, apduChannel).run();
+        return new SetNicknameWorker(TextUtil.iccidLittleToBig(iccid), nickname, apduChannel).run();
     }
 
     public void smdsRetrieveEvents(Progress progress) {

+ 2 - 0
libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/util/TextUtil.kt

@@ -49,6 +49,7 @@ object TextUtil {
      *
      * @param iccid The ICCID to be converted
      */
+    @JvmStatic
     fun iccidBigToLittle(iccid: String): String {
         val builder = StringBuilder()
         for (i in 0 until iccid.length / 2) {
@@ -63,6 +64,7 @@ object TextUtil {
      *
      * @param iccid The ICCID to be converted
      */
+    @JvmStatic
     fun iccidLittleToBig(iccidLittle: String): String {
         val builder = StringBuilder()
         for (i in 0 until iccidLittle.length / 2) {