Use RECEIVER_NOT_EXPORTED in CarrierPrivilegeAuthenticator.
Passing one of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED is required for all code targeting T or above. The correct value here is RECEIVER_NOT_EXPORTED because the receiver is being registered in the system server and the broadcast comes from the system server itself (same UID). This does not need to be guarded by OS version because CarrierPrivilegeAuthenticator is only used on T+. Test: m Fix: 217642082 Change-Id: I09840b17bd54352896607737b56c6a692ffbd2c2
This commit is contained in:
committed by
Chalard Jean
parent
1513c9991e
commit
7569d51446
@@ -19,6 +19,8 @@ package com.android.server.connectivity;
|
|||||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_CBS;
|
import static android.net.NetworkCapabilities.NET_CAPABILITY_CBS;
|
||||||
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
|
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
|
||||||
|
|
||||||
|
import static com.android.networkstack.apishim.ConstantsShim.RECEIVER_NOT_EXPORTED;
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -158,7 +160,7 @@ public class CarrierPrivilegeAuthenticator extends BroadcastReceiver {
|
|||||||
private void registerForCarrierChanges() {
|
private void registerForCarrierChanges() {
|
||||||
final IntentFilter filter = new IntentFilter();
|
final IntentFilter filter = new IntentFilter();
|
||||||
filter.addAction(TelephonyManager.ACTION_MULTI_SIM_CONFIG_CHANGED);
|
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();
|
registerCarrierPrivilegesListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ import java.util.List;
|
|||||||
@RunWith(DevSdkIgnoreRunner.class)
|
@RunWith(DevSdkIgnoreRunner.class)
|
||||||
@IgnoreUpTo(SC_V2) // TODO: Use to Build.VERSION_CODES.SC_V2 when available
|
@IgnoreUpTo(SC_V2) // TODO: Use to Build.VERSION_CODES.SC_V2 when available
|
||||||
public class CarrierPrivilegeAuthenticatorTest {
|
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 SUBSCRIPTION_COUNT = 2;
|
||||||
private static final int TEST_SUBSCRIPTION_ID = 1;
|
private static final int TEST_SUBSCRIPTION_ID = 1;
|
||||||
|
|
||||||
@@ -115,7 +117,7 @@ public class CarrierPrivilegeAuthenticatorTest {
|
|||||||
|
|
||||||
private IntentFilter getIntentFilter() {
|
private IntentFilter getIntentFilter() {
|
||||||
final ArgumentCaptor<IntentFilter> captor = ArgumentCaptor.forClass(IntentFilter.class);
|
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();
|
return captor.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,10 +140,11 @@ public class CarrierPrivilegeAuthenticatorTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testConstructor() throws Exception {
|
public void testConstructor() throws Exception {
|
||||||
verify(mContext).registerReceiver(
|
verify(mContext).registerReceiver(
|
||||||
eq(mCarrierPrivilegeAuthenticator),
|
eq(mCarrierPrivilegeAuthenticator),
|
||||||
any(IntentFilter.class),
|
any(IntentFilter.class),
|
||||||
any(),
|
any(),
|
||||||
any());
|
any(),
|
||||||
|
eq(RECEIVER_NOT_EXPORTED));
|
||||||
final IntentFilter filter = getIntentFilter();
|
final IntentFilter filter = getIntentFilter();
|
||||||
assertEquals(1, filter.countActions());
|
assertEquals(1, filter.countActions());
|
||||||
assertTrue(filter.hasAction(ACTION_MULTI_SIM_CONFIG_CHANGED));
|
assertTrue(filter.hasAction(ACTION_MULTI_SIM_CONFIG_CHANGED));
|
||||||
|
|||||||
Reference in New Issue
Block a user