summaryrefslogtreecommitdiffstats
path: root/java/com/android/incallui/answer/impl/hint
diff options
context:
space:
mode:
Diffstat (limited to 'java/com/android/incallui/answer/impl/hint')
-rw-r--r--java/com/android/incallui/answer/impl/hint/AnswerHintFactory.java32
-rw-r--r--java/com/android/incallui/answer/impl/hint/PawImageLoaderImpl.java25
-rw-r--r--java/com/android/incallui/answer/impl/hint/PawSecretCodeListener.java47
3 files changed, 67 insertions, 37 deletions
diff --git a/java/com/android/incallui/answer/impl/hint/AnswerHintFactory.java b/java/com/android/incallui/answer/impl/hint/AnswerHintFactory.java
index 77b45ec71..9c33b5de6 100644
--- a/java/com/android/incallui/answer/impl/hint/AnswerHintFactory.java
+++ b/java/com/android/incallui/answer/impl/hint/AnswerHintFactory.java
@@ -23,7 +23,6 @@ import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.VisibleForTesting;
import com.android.dialer.common.Assert;
-import com.android.dialer.common.ConfigProvider;
import com.android.dialer.common.ConfigProviderBindings;
import com.android.dialer.common.LogUtil;
import com.android.dialer.util.DialerUtils;
@@ -35,8 +34,9 @@ import com.android.incallui.util.AccessibilityUtil;
*/
public class AnswerHintFactory {
- private static final String CONFIG_ANSWER_HINT_ANSWERED_THRESHOLD_KEY =
- "answer_hint_answered_threshold";
+ @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
+ static final String CONFIG_ANSWER_HINT_ANSWERED_THRESHOLD_KEY = "answer_hint_answered_threshold";
+
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
static final String CONFIG_ANSWER_HINT_WHITELISTED_DEVICES_KEY =
"answer_hint_whitelisted_devices";
@@ -58,12 +58,7 @@ public class AnswerHintFactory {
@NonNull
public AnswerHint create(Context context, long puckUpDuration, long puckUpDelay) {
-
- if (shouldShowAnswerHint(
- context,
- ConfigProviderBindings.get(context),
- DialerUtils.getDefaultSharedPreferenceForDeviceProtectedStorageContext(context),
- Build.PRODUCT)) {
+ if (shouldShowAnswerHint(context, Build.PRODUCT)) {
return new DotAnswerHint(context, puckUpDuration, puckUpDelay);
}
@@ -84,24 +79,23 @@ public class AnswerHintFactory {
}
@VisibleForTesting
- static boolean shouldShowAnswerHint(
- Context context,
- ConfigProvider configProvider,
- SharedPreferences sharedPreferences,
- String device) {
+ static boolean shouldShowAnswerHint(Context context, String device) {
if (AccessibilityUtil.isTouchExplorationEnabled(context)) {
return false;
}
// Devices that has the legacy dialer installed are whitelisted as they are likely to go through
// a UX change during updates.
- if (!isDeviceWhitelisted(device, configProvider)) {
+ if (!isDeviceWhitelisted(context, device)) {
return false;
}
// If the user has gone through the process a few times we can assume they have learnt the
// method.
- int answeredCount = sharedPreferences.getInt(ANSWERED_COUNT_PREFERENCE_KEY, 0);
- long threshold = configProvider.getLong(CONFIG_ANSWER_HINT_ANSWERED_THRESHOLD_KEY, 3);
+ int answeredCount =
+ DialerUtils.getDefaultSharedPreferenceForDeviceProtectedStorageContext(context)
+ .getInt(ANSWERED_COUNT_PREFERENCE_KEY, 0);
+ long threshold =
+ ConfigProviderBindings.get(context).getLong(CONFIG_ANSWER_HINT_ANSWERED_THRESHOLD_KEY, 3);
LogUtil.i(
"AnswerHintFactory.shouldShowAnswerHint",
"answerCount: %d, threshold: %d",
@@ -115,8 +109,8 @@ public class AnswerHintFactory {
* @param configProvider should provide a list of devices quoted with '/' concatenated to a
* string.
*/
- private static boolean isDeviceWhitelisted(String device, ConfigProvider configProvider) {
- return configProvider
+ private static boolean isDeviceWhitelisted(Context context, String device) {
+ return ConfigProviderBindings.get(context)
.getString(CONFIG_ANSWER_HINT_WHITELISTED_DEVICES_KEY, DEFAULT_WHITELISTED_DEVICES_CSV)
.contains("/" + device + "/");
}
diff --git a/java/com/android/incallui/answer/impl/hint/PawImageLoaderImpl.java b/java/com/android/incallui/answer/impl/hint/PawImageLoaderImpl.java
index 21154cade..05358d831 100644
--- a/java/com/android/incallui/answer/impl/hint/PawImageLoaderImpl.java
+++ b/java/com/android/incallui/answer/impl/hint/PawImageLoaderImpl.java
@@ -24,7 +24,9 @@ import android.os.Build.VERSION_CODES;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.android.dialer.common.Assert;
+import com.android.dialer.common.LogUtil;
import com.android.dialer.util.DialerUtils;
+import com.android.incallui.answer.impl.hint.PawSecretCodeListener.PawType;
/** Decrypt the event payload to be shown if in a specific time range and the key is received. */
@TargetApi(VERSION_CODES.M)
@@ -40,10 +42,25 @@ public final class PawImageLoaderImpl implements PawImageLoader {
if (!preferences.getBoolean(PawSecretCodeListener.PAW_ENABLED_WITH_SECRET_CODE_KEY, false)) {
return null;
}
- int drawableId = preferences.getInt(PawSecretCodeListener.PAW_DRAWABLE_ID_KEY, 0);
- if (drawableId == 0) {
- return null;
+ @PawType
+ int pawType =
+ preferences.getInt(PawSecretCodeListener.PAW_TYPE, PawSecretCodeListener.PAW_TYPE_INVALID);
+
+ if (pawType == PawSecretCodeListener.PAW_TYPE_INVALID) {
+ LogUtil.i("PawImageLoaderImpl.loadPayload", "paw type not found, rerolling");
+ PawSecretCodeListener.selectPawType(preferences);
+ pawType =
+ preferences.getInt(
+ PawSecretCodeListener.PAW_TYPE, PawSecretCodeListener.PAW_TYPE_INVALID);
+ }
+
+ switch (pawType) {
+ case PawSecretCodeListener.PAW_TYPE_CAT:
+ return context.getDrawable(R.drawable.cat_paw);
+ case PawSecretCodeListener.PAW_TYPE_DOG:
+ return context.getDrawable(R.drawable.dog_paw);
+ default:
+ throw Assert.createAssertionFailException("unknown paw type " + pawType);
}
- return context.getDrawable(drawableId);
}
}
diff --git a/java/com/android/incallui/answer/impl/hint/PawSecretCodeListener.java b/java/com/android/incallui/answer/impl/hint/PawSecretCodeListener.java
index a8737c363..3b4512c4f 100644
--- a/java/com/android/incallui/answer/impl/hint/PawSecretCodeListener.java
+++ b/java/com/android/incallui/answer/impl/hint/PawSecretCodeListener.java
@@ -20,7 +20,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
-import android.preference.PreferenceManager;
+import android.support.annotation.IntDef;
import android.support.annotation.VisibleForTesting;
import android.text.TextUtils;
import android.widget.Toast;
@@ -29,6 +29,7 @@ import com.android.dialer.common.ConfigProviderBindings;
import com.android.dialer.common.LogUtil;
import com.android.dialer.logging.DialerImpression.Type;
import com.android.dialer.logging.Logger;
+import com.android.dialer.util.DialerUtils;
import java.util.Random;
/**
@@ -40,7 +41,20 @@ public class PawSecretCodeListener extends BroadcastReceiver {
static final String CONFIG_PAW_SECRET_CODE = "paw_secret_code";
public static final String PAW_ENABLED_WITH_SECRET_CODE_KEY = "paw_enabled_with_secret_code";
- public static final String PAW_DRAWABLE_ID_KEY = "paw_drawable_id";
+
+ /** Which paw to show, must be {@link PawType} */
+ public static final String PAW_TYPE = "paw_type";
+
+ /** Resource id is not stable across app versions. Use {@link #PAW_TYPE} instead. */
+ @Deprecated public static final String PAW_DRAWABLE_ID_KEY = "paw_drawable_id";
+
+ /** Enum for all paws. */
+ @IntDef({PAW_TYPE_INVALID, PAW_TYPE_CAT, PAW_TYPE_DOG})
+ @interface PawType {}
+
+ public static final int PAW_TYPE_INVALID = 0;
+ public static final int PAW_TYPE_CAT = 1;
+ public static final int PAW_TYPE_DOG = 2;
@Override
public void onReceive(Context context, Intent intent) {
@@ -54,7 +68,8 @@ public class PawSecretCodeListener extends BroadcastReceiver {
if (!TextUtils.equals(secretCode, host)) {
return;
}
- SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
+ SharedPreferences preferences =
+ DialerUtils.getDefaultSharedPreferenceForDeviceProtectedStorageContext(context);
boolean wasEnabled = preferences.getBoolean(PAW_ENABLED_WITH_SECRET_CODE_KEY, false);
if (wasEnabled) {
preferences.edit().putBoolean(PAW_ENABLED_WITH_SECRET_CODE_KEY, false).apply();
@@ -62,20 +77,24 @@ public class PawSecretCodeListener extends BroadcastReceiver {
Logger.get(context).logImpression(Type.EVENT_ANSWER_HINT_DEACTIVATED);
LogUtil.i("PawSecretCodeListener.onReceive", "PawAnswerHint disabled");
} else {
- int drawableId;
- if (new Random().nextBoolean()) {
- drawableId = R.drawable.cat_paw;
- } else {
- drawableId = R.drawable.dog_paw;
- }
- preferences
- .edit()
- .putBoolean(PAW_ENABLED_WITH_SECRET_CODE_KEY, true)
- .putInt(PAW_DRAWABLE_ID_KEY, drawableId)
- .apply();
+ selectPawType(preferences);
Toast.makeText(context, R.string.event_activated, Toast.LENGTH_SHORT).show();
Logger.get(context).logImpression(Type.EVENT_ANSWER_HINT_ACTIVATED);
LogUtil.i("PawSecretCodeListener.onReceive", "PawAnswerHint enabled");
}
}
+
+ public static void selectPawType(SharedPreferences preferences) {
+ @PawType int pawType;
+ if (new Random().nextBoolean()) {
+ pawType = PAW_TYPE_CAT;
+ } else {
+ pawType = PAW_TYPE_DOG;
+ }
+ preferences
+ .edit()
+ .putBoolean(PAW_ENABLED_WITH_SECRET_CODE_KEY, true)
+ .putInt(PAW_TYPE, pawType)
+ .apply();
+ }
}