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

Commit 968db910 authored by Michael Groover's avatar Michael Groover Committed by Gerrit Code Review
Browse files

Merge "Add required flag to registerReceiver call in NetworkMonitor"

parents 47bc53ae 28b62d47
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -34,4 +34,11 @@ public class ConstantsShim extends com.android.networkstack.apishim.api30.Consta
    // When removing this shim, the version in NetworkMonitorUtils should be removed too.
    // TODO: add TRANSPORT_TEST to system API in API 31 (it is only a test API as of R)
    public static final int TRANSPORT_TEST = 7;

    /**
     * Flag for {@link android.content.Context#registerReceiver}: The receiver cannot receive
     * broadcasts from other apps; has the same behavior as marking a statically registered receiver
     * with "exported=false".
     */
    public static final int RECEIVER_NOT_EXPORTED = 0x4;
}
+4 −1
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ import static com.android.net.module.util.ConnectivityUtils.isIPv6ULA;
import static com.android.net.module.util.DeviceConfigUtils.getResBooleanConfig;
import static com.android.networkstack.apishim.ConstantsShim.DETECTION_METHOD_DNS_EVENTS;
import static com.android.networkstack.apishim.ConstantsShim.DETECTION_METHOD_TCP_METRICS;
import static com.android.networkstack.apishim.ConstantsShim.RECEIVER_NOT_EXPORTED;
import static com.android.networkstack.apishim.ConstantsShim.TRANSPORT_TEST;
import static com.android.networkstack.util.DnsUtils.PRIVATE_DNS_PROBE_HOST_SUFFIX;
import static com.android.networkstack.util.DnsUtils.TYPE_ADDRCONFIG;
@@ -157,6 +158,7 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.RingBufferIndices;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
import com.android.modules.utils.build.SdkLevel;
import com.android.net.module.util.DeviceConfigUtils;
import com.android.net.module.util.NetworkStackConstants;
import com.android.networkstack.NetworkStackNotifier;
@@ -1428,7 +1430,8 @@ public class NetworkMonitor extends StateMachine {
            mToken = token;
            mWhat = what;
            mAction = action + "_" + mCleartextDnsNetwork.getNetworkHandle() + "_" + token;
            mContext.registerReceiver(this, new IntentFilter(mAction));
            final int flags = SdkLevel.isAtLeastT() ? RECEIVER_NOT_EXPORTED : 0;
            mContext.registerReceiver(this, new IntentFilter(mAction), flags);
        }
        public PendingIntent getPendingIntent() {
            final Intent intent = new Intent(mAction);
+5 −0
Original line number Diff line number Diff line
@@ -555,6 +555,11 @@ public class NetworkMonitorTest {
            mRegisteredReceivers.add(invocation.getArgument(0));
            return new Intent();
        });
        when(mContext.registerReceiver(any(BroadcastReceiver.class), any(), anyInt())).then(
                (invocation) -> {
                    mRegisteredReceivers.add(invocation.getArgument(0));
                    return new Intent();
                });

        doAnswer((invocation) -> {
            mRegisteredReceivers.remove(invocation.getArgument(0));