Add unaudited exported flag to exposed runtime receivers

Android T allows apps to declare a runtime receiver as not exported
by invoking registerReceiver with a new RECEIVER_NOT_EXPORTED flag;
receivers registered with this flag will only receive broadcasts from
the platform and the app itself. However to ensure developers can
properly protect their receivers, all apps targeting T or later
registering a receiver for non-system broadcasts must specify either
the exported or not exported flag when invoking #registerReceiver;
if one of these flags is not provided, the platform will throw a
SecurityException. This commit updates all the exposed receivers
with a new RECEIVER_EXPORTED_UNAUDITED flag to maintain the existing
behavior of exporting the receiver while also flagging the receiver
for audit before the T release.

Bug: 161145287
Test: Build
Change-Id: If360077718549a66179175e197817f7315d8c8ca
This commit is contained in:
Michael Groover
2021-12-30 08:28:33 -08:00
parent 7866342c6a
commit 0a46c2f78c
8 changed files with 15 additions and 8 deletions

View File

@@ -73,7 +73,8 @@ public abstract class AbstractConnectivityPreferenceController
}
mContext.registerReceiver(mConnectivityReceiver, connectivityIntentFilter,
android.Manifest.permission.CHANGE_NETWORK_STATE, null);
android.Manifest.permission.CHANGE_NETWORK_STATE, null,
Context.RECEIVER_EXPORTED_UNAUDITED);
}
protected abstract String[] getConnectivityIntents();

View File

@@ -94,7 +94,8 @@ public class CountdownConditionProvider extends SystemConditionProviderService {
@Override
public void onConnected() {
if (DEBUG) Slog.d(TAG, "onConnected");
mContext.registerReceiver(mReceiver, new IntentFilter(ACTION));
mContext.registerReceiver(mReceiver, new IntentFilter(ACTION),
Context.RECEIVER_EXPORTED_UNAUDITED);
mConnected = true;
}

View File

@@ -306,7 +306,8 @@ public class EventConditionProvider extends SystemConditionProviderService {
filter.addAction(Intent.ACTION_TIME_CHANGED);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
filter.addAction(ACTION_EVALUATE);
registerReceiver(mReceiver, filter);
registerReceiver(mReceiver, filter,
Context.RECEIVER_EXPORTED_UNAUDITED);
} else {
unregisterReceiver(mReceiver);
}

View File

@@ -100,7 +100,8 @@ public class NotificationHistoryDatabase {
IntentFilter deletionFilter = new IntentFilter(ACTION_HISTORY_DELETION);
deletionFilter.addDataScheme(SCHEME_DELETION);
mContext.registerReceiver(mFileCleanupReceiver, deletionFilter);
mContext.registerReceiver(mFileCleanupReceiver, deletionFilter,
Context.RECEIVER_EXPORTED_UNAUDITED);
}
public void init() {

View File

@@ -2328,7 +2328,8 @@ public class NotificationManagerService extends SystemService {
IntentFilter timeoutFilter = new IntentFilter(ACTION_NOTIFICATION_TIMEOUT);
timeoutFilter.addDataScheme(SCHEME_TIMEOUT);
getContext().registerReceiver(mNotificationTimeoutReceiver, timeoutFilter);
getContext().registerReceiver(mNotificationTimeoutReceiver, timeoutFilter,
Context.RECEIVER_EXPORTED_UNAUDITED);
IntentFilter settingsRestoredFilter = new IntentFilter(Intent.ACTION_SETTING_RESTORED);
getContext().registerReceiver(mRestoreReceiver, settingsRestoredFilter);

View File

@@ -261,7 +261,8 @@ public class ScheduleConditionProvider extends SystemConditionProviderService {
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
filter.addAction(ACTION_EVALUATE);
filter.addAction(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED);
registerReceiver(mReceiver, filter);
registerReceiver(mReceiver, filter,
Context.RECEIVER_EXPORTED_UNAUDITED);
} else {
unregisterReceiver(mReceiver);
}

View File

@@ -116,7 +116,8 @@ public class SnoozeHelper {
mContext = context;
IntentFilter filter = new IntentFilter(REPOST_ACTION);
filter.addDataScheme(REPOST_SCHEME);
mContext.registerReceiver(mBroadcastReceiver, filter);
mContext.registerReceiver(mBroadcastReceiver, filter,
Context.RECEIVER_EXPORTED_UNAUDITED);
mAm = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
mCallback = callback;
mUserProfiles = userProfiles;

View File

@@ -108,7 +108,7 @@ public class NotificationHistoryDatabaseTest extends UiServiceTestCase {
@Test
public void testDeletionReceiver() {
verify(mContext, times(1)).registerReceiver(any(), any());
verify(mContext, times(1)).registerReceiver(any(), any(), anyInt());
}
@Test