Bug 1218721 - Part 1 - Always Insert Name/Number when Providing IccContact Response. r=echen, a=mahe
authorBevis Tseng <btseng@mozilla.com>
Fri, 30 Oct 2015 20:22:07 +0800
changeset 284546 1f3ac230b856edb7d9b050d2117efa3d09f4ad47
parent 284545 1091f16dde9bcfa190a7cc892aaa14b979ae0b81
child 284547 36ad3870f762a7d1b6e27773364df8654c447038
push id136
push usercbook@mozilla.com
push dateTue, 10 Nov 2015 09:57:03 +0000
reviewersechen, mahe
bugs1218721
milestone44.0a2
Bug 1218721 - Part 1 - Always Insert Name/Number when Providing IccContact Response. r=echen, a=mahe
dom/icc/IccCallback.cpp
dom/icc/IccContact.cpp
dom/icc/gonk/IccService.js
dom/icc/ipc/IccIPCUtils.cpp
dom/system/gonk/ril_worker.js
--- a/dom/icc/IccCallback.cpp
+++ b/dom/icc/IccCallback.cpp
@@ -33,46 +33,53 @@ IccContactToMozContact(JSContext* aCx, G
   // Names
   char16_t** rawStringArray = nullptr;
   uint32_t count = 0;
   nsresult rv = aIccContact->GetNames(&count, &rawStringArray);
   NS_ENSURE_SUCCESS(rv, rv);
   if (count > 0) {
     Sequence<nsString>& nameSeq = properties.mName.Construct().SetValue();
     for (uint32_t i = 0; i < count; i++) {
-      nameSeq.AppendElement(nsDependentString(rawStringArray[i]), fallible);
+      nameSeq.AppendElement(
+        rawStringArray[i] ? nsDependentString(rawStringArray[i])
+                          : EmptyString(),
+        fallible);
     }
     NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(count, rawStringArray);
   }
 
   // Numbers
   rawStringArray = nullptr;
   count = 0;
   rv = aIccContact->GetNumbers(&count, &rawStringArray);
   NS_ENSURE_SUCCESS(rv, rv);
   if (count > 0) {
     Sequence<ContactTelField>& numberSeq = properties.mTel.Construct().SetValue();
     for (uint32_t i = 0; i < count; i++) {
       ContactTelField number;
-      number.mValue.Construct() = nsDependentString(rawStringArray[i]);
+      number.mValue.Construct() =
+        rawStringArray[i] ? nsDependentString(rawStringArray[i])
+                          : EmptyString();
       numberSeq.AppendElement(number, fallible);
     }
     NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(count, rawStringArray);
   }
 
   // Emails
   rawStringArray = nullptr;
   count = 0;
   rv = aIccContact->GetEmails(&count, &rawStringArray);
   NS_ENSURE_SUCCESS(rv, rv);
   if (count > 0) {
     Sequence<ContactField>& emailSeq = properties.mEmail.Construct().SetValue();
     for (uint32_t i = 0; i < count; i++) {
       ContactField email;
-      email.mValue.Construct() = nsDependentString(rawStringArray[i]);
+      email.mValue.Construct() =
+        rawStringArray[i] ? nsDependentString(rawStringArray[i])
+                          : EmptyString();
       emailSeq.AppendElement(email, fallible);
     }
     NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(count, rawStringArray);
   }
 
   ErrorResult er;
   RefPtr<mozContact> contact
     = mozContact::Constructor(aGlobal, aCx, properties, er);
--- a/dom/icc/IccContact.cpp
+++ b/dom/icc/IccContact.cpp
@@ -124,16 +124,21 @@ NS_IMETHODIMP IccContact::Get##_field(ui
     return NS_OK;                                                               \
   }                                                                             \
   char16_t** temp =                                                             \
     static_cast<char16_t**>(moz_xmalloc(sizeof(char16_t*) * (count)));          \
   if (temp == nullptr) {                                                        \
     return NS_ERROR_OUT_OF_MEMORY;                                              \
   }                                                                             \
   for (uint32_t i = 0; i < count; i++) {                                        \
+    if(m##_field[i].IsVoid()) {                                                 \
+      (temp)[i] = nullptr;                                                      \
+      continue;                                                                 \
+    }                                                                           \
+                                                                                \
     (temp)[i] = ToNewUnicode(m##_field[i]);                                     \
     if (!(temp)[i]) {                                                           \
       NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(i, temp);                           \
       return NS_ERROR_OUT_OF_MEMORY;                                            \
     }                                                                           \
   }                                                                             \
                                                                                 \
   *aCount = count;                                                              \
--- a/dom/icc/gonk/IccService.js
+++ b/dom/icc/gonk/IccService.js
@@ -81,23 +81,18 @@ CdmaIccInfo.prototype = {
 };
 
 function IccContact(aContact) {
   this.id = aContact.contactId || null;
   this._names = [];
   this._numbers = [];
   this._emails = [];
 
-  if (aContact.alphaId) {
-    this._names.push(aContact.alphaId);
-  }
-
-  if (aContact.number) {
-    this._numbers.push(aContact.number);
-  }
+  this._names.push(aContact.alphaId);
+  this._numbers.push(aContact.number);
 
   let anrLen = aContact.anr ? aContact.anr.length : 0;
   for (let i = 0; i < anrLen; i++) {
     this._numbers.push(aContact.anr[i]);
   }
 
   if (aContact.email) {
     this._emails.push(aContact.email);
--- a/dom/icc/ipc/IccIPCUtils.cpp
+++ b/dom/icc/ipc/IccIPCUtils.cpp
@@ -46,41 +46,47 @@ IccIPCUtils::GetIccContactDataFromIccCon
 
   // Names
   char16_t** rawStringArray = nullptr;
   uint32_t count = 0;
   rv = aContact->GetNames(&count, &rawStringArray);
   NS_ENSURE_SUCCESS_VOID(rv);
   if (count > 0) {
     for (uint32_t i = 0; i < count; i++) {
-      aOutData.names().AppendElement(nsDependentString(rawStringArray[i]));
+      aOutData.names().AppendElement(
+        rawStringArray[i] ? nsDependentString(rawStringArray[i])
+                          : NullString());
     }
     NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(count, rawStringArray);
   }
 
   // Numbers
   rawStringArray = nullptr;
   count = 0;
   rv = aContact->GetNumbers(&count, &rawStringArray);
   NS_ENSURE_SUCCESS_VOID(rv);
   if (count > 0) {
     for (uint32_t i = 0; i < count; i++) {
-      aOutData.numbers().AppendElement(nsDependentString(rawStringArray[i]));
+      aOutData.numbers().AppendElement(
+        rawStringArray[i] ? nsDependentString(rawStringArray[i])
+                          : NullString());
     }
     NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(count, rawStringArray);
   }
 
   // Emails
   rawStringArray = nullptr;
   count = 0;
   rv = aContact->GetEmails(&count, &rawStringArray);
   NS_ENSURE_SUCCESS_VOID(rv);
   if (count > 0) {
     for (uint32_t i = 0; i < count; i++) {
-      aOutData.emails().AppendElement(nsDependentString(rawStringArray[i]));
+      aOutData.emails().AppendElement(
+        rawStringArray[i] ? nsDependentString(rawStringArray[i])
+                          : NullString());
     }
     NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(count, rawStringArray);
   }
 }
 
 } // namespace icc
 } // namespace dom
 } // namespace mozilla
\ No newline at end of file
--- a/dom/system/gonk/ril_worker.js
+++ b/dom/system/gonk/ril_worker.js
@@ -8684,17 +8684,17 @@ ICCPDUHelperObject.prototype = {
 
   /**
    * Write GSM 8-bit unpacked octets.
    *
    * @param numOctets   Number of total octets to be writen, including trailing
    *                    0xff.
    * @param str         String to be written. Could be null.
    *
-   * @return The string has been written into Buf.
+   * @return The string has been written into Buf. "" if str is null.
    */
   writeStringTo8BitUnpacked: function(numOctets, str) {
     const langTable = PDU_NL_LOCKING_SHIFT_TABLES[PDU_NL_IDENTIFIER_DEFAULT];
     const langShiftTable = PDU_NL_SINGLE_SHIFT_TABLES[PDU_NL_IDENTIFIER_DEFAULT];
 
     let GsmPDUHelper = this.context.GsmPDUHelper;
 
     // If the character is GSM extended alphabet, two octets will be written.
@@ -8724,17 +8724,17 @@ ICCPDUHelperObject.prototype = {
       j++;
     }
 
     // trailing 0xff
     while (j++ < numOctets) {
       GsmPDUHelper.writeHexOctet(0xff);
     }
 
-    return (str) ? str.substring(0, i) : null;
+    return (str) ? str.substring(0, i) : "";
   },
 
   /**
    * Write UCS2 String on UICC.
    * The default choose 0x81 or 0x82 encode, otherwise use 0x80 encode.
    *
    * @see TS 102.221, Annex A.
    * @param numOctets
@@ -9085,17 +9085,17 @@ ICCPDUHelperObject.prototype = {
    *        Alpha Identifier to be written.
    *
    * @return The Alpha Identifier has been written into Buf.
    *
    * Unused octets will be written as 0xff.
    */
   writeAlphaIdentifier: function(numOctets, alphaId) {
     if (numOctets === 0) {
-      return null;
+      return "";
     }
 
     // If alphaId is empty or it's of GSM 8 bit.
     if (!alphaId || this.context.ICCUtilsHelper.isGsm8BitAlphabet(alphaId)) {
       return this.writeStringTo8BitUnpacked(numOctets, alphaId);
     } else {
       return this.writeICCUCS2String(numOctets, alphaId);
     }
@@ -9217,17 +9217,17 @@ ICCPDUHelperObject.prototype = {
         GsmPDUHelper.writeHexOctet(0xff);
       }
       return writtenNumber;
     } else {
       // +1 for numLen
       for (let i = 0; i < ADN_MAX_BCD_NUMBER_BYTES + 1; i++) {
         GsmPDUHelper.writeHexOctet(0xff);
       }
-      return null;
+      return "";
     }
   }
 };
 
 function StkCommandParamsFactoryObject(aContext) {
   this.context = aContext;
 }
 StkCommandParamsFactoryObject.prototype = {