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

Commit 1acc0030 authored by Remi NGUYEN VAN's avatar Remi NGUYEN VAN
Browse files

Use FLAG_IMMUTABLE on NetworkStackNotifier intents

FLAG_UPDATE_CURRENT was not helpful because:
 - For the venue info notification, the only extra is the Network, and
   the intent uses the network handle as identifier; meaning that two
   matching intents would already have the same extra.
 - The ACTION_WIFI_SETTINGS intent does not have any extra, so there is
   nothing to update.

Bug: 157475111
Test: atest NetworkStackTests; manual: connected to captive portals and
          used notifications
Change-Id: Ifd9e6ff04f2d574f3e28d612c8ea6215a209069e
parent b8ac953a
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -239,7 +239,7 @@ public class NetworkStackNotifier {
                    .setContentText(res.getString(R.string.tap_for_info))
                    .setContentText(res.getString(R.string.tap_for_info))
                    .setContentIntent(mDependencies.getActivityPendingIntent(
                    .setContentIntent(mDependencies.getActivityPendingIntent(
                            getContextAsUser(mContext, UserHandle.CURRENT),
                            getContextAsUser(mContext, UserHandle.CURRENT),
                            infoIntent, PendingIntent.FLAG_UPDATE_CURRENT));
                            infoIntent, PendingIntent.FLAG_IMMUTABLE));


            networkStatus.mShownNotification = NOTE_VENUE_INFO;
            networkStatus.mShownNotification = NOTE_VENUE_INFO;
        } else if (showValidated) {
        } else if (showValidated) {
@@ -252,7 +252,7 @@ public class NetworkStackNotifier {
                    .setContentIntent(mDependencies.getActivityPendingIntent(
                    .setContentIntent(mDependencies.getActivityPendingIntent(
                            getContextAsUser(mContext, UserHandle.CURRENT),
                            getContextAsUser(mContext, UserHandle.CURRENT),
                            new Intent(Settings.ACTION_WIFI_SETTINGS),
                            new Intent(Settings.ACTION_WIFI_SETTINGS),
                            PendingIntent.FLAG_UPDATE_CURRENT));
                            PendingIntent.FLAG_IMMUTABLE));


            networkStatus.mShownNotification = NOTE_CONNECTED;
            networkStatus.mShownNotification = NOTE_CONNECTED;
        } else {
        } else {
+6 −3
Original line number Original line Diff line number Diff line
@@ -22,7 +22,7 @@ import android.app.NotificationManager
import android.app.NotificationManager.IMPORTANCE_DEFAULT
import android.app.NotificationManager.IMPORTANCE_DEFAULT
import android.app.NotificationManager.IMPORTANCE_NONE
import android.app.NotificationManager.IMPORTANCE_NONE
import android.app.PendingIntent
import android.app.PendingIntent
import android.app.PendingIntent.FLAG_UPDATE_CURRENT
import android.app.PendingIntent.FLAG_IMMUTABLE
import android.content.Context
import android.content.Context
import android.content.Intent
import android.content.Intent
import android.content.res.Resources
import android.content.res.Resources
@@ -57,6 +57,7 @@ import org.junit.runner.RunWith
import org.mockito.ArgumentCaptor
import org.mockito.ArgumentCaptor
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.ArgumentMatchers.eq
import org.mockito.ArgumentMatchers.eq
import org.mockito.ArgumentMatchers.intThat
import org.mockito.Captor
import org.mockito.Captor
import org.mockito.Mock
import org.mockito.Mock
import org.mockito.Mockito.any
import org.mockito.Mockito.any
@@ -188,7 +189,8 @@ class NetworkStackNotifierTest {
        assertEquals(CHANNEL_CONNECTED, note.channelId)
        assertEquals(CHANNEL_CONNECTED, note.channelId)
        assertEquals(timeout, note.timeoutAfter)
        assertEquals(timeout, note.timeoutAfter)
        verify(mDependencies).getActivityPendingIntent(
        verify(mDependencies).getActivityPendingIntent(
                eq(mCurrentUserContext), mIntentCaptor.capture(), eq(FLAG_UPDATE_CURRENT))
                eq(mCurrentUserContext), mIntentCaptor.capture(),
                intThat { it or FLAG_IMMUTABLE != 0 })
    }
    }


    private fun verifyCanceledNotificationAfterNetworkLost() {
    private fun verifyCanceledNotificationAfterNetworkLost() {
@@ -279,7 +281,8 @@ class NetworkStackNotifierTest {


        verify(mNm).notify(eq(TEST_NETWORK_TAG), mNoteIdCaptor.capture(), mNoteCaptor.capture())
        verify(mNm).notify(eq(TEST_NETWORK_TAG), mNoteIdCaptor.capture(), mNoteCaptor.capture())
        verify(mDependencies).getActivityPendingIntent(
        verify(mDependencies).getActivityPendingIntent(
                eq(mCurrentUserContext), mIntentCaptor.capture(), eq(FLAG_UPDATE_CURRENT))
                eq(mCurrentUserContext), mIntentCaptor.capture(),
                intThat { it or FLAG_IMMUTABLE != 0 })
        verifyVenueInfoIntent(mIntentCaptor.value)
        verifyVenueInfoIntent(mIntentCaptor.value)
        verifyCanceledNotificationAfterDefaultNetworkLost()
        verifyCanceledNotificationAfterDefaultNetworkLost()
    }
    }