diff options
author | Irfan Sheriff <isheriff@google.com> | 2011-09-06 10:56:53 -0700 |
---|---|---|
committer | Irfan Sheriff <isheriff@google.com> | 2011-09-06 11:51:30 -0700 |
commit | daf57e5ff495684f93d9ac2f5c5fc826a02f5f7a (patch) | |
tree | 06d44a9a154f2c89155d8329c5026a3713f7227a /wifi/java/android | |
parent | 4be4d31f34a0fd0e23de1cbda311c07412f8d0b8 (diff) | |
download | frameworks_base-daf57e5ff495684f93d9ac2f5c5fc826a02f5f7a.zip frameworks_base-daf57e5ff495684f93d9ac2f5c5fc826a02f5f7a.tar.gz frameworks_base-daf57e5ff495684f93d9ac2f5c5fc826a02f5f7a.tar.bz2 |
Add notification when p2p is enabled
Bug: 5262278
Change-Id: I82890323c4e4e2952b4c9c9bc503856095d90c21
Diffstat (limited to 'wifi/java/android')
-rw-r--r-- | wifi/java/android/net/wifi/p2p/WifiP2pService.java | 43 |
1 files changed, 43 insertions, 0 deletions
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 @@ public class WifiP2pService extends IWifiP2pManager.Stub { private Context mContext; private String mInterface; + private Notification mNotification; INetworkManagementService mNwService; private DhcpStateMachine mDhcpStateMachine; @@ -605,6 +609,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub { sendP2pStateChangedBroadcast(true); mNetworkInfo.setIsAvailable(true); initializeP2pSettings(); + showNotification(); } @Override @@ -695,6 +700,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub { public void exit() { sendP2pStateChangedBroadcast(false); mNetworkInfo.setIsAvailable(false); + clearNotification(); } } @@ -1218,5 +1224,42 @@ public class WifiP2pService extends IWifiP2pManager.Stub { 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; + } + } + } } |