summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStephen Bird <sbird@cyngn.com>2016-06-10 12:00:17 -0700
committerStephen Bird <sbird@cyngn.com>2016-06-10 16:24:48 -0700
commit5287347effa7cb26f19dfa511208e0f747009dc8 (patch)
treeed597969d98f4816e003574c177b6d48f328e62c /src
parent49ee0372aa2018ff5ccf93b1595e589bd21553f7 (diff)
downloadandroid_packages_apps_Dialer-5287347effa7cb26f19dfa511208e0f747009dc8.tar.gz
android_packages_apps_Dialer-5287347effa7cb26f19dfa511208e0f747009dc8.tar.bz2
android_packages_apps_Dialer-5287347effa7cb26f19dfa511208e0f747009dc8.zip
Increment nudge only after shown intent returns
Previously there was a chance that a nudge would be sent to discovery but then not shown. Ticket: CD-681 Change-Id: I8671a83b23ed77b2ae1fabcfcdf4a01ec5eae108
Diffstat (limited to 'src')
-rw-r--r--src/com/android/dialer/discovery/DiscoveryEventHandler.java48
-rw-r--r--src/com/android/dialer/discovery/DiscoverySignalReceiver.java10
-rw-r--r--src/com/android/dialer/discovery/WifiCallStatusNudgeListener.java9
3 files changed, 41 insertions, 26 deletions
diff --git a/src/com/android/dialer/discovery/DiscoveryEventHandler.java b/src/com/android/dialer/discovery/DiscoveryEventHandler.java
index eac2b3d6b..c73038baf 100644
--- a/src/com/android/dialer/discovery/DiscoveryEventHandler.java
+++ b/src/com/android/dialer/discovery/DiscoveryEventHandler.java
@@ -91,8 +91,12 @@ public class DiscoveryEventHandler {
Bundle b = theEntry.getValue();
+ // If we are ready to show the nudge, then we will not increment the
+ // count here. Instead the count will be incremented in
+ // DiscoverySignalReceiver when the nudge is properly shown.
if (!validateShouldShowNudge(key, b) && !isTesting) {
- // Nudge not yet ready for this item.
+ // Nudge not yet ready for this item. increment event count
+ incrementCount(key, mContext);
continue;
}
@@ -238,16 +242,9 @@ public class DiscoveryEventHandler {
SharedPreferences preferences = mContext.getSharedPreferences(DialtactsActivity
.SHARED_PREFS_NAME, Context.MODE_PRIVATE);
- int count = 0;
-
- // The count starts at 1 here because this is the first time we've seen this item.
- if (key.equals(NudgeKey.NOTIFICATION_INTERNATIONAL_CALL)) {
- count = preferences.getInt(CallMethodUtils.PREF_INTERNATIONAL_CALLS, 1);
- } else if (key.equals(NudgeKey.NOTIFICATION_WIFI_CALL)) {
- count = preferences.getInt(CallMethodUtils.PREF_WIFI_CALL, 1);
- } else if (key.equals(NudgeKey.NOTIFICATION_ROAMING)) {
- count = preferences.getInt(CallMethodUtils.PREF_ROAMING_CALLS, 1);
- }
+ String preferenceKey = getPreferenceKeyForNudgeKey(key);
+ // If the preference does not exist then this is the first event so default to 1;
+ int count = preferences.getInt(preferenceKey, 1);
checkCount = (count == b.getInt(NudgeKey.NOTIFICATION_PARAM_EVENTS_FIRST_NUDGE, 0)) ||
(count == b.getInt(NudgeKey.NOTIFICATION_PARAM_EVENTS_SECOND_NUDGE, 0));
@@ -256,4 +253,33 @@ public class DiscoveryEventHandler {
return checkCount;
}
+ private static String getPreferenceKeyForNudgeKey(String nudgeKey) {
+ String prefKey = null;
+ switch(nudgeKey) {
+ case NudgeKey.NOTIFICATION_INTERNATIONAL_CALL:
+ prefKey = CallMethodUtils.PREF_INTERNATIONAL_CALLS;
+ break;
+ case NudgeKey.NOTIFICATION_WIFI_CALL:
+ prefKey = CallMethodUtils.PREF_WIFI_CALL;
+ break;
+ case NudgeKey.NOTIFICATION_ROAMING:
+ prefKey = CallMethodUtils.PREF_ROAMING_CALLS;
+ break;
+ }
+ return prefKey;
+ }
+
+ public static void incrementCount(String nudgeKey, Context context) {
+ String prefKey = getPreferenceKeyForNudgeKey(nudgeKey);
+
+ if (prefKey != null) {
+ SharedPreferences nudgePrefs = context.getSharedPreferences(
+ DialtactsActivity.SHARED_PREFS_NAME, Context.MODE_PRIVATE);
+ // If the preference does not exist then set default to zero so when we increment it
+ // right after then we will have the correct value (1).
+ int currentCount = nudgePrefs.getInt(prefKey, 0);
+ nudgePrefs.edit().putInt(prefKey, ++currentCount).apply();
+ }
+ }
+
}
diff --git a/src/com/android/dialer/discovery/DiscoverySignalReceiver.java b/src/com/android/dialer/discovery/DiscoverySignalReceiver.java
index 680426543..da7d2aed6 100644
--- a/src/com/android/dialer/discovery/DiscoverySignalReceiver.java
+++ b/src/com/android/dialer/discovery/DiscoverySignalReceiver.java
@@ -57,13 +57,7 @@ public class DiscoverySignalReceiver extends BroadcastReceiver {
switch (action) {
case Intent.ACTION_NEW_OUTGOING_CALL:
String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
- SharedPreferences preferences = context
- .getSharedPreferences(DialtactsActivity.SHARED_PREFS_NAME,
- Context.MODE_PRIVATE);
- int currentCount = preferences.getInt(CallMethodUtils.PREF_INTERNATIONAL_CALLS, 0);
if (isMaybeInternationalNumber(context, phoneNumber)) {
- preferences.edit().putInt(CallMethodUtils.PREF_INTERNATIONAL_CALLS,
- ++currentCount).apply();
startServiceForInternationalCallMade(context);
}
break;
@@ -90,6 +84,10 @@ public class DiscoverySignalReceiver extends BroadcastReceiver {
editor.putLong(timeKey, System.currentTimeMillis());
editor.apply();
+ // The nudge was shown, so we want to increment the count because this is a real
+ // event.
+ DiscoveryEventHandler.incrementCount(nudgeKey, context);
+
recordDiscoveryCount(nudgeComponent, nudgeKey,
InCallMetricsHelper.Parameters.COUNT);
diff --git a/src/com/android/dialer/discovery/WifiCallStatusNudgeListener.java b/src/com/android/dialer/discovery/WifiCallStatusNudgeListener.java
index 3990d27f4..570298304 100644
--- a/src/com/android/dialer/discovery/WifiCallStatusNudgeListener.java
+++ b/src/com/android/dialer/discovery/WifiCallStatusNudgeListener.java
@@ -140,20 +140,11 @@ public class WifiCallStatusNudgeListener {
private static void callOnWifiSuccess() {
if (DEBUG) Log.v(TAG, "call was made with wifi connected the whole time");
- SharedPreferences preferences = mContext
- .getSharedPreferences(DialtactsActivity.SHARED_PREFS_NAME, Context.MODE_PRIVATE);
-
- int currentCount;
// If the network is roaming and we are on wifi,
// then we want to show a potential roaming nudge instead of a wifi nudge.
if (mTelephonyManager.isNetworkRoaming()) {
- currentCount = preferences.getInt(CallMethodUtils.PREF_ROAMING_CALLS, 0);
- preferences.edit().putInt(CallMethodUtils.PREF_ROAMING_CALLS, ++currentCount).apply();
DiscoverySignalReceiver.startServiceForConnectivityChanged(mContext);
} else {
- currentCount = preferences.getInt(CallMethodUtils.PREF_WIFI_CALL, 0);
- preferences.edit().putInt(CallMethodUtils.PREF_WIFI_CALL, ++currentCount).apply();
-
new DiscoveryEventHandler(mContext).getNudgeProvidersWithKey(
NudgeKey.NOTIFICATION_WIFI_CALL);
}