Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 20994455 authored by Iavor-Valentin Iftime's avatar Iavor-Valentin Iftime Committed by Android (Google) Code Review
Browse files

Merge changes from topic "polite_notifications_main" into main

* changes:
  Polite notifications
  Add volume to IRingtonePlayer.playAsync
  Add feature flags for Polite Notifications
parents f0360c28 b551eb6a
Loading
Loading
Loading
Loading
+23 −1
Original line number Diff line number Diff line
@@ -272,6 +272,10 @@ public final class NotificationChannel implements Parcelable {
    private boolean mDemoted = false;
    private boolean mImportantConvo = false;
    private long mDeletedTime = DEFAULT_DELETION_TIME_MS;
    /** Do not (de)serialize this value: it only affects logic in system_server and that logic
     * is reset on each boot {@link NotificationAttentionHelper#buzzBeepBlinkLocked}.
     */
    private long mLastNotificationUpdateTimeMs = 0;

    /**
     * Creates a notification channel.
@@ -931,6 +935,23 @@ public final class NotificationChannel implements Parcelable {
        return (mUserLockedFields & USER_LOCKED_SOUND) != 0;
    }

    /**
     * Returns the time of the notification post or last update for this channel.
     * @return time of post / last update
     * @hide
     */
    public long getLastNotificationUpdateTimeMs() {
        return mLastNotificationUpdateTimeMs;
    }

    /**
     * Sets the time of the notification post or last update for this channel.
     * @hide
     */
    public void setLastNotificationUpdateTimeMs(long updateTimeMs) {
        mLastNotificationUpdateTimeMs = updateTimeMs;
    }

    /**
     * @hide
     */
@@ -1408,7 +1429,8 @@ public final class NotificationChannel implements Parcelable {
                + ", mParent=" + mParentId
                + ", mConversationId=" + mConversationId
                + ", mDemoted=" + mDemoted
                + ", mImportantConvo=" + mImportantConvo;
                + ", mImportantConvo=" + mImportantConvo
                + ", mLastNotificationUpdateTimeMs=" + mLastNotificationUpdateTimeMs;
    }

    /** @hide */
+31 −0
Original line number Diff line number Diff line
@@ -5353,6 +5353,37 @@ public final class Settings {
        /** {@hide} */
        public static final Uri NOTIFICATION_SOUND_CACHE_URI = getUriFor(NOTIFICATION_SOUND_CACHE);
        /**
         * When enabled, notifications attention effects: sound, vibration, flashing
         * will have a cooldown timer.
         *
         * The value 1 - enable, 0 - disable
         * @hide
         */
        public static final String NOTIFICATION_COOLDOWN_ENABLED =
            "notification_cooldown_enabled";
        /**
         * When enabled, notification cooldown will apply to all notifications.
         * Otherwise cooldown will only apply to conversations.
         *
         * The value 1 - enable, 0 - disable
         * Only valid if {@code NOTIFICATION_COOLDOWN_ENABLED} is enabled.
         * @hide
         */
        public static final String NOTIFICATION_COOLDOWN_ALL =
            "notification_cooldown_all";
        /**
         * When enabled, notification attention effects will be restricted to vibration only
         * as long as the screen is unlocked.
         *
         * The value 1 - enable, 0 - disable
         * @hide
         */
        public static final String NOTIFICATION_COOLDOWN_VIBRATE_UNLOCKED =
            "notification_cooldown_vibrate_unlocked";
        /**
         * Persistent store for the system-wide default alarm alert.
         *
+90 −0
Original line number Diff line number Diff line
@@ -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() */
@@ -133,6 +159,22 @@ public class SystemUiSystemPropertiesFlags {
        return new Flag(name, false, null);
    }

    /**
     * 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.
@@ -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));
        }
    }
}
+19 −4
Original line number Diff line number Diff line
@@ -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 -> {
        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;
            }
        };
    }

+1 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ interface IRingtonePlayer {
    oneway void setHapticGeneratorEnabled(IBinder token, boolean hapticGeneratorEnabled);

    /** Used for Notification sound playback. */
    oneway void playAsync(in Uri uri, in UserHandle user, boolean looping, in AudioAttributes aa);
    oneway void playAsync(in Uri uri, in UserHandle user, boolean looping, in AudioAttributes aa, float volume);
    oneway void stopAsync();

    /** Return the title of the media. */
Loading