Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inserting to SIM card fails with NAME_EXCEEDED_MAX_CHAR_LIMIT #326

Open
Aroxed opened this issue Sep 25, 2023 · 8 comments
Open

Inserting to SIM card fails with NAME_EXCEEDED_MAX_CHAR_LIMIT #326

Aroxed opened this issue Sep 25, 2023 · 8 comments
Assignees
Labels
question Further information is requested

Comments

@Aroxed
Copy link

Aroxed commented Sep 25, 2023

Hi!
I'm trying to insert a contact into my SIM card. I've used such an approach as in the sample:

        val result = Contacts(context).sim().insertWithPermission().simContact { name="a1"; number="321" }.commitWithContext()

The result is:

SimContactsInsert.Result {
    isSuccessful: false
    failureReasons: {NewSimContact(name=a1, number=321, isRedacted=false)=NAME_EXCEEDED_MAX_CHAR_LIMIT}
    isRedacted: false
}

Also I ran the code according to the documentation:

        var insertResult: SimContactsInsert.Result;
            val newContact1 = NewSimContact(name = "abcdef", number = "1234567890")
            val newContact2 = NewSimContact(name = "abcdfb", number = "1234567890")
            val isSimCardReady = Contacts(this.applicationContext).sim().cardInfo.isReady // true
            insertResult = Contacts(this.applicationContext)
                .sim()
                .insert()
                .simContacts(newContact1, newContact2)
                .commit()

And the result is the same.
Could you tell me what I did wrong regarding NAME_EXCEEDED_MAX_CHAR_LIMIT?

I really appreciate any help you can provide.
Andrii.

@vestrel00 vestrel00 changed the title NAME_EXCEEDED_MAX_CHAR_LIMIT after inserting into a SIM card Inserting to SIM card fails with NAME_EXCEEDED_MAX_CHAR_LIMIT Sep 25, 2023
@vestrel00
Copy link
Owner

vestrel00 commented Sep 25, 2023

I'll try to reproduce this issue with my physical devices tomorrow. I'm the meantime, could you provide me some more details? I want to know the following;

  1. What is the device you are testing on?
  2. What is the Android OS version of that device?
  3. Can you put more than one SIM card into that device (does it support multiple SIM cards)?
  4. What SIM card are you using?
  5. Are you able to insert new contacts into the SIM card using different software such as https://play.google.com/store/apps/details?id=com.midi.siminfo ?
  6. Are you able to query the SIM card and get contacts?
  7. Are you able to delete contacts from the SIM card?
  8. Log the values of the character limits;
val contactsApi = Contacts(context)
val nameMaxLength = contactsApi.sim().cardInfo.maxCharacterLimits().nameMaxLength()
val numberMaxLength = contactsApi.sim().cardInfo.maxCharacterLimits().numberMaxLength()

I want to know the values of nameMaxLenght and numberMaxLength. If it is 0 or -1, then I think that insertion is failing during the char max length calculation process. In order to calculate the char max length, the API internally attempts to insert contacts with different name and number char lengths starting from the max possible length all the way to 0. If all inserts failed during that process, then the char max lengths will be 0.

Thanks for raising this issue! I'm hoping to get to the bottom of this with your help 😁

@vestrel00 vestrel00 self-assigned this Sep 25, 2023
@vestrel00 vestrel00 added bug Something isn't working and removed bug Something isn't working labels Sep 25, 2023
@vestrel00
Copy link
Owner

I will wait with labeling this as a bug until I get more details 😃

@Aroxed
Copy link
Author

Aroxed commented Sep 25, 2023

Here is the detailed information.

What is the device you are testing on?
Samsung Galaxy M32

What is the Android OS version of that device?
Android 13

Can you put more than one SIM card into that device (does it support multiple SIM cards)?
Dual SIM Card. (Tried to disable one of the SIM Cards. The result is the same)

What SIM card are you using?
I didn't understand what exactly would you like to find out.

Are you able to insert new contacts into the SIM card using different software such as https://play.google.com/store/apps/details?id=com.midi.siminfo ?
I've installed "SIM Card Info + SIM Contacts". Yes, I can add but only after restarting the SIM card (switching the phone to the Flight mode and back).
I used other applications like (https://play.google.com/store/apps/details?id=com.dev.simcontactsmanager). They strangely work often only after restarting my SIM.

Are you able to query the SIM card and get contacts?
Yes, reading works without any issues (Your sample app returns the list of SIM's contacts)

Are you able to delete contacts from the SIM card?
Yes, I can delete using your app as well as using "simcontactsmanager" app after the SIM restarting.

Log the values of the character limits:
nameMaxLength = 0
numberMaxLength = 0
Can I cope this 'zero' problem?

P.S. I've also run my code at Samsung Galaxy M31s/Android 12/Dual SIM Card. The result is the same.

@Aroxed
Copy link
Author

Aroxed commented Sep 25, 2023

I've also hardcoded two lines in java/contacts/core/sim/SimCardMaxCharacterLimits.kt:
Line 162: override fun numberMaxLength(): Int = 10 //numberMaxLength { false }
Line 140: override fun nameMaxLength(): Int = 10 //nameMaxLength { false }
And got the result:

SimContactsInsert.Result {
    isSuccessful: false
    failureReasons: {NewSimContact(name=sch281, number=321, isRedacted=false)=UNKNOWN}
    isRedacted: false
}

But after I restarted my SIM card again I got:

SimContactsInsert.Result {
    isSuccessful: true
    failureReasons: {NewSimContact(name=sch281, number=321, isRedacted=false)=null}
    isRedacted: false
}

It worked!
So, that's probably an issue with 'zero' nameMaxLength() and numberMaxLength(). Could you fix it somehow? :)
Maybe allowing a programmer to set default values for them when zero is calculated? ;)

@Aroxed
Copy link
Author

Aroxed commented Sep 25, 2023

I have another question for you as an expert in Android contacts. Do you know if is it possible when me to add a contact to my SIM card to specify the exact position of the contact in the SIM card's phone book? Does it add contacts sequentially?
For example, if I have an empty contact book can I be sure that contacts are placed one-by-one as I enter them?

Thanks.

@vestrel00
Copy link
Owner

vestrel00 commented Sep 25, 2023

Thanks so much for all the detailed information!

I've also hardcoded...
But after I restarted my SIM card again...
It worked!

It seems like there might not be any issue with the API! The other apps you used for testing also failed but then started working after restarting your SIM card. Same with this library.

So, that's probably an issue with 'zero' nameMaxLength() and numberMaxLength(). Could you fix it somehow? Maybe allowing a programmer to set default values for them when zero is calculated?

I believe I can make an internal fix for this. When 0 WAS calculated and an insert or update operation is attempted, I can perform recalculations by clearing the cache; Contacts(context).sim().cardInfo.maxCharacterLimits().clearCachedNameAndNumberMaxLengths()

Read my docs for more info on this; https://vestrel00.github.io/contacts-android/sim/about-sim-contacts/#character-limits

You can probably also make the fix on your end too by checking if the max char lengths is 0 if an error occurred, then call clearCachedNameAndNumberMaxLengths, and then try again.

EDIT: It seems like there might be an issue with the max length calculation. I'm already checking for 0 every time I try to use the max length stored in cache and recalculating if it is 0. I will need to take a deeper look into this.

Screenshot 2023-09-25 at 6 10 56 AM

@Aroxed, are you sure that the insert only works after restarting SIM with the the following hardcoded changes you made?

Line 162: override fun numberMaxLength(): Int = 10 //numberMaxLength { false }
Line 140: override fun nameMaxLength(): Int = 10 //nameMaxLength { false }

Without the above changes, after restarting SIM, the insert still fails? Could you try again without any hard code changes to the API?

Also, since you are able to reproduce the issue and you are able to make code changes and run the sample app, do you mind trying to figure out what's wrong? Maybe you can even come up with a fix (fork this repo and create a PR)? I don't mind how you fix it, I can always clean it up later and add/update documentation if necessary.

Let me know. Thanks! 😁

@vestrel00
Copy link
Owner

Do you know if is it possible when me to add a contact to my SIM card to specify the exact position of the contact in the SIM card's phone book? Does it add contacts sequentially?

This is a tricky one to answer because internally the SIM card stores contacts based on an integer ID. However, applications that show the contacts in a UI can choose to order contacts in however way they want (typically by name).

Feel free to read all of my developer notes on this that I wrote while writing the APIs. Specifically this section; https://vestrel00.github.io/contacts-android/sim/about-sim-contacts/#figuring-out-how-to-perform-crud-operations

image

@vestrel00 vestrel00 added the bug Something isn't working label Sep 25, 2023
@vestrel00
Copy link
Owner

vestrel00 commented Sep 30, 2023

I'll try to reproduce this issue on my numerous physical devices next week or the following week. Work and life are extremely busy!


@Aroxed, could you please re-confirm. Without making any code changes to the library, after restarting SIM, the library insert still fails?

Also, as I've mentioned, please feel free to tackle this issue yourself and create a PR 🙏

@vestrel00 vestrel00 added question Further information is requested and removed bug Something isn't working labels Oct 3, 2023
@github-project-automation github-project-automation bot moved this to Waiting for reply in Consumer issues Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
Status: Waiting for reply
Development

No branches or pull requests

2 participants