如何实现策略规则?

wlp8pajw  于 2021-06-29  发布在  Java
关注(0)|答案(1)|浏览(342)

这里有人知道什么政策和如何执行规则吗?我正在尝试复制“请勿打扰”设置,其中不允许通话,但也可能出现例外情况,例如媒体声音、触摸声音等。我已设法禁止通话,但当我切换“例外”设置(从我的应用程序中)时,这将恢复为“仅限带星星的联系人”。我附上一个截图,我正在尝试复制我的应用程序。以下是我目前使用的代码:

3 -> {
                                notificationManager.setInterruptionFilter(
                                    NotificationManager.INTERRUPTION_FILTER_PRIORITY
                                )
                                notificationManager.setNotificationPolicy(
                                    NotificationManager.Policy(
                                        PEOPLE_TYPE_NONE,
                                        PRIORITY_SENDERS_ANY,
                                        PRIORITY_SENDERS_ANY
                                    )
                                )
                            }

我也看过:https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/service/notification/zenmodeconfig.java;drc=主机;l=754和https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/service/notification/zenpolicy.java
提出了这个函数,但它什么都没做…:

fun zenPolicyBuilder(): ZenPolicy.Builder {

    val builder = ZenPolicy.Builder()

    val calls = PRIORITY_CATEGORY_CALLS
    val repeatCallers = PRIORITY_CATEGORY_REPEAT_CALLERS
    val alarms = PRIORITY_CATEGORY_ALARMS
    val media = PRIORITY_CATEGORY_MEDIA
    val system = PRIORITY_CATEGORY_SYSTEM
    val events = PRIORITY_CATEGORY_EVENTS
    val reminders = PRIORITY_CATEGORY_REMINDERS

    return when {
        calls != ZenPolicy.PEOPLE_TYPE_UNSET -> {
            builder.allowCalls(PEOPLE_TYPE_NONE)
        }
        repeatCallers != ZenPolicy.STATE_UNSET -> {
            builder.allowRepeatCallers(repeatCallers == ZenPolicy.STATE_ALLOW)
        }
        alarms != ZenPolicy.STATE_UNSET -> {
            builder.allowAlarms(alarms == ZenPolicy.STATE_ALLOW)
        }
        media != ZenPolicy.STATE_UNSET -> {
            builder.allowMedia(media == ZenPolicy.STATE_ALLOW)
        }
        system != ZenPolicy.STATE_UNSET -> {
            builder.allowSystem(system == ZenPolicy.STATE_ALLOW)
        }
        events != ZenPolicy.STATE_UNSET -> {
            builder.allowEvents(events == ZenPolicy.STATE_ALLOW)
        }
        reminders != ZenPolicy.STATE_UNSET -> {
            builder.allowReminders(reminders == ZenPolicy.STATE_ALLOW)
        }
        else -> builder
    }
}

guicsvcw

guicsvcw1#

对于任何可能对未来感兴趣的人来说,我发布的第一个代码片段实际上运行良好。问题来自于我代码的另一部分,它干扰了这个。

相关问题