summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStephen Bird <sbird@cyngn.com>2016-03-03 12:17:56 -0800
committerStephen Bird <sbird@cyngn.com>2016-04-08 10:21:12 -0700
commit29023771eab16b7ae07f8d595ea71919255da9a7 (patch)
treea92d549cf77c7594dc18d5de982490cceda18631 /src
parent7ae75d5e5dcce54308adc4304ff0339af198fc25 (diff)
downloadandroid_packages_apps_Dialer-29023771eab16b7ae07f8d595ea71919255da9a7.tar.gz
android_packages_apps_Dialer-29023771eab16b7ae07f8d595ea71919255da9a7.tar.bz2
android_packages_apps_Dialer-29023771eab16b7ae07f8d595ea71919255da9a7.zip
Add Wifi Call nudge
If we make a call and are on wifi the entire time, we could have placed this call via an incall provider. Allow the provider to nudge the user about this depending on certain event counts. Similar to the international call nudge. Also, fix a bug where nudge providers do not have a nudge that we are requesting. Ticket: CD-428 Change-Id: Icb291630e1b57252f94cdcf65213c6a480b845a6
Diffstat (limited to 'src')
-rw-r--r--src/com/android/dialer/DialerApplication.java3
-rw-r--r--src/com/android/dialer/discovery/DiscoveryEventHandler.java49
-rw-r--r--src/com/android/dialer/discovery/WifiCallStatusNudgeListener.java146
3 files changed, 184 insertions, 14 deletions
diff --git a/src/com/android/dialer/DialerApplication.java b/src/com/android/dialer/DialerApplication.java
index 3e762632a..325320ea6 100644
--- a/src/com/android/dialer/DialerApplication.java
+++ b/src/com/android/dialer/DialerApplication.java
@@ -21,6 +21,7 @@ import android.os.Trace;
import com.android.contacts.common.extensions.ExtensionsFactory;
import com.android.contacts.commonbind.analytics.AnalyticsUtil;
+import com.android.dialer.discovery.WifiCallStatusNudgeListener;
import com.android.phone.common.incall.CallMethodHelper;
import com.android.dialer.util.MetricsHelper;
@@ -46,6 +47,8 @@ public class DialerApplication extends Application {
CallMethodHelper.init(this);
MetricsHelper.init(this);
+ WifiCallStatusNudgeListener.init(this);
Trace.endSection();
+
}
}
diff --git a/src/com/android/dialer/discovery/DiscoveryEventHandler.java b/src/com/android/dialer/discovery/DiscoveryEventHandler.java
index 512538717..d16442065 100644
--- a/src/com/android/dialer/discovery/DiscoveryEventHandler.java
+++ b/src/com/android/dialer/discovery/DiscoveryEventHandler.java
@@ -64,17 +64,23 @@ public class DiscoveryEventHandler {
Map nudgePlugins =
NudgeServices.NudgeApi.getAvailableNudgesForKey(client, key).await().components;
+ ArrayList<NotificationNudge> notificationNudges = new ArrayList<>();
+
+ if (nudgePlugins == null) {
+ return notificationNudges;
+ }
+
InCallApi api = InCallServices.getInstance();
List<ComponentName> plugins = api.getInstalledPlugins(client).await().components;
HashMap<String, Bundle> availableNudges = new HashMap<>();
+
for (Object entry : nudgePlugins.entrySet()) {
Map.Entry<ComponentName, Bundle> theEntry = (Map.Entry<ComponentName, Bundle>) entry;
availableNudges.put(theEntry.getKey().getPackageName(), theEntry.getValue());
}
- ArrayList<NotificationNudge> notificationNudges = new ArrayList<>();
if (plugins != null && plugins.size() > 0) {
@@ -87,19 +93,9 @@ public class DiscoveryEventHandler {
Bundle b = availableNudges.get(component.getPackageName());
- if (key.equals(NudgeKey.NOTIFICATION_INTERNATIONAL_CALL)) {
- SharedPreferences preferences = context
- .getSharedPreferences(DialtactsActivity.SHARED_PREFS_NAME,
- Context.MODE_PRIVATE);
- int count = preferences.getInt(CallMethodUtils.PREF_INTERNATIONAL_CALLS, 0);
- boolean checkCount =
- count != b.getInt(NudgeKey.NOTIFICATION_PARAM_EVENTS_FIRST_NUDGE) ||
- count != b.getInt(NudgeKey.NOTIFICATION_PARAM_EVENTS_SECOND_NUDGE);
-
- if (checkCount) {
- // Nudge not yet ready for this item.
- continue;
- }
+ if (validateShouldShowNudge(key, context, b)) {
+ // Nudge not yet ready for this item.
+ continue;
}
if (DEBUG_STATUS || (statusResult.status != PluginStatus.DISABLED &&
@@ -150,4 +146,29 @@ public class DiscoveryEventHandler {
}
return notificationNudges;
}
+
+ private static boolean validateShouldShowNudge(String key, Context c, Bundle b) {
+
+ boolean checkCount = false;
+
+ SharedPreferences preferences = c.getSharedPreferences(DialtactsActivity.SHARED_PREFS_NAME,
+ Context.MODE_PRIVATE);
+
+ int count = 0;
+
+ if (key.equals(NudgeKey.NOTIFICATION_INTERNATIONAL_CALL)) {
+ count = preferences.getInt(CallMethodUtils.PREF_INTERNATIONAL_CALLS, 0);
+ } else if (key.equals(NudgeKey.NOTIFICATION_WIFI_CALL)) {
+ count = preferences.getInt(CallMethodUtils.PREF_WIFI_CALL, 0);
+ }
+
+ checkCount =
+ count == b.getInt(NudgeKey.NOTIFICATION_PARAM_EVENTS_FIRST_NUDGE, 0) ||
+ count == b.getInt(NudgeKey.NOTIFICATION_PARAM_EVENTS_SECOND_NUDGE, 0);
+
+ // return true if nudge should be shown
+ return checkCount;
+
+ }
+
}
diff --git a/src/com/android/dialer/discovery/WifiCallStatusNudgeListener.java b/src/com/android/dialer/discovery/WifiCallStatusNudgeListener.java
new file mode 100644
index 000000000..a1f12c0ed
--- /dev/null
+++ b/src/com/android/dialer/discovery/WifiCallStatusNudgeListener.java
@@ -0,0 +1,146 @@
+package com.android.dialer.discovery;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.SharedPreferences;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+import android.net.wifi.WifiManager;
+import android.os.Handler;
+import android.os.Message;
+import android.telephony.PhoneStateListener;
+import android.telephony.TelephonyManager;
+import android.util.Log;
+import com.android.dialer.DialtactsActivity;
+import com.android.phone.common.incall.CallMethodUtils;
+import com.cyanogen.ambient.discovery.util.NudgeKey;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * Listener to monitor and count calls that have wifi connected the entire time.
+ */
+public class WifiCallStatusNudgeListener {
+
+ private final static String TAG = WifiCallStatusNudgeListener.class.getSimpleName();
+ private final static boolean DEBUG = false;
+
+ private final static AtomicBoolean mReceiverRegistered = new AtomicBoolean(false);
+ private final static int WIFI_STATE_DISABLED = 0;
+ private final static int CALL_STATE_IDLE = 1;
+ private final static int CALL_STATE_OFFHOOK = 2;
+
+ private static Context mContext;
+
+ private static BroadcastReceiver mWifiListener = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ int state = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
+ WifiManager.WIFI_STATE_UNKNOWN);
+ if (DEBUG) Log.v(TAG, "Got wifi state: " + state);
+ if (state == WifiManager.WIFI_STATE_DISABLED) {
+ Message phoneStateMessage
+ = mPhoneWifiStateHandler.obtainMessage(WIFI_STATE_DISABLED);
+ phoneStateMessage.sendToTarget();
+ }
+ }
+ };
+
+ private static Handler mPhoneWifiStateHandler = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ switch(msg.what) {
+ case CALL_STATE_OFFHOOK:
+ ConnectivityManager connManager = (ConnectivityManager) mContext
+ .getSystemService(Context.CONNECTIVITY_SERVICE);
+ NetworkInfo mWifi
+ = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
+
+ // If wifi is connected when we first get the OFFHOOK state, start a receiver to
+ // watch for wifi connection slips during the call.
+ if (mWifi.isConnected()) {
+ startReceiver();
+ } else {
+ callOnWifiFailure();
+ }
+ break;
+ case CALL_STATE_IDLE:
+ synchronized (mReceiverRegistered) {
+ if (mReceiverRegistered.get()) {
+ // We lasted the whole call
+ stopReceiver();
+ callOnWifiSuccess();
+ } else {
+ callOnWifiFailure();
+ }
+ }
+ break;
+ case WIFI_STATE_DISABLED:
+ stopReceiver();
+ break;
+ }
+ super.handleMessage(msg);
+ }
+ };
+
+ private static PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
+ @Override
+ public void onCallStateChanged(int state, String incomingNumber) {
+ super.onCallStateChanged(state, incomingNumber);
+ if (state == TelephonyManager.CALL_STATE_IDLE) {
+ Message phoneStateMessage
+ = mPhoneWifiStateHandler.obtainMessage(CALL_STATE_IDLE);
+ phoneStateMessage.sendToTarget();
+ } else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
+ Message phoneStateMessage
+ = mPhoneWifiStateHandler.obtainMessage(CALL_STATE_OFFHOOK);
+ phoneStateMessage.sendToTarget();
+ }
+ }
+ };
+
+ public static void init(Context c) {
+ mContext = c;
+ mReceiverRegistered.set(false);
+
+ TelephonyManager telephony
+ = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
+ telephony.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
+ }
+
+ private static void startReceiver() {
+ synchronized (mReceiverRegistered) {
+ if (DEBUG) Log.v(TAG, "Receiver starting...");
+ IntentFilter intFilter = new IntentFilter();
+ intFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
+ mContext.registerReceiver(mWifiListener, intFilter);
+ mReceiverRegistered.set(true);
+ }
+ }
+
+ private static void stopReceiver() {
+ synchronized (mReceiverRegistered) {
+ if (DEBUG) Log.v(TAG, "Receiver stopping...");
+ mContext.unregisterReceiver(mWifiListener);
+ mReceiverRegistered.set(false);
+ }
+ }
+
+ 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 = preferences.getInt(CallMethodUtils.PREF_WIFI_CALL, 0);
+ preferences.edit().putInt(CallMethodUtils.PREF_WIFI_CALL, ++currentCount).apply();
+
+ DiscoveryEventHandler.getNudgeProvidersWithKey(mContext, NudgeKey.NOTIFICATION_WIFI_CALL);
+ }
+
+ private static void callOnWifiFailure() {
+ if (DEBUG) Log.v(TAG, "call was made with wifi not connected at some point");
+ }
+}