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

Commit fdc4e4af authored by Paul Jensen's avatar Paul Jensen
Browse files

Fix hiding of sign-in to network notification.

Don't rely on the NetworkAgent still being connected when we go to
hide the notification.  The notification is hidden when the
NetworkAgent is disconnected so that wasn't a safe assumption.
By using the NetID as the notification identifier we also fix the
issue of multiple notifications of the same network type inadvertently
hiding the incorrect notification with the same network type.

bug:16317917
Change-Id: I01fdc466a0f430af9fc378445586ec7b83b3ac83
parent cdf2564d
Loading
Loading
Loading
Loading
+23 −10
Original line number Diff line number Diff line
@@ -3199,13 +3199,17 @@ public class ConnectivityService extends IConnectivityManager.Stub {
                    break;
                }
                case NetworkMonitor.EVENT_PROVISIONING_NOTIFICATION: {
                    NetworkAgentInfo nai = mNetworkAgentInfos.get(msg.replyTo);
                    if (msg.arg1 == 0) {
                        setProvNotificationVisibleIntent(false, msg.arg2, 0, null, null);
                    } else {
                        NetworkAgentInfo nai = mNetworkForNetId.get(msg.arg2);
                        if (nai == null) {
                            loge("EVENT_PROVISIONING_NOTIFICATION from unknown NetworkMonitor");
                            break;
                        }
                    setProvNotificationVisibleIntent(msg.arg1 != 0, nai.networkInfo.getType(),
                        setProvNotificationVisibleIntent(true, msg.arg2, nai.networkInfo.getType(),
                                nai.networkInfo.getExtraInfo(), (PendingIntent)msg.obj);
                    }
                    break;
                }
                case NetworkStateTracker.EVENT_STATE_CHANGED: {
@@ -4958,10 +4962,19 @@ public class ConnectivityService extends IConnectivityManager.Stub {
                    break;
            }
        }
        setProvNotificationVisibleIntent(visible, networkType, extraInfo, pendingIntent);
        // Concatenate the range of types onto the range of NetIDs.
        int id = MAX_NET_ID + 1 + (networkType - ConnectivityManager.TYPE_NONE);
        setProvNotificationVisibleIntent(visible, id, networkType, extraInfo, pendingIntent);
    }

    private void setProvNotificationVisibleIntent(boolean visible, int networkType,
    /**
     * Show or hide network provisioning notificaitons.
     *
     * @param id an identifier that uniquely identifies this notification.  This must match
     *         between show and hide calls.  We use the NetID value but for legacy callers
     *         we concatenate the range of types with the range of NetIDs.
     */
    private void setProvNotificationVisibleIntent(boolean visible, int id, int networkType,
            String extraInfo, PendingIntent intent) {
        if (DBG) {
            log("setProvNotificationVisibleIntent: E visible=" + visible + " networkType=" +
@@ -5008,14 +5021,14 @@ public class ConnectivityService extends IConnectivityManager.Stub {
            notification.contentIntent = intent;

            try {
                notificationManager.notify(NOTIFICATION_ID, networkType, notification);
                notificationManager.notify(NOTIFICATION_ID, id, notification);
            } catch (NullPointerException npe) {
                loge("setNotificaitionVisible: visible notificationManager npe=" + npe);
                npe.printStackTrace();
            }
        } else {
            try {
                notificationManager.cancel(NOTIFICATION_ID, networkType);
                notificationManager.cancel(NOTIFICATION_ID, id);
            } catch (NullPointerException npe) {
                loge("setNotificaitionVisible: cancel notificationManager npe=" + npe);
                npe.printStackTrace();
+6 −6
Original line number Diff line number Diff line
@@ -148,8 +148,8 @@ public class NetworkMonitor extends StateMachine {
    /**
     * Request ConnectivityService display provisioning notification.
     * arg1    = Whether to make the notification visible.
     * obj     = Intent to be launched when notification selected by user.
     * replyTo = NetworkAgentInfo.messenger so ConnectivityService can identify sender.
     * arg2    = NetID.
     * obj     = Intent to be launched when notification selected by user, null if !arg1.
     */
    public static final int EVENT_PROVISIONING_NOTIFICATION = BASE + 12;

@@ -447,9 +447,9 @@ public class NetworkMonitor extends StateMachine {
            // Initiate notification to sign-in.
            Intent intent = new Intent(ACTION_SIGN_IN_REQUESTED);
            intent.putExtra(Intent.EXTRA_TEXT, String.valueOf(mNetworkAgentInfo.network.netId));
            Message message = obtainMessage(EVENT_PROVISIONING_NOTIFICATION, 1, 0,
            Message message = obtainMessage(EVENT_PROVISIONING_NOTIFICATION, 1,
                    mNetworkAgentInfo.network.netId,
                    PendingIntent.getBroadcast(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
            message.replyTo = mNetworkAgentInfo.messenger;
            mConnectivityServiceHandler.sendMessage(message);
        }

@@ -470,8 +470,8 @@ public class NetworkMonitor extends StateMachine {

        @Override
        public void exit() {
            Message message = obtainMessage(EVENT_PROVISIONING_NOTIFICATION, 0, 0, null);
            message.replyTo = mNetworkAgentInfo.messenger;
            Message message = obtainMessage(EVENT_PROVISIONING_NOTIFICATION, 0,
                    mNetworkAgentInfo.network.netId, null);
            mConnectivityServiceHandler.sendMessage(message);
            mContext.unregisterReceiver(mUserRespondedBroadcastReceiver);
            mUserRespondedBroadcastReceiver = null;