diff options
Diffstat (limited to 'service/java/com/android/server/deviceconfig/BootNotificationCreator.java')
-rw-r--r-- | service/java/com/android/server/deviceconfig/BootNotificationCreator.java | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/service/java/com/android/server/deviceconfig/BootNotificationCreator.java b/service/java/com/android/server/deviceconfig/BootNotificationCreator.java index 388fedc..9772141 100644 --- a/service/java/com/android/server/deviceconfig/BootNotificationCreator.java +++ b/service/java/com/android/server/deviceconfig/BootNotificationCreator.java @@ -3,6 +3,7 @@ package com.android.server.deviceconfig; import android.annotation.NonNull; import android.app.AlarmManager; import android.app.Notification; +import android.app.Notification.Action; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; @@ -21,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. * @@ -54,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(), @@ -72,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; @@ -102,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) { @@ -114,11 +145,15 @@ class BootNotificationCreator implements OnPropertiesChangedListener { try { Context resourcesContext = context.createPackageContext(RESOURCES_PACKAGE, 0); + Action action = new Action.Builder( + Icon.createWithResource(resourcesContext, R.drawable.ic_restart), + resourcesContext.getString(R.string.boot_notification_action_text), + pendingIntent).build(); Notification notification = new Notification.Builder(context, CHANNEL_ID) .setContentText(resourcesContext.getString(R.string.boot_notification_content)) .setContentTitle(resourcesContext.getString(R.string.boot_notification_title)) .setSmallIcon(Icon.createWithResource(resourcesContext, R.drawable.ic_flag)) - .setContentIntent(pendingIntent) + .addAction(action) .build(); notificationManager.notify(NOTIFICATION_ID, notification); } catch (NameNotFoundException e) { |