mueller-ma / PrepaidBalance

App to check your prepaid balance
Apache License 2.0
35 stars 14 forks source link

SIM selection incorrectly lists "not set" if SIM has no name #296

Closed juleskers closed 1 month ago

juleskers commented 1 month ago

Describe the bug My new phone uses an eSIM, and for some reason the profile I downloaded fromy carrier came without a name set. I manually specified the name on my device settings.

In prepaid balance, this SIM is available in the sim-selection setting, but listed with the empty, Carrier-provided name (see screenshot).
If this is selected, the overview "hint" text for sim selection will incorrectly show "not set" (see screenshot background).

Despite the visual "not set", the app functions correctly, refreshing receives a fresh USSD response, and updates the "last refreshed" timestamp.

Screenshot_20240704-091514_Prepaid Saldo

I'm guessing the empty-string name accidentally overlaps with an actual "setting is null (or empty)" check.

Expected behavior It is probably more sensible to use (or at least fall back to) a manually provided name, if the sim has one.

Device (please complete the following information):

juleskers commented 1 month ago

I plan on having a look in the code, and Android API docs, to see if I can whip something up, but I wanted to start of publicly documenting the issue first, in case I never get anywhere.

juleskers commented 1 month ago

Research notes:

Prefs currently shows: https://developer.android.com/reference/android/telephony/SubscriptionInfo#getCarrierName()

https://github.com/mueller-ma/PrepaidBalance/blob/d2d5940ec783d4ee96102da0c879f2821f105881/app/src/main/java/com/github/muellerma/prepaidbalance/ui/PreferenceActivity.kt#L157

Todo investigate: display name (either as fallback or replacement) https://developer.android.com/reference/android/telephony/SubscriptionInfo#getDisplayName()

I have a nice testcase, since one of my aims is foreign, so it is roaming by definition.

Nice-to-haves: https://developer.android.com/reference/android/telephony/SubscriptionInfo#getIconTint()
https://developer.android.com/reference/android/telephony/SubscriptionInfo?hl=en#createIconBitmap(android.content.Context)

juleskers commented 1 month ago

Research update, I've gotten a debug-build of the app running on my phone :tada:

Adding in some log-statements gave me the following info on the SubscriptionInfos:

physical sim (as-is, no sensitive info present that needs to be deleted

{id=2 iccId= simSlotIndex=0 carrierId=1644 displayName=KPN carrierName=o2 - de — KPN nameSource=2 iconTint=-15181124 number= dataRoaming=1 iconBitmap=null mcc=204 mnc=12 countryIso=nl isEmbedded=false nativeAccessRules=null cardString= cardId=1 portIndex=0 isOpportunistic=false groupUUID=null isGroupDisabled=false profileClass=-1 ehplmns=null hplmns=null subscriptionType=0 groupOwner=null carrierConfigAccessRules=null areUiccApplicationsEnabled=true usageSetting=0}

embedded eSim (redacted a bunch of info that looked like certificates, no idea how private those are supposed to be):

{id=1 iccId= simSlotIndex=1 carrierId=2092 displayName=congstar carrierName= nameSource=2 iconTint=-9033797 number= dataRoaming=1 iconBitmap=null mcc=262 mnc=01 countryIso=de isEmbedded=true nativeAccessRules=null cardString= cardId=0 portIndex=0 isOpportunistic=false groupUUID=null isGroupDisabled=false profileClass=2 ehplmns=null hplmns=null subscriptionType=0 groupOwner=null carrierConfigAccessRules=[*REDACTED*] areUiccApplicationsEnabled=true usageSetting=0}

The essential elements are:

physical: displayName=KPN carrierName=o2 - de — KPN
embedded: displayName=congstar carrierName=

as I suspected, the "carrierName" is empty, not null.
For the correctly functioning sim-card, the carrierName shows exactly what is shown in my device's status bar: first the actually connected (roaming) network, dash-joined with my SIM-card issuer. The displayName indeed changes when I manually change my device settings > networks > sim-cards > sim (where one also changes the accent color).


P.S. getting a debug-build involved an annoying amount of Yak-Shaving. My normal IDE is IntelliJ, which does have an Android-plugin. However, that plugin is always slow to update, so it doesn't support the current Android-Gradle-Plugin used by the project. Instead, I get the following error when opening the project in IntelliJ (reading gradle project settings fails)

The project is using an incompatible version (AGP 8.3.2) of the Android Gradle plugin. Latest supported version is AGP 8.2.0

So, I had to install the full "Android Studio"