IccProviderpublic class IccProvider extends android.content.ContentProvider
Fields Summary |
---|
private static final String | TAG | private static final boolean | DBG | private static final String[] | ADDRESS_BOOK_COLUMN_NAMES | protected static final int | ADN | protected static final int | ADN_SUB | protected static final int | FDN | protected static final int | FDN_SUB | protected static final int | SDN | protected static final int | SDN_SUB | protected static final int | ADN_ALL | protected static final String | STR_TAG | protected static final String | STR_NUMBER | protected static final String | STR_EMAILS | protected static final String | STR_PIN2 | private static final android.content.UriMatcher | URL_MATCHER | private android.telephony.SubscriptionManager | mSubscriptionManager |
Methods Summary |
---|
private boolean | addIccRecordToEf(int efType, java.lang.String name, java.lang.String number, java.lang.String[] emails, java.lang.String pin2, int subId)
if (DBG) log("addIccRecordToEf: efType=" + efType + ", name=" + name +
", number=" + number + ", emails=" + emails + ", subscription=" + subId);
boolean success = false;
// TODO: do we need to call getAdnRecordsInEf() before calling
// updateAdnRecordsInEfBySearch()? In any case, we will leave
// the UI level logic to fill that prereq if necessary. But
// hopefully, we can remove this requirement.
try {
IIccPhoneBook iccIpb = IIccPhoneBook.Stub.asInterface(
ServiceManager.getService("simphonebook"));
if (iccIpb != null) {
success = iccIpb.updateAdnRecordsInEfBySearchForSubscriber(subId, efType,
"", "", name, number, pin2);
}
} catch (RemoteException ex) {
// ignore it
} catch (SecurityException ex) {
if (DBG) log(ex.toString());
}
if (DBG) log("addIccRecordToEf: " + success);
return success;
| public int | delete(android.net.Uri url, java.lang.String where, java.lang.String[] whereArgs)
int efType;
int subId;
int match = URL_MATCHER.match(url);
switch (match) {
case ADN:
efType = IccConstants.EF_ADN;
subId = SubscriptionManager.getDefaultSubId();
break;
case ADN_SUB:
efType = IccConstants.EF_ADN;
subId = getRequestSubId(url);
break;
case FDN:
efType = IccConstants.EF_FDN;
subId = SubscriptionManager.getDefaultSubId();
break;
case FDN_SUB:
efType = IccConstants.EF_FDN;
subId = getRequestSubId(url);
break;
default:
throw new UnsupportedOperationException(
"Cannot insert into URL: " + url);
}
if (DBG) log("delete");
// parse where clause
String tag = null;
String number = null;
String[] emails = null;
String pin2 = null;
String[] tokens = where.split("AND");
int n = tokens.length;
while (--n >= 0) {
String param = tokens[n];
if (DBG) log("parsing '" + param + "'");
String[] pair = param.split("=");
if (pair.length != 2) {
Rlog.e(TAG, "resolve: bad whereClause parameter: " + param);
continue;
}
String key = pair[0].trim();
String val = pair[1].trim();
if (STR_TAG.equals(key)) {
tag = normalizeValue(val);
} else if (STR_NUMBER.equals(key)) {
number = normalizeValue(val);
} else if (STR_EMAILS.equals(key)) {
//TODO(): Email is null.
emails = null;
} else if (STR_PIN2.equals(key)) {
pin2 = normalizeValue(val);
}
}
if (efType == FDN && TextUtils.isEmpty(pin2)) {
return 0;
}
boolean success = deleteIccRecordFromEf(efType, tag, number, emails, pin2, subId);
if (!success) {
return 0;
}
getContext().getContentResolver().notifyChange(url, null);
return 1;
| private boolean | deleteIccRecordFromEf(int efType, java.lang.String name, java.lang.String number, java.lang.String[] emails, java.lang.String pin2, int subId)
if (DBG) log("deleteIccRecordFromEf: efType=" + efType +
", name=" + name + ", number=" + number + ", emails=" + emails +
", pin2=" + pin2 + ", subscription=" + subId);
boolean success = false;
try {
IIccPhoneBook iccIpb = IIccPhoneBook.Stub.asInterface(
ServiceManager.getService("simphonebook"));
if (iccIpb != null) {
success = iccIpb.updateAdnRecordsInEfBySearchForSubscriber(subId, efType,
name, number, "", "", pin2);
}
} catch (RemoteException ex) {
// ignore it
} catch (SecurityException ex) {
if (DBG) log(ex.toString());
}
if (DBG) log("deleteIccRecordFromEf: " + success);
return success;
| private int | getRequestSubId(android.net.Uri url)
if (DBG) log("getRequestSubId url: " + url);
try {
return Integer.parseInt(url.getLastPathSegment());
} catch (NumberFormatException ex) {
throw new IllegalArgumentException("Unknown URL " + url);
}
| public java.lang.String | getType(android.net.Uri url)
switch (URL_MATCHER.match(url)) {
case ADN:
case ADN_SUB:
case FDN:
case FDN_SUB:
case SDN:
case SDN_SUB:
case ADN_ALL:
return "vnd.android.cursor.dir/sim-contact";
default:
throw new IllegalArgumentException("Unknown URL " + url);
}
| public android.net.Uri | insert(android.net.Uri url, android.content.ContentValues initialValues)
Uri resultUri;
int efType;
String pin2 = null;
int subId;
if (DBG) log("insert");
int match = URL_MATCHER.match(url);
switch (match) {
case ADN:
efType = IccConstants.EF_ADN;
subId = SubscriptionManager.getDefaultSubId();
break;
case ADN_SUB:
efType = IccConstants.EF_ADN;
subId = getRequestSubId(url);
break;
case FDN:
efType = IccConstants.EF_FDN;
subId = SubscriptionManager.getDefaultSubId();
pin2 = initialValues.getAsString("pin2");
break;
case FDN_SUB:
efType = IccConstants.EF_FDN;
subId = getRequestSubId(url);
pin2 = initialValues.getAsString("pin2");
break;
default:
throw new UnsupportedOperationException(
"Cannot insert into URL: " + url);
}
String tag = initialValues.getAsString("tag");
String number = initialValues.getAsString("number");
// TODO(): Read email instead of sending null.
boolean success = addIccRecordToEf(efType, tag, number, null, pin2, subId);
if (!success) {
return null;
}
StringBuilder buf = new StringBuilder("content://icc/");
switch (match) {
case ADN:
buf.append("adn/");
break;
case ADN_SUB:
buf.append("adn/subId/");
break;
case FDN:
buf.append("fdn/");
break;
case FDN_SUB:
buf.append("fdn/subId/");
break;
}
// TODO: we need to find out the rowId for the newly added record
buf.append(0);
resultUri = Uri.parse(buf.toString());
getContext().getContentResolver().notifyChange(url, null);
/*
// notify interested parties that an insertion happened
getContext().getContentResolver().notifyInsert(
resultUri, rowID, null);
*/
return resultUri;
| private android.database.Cursor | loadAllSimContacts(int efType)
Cursor [] result;
List<SubscriptionInfo> subInfoList = mSubscriptionManager.getActiveSubscriptionInfoList();
if ((subInfoList == null) || (subInfoList.size() == 0)) {
result = new Cursor[0];
} else {
int subIdCount = subInfoList.size();
result = new Cursor[subIdCount];
int subId;
for (int i = 0; i < subIdCount; i++) {
subId = subInfoList.get(i).getSubscriptionId();
result[i] = loadFromEf(efType, subId);
Rlog.i(TAG,"ADN Records loaded for Subscription ::" + subId);
}
}
return new MergeCursor(result);
| private android.database.MatrixCursor | loadFromEf(int efType, int subId)
if (DBG) log("loadFromEf: efType=" + efType + ", subscription=" + subId);
List<AdnRecord> adnRecords = null;
try {
IIccPhoneBook iccIpb = IIccPhoneBook.Stub.asInterface(
ServiceManager.getService("simphonebook"));
if (iccIpb != null) {
adnRecords = iccIpb.getAdnRecordsInEfForSubscriber(subId, efType);
}
} catch (RemoteException ex) {
// ignore it
} catch (SecurityException ex) {
if (DBG) log(ex.toString());
}
if (adnRecords != null) {
// Load the results
final int N = adnRecords.size();
final MatrixCursor cursor = new MatrixCursor(ADDRESS_BOOK_COLUMN_NAMES, N);
if (DBG) log("adnRecords.size=" + N);
for (int i = 0; i < N ; i++) {
loadRecord(adnRecords.get(i), cursor, i);
}
return cursor;
} else {
// No results to load
Rlog.w(TAG, "Cannot load ADN records");
return new MatrixCursor(ADDRESS_BOOK_COLUMN_NAMES);
}
| private void | loadRecord(com.android.internal.telephony.uicc.AdnRecord record, android.database.MatrixCursor cursor, int id)Loads an AdnRecord into a MatrixCursor. Must be called with mLock held.
if (!record.isEmpty()) {
Object[] contact = new Object[4];
String alphaTag = record.getAlphaTag();
String number = record.getNumber();
if (DBG) log("loadRecord: " + alphaTag + ", " + number + ",");
contact[0] = alphaTag;
contact[1] = number;
String[] emails = record.getEmails();
if (emails != null) {
StringBuilder emailString = new StringBuilder();
for (String email: emails) {
if (DBG) log("Adding email:" + email);
emailString.append(email);
emailString.append(",");
}
contact[2] = emailString.toString();
}
contact[3] = id;
cursor.addRow(contact);
}
| private void | log(java.lang.String msg)
Rlog.d(TAG, "[IccProvider] " + msg);
| private java.lang.String | normalizeValue(java.lang.String inVal)
int len = inVal.length();
// If name is empty in contact return null to avoid crash.
if (len == 0) {
if (DBG) log("len of input String is 0");
return inVal;
}
String retVal = inVal;
if (inVal.charAt(0) == '\'" && inVal.charAt(len-1) == '\'") {
retVal = inVal.substring(1, len-1);
}
return retVal;
| public boolean | onCreate()
mSubscriptionManager = SubscriptionManager.from(getContext());
return true;
| public android.database.Cursor | query(android.net.Uri url, java.lang.String[] projection, java.lang.String selection, java.lang.String[] selectionArgs, java.lang.String sort)
if (DBG) log("query");
switch (URL_MATCHER.match(url)) {
case ADN:
return loadFromEf(IccConstants.EF_ADN, SubscriptionManager.getDefaultSubId());
case ADN_SUB:
return loadFromEf(IccConstants.EF_ADN, getRequestSubId(url));
case FDN:
return loadFromEf(IccConstants.EF_FDN, SubscriptionManager.getDefaultSubId());
case FDN_SUB:
return loadFromEf(IccConstants.EF_FDN, getRequestSubId(url));
case SDN:
return loadFromEf(IccConstants.EF_SDN, SubscriptionManager.getDefaultSubId());
case SDN_SUB:
return loadFromEf(IccConstants.EF_SDN, getRequestSubId(url));
case ADN_ALL:
return loadAllSimContacts(IccConstants.EF_ADN);
default:
throw new IllegalArgumentException("Unknown URL " + url);
}
| public int | update(android.net.Uri url, android.content.ContentValues values, java.lang.String where, java.lang.String[] whereArgs)
String pin2 = null;
int efType;
int subId;
if (DBG) log("update");
int match = URL_MATCHER.match(url);
switch (match) {
case ADN:
efType = IccConstants.EF_ADN;
subId = SubscriptionManager.getDefaultSubId();
break;
case ADN_SUB:
efType = IccConstants.EF_ADN;
subId = getRequestSubId(url);
break;
case FDN:
efType = IccConstants.EF_FDN;
subId = SubscriptionManager.getDefaultSubId();
pin2 = values.getAsString("pin2");
break;
case FDN_SUB:
efType = IccConstants.EF_FDN;
subId = getRequestSubId(url);
pin2 = values.getAsString("pin2");
break;
default:
throw new UnsupportedOperationException(
"Cannot insert into URL: " + url);
}
String tag = values.getAsString("tag");
String number = values.getAsString("number");
String[] emails = null;
String newTag = values.getAsString("newTag");
String newNumber = values.getAsString("newNumber");
String[] newEmails = null;
// TODO(): Update for email.
boolean success = updateIccRecordInEf(efType, tag, number,
newTag, newNumber, pin2, subId);
if (!success) {
return 0;
}
getContext().getContentResolver().notifyChange(url, null);
return 1;
| private boolean | updateIccRecordInEf(int efType, java.lang.String oldName, java.lang.String oldNumber, java.lang.String newName, java.lang.String newNumber, java.lang.String pin2, int subId)
if (DBG) log("updateIccRecordInEf: efType=" + efType +
", oldname=" + oldName + ", oldnumber=" + oldNumber +
", newname=" + newName + ", newnumber=" + newNumber +
", subscription=" + subId);
boolean success = false;
try {
IIccPhoneBook iccIpb = IIccPhoneBook.Stub.asInterface(
ServiceManager.getService("simphonebook"));
if (iccIpb != null) {
success = iccIpb.updateAdnRecordsInEfBySearchForSubscriber(subId, efType, oldName,
oldNumber, newName, newNumber, pin2);
}
} catch (RemoteException ex) {
// ignore it
} catch (SecurityException ex) {
if (DBG) log(ex.toString());
}
if (DBG) log("updateIccRecordInEf: " + success);
return success;
|
|