From e6f53f470df53a481b6189438d4ac38cf24e3463 Mon Sep 17 00:00:00 2001 From: Android Dialer Date: Mon, 21 May 2018 13:16:45 -0700 Subject: 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 --- .../spam/SpamAlternativeExperimentUtil.java | 52 +++++++++++++ .../incallui/spam/SpamCallListListener.java | 24 ++++-- .../incallui/spam/SpamNotificationActivity.java | 17 +++- .../android/incallui/spam/res/values/strings.xml | 91 ++++++++++++++++++++++ 4 files changed, 175 insertions(+), 9 deletions(-) create mode 100644 java/com/android/incallui/spam/SpamAlternativeExperimentUtil.java diff --git a/java/com/android/incallui/spam/SpamAlternativeExperimentUtil.java b/java/com/android/incallui/spam/SpamAlternativeExperimentUtil.java new file mode 100644 index 000000000..52eadcff3 --- /dev/null +++ b/java/com/android/incallui/spam/SpamAlternativeExperimentUtil.java @@ -0,0 +1,52 @@ +/* + * 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; + } +} diff --git a/java/com/android/incallui/spam/SpamCallListListener.java b/java/com/android/incallui/spam/SpamCallListListener.java index 350dd60fc..d03055568 100644 --- a/java/com/android/incallui/spam/SpamCallListListener.java +++ b/java/com/android/incallui/spam/SpamCallListListener.java @@ -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}. diff --git a/java/com/android/incallui/spam/SpamNotificationActivity.java b/java/com/android/incallui/spam/SpamNotificationActivity.java index 37755fc53..4c0c67c92 100644 --- a/java/com/android/incallui/spam/SpamNotificationActivity.java +++ b/java/com/android/incallui/spam/SpamNotificationActivity.java @@ -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) { diff --git a/java/com/android/incallui/spam/res/values/strings.xml b/java/com/android/incallui/spam/res/values/strings.xml index e893f2afc..7626754e3 100644 --- a/java/com/android/incallui/spam/res/values/strings.xml +++ b/java/com/android/incallui/spam/res/values/strings.xml @@ -44,6 +44,97 @@ Yes, block number + + + Was %1$s a junk caller? + + %1$s blocked and call was reported as junk. + + Call from %1$s reported as not junk. + + Tap to add to contacts or block junk number. + + This is the first time this number called you. If this call was junk, you can block this number and report it. + + Tap to report as not junk or block it + + Block & report junk + + No, not junk + + + + Was %1$s a junk/spam caller? + + %1$s blocked and call was reported as junk/spam. + + Call from %1$s reported as not junk/spam. + + Tap to add to contacts or block junk/spam number. + + This is the first time this number called you. If this call was junk/spam, you can block this number and report it. + + Tap to report as not junk/spam or block it + + Block & report junk/spam + + No, not junk/spam + + + + Was %1$s an unwanted caller? + + %1$s blocked and call was reported as unwanted. + + Call from %1$s reported as useful. + + Tap to add to contacts or block unwanted number. + + This is the first time this number called you. If this call was unwanted, you can block this number and report it. + + Tap to report as useful or block it + + Block & report unwanted + + No, not unwanted + + + + Was %1$s a spam/unwanted caller? + + %1$s blocked and call was reported as spam/unwanted. + + Call from %1$s reported as not spam/unwanted. + + Tap to add to contacts or block spam/unwanted number. + + This is the first time this number called you. If this call was spam/unwanted, you can block this number and report it. + + Tap to report as not spam/unwanted or block it + + Block & report spam/unwanted + + No, not spam/unwanted + + + + Was %1$s a junk/unwanted caller? + + %1$s blocked and call was reported as junk/unwanted. + + Call from %1$s reported as not junk/unwanted. + + Tap to add to contacts or block junk/unwanted number. + + This is the first time this number called you. If this call was junk/unwanted, you can block this number and report it. + + Tap to report as not junk/unwanted or block it + + Block & report junk/unwanted + + No, not junk/unwanted + + Dismiss -- cgit v1.2.3