Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e6f53f47 authored by Android Dialer's avatar Android Dialer Committed by Copybara-Service
Browse files

Adds alternative spam words for non-english speaking countries.

This CL adds alternative spam words and code for using these words in an experiment.

Test: Tap, Unit tests where alterntive experiment is provided and not provided.
PiperOrigin-RevId: 197444892
Change-Id: Iff042966f1728ac571699085f07d1325e756dd36
parent 599705c2
Loading
Loading
Loading
Loading
+52 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.incallui.spam;

import android.content.Context;
import com.android.dialer.common.LogUtil;
import com.android.dialer.configprovider.ConfigProviderBindings;

/** Returns resource id based on experiment number. */
public final class SpamAlternativeExperimentUtil {

  /**
   * Returns the resource id using a resource name for an experiment where we want to use
   * alternative words for the keyword spam.
   */
  public static int getResourceIdByName(String resourceName, Context context) {
    long experiment =
        ConfigProviderBindings.get(context).getLong("experiment_for_alternative_spam_word", 230150);
    LogUtil.i(
        "SpamAlternativeExperimentUtil.getResourceIdByName", "using experiment %d", experiment);
    String modifiedResourceName = resourceName;
    if (experiment != 230150) {
      modifiedResourceName = resourceName + "_" + experiment;
    }
    int resourceId =
        context
            .getResources()
            .getIdentifier(modifiedResourceName, "string", context.getPackageName());
    if (resourceId == 0) {
      LogUtil.i(
          "SpamAlternativeExperimentUtil.getResourceIdByName",
          "not found experiment %d",
          experiment);
      return context.getResources().getIdentifier(resourceName, "string", context.getPackageName());
    }
    return resourceId;
  }
}
+19 −5
Original line number Diff line number Diff line
@@ -277,11 +277,15 @@ public class SpamCallListListener implements CallList.Listener {
    Notification.Builder notificationBuilder =
        createAfterCallNotificationBuilder(call)
            .setContentText(
                context.getString(R.string.spam_notification_non_spam_call_collapsed_text))
                context.getString(
                    SpamAlternativeExperimentUtil.getResourceIdByName(
                        "spam_notification_non_spam_call_collapsed_text", context)))
            .setStyle(
                new Notification.BigTextStyle()
                    .bigText(
                        context.getString(R.string.spam_notification_non_spam_call_expanded_text)))
                        context.getString(
                            SpamAlternativeExperimentUtil.getResourceIdByName(
                                "spam_notification_non_spam_call_expanded_text", context))))
            // Add contact
            .addAction(
                new Notification.Action.Builder(
@@ -392,12 +396,17 @@ public class SpamCallListListener implements CallList.Listener {
    Notification.Builder notificationBuilder =
        createAfterCallNotificationBuilder(call)
            .setLargeIcon(Icon.createWithResource(context, R.drawable.spam_notification_icon))
            .setContentText(context.getString(R.string.spam_notification_spam_call_collapsed_text))
            .setContentText(
                context.getString(
                    SpamAlternativeExperimentUtil.getResourceIdByName(
                        "spam_notification_spam_call_collapsed_text", context)))
            // Not spam
            .addAction(
                new Notification.Action.Builder(
                        R.drawable.quantum_ic_close_vd_theme_24,
                        context.getString(R.string.spam_notification_was_not_spam_action_text),
                        context.getString(
                            SpamAlternativeExperimentUtil.getResourceIdByName(
                                "spam_notification_was_not_spam_action_text", context)),
                        createNotSpamPendingIntent(call))
                    .build())
            // Block/report spam
@@ -408,11 +417,16 @@ public class SpamCallListListener implements CallList.Listener {
                        createBlockReportSpamPendingIntent(call))
                    .build())
            .setContentTitle(
                context.getString(R.string.spam_notification_title, getDisplayNumber(call)));
                context.getString(
                    SpamAlternativeExperimentUtil.getResourceIdByName(
                        "spam_notification_title", context),
                    getDisplayNumber(call)));
    DialerNotificationManager.notify(
        context, getNotificationTagForCall(call), NOTIFICATION_ID, notificationBuilder.build());
  }



  /**
   * Creates a pending intent for block/report spam action. If enabled, this intent is forwarded to
   * the {@link SpamNotificationActivity}, otherwise to the {@link SpamNotificationService}.
+13 −4
Original line number Diff line number Diff line
@@ -406,7 +406,9 @@ public class SpamNotificationActivity extends FragmentActivity {
          .setCancelable(false)
          .setTitle(
              getString(
                  R.string.spam_notification_title, getFormattedNumber(number, applicationContext)))
                  SpamAlternativeExperimentUtil.getResourceIdByName(
                      "spam_notification_title", applicationContext),
                  getFormattedNumber(number, applicationContext)))
          .setNeutralButton(
              getString(R.string.spam_notification_action_dismiss),
              new DialogInterface.OnClickListener() {
@@ -428,7 +430,9 @@ public class SpamNotificationActivity extends FragmentActivity {
                }
              })
          .setNegativeButton(
              getString(R.string.spam_notification_was_not_spam_action_text),
              getString(
                  SpamAlternativeExperimentUtil.getResourceIdByName(
                      "spam_notification_was_not_spam_action_text", applicationContext)),
              new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
@@ -494,7 +498,10 @@ public class SpamNotificationActivity extends FragmentActivity {
          .setTitle(
              getString(R.string.non_spam_notification_title, getFormattedNumber(number, context)))
          .setCancelable(false)
          .setMessage(getString(R.string.spam_notification_non_spam_call_expanded_text))
          .setMessage(
              getString(
                  SpamAlternativeExperimentUtil.getResourceIdByName(
                      "spam_notification_non_spam_call_expanded_text", context)))
          .setNeutralButton(
              getString(R.string.spam_notification_action_dismiss),
              new DialogInterface.OnClickListener() {
@@ -514,7 +521,9 @@ public class SpamNotificationActivity extends FragmentActivity {
                }
              })
          .setNegativeButton(
              getString(R.string.spam_notification_dialog_block_report_spam_action_text),
              getString(
                  SpamAlternativeExperimentUtil.getResourceIdByName(
                      "spam_notification_dialog_block_report_spam_action_text", context)),
              new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
+91 −0
Original line number Diff line number Diff line
@@ -44,6 +44,97 @@
  <!-- Text for the blocking spam action in the after call prompt. [CHAR LIMIT=40] -->
  <string name="spam_notification_block_spam_action_text">Yes, block number</string>

  <!-- Strings for 'junk' spam word alternative-->
  <!-- Title for the notification to the user after a call from an spammer ends. [CHAR LIMIT=100] -->
  <string translatable="false" name="spam_notification_title_230151">Was <xliff:g id="number">%1$s</xliff:g> a junk caller?</string>
  <!-- Text for the toast shown after the user presses block/report spam. [CHAR LIMIT=100] -->
  <string translatable="false" name="spam_notification_block_report_toast_text_230151"><xliff:g id="number">%1$s</xliff:g> blocked and call was reported as junk.</string>
  <!-- Text for the toast shown after the user presses not spam. [CHAR LIMIT=100] -->
  <string translatable="false" name="spam_notification_not_spam_toast_text_230151">Call from <xliff:g id="number">%1$s</xliff:g> reported as not junk.</string>
  <!-- Text displayed in the collapsed notification to the user after a non-spam call ends. [CHAR LIMIT=100] -->
  <string translatable="false" name="spam_notification_non_spam_call_collapsed_text_230151">Tap to add to contacts or block junk number.</string>
  <!-- Text displayed in the expanded notification to the user after a non-spam call ends. [CHAR LIMIT=NONE] -->
  <string translatable="false" name="spam_notification_non_spam_call_expanded_text_230151">This is the first time this number called you. If this call was junk, you can block this number and report it.</string>
  <!-- Text displayed in the collapsed notification to the user after a spam call ends. [CHAR LIMIT=100] -->
  <string translatable="false" name="spam_notification_spam_call_collapsed_text_230151">Tap to report as not junk or block it</string>
  <!-- Text for the blocking and reporting spam action in the after call dialog. [CHAR LIMIT=40] -->
  <string translatable="false" name="spam_notification_dialog_block_report_spam_action_text_230151">Block &amp; report junk</string>
  <!-- Text for the marking a call as not spam in the after call prompt. [CHAR LIMIT=40] -->
  <string translatable="false" name="spam_notification_was_not_spam_action_text_230151">No, not junk</string>

  <!-- Strings for 'junk/spam' spam word alternative-->
  <!-- Title for the notification to the user after a call from an spammer ends. [CHAR LIMIT=100] -->
  <string translatable="false" name="spam_notification_title_230152">Was <xliff:g id="number">%1$s</xliff:g> a junk/spam caller?</string>
  <!-- Text for the toast shown after the user presses block/report spam. [CHAR LIMIT=100] -->
  <string translatable="false" name="spam_notification_block_report_toast_text_230152"><xliff:g id="number">%1$s</xliff:g> blocked and call was reported as junk/spam.</string>
  <!-- Text for the toast shown after the user presses not spam. [CHAR LIMIT=100] -->
  <string translatable="false" name="spam_notification_not_spam_toast_text_230152">Call from <xliff:g id="number">%1$s</xliff:g> reported as not junk/spam.</string>
  <!-- Text displayed in the collapsed notification to the user after a non-spam call ends. [CHAR LIMIT=100] -->
  <string translatable="false" name="spam_notification_non_spam_call_collapsed_text_230152">Tap to add to contacts or block junk/spam number.</string>
  <!-- Text displayed in the expanded notification to the user after a non-spam call ends. [CHAR LIMIT=NONE] -->
  <string translatable="false" name="spam_notification_non_spam_call_expanded_text_230152">This is the first time this number called you. If this call was junk/spam, you can block this number and report it.</string>
  <!-- Text displayed in the collapsed notification to the user after a spam call ends. [CHAR LIMIT=100] -->
  <string translatable="false" name="spam_notification_spam_call_collapsed_text_230152">Tap to report as not junk/spam or block it</string>
  <!-- Text for the blocking and reporting spam action in the after call dialog. [CHAR LIMIT=40] -->
  <string translatable="false" name="spam_notification_dialog_block_report_spam_action_text_230152">Block &amp; report junk/spam</string>
  <!-- Text for the marking a call as not spam in the after call prompt. [CHAR LIMIT=40] -->
  <string translatable="false" name="spam_notification_was_not_spam_action_text_230152">No, not junk/spam</string>

  <!-- Strings for 'unwanted' spam word alternative-->
  <!-- Title for the notification to the user after a call from an spammer ends. [CHAR LIMIT=100] -->
  <string translatable="false" name="spam_notification_title_230153">Was <xliff:g id="number">%1$s</xliff:g> an unwanted caller?</string>
  <!-- Text for the toast shown after the user presses block/report spam. [CHAR LIMIT=100] -->
  <string translatable="false" name="spam_notification_block_report_toast_text_230153"><xliff:g id="number">%1$s</xliff:g> blocked and call was reported as unwanted.</string>
  <!-- Text for the toast shown after the user presses not spam. [CHAR LIMIT=100] -->
  <string translatable="false" name="spam_notification_not_spam_toast_text_230153">Call from <xliff:g id="number">%1$s</xliff:g> reported as useful.</string>
  <!-- Text displayed in the collapsed notification to the user after a non-spam call ends. [CHAR LIMIT=100] -->
  <string translatable="false" name="spam_notification_non_spam_call_collapsed_text_230153">Tap to add to contacts or block unwanted number.</string>
  <!-- Text displayed in the expanded notification to the user after a non-spam call ends. [CHAR LIMIT=NONE] -->
  <string translatable="false" name="spam_notification_non_spam_call_expanded_text_230153">This is the first time this number called you. If this call was unwanted, you can block this number and report it.</string>
  <!-- Text displayed in the collapsed notification to the user after a spam call ends. [CHAR LIMIT=100] -->
  <string translatable="false" name="spam_notification_spam_call_collapsed_text_230153">Tap to report as useful or block it</string>
  <!-- Text for the blocking and reporting spam action in the after call dialog. [CHAR LIMIT=40] -->
  <string translatable="false" name="spam_notification_dialog_block_report_spam_action_text_230153">Block &amp; report unwanted</string>
  <!-- Text for the marking a call as not spam in the after call prompt. [CHAR LIMIT=40] -->
  <string translatable="false" name="spam_notification_was_not_spam_action_text_230153">No, not unwanted</string>

  <!-- Strings for 'spam/unwanted' spam word alternative-->
  <!-- Title for the notification to the user after a call from an spammer ends. [CHAR LIMIT=100] -->
  <string translatable="false" name="spam_notification_title_230154">Was <xliff:g id="number">%1$s</xliff:g> a spam/unwanted caller?</string>
  <!-- Text for the toast shown after the user presses block/report spam. [CHAR LIMIT=100] -->
  <string translatable="false" name="spam_notification_block_report_toast_text_230154"><xliff:g id="number">%1$s</xliff:g> blocked and call was reported as spam/unwanted.</string>
  <!-- Text for the toast shown after the user presses not spam. [CHAR LIMIT=100] -->
  <string translatable="false" name="spam_notification_not_spam_toast_text_230154">Call from <xliff:g id="number">%1$s</xliff:g> reported as not spam/unwanted.</string>
  <!-- Text displayed in the collapsed notification to the user after a non-spam call ends. [CHAR LIMIT=100] -->
  <string translatable="false" name="spam_notification_non_spam_call_collapsed_text_230154">Tap to add to contacts or block spam/unwanted number.</string>
  <!-- Text displayed in the expanded notification to the user after a non-spam call ends. [CHAR LIMIT=NONE] -->
  <string translatable="false" name="spam_notification_non_spam_call_expanded_text_230154">This is the first time this number called you. If this call was spam/unwanted, you can block this number and report it.</string>
  <!-- Text displayed in the collapsed notification to the user after a spam call ends. [CHAR LIMIT=100] -->
  <string translatable="false" name="spam_notification_spam_call_collapsed_text_230154">Tap to report as not spam/unwanted or block it</string>
  <!-- Text for the blocking and reporting spam action in the after call dialog. [CHAR LIMIT=40] -->
  <string translatable="false" name="spam_notification_dialog_block_report_spam_action_text_230154">Block &amp; report spam/unwanted</string>
  <!-- Text for the marking a call as not spam in the after call prompt. [CHAR LIMIT=40] -->
  <string translatable="false" name="spam_notification_was_not_spam_action_text_230154">No, not spam/unwanted</string>

  <!-- Strings for 'junk/unwanted' spam word alternative-->
  <!-- Title for the notification to the user after a call from an spammer ends. [CHAR LIMIT=100] -->
  <string translatable="false" name="spam_notification_title_230155">Was <xliff:g id="number">%1$s</xliff:g> a junk/unwanted caller?</string>
  <!-- Text for the toast shown after the user presses block/report spam. [CHAR LIMIT=100] -->
  <string translatable="false" name="spam_notification_block_report_toast_text_230155"><xliff:g id="number">%1$s</xliff:g> blocked and call was reported as junk/unwanted.</string>
  <!-- Text for the toast shown after the user presses not spam. [CHAR LIMIT=100] -->
  <string translatable="false" name="spam_notification_not_spam_toast_text_230155">Call from <xliff:g id="number">%1$s</xliff:g> reported as not junk/unwanted.</string>
  <!-- Text displayed in the collapsed notification to the user after a non-spam call ends. [CHAR LIMIT=100] -->
  <string translatable="false" name="spam_notification_non_spam_call_collapsed_text_230155">Tap to add to contacts or block junk/unwanted number.</string>
  <!-- Text displayed in the expanded notification to the user after a non-spam call ends. [CHAR LIMIT=NONE] -->
  <string translatable="false" name="spam_notification_non_spam_call_expanded_text_230155">This is the first time this number called you. If this call was junk/unwanted, you can block this number and report it.</string>
  <!-- Text displayed in the collapsed notification to the user after a spam call ends. [CHAR LIMIT=100] -->
  <string translatable="false" name="spam_notification_spam_call_collapsed_text_230155">Tap to report as not junk/unwanted or block it</string>
  <!-- Text for the blocking and reporting spam action in the after call dialog. [CHAR LIMIT=40] -->
  <string translatable="false" name="spam_notification_dialog_block_report_spam_action_text_230155">Block &amp; report junk/unwanted</string>
  <!-- Text for the marking a call as not spam in the after call prompt. [CHAR LIMIT=40] -->
  <string translatable="false" name="spam_notification_was_not_spam_action_text_230155">No, not junk/unwanted</string>


  <!-- Label for "Dismiss" dialog action. [CHAR LIMIT=12] -->
  <string name="spam_notification_action_dismiss">Dismiss</string>