Merge "Use RECEIVER_NOT_EXPORTED in CarrierPrivilegeAuthenticator."

This commit is contained in:
Jean Chalard
2022-02-04 16:40:30 +00:00
committed by Gerrit Code Review
2 changed files with 11 additions and 6 deletions

View File

@@ -19,6 +19,8 @@ package com.android.server.connectivity;
import static android.net.NetworkCapabilities.NET_CAPABILITY_CBS;
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
import static com.android.networkstack.apishim.ConstantsShim.RECEIVER_NOT_EXPORTED;
import android.annotation.NonNull;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -158,7 +160,7 @@ public class CarrierPrivilegeAuthenticator extends BroadcastReceiver {
private void registerForCarrierChanges() {
final IntentFilter filter = new IntentFilter();
filter.addAction(TelephonyManager.ACTION_MULTI_SIM_CONFIG_CHANGED);
mContext.registerReceiver(this, filter, null, mHandler);
mContext.registerReceiver(this, filter, null, mHandler, RECEIVER_NOT_EXPORTED /* flags */);
registerCarrierPrivilegesListeners();
}

View File

@@ -69,6 +69,8 @@ import java.util.List;
@RunWith(DevSdkIgnoreRunner.class)
@IgnoreUpTo(SC_V2) // TODO: Use to Build.VERSION_CODES.SC_V2 when available
public class CarrierPrivilegeAuthenticatorTest {
// TODO : use ConstantsShim.RECEIVER_NOT_EXPORTED when it's available in tests.
private static final int RECEIVER_NOT_EXPORTED = 4;
private static final int SUBSCRIPTION_COUNT = 2;
private static final int TEST_SUBSCRIPTION_ID = 1;
@@ -115,7 +117,7 @@ public class CarrierPrivilegeAuthenticatorTest {
private IntentFilter getIntentFilter() {
final ArgumentCaptor<IntentFilter> captor = ArgumentCaptor.forClass(IntentFilter.class);
verify(mContext).registerReceiver(any(), captor.capture(), any(), any());
verify(mContext).registerReceiver(any(), captor.capture(), any(), any(), anyInt());
return captor.getValue();
}
@@ -138,10 +140,11 @@ public class CarrierPrivilegeAuthenticatorTest {
@Test
public void testConstructor() throws Exception {
verify(mContext).registerReceiver(
eq(mCarrierPrivilegeAuthenticator),
any(IntentFilter.class),
any(),
any());
eq(mCarrierPrivilegeAuthenticator),
any(IntentFilter.class),
any(),
any(),
eq(RECEIVER_NOT_EXPORTED));
final IntentFilter filter = getIntentFilter();
assertEquals(1, filter.countActions());
assertTrue(filter.hasAction(ACTION_MULTI_SIM_CONFIG_CHANGED));