Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8b55e926 authored by Irfan Sheriff's avatar Irfan Sheriff Committed by Android (Google) Code Review
Browse files

Merge "Add notification when p2p is enabled"

parents 289c2b25 daf57e5f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -2684,6 +2684,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>
+43 −0
Original line number Diff line number Diff line
@@ -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;
        }
    }

    }
}