summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/spam
diff options
context:
space:
mode:
authorAndroid Dialer <noreply@google.com>2018-04-23 16:48:28 -0700
committerCopybara-Service <copybara-piper@google.com>2018-04-23 16:50:08 -0700
commit59321c69c8a35cfd97b4718952619d8a7356039f (patch)
treecfc2bfd02c0c103d7a9b9d20287f09a43385059e /java/com/android/dialer/spam
parent4558ed566b2da4562b0ac9773cdb679e5d097277 (diff)
Add spam blocking promo notification after user reports spam in after call
notification. Bug: 76436793 Test: SpamNotificationServiceTest PiperOrigin-RevId: 194006876 Change-Id: I7325599cc5581200f124a8fb64a8f4938675c734
Diffstat (limited to 'java/com/android/dialer/spam')
-rw-r--r--java/com/android/dialer/spam/promo/SpamBlockingPromoHelper.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/java/com/android/dialer/spam/promo/SpamBlockingPromoHelper.java b/java/com/android/dialer/spam/promo/SpamBlockingPromoHelper.java
index b5bdd74b7..891ac44ad 100644
--- a/java/com/android/dialer/spam/promo/SpamBlockingPromoHelper.java
+++ b/java/com/android/dialer/spam/promo/SpamBlockingPromoHelper.java
@@ -16,16 +16,23 @@
package com.android.dialer.spam.promo;
+import android.annotation.SuppressLint;
import android.app.FragmentManager;
+import android.app.Notification;
+import android.app.Notification.Builder;
+import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface.OnDismissListener;
import android.preference.PreferenceManager;
import android.support.design.widget.Snackbar;
+import android.support.v4.os.BuildCompat;
import android.view.View;
import android.widget.Toast;
import com.android.dialer.configprovider.ConfigProviderBindings;
import com.android.dialer.logging.DialerImpression;
import com.android.dialer.logging.Logger;
+import com.android.dialer.notification.DialerNotificationManager;
+import com.android.dialer.notification.NotificationChannelId;
import com.android.dialer.spam.SpamSettings;
import com.android.dialer.spam.SpamSettings.ModifySettingListener;
@@ -139,4 +146,58 @@ public class SpamBlockingPromoHelper {
: context.getString(R.string.spam_blocking_settings_enable_error_text);
Toast.makeText(context, toastText, Toast.LENGTH_LONG).show();
}
+
+ /**
+ * Shows a spam blocking promo notification.
+ *
+ * @param notificationTag a string identifier for this notification.
+ * @param notificationId an identifier for this notification.
+ * @param contentIntent pending intent to be sent when notification is clicked.
+ * @param actionIntent pending intent to be sent when enable-spam-blocking button is clicked.
+ */
+ public void showSpamBlockingPromoNotification(
+ String notificationTag,
+ int notificationId,
+ PendingIntent contentIntent,
+ PendingIntent actionIntent) {
+ updateLastShowSpamTimestamp();
+ Logger.get(context)
+ .logImpression(DialerImpression.Type.SPAM_BLOCKING_AFTER_CALL_NOTIFICATION_PROMO_SHOWN);
+ DialerNotificationManager.notify(
+ context,
+ notificationTag,
+ notificationId,
+ getSpamBlockingPromoNotification(contentIntent, actionIntent));
+ }
+
+ /**
+ * Builds a spam blocking promo notification with given intents.
+ *
+ * @param contentIntent pending intent to be sent when notification is clicked.
+ * @param actionIntent pending intent to be sent when enable-spam-blocking button is clicked.
+ */
+ @SuppressLint("NewApi")
+ private Notification getSpamBlockingPromoNotification(
+ PendingIntent contentIntent, PendingIntent actionIntent) {
+ Notification.Builder builder =
+ new Builder(context)
+ .setContentIntent(contentIntent)
+ .setCategory(Notification.CATEGORY_STATUS)
+ .setPriority(Notification.PRIORITY_DEFAULT)
+ .setColor(context.getColor(R.color.dialer_theme_color))
+ .setSmallIcon(R.drawable.quantum_ic_call_vd_theme_24)
+ .setContentText(context.getString(R.string.spam_blocking_promo_text))
+ .addAction(
+ new Notification.Action.Builder(
+ R.drawable.quantum_ic_block_vd_theme_24,
+ context.getString(R.string.spam_blocking_promo_action_filter_spam),
+ actionIntent)
+ .build())
+ .setContentTitle(context.getString(R.string.spam_blocking_promo_title));
+
+ if (BuildCompat.isAtLeastO()) {
+ builder.setChannelId(NotificationChannelId.DEFAULT);
+ }
+ return builder.build();
+ }
}