Skip to content

Commit 8b55e92

Browse files
isheriffAndroid (Google) Code Review
authored andcommitted
Merge "Add notification when p2p is enabled"
2 parents 289c2b2 + daf57e5 commit 8b55e92

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

core/res/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2684,6 +2684,8 @@
26842684
<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>
26852685
<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>
26862686
<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>
2687+
<string name="wifi_p2p_enabled_notification_title">Wi-Fi Direct is on</string>
2688+
<string name="wifi_p2p_enabled_notification_message">Touch for settings</string>
26872689

26882690
<!-- Name of the dialog that lets the user choose an accented character to insert -->
26892691
<string name="select_character">Insert character</string>

wifi/java/android/net/wifi/p2p/WifiP2pService.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
package android.net.wifi.p2p;
1818

1919
import android.app.AlertDialog;
20+
import android.app.Notification;
21+
import android.app.NotificationManager;
22+
import android.app.PendingIntent;
2023
import android.content.BroadcastReceiver;
2124
import android.content.Context;
2225
import android.content.DialogInterface;
@@ -84,6 +87,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
8487

8588
private Context mContext;
8689
private String mInterface;
90+
private Notification mNotification;
8791

8892
INetworkManagementService mNwService;
8993
private DhcpStateMachine mDhcpStateMachine;
@@ -605,6 +609,7 @@ public void enter() {
605609
sendP2pStateChangedBroadcast(true);
606610
mNetworkInfo.setIsAvailable(true);
607611
initializeP2pSettings();
612+
showNotification();
608613
}
609614

610615
@Override
@@ -695,6 +700,7 @@ public boolean processMessage(Message message) {
695700
public void exit() {
696701
sendP2pStateChangedBroadcast(false);
697702
mNetworkInfo.setIsAvailable(false);
703+
clearNotification();
698704
}
699705
}
700706

@@ -1218,5 +1224,42 @@ private void loge(String s) {
12181224
Slog.e(TAG, s);
12191225
}
12201226

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+
12211264
}
12221265
}

0 commit comments

Comments
 (0)