Compare commits

..

3 commits

7 changed files with 54 additions and 13 deletions

View file

@ -2,6 +2,7 @@ package im.angry.openeuicc.ui
import android.app.Dialog import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import android.text.Editable
import android.util.Log import android.util.Log
import android.view.* import android.view.*
import android.widget.ProgressBar import android.widget.ProgressBar
@ -32,6 +33,7 @@ class ProfileDownloadFragment : DialogFragment(), EuiccFragmentMarker, Toolbar.O
private lateinit var profileDownloadServer: TextInputLayout private lateinit var profileDownloadServer: TextInputLayout
private lateinit var profileDownloadCode: TextInputLayout private lateinit var profileDownloadCode: TextInputLayout
private lateinit var profileDownloadConfirmationCode: TextInputLayout private lateinit var profileDownloadConfirmationCode: TextInputLayout
private lateinit var profileDownloadIMEI: TextInputLayout
private lateinit var progress: ProgressBar private lateinit var progress: ProgressBar
private var downloading = false private var downloading = false
@ -57,6 +59,7 @@ class ProfileDownloadFragment : DialogFragment(), EuiccFragmentMarker, Toolbar.O
profileDownloadServer = view.findViewById(R.id.profile_download_server) profileDownloadServer = view.findViewById(R.id.profile_download_server)
profileDownloadCode = view.findViewById(R.id.profile_download_code) profileDownloadCode = view.findViewById(R.id.profile_download_code)
profileDownloadConfirmationCode = view.findViewById(R.id.profile_download_confirmation_code) profileDownloadConfirmationCode = view.findViewById(R.id.profile_download_confirmation_code)
profileDownloadIMEI = view.findViewById(R.id.profile_download_imei)
progress = view.findViewById(R.id.progress) progress = view.findViewById(R.id.progress)
toolbar.inflateMenu(R.menu.fragment_profile_download) toolbar.inflateMenu(R.menu.fragment_profile_download)
@ -96,6 +99,11 @@ class ProfileDownloadFragment : DialogFragment(), EuiccFragmentMarker, Toolbar.O
setWidthPercent(95) setWidthPercent(95)
} }
override fun onStart() {
super.onStart()
profileDownloadIMEI.editText!!.text = Editable.Factory.getInstance().newEditable(channel.imei)
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return super.onCreateDialog(savedInstanceState).also { return super.onCreateDialog(savedInstanceState).also {
it.window?.requestFeature(Window.FEATURE_NO_TITLE) it.window?.requestFeature(Window.FEATURE_NO_TITLE)
@ -114,8 +122,11 @@ class ProfileDownloadFragment : DialogFragment(), EuiccFragmentMarker, Toolbar.O
} }
val code = profileDownloadCode.editText!!.text.toString().trim() val code = profileDownloadCode.editText!!.text.toString().trim()
.ifBlank { null }
val confirmationCode = profileDownloadConfirmationCode.editText!!.text.toString().trim() val confirmationCode = profileDownloadConfirmationCode.editText!!.text.toString().trim()
.ifBlank { null } .ifBlank { null }
val imei = profileDownloadIMEI.editText!!.text.toString().trim()
.ifBlank { null }
downloading = true downloading = true
@ -127,7 +138,7 @@ class ProfileDownloadFragment : DialogFragment(), EuiccFragmentMarker, Toolbar.O
lifecycleScope.launch { lifecycleScope.launch {
try { try {
doDownloadProfile(server, code, confirmationCode) doDownloadProfile(server, code, confirmationCode, imei)
} catch (e: Exception) { } catch (e: Exception) {
Log.d(TAG, "Error downloading profile") Log.d(TAG, "Error downloading profile")
Log.d(TAG, Log.getStackTraceString(e)) Log.d(TAG, Log.getStackTraceString(e))
@ -141,8 +152,8 @@ class ProfileDownloadFragment : DialogFragment(), EuiccFragmentMarker, Toolbar.O
} }
} }
private suspend fun doDownloadProfile(server: String, code: String, confirmationCode: String?) = withContext(Dispatchers.IO) { private suspend fun doDownloadProfile(server: String, code: String?, confirmationCode: String?, imei: String?) = withContext(Dispatchers.IO) {
channel.lpa.downloadProfile(server, code, channel.imei, confirmationCode, object : ProfileDownloadCallback { channel.lpa.downloadProfile(server, code, imei, confirmationCode, object : ProfileDownloadCallback {
override fun onStateUpdate(state: ProfileDownloadCallback.DownloadState) { override fun onStateUpdate(state: ProfileDownloadCallback.DownloadState) {
lifecycleScope.launch(Dispatchers.Main) { lifecycleScope.launch(Dispatchers.Main) {
progress.isIndeterminate = false progress.isIndeterminate = false

View file

@ -66,11 +66,13 @@
app:layout_constraintTop_toBottomOf="@id/profile_download_server" app:layout_constraintTop_toBottomOf="@id/profile_download_server"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintWidth_percent=".8"> app:layout_constraintWidth_percent=".8"
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:inputType="textPassword"
android:theme="@style/Theme.OpenEUICC.Input.Cursor"/> android:theme="@style/Theme.OpenEUICC.Input.Cursor"/>
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
@ -85,12 +87,35 @@
app:layout_constraintTop_toBottomOf="@id/profile_download_code" app:layout_constraintTop_toBottomOf="@id/profile_download_code"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintWidth_percent=".8"
app:layout_constraintWidth_percent=".8"> app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:inputType="textPassword"
android:theme="@style/Theme.OpenEUICC.Input.Cursor"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/profile_download_imei"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginVertical="15dp"
android:hint="@string/profile_download_imei"
style="@style/Widget.OpenEUICC.Input"
app:layout_constraintTop_toBottomOf="@id/profile_download_confirmation_code"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintWidth_percent=".8"
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="textPassword"
android:theme="@style/Theme.OpenEUICC.Input.Cursor"/> android:theme="@style/Theme.OpenEUICC.Input.Cursor"/>
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>

View file

@ -24,6 +24,7 @@
<string name="profile_download_server">Server (RSP / SM-DP+)</string> <string name="profile_download_server">Server (RSP / SM-DP+)</string>
<string name="profile_download_code">Activation Code</string> <string name="profile_download_code">Activation Code</string>
<string name="profile_download_confirmation_code">Confirmation Code (Optional)</string> <string name="profile_download_confirmation_code">Confirmation Code (Optional)</string>
<string name="profile_download_imei">IMEI (Optional)</string>
<string name="profile_download_scan">Scan QR Code</string> <string name="profile_download_scan">Scan QR Code</string>
<string name="profile_download_ok">Download</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_download_failed">Failed to download eSIM. Check your activation / QR code.</string>

View file

@ -8,7 +8,7 @@ interface LocalProfileAssistant {
fun disableProfile(iccid: String): Boolean fun disableProfile(iccid: String): Boolean
fun deleteProfile(iccid: String): Boolean fun deleteProfile(iccid: String): Boolean
fun downloadProfile(smdp: String, matchingId: String, imei: String, fun downloadProfile(smdp: String, matchingId: String?, imei: String?,
confirmationCode: String?, callback: ProfileDownloadCallback): Boolean confirmationCode: String?, callback: ProfileDownloadCallback): Boolean
fun setNickname( fun setNickname(

View file

@ -23,6 +23,6 @@ internal object LpacJni {
// es9p + es10b // es9p + es10b
// We do not expose all of the functions because of tediousness :) // We do not expose all of the functions because of tediousness :)
external fun downloadProfile(handle: Long, smdp: String, matchingId: String, imei: String, external fun downloadProfile(handle: Long, smdp: String, matchingId: String?, imei: String?,
confirmationCode: String?, callback: ProfileDownloadCallback): Int confirmationCode: String?, callback: ProfileDownloadCallback): Int
} }

View file

@ -37,7 +37,7 @@ class LocalProfileAssistantImpl(
return LpacJni.es10cDeleteProfile(contextHandle, iccid) == 0 return LpacJni.es10cDeleteProfile(contextHandle, iccid) == 0
} }
override fun downloadProfile(smdp: String, matchingId: String, imei: String, override fun downloadProfile(smdp: String, matchingId: String?, imei: String?,
confirmationCode: String?, callback: ProfileDownloadCallback): Boolean { confirmationCode: String?, callback: ProfileDownloadCallback): Boolean {
return LpacJni.downloadProfile(contextHandle, smdp, matchingId, imei, confirmationCode, callback) == 0 return LpacJni.downloadProfile(contextHandle, smdp, matchingId, imei, confirmationCode, callback) == 0
} }

View file

@ -60,8 +60,10 @@ Java_net_typeblog_lpac_1jni_LpacJni_downloadProfile(JNIEnv *env, jobject thiz, j
if (confirmation_code != NULL) if (confirmation_code != NULL)
_confirmation_code = (*env)->GetStringUTFChars(env, confirmation_code, NULL); _confirmation_code = (*env)->GetStringUTFChars(env, confirmation_code, NULL);
if (matching_id != NULL)
_matching_id = (*env)->GetStringUTFChars(env, matching_id, NULL); _matching_id = (*env)->GetStringUTFChars(env, matching_id, NULL);
_smdp = (*env)->GetStringUTFChars(env, smdp, NULL); _smdp = (*env)->GetStringUTFChars(env, smdp, NULL);
if (imei != NULL)
_imei = (*env)->GetStringUTFChars(env, imei, NULL); _imei = (*env)->GetStringUTFChars(env, imei, NULL);
(*env)->CallVoidMethod(env, callback, on_state_update, download_state_preparing); (*env)->CallVoidMethod(env, callback, on_state_update, download_state_preparing);
@ -122,8 +124,10 @@ out:
free(transaction_id); free(transaction_id);
if (_confirmation_code != NULL) if (_confirmation_code != NULL)
(*env)->ReleaseStringUTFChars(env, confirmation_code, _confirmation_code); (*env)->ReleaseStringUTFChars(env, confirmation_code, _confirmation_code);
if (_matching_id != NULL)
(*env)->ReleaseStringUTFChars(env, matching_id, _matching_id); (*env)->ReleaseStringUTFChars(env, matching_id, _matching_id);
(*env)->ReleaseStringUTFChars(env, smdp, _smdp); (*env)->ReleaseStringUTFChars(env, smdp, _smdp);
if (_imei != NULL)
(*env)->ReleaseStringUTFChars(env, imei, _imei); (*env)->ReleaseStringUTFChars(env, imei, _imei);
return ret; return ret;
} }