Closed Bug 779334 Opened 12 years ago Closed 12 years ago

Cannot import contacts from SIM card

Categories

(Firefox OS Graveyard :: General, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED WORKSFORME

People

(Reporter: arcturus, Unassigned)

References

Details

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:17.0) Gecko/17.0 Firefox/17.0
Build ID: 20120723030606

Steps to reproduce:

Cannot import contacts from SIM using api:

Using the following code:

console.log('FJJ ::: About to start dumping contacts from SIM');
var request = navigator.mozContacts.getSimContacts('ADN');
request.onsuccess = function() {
  console.log('FJJ ::: We managed to read the sim contacts ' + request.result);
  console.log('FJJ ::: Contacts readed ' + request.result.length);
  if (request.result) {
    request.result.forEach(function (contact) {
      console.log('FJJ :: Name: ' + contact.name + ' ::: ' + contact.tel);
    });
  }
};
request.onerror = function() {
  console.log('Error reading sim contacts');
};

Not able to get any onerror or onsuccess message.

When asking for the sim contacts type 'FDN' we get 0 (maybe cause we don't have any of those).

Checked in the SIM card that we have contacts (inserted with incredible Nokia 3310)
Yoshi can you test if something regressed? I can take a look tomorrow.
Works for me with the following code:

> function readFromSIM() {
>   var type = 'ADN'; // valid values: 'ADN', 'FDN'
>   var request = navigator.mozContacts.getSimContacts(type);
>   console.log('Importing SIM contacts (' + type + ')...');
>   request.onsuccess = function onsuccess() {
>     for (var i = 0; i < request.result.length; i++) {
>       var contact = request.result[i];
>       console.log(contact.name + ' - ' + contact.tel);
>     }
>     console.log(request.result.length + ' contacts found.');
>   };
>   request.onerror = function onerror() {
>     console.log('Error reading SIM contacts.');
>   };
> }

Note that it took ~3 seconds to import 26 contacts on my SIM card.
(In reply to Fabien Cazenave (:kaze) from comment #2)
> Works for me with the following code:
> 
> > function readFromSIM() {
> >   var type = 'ADN'; // valid values: 'ADN', 'FDN'
> >   var request = navigator.mozContacts.getSimContacts(type);
> >   console.log('Importing SIM contacts (' + type + ')...');
> >   request.onsuccess = function onsuccess() {
> >     for (var i = 0; i < request.result.length; i++) {
> >       var contact = request.result[i];
> >       console.log(contact.name + ' - ' + contact.tel);
> >     }
> >     console.log(request.result.length + ' contacts found.');
> >   };
> >   request.onerror = function onerror() {
> >     console.log('Error reading SIM contacts.');
> >   };
> > }
> 
> Note that it took ~3 seconds to import 26 contacts on my SIM card.

Thanks Kaze! SIM access is slow :( and users probably won't use it every day so I don't think we should spend too much time trying to make it faster.
I wonder if we should make the SIM contacts reader yield each record individually, much like IndexedDB does it. That way the UI can at least show the progress visually. Good v2 feature, I guess.
(In reply to Philipp von Weitershausen [:philikon] from comment #4)
> I wonder if we should make the SIM contacts reader yield each record
> individually, much like IndexedDB does it. That way the UI can at least show
> the progress visually. Good v2 feature, I guess.

Right, I already looked at the code but that's not a trivial change. v2 sounds good.
+1

FTR, I think it would be better (= more consistent + better code separation) if the `getSimContacts()' method could return an array of mozContact elements instead of simple key/value pairs.
(In reply to Fabien Cazenave (:kaze) from comment #6)
> +1
> 
> FTR, I think it would be better (= more consistent + better code separation)
> if the `getSimContacts()' method could return an array of mozContact
> elements instead of simple key/value pairs.

Huh that's true. I had a version that returned mozContacts but somehow it's not in the code. I can change that right away if you want.
(In reply to Gregor Wagner [:gwagner] from comment #1)
> Yoshi can you test if something regressed? I can take a look tomorrow.
Hi,
I can also get the sim contacts.
maybe due to permission issue? 

update to latest gecko and gaia I can see 

I/Gecko   ( 1836): -*- ContactManager: Constructor
I/Gecko   ( 1836): -*- ContactManager: Contacts permission: false
I/Gecko   ( 1836): -*- ContactManager: getSimContacts not allowed
E/GeckoConsole( 1836): [JavaScript Error: "uncaught exception: 2147500033"]
(In reply to Yoshi Huang[:yoshi][:allstars.chh] from comment #9)
> maybe due to permission issue? 
> 
> update to latest gecko and gaia I can see 
> 
> I/Gecko   ( 1836): -*- ContactManager: Constructor
> I/Gecko   ( 1836): -*- ContactManager: Contacts permission: false
> I/Gecko   ( 1836): -*- ContactManager: getSimContacts not allowed
> E/GeckoConsole( 1836): [JavaScript Error: "uncaught exception: 2147500033"]

This changed yesterday and it should work with latest gaia. Can you check what app wants access by dumping the nodePrincipal in https://mxr.mozilla.org/mozilla-central/source/dom/contacts/ContactManager.js#460?
(In reply to Yoshi Huang[:yoshi][:allstars.chh] from comment #9)
> maybe due to permission issue? 
> 
> update to latest gecko and gaia I can see 
> 
> I/Gecko   ( 1836): -*- ContactManager: Constructor
> I/Gecko   ( 1836): -*- ContactManager: Contacts permission: false
> I/Gecko   ( 1836): -*- ContactManager: getSimContacts not allowed
> E/GeckoConsole( 1836): [JavaScript Error: "uncaught exception: 2147500033"]

I tried pretty hard to reproduce this but I couldn't :( I need more information here. How is your update process?
(In reply to Gregor Wagner [:gwagner] from comment #11)
Hi gregor,
  I didn't add permission 'contacts' in my test gaia app, it works now. Sorry for causing confusion.

Thanks
Francisco does it work now for you? Can we close this bug?
Yes,

I tried it and now working for me. Go ahead and close the bug.

Thanks a lot for your help!
Status: UNCONFIRMED → RESOLVED
Closed: 12 years ago
Resolution: --- → WORKSFORME
(In reply to Gregor Wagner [:gwagner] from comment #5)
> (In reply to Philipp von Weitershausen [:philikon] from comment #4)
> > I wonder if we should make the SIM contacts reader yield each record
> > individually, much like IndexedDB does it. That way the UI can at least show
> > the progress visually. Good v2 feature, I guess.
> 
> Right, I already looked at the code but that's not a trivial change. v2
> sounds good.

FTR, it’s been reported that importing SIM card contacts can take several *minutes*, see https://github.com/mozilla-b2g/gaia/issues/3196
You need to log in before you can comment on or make changes to this bug.