Compare commits

..

No commits in common. "715f19166f22835cdc33b914a2e14b53a2b27de4" and "8aa08b99eca01fe34b5efc066b84ea18e2a3918d" have entirely different histories.

12 changed files with 8 additions and 284 deletions

2
.idea/misc.xml generated
View file

@ -8,10 +8,8 @@
<entry key="app/src/main/res/layout/euicc_profile.xml" value="0.19375" />
<entry key="app/src/main/res/layout/fragment_euicc.xml" value="0.19375" />
<entry key="app/src/main/res/layout/fragment_profile_download.xml" value="0.19375" />
<entry key="app/src/main/res/layout/fragment_profile_rename.xml" value="0.19375" />
<entry key="app/src/main/res/menu/activity_main_slot_spinner.xml" value="0.19375" />
<entry key="app/src/main/res/menu/fragment_profile_download.xml" value="0.19375" />
<entry key="app/src/main/res/menu/fragment_profile_rename.xml" value="0.19375" />
<entry key="app/src/main/res/menu/profile_options.xml" value="0.19375" />
</map>
</option>

View file

@ -14,7 +14,6 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.truphone.lpa.impl.ProfileKey.*
import com.truphone.lpad.progress.Progress
import im.angry.openeuicc.R
import im.angry.openeuicc.databinding.EuiccProfileBinding
@ -78,7 +77,7 @@ class EuiccManagementFragment : Fragment(), EuiccFragmentMarker, EuiccProfilesCh
}
withContext(Dispatchers.Main) {
adapter.profiles = profiles.filter { it[PROFILE_CLASS.name] != "0" }
adapter.profiles = profiles.filter { it["PROFILE_CLASS"] != "0" }
adapter.notifyDataSetChanged()
binding.swipeRefresh.isRefreshing = false
}
@ -128,8 +127,8 @@ class EuiccManagementFragment : Fragment(), EuiccFragmentMarker, EuiccProfilesCh
fun setProfile(profile: Map<String, String>) {
this.profile = profile
binding.name.text = getName()
// TODO: The library is not exposing the nicknames. Expose them so that we can do something here.
binding.name.text = profile["NAME"]
binding.state.setText(
if (isEnabled()) {
R.string.enabled
@ -137,20 +136,13 @@ class EuiccManagementFragment : Fragment(), EuiccFragmentMarker, EuiccProfilesCh
R.string.disabled
}
)
binding.provider.text = profile[PROVIDER_NAME.name]
binding.iccid.text = profile[ICCID.name]
binding.provider.text = profile["PROVIDER_NAME"]
binding.iccid.text = profile["ICCID"]
binding.iccid.transformationMethod = PasswordTransformationMethod.getInstance()
}
private fun isEnabled(): Boolean =
profile[STATE.name]?.lowercase() == "enabled"
private fun getName(): String =
if (profile[NICKNAME.name].isNullOrEmpty()) {
profile[NAME.name]
} else {
profile[NICKNAME.name]
}!!
profile["STATE"]?.lowercase() == "enabled"
private fun showOptionsMenu() {
PopupMenu(binding.root.context, binding.profileMenu).apply {
@ -166,12 +158,7 @@ class EuiccManagementFragment : Fragment(), EuiccFragmentMarker, EuiccProfilesCh
private fun onMenuItemClicked(item: MenuItem): Boolean =
when (item.itemId) {
R.id.enable -> {
enableProfile(profile[ICCID.name]!!)
true
}
R.id.rename -> {
ProfileRenameFragment.newInstance(slotId, profile[ICCID.name]!!, getName())
.show(childFragmentManager, ProfileRenameFragment.TAG)
enableProfile(profile["ICCID"]!!)
true
}
else -> false

View file

@ -1,109 +0,0 @@
package im.angry.openeuicc.ui
import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.Window
import androidx.fragment.app.DialogFragment
import androidx.lifecycle.lifecycleScope
import im.angry.openeuicc.R
import im.angry.openeuicc.databinding.FragmentProfileRenameBinding
import im.angry.openeuicc.util.setWidthPercent
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.lang.Exception
import java.lang.RuntimeException
class ProfileRenameFragment : DialogFragment(), EuiccFragmentMarker {
companion object {
const val TAG = "ProfileRenameFragment"
fun newInstance(slotId: Int, iccid: String, currentName: String): ProfileRenameFragment {
val instance = newInstanceEuicc(ProfileRenameFragment::class.java, slotId)
instance.requireArguments().apply {
putString("iccid", iccid)
putString("currentName", currentName)
}
return instance
}
}
private var _binding: FragmentProfileRenameBinding? = null
private val binding get() = _binding!!
private var renaming = false
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentProfileRenameBinding.inflate(inflater, container, false)
binding.toolbar.inflateMenu(R.menu.fragment_profile_rename)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.toolbar.apply {
setTitle(R.string.rename)
setNavigationOnClickListener {
if (!renaming) dismiss()
}
setOnMenuItemClickListener {
if (!renaming) rename()
true
}
}
}
override fun onStart() {
super.onStart()
binding.profileRenameNewName.editText!!.setText(requireArguments().getString("currentName"))
}
override fun onResume() {
super.onResume()
setWidthPercent(95)
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return super.onCreateDialog(savedInstanceState).also {
it.window?.requestFeature(Window.FEATURE_NO_TITLE)
it.setCanceledOnTouchOutside(false)
}
}
private fun rename() {
val name = binding.profileRenameNewName.editText!!.text.toString().trim()
renaming = true
binding.progress.isIndeterminate = true
binding.progress.visibility = View.VISIBLE
lifecycleScope.launch {
try {
doRename(name)
} catch (e: Exception) {
Log.d(TAG, "Failed to rename profile")
Log.d(TAG, Log.getStackTraceString(e))
} finally {
if (parentFragment is EuiccProfilesChangedListener) {
(parentFragment as EuiccProfilesChangedListener).onEuiccProfilesChanged()
}
dismiss()
}
}
}
private suspend fun doRename(name: String) = withContext(Dispatchers.IO) {
if (!channel.lpa.setNickname(requireArguments().getString("iccid"), name)) {
throw RuntimeException("Profile nickname not changed")
}
}
}

View file

@ -1,60 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:theme="@style/Theme.OpenEUICC"
android:background="?attr/colorPrimary"
android:elevation="4dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintWidth_percent="1"
app:navigationIcon="?homeAsUpIndicator" />
<View
android:id="@+id/guideline"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="vertical"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="@id/toolbar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<ProgressBar
android:id="@+id/progress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@id/toolbar"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toTopOf="@id/guideline"
style="@style/Widget.AppCompat.ProgressBar.Horizontal" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/profile_rename_new_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginVertical="15dp"
android:hint="@string/profile_rename_new_name"
style="@style/Widget.OpenEUICC.Input"
app:layout_constraintTop_toBottomOf="@id/toolbar"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintWidth_percent=".8">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/Theme.OpenEUICC.Input.Cursor"/>
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/ok"
android:icon="@drawable/ic_check_black"
android:title="@string/rename"
app:showAsAction="ifRoom"/>
</menu>

View file

@ -4,10 +4,6 @@
android:id="@+id/enable"
android:title="@string/enable"/>
<item
android:id="@+id/rename"
android:title="@string/rename"/>
<item
android:id="@+id/delete"
android:title="@string/delete"/>

View file

@ -10,7 +10,6 @@
<string name="enable">Enable</string>
<string name="delete">Delete</string>
<string name="rename">Rename</string>
<string name="toast_profile_enabled">eSIM profile switched. Please wait for a while when the card is restarting.</string>
<string name="toast_profile_enable_failed">Cannot switch to new eSIM profile.</string>
@ -21,6 +20,4 @@
<string name="profile_download_scan">Scan QR Code</string>
<string name="profile_download_ok">Download</string>
<string name="profile_download_failed">Failed to download eSIM. Check your activation / QR code.</string>
<string name="profile_rename_new_name">New nickname</string>
</resources>

View file

@ -37,6 +37,4 @@ public interface LocalProfileAssistant {
String allocateProfile(String mcc);
void processPendingNotifications();
boolean setNickname(String iccid, String nickname);
}

View file

@ -42,7 +42,6 @@ class ListProfilesWorker {
profileMap.put(ProfileKey.STATE.name(), LocalProfileAssistantImpl.DISABLED_STATE.equals(info.getProfileState().toString()) ? "Disabled" : "Enabled");
profileMap.put(ProfileKey.ICCID.name(), info.getIccid().toString());
profileMap.put(ProfileKey.NAME.name(), (info.getProfileName()!=null)?info.getProfileName().toString():"");
profileMap.put(ProfileKey.NICKNAME.name(), (info.getProfileNickname()!=null)?info.getProfileNickname().toString():"");
profileMap.put(ProfileKey.PROVIDER_NAME.name(), (info.getServiceProviderName()!=null)?info.getServiceProviderName().toString():"");
profileMap.put(ProfileKey.ISDP_AID.name(), (info.getIsdpAid()!=null)?info.getIsdpAid().toString():"");
profileMap.put(ProfileKey.PROFILE_CLASS.name(), (info.getProfileClass()!=null)?info.getProfileClass().toString():"");

View file

@ -136,11 +136,6 @@ public class LocalProfileAssistantImpl implements LocalProfileAssistant {
}
@Override
public boolean setNickname(String iccid, String nickname) {
return new SetNicknameWorker(iccid, nickname, apduChannel).run();
}
public void smdsRetrieveEvents(Progress progress) {
// return new SmdsRetrieveEvents();
}

View file

@ -4,7 +4,6 @@ public enum ProfileKey {
ICCID,
STATE,
NAME,
NICKNAME,
PROVIDER_NAME,
ISDP_AID,
PROFILE_CLASS,

View file

@ -1,67 +0,0 @@
package com.truphone.lpa.impl;
import com.truphone.lpa.ApduChannel;
import com.truphone.lpa.apdu.ApduUtils;
import com.truphone.rsp.dto.asn1.rspdefinitions.SetNicknameResponse;
import com.truphone.util.LogStub;
import com.truphone.util.Util;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
public class SetNicknameWorker {
private static final Logger LOG = Logger.getLogger(ListProfilesWorker.class.getName());
private final String iccid;
private final String nickname;
private final ApduChannel apduChannel;
SetNicknameWorker(String iccid, String nickname, ApduChannel apduChannel) {
this.apduChannel = apduChannel;
this.iccid = iccid;
this.nickname = nickname;
}
boolean run() {
if (LogStub.getInstance().isDebugEnabled()) {
LogStub.getInstance().logDebug(LOG, LogStub.getInstance().getTag() + " - Renaming profile: " + iccid);
}
String apdu = ApduUtils.setNicknameApdu(iccid, Util.byteArrayToHexString(nickname.getBytes(), ""));
String eResponse = apduChannel.transmitAPDU(apdu);
try {
InputStream is = new ByteArrayInputStream(Hex.decodeHex(eResponse.toCharArray()));
SetNicknameResponse response = new SetNicknameResponse();
response.decode(is);
if ("0".equals(response.getSetNicknameResult().toString())) {
if (LogStub.getInstance().isDebugEnabled()) {
LogStub.getInstance().logDebug(LOG, LogStub.getInstance().getTag() + " - Profile renamed: " + iccid);
}
return true;
} else {
if (LogStub.getInstance().isDebugEnabled()) {
LogStub.getInstance().logDebug(LOG, LogStub.getInstance().getTag() + " - Profile not renamed: " + iccid);
}
return false;
}
} catch (IOException ioe) {
LOG.log(Level.SEVERE, LogStub.getInstance().getTag() + " - iccid: " + iccid + " profile failed to be renamed");
throw new RuntimeException("Unable to rename profile: " + iccid + ", response: " + eResponse);
} catch (DecoderException e) {
LOG.log(Level.SEVERE, LogStub.getInstance().getTag() + " - " + e.getMessage(), e);
LOG.log(Level.SEVERE, LogStub.getInstance().getTag() + " - iccid: " + iccid + " profile failed to be renamed. Exception in Decoder:" + e.getMessage());
throw new RuntimeException("Unable to rename profile: " + iccid + ", response: " + eResponse);
}
}
}