diff options
author | 2023-07-18 15:23:00 +0200 | |
---|---|---|
committer | 2023-10-11 11:27:20 +0200 | |
commit | 84282d807f5a657aadbbfb096b6206d1bf172ecd (patch) | |
tree | c690a7742468307a5ebaae4648aff082ef7eb00c | |
parent | 1f09f7117505d30ea5e4d0687edf610e99c47849 (diff) |
Add feature flags for Polite Notifications
Add sysprop flags to enable and configure the polite notifications feature.
Test: atest FrameworksUiServicesTests
Bug: 270456865
Bug: 291897570
Bug: 291899544
Bug: 291907312
Change-Id: Id8b9dce9b9622626c481a240c644becbed389a7a
3 files changed, 133 insertions, 4 deletions
diff --git a/core/java/com/android/internal/config/sysui/SystemUiSystemPropertiesFlags.java b/core/java/com/android/internal/config/sysui/SystemUiSystemPropertiesFlags.java index cb2d93474971..b1d22e069d9d 100644 --- a/core/java/com/android/internal/config/sysui/SystemUiSystemPropertiesFlags.java +++ b/core/java/com/android/internal/config/sysui/SystemUiSystemPropertiesFlags.java @@ -86,6 +86,28 @@ public class SystemUiSystemPropertiesFlags { public static final Flag ENABLE_ATTENTION_HELPER_REFACTOR = devFlag( "persist.debug.sysui.notification.enable_attention_helper_refactor"); + // TODO b/291899544: for released flags, use resource config values + /** Value used by polite notif. feature */ + public static final Flag NOTIF_COOLDOWN_T1 = devFlag( + "persist.debug.sysui.notification.notif_cooldown_t1", 5000); + /** Value used by polite notif. feature */ + public static final Flag NOTIF_COOLDOWN_T2 = devFlag( + "persist.debug.sysui.notification.notif_cooldown_t2", 3000); + /** Value used by polite notif. feature */ + public static final Flag NOTIF_VOLUME1 = devFlag( + "persist.debug.sysui.notification.notif_volume1", 30); + public static final Flag NOTIF_VOLUME2 = devFlag( + "persist.debug.sysui.notification.notif_volume2", 0); + /** Value used by polite notif. feature. -1 to ignore the counter */ + public static final Flag NOTIF_COOLDOWN_COUNTER_RESET = devFlag( + "persist.debug.sysui.notification.notif_cooldown_counter_reset", 10); + /** + * Value used by polite notif. feature: cooldown behavior/strategy. Valid values: rule1, + * rule2 + */ + public static final Flag NOTIF_COOLDOWN_RULE = devFlag( + "persist.debug.sysui.notification.notif_cooldown_rule", "rule1"); + /** b/301242692: Visit extra URIs used in notifications to prevent security issues. */ public static final Flag VISIT_RISKY_URIS = devFlag( "persist.sysui.notification.visit_risky_uris"); @@ -97,6 +119,10 @@ public class SystemUiSystemPropertiesFlags { public interface FlagResolver { /** Is the flag enabled? */ boolean isEnabled(Flag flag); + /** Get the flag value (integer) */ + int getIntValue(Flag flag); + /** Get the flag value (string) */ + String getStringValue(Flag flag); } /** The primary, immutable resolver returned by getResolver() */ @@ -134,6 +160,22 @@ public class SystemUiSystemPropertiesFlags { } /** + * Creates a flag that with a default integer value in debuggable builds. + */ + @VisibleForTesting + public static Flag devFlag(String name, int defaultValue) { + return new Flag(name, defaultValue, null); + } + + /** + * Creates a flag that with a default string value in debuggable builds. + */ + @VisibleForTesting + public static Flag devFlag(String name, String defaultValue) { + return new Flag(name, defaultValue, null); + } + + /** * Creates a flag that is disabled by default in debuggable builds. * It can be enabled or force-disabled by setting this flag's SystemProperty to 1 or 0. * If this flag's SystemProperty is not set, the flag can be enabled by setting the @@ -161,6 +203,8 @@ public class SystemUiSystemPropertiesFlags { public static final class Flag { public final String mSysPropKey; public final boolean mDefaultValue; + public final int mDefaultIntValue; + public final String mDefaultStringValue; @Nullable public final Flag mDebugDefault; @@ -170,6 +214,24 @@ public class SystemUiSystemPropertiesFlags { mSysPropKey = sysPropKey; mDefaultValue = defaultValue; mDebugDefault = debugDefault; + mDefaultIntValue = 0; + mDefaultStringValue = null; + } + + public Flag(@NonNull String sysPropKey, int defaultValue, @Nullable Flag debugDefault) { + mSysPropKey = sysPropKey; + mDefaultIntValue = defaultValue; + mDebugDefault = debugDefault; + mDefaultValue = false; + mDefaultStringValue = null; + } + + public Flag(@NonNull String sysPropKey, String defaultValue, @Nullable Flag debugDefault) { + mSysPropKey = sysPropKey; + mDefaultStringValue = defaultValue; + mDebugDefault = debugDefault; + mDefaultValue = false; + mDefaultIntValue = 0; } } @@ -181,6 +243,16 @@ public class SystemUiSystemPropertiesFlags { public boolean isEnabled(Flag flag) { return flag.mDefaultValue; } + + @Override + public int getIntValue(Flag flag) { + return flag.mDefaultIntValue; + } + + @Override + public String getStringValue(Flag flag) { + return flag.mDefaultStringValue; + } } /** Implementation of the interface used in debuggable builds. */ @@ -199,5 +271,23 @@ public class SystemUiSystemPropertiesFlags { public boolean getBoolean(String key, boolean defaultValue) { return SystemProperties.getBoolean(key, defaultValue); } + + /** Look up the value; overridable for tests to avoid needing to set SystemProperties */ + @VisibleForTesting + public int getIntValue(Flag flag) { + if (flag.mDebugDefault == null) { + return SystemProperties.getInt(flag.mSysPropKey, flag.mDefaultIntValue); + } + return SystemProperties.getInt(flag.mSysPropKey, getIntValue(flag.mDebugDefault)); + } + + /** Look up the value; overridable for tests to avoid needing to set SystemProperties */ + @VisibleForTesting + public String getStringValue(Flag flag) { + if (flag.mDebugDefault == null) { + return SystemProperties.get(flag.mSysPropKey, flag.mDefaultStringValue); + } + return SystemProperties.get(flag.mSysPropKey, getStringValue(flag.mDebugDefault)); + } } } diff --git a/core/tests/coretests/src/android/service/notification/NotificationRankingUpdateTest.java b/core/tests/coretests/src/android/service/notification/NotificationRankingUpdateTest.java index bfdb15b7f7c8..517aeae53784 100644 --- a/core/tests/coretests/src/android/service/notification/NotificationRankingUpdateTest.java +++ b/core/tests/coretests/src/android/service/notification/NotificationRankingUpdateTest.java @@ -48,6 +48,8 @@ import androidx.test.InstrumentationRegistry; import androidx.test.filters.SmallTest; import com.android.internal.config.sysui.SystemUiSystemPropertiesFlags; +import com.android.internal.config.sysui.SystemUiSystemPropertiesFlags.Flag; +import com.android.internal.config.sysui.SystemUiSystemPropertiesFlags.FlagResolver; import org.junit.After; import org.junit.Assert; @@ -422,11 +424,24 @@ public class NotificationRankingUpdateTest { mNotificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "test channel", NotificationManager.IMPORTANCE_DEFAULT); - SystemUiSystemPropertiesFlags.TEST_RESOLVER = flag -> { - if (flag.mSysPropKey.equals(RANKING_UPDATE_ASHMEM.mSysPropKey)) { - return mRankingUpdateAshmem; + SystemUiSystemPropertiesFlags.TEST_RESOLVER = new FlagResolver() { + @Override + public boolean isEnabled(Flag flag) { + if (flag.mSysPropKey.equals(RANKING_UPDATE_ASHMEM.mSysPropKey)) { + return mRankingUpdateAshmem; + } + return new SystemUiSystemPropertiesFlags.DebugResolver().isEnabled(flag); + } + + @Override + public int getIntValue(Flag flag) { + return 0; + } + + @Override + public String getStringValue(Flag flag) { + return null; } - return new SystemUiSystemPropertiesFlags.DebugResolver().isEnabled(flag); }; } diff --git a/tests/testables/src/com/android/internal/config/sysui/TestableFlagResolver.java b/tests/testables/src/com/android/internal/config/sysui/TestableFlagResolver.java index 6a6ab00e33ff..a43e1b091d41 100644 --- a/tests/testables/src/com/android/internal/config/sysui/TestableFlagResolver.java +++ b/tests/testables/src/com/android/internal/config/sysui/TestableFlagResolver.java @@ -21,15 +21,39 @@ import java.util.Map; public class TestableFlagResolver implements SystemUiSystemPropertiesFlags.FlagResolver { private Map<String, Boolean> mOverrides = new HashMap<>(); + private Map<String, Integer> mOverridesInt = new HashMap<>(); + private Map<String, String> mOverridesString = new HashMap<>(); @Override public boolean isEnabled(SystemUiSystemPropertiesFlags.Flag flag) { return mOverrides.getOrDefault(flag.mSysPropKey, flag.mDefaultValue); } + @Override + public int getIntValue(SystemUiSystemPropertiesFlags.Flag flag) { + return mOverridesInt.getOrDefault(flag.mSysPropKey, flag.mDefaultIntValue); + } + + @Override + public String getStringValue(SystemUiSystemPropertiesFlags.Flag flag) { + return mOverridesString.getOrDefault(flag.mSysPropKey, flag.mDefaultStringValue); + } + public TestableFlagResolver setFlagOverride(SystemUiSystemPropertiesFlags.Flag flag, boolean isEnabled) { mOverrides.put(flag.mSysPropKey, isEnabled); return this; } + + public TestableFlagResolver setFlagOverride(SystemUiSystemPropertiesFlags.Flag flag, + int value) { + mOverridesInt.put(flag.mSysPropKey, value); + return this; + } + + public TestableFlagResolver setFlagOverride(SystemUiSystemPropertiesFlags.Flag flag, + String value) { + mOverridesString.put(flag.mSysPropKey, value); + return this; + } } |