|
17 | 17 | package android.net.wifi.p2p; |
18 | 18 |
|
19 | 19 | import android.app.AlertDialog; |
| 20 | +import android.app.Notification; |
| 21 | +import android.app.NotificationManager; |
| 22 | +import android.app.PendingIntent; |
20 | 23 | import android.content.BroadcastReceiver; |
21 | 24 | import android.content.Context; |
22 | 25 | import android.content.DialogInterface; |
@@ -84,6 +87,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub { |
84 | 87 |
|
85 | 88 | private Context mContext; |
86 | 89 | private String mInterface; |
| 90 | + private Notification mNotification; |
87 | 91 |
|
88 | 92 | INetworkManagementService mNwService; |
89 | 93 | private DhcpStateMachine mDhcpStateMachine; |
@@ -605,6 +609,7 @@ public void enter() { |
605 | 609 | sendP2pStateChangedBroadcast(true); |
606 | 610 | mNetworkInfo.setIsAvailable(true); |
607 | 611 | initializeP2pSettings(); |
| 612 | + showNotification(); |
608 | 613 | } |
609 | 614 |
|
610 | 615 | @Override |
@@ -695,6 +700,7 @@ public boolean processMessage(Message message) { |
695 | 700 | public void exit() { |
696 | 701 | sendP2pStateChangedBroadcast(false); |
697 | 702 | mNetworkInfo.setIsAvailable(false); |
| 703 | + clearNotification(); |
698 | 704 | } |
699 | 705 | } |
700 | 706 |
|
@@ -1218,5 +1224,42 @@ private void loge(String s) { |
1218 | 1224 | Slog.e(TAG, s); |
1219 | 1225 | } |
1220 | 1226 |
|
| 1227 | + private void showNotification() { |
| 1228 | + NotificationManager notificationManager = |
| 1229 | + (NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE); |
| 1230 | + if (notificationManager == null || mNotification != null) { |
| 1231 | + return; |
| 1232 | + } |
| 1233 | + |
| 1234 | + Intent intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS); |
| 1235 | + intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); |
| 1236 | + |
| 1237 | + PendingIntent pi = PendingIntent.getActivity(mContext, 0, intent, 0); |
| 1238 | + |
| 1239 | + Resources r = Resources.getSystem(); |
| 1240 | + CharSequence title = r.getText(R.string.wifi_p2p_enabled_notification_title); |
| 1241 | + CharSequence message = r.getText(R.string.wifi_p2p_enabled_notification_message); |
| 1242 | + |
| 1243 | + mNotification = new Notification(); |
| 1244 | + mNotification.when = 0; |
| 1245 | + //TODO: might change to be a seperate icon |
| 1246 | + mNotification.icon = R.drawable.stat_sys_tether_wifi; |
| 1247 | + mNotification.defaults &= ~Notification.DEFAULT_SOUND; |
| 1248 | + mNotification.flags = Notification.FLAG_ONGOING_EVENT; |
| 1249 | + mNotification.tickerText = title; |
| 1250 | + mNotification.setLatestEventInfo(mContext, title, message, pi); |
| 1251 | + |
| 1252 | + notificationManager.notify(mNotification.icon, mNotification); |
| 1253 | + } |
| 1254 | + |
| 1255 | + private void clearNotification() { |
| 1256 | + NotificationManager notificationManager = |
| 1257 | + (NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE); |
| 1258 | + if (notificationManager != null && mNotification != null) { |
| 1259 | + notificationManager.cancel(mNotification.icon); |
| 1260 | + mNotification = null; |
| 1261 | + } |
| 1262 | + } |
| 1263 | + |
1221 | 1264 | } |
1222 | 1265 | } |
0 commit comments