summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGao Bing <w20090@motorola.com>2017-05-09 18:24:07 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-05-09 18:24:07 +0000
commitf1adff9eec7aca1ee050996692b557b4e22e0408 (patch)
treec1f2ecc6499a004614b44a0c81f0f930641cb8bf
parent01e835687ead2bc237b90f9e60793b1b849327ac (diff)
parent23dd386f3799603bcb12c52e7a134aa1196a6285 (diff)
downloadims-f1adff9eec7aca1ee050996692b557b4e22e0408.tar.gz
EABService and EABProvider improvement
am: 23dd386f37 Change-Id: I05fe510f50f7a148619f1ea2868c1a1f8a4f2c86
-rw-r--r--rcs/presencepolling/src/com/android/service/ims/presence/AccountUtil.java105
-rw-r--r--rcs/presencepolling/src/com/android/service/ims/presence/AlarmBroadcastReceiver.java7
-rw-r--r--rcs/presencepolling/src/com/android/service/ims/presence/ContactDbUtil.java124
-rw-r--r--rcs/presencepolling/src/com/android/service/ims/presence/Contacts.java15
-rw-r--r--rcs/presencepolling/src/com/android/service/ims/presence/DatabaseContentProvider.java8
-rw-r--r--rcs/presencepolling/src/com/android/service/ims/presence/EABContactManager.java61
-rw-r--r--rcs/presencepolling/src/com/android/service/ims/presence/EABDbUtil.java129
-rw-r--r--rcs/presencepolling/src/com/android/service/ims/presence/EABProvider.java156
-rw-r--r--rcs/presencepolling/src/com/android/service/ims/presence/EABService.java224
-rw-r--r--rcs/presencepolling/src/com/android/service/ims/presence/InvalidDBException.java41
-rw-r--r--rcs/presencepolling/src/com/android/service/ims/presence/PresenceContact.java8
-rw-r--r--rcs/presencepolling/src/com/android/service/ims/presence/SharedPrefUtil.java121
-rw-r--r--rcs/rcsmanager/src/java/com/android/ims/internal/ContactNumberUtils.java47
-rw-r--r--rcs/rcsmanager/src/java/com/android/ims/internal/EABContract.java8
14 files changed, 442 insertions, 612 deletions
diff --git a/rcs/presencepolling/src/com/android/service/ims/presence/AccountUtil.java b/rcs/presencepolling/src/com/android/service/ims/presence/AccountUtil.java
deleted file mode 100644
index 0139f86..0000000
--- a/rcs/presencepolling/src/com/android/service/ims/presence/AccountUtil.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright (c) 2015, Motorola Mobility LLC
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * - Neither the name of Motorola Mobility nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MOTOROLA MOBILITY LLC BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- */
-
-package com.android.service.ims.presence;
-
-import android.accounts.Account;
-import android.accounts.AccountManager;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.os.Bundle;
-import android.provider.ContactsContract;
-import com.android.ims.internal.Logger;
-
-public class AccountUtil {
- private static Logger logger = Logger.getLogger("AccountUtil");
-
- public static final String ACCOUNT_SETTING = "accountSetting";
- public static final String VTCALL_SETTING = "vtcall_enable"; // "vtCallSetting";
- public static final String PRESENCE_SETTING = "presence_enable";// "presenceSetting";
- public static final String ACCOUNT_TYPE = "com.android.rcs.eab.account";
- public static final String AUTHTOKEN_TYPE = "com.android.rcs.eab.account";
- public static final String ACCOUNT_NAME = " ";
-
- public static Account addRcsAccount(Context context) {
- AccountManager mAccountManager = null;
- mAccountManager = AccountManager.get(context);
- Account[] vCallingAccounts = mAccountManager
- .getAccountsByType(ACCOUNT_TYPE);
-
- if (vCallingAccounts.length == 0) {
- logger.debug("Creating Video Calling Account");
-
- Bundle bundle = new Bundle();
- bundle.putString("pretty_name",
- context.getString(R.string.account_pretty_name));
-
- Account vCallingAccount = new Account(ACCOUNT_NAME, ACCOUNT_TYPE);
- if (!mAccountManager.addAccountExplicitly(vCallingAccount, null,
- null)) {
- logger.error("addRcsAccount() failed!");
- return null;
- }
-
- ContentResolver.setIsSyncable(vCallingAccount,
- ContactsContract.AUTHORITY, 0);
- ContentResolver.setSyncAutomatically(vCallingAccount,
- ContactsContract.AUTHORITY, false);
-
- logger.debug("Video Calling account created succesfuly");
- return vCallingAccount;
- } else {
- Account vCallingAccount = new Account(ACCOUNT_NAME, ACCOUNT_TYPE);
- ContentResolver.setIsSyncable(vCallingAccount,
- ContactsContract.AUTHORITY, 0);
-
- ContentResolver.setSyncAutomatically(vCallingAccount,
- ContactsContract.AUTHORITY, false);
- logger.debug("Video Calling Account already exists");
- return vCallingAccount;
- }
- }
-
- public static boolean removeRcsAccount(Context context) {
- logger.debug("removeRcsAccount()");
- AccountManager mAccountManager = null;
- boolean result = false;
- mAccountManager = AccountManager.get(context);
- Account[] vCallingAccounts = mAccountManager
- .getAccountsByType(ACCOUNT_TYPE);
-
- if (vCallingAccounts.length == 0) {
- logger.debug("Video Calling Account is not present. Do nothing.");
- } else {
- Account vCallingAccount = new Account(ACCOUNT_NAME, ACCOUNT_TYPE);
- mAccountManager.removeAccount(vCallingAccount, null, null);
- logger.debug("Video Calling Account removed.");
- }
- return result;
- }
-}
diff --git a/rcs/presencepolling/src/com/android/service/ims/presence/AlarmBroadcastReceiver.java b/rcs/presencepolling/src/com/android/service/ims/presence/AlarmBroadcastReceiver.java
index 1e5c0ef..3d586f5 100644
--- a/rcs/presencepolling/src/com/android/service/ims/presence/AlarmBroadcastReceiver.java
+++ b/rcs/presencepolling/src/com/android/service/ims/presence/AlarmBroadcastReceiver.java
@@ -34,6 +34,7 @@ import android.content.Intent;
import com.android.ims.internal.Logger;
import com.android.service.ims.presence.Contacts;
+import com.android.service.ims.presence.SharedPrefUtil;
public class AlarmBroadcastReceiver extends BroadcastReceiver {
private Logger logger = Logger.getLogger(this.getClass().getName());
@@ -44,6 +45,8 @@ public class AlarmBroadcastReceiver extends BroadcastReceiver {
PollingTask.ACTION_POLLING_RETRY_ALARM;
private static final String ACTION_EAB_NEW_CONTACT_INSERTED =
Contacts.ACTION_NEW_CONTACT_INSERTED;
+ private static final String ACTION_RESET_EAB_DATABASE =
+ Contacts.ACTION_EAB_DATABASE_RESET;
@Override
public void onReceive(Context context, Intent intent) {
@@ -70,6 +73,10 @@ public class AlarmBroadcastReceiver extends BroadcastReceiver {
String number = intent.getStringExtra(Contacts.NEW_PHONE_NUMBER);
capabilityPolling.enqueueNewContact(number);
}
+ } else if (ACTION_RESET_EAB_DATABASE.equals(action)) {
+ // Reset the values in shared preference related to sync
+ // logic as EAB database is re-created.
+ SharedPrefUtil.resetEABSharedPref(context);
} else {
logger.debug("No interest in this intent: " + action);
}
diff --git a/rcs/presencepolling/src/com/android/service/ims/presence/ContactDbUtil.java b/rcs/presencepolling/src/com/android/service/ims/presence/ContactDbUtil.java
index e4f4a21..b93f708 100644
--- a/rcs/presencepolling/src/com/android/service/ims/presence/ContactDbUtil.java
+++ b/rcs/presencepolling/src/com/android/service/ims/presence/ContactDbUtil.java
@@ -46,92 +46,6 @@ import com.android.ims.internal.Logger;
public class ContactDbUtil {
private static Logger logger = Logger.getLogger("ContactDbUtil");
- public static void addVideoCallingContactGroup(Context context, Account vCallingAccount) {
- logger.info("addVideoCallingContactGroup");
- ContentResolver contentResolver = context.getContentResolver();
- if (vCallingAccount == null) {
- logger.error("vCallingAccount == null");
- return;
- }
- long videoCallingGroupId = 0;
- final Cursor cursor = contentResolver.query(Groups.CONTENT_URI,
- new String[] { Groups._ID },
- Groups.ACCOUNT_NAME + "=? AND " + Groups.ACCOUNT_TYPE + "=? AND " +
- Groups.TITLE + "=?",
- new String[] { AccountUtil.ACCOUNT_NAME, AccountUtil.ACCOUNT_TYPE,
- context.getString(R.string.video_calling_contact_group) }, null);
- if (cursor != null) {
- try {
- if (cursor.moveToFirst()) {
- videoCallingGroupId = cursor.getLong(0);
- }
- } finally {
- cursor.close();
- }
- }
- if (videoCallingGroupId == 0) {
- logger.debug("addVideoCallingContactGroup, creating group");
-
- // Video Calling group doesn't exist yet, so create it
- final ContentValues contentValues = new ContentValues();
- contentValues.put(Groups.ACCOUNT_NAME, AccountUtil.ACCOUNT_NAME);
- contentValues.put(Groups.ACCOUNT_TYPE, AccountUtil.ACCOUNT_TYPE);
- contentValues.put(Groups.TITLE, context.getString(R.string.video_calling_contact_group));
- contentValues.put(Groups.GROUP_IS_READ_ONLY, 1);
- contentValues.put(Groups.GROUP_VISIBLE, 1);
- contentValues.put(Groups.SYSTEM_ID, "com.android.vt.eab");
-
- final Uri newGroupUri = contentResolver.insert(Groups.CONTENT_URI, contentValues);
- if (null != newGroupUri) {
- videoCallingGroupId = ContentUris.parseId(newGroupUri);
- } else {
- logger.error("newGroupUri is null.");
- }
- } else {
- logger.debug("addVideoCallingContactGroup, Video Calling Group, already exists!!!");
-
- }
-
- logger.debug("videoCallingGroupId: " + videoCallingGroupId);
- SharedPrefUtil.setVideoCallingGroupId(context, videoCallingGroupId);
- }
-
- public static void removeVideoCallingContactGroup(Context context) {
- logger.debug("removeVideoCallingContactGroup");
- long storedVideoCallingGroupId = SharedPrefUtil.getVideoCallingGroupId(context);
- long videoCallingGroupId = 0;
- ContentResolver contentResolver = context.getContentResolver();
- final Cursor cursor = contentResolver.query(Groups.CONTENT_URI,
- new String[] { Groups._ID },
- Groups.ACCOUNT_NAME + "=? AND " + Groups.ACCOUNT_TYPE + "=? AND " +
- Groups.TITLE + "=?",
- new String[] { AccountUtil.ACCOUNT_NAME, AccountUtil.ACCOUNT_TYPE,
- context.getString(R.string.video_calling_contact_group) }, null);
- if (cursor != null) {
- try {
- if (cursor.moveToFirst()) {
- videoCallingGroupId = cursor.getLong(0);
- }
- } finally {
- cursor.close();
- }
- }
- logger.debug("videoCallingGroupId : " + videoCallingGroupId);
- logger.debug("storedVideoCallingGroupId : " + storedVideoCallingGroupId);
- if (videoCallingGroupId == 0) {
- logger.debug("videoCallingGroupId : " + videoCallingGroupId +
- " not present. Do nothing. ");
- } else {
- if (storedVideoCallingGroupId == videoCallingGroupId) {
- String deleteWhereClause = Groups._ID + "='" + videoCallingGroupId + "'";
- contentResolver.delete(Groups.CONTENT_URI, deleteWhereClause, null);
- logger.debug("Removing Video Calling Group.");
- }
- SharedPrefUtil.setVideoCallingGroupId(context, 0);
- }
- logger.debug("videoCallingGroupId: " + videoCallingGroupId);
- }
-
public static int resetVtCapability(ContentResolver resolver) {
if(resolver == null) {
logger.error("resetVtCapability, resolver = null");
@@ -147,44 +61,6 @@ public class ContactDbUtil {
return count;
}
- public static int updateVtCapability(ContentResolver resolver, String number, boolean enable) {
- String[] projection = new String[] {EABContract.EABColumns.DATA_ID};
-
- int updatedCount = 0;
- Cursor cursor = null;
- try {
- cursor = resolver.query(Contacts.Impl.CONTENT_URI,
- projection, "PHONE_NUMBERS_EQUAL(contact_number, ?, 0)",
- new String[] {number}, null);
- if(null != cursor) {
- int count = cursor.getCount();
- logger.debug("updateVtCapability to Contact DB, count=" + count);
- if(count <= 0) {
- logger.error("updateVtCapability, no number to be updated");
- cursor.close();
- cursor = null;
- return updatedCount;
- }
-
- while(cursor.moveToNext()) {
- long dataId = cursor.getLong(cursor.getColumnIndex(
- EABContract.EABColumns.DATA_ID));
- // update one by one to avoid loosing matching error.
- updatedCount += updateVtCapability(resolver, dataId, enable);
- }
- }
- } catch (Exception e) {
- logger.error("updateVtCapability exception", e);
- } finally {
- if(cursor != null) {
- cursor.close();
- }
- }
-
- logger.debug("updateVtCapability updatedCount=" + updatedCount);
- return updatedCount;
- }
-
public static int updateVtCapability(ContentResolver resolver, long dataId, boolean enable) {
if(resolver == null) {
logger.error("resetVtCapability, resolver = null");
diff --git a/rcs/presencepolling/src/com/android/service/ims/presence/Contacts.java b/rcs/presencepolling/src/com/android/service/ims/presence/Contacts.java
index cbad25a..588edfd 100644
--- a/rcs/presencepolling/src/com/android/service/ims/presence/Contacts.java
+++ b/rcs/presencepolling/src/com/android/service/ims/presence/Contacts.java
@@ -47,6 +47,12 @@ public final class Contacts {
"android.provider.rcs.eab.EAB_NEW_CONTACT_INSERTED";
/**
+ * Intent that EAB database is reset.
+ */
+ public static final String ACTION_EAB_DATABASE_RESET =
+ "android.provider.rcs.eab.EAB_DATABASE_RESET";
+
+ /**
* Key to bundle the new phone number inserted in EAB Provider.
*/
public static final String NEW_PHONE_NUMBER = "newPhoneNumber";
@@ -77,6 +83,15 @@ public final class Contacts {
* Type: TEXT
* </P>
*/
+ public static final String FORMATTED_NUMBER =
+ EABContract.EABColumns.FORMATTED_NUMBER;
+
+ /**
+ * Key defining the contact number.
+ * <P>
+ * Type: TEXT
+ * </P>
+ */
public static final String CONTACT_NUMBER =
EABContract.EABColumns.CONTACT_NUMBER;
diff --git a/rcs/presencepolling/src/com/android/service/ims/presence/DatabaseContentProvider.java b/rcs/presencepolling/src/com/android/service/ims/presence/DatabaseContentProvider.java
index 0ae9bc9..1872a58 100644
--- a/rcs/presencepolling/src/com/android/service/ims/presence/DatabaseContentProvider.java
+++ b/rcs/presencepolling/src/com/android/service/ims/presence/DatabaseContentProvider.java
@@ -161,8 +161,8 @@ public abstract class DatabaseContentProvider extends ContentProvider {
public synchronized SQLiteDatabase getWritableDatabase() {
try {
return super.getWritableDatabase();
- } catch (InvalidDBException e) {
- logger.error("getWritableDatabase - caught InvalidDBException ");
+ } catch (Exception e) {
+ logger.error("getWritableDatabase exception " + e);
}
// try to delete the database file
@@ -179,8 +179,8 @@ public abstract class DatabaseContentProvider extends ContentProvider {
public synchronized SQLiteDatabase getReadableDatabase() {
try {
return super.getReadableDatabase();
- } catch (InvalidDBException e) {
- logger.error("getReadableDatabase - caught InvalidDBException ");
+ } catch (Exception e) {
+ logger.error("getReadableDatabase exception " + e);
}
// try to delete the database file
diff --git a/rcs/presencepolling/src/com/android/service/ims/presence/EABContactManager.java b/rcs/presencepolling/src/com/android/service/ims/presence/EABContactManager.java
index 5b42a6f..f97df19 100644
--- a/rcs/presencepolling/src/com/android/service/ims/presence/EABContactManager.java
+++ b/rcs/presencepolling/src/com/android/service/ims/presence/EABContactManager.java
@@ -41,6 +41,8 @@ import android.net.Uri;
import android.text.format.Time;
import android.text.TextUtils;
+import com.android.ims.internal.EABContract;
+import com.android.ims.internal.ContactNumberUtils;
import com.android.ims.RcsPresenceInfo;
import com.android.ims.internal.Logger;
@@ -86,6 +88,20 @@ public class EABContactManager {
};
/**
+ * Look up the formatted number and Data ID
+ */
+ private static final String[] DATA_QUERY_PROJECTION = new String[] {
+ Contacts.Impl._ID,
+ Contacts.Impl.FORMATTED_NUMBER,
+ EABContract.EABColumns.DATA_ID
+ };
+ // Data Query Columns, which match the DATA_QUERY_PROJECTION
+ private static final int DATA_QUERY_ID = 0;
+ private static final int DATA_QUERY_FORMATTED_NUMBER = 1;
+ private static final int DATA_QUERY_DATA_ID = 2;
+
+
+ /**
* This class contains all the information necessary to request a new contact.
*/
public static class Request {
@@ -135,7 +151,7 @@ public class EABContactManager {
public Request(String number) {
if (TextUtils.isEmpty(number)) {
throw new IllegalArgumentException(
- "Can't update EAB presence item with");
+ "Can't update EAB presence item with number: " + number);
}
mContactNumber = number;
@@ -706,6 +722,7 @@ public class EABContactManager {
null, null);
}
+ logger.debug("Update contact " + number + " with request: " + values);
return mResolver.update(mBaseUri, values, getWhereClauseForIds(ids),
getWhereArgsForIds(ids));
}
@@ -912,17 +929,43 @@ public class EABContactManager {
}
int count = 0;
+ Cursor cursor = null;
try{
- count = ContactDbUtil.updateVtCapability(mResolver, number,
- (videoCallCapability == RcsPresenceInfo.ServiceState.ONLINE));
- logger.print("update rcsPresenceInfo to Contact DB, count=" + count);
+ cursor = mResolver.query(Contacts.Impl.CONTENT_URI, DATA_QUERY_PROJECTION,
+ "PHONE_NUMBERS_EQUAL(" + Contacts.Impl.FORMATTED_NUMBER + ", ?, 1)",
+ new String[] {number}, null);
+ if(cursor == null) {
+ logger.print("update rcsPresenceInfo to DB: update count=" + count);
+ return count;
+ }
+
+ ContactNumberUtils contactNumberUtils = ContactNumberUtils.getDefault();
+ for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
+ String numberInDB = cursor.getString(DATA_QUERY_FORMATTED_NUMBER);
+ logger.debug("number=" + number + " numberInDB=" + numberInDB +
+ " formatedNumber in DB=" + contactNumberUtils.format(numberInDB));
+ if(number.equals(contactNumberUtils.format(numberInDB))) {
+ count = ContactDbUtil.updateVtCapability(mResolver,
+ cursor.getLong(DATA_QUERY_DATA_ID),
+ (videoCallCapability == RcsPresenceInfo.ServiceState.ONLINE));
+ logger.print("update rcsPresenceInfo to Contact DB, count=" + count);
+
+ int id = cursor.getInt(DATA_QUERY_ID);
+ count += mResolver.update(Contacts.Impl.CONTENT_URI, values,
+ Contacts.Impl._ID + "=" + id, null);
+ logger.debug("count=" + count);
+ }
+ }
- count = mResolver.update(Contacts.Impl.CONTENT_URI, values,
- "PHONE_NUMBERS_EQUAL(contact_number, ?, 0)", new String[] {number});
- logger.print("update rcsPresenceInfo to EAB: update count=" + count +
+ logger.print("update rcsPresenceInfo to DB: update count=" + count +
" rcsPresenceInfo=" + rcsPresenceInfo);
- }catch(Exception e){
- logger.error("updateCapability exception", e);
+ } catch(Exception e){
+ logger.error("updateCapability exception");
+ } finally {
+ if(cursor != null) {
+ cursor.close();
+ cursor = null;
+ }
}
return count;
diff --git a/rcs/presencepolling/src/com/android/service/ims/presence/EABDbUtil.java b/rcs/presencepolling/src/com/android/service/ims/presence/EABDbUtil.java
index 64d7343..02285f3 100644
--- a/rcs/presencepolling/src/com/android/service/ims/presence/EABDbUtil.java
+++ b/rcs/presencepolling/src/com/android/service/ims/presence/EABDbUtil.java
@@ -28,9 +28,8 @@
package com.android.service.ims.presence;
-import static com.android.service.ims.presence.AccountUtil.ACCOUNT_TYPE;
-
import java.util.ArrayList;
+import java.util.LinkedHashMap;
import java.util.List;
import android.content.ContentProviderOperation;
@@ -45,6 +44,7 @@ import android.provider.ContactsContract;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.CommonDataKinds.Phone;
+import android.text.TextUtils;
import com.android.ims.internal.ContactNumberUtils;
import com.android.ims.internal.EABContract;
@@ -52,6 +52,7 @@ import com.android.ims.internal.Logger;
public class EABDbUtil {
static private Logger logger = Logger.getLogger("EABDbUtil");
+ public static final String ACCOUNT_TYPE = "com.android.rcs.eab.account";
public static boolean validateAndSyncFromContactsDb(Context context) {
logger.debug("Enter validateAndSyncFromContactsDb");
@@ -60,7 +61,8 @@ public class EABDbUtil {
long contactLastChange = SharedPrefUtil.getLastContactChangedTimestamp(context, 0);
logger.debug("contact last updated time before init :" + contactLastChange);
ContentResolver contentResolver = context.getContentResolver();
- String[] projection = new String[] { ContactsContract.Contacts._ID,
+ String[] projection = new String[] {
+ ContactsContract.Contacts._ID,
ContactsContract.Contacts.HAS_PHONE_NUMBER,
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Contacts.CONTACT_LAST_UPDATED_TIMESTAMP };
@@ -68,8 +70,13 @@ public class EABDbUtil {
+ ContactsContract.Contacts.CONTACT_LAST_UPDATED_TIMESTAMP
+ " >'" + contactLastChange + "'";
String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " asc";
- Cursor cursor = contentResolver.query(Contacts.CONTENT_URI, projection, selection,
- null, sortOrder);
+ Cursor cursor = null;
+ try {
+ cursor = contentResolver.query(Contacts.CONTENT_URI, projection, selection,
+ null, sortOrder);
+ } catch (Exception e) {
+ logger.error("validateAndSyncFromContactsDb() cursor exception:", e);
+ }
ArrayList<PresenceContact> allEligibleContacts = new ArrayList<PresenceContact>();
if (cursor != null) {
@@ -88,22 +95,29 @@ public class EABDbUtil {
contactLastChange = time;
}
String[] commonDataKindsProjection = new String[] {
+ ContactsContract.CommonDataKinds.Phone._ID,
ContactsContract.CommonDataKinds.Phone.NUMBER,
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.RAW_CONTACT_ID,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID };
- Cursor pCur = contentResolver.query(
- ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
- commonDataKindsProjection,
- ContactsContract.CommonDataKinds.Phone.CONTACT_ID
- + " = ?", new String[] { id }, null);
+ Cursor pCur = null;
+ try {
+ pCur = contentResolver.query(
+ ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
+ commonDataKindsProjection,
+ ContactsContract.CommonDataKinds.Phone.CONTACT_ID
+ + " = ?", new String[] { id }, null);
+ } catch (Exception e) {
+ logger.error("validateAndSyncFromContactsDb() pCur exception:", e);
+ }
+ // ArrayList to avoid duplicate entries of contactNumber having same
+ // contactId, rawContactId and dataId.
ArrayList<String> phoneNumList = new ArrayList<String>();
if (pCur != null && pCur.moveToFirst()) {
do {
String contactNumber = pCur.getString(pCur.getColumnIndex(
ContactsContract.CommonDataKinds.Phone.NUMBER));
- //contactNumber = filterEligibleContact(context, pContactNumber);
if (validateEligibleContact(context, contactNumber)) {
String contactName = pCur.getString(pCur.getColumnIndex(
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
@@ -111,18 +125,21 @@ public class EABDbUtil {
ContactsContract.CommonDataKinds.Phone.RAW_CONTACT_ID));
String contactId = pCur.getString(pCur.getColumnIndex(
ContactsContract.CommonDataKinds.Phone.CONTACT_ID));
- // TODO: HACK - To be resolved as part of EAB Provider rework.
- if (phoneNumList.contains(contactNumber)) continue;
- phoneNumList.add(contactNumber);
+ String dataId = pCur.getString(pCur.getColumnIndex(
+ ContactsContract.CommonDataKinds.Phone._ID));
+ String formattedNumber = formatNumber(contactNumber);
+ String uniquePhoneNum = formattedNumber + contactId
+ + rawContactId + dataId;
+ logger.debug("uniquePhoneNum : " + uniquePhoneNum);
+ if (phoneNumList.contains(uniquePhoneNum)) continue;
+ phoneNumList.add(uniquePhoneNum);
- String dataId = getDataId(contentResolver,rawContactId, contactNumber);
- if (null != dataId) {
- allEligibleContacts.add(new PresenceContact(contactName,
- contactNumber, rawContactId, contactId, dataId));
- } else {
- logger.debug("dataId is null. Don't add contact to " +
- "allEligibleContacts.");
- }
+ allEligibleContacts.add(new PresenceContact(contactName, contactNumber,
+ rawContactId, contactId, dataId, formattedNumber));
+ logger.debug("Eligible List Name: " + contactName +
+ " Number:" + contactNumber + " RawContactID: " + rawContactId +
+ " contactId: " + contactId + " Data.ID : " + dataId
+ + " formattedNumber: " + formattedNumber);
}
} while (pCur.moveToNext());
}
@@ -147,31 +164,6 @@ public class EABDbUtil {
return response;
}
- private static String getDataId(ContentResolver contentResolver,
- String rawContactId, String pContactNumber) {
- String dataId = null;
- String where = Data.RAW_CONTACT_ID + " = '" + rawContactId + "' AND "
- + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'"
- + " AND " + Data.DATA1 + "='" + pContactNumber + "'";
- Cursor cur = null;
- try {
- cur = contentResolver.query(Data.CONTENT_URI,
- new String[] { Data._ID }, where, null, null);
- if (cur.moveToFirst()) {
- dataId = cur.getString(cur.getColumnIndex(Data._ID));
- }
- } catch (SQLiteException e) {
- logger.debug("SQLiteException while querying for dataId : " + e.toString());
- } catch (Exception e) {
- logger.debug("Exception while querying for dataId : " + e);
- } finally {
- if (null != cur) {
- cur.close();
- }
- }
- return dataId;
- }
-
public static void addContactsToEabDb(Context context,
ArrayList<PresenceContact> contactList) {
ArrayList<ContentProviderOperation> operation = new ArrayList<ContentProviderOperation>();
@@ -183,8 +175,9 @@ public class EABDbUtil {
int yieldPoint = 300;
for (int j = 0; j < contactList.size(); j++) {
addContactToEabDb(context, operation, contactList.get(j).getDisplayName(),
- contactList.get(j).getPhoneNumber(), contactList.get(j).getRawContactId(),
- contactList.get(j).getContactId(), contactList.get(j).getDataId());
+ contactList.get(j).getPhoneNumber(), contactList.get(j).getFormattedNumber(),
+ contactList.get(j).getRawContactId(), contactList.get(j).getContactId(),
+ contactList.get(j).getDataId());
if (yieldPoint == j) {
exceuteDB(context, operation);
operation = null;
@@ -197,12 +190,13 @@ public class EABDbUtil {
private static void addContactToEabDb(
Context context, ArrayList<ContentProviderOperation> ops, String displayName,
- String phoneNumber, String rawContactId, String contactId,
+ String phoneNumber, String formattedNumber, String rawContactId, String contactId,
String dataId) {
ops.add(ContentProviderOperation
.newInsert(EABContract.EABColumns.CONTENT_URI)
.withValue(EABContract.EABColumns.CONTACT_NAME, displayName)
.withValue(EABContract.EABColumns.CONTACT_NUMBER, phoneNumber)
+ .withValue(EABContract.EABColumns.FORMATTED_NUMBER, formattedNumber)
.withValue(EABContract.EABColumns.ACCOUNT_TYPE, ACCOUNT_TYPE)
.withValue(EABContract.EABColumns.RAW_CONTACT_ID, rawContactId)
.withValue(EABContract.EABColumns.CONTACT_ID, contactId)
@@ -318,8 +312,8 @@ public class EABDbUtil {
if (count > 0) {
ops.add(ContentProviderOperation.newDelete(EABContract.EABColumns.CONTENT_URI)
.withSelection(EABContract.EABColumns.RAW_CONTACT_ID + " = ? AND "
- + EABContract.EABColumns.DATA_ID + " = ?",
- new String[] { rawContactId, dataId }).build());
+ + EABContract.EABColumns.DATA_ID + " = ?",
+ new String[]{rawContactId, dataId}).build());
}
eabDeleteCursor.close();
}
@@ -402,28 +396,25 @@ public class EABDbUtil {
if ( ContactNumberUtils.NUMBER_VALID == numberType) {
number = true;
}
+ logger.debug("Exiting validateEligibleContact with value : " + number);
return number;
}
- public static String filterEligibleContact(Context context, String mdn) {
- String number = null;
- if (null == mdn) {
- logger.debug("filterEligibleContact - mdn is null.");
- return number;
- }
- logger.debug("Before filterEligibleContact validation : " + mdn);
- List<String> mdbList = new ArrayList<String>();
- mdbList.add(mdn);
+ public static String formatNumber(String mdn) {
+ logger.debug("Enter FormatNumber - mdn : " + mdn);
ContactNumberUtils mNumberUtils = ContactNumberUtils.getDefault();
- mNumberUtils.setContext(context);
- int numberType = mNumberUtils.validate(mdbList);
- logger.debug("ContactNumberUtils.validate response : " + numberType);
- if ( ContactNumberUtils.NUMBER_VALID == numberType) {
- String[] mdnFormatted = mNumberUtils.format(mdbList);
- if (mdnFormatted.length > 0 ){
- number = mdnFormatted[0];
+ return mNumberUtils.format(mdn);
+ }
+
+ public static boolean isSpecialNumber(String number) {
+ logger.debug("Enter isSpecialNumber - number : " + number);
+ boolean result = false;
+ if (null != number) {
+ if (number.startsWith("*67") || number.startsWith("*82")) {
+ result = true;
}
}
- return number;
+ logger.debug("Exit isSpecialNumber - result : " + result);
+ return result;
}
}
diff --git a/rcs/presencepolling/src/com/android/service/ims/presence/EABProvider.java b/rcs/presencepolling/src/com/android/service/ims/presence/EABProvider.java
index 8d2acd0..66bf4ff 100644
--- a/rcs/presencepolling/src/com/android/service/ims/presence/EABProvider.java
+++ b/rcs/presencepolling/src/com/android/service/ims/presence/EABProvider.java
@@ -44,6 +44,7 @@ import android.provider.BaseColumns;
import android.provider.ContactsContract.Contacts;
import android.content.ComponentName;
+import com.android.ims.internal.ContactNumberUtils;
import com.android.ims.RcsPresenceInfo;
import com.android.ims.internal.EABContract;
import com.android.ims.internal.Logger;
@@ -57,7 +58,7 @@ public class EABProvider extends DatabaseContentProvider{
private static final String EAB_DB_NAME = "rcseab.db";
- private static final int EAB_DB_VERSION = 2;
+ private static final int EAB_DB_VERSION = 3;
private static final int EAB_TABLE = 1;
@@ -81,9 +82,9 @@ public class EABProvider extends DatabaseContentProvider{
+ EABContract.EABColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ EABContract.EABColumns.CONTACT_NAME + " TEXT, "
+ EABContract.EABColumns.CONTACT_NUMBER + " TEXT, "
- + EABContract.EABColumns.RAW_CONTACT_ID + " TEXT, "
- + EABContract.EABColumns.CONTACT_ID + " TEXT, "
- + EABContract.EABColumns.DATA_ID + " TEXT, "
+ + EABContract.EABColumns.RAW_CONTACT_ID + " LONG, "
+ + EABContract.EABColumns.CONTACT_ID + " LONG, "
+ + EABContract.EABColumns.DATA_ID + " LONG, "
+ EABContract.EABColumns.ACCOUNT_TYPE + " TEXT, "
+ EABContract.EABColumns.VOLTE_CALL_SERVICE_CONTACT_ADDRESS + " TEXT, "
+ EABContract.EABColumns.VOLTE_CALL_CAPABILITY + " INTEGER, "
@@ -119,11 +120,11 @@ public class EABProvider extends DatabaseContentProvider{
*/
@Override
public boolean upgradeDatabase(SQLiteDatabase db, int oldVersion, int newVersion) {
- logger.debug("Enter: upgradeDatabase() - oldVersion = " + oldVersion +
+ logger.info("Enter: upgradeDatabase() - oldVersion = " + oldVersion +
" newVersion = " + newVersion);
if (oldVersion == newVersion) {
- logger.debug("upgradeDatabase oldVersion == newVersion, No Upgrade Required");
+ logger.info("upgradeDatabase oldVersion == newVersion, No Upgrade Required");
return true;
}
@@ -141,26 +142,49 @@ public class EABProvider extends DatabaseContentProvider{
oldVersion++;
logger.debug("upgradeDatabase : DB has been upgraded to " + oldVersion);
}
+ if (oldVersion == 2) {
+ // Add new column to EABPresence table to handle special numbers *67 and *82.
+ addColumn(db, EABContract.EABColumns.TABLE_NAME,
+ EABContract.EABColumns.FORMATTED_NUMBER, "TEXT DEFAULT NULL");
+
+ // Delete all records from EABPresence table.
+ db.execSQL("DELETE FROM " + EABContract.EABColumns.TABLE_NAME);
+ sendEabResetBroadcast();
+
+ oldVersion++;
+ logger.debug("upgradeDatabase : DB has been upgraded to " + oldVersion);
+ }
+ // add further upgrade code above this
} catch (SQLException exception) {
logger.error("Exception during upgradeDatabase. " + exception.getMessage());
- // DB file had problem
- throw new InvalidDBException();
+ // If exception occured during upgrade database, then drop EABPresence
+ // and recreate it. Please note in this case, all information stored in
+ // table is lost.
+ db.execSQL(EAB_DROP_STATEMENT);
+ upgradeDatabase(db, 0, EAB_DB_VERSION);
+ sendEabResetBroadcast();
+ logger.debug("Dropped and created new EABPresence table.");
}
- // add further upgrade code above this
if (oldVersion == newVersion) {
logger.debug("DB upgrade complete : to " + newVersion);
}
- logger.debug("Exit: upgradeDatabase()");
+ logger.info("Exit: upgradeDatabase()");
return true;
}
@Override
protected boolean downgradeDatabase(SQLiteDatabase db, int oldVersion, int newVersion) {
- // throwing the custom created Exception to catch it in
- // getWritableDatabase or getReadableDatabase
- throw new InvalidDBException();
+ logger.info("Enter: downgradeDatabase()");
+ // Drop and recreate EABPresence table as there should not be a scenario
+ // where EAB table version is greater than EAB_DB_VERSION.
+ db.execSQL(EAB_DROP_STATEMENT);
+ upgradeDatabase(db, 0, EAB_DB_VERSION);
+ sendEabResetBroadcast();
+ logger.debug("Dropped and created new EABPresence table.");
+ logger.info("Exit: downgradeDatabase()");
+ return true;
}
@Override
@@ -350,17 +374,31 @@ public class EABProvider extends DatabaseContentProvider{
getContext().sendBroadcast(intent);
}
+ private void sendEabResetBroadcast() {
+ logger.info("Enter: sendEabResetBroadcast()");
+ Intent intent = new Intent(com.android.service.ims.presence.Contacts
+ .ACTION_EAB_DATABASE_RESET);
+ ComponentName component = new ComponentName("com.android.service.ims.presence",
+ "com.android.service.ims.presence.AlarmBroadcastReceiver");
+ intent.setComponent(component);
+ getContext().sendBroadcast(intent);
+ }
+
private ContentValues verifyIfMdnExists(ContentValues cvalues) {
+ String formattedNumber = null;
String phoneNumber = null;
- if (cvalues.containsKey(EABContract.EABColumns.CONTACT_NUMBER)) {
+ if (cvalues.containsKey(EABContract.EABColumns.CONTACT_NUMBER)
+ && cvalues.containsKey(EABContract.EABColumns.FORMATTED_NUMBER)) {
phoneNumber = cvalues.getAsString(EABContract.EABColumns.CONTACT_NUMBER);
+ formattedNumber = cvalues.getAsString(EABContract.EABColumns.FORMATTED_NUMBER);
} else {
return cvalues;
}
- if (null == phoneNumber) {
+ if (null == formattedNumber) {
return cvalues;
}
String[] projection = new String[] {
+ EABContract.EABColumns.FORMATTED_NUMBER,
EABContract.EABColumns.VOLTE_CALL_SERVICE_CONTACT_ADDRESS,
EABContract.EABColumns.VOLTE_CALL_CAPABILITY,
EABContract.EABColumns.VOLTE_CALL_CAPABILITY_TIMESTAMP,
@@ -371,42 +409,59 @@ public class EABProvider extends DatabaseContentProvider{
EABContract.EABColumns.VIDEO_CALL_CAPABILITY_TIMESTAMP,
EABContract.EABColumns.VIDEO_CALL_AVAILABILITY,
EABContract.EABColumns.VIDEO_CALL_AVAILABILITY_TIMESTAMP};
- String whereClause = "PHONE_NUMBERS_EQUAL(" +
- EABContract.EABColumns.CONTACT_NUMBER + ", ?, 0)";
- String[] selectionArgs = new String[] { phoneNumber };
+ String whereClause = "PHONE_NUMBERS_EQUAL("
+ + EABContract.EABColumns.FORMATTED_NUMBER + ", ?, 0)";
+ String[] selectionArgs = new String[] { formattedNumber };
Cursor cursor = getContext().getContentResolver().query(EABContract.EABColumns.CONTENT_URI,
- projection, whereClause, selectionArgs, null);
+ projection, whereClause, selectionArgs, null);
if ((null != cursor) && (cursor.getCount() > 0)) {
- logger.error("Inserting another copy of MDN to EAB DB.");
- // Update data only from first cursor element.
- cursor.moveToNext();
- cvalues.put(EABContract.EABColumns.VOLTE_CALL_SERVICE_CONTACT_ADDRESS,
- cursor.getString(cursor.
- getColumnIndex(EABContract.EABColumns.VOLTE_CALL_SERVICE_CONTACT_ADDRESS)));
- cvalues.put(EABContract.EABColumns.VOLTE_CALL_CAPABILITY, cursor.getString(cursor
- .getColumnIndex(EABContract.EABColumns.VOLTE_CALL_CAPABILITY)));
- cvalues.put(EABContract.EABColumns.VOLTE_CALL_CAPABILITY_TIMESTAMP,
- cursor.getLong(cursor
- .getColumnIndex(EABContract.EABColumns.VOLTE_CALL_CAPABILITY_TIMESTAMP)));
- cvalues.put(EABContract.EABColumns.VOLTE_CALL_AVAILABILITY, cursor.getString(cursor
- .getColumnIndex(EABContract.EABColumns.VOLTE_CALL_AVAILABILITY)));
- cvalues.put(EABContract.EABColumns.VOLTE_CALL_AVAILABILITY_TIMESTAMP,
- cursor.getLong(cursor
- .getColumnIndex(EABContract.EABColumns.VOLTE_CALL_AVAILABILITY_TIMESTAMP)));
- cvalues.put(EABContract.EABColumns.VIDEO_CALL_SERVICE_CONTACT_ADDRESS,
- cursor.getString(cursor
- .getColumnIndex(EABContract.EABColumns.VIDEO_CALL_SERVICE_CONTACT_ADDRESS)));
- cvalues.put(EABContract.EABColumns.VIDEO_CALL_CAPABILITY, cursor.getString(cursor
- .getColumnIndex(EABContract.EABColumns.VIDEO_CALL_CAPABILITY)));
- cvalues.put(EABContract.EABColumns.VIDEO_CALL_CAPABILITY_TIMESTAMP,
- cursor.getLong(cursor
- .getColumnIndex(EABContract.EABColumns.VIDEO_CALL_CAPABILITY_TIMESTAMP)));
- cvalues.put(EABContract.EABColumns.VIDEO_CALL_AVAILABILITY, cursor.getString(cursor
- .getColumnIndex(EABContract.EABColumns.VIDEO_CALL_AVAILABILITY)));
- cvalues.put(EABContract.EABColumns.VIDEO_CALL_AVAILABILITY_TIMESTAMP,
- cursor.getLong(cursor
- .getColumnIndex(EABContract.EABColumns.VIDEO_CALL_AVAILABILITY_TIMESTAMP)));
- cvalues.put(EABContract.EABColumns.CONTACT_LAST_UPDATED_TIMESTAMP, 0);
+ logger.debug("Cursor count is " + cursor.getCount());
+ // Update data only from first valid cursor element.
+ while (cursor.moveToNext()) {
+ ContactNumberUtils contactNumberUtils = ContactNumberUtils.getDefault();
+ String eabFormattedNumber = cursor.getString(
+ cursor.getColumnIndex(EABContract.EABColumns.FORMATTED_NUMBER));
+
+ // Use contactNumberUtils.format() to format both formattedNumber and
+ // eabFormattedNumber and then check if they are equal.
+ if(contactNumberUtils.format(formattedNumber).equals(
+ contactNumberUtils.format(eabFormattedNumber))) {
+ logger.debug("phoneNumber : "+ phoneNumber +" is already stored in EAB DB. "
+ + " Hence inserting another copy.");
+ cvalues.put(EABContract.EABColumns.VOLTE_CALL_SERVICE_CONTACT_ADDRESS,
+ cursor.getString(cursor.getColumnIndex(
+ EABContract.EABColumns.VOLTE_CALL_SERVICE_CONTACT_ADDRESS)));
+ cvalues.put(EABContract.EABColumns.VOLTE_CALL_CAPABILITY, cursor.getString(
+ cursor.getColumnIndex(
+ EABContract.EABColumns.VOLTE_CALL_CAPABILITY)));
+ cvalues.put(EABContract.EABColumns.VOLTE_CALL_CAPABILITY_TIMESTAMP,
+ cursor.getLong(cursor.getColumnIndex(
+ EABContract.EABColumns.VOLTE_CALL_CAPABILITY_TIMESTAMP)));
+ cvalues.put(EABContract.EABColumns.VOLTE_CALL_AVAILABILITY,
+ cursor.getString(cursor.getColumnIndex(
+ EABContract.EABColumns.VOLTE_CALL_AVAILABILITY)));
+ cvalues.put(EABContract.EABColumns.VOLTE_CALL_AVAILABILITY_TIMESTAMP,
+ cursor.getLong(cursor.getColumnIndex(
+ EABContract.EABColumns.VOLTE_CALL_AVAILABILITY_TIMESTAMP)));
+ cvalues.put(EABContract.EABColumns.VIDEO_CALL_SERVICE_CONTACT_ADDRESS,
+ cursor.getString(cursor.getColumnIndex(
+ EABContract.EABColumns.VIDEO_CALL_SERVICE_CONTACT_ADDRESS)));
+ cvalues.put(EABContract.EABColumns.VIDEO_CALL_CAPABILITY,
+ cursor.getString(cursor.getColumnIndex(
+ EABContract.EABColumns.VIDEO_CALL_CAPABILITY)));
+ cvalues.put(EABContract.EABColumns.VIDEO_CALL_CAPABILITY_TIMESTAMP,
+ cursor.getLong(cursor.getColumnIndex(
+ EABContract.EABColumns.VIDEO_CALL_CAPABILITY_TIMESTAMP)));
+ cvalues.put(EABContract.EABColumns.VIDEO_CALL_AVAILABILITY,
+ cursor.getString(cursor.getColumnIndex(
+ EABContract.EABColumns.VIDEO_CALL_AVAILABILITY)));
+ cvalues.put(EABContract.EABColumns.VIDEO_CALL_AVAILABILITY_TIMESTAMP,
+ cursor.getLong(cursor.getColumnIndex(
+ EABContract.EABColumns.VIDEO_CALL_AVAILABILITY_TIMESTAMP)));
+ cvalues.put(EABContract.EABColumns.CONTACT_LAST_UPDATED_TIMESTAMP, 0);
+ break;
+ }
+ }
}
if (null != cursor) {
cursor.close();
@@ -437,6 +492,9 @@ public class EABProvider extends DatabaseContentProvider{
EABContract.EABColumns.CONTACT_NUMBER));
String displayName = cursor.getString(cursor.getColumnIndex(
EABContract.EABColumns.CONTACT_NAME));
+ logger.debug("Deleting : dataId : " + dataId + " contactId :" + contactId +
+ " rawContactId :" + rawContactId + " phoneNumber :" + phoneNumber +
+ " displayName :" + displayName);
}
} else {
logger.error("cursor is null!");
diff --git a/rcs/presencepolling/src/com/android/service/ims/presence/EABService.java b/rcs/presencepolling/src/com/android/service/ims/presence/EABService.java
index 191a6c1..67aa92b 100644
--- a/rcs/presencepolling/src/com/android/service/ims/presence/EABService.java
+++ b/rcs/presencepolling/src/com/android/service/ims/presence/EABService.java
@@ -96,8 +96,7 @@ public class EABService extends Service {
/**
* When "clear data" is done for contact storage in system settings, EAB
- * Provider must me cleared and PREF_KEY_CHANGE and PREF_KEY_DELETE keys
- * should not cleared.
+ * Provider must be cleared.
*/
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
@@ -127,6 +126,9 @@ public class EABService extends Service {
if(lastChangedTimestamp > currentTimestamp) {
logger.debug("Resetting timestamp values in shared pref.");
SharedPrefUtil.resetEABSharedPref(mContext);
+ // Set Init done to true as only the contact sync timestamps are cleared and
+ // the EABProvider table data is not cleared.
+ SharedPrefUtil.setInitDone(mContext, true);
CapabilityPolling capabilityPolling = CapabilityPolling.getInstance(null);
if (capabilityPolling != null) {
capabilityPolling.enqueueDiscovery(CapabilityPolling.ACTION_POLLING_NORMAL);
@@ -309,23 +311,22 @@ public class EABService extends Service {
logger.debug("Enter: handleMessage");
switch (msg.what) {
- case BOOT_COMPLETED:
- logger.debug("case BOOT_COMPLETED");
- ensureInitDone();
- isEABServiceInitializing = false;
- break;
- case CONTACT_TABLE_MODIFIED:
- logger.debug("case CONTACT_TABLE_MODIFIED");
- ensureVideoCallingGroupCreation();
- validateAndSyncFromContactsDb();
- break;
- case CONTACT_PROFILE_TABLE_MODIFIED:
- logger.debug("case CONTACT_PROFILE_TABLE_MODIFIED");
- validateAndSyncFromProfileDb();
- break;
- default:
- logger.debug("default usecase hit! Do nothing");
- break;
+ case BOOT_COMPLETED:
+ logger.debug("case BOOT_COMPLETED");
+ ensureInitDone();
+ isEABServiceInitializing = false;
+ break;
+ case CONTACT_TABLE_MODIFIED:
+ logger.debug("case CONTACT_TABLE_MODIFIED");
+ validateAndSyncFromContactsDb();
+ break;
+ case CONTACT_PROFILE_TABLE_MODIFIED:
+ logger.debug("case CONTACT_PROFILE_TABLE_MODIFIED");
+ validateAndSyncFromProfileDb();
+ break;
+ default:
+ logger.debug("default usecase hit! Do nothing");
+ break;
}
logger.debug("Exit: handleMessage");
}
@@ -351,7 +352,6 @@ public class EABService extends Service {
private void ensureInitDone() {
logger.debug("Enter : ensureInitDone()");
- ensureVideoCallingGroupCreation();
if(SharedPrefUtil.isInitDone(mContext)) {
logger.debug("EAB initialized already!!! Just Sync with Contacts db.");
validateAndSyncFromContactsDb();
@@ -369,20 +369,6 @@ public class EABService extends Service {
}
}
- private void ensureVideoCallingGroupCreation() {
- logger.debug("TODO: ensureVideoCallingGroupCreation");
- /*
- if (!isRcsProvisioned()) {
- logger.debug("Device is not provisioned. Remove Video calling group and account.");
- ContactDbUtil.removeVideoCallingContactGroup(mContext);
- AccountUtil.removeRcsAccount(mContext);
- } else {
- logger.debug("Device is provisioned. Create Video calling group and account.");
- Account vCallingAccount = AccountUtil.addRcsAccount(mContext);
- ContactDbUtil.addVideoCallingContactGroup(mContext, vCallingAccount);
- }*/
- }
-
private void sendDelayedContactChangeMsg() {
logger.debug("Enter: sendDelayedContactChangeMsg()");
if (null != mServiceHandler && !isEABServiceInitializing) {
@@ -433,59 +419,68 @@ public class EABService extends Service {
"' AND " + ContactsContract.Data.CONTACT_LAST_UPDATED_TIMESTAMP + " > '" +
contactLastChange + "'";
String sortOrder = ContactsContract.Data.CONTACT_LAST_UPDATED_TIMESTAMP + " desc";
-
- Cursor cursor = getContentResolver().query(ContactsContract.Data.CONTENT_URI,
- projection, selection, null, sortOrder);
-
- if (null != cursor) {
- int count = cursor.getCount();
- logger.debug("cursor count : " + count);
- if (count > 0) {
- ArrayList<Long> uniqueRawContactIds = new ArrayList<Long>();
- while (cursor.moveToNext()) {
- Long dataId = Long.valueOf(cursor.getLong(cursor.getColumnIndex(
- ContactsContract.Data._ID)));
- Long contactId = Long.valueOf(cursor.getLong(cursor.getColumnIndex(
- ContactsContract.Data.CONTACT_ID)));
- Long rawContactId = Long.valueOf(cursor.getLong(cursor.getColumnIndex(
- ContactsContract.Data.RAW_CONTACT_ID)));
- String phoneNumber = cursor.getString(cursor.getColumnIndex(
- ContactsContract.Data.DATA1));
- String displayName = cursor.getString(cursor.getColumnIndex(
- ContactsContract.Data.DISPLAY_NAME));
- verifyInsertOrUpdateAction(dataId, contactId, rawContactId, phoneNumber,
- displayName);
- if (uniqueRawContactIds.isEmpty()) {
- uniqueRawContactIds.add(rawContactId);
- } else if (!uniqueRawContactIds.contains(rawContactId)) {
- uniqueRawContactIds.add(rawContactId);
- } else {
- // Do nothing.
- logger.debug("uniqueRawContactIds already contains rawContactId : " +
- rawContactId);
+ Cursor cursor = null;
+ try {
+ cursor = getContentResolver().query(ContactsContract.Data.CONTENT_URI,
+ projection, selection, null, sortOrder);
+
+ if (null != cursor) {
+ int count = cursor.getCount();
+ logger.debug("cursor count : " + count);
+ if (count > 0) {
+ ArrayList<Long> uniqueRawContactIds = new ArrayList<Long>();
+ while (cursor.moveToNext()) {
+ Long dataId = Long.valueOf(cursor.getLong(cursor.getColumnIndex(
+ ContactsContract.Data._ID)));
+ Long contactId = Long.valueOf(cursor.getLong(cursor.getColumnIndex(
+ ContactsContract.Data.CONTACT_ID)));
+ Long rawContactId = Long.valueOf(cursor.getLong(cursor.getColumnIndex(
+ ContactsContract.Data.RAW_CONTACT_ID)));
+ String phoneNumber = cursor.getString(cursor.getColumnIndex(
+ ContactsContract.Data.DATA1));
+ String displayName = cursor.getString(cursor.getColumnIndex(
+ ContactsContract.Data.DISPLAY_NAME));
+ logger.debug("dataId : " + dataId + " rawContactId :" + rawContactId +
+ " contactId : " + contactId
+ + " phoneNumber :" + phoneNumber + " displayName :" + displayName);
+ verifyInsertOrUpdateAction(dataId, contactId, rawContactId, phoneNumber,
+ displayName);
+ if (uniqueRawContactIds.isEmpty()) {
+ uniqueRawContactIds.add(rawContactId);
+ } else if (!uniqueRawContactIds.contains(rawContactId)) {
+ uniqueRawContactIds.add(rawContactId);
+ } else {
+ // Do nothing.
+ logger.debug("uniqueRawContactIds already contains rawContactId : " +
+ rawContactId);
+ }
+ }
+ checkForPhoneNumberDelete(uniqueRawContactIds);
+ // Save the largest timestamp returned. Only need the first one due to
+ // the sort order.
+ cursor.moveToFirst();
+ long timestamp = cursor.getLong(cursor
+ .getColumnIndex(ContactsContract.Data.CONTACT_LAST_UPDATED_TIMESTAMP));
+ if (timestamp > 0) {
+ SharedPrefUtil.saveLastContactChangedTimestamp(mContext, timestamp);
}
}
- checkForPhoneNumberDelete(uniqueRawContactIds);
- // Save the largest timestamp returned. Only need the first one due to
- // the sort order.
- cursor.moveToFirst();
- long timestamp = cursor.getLong(cursor
- .getColumnIndex(ContactsContract.Data.CONTACT_LAST_UPDATED_TIMESTAMP));
- if (timestamp > 0) {
- SharedPrefUtil.saveLastContactChangedTimestamp(mContext, timestamp);
- }
+ } else {
+ logger.error("cursor is null!");
+ }
+ } catch (Exception e) {
+ logger.error("checkForContactNumberChanges() exception:", e);
+ } finally {
+ if (null != cursor) {
+ cursor.close();
}
- } else {
- logger.error("cursor is null!");
- }
- if (null != cursor) {
- cursor.close();
}
logger.debug("Exit: checkForContactNumberChanges()");
}
private void verifyInsertOrUpdateAction(Long dataId, Long contactId,
Long rawContactId, String phoneNumber, String displayName) {
+ logger.debug("Enter: verifyInsertOrUpdateAction() phoneNumber : " + phoneNumber);
if (null == phoneNumber){
logger.error("Error: return as phoneNumber is null");
return;
@@ -496,7 +491,8 @@ public class EABService extends Service {
EABContract.EABColumns.CONTACT_NAME };
String eabWhereClause = EABContract.EABColumns.DATA_ID + " ='" + dataId.toString()
+ "' AND " + EABContract.EABColumns.RAW_CONTACT_ID + " ='"
- + rawContactId.toString() + "'";
+ + rawContactId.toString() + "' AND " + EABContract.EABColumns.CONTACT_ID
+ + " ='" + contactId.toString() + "'";
logger.debug("eabWhereClause : " + eabWhereClause);
Cursor eabCursor = getContentResolver().query(EABContract.EABColumns.CONTENT_URI,
@@ -512,17 +508,18 @@ public class EABService extends Service {
.getColumnIndex(EABContract.EABColumns.CONTACT_NUMBER));
String eabDisplayName = eabCursor.getString(eabCursor
.getColumnIndex(EABContract.EABColumns.CONTACT_NAME));
- // Contact names should match and both numbers should not be
- // null & should not match.
- if ((null != eabPhoneNumber)
- && !PhoneNumberUtils.compare(mContext, phoneNumber, eabPhoneNumber)) {
- // Update use-case.
- handlePhoneNumberChanged(dataId, contactId, rawContactId,
- eabPhoneNumber, phoneNumber, displayName);
- } else {
- if ((null != eabPhoneNumber)
- && PhoneNumberUtils.compare(mContext, phoneNumber, eabPhoneNumber)
- && !TextUtils.equals(displayName, eabDisplayName)) {
+ logger.debug("phoneNumber : " + phoneNumber
+ + " eabPhoneNumber :" + eabPhoneNumber);
+ // If contact number do not match, then update EAB database with the new
+ // number. If contact name do not match, then update EAB database with the
+ // new name.
+ if (null != eabPhoneNumber) {
+ if (!phoneNumber.equals(eabPhoneNumber)) {
+ // Update use-case.
+ handlePhoneNumberChanged(dataId, contactId, rawContactId,
+ eabPhoneNumber, phoneNumber, displayName);
+ } else if (!TextUtils.equals(displayName, eabDisplayName)) {
+ // Update name use-case.
handlePhoneNameUpdate(dataId, contactId, rawContactId,
phoneNumber, displayName);
} else {
@@ -620,6 +617,7 @@ public class EABService extends Service {
while (eabDbCursor.moveToNext()) {
String eabPhoneNumber = eabDbCursor.getString(eabDbCursor
.getColumnIndex(EABContract.EABColumns.CONTACT_NUMBER));
+ logger.debug("eabPhoneNumber :" + eabPhoneNumber);
Long eabDataId = Long.valueOf(eabDbCursor.getLong(eabDbCursor
.getColumnIndex(EABContract.EABColumns.DATA_ID)));
logger.debug("eabDataId :" + eabDataId);
@@ -629,8 +627,8 @@ public class EABService extends Service {
eabDataIdList.add(eabDataId);
} else {
// Something is wrong. There can not be duplicate numbers.
- logger.error("Duplicate entry for DataId : " + eabDataId +
- " found in EABProvider.");
+ logger.error("Duplicate entry for PhoneNumber :" + eabPhoneNumber
+ + " with DataId : " + eabDataId + " found in EABProvider.");
}
}
logger.debug("Before computation eabDataIdList size :" +
@@ -641,12 +639,15 @@ public class EABService extends Service {
Long contactDataId = Long.valueOf(contactDbCursor.getLong(
contactDbCursor
.getColumnIndex(ContactsContract.Data._ID)));
+ logger.debug("contactPhoneNumber : " + contactPhoneNumber +
+ " dataId : " + contactDataId);
if (eabDataIdList.contains(contactDataId) ) {
eabDataIdList.remove(contactDataId);
logger.debug("Number removed from eabDataIdList");
} else {
// Something is wrong. There can not be new number in Contacts DB.
- logger.error("DataId " + contactDataId +
+ logger.error("Number :" + contactPhoneNumber
+ + " with DataId : " + contactDataId +
" not found in EABProvider.");
}
}
@@ -762,6 +763,11 @@ public class EABService extends Service {
ContactsContract.Contacts.Entity.DATA1));
String profileName = cursor.getString(cursor.getColumnIndex(
ContactsContract.Contacts.Entity.DISPLAY_NAME));
+ logger.debug("Profile Name : " + profileName
+ + " Profile Number : " + contactNumber
+ + " profile dataId : " + dataId
+ + " profile rawContactId : " + rawContactId
+ + " profile contactId : " + contactId);
if (profileDataIdList.isEmpty()) {
profileDataIdList.add(dataId);
profileNumberList.clear();
@@ -771,7 +777,8 @@ public class EABService extends Service {
profileNumberList.add(contactNumber);
} else {
// There are duplicate entries in Profile's Table
- logger.error("Duplicate entry in Profile's Table for dataId : " + dataId);
+ logger.error("Duplicate entry in Profile's Table for contact :" +
+ contactNumber + " dataId : " + dataId);
}
verifyInsertOrUpdateAction(dataId, contactId, rawContactId, contactNumber,
profileName);
@@ -911,6 +918,10 @@ public class EABService extends Service {
private void handlePhoneNumberInsertion(Long dataId, Long contactId,
Long rawContactId, String phoneNumber, String contactName) {
+ logger.debug("handlePhoneNumberInsertion() rawContactId : "
+ + rawContactId + " dataId :" + dataId + " contactId :"
+ + contactId + " phoneNumber :" + phoneNumber + " contactName :"
+ + contactName);
if (!EABDbUtil.validateEligibleContact(mContext, phoneNumber)) {
logger.debug("Return as number is not elegible for VT.");
return;
@@ -927,8 +938,9 @@ public class EABService extends Service {
if (null != contactId) {
sContactId = contactId.toString();
}
+ String formattedNumber = EABDbUtil.formatNumber(phoneNumber);
ArrayList<PresenceContact> contactListToInsert = new ArrayList<PresenceContact>();
- contactListToInsert.add(new PresenceContact(contactName, phoneNumber,
+ contactListToInsert.add(new PresenceContact(contactName, phoneNumber, formattedNumber,
sRawContactId, sContactId, sDataId));
EABDbUtil.addContactsToEabDb(getApplicationContext(),
@@ -939,6 +951,11 @@ public class EABService extends Service {
Long rawContactId, String oldPhoneNumber, String newPhoneNumber,
String contactName) {
+ logger.debug("handlePhoneNumberChanged() rawContactId : " + rawContactId
+ + " dataId :" + dataId + " oldPhoneNumber :" + oldPhoneNumber
+ + " newPhoneNumber :" + newPhoneNumber + " contactName :"
+ + contactName);
+
if (null == oldPhoneNumber && null == newPhoneNumber) {
logger.debug("Both old and new numbers are null.");
return;
@@ -958,17 +975,19 @@ public class EABService extends Service {
if (null != contactId) {
sContactId = contactId.toString();
}
+ String newFormattedNumber = EABDbUtil.formatNumber(newPhoneNumber);
+ logger.debug("newFormattedNumber : " + newFormattedNumber);
logger.debug("Removing old number and inserting new number in EABProvider.");
if (null != oldPhoneNumber) {
contactListToDelete.add(new PresenceContact(contactName,
- oldPhoneNumber, sRawContactId, sContactId, sDataId));
+ oldPhoneNumber, sRawContactId, sContactId, sDataId, null));
// Delete old number from EAB Presence Table
EABDbUtil.deleteNumbersFromEabDb(getApplicationContext(), contactListToDelete);
}
if (null != newPhoneNumber) {
if (EABDbUtil.validateEligibleContact(mContext, newPhoneNumber)) {
contactListToInsert.add(new PresenceContact(contactName,
- newPhoneNumber, sRawContactId, sContactId, sDataId));
+ newPhoneNumber, sRawContactId, sContactId, sDataId, newFormattedNumber));
// Insert new number from EAB Presence Table
EABDbUtil.addContactsToEabDb(getApplicationContext(), contactListToInsert);
} else {
@@ -987,7 +1006,7 @@ public class EABService extends Service {
if (null != rawContactId) {
sRawContactId = rawContactId.toString();
}
- phoneNumberToDeleteList.add(new PresenceContact(null, null,
+ phoneNumberToDeleteList.add(new PresenceContact(null, null, null,
sRawContactId, null, staleDataId.toString()));
}
}
@@ -997,6 +1016,8 @@ public class EABService extends Service {
private void handlePhoneNameUpdate(Long dataId, Long contactId,
Long rawContactId, String phoneNumber, String newDisplayName) {
+ logger.debug("handlePhoneNameUpdate() rawContactId : " + rawContactId
+ + " dataId :" + dataId + " newDisplayName :" + newDisplayName);
String sRawContactId = null;
String sDataId = null;
String sContactId = null;
@@ -1011,7 +1032,7 @@ public class EABService extends Service {
}
ArrayList<PresenceContact> contactNameToUpdate = new ArrayList<PresenceContact>();
contactNameToUpdate.add(new PresenceContact(newDisplayName,
- phoneNumber, sRawContactId, sContactId, sDataId));
+ phoneNumber, null, sRawContactId, sContactId, sDataId));
EABDbUtil.updateNamesInEabDb(getApplicationContext(), contactNameToUpdate);
}
@@ -1022,7 +1043,8 @@ public class EABService extends Service {
logger.debug("handleContactDeleted : contactId is null");
}
ArrayList<PresenceContact> contactListToDelete = new ArrayList<PresenceContact>();
- contactListToDelete.add(new PresenceContact(null, null, null, contactId.toString(), null));
+ contactListToDelete.add(new PresenceContact(
+ null, null, null, null, contactId.toString(), null));
//ContactDbUtil.deleteRawContact(getApplicationContext(), contactListToDelete);
EABDbUtil.deleteContactsFromEabDb(mContext, contactListToDelete);
@@ -1033,7 +1055,7 @@ public class EABService extends Service {
logger.debug("contactProfileMinId : " + contactProfileMinId);
ArrayList<PresenceContact> contactListToDelete = new ArrayList<PresenceContact>();
- contactListToDelete.add(new PresenceContact(null, null, null,
+ contactListToDelete.add(new PresenceContact(null, null, null, null,
contactProfileMinId.toString(), null));
EABDbUtil.deleteContactsFromEabDb(mContext, contactListToDelete);
diff --git a/rcs/presencepolling/src/com/android/service/ims/presence/InvalidDBException.java b/rcs/presencepolling/src/com/android/service/ims/presence/InvalidDBException.java
deleted file mode 100644
index 1e7fdeb..0000000
--- a/rcs/presencepolling/src/com/android/service/ims/presence/InvalidDBException.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2015, Motorola Mobility LLC
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * - Neither the name of Motorola Mobility nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MOTOROLA MOBILITY LLC BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- */
-
-package com.android.service.ims.presence;
-
-import android.database.sqlite.SQLiteException;
-
-//A custom exception for onDowngrade()
-public class InvalidDBException extends SQLiteException {
- public InvalidDBException() {
- }
-
- public InvalidDBException(String error) {
- super(error);
- }
-}
diff --git a/rcs/presencepolling/src/com/android/service/ims/presence/PresenceContact.java b/rcs/presencepolling/src/com/android/service/ims/presence/PresenceContact.java
index a9bd8a5..4495309 100644
--- a/rcs/presencepolling/src/com/android/service/ims/presence/PresenceContact.java
+++ b/rcs/presencepolling/src/com/android/service/ims/presence/PresenceContact.java
@@ -34,6 +34,7 @@ public class PresenceContact {
String mDisplayName = null;
String mPhoneNumber = null;
+ String mFormattedNumber = null;
String mRawContactId = null;
String mContactId = null;
String mDataId = null;
@@ -43,10 +44,11 @@ public class PresenceContact {
String mVtUri = null;
- public PresenceContact(String name, String number, String rawContactId,
+ public PresenceContact(String name, String number, String formattedNumber, String rawContactId,
String contactId, String dataId) {
mDisplayName = name;
mPhoneNumber = number;
+ mFormattedNumber = formattedNumber;
mRawContactId = rawContactId;
mContactId = contactId;
mDataId = dataId;
@@ -60,6 +62,10 @@ public class PresenceContact {
return mPhoneNumber;
}
+ public String getFormattedNumber() {
+ return mFormattedNumber;
+ }
+
public String getRawContactId() {
return mRawContactId;
}
diff --git a/rcs/presencepolling/src/com/android/service/ims/presence/SharedPrefUtil.java b/rcs/presencepolling/src/com/android/service/ims/presence/SharedPrefUtil.java
index 9e9a31e..5144b7b 100644
--- a/rcs/presencepolling/src/com/android/service/ims/presence/SharedPrefUtil.java
+++ b/rcs/presencepolling/src/com/android/service/ims/presence/SharedPrefUtil.java
@@ -37,13 +37,6 @@ public class SharedPrefUtil {
private static final String CONTACT_CHANGED_PREF_KEY = "timestamp_change";
private static final String CONTACT_DELETE_PREF_KEY = "timestamp_delete";
private static final String CONTACT_PROFILE_CHANGED_PREF_KEY = "profile_timestamp_change";
- public static final String VIDEO_CALLING_GROUP_ID = "video_calling_group_id";
- public static final String VIDEO_CALLING_WARN_SHOW = "video_calling_warning_alert_show";
- public static final String VIDEO_CALL_OFF_WARN_SHOW = "video_call_off_alert_show";
- public static final String MOBILE_DATA_ON_WARN_SHOW = "mobile_data_on_alert_show";
- public static final String VOLTE_ON_WARN_SHOW = "volte_on_alert_show";
- public static final String TTY_OFF_WARN_SHOW = "tty_off_alert_show";
- public static final String VT_ON_WARN_SHOW = "vt_on_alert_show";
public static boolean isInitDone(Context context) {
SharedPreferences eabPref = context.getSharedPreferences(
@@ -58,9 +51,11 @@ public class SharedPrefUtil {
}
public static long getLastContactChangedTimestamp(Context context, long time) {
+ long contactModifySyncTime = 0;
SharedPreferences pref = context.getSharedPreferences(EAB_SHARED_PREF,
Context.MODE_PRIVATE);
- return pref.getLong(CONTACT_CHANGED_PREF_KEY, time);
+ contactModifySyncTime = pref.getLong(CONTACT_CHANGED_PREF_KEY, time);
+ return validateDeviceTimestamp(context, contactModifySyncTime);
}
public static void saveLastContactChangedTimestamp(Context context, long time) {
@@ -70,9 +65,11 @@ public class SharedPrefUtil {
}
public static long getLastProfileContactChangedTimestamp(Context context, long time) {
+ long profileModifySyncTime = 0;
SharedPreferences pref = context.getSharedPreferences(EAB_SHARED_PREF,
Context.MODE_PRIVATE);
- return pref.getLong(CONTACT_PROFILE_CHANGED_PREF_KEY, time);
+ profileModifySyncTime = pref.getLong(CONTACT_PROFILE_CHANGED_PREF_KEY, time);
+ return validateDeviceTimestamp(context, profileModifySyncTime);
}
public static void saveLastProfileContactChangedTimestamp(Context context, long time) {
@@ -82,9 +79,11 @@ public class SharedPrefUtil {
}
public static long getLastContactDeletedTimestamp(Context context, long time) {
+ long contactDeleteSyncTime = 0;
SharedPreferences pref = context.getSharedPreferences(EAB_SHARED_PREF,
Context.MODE_PRIVATE);
- return pref.getLong(CONTACT_DELETE_PREF_KEY, time);
+ contactDeleteSyncTime = pref.getLong(CONTACT_DELETE_PREF_KEY, time);
+ return validateDeviceTimestamp(context, contactDeleteSyncTime);
}
public static void saveLastContactDeletedTimestamp(Context context, long time) {
@@ -93,90 +92,18 @@ public class SharedPrefUtil {
eabPref.putLong(CONTACT_DELETE_PREF_KEY, time).commit();
}
- public static void setVideoCallingGroupId(Context context,
- long videoCallingGroupId) {
- SharedPreferences.Editor eabPref = context.getSharedPreferences(
- EAB_SHARED_PREF, Context.MODE_PRIVATE).edit();
- eabPref.putLong(VIDEO_CALLING_GROUP_ID, videoCallingGroupId).commit();
- }
-
- public static long getVideoCallingGroupId(Context context){
- SharedPreferences eabPref = context.getSharedPreferences(
- EAB_SHARED_PREF, Context.MODE_PRIVATE);
- return eabPref.getLong(VIDEO_CALLING_GROUP_ID, 0L);
- }
-
- public static void setVideoCallingWarnDisable(Context context,
- boolean enable) {
- SharedPreferences.Editor eabPref = context.getSharedPreferences(
- EAB_SHARED_PREF, Context.MODE_PRIVATE).edit();
- eabPref.putBoolean(VIDEO_CALLING_WARN_SHOW, enable).apply();
- }
-
- public static boolean isVideoCallingWarnDisabled(Context context){
- SharedPreferences eabPref = context.getSharedPreferences(
- EAB_SHARED_PREF, Context.MODE_PRIVATE);
- return eabPref.getBoolean(VIDEO_CALLING_WARN_SHOW, false);
- }
-
- public static void setVideoCallOffWarnDisable(Context context, boolean enable){
- SharedPreferences.Editor eabPref = context.getSharedPreferences(EAB_SHARED_PREF,
- Context.MODE_PRIVATE).edit();
- eabPref.putBoolean(VIDEO_CALL_OFF_WARN_SHOW, enable).apply();
- }
-
- public static boolean isVideoCallOffWarnDisabled(Context context){
- SharedPreferences eabPref = context.getSharedPreferences(EAB_SHARED_PREF,
- Context.MODE_PRIVATE);
- return eabPref.getBoolean(VIDEO_CALL_OFF_WARN_SHOW, false);
- }
-
- public static void setMobileDataOnWarnDisable(Context context, boolean enable){
- SharedPreferences.Editor eabPref = context.getSharedPreferences(EAB_SHARED_PREF,
- Context.MODE_PRIVATE).edit();
- eabPref.putBoolean(MOBILE_DATA_ON_WARN_SHOW, enable).apply();
- }
-
- public static boolean isMobileDataOnWarnDisabled(Context context){
- SharedPreferences eabPref = context.getSharedPreferences(EAB_SHARED_PREF,
- Context.MODE_PRIVATE);
- return eabPref.getBoolean(MOBILE_DATA_ON_WARN_SHOW, false);
- }
-
- public static void setVolteOnWarnDisable(Context context, boolean enable){
- SharedPreferences.Editor eabPref = context.getSharedPreferences(EAB_SHARED_PREF,
- Context.MODE_PRIVATE).edit();
- eabPref.putBoolean(VOLTE_ON_WARN_SHOW, enable).apply();
- }
-
- public static boolean isVolteOnWarnDisabled(Context context){
- SharedPreferences eabPref = context.getSharedPreferences(EAB_SHARED_PREF,
- Context.MODE_PRIVATE);
- return eabPref.getBoolean(VOLTE_ON_WARN_SHOW, false);
- }
-
- public static void setTtyOffWarnDisable(Context context, boolean enable){
- SharedPreferences.Editor eabPref = context.getSharedPreferences(EAB_SHARED_PREF,
- Context.MODE_PRIVATE).edit();
- eabPref.putBoolean(TTY_OFF_WARN_SHOW, enable).apply();
- }
-
- public static boolean isTtyOffWarnDisabled(Context context){
- SharedPreferences eabPref = context.getSharedPreferences(EAB_SHARED_PREF,
- Context.MODE_PRIVATE);
- return eabPref.getBoolean(TTY_OFF_WARN_SHOW, false);
- }
-
- public static void setVTOnWarnDisable(Context context, boolean enable){
- SharedPreferences.Editor eabPref = context.getSharedPreferences(EAB_SHARED_PREF,
- Context.MODE_PRIVATE).edit();
- eabPref.putBoolean(VT_ON_WARN_SHOW, enable).apply();
- }
-
- public static boolean isVTOnWarnDisabled(Context context){
- SharedPreferences eabPref = context.getSharedPreferences(EAB_SHARED_PREF,
- Context.MODE_PRIVATE);
- return eabPref.getBoolean(VT_ON_WARN_SHOW, false);
+ private static long validateDeviceTimestamp(Context context, long lastSyncedTimestamp) {
+ long deviceCurrentTimeMillis = System.currentTimeMillis();
+ if((lastSyncedTimestamp != 0) && lastSyncedTimestamp > deviceCurrentTimeMillis) {
+ SharedPreferences.Editor eabPref = context.getSharedPreferences(
+ EAB_SHARED_PREF, Context.MODE_PRIVATE).edit();
+ eabPref.putLong(CONTACT_CHANGED_PREF_KEY, 0);
+ eabPref.putLong(CONTACT_DELETE_PREF_KEY, 0);
+ eabPref.putLong(CONTACT_PROFILE_CHANGED_PREF_KEY, 0);
+ eabPref.commit();
+ lastSyncedTimestamp = 0;
+ }
+ return lastSyncedTimestamp;
}
public static void resetEABSharedPref(Context context) {
@@ -186,12 +113,6 @@ public class SharedPrefUtil {
eabPref.putLong(CONTACT_CHANGED_PREF_KEY, 0);
eabPref.putLong(CONTACT_DELETE_PREF_KEY, 0);
eabPref.putLong(CONTACT_PROFILE_CHANGED_PREF_KEY, 0);
- eabPref.putBoolean(VIDEO_CALLING_WARN_SHOW, false);
- eabPref.putBoolean(VIDEO_CALL_OFF_WARN_SHOW, false);
- eabPref.putBoolean(MOBILE_DATA_ON_WARN_SHOW, false);
- eabPref.putBoolean(VOLTE_ON_WARN_SHOW, false);
- eabPref.putBoolean(TTY_OFF_WARN_SHOW, false);
- eabPref.putBoolean(VT_ON_WARN_SHOW, false);
eabPref.commit();
}
}
diff --git a/rcs/rcsmanager/src/java/com/android/ims/internal/ContactNumberUtils.java b/rcs/rcsmanager/src/java/com/android/ims/internal/ContactNumberUtils.java
index b69b42c..1ed03f9 100644
--- a/rcs/rcsmanager/src/java/com/android/ims/internal/ContactNumberUtils.java
+++ b/rcs/rcsmanager/src/java/com/android/ims/internal/ContactNumberUtils.java
@@ -77,6 +77,13 @@ public class ContactNumberUtils {
return null;
}
+ if(number.startsWith("*67") || number.startsWith("*82")) {
+ number = number.substring(3);
+ if (TextUtils.isEmpty(number)) {
+ return null;
+ }
+ }
+
number = PhoneNumberUtils.stripSeparators(number);
int len = number.length();
@@ -95,10 +102,22 @@ public class ContactNumberUtils {
if (number.startsWith("1")) {
number = "+" + number;
}
- } else if (len >= NUMBER_LENGTH_NORMAL + 4) {
- if (number.startsWith("011")) {
+ } else if(len >= NUMBER_LENGTH_NORMAL + 2) {
+ if ((len >= NUMBER_LENGTH_NORMAL + 4) && (number.startsWith("011"))) {
number = "+" + number.substring(3);
}
+
+ if (!number.startsWith("+")) {
+ if (number.startsWith("1")) {
+ number = "+" + number;;
+ } else {
+ number = "+1" + number;
+ }
+ }
+ }
+
+ if(number.length() > NUMBER_LENGTH_MAX) {
+ return null;
}
return number;
@@ -126,6 +145,13 @@ public class ContactNumberUtils {
return NUMBER_INVALID;
}
+ if(number.startsWith("*67") || number.startsWith("*82")) {
+ number = number.substring(3);
+ if (TextUtils.isEmpty(number)) {
+ return NUMBER_INVALID;
+ }
+ }
+
if(number.contains("*")) {
return NUMBER_PRELOADED_ENTRY;
}
@@ -147,16 +173,15 @@ public class ContactNumberUtils {
}
int len = number.length();
- if (len > "+1-nnn-nnn-nnnn".length()) {
- return NUMBER_INVALID;
- } else if (len < NUMBER_LENGTH_NO_AREA_CODE) {
+ if (len < NUMBER_LENGTH_NORMAL) {
return NUMBER_INVALID;
}
number = format(number);
- if (number.startsWith("+1")) {
+ if (number.startsWith("+")) {
len = number.length();
- if (len == NUMBER_LENGTH_NORMAL + 2) {
+ // make sure the number after stripped the national number still be 10 digits
+ if (len >= NUMBER_LENGTH_NORMAL + 2) {
return NUMBER_VALID;
}
}
@@ -247,8 +272,12 @@ public class ContactNumberUtils {
/**
* Contact number length.
*/
- private static final int NUMBER_LENGTH_NORMAL = 10;
- private static final int NUMBER_LENGTH_NO_AREA_CODE = 7;
+ // As per E164 the maximum number length should be 15.
+ // But as per implemention of libphonenumber it found longer length in Germany.
+ // So we use the same length as libphonenumber.
+ private int NUMBER_LENGTH_MAX = 17;
+ private int NUMBER_LENGTH_NORMAL = 10;
+ private int NUMBER_LENGTH_NO_AREA_CODE = 7;
/**
* Save the singleton instance.
diff --git a/rcs/rcsmanager/src/java/com/android/ims/internal/EABContract.java b/rcs/rcsmanager/src/java/com/android/ims/internal/EABContract.java
index 7796071..93a8ab9 100644
--- a/rcs/rcsmanager/src/java/com/android/ims/internal/EABContract.java
+++ b/rcs/rcsmanager/src/java/com/android/ims/internal/EABContract.java
@@ -226,6 +226,14 @@ public final class EABContract {
public static final String VOLTE_STATUS = "volte_status";
/**
+ * Key defining the formatted number.
+ * <p>
+ * Type: TEXT
+ * </p>
+ */
+ public static final String FORMATTED_NUMBER = "formatted_number";
+
+ /**
* @hide
*/
public static final String[] PROJECTION = new String[] {