Skip to content

Commit

Permalink
feat(#2): automatically supply the PIN code to unlock the SIM card (#20)
Browse files Browse the repository at this point in the history
* Add `SIM PIN` preference

* Add `PinStorage` to store PIN codes in the CE storage

* Add `AuthenticationPromptActivity` to unlock hardware-backed KeyStore

* Add SIM PIN encrypt/decrypt support

* fix(TimePicker): call `callChangeListener()` only if time value changed

* Make available clear PIN codes after reboot & when alarm goes off

* Handle `Resume-on-Reboot` (RoR) stage when `Full-Disk Encryption` (FDE) enabled

* Add user-space (banner/notification) error handling on PIN incorrect/corrupted

* Add `SimPinFeeder` to supply SIM PIN codes when alarm goes off

* Import translations

* Update README.md

* Update app images
  • Loading branch information
iusmac committed Jun 2, 2024
1 parent c2c64e4 commit bf404f6
Show file tree
Hide file tree
Showing 69 changed files with 2,740 additions and 33 deletions.
1 change: 1 addition & 0 deletions Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ android_app {
"SettingsLibSettingsTheme",
"SettingsLibTwoTargetPreference",
"androidx.annotation_annotation",
"androidx.biometric_biometric",
"androidx.collection_collection",
"androidx.core_core",
"androidx.lifecycle_lifecycle-livedata",
Expand Down
13 changes: 13 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,18 @@
android:foregroundServiceType="systemExempted"
android:directBootAware="true">
</service>

<activity
android:name=".ui.AuthenticationPromptActivity"
android:excludeFromRecents="true"
android:exported="false"
android:theme="@*android:style/Theme.DeviceDefault.Settings.Dialog.NoActionBar">
</activity>

<service
android:name=".UserAuthenticationObserverService"
android:exported="false"
android:foregroundServiceType="systemExempted">
</service>
</application>
</manifest>
39 changes: 30 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ If you're a normal user willing to give it a try, see [Installation](#installati
##### Screenshots
<p>
<img src="images/home-a13-dark.jpg" width="200" alt="Home A13 Dark Screenshot" />
<img src="images/scheduler-a13-light.jpg" width="200" alt="Scheduler A13 Light Screenshot" />
<img src="images/scheduler-a14-light.jpg" width="200" alt="Scheduler A14 Light Screenshot" />
<img src="images/home-a10-light.jpg" width="200" alt="Home A10 Light Screenshot" />
<img src="images/scheduler-a10-dark.jpg" width="200" alt="Scheduler A10 Dark Screenshot" />
</p>
Expand All @@ -52,14 +52,6 @@ If you're a normal user willing to give it a try, see [Installation](#installati
> Subscribe to the iusmac/7SIM/issues/1 to be notified when this feature will be fully
> implemented.
- Automatically supply the PIN code provided by you to unlock the SIM card
> 🚧 **Work-in-Progress**
>
> This feature is under development. Mostly, the devices lacking the
> [capability to turn on/off SIM cards out-of-the-box][faq-check-toggle-uicc-subscription-support]
> need it for the best UX. Because of this, this feature has the highest priority over all other
> features on the "TO DO" list.
>
> Subscribe to the iusmac/7SIM/issues/2 to be notified when this feature will be implemented.
- Automatically detect ongoing call and postpone SIM card deactivation
- Tinted SIM card icons
- Real-Time SIM list updates
Expand Down Expand Up @@ -220,6 +212,25 @@ they are signed with the public Android platform signature. Therefore, you can g
app only from your ROM maintainer with OTA updates.
</details>

<details>
<summary id="faq-sim-pin-codes-storing">9. Where's my SIM PIN code stored?</summary>

The SIM PIN codes are stored on disk after being encrypted using the newly generated secret key
bound to your screen lock credentials, such as PIN/password/pattern or biometric (Android 10 only).
The secret key will be stored in the [Hardware-backed Keystore](https://source.android.com/docs/security/features/keystore),
and the user authentication will take place for every use of the key. This is the highest security
level you can have on an Android device.

> ⚠️ Warning
>
> If "_None_" or "_Swipe_" is set as your screen lock method, the default (known to everyone) key
> will be used to encrypt your SIM PIN codes. Although the decryption will require physical access
> to the device, this is the <strong>lowest</strong> possible level of protection, as the data can
> be easily accessed (especially on a rooted device), if your phone is lost or stolen.
See also [Irreversibly Invalidated SIM PIN Codes](#3-irreversibly-invalidated-sim-pin-codes)
</details>

# For ROM Maintainers
If you're a ROM maintainer and wish to integrate this app into your ROM, follow these steps:
1. Choose one of the following methods to add the app to the Android sources:
Expand Down Expand Up @@ -461,6 +472,16 @@ subscribes to these changes and remains working in the background. Since this ap
purpose to not waste system resources and do all the work on-demand, there is currently no
workaround to this.

#### 3. Irreversibly Invalidated SIM PIN Codes
The SIM PIN codes will become unusable under the following conditions:
1. After disabling the secure screen lock method (e.g., re-configuring it to "_None_" or "_Swipe_")
2. After clearing the data for the **system built-in Settings app** via "App Info > Storage & Cache >
Clear storage"

These actions will irreversibly invalidate the secret key, making the SIM PIN decryption operation
impossible. To restore functionality, you'll need to provide all SIM PIN codes again to regenerate
the secret key.

# Contributing
### Contribute Code
You are welcome to contribute to the project!
Expand Down
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ buildscript {
// https://mvnrepository.com/artifact/androidx.appcompat/appcompat
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/appcompat/appcompat/
appcompat : 'androidx.appcompat:appcompat:1.7.0-beta01',
// https://mvnrepository.com/artifact/androidx.biometric/biometric
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/biometric/biometric/
biometric : 'androidx.biometric:biometric:1.2.0-alpha05', // TODO: AOSP sources use 1.2.0-alpha06; upgrade when available in maven central
// https://mvnrepository.com/artifact/androidx.collection/collection
// https://android.googlesource.com/platform/prebuilts/sdk/+/refs/heads/main/current/androidx/m2repository/androidx/collection/collection-jvm/
collection : 'androidx.collection:collection:1.4.0-alpha02',
Expand Down Expand Up @@ -186,6 +189,7 @@ addCompileOnlyJar('android-34.jar')

dependencies {
implementation libs.annotation
implementation libs.biometric
implementation libs.collection
implementation libs.core
implementation libs.livedata
Expand Down
Binary file modified images/scheduler-a10-dark.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/scheduler-a13-light.jpg
Binary file not shown.
Binary file added images/scheduler-a14-light.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions res/values-ar-rSA/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,15 @@
<string name="foreground_notification_paused_in_background_title">"متوقف مؤقتًا في الخلفية"</string>
<string name="foreground_notification_call_in_progress_text">"الاتصال قيد التقدم…"</string>
<string name="preference_not_set">"لم يتم الضبط"</string>
<string name="scheduler_pin_title">"‏رقم التعريف الشخصي لشريحة SIM"</string>
<string name="scheduler_pin_set_summary">"‏تم ضبط رمز PIN"</string>
<string name="scheduler_pin_unset_summary">"‏أدخل رقم التعريف الشخصي لشريحة SIM"</string>
<string name="scheduler_pin_invalid_hint">"اكتب رمز رقم التعريف الشخصي المكوّن من ٤ إلى ٨ أرقام."</string>
<string name="scheduler_pin_banner_sim_pin_decryption_failed_reason">"لم يتم فك شفرة رمز PIN لشريحة SIM. أعد إدخال رمز PIN لشريحة SIM لإصلاح المشكلة."</string>
<string name="scheduler_pin_banner_wrong_sim_pin_code_reason">"‏رقم التعريف الشخصي لشريحة SIM غير صحيح. ‏أعد إدخال رمز PIN الصحيح."</string>
<string name="scheduler_pin_banner_enter_pin_code_button_text">"‏أدخل رقم التعريف الشخصي لشريحة SIM"</string>
<string name="foreground_notification_unlock_to_continue_text">"فتح القفل للمتابعة…"</string>
<string name="notification_tap_to_fix_text">"انقر للإصلاح"</string>
<string name="sim_pin_operation_failed">"تعذّر إتمام عملية \"رقم التعريف الشخصي\" لشريحة SIM"</string>
<string name="sim_unlock_failed">"فشل طلب إلغاء تأمين SIM."</string>
</resources>
11 changes: 11 additions & 0 deletions res/values-az-rAZ/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,15 @@
<string name="foreground_notification_paused_in_background_title">"Arxa fonda dayandırıldı"</string>
<string name="foreground_notification_call_in_progress_text">"Zəng davam edir…"</string>
<string name="preference_not_set">"Ayarlanmayıb"</string>
<string name="scheduler_pin_title">"SIM PIN"</string>
<string name="scheduler_pin_set_summary">"PIN ayarlandı"</string>
<string name="scheduler_pin_unset_summary">"SIM PIN'ni daxil edin"</string>
<string name="scheduler_pin_invalid_hint">"4–8 rəqəmli PIN daxil edin."</string>
<string name="scheduler_pin_banner_sim_pin_decryption_failed_reason">"SIM PIN kodunu deşifrə etmək mümkün olmadı. Problemi həll etmək üçün SIM PIN kodunu yenidən daxil edin."</string>
<string name="scheduler_pin_banner_wrong_sim_pin_code_reason">"Yanlış SIM PIN kodu. Düzgün PIN kodu yenidən daxil edin."</string>
<string name="scheduler_pin_banner_enter_pin_code_button_text">"SIM PIN'ni daxil edin"</string>
<string name="foreground_notification_unlock_to_continue_text">"Davam etmək üçün kilidi açın…"</string>
<string name="notification_tap_to_fix_text">"Həll etmək üçün klikləyin"</string>
<string name="sim_pin_operation_failed">"SIM PIN əməliyyatı alınmadı!"</string>
<string name="sim_unlock_failed">"SIM kilid açma sorğusu uğursuz oldu."</string>
</resources>
11 changes: 11 additions & 0 deletions res/values-be-rBY/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,15 @@
<string name="foreground_notification_paused_in_background_title">"Прыпынена ў фон. рэжыме"</string>
<string name="foreground_notification_call_in_progress_text">"Ідзе выклік…"</string>
<string name="preference_not_set">"Не зададзена"</string>
<string name="scheduler_pin_title">"PIN-код SIM-карты"</string>
<string name="scheduler_pin_set_summary">"PIN-код усталяваны"</string>
<string name="scheduler_pin_unset_summary">"Увядзіце PIN-код SIM-карты"</string>
<string name="scheduler_pin_invalid_hint">"Увядзіце PIN-код, які змяшчае ад 4 да 8 лічбаў."</string>
<string name="scheduler_pin_banner_sim_pin_decryption_failed_reason">"Не ўдалося расшыфраваць PIN-код SIM-карты. Каб выправіць праблему, паўторна ўвядзіце PIN-код SIM-карты."</string>
<string name="scheduler_pin_banner_wrong_sim_pin_code_reason">"Няправільны PIN-код SIM-карты. Паўторна увядзіце правільны PIN-код."</string>
<string name="scheduler_pin_banner_enter_pin_code_button_text">"Увядзіце PIN-код SIM-карты"</string>
<string name="foreground_notification_unlock_to_continue_text">"Разблакіруйце, каб працягнуць…"</string>
<string name="notification_tap_to_fix_text">"Націсніце, каб выправіць"</string>
<string name="sim_pin_operation_failed">"Разблакіраваць SIM-карту PIN-кодам не атрымалася!"</string>
<string name="sim_unlock_failed">"Не атрымалася выканаць запыт на разблакоўку SIM."</string>
</resources>
11 changes: 11 additions & 0 deletions res/values-bg-rBG/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,15 @@
<string name="foreground_notification_paused_in_background_title">"На пауза на заден план"</string>
<string name="foreground_notification_call_in_progress_text">"Извършва се обаждане…"</string>
<string name="preference_not_set">"Не е зададено"</string>
<string name="scheduler_pin_title">"ПИН код за SIM карта"</string>
<string name="scheduler_pin_set_summary">"PIN кодът е зададен"</string>
<string name="scheduler_pin_unset_summary">"Въведете ПИН кода за SIM картата"</string>
<string name="scheduler_pin_invalid_hint">"Въведете ПИН код с четири до осем цифри."</string>
<string name="scheduler_pin_banner_sim_pin_decryption_failed_reason">"Не можа да се декриптира PIN кода на SIM картата. Въведете отново PIN кода на SIM картата, за да го поправите."</string>
<string name="scheduler_pin_banner_wrong_sim_pin_code_reason">"Неправилен ПИН код за SIM картата. Въведете отново правилния PIN код."</string>
<string name="scheduler_pin_banner_enter_pin_code_button_text">"Въведете ПИН кода за SIM картата"</string>
<string name="foreground_notification_unlock_to_continue_text">"Отключете, за да продължите…"</string>
<string name="notification_tap_to_fix_text">"Докоснете за коригиране"</string>
<string name="sim_pin_operation_failed">"Операцията с ПИН кода за SIM картата не бе успешна!"</string>
<string name="sim_unlock_failed">"Неуспешно искане за отключване на СИМ карта."</string>
</resources>
11 changes: 11 additions & 0 deletions res/values-bn-rBD/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,15 @@
<string name="foreground_notification_paused_in_background_title">"পশ্চাদপটে বিরাম দেওয়া আছে"</string>
<string name="foreground_notification_call_in_progress_text">"কল করা হচ্ছে…"</string>
<string name="preference_not_set">"সেট করা হয়নি"</string>
<string name="scheduler_pin_title">"সিম পিন"</string>
<string name="scheduler_pin_set_summary">"পিন সেট করা হয়েছে"</string>
<string name="scheduler_pin_unset_summary">"সিমের পিন লিখুন"</string>
<string name="scheduler_pin_invalid_hint">"একটি ৪ থেকে ৮ সংখ্যার পিন লিখুন।"</string>
<string name="scheduler_pin_banner_sim_pin_decryption_failed_reason">"SIM পিন কোড ডিক্রিপ্ট করা যায়নি। সমস্যা সমাধানের জন্য পুনরায় SIM পিন কোডটি প্রবেশ করুন।"</string>
<string name="scheduler_pin_banner_wrong_sim_pin_code_reason">"সিম কার্ডের ভুল পিন কোড দিয়েছেন। সঠিক PIN কোড পুনরায় লিখুন৷"</string>
<string name="scheduler_pin_banner_enter_pin_code_button_text">"সিমের পিন লিখুন"</string>
<string name="foreground_notification_unlock_to_continue_text">"চালিয়ে যেতে আনলক করুন…"</string>
<string name="notification_tap_to_fix_text">"ঠিক করতে ট্যাপ করুন"</string>
<string name="sim_pin_operation_failed">"সিম পিন দিয়ে আনলক করা যায়নি!"</string>
<string name="sim_unlock_failed">"সিম আনলক অনুরোধ ব্যর্থ হয়েছে!"</string>
</resources>
11 changes: 11 additions & 0 deletions res/values-ca-rES/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,15 @@
<string name="foreground_notification_paused_in_background_title">"Posada en pausa de fons"</string>
<string name="foreground_notification_call_in_progress_text">"Trucada en curs…"</string>
<string name="preference_not_set">"No definit"</string>
<string name="scheduler_pin_title">"PIN de la SIM"</string>
<string name="scheduler_pin_set_summary">"S'ha definit el PIN"</string>
<string name="scheduler_pin_unset_summary">"Introdueix el PIN de la SIM"</string>
<string name="scheduler_pin_invalid_hint">"Escriu un PIN que tingui entre 4 i 8 números."</string>
<string name="scheduler_pin_banner_sim_pin_decryption_failed_reason">"No s'ha pogut desxifrar el codi PIN de la SIM. Torna a introduir el codi PIN de la SIM per solucionar-ho."</string>
<string name="scheduler_pin_banner_wrong_sim_pin_code_reason">"El codi PIN de la SIM no és correcte. Torna a introduir el codi PIN correcte."</string>
<string name="scheduler_pin_banner_enter_pin_code_button_text">"Introdueix el PIN de la SIM"</string>
<string name="foreground_notification_unlock_to_continue_text">"Desbloqueja per continuar…"</string>
<string name="notification_tap_to_fix_text">"Toca per solucionar el problema"</string>
<string name="sim_pin_operation_failed">"Ha fallat l'operació del PIN de la SIM"</string>
<string name="sim_unlock_failed">"La petició de desbloqueig del SIM no ha tingut èxit."</string>
</resources>
11 changes: 11 additions & 0 deletions res/values-cs-rCZ/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,15 @@
<string name="foreground_notification_paused_in_background_title">"Pozastaveno na pozadí"</string>
<string name="foreground_notification_call_in_progress_text">"Probíhá hovor…"</string>
<string name="preference_not_set">"Nenastaveno"</string>
<string name="scheduler_pin_title">"Kód PIN SIM karty"</string>
<string name="scheduler_pin_set_summary">"Kód PIN byl nastaven"</string>
<string name="scheduler_pin_unset_summary">"Zadejte kód PIN SIM karty"</string>
<string name="scheduler_pin_invalid_hint">"Zadejte kód PIN o délce 4–8 číslic."</string>
<string name="scheduler_pin_banner_sim_pin_decryption_failed_reason">"Nepodařilo se dešifrovat PIN kód SIM karty. Zadejte znovu PIN kód SIM karty, aby se problém vyřešil."</string>
<string name="scheduler_pin_banner_wrong_sim_pin_code_reason">"Zadali jste nesprávný PIN SIM karty. Znovu zadejte správný kód PIN."</string>
<string name="scheduler_pin_banner_enter_pin_code_button_text">"Zadejte kód PIN SIM karty"</string>
<string name="foreground_notification_unlock_to_continue_text">"Pokračujte odemknutím…"</string>
<string name="notification_tap_to_fix_text">"Problém odstraníte klepnutím"</string>
<string name="sim_pin_operation_failed">"Operace pomocí kódu PIN SIM karty se nezdařila."</string>
<string name="sim_unlock_failed">"Požadavek odemknutí SIM neúspěšný."</string>
</resources>
11 changes: 11 additions & 0 deletions res/values-da-rDK/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,15 @@
<string name="foreground_notification_paused_in_background_title">"Standset i baggrunden"</string>
<string name="foreground_notification_call_in_progress_text">"Opkald i gang …"</string>
<string name="preference_not_set">"Ikke angivet"</string>
<string name="scheduler_pin_title">"Pinkode til SIM-kort"</string>
<string name="scheduler_pin_set_summary">"Pinkoden er blevet indstillet"</string>
<string name="scheduler_pin_unset_summary">"Angiv pinkoden til SIM-kortet"</string>
<string name="scheduler_pin_invalid_hint">"Angiv en pinkode på mellem 4 og 8 tal."</string>
<string name="scheduler_pin_banner_sim_pin_decryption_failed_reason">"SIM PIN-koden kunne ikke dekrypteres. Indtast SIM PIN-koden igen for at rette fejlen."</string>
<string name="scheduler_pin_banner_wrong_sim_pin_code_reason">"Du har angivet en forkert pinkode til SIM-kortet. Angiv den korrekte PIN-kode."</string>
<string name="scheduler_pin_banner_enter_pin_code_button_text">"Angiv pinkoden til SIM-kortet"</string>
<string name="foreground_notification_unlock_to_continue_text">"Lås op for at gå videre…"</string>
<string name="notification_tap_to_fix_text">"Tryk for at løse problemet"</string>
<string name="sim_pin_operation_failed">"Pinkoden til SIM-kortet blev afvist"</string>
<string name="sim_unlock_failed">"Anmodning om oplåsning af SIM-kort mislykkedes."</string>
</resources>
Loading

0 comments on commit bf404f6

Please sign in to comment.