Start service intent when contact is being displayed
Bug:5138185
Change-Id: I84dbf0f933d575b4910b220fe9743a47f46d5762
diff --git a/src/com/android/contacts/ContactLoader.java b/src/com/android/contacts/ContactLoader.java
index 9daa1e0..d8874dc 100644
--- a/src/com/android/contacts/ContactLoader.java
+++ b/src/com/android/contacts/ContactLoader.java
@@ -30,6 +30,7 @@
import android.content.Context;
import android.content.Entity;
import android.content.Entity.NamedContentValues;
+import android.content.Intent;
import android.content.Loader;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
@@ -772,7 +773,7 @@
HashMap<String, AccountType> result = new HashMap<String, AccountType>(allInvitables);
- // Remove the ones that already has a raw contact in the current contact
+ // Remove the ones that already have a raw contact in the current contact
for (Entity entity : contactData.getEntities()) {
final String type = entity.getEntityValues().getAsString(RawContacts.ACCOUNT_TYPE);
if (!TextUtils.isEmpty(type)) {
@@ -1082,12 +1083,45 @@
mContact.setLoadingPhoto(true);
new AsyncPhotoLoader().execute(mContact.getPhotoUri());
}
+
+ // inform the source of the data that this contact is being looked at
+ postViewNotificationToSyncAdapter();
}
deliverResult(mContact);
}
}
+ /**
+ * Posts a message to the contributing sync adapters that have opted-in, notifying them
+ * that the contact has just been loaded
+ */
+ private void postViewNotificationToSyncAdapter() {
+ Context context = getContext();
+ for (Entity entity : mContact.getEntities()) {
+ final ContentValues entityValues = entity.getEntityValues();
+ final String type = entityValues.getAsString(RawContacts.ACCOUNT_TYPE);
+ final String dataSet = entityValues.getAsString(RawContacts.DATA_SET);
+ final AccountType accountType = AccountTypeManager.getInstance(context ).getAccountType(
+ type, dataSet);
+ final String serviceName = accountType.getViewContactNotifyServiceClassName();
+ final String resPackageName = accountType.resPackageName;
+ if (!TextUtils.isEmpty(serviceName) && !TextUtils.isEmpty(resPackageName)) {
+ final long rawContactId = entityValues.getAsLong(RawContacts.Entity._ID);
+ final Uri uri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
+ final Intent intent = new Intent();
+ intent.setClassName(resPackageName, serviceName);
+ intent.setAction(Intent.ACTION_VIEW);
+ intent.setDataAndType(uri, RawContacts.CONTENT_ITEM_TYPE);
+ try {
+ context.startService(intent);
+ } catch (Exception e) {
+ Log.e(TAG, "Error sending message to source-app", e);
+ }
+ }
+ }
+ }
+
private class AsyncPhotoLoader extends AsyncTask<String, Void, byte[]> {
private static final int BUFFER_SIZE = 1024*16;
diff --git a/src/com/android/contacts/detail/ContactLoaderFragment.java b/src/com/android/contacts/detail/ContactLoaderFragment.java
index 8d3cd75..265550b 100644
--- a/src/com/android/contacts/detail/ContactLoaderFragment.java
+++ b/src/com/android/contacts/detail/ContactLoaderFragment.java
@@ -19,7 +19,6 @@
import com.android.contacts.ContactLoader;
import com.android.contacts.ContactSaveService;
import com.android.contacts.R;
-import com.android.contacts.activities.ContactDetailActivity;
import com.android.contacts.activities.ContactDetailActivity.FragmentKeyListener;
import com.android.contacts.util.PhoneCapabilityTester;
import com.android.internal.util.Objects;
@@ -29,7 +28,6 @@
import android.app.LoaderManager;
import android.app.LoaderManager.LoaderCallbacks;
import android.content.ActivityNotFoundException;
-import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.Loader;
diff --git a/src/com/android/contacts/model/AccountType.java b/src/com/android/contacts/model/AccountType.java
index 59b9f45..67100a8 100644
--- a/src/com/android/contacts/model/AccountType.java
+++ b/src/com/android/contacts/model/AccountType.java
@@ -112,6 +112,16 @@
return null;
}
+ /**
+ * Returns an optional service that can be launched whenever a contact is being looked at.
+ * This allows the sync adapter to provide more up-to-date information.
+ * The service class should reside in the sync adapter package as determined by
+ * {@link #resPackageName}.
+ */
+ public String getViewContactNotifyServiceClassName() {
+ return null;
+ }
+
public CharSequence getDisplayLabel(Context context) {
return getResourceText(context, summaryResPackageName, titleRes, accountType);
}
diff --git a/src/com/android/contacts/model/ExternalAccountType.java b/src/com/android/contacts/model/ExternalAccountType.java
index e5af8f8..5dd4d3b 100644
--- a/src/com/android/contacts/model/ExternalAccountType.java
+++ b/src/com/android/contacts/model/ExternalAccountType.java
@@ -57,6 +57,7 @@
private static final String ATTR_CREATE_CONTACT_ACTIVITY = "createContactActivity";
private static final String ATTR_INVITE_CONTACT_ACTIVITY = "inviteContactActivity";
private static final String ATTR_INVITE_CONTACT_ACTION_LABEL = "inviteContactActionLabel";
+ private static final String ATTR_VIEW_CONTACT_NOTIFY_SERVICE = "viewContactNotifyService";
private static final String ATTR_DATA_SET = "dataSet";
private static final String ATTR_EXTENSION_PACKAGE_NAMES = "extensionPackageNames";
@@ -71,6 +72,7 @@
private String mCreateContactActivityClassName;
private String mInviteContactActivity;
private String mInviteActionLabelAttribute;
+ private String mViewContactNotifyService;
private List<String> mExtensionPackageNames;
private int mInviteActionLabelResId;
private String mAccountTypeLabelAttribute;
@@ -149,6 +151,11 @@
}
@Override
+ public String getViewContactNotifyServiceClassName() {
+ return mViewContactNotifyService;
+ }
+
+ @Override
public List<String> getExtensionPackageNames() {
return mExtensionPackageNames;
}
@@ -193,6 +200,8 @@
mInviteContactActivity = value;
} else if (ATTR_INVITE_CONTACT_ACTION_LABEL.equals(attr)) {
mInviteActionLabelAttribute = value;
+ } else if (ATTR_VIEW_CONTACT_NOTIFY_SERVICE.equals(attr)) {
+ mViewContactNotifyService = value;
} else if (ATTR_DATA_SET.equals(attr)) {
dataSet = value;
} else if (ATTR_EXTENSION_PACKAGE_NAMES.equals(attr)) {