Add notification when p2p is enabled

Bug: 5262278
Change-Id: I82890323c4e4e2952b4c9c9bc503856095d90c21
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index a9e2971..9cd2d16 100755
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -2681,6 +2681,8 @@
     <string name="wifi_p2p_pbc_go_negotiation_request_message">Wi-Fi Direct connection setup request from <xliff:g id="p2p_device_address">%1$s</xliff:g>. Click OK to accept. </string>
     <string name="wifi_p2p_pin_go_negotiation_request_message">Wi-Fi Direct connection setup request from <xliff:g id="p2p_device_address">%1$s</xliff:g>. Enter pin to proceed. </string>
     <string name="wifi_p2p_pin_display_message">WPS pin <xliff:g id="p2p_wps_pin">%1$s</xliff:g> needs to be entered on the peer device <xliff:g id="p2p_client_address">%2$s</xliff:g> for connection setup to proceed </string>
+    <string name="wifi_p2p_enabled_notification_title">Wi-Fi Direct is on</string>
+    <string name="wifi_p2p_enabled_notification_message">Touch for settings</string>
 
     <!-- Name of the dialog that lets the user choose an accented character to insert -->
     <string name="select_character">Insert character</string>
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pService.java b/wifi/java/android/net/wifi/p2p/WifiP2pService.java
index 333160f..5297302 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pService.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pService.java
@@ -17,6 +17,9 @@
 package android.net.wifi.p2p;
 
 import android.app.AlertDialog;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.DialogInterface;
@@ -84,6 +87,7 @@
 
     private Context mContext;
     private String mInterface;
+    private Notification mNotification;
 
     INetworkManagementService mNwService;
     private DhcpStateMachine mDhcpStateMachine;
@@ -605,6 +609,7 @@
             sendP2pStateChangedBroadcast(true);
             mNetworkInfo.setIsAvailable(true);
             initializeP2pSettings();
+            showNotification();
         }
 
         @Override
@@ -695,6 +700,7 @@
         public void exit() {
             sendP2pStateChangedBroadcast(false);
             mNetworkInfo.setIsAvailable(false);
+            clearNotification();
         }
     }
 
@@ -1218,5 +1224,42 @@
         Slog.e(TAG, s);
     }
 
+    private void showNotification() {
+        NotificationManager notificationManager =
+            (NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE);
+        if (notificationManager == null || mNotification != null) {
+            return;
+        }
+
+        Intent intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS);
+        intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
+
+        PendingIntent pi = PendingIntent.getActivity(mContext, 0, intent, 0);
+
+        Resources r = Resources.getSystem();
+        CharSequence title = r.getText(R.string.wifi_p2p_enabled_notification_title);
+        CharSequence message = r.getText(R.string.wifi_p2p_enabled_notification_message);
+
+        mNotification = new Notification();
+        mNotification.when = 0;
+        //TODO: might change to be a seperate icon
+        mNotification.icon = R.drawable.stat_sys_tether_wifi;
+        mNotification.defaults &= ~Notification.DEFAULT_SOUND;
+        mNotification.flags = Notification.FLAG_ONGOING_EVENT;
+        mNotification.tickerText = title;
+        mNotification.setLatestEventInfo(mContext, title, message, pi);
+
+        notificationManager.notify(mNotification.icon, mNotification);
+    }
+
+    private void clearNotification() {
+        NotificationManager notificationManager =
+            (NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE);
+        if (notificationManager != null && mNotification != null) {
+            notificationManager.cancel(mNotification.icon);
+            mNotification = null;
+        }
+    }
+
     }
 }