diff options
Diffstat (limited to 'service/java/com/android/server/deviceconfig/BootNotificationCreator.java')
-rw-r--r-- | service/java/com/android/server/deviceconfig/BootNotificationCreator.java | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/service/java/com/android/server/deviceconfig/BootNotificationCreator.java b/service/java/com/android/server/deviceconfig/BootNotificationCreator.java index 38a4e57..9772141 100644 --- a/service/java/com/android/server/deviceconfig/BootNotificationCreator.java +++ b/service/java/com/android/server/deviceconfig/BootNotificationCreator.java @@ -22,11 +22,14 @@ import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZonedDateTime; +import java.io.IOException; +import java.util.Map; +import java.util.Set; import static android.app.NotificationManager.IMPORTANCE_HIGH; /** - * Creates notifications when flags are staged on the device. + * Creates notifications when aconfig flags are staged on the device. * * The notification alerts the user to reboot, to apply the staged flags. * @@ -55,11 +58,15 @@ class BootNotificationCreator implements OnPropertiesChangedListener { private Context context; - private static final int REBOOT_HOUR = 18; - private static final int REBOOT_MINUTE = 2; + private static final int REBOOT_HOUR = 10; + private static final int REBOOT_MINUTE = 0; - public BootNotificationCreator(@NonNull Context context) { + private Map<String, Set<String>> aconfigFlags; + + public BootNotificationCreator(@NonNull Context context, + Map<String, Set<String>> aconfigFlags) { this.context = context; + this.aconfigFlags = aconfigFlags; this.context.registerReceiver( new HardRebootBroadcastReceiver(), @@ -73,6 +80,10 @@ class BootNotificationCreator implements OnPropertiesChangedListener { @Override public void onPropertiesChanged(Properties properties) { + if (!containsAconfigChanges(properties)) { + return; + } + if (!tryInitializeDependenciesIfNeeded()) { Slog.i(TAG, "not posting notif; service dependencies not ready"); return; @@ -103,6 +114,25 @@ class BootNotificationCreator implements OnPropertiesChangedListener { AlarmManager.RTC_WAKEUP, scheduledPostTimeLong, pendingIntent); } + private boolean containsAconfigChanges(Properties properties) { + for (String namespaceAndFlag : properties.getKeyset()) { + int firstStarIndex = namespaceAndFlag.indexOf("*"); + if (firstStarIndex == -1 || firstStarIndex == 0 + || firstStarIndex == namespaceAndFlag.length() - 1) { + Slog.w(TAG, "detected malformed staged flag: " + namespaceAndFlag); + continue; + } + + String namespace = namespaceAndFlag.substring(0, firstStarIndex); + String flag = namespaceAndFlag.substring(firstStarIndex + 1); + + if (aconfigFlags.get(namespace) != null && aconfigFlags.get(namespace).contains(flag)) { + return true; + } + } + return false; + } + private class PostNotificationBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { |