Goodwy / Dialer

GNU General Public License v3.0
64 stars 15 forks source link

Incorrect SIM shown in Recents page for contacts #48

Closed eblis closed 2 months ago

eblis commented 2 months ago

I have 2 SIMs active on my Phone, SIM 1 is green, SIM2 is yellow. In the recents page, when I click on information for a contact it shows that all calls have been made from SIM2, even though most (if not all of the calls) were actually made from SIM1.

There seems to be a problem with showing which SIM was used to make the call(s), it always lists SIM2.

Goodwy commented 2 months ago

Can you attach a screenshot of the problem and specify which version of the app you are using?

eblis commented 2 months ago

Version 5.2.8.

I see a number 2 with yellow, I'm guessing it's SIM2. Also, not all calls are marked as HD, whereas in Google Phone they are marked HD, but I guess that's a separate issue.

Screenshot_20240907-144015~2

This is my SIM configuration Screenshot_20240907-144413

And if I look in Google Phone it shows the call as coming from orange. Screenshot_20240907-144248

Goodwy commented 2 months ago

Are sim card numbers displayed correctly in the Recent tab?

eblis commented 2 months ago

You mean on the main Recents page, where all contacts are listed? No, it's showing 2 there as well for all calls from SIM1 (my main SIM).

And I just tried to make a call from SIM 2 and it's shown as 3 in the Recents page

Goodwy commented 2 months ago

What kind of device do you have?

eblis commented 2 months ago

Realme GT neo 2

eblis commented 2 months ago

So it looks like SIM id is 1, 2, 3, etc, but SIM.handle.id is "2", "3", "4", ... image

eblis commented 2 months ago

Instead of checking if the manufacturer is Huawei (and Realme) could you maybe look for the minimum slot index and use that as an offset?

Something like this: val simOffset = 1 - (accountIdToSimIDMap.keys.map { it.toInt() }.min())

And then simID = if (it >= 0) it + simOffset else -1

Manufacturer Minimum SIM slot offset
Realme "2" -1
Huawei "0" 1
Honor "0" 1
others "1" 0

This way it should work for any manufacturer without having to check each one separately.

eblis commented 2 months ago

Alternatively, if you reverse the 2 ways to fetch the SIMs it would work for Realme, as the map is correct, "2" -> 1, "3" -> 2, but it never executes as it thinks it got the correct SIM via the offsetting.

                simID = accountIdToSimIDMap[accountId] ?: -1
                if ((simID == -1) && (accountId != null)) {
                    if (accountId.length == 1) {
                        accountId.toIntOrNull()?.let {
                            val index = if (isHuawei) 1 else 0 //Huawei's sim card index returns (0,1...)
                            simID = if (it >= 0) it + index else -1
                        }
                    }
                }
Goodwy commented 2 months ago

The problem is the sim card value in Recent android calls: val accountId = cursor.getStringValue(Calls.PHONE_ACCOUNT_ID) Can contain PhoneAccountHandle, sim card number (1,2...) or sim card index (0,1...). Earlier we considered that only PhoneAccountHandle is stored there and it worked correctly for most devices, most likely we will return this principle and only for Huawei devices we will try to calculate as if the sim card index is stored there.

Goodwy commented 2 months ago

Instead of checking if the manufacturer is Huawei (and Realme) could you maybe look for the minimum slot index and use that as an offset?

Something like this: val simOffset = 1 - (accountIdToSimIDMap.keys.map { it.toInt() }.min())

And then simID = if (it >= 0) it + simOffset else -1

Manufacturer Minimum SIM slot offset Realme "2" -1 Huawei "0" 1 Honor "0" 1 others "1" 0 This way it should work for any manufacturer without having to check each one separately.

To do this, we need to go through all the records with the cursor and see what SIM card values exist. In some cases it will give incorrect result, for example, when the list contains only calls on one of SIM cards.

eblis commented 2 months ago

I thought it was iterating over all SIMs in the system, not just the SIMs used for that contact

Goodwy commented 2 months ago

getAvailableSIMCardLabels() - looks for all available SIM cards on the device and there are no problems with it. The problem is with information about SIM card that is recorded in Android's call history.

eblis commented 2 months ago

But then calculating the minimum from getAvailableSIMCardLabels() and using that as the offset should work. I'll create a quick PR and you can have a look.

Goodwy commented 2 months ago

In getAvailableSIMCardLabels() we assign the SIM card index ourselves, it will not match the data from the call list.

eblis commented 2 months ago

I saw that, but the keys in getAvailableSIMCardLabels are the keys used in the call list, no ? I would expect the keys for Huawei devices to be something like "0", "1", are they something else ?

Goodwy commented 2 months ago

For example, on my Xiaomi device the key is the PhoneAccountHandle object, which consists of a bunch of letters and numbers, on one of the user's Huawei devices it was the SIM card slot index (0,1...), on some other Xiaomi devices it was the SIM card number (1,2...).

Goodwy commented 2 months ago

Check after the 5.2.9 update, Google Play is still checking, but on GitHub it's already available.

eblis commented 2 months ago

Correct SIM (1 and 2) is now shown for recent calls with 5.2.9