summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtem Shvadskiy <ashvadskiy@cyngn.com>2016-05-23 12:24:25 -0700
committerArtem Shvadskiy <ashvadskiy@cyngn.com>2016-05-25 16:29:20 -0700
commit4153f978a658a5002ac69237ec4bd43dab3c8c24 (patch)
treeffd05c2482d0fad7b80ca1fe71ce8882e5e7424f
parentfb284b98ddba9da9147d20bf3c2ca343fdee5f3e (diff)
downloadandroid_packages_apps_Messaging-4153f978a658a5002ac69237ec4bd43dab3c8c24.tar.gz
android_packages_apps_Messaging-4153f978a658a5002ac69237ec4bd43dab3c8c24.tar.bz2
android_packages_apps_Messaging-4153f978a658a5002ac69237ec4bd43dab3c8c24.zip
Integrate CallerInfo with notifications
- Allow notifications to use network URIs for avatar icons. - Implement redirect following in network URI requests. - Refactor lookup API Change-Id: Ica61c7aadac1d32dc9d04785f381abf9e0fb1441 issue-id: OPO-725 (cherry picked from commit a29d1394bc9533a022d1db2183f7a48b6fa01b44)
-rw-r--r--src/com/android/messaging/BugleApplication.java24
-rw-r--r--src/com/android/messaging/datamodel/BugleNotifications.java63
-rw-r--r--src/com/android/messaging/datamodel/MessageNotificationState.java95
-rw-r--r--src/com/android/messaging/datamodel/media/NetworkUriImageRequest.java30
-rw-r--r--src/com/android/messaging/ui/PersonItemView.java8
-rw-r--r--src/com/android/messaging/ui/contact/AddContactsConfirmationDialog.java8
-rw-r--r--src/com/android/messaging/ui/conversation/ConversationFragment.java10
-rw-r--r--src/com/android/messaging/ui/conversation/ConversationMessageView.java6
-rw-r--r--src/com/android/messaging/ui/conversationlist/AbstractConversationListActivity.java4
-rw-r--r--src/com/android/messaging/ui/conversationlist/ConversationListItemView.java8
-rw-r--r--src/com/android/messaging/util/DialogUtil.java4
-rw-r--r--src/com/android/messaging/widget/BaseWidgetFactory.java6
-rw-r--r--src/com/android/messaging/widget/WidgetConversationListService.java4
-rw-r--r--src/com/android/messaging/widget/WidgetConversationService.java4
-rw-r--r--src/com/cyanogenmod/messaging/lookup/ILookupClient.java7
-rw-r--r--src/com/cyanogenmod/messaging/lookup/LookupProviderManager.java81
-rw-r--r--src/com/cyanogenmod/messaging/ui/QuickMessageView.java13
17 files changed, 262 insertions, 113 deletions
diff --git a/src/com/android/messaging/BugleApplication.java b/src/com/android/messaging/BugleApplication.java
index c95d75e..3e9cef2 100644
--- a/src/com/android/messaging/BugleApplication.java
+++ b/src/com/android/messaging/BugleApplication.java
@@ -64,7 +64,7 @@ public class BugleApplication extends Application implements UncaughtExceptionHa
private static boolean sRunningTests = false;
// Lookup provider members
- private static LookupProviderManager mLookupProviderManager;
+ private static LookupProviderManager sLookupProviderManager;
@VisibleForTesting
protected static void setTestsRunning() {
@@ -105,7 +105,7 @@ public class BugleApplication extends Application implements UncaughtExceptionHa
Trace.endSection();
- mLookupProviderManager = new LookupProviderManager(this);
+ sLookupProviderManager = new LookupProviderManager(this);
}
@Override
@@ -198,7 +198,7 @@ public class BugleApplication extends Application implements UncaughtExceptionHa
LogUtil.d(TAG, "BugleApplication.onLowMemory");
}
Factory.get().reclaimMemory();
- mLookupProviderManager.onLowMemory();
+ sLookupProviderManager.onLowMemory();
}
@Override
@@ -286,8 +286,22 @@ public class BugleApplication extends Application implements UncaughtExceptionHa
*
* @return {@link ILookupClient} or null
*/
- public static ILookupClient getLookupProviderClient() {
- return mLookupProviderManager;
+ public static ILookupClient getLookupProvider() {
+ return sLookupProviderManager;
}
+ /**
+ * Notify the provider that you would like to use it. Must be followed by
+ * {@link #releaseLookupProvider()} when you are finished, so client can clean up.
+ */
+ public static void acquireLookupProvider() {
+ sLookupProviderManager.onConsumerActivated();
+ }
+
+ /**
+ * Notify the provider that you are finished using it.
+ */
+ public static void releaseLookupProvider() {
+ sLookupProviderManager.onConsumerDeactivated();
+ }
}
diff --git a/src/com/android/messaging/datamodel/BugleNotifications.java b/src/com/android/messaging/datamodel/BugleNotifications.java
index f0ca910..29e4443 100644
--- a/src/com/android/messaging/datamodel/BugleNotifications.java
+++ b/src/com/android/messaging/datamodel/BugleNotifications.java
@@ -25,7 +25,10 @@ import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
import android.graphics.Typeface;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Bundle;
@@ -43,6 +46,8 @@ import android.text.TextUtils;
import android.text.style.StyleSpan;
import android.text.style.TextAppearanceSpan;
+import android.util.Log;
+import android.widget.RemoteViews;
import com.android.messaging.Factory;
import com.android.messaging.R;
import com.android.messaging.datamodel.MessageNotificationState.BundledMessageNotificationState;
@@ -121,6 +126,9 @@ public class BugleNotifications {
private static final String WEARABLE_COMPANION_APP_PACKAGE = "com.google.android.wearable.app";
+ private static final String ANDROID_PACKAGE_NAME = "android";
+ private static final String RESOURCE_ID = "id";
+
private static final Set<NotificationState> sPendingNotifications =
new HashSet<NotificationState>();
@@ -491,8 +499,15 @@ public class BugleNotifications {
if (state.mParticipantAvatarsUris != null) {
final Uri avatarUri = state.mParticipantAvatarsUris.get(0);
- final AvatarRequestDescriptor descriptor = new AvatarRequestDescriptor(avatarUri,
- sIconWidth, sIconHeight, OsUtil.isAtLeastL());
+ UriImageRequestDescriptor descriptor;
+ // Use generic Uri descriptor if not an Avatar.
+ if (AvatarUriUtil.isAvatarUri(avatarUri)) {
+ descriptor = new AvatarRequestDescriptor(avatarUri,
+ sIconWidth, sIconHeight, OsUtil.isAtLeastL());
+ } else {
+ descriptor = new UriImageRequestDescriptor(avatarUri, sIconWidth, sIconHeight,
+ true, 0, 0);
+ }
final MediaRequest<ImageResource> imageRequest = descriptor.buildSyncMediaRequest(
context);
@@ -855,7 +870,17 @@ public class BugleNotifications {
// Apply the wearable options and build & post the notification
notifBuilder.extend(wearableExtender);
- doNotify(notifBuilder.build(), notificationState);
+
+ // Apply custom icon.
+ Notification notification = notifBuilder.build();
+ if (notificationState instanceof MessageNotificationState) {
+ Drawable icon = ((MessageNotificationState) notificationState).getCustomIcon();
+ if (icon != null) {
+ applyCustomNotificationIcon(context, notification, icon);
+ }
+ }
+
+ doNotify(notification, notificationState);
}
private static void setWearableGroupOptions(final NotificationCompat.Builder notifBuilder,
@@ -1234,4 +1259,36 @@ public class BugleNotifications {
PendingIntentConstants.MSG_SEND_ERROR,
builder.build());
}
+
+ private static void applyCustomNotificationIcon(Context context, Notification notification,
+ Drawable logo) {
+ RemoteViews[] viewsToUpdate = new RemoteViews[] {
+ notification.contentView,
+ notification.bigContentView,
+ notification.headsUpContentView};
+ // add LookupProvider badge to Notification
+ Bitmap bitmap;
+ if (logo instanceof BitmapDrawable) {
+ bitmap = ((BitmapDrawable) logo).getBitmap();
+ } else {
+ bitmap = Bitmap.createBitmap(logo.getIntrinsicWidth(), logo.getIntrinsicHeight(),
+ Bitmap.Config.ARGB_8888);
+ Canvas canvas = new Canvas(bitmap);
+ logo.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
+ logo.draw(canvas);
+ }
+ for (RemoteViews view : viewsToUpdate) {
+ if (view == null) continue;
+ int rightIconId = getNotificationRightIconId(context);
+ view.setImageViewBitmap(rightIconId, bitmap);
+ view.setViewPadding(rightIconId, 0, 0, 0, 0);
+ }
+ }
+
+ private static int getNotificationRightIconId(Context context) {
+ // check if resource ID exists, should cause build error if this resource does not exist
+ int checkResourceExists = com.android.internal.R.id.right_icon;
+ return context.getResources().getIdentifier("right_icon", RESOURCE_ID,
+ ANDROID_PACKAGE_NAME);
+ }
}
diff --git a/src/com/android/messaging/datamodel/MessageNotificationState.java b/src/com/android/messaging/datamodel/MessageNotificationState.java
index 4bf8f77..b7b172f 100644
--- a/src/com/android/messaging/datamodel/MessageNotificationState.java
+++ b/src/com/android/messaging/datamodel/MessageNotificationState.java
@@ -21,7 +21,9 @@ import android.content.Context;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Typeface;
+import android.graphics.drawable.Drawable;
import android.net.Uri;
+import android.os.AsyncTask;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.Builder;
import android.support.v4.app.NotificationCompat.WearableExtender;
@@ -37,6 +39,7 @@ import android.text.style.StyleSpan;
import android.text.style.TextAppearanceSpan;
import android.text.style.URLSpan;
+import com.android.messaging.BugleApplication;
import com.android.messaging.Factory;
import com.android.messaging.R;
import com.android.messaging.datamodel.data.ConversationListItemData;
@@ -52,11 +55,15 @@ import com.android.messaging.util.Assert;
import com.android.messaging.util.AvatarUriUtil;
import com.android.messaging.util.BugleGservices;
import com.android.messaging.util.BugleGservicesKeys;
+import com.android.messaging.util.ContactUtil;
import com.android.messaging.util.ContentType;
import com.android.messaging.util.ConversationIdSet;
import com.android.messaging.util.LogUtil;
import com.android.messaging.util.PendingIntentConstants;
import com.android.messaging.util.UriUtil;
+import com.cyanogen.lookup.phonenumber.response.LookupResponse;
+import com.cyanogenmod.messaging.lookup.ILookupClient;
+import com.cyanogenmod.messaging.lookup.LookupProviderManager;
import com.cyanogenmod.messaging.quickmessage.NotificationInfo;
import com.google.common.collect.Lists;
@@ -96,6 +103,31 @@ public abstract class MessageNotificationState extends NotificationState {
private static final int REPLY_INTENT_REQUEST_CODE_OFFSET = 0;
private static final int NUM_EXTRA_REQUEST_CODES_NEEDED = 1;
+
+ /**
+ * Handle CallerInfo lookup results. Ideally we would have info ready when building a
+ * notification, but if this is a cold lookup for this contact, we will show the unknown
+ * contact number right away, then refresh once we receive lookup results.
+ */
+ private static final LookupProviderManager.LookupProviderListener sLookupListener =
+ new LookupProviderManager.LookupProviderListener() {
+ @Override
+ public void onNewInfoAvailable(LookupResponse response) {
+ if (response != null) {
+ new AsyncTask<Void, Void, Void>() {
+ @Override
+ protected Void doInBackground(Void... params) {
+ BugleNotifications.update(true, BugleNotifications.UPDATE_MESSAGES);
+
+ // Notify the provider client that we are done using it.
+ BugleApplication.releaseLookupProvider();
+ return null;
+ }
+ }.execute();
+ }
+ }
+ };
+
protected String mTickerSender = null;
protected CharSequence mTickerText = null;
protected String mTitle = null;
@@ -104,6 +136,8 @@ public abstract class MessageNotificationState extends NotificationState {
protected String mAttachmentType = null;
protected boolean mTickerNoContent;
+ private Drawable mCustomIcon;
+
@Override
protected Uri getAttachmentUri() {
return mAttachmentUri;
@@ -119,6 +153,20 @@ public abstract class MessageNotificationState extends NotificationState {
return R.drawable.ic_sms_light;
}
+ /**
+ * @return alternative small icon to display.
+ */
+ public Drawable getCustomIcon() {
+ return mCustomIcon;
+ }
+
+ /**
+ * @param icon alternative small icon to display.
+ */
+ public void setCustomIcon(Drawable icon) {
+ mCustomIcon = icon;
+ }
+
@Override
public int getPriority() {
// Returning PRIORITY_HIGH causes L to put up a HUD notification. Without it, the ticker
@@ -154,11 +202,12 @@ public abstract class MessageNotificationState extends NotificationState {
final String mAuthorFirstName;
boolean mIsManualDownloadNeeded;
final String mMessageId;
+ final Drawable mCustomIcon;
MessageLineInfo(final boolean isGroup, final String authorFullName,
final String authorFirstName, final CharSequence text, final Uri attachmentUrl,
final String attachmentType, final boolean isManualDownloadNeeded,
- final String messageId) {
+ final String messageId, final Drawable customIcon) {
super(BugleNotifications.LOCAL_SMS_NOTIFICATION);
mAuthorFullName = authorFullName;
mAuthorFirstName = authorFirstName;
@@ -167,6 +216,7 @@ public abstract class MessageNotificationState extends NotificationState {
mAttachmentType = attachmentType;
mIsManualDownloadNeeded = isManualDownloadNeeded;
mMessageId = messageId;
+ mCustomIcon = customIcon;
}
}
@@ -886,6 +936,7 @@ public abstract class MessageNotificationState extends NotificationState {
String groupConversationName = null;
final int maxMessages = getMaxMessagesInConversationNotification();
+ ILookupClient lookupClient = BugleApplication.getLookupProvider();
do {
convMessageData.bind(convMessageCursor);
@@ -898,6 +949,9 @@ public abstract class MessageNotificationState extends NotificationState {
final String convId = convMessageData.getConversationId();
final String messageId = convMessageData.getMessageId();
+ Uri profileUri = convMessageData.getSenderProfilePhotoUri();
+ Drawable customIcon = null;
+
CharSequence text = messageText;
final boolean isManualDownloadNeeded = convMessageData.getIsMmsNotification();
if (isManualDownloadNeeded) {
@@ -921,8 +975,33 @@ public abstract class MessageNotificationState extends NotificationState {
final ParticipantData participantData =
ParticipantData.getFromId(db, convData.getSelfId());
groupConversationName = convData.getName();
+
+ // Lookup CallerInfo data if contact is unknown.
+ if (!ContactUtil.isValidContactId(convData.getParticipantContactId())) {
+ LookupResponse lookupResponse =
+ lookupClient.lookupCachedInfoForPhoneNumber(senderDestination);
+
+ // Substitute info into conversation if
+ // we already have data for this contact.
+ if (lookupResponse != null) {
+ profileUri = lookupResponse.mPhotoUrl == null ?
+ null : Uri.parse(lookupResponse.mPhotoUrl);
+ authorFullName = lookupResponse.mName;
+ customIcon = lookupResponse.mAttributionLogo;
+
+ // If none exists, start a query to update notification later.
+ } else {
+ // Ensure the provider client is active so we can use it.
+ BugleApplication.acquireLookupProvider();
+
+ lookupClient.addLookupProviderListener(
+ senderDestination, sLookupListener);
+ lookupClient.lookupInfoForPhoneNumber(senderDestination);
+ }
+ }
+
final Uri avatarUri = AvatarUriUtil.createAvatarUri(
- convMessageData.getSenderProfilePhotoUri(),
+ profileUri,
convMessageData.getSenderFullName(),
convMessageData.getSenderNormalizedDestination(),
convMessageData.getSenderContactLookupKey());
@@ -1008,8 +1087,8 @@ public abstract class MessageNotificationState extends NotificationState {
attachmentType = messagePartData.getContentType();
}
currConvInfo.mLineInfos.add(new MessageLineInfo(currConvInfo.mIsGroup,
- authorFullName, authorFirstName, text,
- attachmentUri, attachmentType, isManualDownloadNeeded, messageId));
+ authorFullName, authorFirstName, text, attachmentUri,
+ attachmentType, isManualDownloadNeeded, messageId, customIcon));
}
messageCount++;
currConvInfo.mTotalMessageCount++;
@@ -1124,6 +1203,14 @@ public abstract class MessageNotificationState extends NotificationState {
}
state.mParticipantContactUris.add(convInfo.mContactUri);
}
+
+ // Apply lookup provider badge for only single-conversation notifications.
+ if (!convInfo.mIsGroup) {
+ MessageLineInfo messageInfo = convInfo.getLatestMessageLineInfo();
+ if (messageInfo != null) {
+ state.setCustomIcon(messageInfo.mCustomIcon);
+ }
+ }
}
}
if (state != null && LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
diff --git a/src/com/android/messaging/datamodel/media/NetworkUriImageRequest.java b/src/com/android/messaging/datamodel/media/NetworkUriImageRequest.java
index 642e947..71b0cc4 100644
--- a/src/com/android/messaging/datamodel/media/NetworkUriImageRequest.java
+++ b/src/com/android/messaging/datamodel/media/NetworkUriImageRequest.java
@@ -36,6 +36,9 @@ import java.net.URL;
*/
public class NetworkUriImageRequest<D extends UriImageRequestDescriptor> extends
ImageRequest<D> {
+ private static final String HEADER_FIELD_LOCATION = "Location";
+
+ private static final int REDIRECT_LIMIT = 20;
public NetworkUriImageRequest(Context context, D descriptor) {
super(context, descriptor);
@@ -82,17 +85,33 @@ public class NetworkUriImageRequest<D extends UriImageRequestDescriptor> extends
@Override
public Bitmap loadBitmapInternal() throws IOException {
Assert.isNotMainThread();
+ return retrieveHttpBitmap(mDescriptor.uri.toString(), 0);
+ }
- InputStream inputStream = null;
+ private Bitmap retrieveHttpBitmap(String path, int depth) {
Bitmap bitmap = null;
HttpURLConnection connection = null;
try {
- final URL url = new URL(mDescriptor.uri.toString());
+ final URL url = new URL(path);
connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
- if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
- bitmap = BitmapFactory.decodeStream(connection.getInputStream());
+ switch (connection.getResponseCode()) {
+ case HttpURLConnection.HTTP_OK:
+ bitmap = BitmapFactory.decodeStream(connection.getInputStream());
+ break;
+ case HttpURLConnection.HTTP_MOVED_PERM:
+ case HttpURLConnection.HTTP_MOVED_TEMP:
+ if (depth == REDIRECT_LIMIT) {
+ return null;
+ }
+
+ // Follow redirects.
+ bitmap = retrieveHttpBitmap(
+ connection.getHeaderField(HEADER_FIELD_LOCATION), depth + 1);
+ break;
+ default:
+ // Return null Bitmap.
}
} catch (MalformedURLException e) {
LogUtil.e(LogUtil.BUGLE_TAG,
@@ -108,9 +127,6 @@ public class NetworkUriImageRequest<D extends UriImageRequestDescriptor> extends
"IOException trying to get inputStream for image with url: "
+ mDescriptor.uri.toString(), e);
} finally {
- if (inputStream != null) {
- inputStream.close();
- }
if (connection != null) {
connection.disconnect();
}
diff --git a/src/com/android/messaging/ui/PersonItemView.java b/src/com/android/messaging/ui/PersonItemView.java
index feb9038..51f8c0e 100644
--- a/src/com/android/messaging/ui/PersonItemView.java
+++ b/src/com/android/messaging/ui/PersonItemView.java
@@ -88,7 +88,7 @@ public class PersonItemView extends LinearLayout implements PersonItemDataListen
mBinding.detach();
}
if (!TextUtils.isEmpty(mLastNormalizedNumber)) {
- BugleApplication.getLookupProviderClient()
+ BugleApplication.getLookupProvider()
.removeLookupProviderListener(mLastNormalizedNumber, this);
mLastNormalizedNumber = null;
}
@@ -114,7 +114,7 @@ public class PersonItemView extends LinearLayout implements PersonItemDataListen
mBinding.unbind();
}
if (!TextUtils.isEmpty(mLastNormalizedNumber)) {
- BugleApplication.getLookupProviderClient()
+ BugleApplication.getLookupProvider()
.removeLookupProviderListener(mLastNormalizedNumber, this);
mLastNormalizedNumber = null;
}
@@ -131,9 +131,9 @@ public class PersonItemView extends LinearLayout implements PersonItemDataListen
mLastNormalizedNumber = personData.getNormalizedDestination();
}
updateViewAppearance();
- BugleApplication.getLookupProviderClient()
+ BugleApplication.getLookupProvider()
.addLookupProviderListener(mLastNormalizedNumber, this);
- BugleApplication.getLookupProviderClient()
+ BugleApplication.getLookupProvider()
.lookupInfoForPhoneNumber(mLastNormalizedNumber);
}
diff --git a/src/com/android/messaging/ui/contact/AddContactsConfirmationDialog.java b/src/com/android/messaging/ui/contact/AddContactsConfirmationDialog.java
index b5192ea..62cd62b 100644
--- a/src/com/android/messaging/ui/contact/AddContactsConfirmationDialog.java
+++ b/src/com/android/messaging/ui/contact/AddContactsConfirmationDialog.java
@@ -48,7 +48,7 @@ public class AddContactsConfirmationDialog implements DialogInterface.OnClickLis
mContext = context;
mAvatarUri = avatarUri;
mNormalizedDestination = normalizedDestination;
- BugleApplication.getLookupProviderClient().addLookupProviderListener
+ BugleApplication.getLookupProvider().addLookupProviderListener
(mNormalizedDestination, this);
}
@@ -63,7 +63,7 @@ public class AddContactsConfirmationDialog implements DialogInterface.OnClickLis
.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
- BugleApplication.getLookupProviderClient().removeLookupProviderListener
+ BugleApplication.getLookupProvider().removeLookupProviderListener
(mNormalizedDestination, AddContactsConfirmationDialog.this);
}
})
@@ -90,7 +90,7 @@ public class AddContactsConfirmationDialog implements DialogInterface.OnClickLis
default:
break;
}
- BugleApplication.getLookupProviderClient().removeLookupProviderListener
+ BugleApplication.getLookupProvider().removeLookupProviderListener
(mNormalizedDestination, this);
}
@@ -113,7 +113,7 @@ public class AddContactsConfirmationDialog implements DialogInterface.OnClickLis
mTextView.setContentDescription(vocalizedDisplayName);
}
- BugleApplication.getLookupProviderClient()
+ BugleApplication.getLookupProvider()
.lookupInfoForPhoneNumber(mNormalizedDestination);
return view;
diff --git a/src/com/android/messaging/ui/conversation/ConversationFragment.java b/src/com/android/messaging/ui/conversation/ConversationFragment.java
index 0bfd644..df93291 100644
--- a/src/com/android/messaging/ui/conversation/ConversationFragment.java
+++ b/src/com/android/messaging/ui/conversation/ConversationFragment.java
@@ -43,7 +43,6 @@ import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Parcelable;
-import android.provider.Telephony;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.text.BidiFormatter;
import android.support.v4.text.TextDirectionHeuristicsCompat;
@@ -52,12 +51,9 @@ import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
-import android.telephony.SmsManager;
-import android.telephony.SmsMessage;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
-import android.util.Log;
import android.view.ActionMode;
import android.view.Display;
import android.view.LayoutInflater;
@@ -1013,7 +1009,7 @@ public class ConversationFragment extends Fragment implements ConversationDataLi
LocalBroadcastManager.getInstance(getActivity())
.unregisterReceiver(mConversationSelfIdChangeReceiver);
- BugleApplication.getLookupProviderClient().removeLookupProviderListener(mBinding.getData
+ BugleApplication.getLookupProvider().removeLookupProviderListener(mBinding.getData
().getParticipantPhoneNumber(), this);
}
@@ -1667,9 +1663,9 @@ public class ConversationFragment extends Fragment implements ConversationDataLi
if (otherParticipant != null && ContactUtil.isValidContactId(
otherParticipant.getContactId())) {
if (!TextUtils.isEmpty(mBinding.getData().getParticipantPhoneNumber())) {
- BugleApplication.getLookupProviderClient().addLookupProviderListener(
+ BugleApplication.getLookupProvider().addLookupProviderListener(
mBinding.getData().getParticipantPhoneNumber(), this);
- BugleApplication.getLookupProviderClient().lookupInfoForPhoneNumber(
+ BugleApplication.getLookupProvider().lookupInfoForPhoneNumber(
mBinding.getData().getParticipantPhoneNumber());
}
}
diff --git a/src/com/android/messaging/ui/conversation/ConversationMessageView.java b/src/com/android/messaging/ui/conversation/ConversationMessageView.java
index de50184..22128bc 100644
--- a/src/com/android/messaging/ui/conversation/ConversationMessageView.java
+++ b/src/com/android/messaging/ui/conversation/ConversationMessageView.java
@@ -507,9 +507,9 @@ public class ConversationMessageView extends FrameLayout implements View.OnClick
mData.getSenderContactLookupKey(), mData.getSenderNormalizedDestination());
if (mData.getIsIncoming()
&& !ContactUtil.isValidContactId(mData.getSenderContactId())) {
- BugleApplication.getLookupProviderClient().addLookupProviderListener(
+ BugleApplication.getLookupProvider().addLookupProviderListener(
mData.getSenderNormalizedDestination(), this);
- BugleApplication.getLookupProviderClient().lookupInfoForPhoneNumber(
+ BugleApplication.getLookupProvider().lookupInfoForPhoneNumber(
mData.getSenderNormalizedDestination());
}
}
@@ -1242,7 +1242,7 @@ public class ConversationMessageView extends FrameLayout implements View.OnClick
super.onDetachedFromWindow();
if (mData.getIsIncoming()
&& !ContactUtil.isValidContactId(mData.getSenderContactId())) {
- BugleApplication.getLookupProviderClient().removeLookupProviderListener(
+ BugleApplication.getLookupProvider().removeLookupProviderListener(
mData.getSenderNormalizedDestination(), this);
}
}
diff --git a/src/com/android/messaging/ui/conversationlist/AbstractConversationListActivity.java b/src/com/android/messaging/ui/conversationlist/AbstractConversationListActivity.java
index 462652f..33d8ce5 100644
--- a/src/com/android/messaging/ui/conversationlist/AbstractConversationListActivity.java
+++ b/src/com/android/messaging/ui/conversationlist/AbstractConversationListActivity.java
@@ -244,8 +244,8 @@ public abstract class AbstractConversationListActivity extends BugleActionBarAc
conversation.conversationId,
undoListener);
- if (BugleApplication.getLookupProviderClient().hasSpamReporting()) {
- BugleApplication.getLookupProviderClient().markAsSpam(conversation
+ if (BugleApplication.getLookupProvider().hasSpamReporting()) {
+ BugleApplication.getLookupProvider().markAsSpam(conversation
.otherParticipantNormalizedDestination);
}
}
diff --git a/src/com/android/messaging/ui/conversationlist/ConversationListItemView.java b/src/com/android/messaging/ui/conversationlist/ConversationListItemView.java
index cbfc1e4..7dbe62b 100644
--- a/src/com/android/messaging/ui/conversationlist/ConversationListItemView.java
+++ b/src/com/android/messaging/ui/conversationlist/ConversationListItemView.java
@@ -371,7 +371,7 @@ public class ConversationListItemView extends FrameLayout implements OnClickList
// Reset lookup provider listener
if (!TextUtils.isEmpty(mCurrentNumber)) {
if (!ContactUtil.isValidContactId(mData.getParticipantContactId())) {
- BugleApplication.getLookupProviderClient()
+ BugleApplication.getLookupProvider()
.removeLookupProviderListener(mCurrentNumber,
this);
}
@@ -473,9 +473,9 @@ public class ConversationListItemView extends FrameLayout implements OnClickList
mCurrentNumber = mData.getOtherParticipantNormalizedDestination();
if (!ContactUtil.isValidContactId(mData.getParticipantContactId())) {
- BugleApplication.getLookupProviderClient()
+ BugleApplication.getLookupProvider()
.addLookupProviderListener(mCurrentNumber, this);
- BugleApplication.getLookupProviderClient().lookupInfoForPhoneNumber(mCurrentNumber);
+ BugleApplication.getLookupProvider().lookupInfoForPhoneNumber(mCurrentNumber);
}
mContactCheckmarkView.setVisibility(checkmarkVisiblity);
@@ -714,7 +714,7 @@ public class ConversationListItemView extends FrameLayout implements OnClickList
super.onDetachedFromWindow();
if (!ContactUtil.isValidContactId(mData.getParticipantContactId())) {
- BugleApplication.getLookupProviderClient().removeLookupProviderListener(
+ BugleApplication.getLookupProvider().removeLookupProviderListener(
mData.getOtherParticipantNormalizedDestination(), this);
}
}
diff --git a/src/com/android/messaging/util/DialogUtil.java b/src/com/android/messaging/util/DialogUtil.java
index d2edf47..c913c3c 100644
--- a/src/com/android/messaging/util/DialogUtil.java
+++ b/src/com/android/messaging/util/DialogUtil.java
@@ -77,11 +77,11 @@ public class DialogUtil {
.setPositiveButton(android.R.string.ok, positiveClickListener)
.setOnCancelListener(onCancelListener);
- if (view != null && BugleApplication.getLookupProviderClient().hasSpamReporting()) {
+ if (view != null && BugleApplication.getLookupProvider().hasSpamReporting()) {
builder.setView(view);
CheckBox checkBox = (CheckBox) view.findViewById(R.id.chkReportSpam);
String reportSpamBlurb = context.getString(R.string.report_as_spam_to, BugleApplication
- .getLookupProviderClient().getProviderName());
+ .getLookupProvider().getProviderName());
checkBox.setText(reportSpamBlurb);
}
diff --git a/src/com/android/messaging/widget/BaseWidgetFactory.java b/src/com/android/messaging/widget/BaseWidgetFactory.java
index c87a100..4d74c93 100644
--- a/src/com/android/messaging/widget/BaseWidgetFactory.java
+++ b/src/com/android/messaging/widget/BaseWidgetFactory.java
@@ -30,6 +30,7 @@ import android.text.style.StyleSpan;
import android.widget.RemoteViews;
import android.widget.RemoteViewsService;
+import com.android.messaging.BugleApplication;
import com.android.messaging.R;
import com.android.messaging.datamodel.media.AvatarGroupRequestDescriptor;
import com.android.messaging.datamodel.media.AvatarRequestDescriptor;
@@ -40,7 +41,6 @@ import com.android.messaging.datamodel.media.MediaResourceManager;
import com.android.messaging.datamodel.media.UriImageRequestDescriptor;
import com.android.messaging.util.AvatarUriUtil;
import com.android.messaging.util.LogUtil;
-import com.cyanogenmod.messaging.lookup.LookupProviderManager;
/**
* Remote Views Factory for Bugle Widget.
@@ -81,7 +81,7 @@ abstract class BaseWidgetFactory implements RemoteViewsService.RemoteViewsFactor
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "onCreate");
}
- mContext.sendBroadcast(new Intent(LookupProviderManager.ACTION_CREATED));
+ BugleApplication.acquireLookupProvider();
}
@Override
@@ -94,7 +94,7 @@ abstract class BaseWidgetFactory implements RemoteViewsService.RemoteViewsFactor
mCursor.close();
mCursor = null;
}
- mContext.sendBroadcast(new Intent(LookupProviderManager.ACTION_DESTROYED));
+ BugleApplication.releaseLookupProvider();
}
}
diff --git a/src/com/android/messaging/widget/WidgetConversationListService.java b/src/com/android/messaging/widget/WidgetConversationListService.java
index 0748757..0ef1874 100644
--- a/src/com/android/messaging/widget/WidgetConversationListService.java
+++ b/src/com/android/messaging/widget/WidgetConversationListService.java
@@ -107,7 +107,7 @@ public class WidgetConversationListService extends RemoteViewsService {
LookupResponse lookupResponse = null;
if (!ContactUtil.isValidContactId(conv.getParticipantContactId())) {
// Make blocking call
- lookupResponse = BugleApplication.getLookupProviderClient()
+ lookupResponse = BugleApplication.getLookupProvider()
.blockingLookupInfoForPhoneNumber(conv
.getOtherParticipantNormalizedDestination());
}
@@ -184,7 +184,7 @@ public class WidgetConversationListService extends RemoteViewsService {
// Attribution logo
if (lookupResponse != null) {
- Bitmap bitmap = BugleApplication.getLookupProviderClient()
+ Bitmap bitmap = BugleApplication.getLookupProvider()
.getCachedAttributionLogoBitmap(lookupResponse.mProviderName);
if (bitmap != null) {
remoteViews.setImageViewBitmap(R.id.attribution_logo, bitmap);
diff --git a/src/com/android/messaging/widget/WidgetConversationService.java b/src/com/android/messaging/widget/WidgetConversationService.java
index 94dc545..48955e5 100644
--- a/src/com/android/messaging/widget/WidgetConversationService.java
+++ b/src/com/android/messaging/widget/WidgetConversationService.java
@@ -149,7 +149,7 @@ public class WidgetConversationService extends RemoteViewsService {
LookupResponse lookupResponse = null;
if (!ContactUtil.isValidContactId(message.getSenderContactId())) {
// Make blocking call
- lookupResponse = BugleApplication.getLookupProviderClient()
+ lookupResponse = BugleApplication.getLookupProvider()
.blockingLookupInfoForPhoneNumber(
message.getSenderNormalizedDestination());
}
@@ -266,7 +266,7 @@ public class WidgetConversationService extends RemoteViewsService {
// Attribution logo
if (lookupResponse != null) {
- Bitmap bitmap = BugleApplication.getLookupProviderClient()
+ Bitmap bitmap = BugleApplication.getLookupProvider()
.getCachedAttributionLogoBitmap(lookupResponse.mProviderName);
if (bitmap != null) {
remoteViews.setImageViewBitmap(R.id.attribution_logo, bitmap);
diff --git a/src/com/cyanogenmod/messaging/lookup/ILookupClient.java b/src/com/cyanogenmod/messaging/lookup/ILookupClient.java
index e3cd13a..14c2cff 100644
--- a/src/com/cyanogenmod/messaging/lookup/ILookupClient.java
+++ b/src/com/cyanogenmod/messaging/lookup/ILookupClient.java
@@ -52,6 +52,13 @@ public interface ILookupClient {
LookupResponse blockingLookupInfoForPhoneNumber(String phoneNumber);
/**
+ * Will check the local cache to see if data exists, but will not lookup new data.
+ * @param phoneNumber {@link String} not null or empty
+ * @return {@link LookupResponse}
+ */
+ LookupResponse lookupCachedInfoForPhoneNumber(String phoneNumber);
+
+ /**
* Fetches the possibly cached bitmap for a lookup provider of the given name
*
* @param providerName {@link String }
diff --git a/src/com/cyanogenmod/messaging/lookup/LookupProviderManager.java b/src/com/cyanogenmod/messaging/lookup/LookupProviderManager.java
index a5a6e49..7a4adb3 100644
--- a/src/com/cyanogenmod/messaging/lookup/LookupProviderManager.java
+++ b/src/com/cyanogenmod/messaging/lookup/LookupProviderManager.java
@@ -17,10 +17,6 @@ package com.cyanogenmod.messaging.lookup;
import android.app.Activity;
import android.app.Application;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.os.Bundle;
@@ -53,7 +49,7 @@ import java.util.concurrent.ConcurrentHashMap;
* @see {@link LookupRequest.Callback}
* @see {@link ILookupClient}
*/
-public class LookupProviderManager extends BroadcastReceiver implements Application
+public class LookupProviderManager implements Application
.ActivityLifecycleCallbacks, LookupRequest.Callback, ILookupClient {
private static final String TAG = "LookupProviderManager";
@@ -63,16 +59,15 @@ public class LookupProviderManager extends BroadcastReceiver implements Applicat
private static final Handler sHandler = new Handler(Looper.getMainLooper());
private static final LinkedHashMap<String, Bitmap> sAttributionLogoBitmapCache = new
LinkedHashMap<>(1);
+
+ private final Object mConsumerLock = new Object();
+
private Application mApplication;
private ConcurrentHashMap<String, LookupResponse> mPhoneNumberLookupCache;
private ConcurrentHashMap<String, HashSet<LookupProviderListener>> mLookupListeners;
private LookupHandlerThread mLookupHandlerThread;
private boolean mIsPhoneNumberLookupInitialized;
- private short mActivityCount = 0;
- private short mServiceCount = 0;
-
- public static final String ACTION_CREATED = "service_created";
- public static final String ACTION_DESTROYED = "service_destroyed";
+ private short mConsumerCount = 0;
public LookupProviderManager() {
}
@@ -90,10 +85,6 @@ public class LookupProviderManager extends BroadcastReceiver implements Applicat
mPhoneNumberLookupCache = new ConcurrentHashMap<String, LookupResponse>();
mLookupListeners = new ConcurrentHashMap<String, HashSet<LookupProviderListener>>();
application.registerActivityLifecycleCallbacks(this);
- IntentFilter filter = new IntentFilter();
- filter.addAction(ACTION_CREATED);
- filter.addAction(ACTION_DESTROYED);
- application.registerReceiver(this, filter);
mApplication = application;
}
@@ -219,50 +210,38 @@ public class LookupProviderManager extends BroadcastReceiver implements Applicat
}
}
- /* --------------------- Private level service count methods -------------------------------*/
+ /* --------------------- Generic consumer count methods -------------------------------*/
- private void onServiceCreated() {
- ++mServiceCount;
- if (mServiceCount == 1) {
- if (!mIsPhoneNumberLookupInitialized) {
- mIsPhoneNumberLookupInitialized = start();
+ public void onConsumerActivated() {
+ synchronized (mConsumerLock) {
+ ++mConsumerCount;
+ if (mConsumerCount == 1) {
+ if (!mIsPhoneNumberLookupInitialized) {
+ mIsPhoneNumberLookupInitialized = start();
+ }
}
}
}
- private void onServiceDestroyed() {
- --mServiceCount;
- if (mServiceCount == 0 && mActivityCount == 0) {
- if (mIsPhoneNumberLookupInitialized) {
- stop();
- mIsPhoneNumberLookupInitialized = false;
+ public void onConsumerDeactivated() {
+ synchronized (mConsumerLock) {
+ --mConsumerCount;
+ if (mConsumerCount == 0) {
+ if (mIsPhoneNumberLookupInitialized) {
+ stop();
+ mIsPhoneNumberLookupInitialized = false;
+ }
}
}
}
- @Override
- public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
- if (ACTION_CREATED.equalsIgnoreCase(action)) {
- onServiceCreated();
- } else if (ACTION_DESTROYED.equalsIgnoreCase(action)) {
- onServiceDestroyed();
- }
- }
-
/* --------------------- Activity callback interfaces -------------------------------------*/
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
log("onActivityCreated(" + activity + ", " + savedInstanceState + ")");
- ++mActivityCount;
- if (mActivityCount == 1) {
- if (!mIsPhoneNumberLookupInitialized) {
- mIsPhoneNumberLookupInitialized = start();
- }
- }
+ onConsumerActivated();
}
- /* --------------------- Lookup Client interfaces -----------------------------------------*/
@Override
public void onActivityStarted(Activity activity) {}
@@ -280,16 +259,11 @@ public class LookupProviderManager extends BroadcastReceiver implements Applicat
@Override
public void onActivityDestroyed(Activity activity) {
- log("onActivityCreated(" + activity + ")");
- --mActivityCount;
- if (mActivityCount == 0 && mServiceCount == 0) {
- if (mIsPhoneNumberLookupInitialized) {
- stop();
- mIsPhoneNumberLookupInitialized = false;
- }
- }
+ log("onActivityDestroyed(" + activity + ")");
+ onConsumerDeactivated();
}
+ /* --------------------- Lookup Client interfaces -----------------------------------------*/
@Override
public LookupResponse blockingLookupInfoForPhoneNumber(String phoneNumber) {
LookupResponse response = null;
@@ -317,6 +291,11 @@ public class LookupProviderManager extends BroadcastReceiver implements Applicat
}
@Override
+ public LookupResponse lookupCachedInfoForPhoneNumber(String phoneNumber) {
+ return mPhoneNumberLookupCache.get(phoneNumber);
+ }
+
+ @Override
public Bitmap getCachedAttributionLogoBitmap(String providerName) {
if (!TextUtils.isEmpty(providerName)) {
return sAttributionLogoBitmapCache.get(providerName);
diff --git a/src/com/cyanogenmod/messaging/ui/QuickMessageView.java b/src/com/cyanogenmod/messaging/ui/QuickMessageView.java
index 324875f..3eff9f7 100644
--- a/src/com/cyanogenmod/messaging/ui/QuickMessageView.java
+++ b/src/com/cyanogenmod/messaging/ui/QuickMessageView.java
@@ -2,11 +2,7 @@ package com.cyanogenmod.messaging.ui;
import android.content.Context;
-import android.content.res.Resources;
-import android.net.Uri;
import android.telephony.SmsMessage;
-import android.telephony.SubscriptionInfo;
-import android.telephony.SubscriptionManager;
import android.text.Editable;
import android.text.InputFilter;
import android.text.InputType;
@@ -17,17 +13,14 @@ import android.util.Log;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.widget.ImageButton;
-import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.android.messaging.BugleApplication;
import com.android.messaging.Factory;
import com.android.messaging.R;
-import com.android.messaging.datamodel.data.ParticipantData;
import com.android.messaging.ui.PlainTextEditText;
import com.android.messaging.ui.conversation.SimIconView;
-import com.android.messaging.util.AvatarUriUtil;
import com.android.messaging.util.ContactUtil;
import com.android.messaging.util.UiUtils;
import com.cyanogen.lookup.phonenumber.response.LookupResponse;
@@ -99,9 +92,9 @@ public class QuickMessageView extends LinearLayout implements TextWatcher,
}
updateMessageCounter(messageNumber, messageCount);
if (!ContactUtil.isValidContactId(mQuickMessage.getFromContactId())) {
- BugleApplication.getLookupProviderClient().addLookupProviderListener(
+ BugleApplication.getLookupProvider().addLookupProviderListener(
mQuickMessage.getSenderNormalizedDestination(), this);
- BugleApplication.getLookupProviderClient().lookupInfoForPhoneNumber(
+ BugleApplication.getLookupProvider().lookupInfoForPhoneNumber(
mQuickMessage.getSenderNormalizedDestination());
}
}
@@ -127,7 +120,7 @@ public class QuickMessageView extends LinearLayout implements TextWatcher,
public void onDetachedFromWindow() {
super.onDetachedFromWindow();
if (!ContactUtil.isValidContactId(mQuickMessage.getFromContactId())) {
- BugleApplication.getLookupProviderClient().removeLookupProviderListener(
+ BugleApplication.getLookupProvider().removeLookupProviderListener(
mQuickMessage.getSenderNormalizedDestination(), this);
}
}