Enable notification permission enforcement

This change will guard posting notifications with a new
"android.permission.POST_NOTIFICATIONS" permission introcuded as part of
Android T.

This permission is marked "dangerous" and will require both declaring
usage of the permission in AndroidManifest.xml as well as showing a
runtime prompt to the user in order to be granted the permission.

Packages which are not granted the permission will have their
notifications silently dropped.

Test: atest Cts*
Bug: 194833441

Change-Id: I274738d4d4c3b09902844708327feb2d1d367307
This commit is contained in:
Steve Elliott
2022-01-18 15:49:32 -05:00
parent b476f8b522
commit 17e784a8b8

View File

@@ -3624,7 +3624,7 @@ public class SettingsProvider extends ContentProvider {
}
private final class UpgradeController {
private static final int SETTINGS_VERSION = 208;
private static final int SETTINGS_VERSION = 209;
private final int mUserId;
@@ -5497,6 +5497,20 @@ public class SettingsProvider extends ContentProvider {
currentVersion = 208;
}
if (currentVersion == 208) {
// Version 208: Enable enforcement of
// android.Manifest.permission#POST_NOTIFICATIONS in order for applications
// to post notifications.
final SettingsState secureSettings = getSecureSettingsLocked(userId);
secureSettings.insertSettingLocked(
Secure.NOTIFICATION_PERMISSION_ENABLED,
/* enabled= */" 1",
/* tag= */ null,
/* makeDefault= */ false,
SettingsState.SYSTEM_PACKAGE_NAME);
currentVersion = 209;
}
// vXXX: Add new settings above this point.
if (currentVersion != newVersion) {