Skip to content

Commit 9f36f51

Browse files
Jake HambyJean-Baptiste Queru
authored andcommitted
Fix updating and deleting FDN entries with an empty alpha identifier.
- Fix AdnRecord.buildAdnString() to generate the correct record when alpha identifier is empty. This allows the user to update an FDN entry to remove the alpha identifier. Previously the entire entry would be deleted because an empty record was generated here when the alpha identifier was empty, rather than a record containing the phone number with an empty alpha tag. Also, return null if the number or alpha tag are too long. - Fix bug in IccProvider.delete() where efType was compared against local FDN constant rather than IccConstants.EF_FDN. This would always return false. Comparing with IccConstants.EF_FDN gives the intended behavior. Change-Id: I0ea75d7e107c7318c9a48ae6e0a15845a718f4c0
1 parent 27b2267 commit 9f36f51

File tree

3 files changed

+48
-37
lines changed

3 files changed

+48
-37
lines changed

telephony/java/com/android/internal/telephony/AdnRecord.java

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919
import android.os.Parcel;
2020
import android.os.Parcelable;
2121
import android.telephony.PhoneNumberUtils;
22+
import android.text.TextUtils;
2223
import android.util.Log;
2324

24-
import com.android.internal.telephony.GsmAlphabet;
25-
2625
import java.util.Arrays;
2726

2827

@@ -38,8 +37,8 @@ public class AdnRecord implements Parcelable {
3837

3938
//***** Instance Variables
4039

41-
String alphaTag = "";
42-
String number = "";
40+
String alphaTag = null;
41+
String number = null;
4342
String[] emails;
4443
int extRecord = 0xff;
4544
int efid; // or 0 if none
@@ -63,8 +62,8 @@ public class AdnRecord implements Parcelable {
6362
// ADN offset
6463
static final int ADN_BCD_NUMBER_LENGTH = 0;
6564
static final int ADN_TON_AND_NPI = 1;
66-
static final int ADN_DAILING_NUMBER_START = 2;
67-
static final int ADN_DAILING_NUMBER_END = 11;
65+
static final int ADN_DIALING_NUMBER_START = 2;
66+
static final int ADN_DIALING_NUMBER_END = 11;
6867
static final int ADN_CAPABILITY_ID = 12;
6968
static final int ADN_EXTENSION_ID = 13;
7069

@@ -152,17 +151,31 @@ public String toString() {
152151
}
153152

154153
public boolean isEmpty() {
155-
return alphaTag.equals("") && number.equals("") && emails == null;
154+
return TextUtils.isEmpty(alphaTag) && TextUtils.isEmpty(number) && emails == null;
156155
}
157156

158157
public boolean hasExtendedRecord() {
159158
return extRecord != 0 && extRecord != 0xff;
160159
}
161160

161+
/** Helper function for {@link #isEqual}. */
162+
private static boolean stringCompareNullEqualsEmpty(String s1, String s2) {
163+
if (s1 == s2) {
164+
return true;
165+
}
166+
if (s1 == null) {
167+
s1 = "";
168+
}
169+
if (s2 == null) {
170+
s2 = "";
171+
}
172+
return (s1.equals(s2));
173+
}
174+
162175
public boolean isEqual(AdnRecord adn) {
163-
return ( alphaTag.equals(adn.getAlphaTag()) &&
164-
number.equals(adn.getNumber()) &&
165-
Arrays.equals(emails, adn.getEmails()));
176+
return ( stringCompareNullEqualsEmpty(alphaTag, adn.alphaTag) &&
177+
stringCompareNullEqualsEmpty(number, adn.number) &&
178+
Arrays.equals(emails, adn.emails));
166179
}
167180
//***** Parcelable Implementation
168181

@@ -184,36 +197,33 @@ public void writeToParcel(Parcel dest, int flags) {
184197
*
185198
* @param recordSize is the size X of EF record
186199
* @return hex byte[recordSize] to be written to EF record
187-
* return nulll for wrong format of dialing nubmer or tag
200+
* return null for wrong format of dialing number or tag
188201
*/
189202
public byte[] buildAdnString(int recordSize) {
190203
byte[] bcdNumber;
191204
byte[] byteTag;
192-
byte[] adnString = null;
205+
byte[] adnString;
193206
int footerOffset = recordSize - FOOTER_SIZE_BYTES;
194207

195-
if (number == null || number.equals("") ||
196-
alphaTag == null || alphaTag.equals("")) {
208+
// create an empty record
209+
adnString = new byte[recordSize];
210+
for (int i = 0; i < recordSize; i++) {
211+
adnString[i] = (byte) 0xFF;
212+
}
197213

198-
Log.w(LOG_TAG, "[buildAdnString] Empty alpha tag or number");
199-
adnString = new byte[recordSize];
200-
for (int i = 0; i < recordSize; i++) {
201-
adnString[i] = (byte) 0xFF;
202-
}
214+
if (TextUtils.isEmpty(number)) {
215+
Log.w(LOG_TAG, "[buildAdnString] Empty dialing number");
216+
return adnString; // return the empty record (for delete)
203217
} else if (number.length()
204-
> (ADN_DAILING_NUMBER_END - ADN_DAILING_NUMBER_START + 1) * 2) {
218+
> (ADN_DIALING_NUMBER_END - ADN_DIALING_NUMBER_START + 1) * 2) {
205219
Log.w(LOG_TAG,
206-
"[buildAdnString] Max length of dailing number is 20");
207-
} else if (alphaTag.length() > footerOffset) {
220+
"[buildAdnString] Max length of dialing number is 20");
221+
return null;
222+
} else if (alphaTag != null && alphaTag.length() > footerOffset) {
208223
Log.w(LOG_TAG,
209224
"[buildAdnString] Max length of tag is " + footerOffset);
225+
return null;
210226
} else {
211-
212-
adnString = new byte[recordSize];
213-
for (int i = 0; i < recordSize; i++) {
214-
adnString[i] = (byte) 0xFF;
215-
}
216-
217227
bcdNumber = PhoneNumberUtils.numberToCalledPartyBCD(number);
218228

219229
System.arraycopy(bcdNumber, 0, adnString,
@@ -222,16 +232,17 @@ public byte[] buildAdnString(int recordSize) {
222232
adnString[footerOffset + ADN_BCD_NUMBER_LENGTH]
223233
= (byte) (bcdNumber.length);
224234
adnString[footerOffset + ADN_CAPABILITY_ID]
225-
= (byte) 0xFF; // Capacility Id
235+
= (byte) 0xFF; // Capability Id
226236
adnString[footerOffset + ADN_EXTENSION_ID]
227237
= (byte) 0xFF; // Extension Record Id
228238

229-
byteTag = GsmAlphabet.stringToGsm8BitPacked(alphaTag);
230-
System.arraycopy(byteTag, 0, adnString, 0, byteTag.length);
239+
if (!TextUtils.isEmpty(alphaTag)) {
240+
byteTag = GsmAlphabet.stringToGsm8BitPacked(alphaTag);
241+
System.arraycopy(byteTag, 0, adnString, 0, byteTag.length);
242+
}
231243

244+
return adnString;
232245
}
233-
234-
return adnString;
235246
}
236247

237248
/**

telephony/java/com/android/internal/telephony/AdnRecordLoader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public AdnRecordLoader(PhoneBase phone) {
106106
* It will get the record size of EF record and compose hex adn array
107107
* then write the hex array to EF record
108108
*
109-
* @param adn is set with alphaTag and phoneNubmer
109+
* @param adn is set with alphaTag and phone number
110110
* @param ef EF fileid
111111
* @param extensionEF extension EF fileid
112112
* @param recordNumber 1-based record index
@@ -159,7 +159,7 @@ public AdnRecordLoader(PhoneBase phone) {
159159
data = adn.buildAdnString(recordSize[0]);
160160

161161
if(data == null) {
162-
throw new RuntimeException("worong ADN format",
162+
throw new RuntimeException("wrong ADN format",
163163
ar.exception);
164164
}
165165

@@ -218,7 +218,7 @@ public AdnRecordLoader(PhoneBase phone) {
218218
throw new RuntimeException("load failed", ar.exception);
219219
}
220220

221-
Log.d(LOG_TAG,"ADN extention EF: 0x"
221+
Log.d(LOG_TAG,"ADN extension EF: 0x"
222222
+ Integer.toHexString(extensionEF)
223223
+ ":" + adn.extRecord
224224
+ "\n" + IccUtils.bytesToHexString(data));

telephony/java/com/android/internal/telephony/IccProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public int delete(Uri url, String where, String[] whereArgs) {
277277
return 0;
278278
}
279279

280-
if (efType == FDN && TextUtils.isEmpty(pin2)) {
280+
if (efType == IccConstants.EF_FDN && TextUtils.isEmpty(pin2)) {
281281
return 0;
282282
}
283283

0 commit comments

Comments
 (0)