Redesign individual conversation page
Test: atest Fixes: 151765526 Change-Id: I98d45222104eb03449e469bcd80fd5f23c2935ca
This commit is contained in:
158
res/layout/notif_priority_conversation_preference.xml
Normal file
158
res/layout/notif_priority_conversation_preference.xml
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2020 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/app_entities_header"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center"
|
||||||
|
android:padding="@dimen/notification_importance_toggle_marginTop"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<com.android.settings.notification.NotificationButtonRelativeLayout
|
||||||
|
android:id="@+id/priority_group"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="@dimen/notification_importance_button_padding"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true">
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/priority_icon"
|
||||||
|
android:src="@drawable/ic_important_outline"
|
||||||
|
android:background="@android:color/transparent"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:clickable="false"
|
||||||
|
android:focusable="false"/>
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/priority_label"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:clickable="false"
|
||||||
|
android:focusable="false"
|
||||||
|
android:layout_toEndOf="@id/priority_icon"
|
||||||
|
android:layout_marginStart="@dimen/notification_importance_drawable_padding"
|
||||||
|
android:textAppearance="@style/TextAppearance.NotificationImportanceButton.Unselected"
|
||||||
|
android:text="@string/notification_priority_title"/>
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/priority_summary"
|
||||||
|
android:paddingTop="@dimen/notification_importance_button_padding"
|
||||||
|
android:text="@string/notification_channel_summary_priority"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:clickable="false"
|
||||||
|
android:focusable="false"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="2"
|
||||||
|
android:layout_below="@id/priority_icon"
|
||||||
|
android:textAppearance="@style/TextAppearance.NotificationImportanceDetail"
|
||||||
|
android:visibility="gone" />
|
||||||
|
</com.android.settings.notification.NotificationButtonRelativeLayout>
|
||||||
|
|
||||||
|
<com.android.settings.notification.NotificationButtonRelativeLayout
|
||||||
|
android:id="@+id/alert"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="@dimen/notification_importance_button_padding"
|
||||||
|
android:layout_marginTop="@dimen/notification_importance_button_separation"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true">
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/alert_icon"
|
||||||
|
android:src="@drawable/ic_notifications_alert"
|
||||||
|
android:background="@android:color/transparent"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:clickable="false"
|
||||||
|
android:focusable="false"/>
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/alert_label"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:clickable="false"
|
||||||
|
android:focusable="false"
|
||||||
|
android:layout_toEndOf="@id/alert_icon"
|
||||||
|
android:layout_marginStart="@dimen/notification_importance_drawable_padding"
|
||||||
|
android:textAppearance="@style/TextAppearance.NotificationImportanceButton.Unselected"
|
||||||
|
android:text="@string/notification_alert_title"/>
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/alert_summary"
|
||||||
|
android:paddingTop="@dimen/notification_importance_button_padding"
|
||||||
|
android:text="@string/notification_channel_summary_default"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:clickable="false"
|
||||||
|
android:focusable="false"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="2"
|
||||||
|
android:layout_below="@id/alert_icon"
|
||||||
|
android:textAppearance="@style/TextAppearance.NotificationImportanceDetail"
|
||||||
|
android:visibility="gone" />
|
||||||
|
</com.android.settings.notification.NotificationButtonRelativeLayout>
|
||||||
|
|
||||||
|
<com.android.settings.notification.NotificationButtonRelativeLayout
|
||||||
|
android:id="@+id/silence"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="@dimen/notification_importance_button_padding"
|
||||||
|
android:layout_marginTop="@dimen/notification_importance_button_separation"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true">
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/silence_icon"
|
||||||
|
android:src="@drawable/ic_notifications_off_24dp"
|
||||||
|
android:background="@android:color/transparent"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:clickable="false"
|
||||||
|
android:focusable="false"/>
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/silence_label"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:clickable="false"
|
||||||
|
android:focusable="false"
|
||||||
|
android:layout_toEndOf="@id/silence_icon"
|
||||||
|
android:layout_marginStart="@dimen/notification_importance_drawable_padding"
|
||||||
|
android:textAppearance="@style/TextAppearance.NotificationImportanceButton.Unselected"
|
||||||
|
android:text="@string/notification_silence_title"/>
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/silence_summary"
|
||||||
|
android:paddingTop="@dimen/notification_importance_button_padding"
|
||||||
|
android:text="@string/notification_channel_summary_low"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:clickable="false"
|
||||||
|
android:focusable="false"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="2"
|
||||||
|
android:layout_below="@id/silence_icon"
|
||||||
|
android:textAppearance="@style/TextAppearance.NotificationImportanceDetail"
|
||||||
|
android:visibility="gone" />
|
||||||
|
</com.android.settings.notification.NotificationButtonRelativeLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
@@ -8415,6 +8415,12 @@
|
|||||||
<!-- [CHAR LIMIT=180] Notification importance description. More details from allow_interruption string - specifics of how notifications may interrupt. -->
|
<!-- [CHAR LIMIT=180] Notification importance description. More details from allow_interruption string - specifics of how notifications may interrupt. -->
|
||||||
<string name="allow_interruption_summary">Let the app make sound, vibrate, and/or pop notifications on screen</string>
|
<string name="allow_interruption_summary">Let the app make sound, vibrate, and/or pop notifications on screen</string>
|
||||||
|
|
||||||
|
<!-- [CHAR LIMIT=150] Notification Importance title: important conversation level -->
|
||||||
|
<string name="notification_priority_title">Priority</string>
|
||||||
|
|
||||||
|
<!-- [CHAR LIMIT=150] Notification Importance title: important conversation level summary -->
|
||||||
|
<string name="notification_channel_summary_priority">Shows at top of conversation section and appears as a bubble.</string>
|
||||||
|
|
||||||
<!-- Channel summaries for the app notification page -->
|
<!-- Channel summaries for the app notification page -->
|
||||||
|
|
||||||
<!-- [CHAR LIMIT=150] Notification Importance title: min importance level summary -->
|
<!-- [CHAR LIMIT=150] Notification Importance title: min importance level summary -->
|
||||||
|
@@ -26,19 +26,11 @@
|
|||||||
settings:allowDividerBelow="true"/>
|
settings:allowDividerBelow="true"/>
|
||||||
|
|
||||||
<!-- important conversation -->
|
<!-- important conversation -->
|
||||||
<com.android.settingslib.RestrictedSwitchPreference
|
<com.android.settings.notification.app.ConversationPriorityPreference
|
||||||
android:key="important"
|
android:key="priority"
|
||||||
android:title="@string/notification_conversation_important"
|
android:title="@string/notification_conversation_important"
|
||||||
android:icon="@drawable/ic_important_outline"
|
settings:allowDividerAbove="true"
|
||||||
settings:restrictedSwitchSummary="@string/enabled_by_admin"
|
settings:allowDividerBelow="true"/>
|
||||||
settings:allowDividerAbove="true"/>
|
|
||||||
|
|
||||||
<!-- silence -->
|
|
||||||
<com.android.settingslib.RestrictedSwitchPreference
|
|
||||||
android:key="alerting"
|
|
||||||
android:icon="@drawable/ic_notification_alert"
|
|
||||||
android:title="@string/notification_alert_title"
|
|
||||||
android:summary="@string/notification_channel_summary_default"/>
|
|
||||||
|
|
||||||
<!-- bubbles -->
|
<!-- bubbles -->
|
||||||
<com.android.settingslib.RestrictedSwitchPreference
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
@@ -48,47 +40,6 @@
|
|||||||
android:icon="@drawable/ic_create_bubble"
|
android:icon="@drawable/ic_create_bubble"
|
||||||
settings:restrictedSwitchSummary="@string/enabled_by_admin" />
|
settings:restrictedSwitchSummary="@string/enabled_by_admin" />
|
||||||
|
|
||||||
<!-- peeking -->
|
|
||||||
<com.android.settingslib.RestrictedSwitchPreference
|
|
||||||
android:key="high_importance"
|
|
||||||
android:title="@string/notification_importance_high_title"
|
|
||||||
android:summary="@string/notification_channel_summary_high"/>
|
|
||||||
|
|
||||||
<!-- Visibility Override -->
|
|
||||||
<com.android.settings.RestrictedListPreference
|
|
||||||
android:key="visibility_override"
|
|
||||||
android:icon="@drawable/ic_lock"
|
|
||||||
android:title="@string/app_notification_visibility_override_title"/>
|
|
||||||
|
|
||||||
<!-- Show badge -->
|
|
||||||
<com.android.settingslib.RestrictedSwitchPreference
|
|
||||||
android:key="badge"
|
|
||||||
android:title="@string/notification_channel_badge_title"
|
|
||||||
settings:useAdditionalSummary="true"
|
|
||||||
settings:restrictedSwitchSummary="@string/enabled_by_admin"/>
|
|
||||||
|
|
||||||
<!-- Lights -->
|
|
||||||
<com.android.settingslib.RestrictedSwitchPreference
|
|
||||||
android:key="lights"
|
|
||||||
android:title="@string/notification_show_lights_title"
|
|
||||||
settings:useAdditionalSummary="true"/>
|
|
||||||
|
|
||||||
<!-- Vibration -->
|
|
||||||
<com.android.settingslib.RestrictedSwitchPreference
|
|
||||||
android:key="vibrate"
|
|
||||||
android:icon="@drawable/ic_volume_ringer_vibrate"
|
|
||||||
android:title="@string/notification_vibrate_title"
|
|
||||||
settings:useAdditionalSummary="true" />
|
|
||||||
|
|
||||||
<!-- ringtone -->
|
|
||||||
<com.android.settings.notification.app.NotificationSoundPreference
|
|
||||||
android:key="ringtone"
|
|
||||||
android:title="@string/notification_channel_sound_title"
|
|
||||||
android:dialogTitle="@string/notification_channel_sound_title"
|
|
||||||
android:icon="@drawable/ic_media_stream"
|
|
||||||
android:showSilent="true"
|
|
||||||
android:showDefault="true"/>
|
|
||||||
|
|
||||||
<!-- demote -->
|
<!-- demote -->
|
||||||
<Preference
|
<Preference
|
||||||
android:key="demote"
|
android:key="demote"
|
||||||
@@ -97,22 +48,55 @@
|
|||||||
android:summary="@string/demote_conversation_summary"
|
android:summary="@string/demote_conversation_summary"
|
||||||
settings:allowDividerAbove="true"/>
|
settings:allowDividerAbove="true"/>
|
||||||
|
|
||||||
<Preference
|
|
||||||
android:key="add_to_home"
|
|
||||||
android:title="@string/notification_conversation_add_to_home"
|
|
||||||
android:icon="@drawable/ic_add_to_home"
|
|
||||||
settings:allowDividerAbove="true"/>
|
|
||||||
|
|
||||||
<Preference
|
|
||||||
android:key="app_link"
|
|
||||||
android:title="@string/app_settings_link"
|
|
||||||
settings:allowDividerAbove="true"/>
|
|
||||||
|
|
||||||
<com.android.settings.notification.app.NotificationFooterPreference
|
|
||||||
android:key="desc" />
|
|
||||||
|
|
||||||
<com.android.settings.notification.app.NotificationFooterPreference
|
<com.android.settings.notification.app.NotificationFooterPreference
|
||||||
android:key="block_desc"
|
android:key="block_desc"
|
||||||
settings:allowDividerAbove="false"/>
|
settings:allowDividerAbove="false"/>
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="channel_advanced"
|
||||||
|
android:order="50"
|
||||||
|
settings:initialExpandedChildrenCount="0">
|
||||||
|
|
||||||
|
<!-- peeking -->
|
||||||
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
|
android:key="high_importance"
|
||||||
|
android:title="@string/notification_importance_high_title"
|
||||||
|
android:summary="@string/notification_channel_summary_high"/>
|
||||||
|
|
||||||
|
<!-- ringtone -->
|
||||||
|
<com.android.settings.notification.app.NotificationSoundPreference
|
||||||
|
android:key="ringtone"
|
||||||
|
android:title="@string/notification_channel_sound_title"
|
||||||
|
android:dialogTitle="@string/notification_channel_sound_title"
|
||||||
|
android:icon="@drawable/ic_media_stream"
|
||||||
|
android:showSilent="true"
|
||||||
|
android:showDefault="true"/>
|
||||||
|
|
||||||
|
<!-- Visibility Override -->
|
||||||
|
<com.android.settings.RestrictedListPreference
|
||||||
|
android:key="visibility_override"
|
||||||
|
android:icon="@drawable/ic_lock"
|
||||||
|
android:title="@string/app_notification_visibility_override_title"/>
|
||||||
|
|
||||||
|
<!-- Show badge -->
|
||||||
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
|
android:key="badge"
|
||||||
|
android:title="@string/notification_channel_badge_title"
|
||||||
|
settings:useAdditionalSummary="true"
|
||||||
|
settings:restrictedSwitchSummary="@string/enabled_by_admin"/>
|
||||||
|
|
||||||
|
<!-- Lights -->
|
||||||
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
|
android:key="lights"
|
||||||
|
android:title="@string/notification_show_lights_title"
|
||||||
|
settings:useAdditionalSummary="true"/>
|
||||||
|
|
||||||
|
<!-- Vibration -->
|
||||||
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
|
android:key="vibrate"
|
||||||
|
android:icon="@drawable/ic_volume_ringer_vibrate"
|
||||||
|
android:title="@string/notification_vibrate_title"
|
||||||
|
settings:useAdditionalSummary="true" />
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
@@ -68,7 +68,7 @@ public class BubblePreferenceController extends NotificationPreferenceController
|
|||||||
if (isDefaultChannel()) {
|
if (isDefaultChannel()) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return mAppRow != null && mAppRow.allowBubbles;
|
return mAppRow != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@@ -18,15 +18,8 @@ package com.android.settings.notification.app;
|
|||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.preference.PreferenceGroup;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.internal.widget.LockPatternUtils;
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.notification.NotificationBackend;
|
import com.android.settings.notification.NotificationBackend;
|
||||||
@@ -60,7 +53,7 @@ public class ConversationListSettings extends DashboardFragment {
|
|||||||
@Override
|
@Override
|
||||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||||
mControllers = new ArrayList<>();
|
mControllers = new ArrayList<>();
|
||||||
mControllers.add(new ImportantConversationsPreferenceController(context, mBackend));
|
mControllers.add(new PriorityConversationsPreferenceController(context, mBackend));
|
||||||
mControllers.add(new AllConversationsPreferenceController(context, mBackend));
|
mControllers.add(new AllConversationsPreferenceController(context, mBackend));
|
||||||
return new ArrayList<>(mControllers);
|
return new ArrayList<>(mControllers);
|
||||||
}
|
}
|
||||||
|
@@ -79,18 +79,13 @@ public class ConversationNotificationSettings extends NotificationSettings {
|
|||||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||||
mControllers = new ArrayList<>();
|
mControllers = new ArrayList<>();
|
||||||
mControllers.add(new ConversationHeaderPreferenceController(context, this));
|
mControllers.add(new ConversationHeaderPreferenceController(context, this));
|
||||||
mControllers.add(new ConversationImportantPreferenceController(
|
mControllers.add(new ConversationPriorityPreferenceController(
|
||||||
context, mBackend, mDependentFieldListener));
|
context, mBackend, mDependentFieldListener));
|
||||||
mControllers.add(new DefaultImportancePreferenceController(
|
|
||||||
context, mDependentFieldListener, mBackend));
|
|
||||||
mControllers.add(new AddToHomeScreenPreferenceController(context, mBackend));
|
|
||||||
mControllers.add(new HighImportancePreferenceController(
|
mControllers.add(new HighImportancePreferenceController(
|
||||||
context, mDependentFieldListener, mBackend));
|
context, mDependentFieldListener, mBackend));
|
||||||
mControllers.add(new SoundPreferenceController(context, this,
|
mControllers.add(new SoundPreferenceController(context, this,
|
||||||
mDependentFieldListener, mBackend));
|
mDependentFieldListener, mBackend));
|
||||||
mControllers.add(new VibrationPreferenceController(context, mBackend));
|
mControllers.add(new VibrationPreferenceController(context, mBackend));
|
||||||
mControllers.add(new AppLinkPreferenceController(context));
|
|
||||||
mControllers.add(new DescriptionPreferenceController(context));
|
|
||||||
mControllers.add(new VisibilityPreferenceController(context, new LockPatternUtils(context),
|
mControllers.add(new VisibilityPreferenceController(context, new LockPatternUtils(context),
|
||||||
mBackend));
|
mBackend));
|
||||||
mControllers.add(new LightsPreferenceController(context, mBackend));
|
mControllers.add(new LightsPreferenceController(context, mBackend));
|
||||||
|
@@ -0,0 +1,221 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.notification.app;
|
||||||
|
|
||||||
|
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
|
||||||
|
import static android.app.NotificationManager.IMPORTANCE_LOW;
|
||||||
|
import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
|
||||||
|
import static android.view.View.GONE;
|
||||||
|
import static android.view.View.VISIBLE;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.ColorStateList;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.transition.AutoTransition;
|
||||||
|
import android.transition.TransitionManager;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.util.Pair;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceViewHolder;
|
||||||
|
|
||||||
|
import com.android.settings.Utils;
|
||||||
|
import com.android.settingslib.R;
|
||||||
|
|
||||||
|
public class ConversationPriorityPreference extends Preference {
|
||||||
|
|
||||||
|
private boolean mIsConfigurable = true;
|
||||||
|
private int mImportance;
|
||||||
|
private int mOriginalImportance;
|
||||||
|
private boolean mPriorityConversation;
|
||||||
|
private View mSilenceButton;
|
||||||
|
private View mAlertButton;
|
||||||
|
private View mPriorityButton;
|
||||||
|
private Context mContext;
|
||||||
|
Drawable selectedBackground;
|
||||||
|
Drawable unselectedBackground;
|
||||||
|
private static final int BUTTON_ANIM_TIME_MS = 100;
|
||||||
|
|
||||||
|
public ConversationPriorityPreference(Context context, AttributeSet attrs,
|
||||||
|
int defStyleAttr, int defStyleRes) {
|
||||||
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
init(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConversationPriorityPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
init(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConversationPriorityPreference(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
init(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConversationPriorityPreference(Context context) {
|
||||||
|
super(context);
|
||||||
|
init(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init(Context context) {
|
||||||
|
mContext = context;
|
||||||
|
selectedBackground = mContext.getDrawable(R.drawable.button_border_selected);
|
||||||
|
unselectedBackground = mContext.getDrawable(R.drawable.button_border_unselected);
|
||||||
|
setLayoutResource(R.layout.notif_priority_conversation_preference);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImportance(int importance) {
|
||||||
|
mImportance = importance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConfigurable(boolean configurable) {
|
||||||
|
mIsConfigurable = configurable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPriorityConversation(boolean priorityConversation) {
|
||||||
|
mPriorityConversation = priorityConversation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOriginalImportance(int importance) {
|
||||||
|
mOriginalImportance = importance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(final PreferenceViewHolder holder) {
|
||||||
|
super.onBindViewHolder(holder);
|
||||||
|
holder.itemView.setClickable(false);
|
||||||
|
|
||||||
|
mSilenceButton = holder.findViewById(R.id.silence);
|
||||||
|
mAlertButton = holder.findViewById(R.id.alert);
|
||||||
|
mPriorityButton = holder.findViewById(R.id.priority_group);
|
||||||
|
|
||||||
|
if (!mIsConfigurable) {
|
||||||
|
mSilenceButton.setEnabled(false);
|
||||||
|
mAlertButton.setEnabled(false);
|
||||||
|
mPriorityButton.setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateToggles((ViewGroup) holder.itemView, mImportance, mPriorityConversation,
|
||||||
|
false);
|
||||||
|
|
||||||
|
mSilenceButton.setOnClickListener(v -> {
|
||||||
|
callChangeListener(new Pair(IMPORTANCE_LOW, false));
|
||||||
|
updateToggles((ViewGroup) holder.itemView, IMPORTANCE_LOW, false, true);
|
||||||
|
});
|
||||||
|
mAlertButton.setOnClickListener(v -> {
|
||||||
|
int newImportance = Math.max(mOriginalImportance, IMPORTANCE_DEFAULT);
|
||||||
|
callChangeListener(new Pair(newImportance, false));
|
||||||
|
updateToggles((ViewGroup) holder.itemView, newImportance, false, true);
|
||||||
|
});
|
||||||
|
mPriorityButton.setOnClickListener(v -> {
|
||||||
|
int newImportance = Math.max(mOriginalImportance, IMPORTANCE_DEFAULT);
|
||||||
|
callChangeListener(new Pair(newImportance, true));
|
||||||
|
updateToggles((ViewGroup) holder.itemView, newImportance, true, true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private ColorStateList getAccentTint() {
|
||||||
|
return Utils.getColorAccent(getContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ColorStateList getRegularTint() {
|
||||||
|
return Utils.getColorAttr(getContext(), android.R.attr.textColorPrimary);
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateToggles(ViewGroup parent, int importance, boolean isPriority,
|
||||||
|
boolean fromUser) {
|
||||||
|
if (fromUser) {
|
||||||
|
AutoTransition transition = new AutoTransition();
|
||||||
|
transition.setDuration(BUTTON_ANIM_TIME_MS);
|
||||||
|
TransitionManager.beginDelayedTransition(parent, transition);
|
||||||
|
}
|
||||||
|
|
||||||
|
ColorStateList colorAccent = getAccentTint();
|
||||||
|
ColorStateList colorNormal = getRegularTint();
|
||||||
|
ImageView silenceIcon = parent.findViewById(R.id.silence_icon);
|
||||||
|
TextView silenceLabel = parent.findViewById(R.id.silence_label);
|
||||||
|
TextView silenceSummary = parent.findViewById(R.id.silence_summary);
|
||||||
|
ImageView alertIcon = parent.findViewById(R.id.alert_icon);
|
||||||
|
TextView alertLabel = parent.findViewById(R.id.alert_label);
|
||||||
|
TextView alertSummary = parent.findViewById(R.id.alert_summary);
|
||||||
|
ImageView priorityIcon = parent.findViewById(R.id.priority_icon);
|
||||||
|
TextView priorityLabel = parent.findViewById(R.id.priority_label);
|
||||||
|
TextView prioritySummary = parent.findViewById(R.id.priority_summary);
|
||||||
|
|
||||||
|
if (importance <= IMPORTANCE_LOW && importance > IMPORTANCE_UNSPECIFIED) {
|
||||||
|
alertSummary.setVisibility(GONE);
|
||||||
|
alertIcon.setImageTintList(colorNormal);
|
||||||
|
alertLabel.setTextColor(colorNormal);
|
||||||
|
|
||||||
|
prioritySummary.setVisibility(GONE);
|
||||||
|
priorityIcon.setImageTintList(colorNormal);
|
||||||
|
priorityLabel.setTextColor(colorNormal);
|
||||||
|
|
||||||
|
silenceIcon.setImageTintList(colorAccent);
|
||||||
|
silenceLabel.setTextColor(colorAccent);
|
||||||
|
silenceSummary.setVisibility(VISIBLE);
|
||||||
|
|
||||||
|
mAlertButton.setBackground(unselectedBackground);
|
||||||
|
mPriorityButton.setBackground(unselectedBackground);
|
||||||
|
mSilenceButton.setBackground(selectedBackground);
|
||||||
|
// a11y service won't always read the newly appearing text in the right order if the
|
||||||
|
// selection happens too soon (readback happens on a different thread as layout). post
|
||||||
|
// the selection to make that conflict less likely
|
||||||
|
parent.post(() -> mSilenceButton.setSelected(true));
|
||||||
|
} else {
|
||||||
|
if (isPriority) {
|
||||||
|
alertSummary.setVisibility(GONE);
|
||||||
|
alertIcon.setImageTintList(colorNormal);
|
||||||
|
alertLabel.setTextColor(colorNormal);
|
||||||
|
|
||||||
|
prioritySummary.setVisibility(VISIBLE);
|
||||||
|
priorityIcon.setImageTintList(colorAccent);
|
||||||
|
priorityLabel.setTextColor(colorAccent);
|
||||||
|
|
||||||
|
silenceIcon.setImageTintList(colorNormal);
|
||||||
|
silenceLabel.setTextColor(colorNormal);
|
||||||
|
silenceSummary.setVisibility(GONE);
|
||||||
|
|
||||||
|
mAlertButton.setBackground(unselectedBackground);
|
||||||
|
mPriorityButton.setBackground(selectedBackground);
|
||||||
|
mSilenceButton.setBackground(unselectedBackground);
|
||||||
|
parent.post(() -> mPriorityButton.setSelected(true));
|
||||||
|
} else {
|
||||||
|
alertSummary.setVisibility(VISIBLE);
|
||||||
|
alertIcon.setImageTintList(colorAccent);
|
||||||
|
alertLabel.setTextColor(colorAccent);
|
||||||
|
|
||||||
|
prioritySummary.setVisibility(GONE);
|
||||||
|
priorityIcon.setImageTintList(colorNormal);
|
||||||
|
priorityLabel.setTextColor(colorNormal);
|
||||||
|
|
||||||
|
silenceIcon.setImageTintList(colorNormal);
|
||||||
|
silenceLabel.setTextColor(colorNormal);
|
||||||
|
silenceSummary.setVisibility(GONE);
|
||||||
|
|
||||||
|
mAlertButton.setBackground(selectedBackground);
|
||||||
|
mPriorityButton.setBackground(unselectedBackground);
|
||||||
|
mSilenceButton.setBackground(unselectedBackground);
|
||||||
|
parent.post(() -> mAlertButton.setSelected(true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -16,25 +16,22 @@
|
|||||||
|
|
||||||
package com.android.settings.notification.app;
|
package com.android.settings.notification.app;
|
||||||
|
|
||||||
import static android.provider.Settings.Secure.BUBBLE_IMPORTANT_CONVERSATIONS;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.provider.Settings;
|
import android.util.Pair;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
import com.android.settings.notification.NotificationBackend;
|
import com.android.settings.notification.NotificationBackend;
|
||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
|
||||||
|
|
||||||
public class ConversationImportantPreferenceController extends NotificationPreferenceController
|
public class ConversationPriorityPreferenceController extends NotificationPreferenceController
|
||||||
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
|
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
private static final String TAG = "ConvoImpPC";
|
private static final String TAG = "ConvoPriorityPC";
|
||||||
private static final String KEY = "important";
|
private static final String KEY = "priority";
|
||||||
private final NotificationSettings.DependentFieldListener mDependentFieldListener;
|
private final NotificationSettings.DependentFieldListener mDependentFieldListener;
|
||||||
|
|
||||||
public ConversationImportantPreferenceController(Context context,
|
public ConversationPriorityPreferenceController(Context context,
|
||||||
NotificationBackend backend, NotificationSettings.DependentFieldListener listener) {
|
NotificationBackend backend, NotificationSettings.DependentFieldListener listener) {
|
||||||
super(context, backend);
|
super(context, backend);
|
||||||
mDependentFieldListener = listener;
|
mDependentFieldListener = listener;
|
||||||
@@ -58,10 +55,12 @@ public class ConversationImportantPreferenceController extends NotificationPrefe
|
|||||||
|
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mAppRow != null) {
|
if (mAppRow != null) {
|
||||||
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
preference.setEnabled(mAdmin == null && !mChannel.isImportanceLockedByOEM());
|
||||||
pref.setDisabledByAdmin(mAdmin);
|
ConversationPriorityPreference pref = (ConversationPriorityPreference) preference;
|
||||||
pref.setChecked(mChannel.isImportantConversation());
|
pref.setConfigurable(!mChannel.isImportanceLockedByOEM());
|
||||||
pref.setEnabled(!pref.isDisabledByAdmin());
|
pref.setImportance(mChannel.getImportance());
|
||||||
|
pref.setOriginalImportance(mChannel.getOriginalImportance());
|
||||||
|
pref.setPriorityConversation(mChannel.isImportantConversation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,19 +69,21 @@ public class ConversationImportantPreferenceController extends NotificationPrefe
|
|||||||
if (mChannel == null) {
|
if (mChannel == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final boolean value = (Boolean) newValue;
|
boolean wasPriorityConversation = mChannel.isImportantConversation();
|
||||||
mChannel.setImportantConversation(value);
|
|
||||||
if (value && bubbleImportantConversations()) {
|
final Pair<Integer, Boolean> value = (Pair) newValue;
|
||||||
|
mChannel.setImportance(value.first);
|
||||||
|
mChannel.setImportantConversation(value.second);
|
||||||
|
|
||||||
|
if (value.second) {
|
||||||
mChannel.setAllowBubbles(true);
|
mChannel.setAllowBubbles(true);
|
||||||
|
} else if (wasPriorityConversation) {
|
||||||
|
mChannel.setAllowBubbles(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
mDependentFieldListener.onFieldValueChanged();
|
mDependentFieldListener.onFieldValueChanged();
|
||||||
saveChannel();
|
saveChannel();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean bubbleImportantConversations() {
|
|
||||||
return Settings.Secure.getInt(mContext.getContentResolver(),
|
|
||||||
BUBBLE_IMPORTANT_CONVERSATIONS, 1) == 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
@@ -1,85 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2020 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.notification.app;
|
|
||||||
|
|
||||||
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
|
|
||||||
import static android.app.NotificationManager.IMPORTANCE_LOW;
|
|
||||||
|
|
||||||
import android.app.NotificationChannel;
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
|
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
|
||||||
import com.android.settings.notification.NotificationBackend;
|
|
||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
|
||||||
|
|
||||||
public class DefaultImportancePreferenceController extends NotificationPreferenceController
|
|
||||||
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
|
|
||||||
|
|
||||||
private static final String KEY = "alerting";
|
|
||||||
private NotificationSettings.DependentFieldListener mDependentFieldListener;
|
|
||||||
|
|
||||||
public DefaultImportancePreferenceController(Context context,
|
|
||||||
NotificationSettings.DependentFieldListener dependentFieldListener,
|
|
||||||
NotificationBackend backend) {
|
|
||||||
super(context, backend);
|
|
||||||
mDependentFieldListener = dependentFieldListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPreferenceKey() {
|
|
||||||
return KEY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAvailable() {
|
|
||||||
if (!super.isAvailable()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (mChannel == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (isDefaultChannel()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateState(Preference preference) {
|
|
||||||
if (mAppRow != null && mChannel != null) {
|
|
||||||
preference.setEnabled(mAdmin == null && !mChannel.isImportanceLockedByOEM());
|
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
|
||||||
pref.setChecked(mChannel.getImportance() >= IMPORTANCE_DEFAULT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
||||||
if (mChannel != null) {
|
|
||||||
final boolean checked = (boolean) newValue;
|
|
||||||
|
|
||||||
mChannel.setImportance(checked ? IMPORTANCE_DEFAULT : IMPORTANCE_LOW);
|
|
||||||
mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
|
|
||||||
saveChannel();
|
|
||||||
mDependentFieldListener.onFieldValueChanged();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -28,14 +28,14 @@ import com.android.settings.notification.NotificationBackend;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ImportantConversationsPreferenceController extends
|
public class PriorityConversationsPreferenceController extends
|
||||||
ConversationListPreferenceController {
|
ConversationListPreferenceController {
|
||||||
|
|
||||||
private static final String KEY = "important_conversations";
|
private static final String KEY = "important_conversations";
|
||||||
private static final String LIST_KEY = "important_conversations_list";
|
private static final String LIST_KEY = "important_conversations_list";
|
||||||
private List<ConversationChannelWrapper> mConversations;
|
private List<ConversationChannelWrapper> mConversations;
|
||||||
|
|
||||||
public ImportantConversationsPreferenceController(Context context,
|
public PriorityConversationsPreferenceController(Context context,
|
||||||
NotificationBackend backend) {
|
NotificationBackend backend) {
|
||||||
super(context, backend);
|
super(context, backend);
|
||||||
}
|
}
|
@@ -122,7 +122,7 @@ public class BubblePreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAvailable_channel_notIfAppOff() {
|
public void testIsAvailable_channel_yesIfAppOff() {
|
||||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.allowBubbles = false;
|
appRow.allowBubbles = false;
|
||||||
@@ -130,7 +130,7 @@ public class BubblePreferenceControllerTest {
|
|||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null);
|
||||||
|
|
||||||
assertFalse(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -199,18 +199,6 @@ public class BubblePreferenceControllerTest {
|
|||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsAvailable_channelAppOff() {
|
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
|
||||||
appRow.allowBubbles = false;
|
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
|
||||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
|
||||||
|
|
||||||
assertFalse(mController.isAvailable());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState_disabledByAdmin() {
|
public void testUpdateState_disabledByAdmin() {
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
|
@@ -1,206 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2020 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.notification.app;
|
|
||||||
|
|
||||||
import static android.app.NotificationChannel.DEFAULT_CHANNEL_ID;
|
|
||||||
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
|
|
||||||
import static android.app.NotificationManager.IMPORTANCE_HIGH;
|
|
||||||
import static android.provider.Settings.Secure.BUBBLE_IMPORTANT_CONVERSATIONS;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.times;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.app.NotificationChannel;
|
|
||||||
import android.app.NotificationManager;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.UserManager;
|
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.settings.notification.NotificationBackend;
|
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
|
||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Answers;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
|
||||||
public class ConversationImportantPreferenceControllerTest {
|
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
@Mock
|
|
||||||
private NotificationBackend mBackend;
|
|
||||||
@Mock
|
|
||||||
private NotificationManager mNm;
|
|
||||||
@Mock
|
|
||||||
private UserManager mUm;
|
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
|
||||||
private PreferenceScreen mScreen;
|
|
||||||
@Mock
|
|
||||||
private NotificationSettings.DependentFieldListener mDependentFieldListener;
|
|
||||||
|
|
||||||
private ConversationImportantPreferenceController mController;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
ShadowApplication shadowApplication = ShadowApplication.getInstance();
|
|
||||||
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
|
|
||||||
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
|
|
||||||
mContext = RuntimeEnvironment.application;
|
|
||||||
mController = spy(new ConversationImportantPreferenceController(
|
|
||||||
mContext, mBackend, mDependentFieldListener));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testNoCrashIfNoOnResume() {
|
|
||||||
mController.isAvailable();
|
|
||||||
mController.updateState(mock(Preference.class));
|
|
||||||
mController.onPreferenceChange(mock(Preference.class), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsAvailable_notChannelNull() {
|
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
|
||||||
assertFalse(mController.isAvailable());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsAvailable() {
|
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
|
||||||
assertTrue(mController.isAvailable());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUpdateState_disabledByAdmin() {
|
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
|
||||||
when(channel.getId()).thenReturn("something");
|
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
|
|
||||||
RestrictedLockUtils.EnforcedAdmin.class));
|
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
|
||||||
mController.updateState(pref);
|
|
||||||
|
|
||||||
assertFalse(pref.isEnabled());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUpdateState() {
|
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
|
||||||
channel.setImportantConversation(true);
|
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
|
||||||
|
|
||||||
RestrictedSwitchPreference pref =
|
|
||||||
new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
|
||||||
mController.updateState(pref);
|
|
||||||
|
|
||||||
assertTrue(pref.isChecked());
|
|
||||||
|
|
||||||
channel.setImportantConversation(false);
|
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
|
||||||
mController.updateState(pref);
|
|
||||||
assertFalse(pref.isChecked());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testOnPreferenceChange_on() {
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
|
||||||
BUBBLE_IMPORTANT_CONVERSATIONS, 0);
|
|
||||||
NotificationChannel channel =
|
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_DEFAULT);
|
|
||||||
channel.setImportantConversation(false);
|
|
||||||
channel.setAllowBubbles(false);
|
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
|
||||||
|
|
||||||
RestrictedSwitchPreference pref =
|
|
||||||
new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
|
||||||
mController.updateState(pref);
|
|
||||||
|
|
||||||
mController.onPreferenceChange(pref, true);
|
|
||||||
|
|
||||||
assertTrue(channel.isImportantConversation());
|
|
||||||
assertFalse(channel.canBubble());
|
|
||||||
verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
|
|
||||||
verify(mDependentFieldListener, times(1)).onFieldValueChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testOnPreferenceChange_on_bubble() {
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
|
||||||
BUBBLE_IMPORTANT_CONVERSATIONS, 1);
|
|
||||||
NotificationChannel channel =
|
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_DEFAULT);
|
|
||||||
channel.setImportantConversation(false);
|
|
||||||
channel.setAllowBubbles(false);
|
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
|
||||||
|
|
||||||
RestrictedSwitchPreference pref =
|
|
||||||
new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
|
||||||
mController.updateState(pref);
|
|
||||||
|
|
||||||
mController.onPreferenceChange(pref, true);
|
|
||||||
|
|
||||||
assertTrue(channel.isImportantConversation());
|
|
||||||
assertTrue(channel.canBubble());
|
|
||||||
verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
|
|
||||||
verify(mDependentFieldListener).onFieldValueChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testOnPreferenceChange_off() {
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
|
||||||
BUBBLE_IMPORTANT_CONVERSATIONS, 1);
|
|
||||||
NotificationChannel channel =
|
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
|
|
||||||
channel.setImportantConversation(true);
|
|
||||||
channel.setAllowBubbles(false);
|
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
|
||||||
|
|
||||||
RestrictedSwitchPreference pref =
|
|
||||||
new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
|
||||||
mController.displayPreference(mScreen);
|
|
||||||
mController.updateState(pref);
|
|
||||||
|
|
||||||
mController.onPreferenceChange(pref, false);
|
|
||||||
|
|
||||||
assertFalse(channel.isImportantConversation());
|
|
||||||
assertFalse(channel.canBubble());
|
|
||||||
verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
|
|
||||||
verify(mDependentFieldListener, times(1)).onFieldValueChanged();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
* Copyright (C) 2020 The Android Open Source Project
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -20,28 +20,32 @@ import static android.app.NotificationChannel.DEFAULT_CHANNEL_ID;
|
|||||||
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
|
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
|
||||||
import static android.app.NotificationManager.IMPORTANCE_HIGH;
|
import static android.app.NotificationManager.IMPORTANCE_HIGH;
|
||||||
import static android.app.NotificationManager.IMPORTANCE_LOW;
|
import static android.app.NotificationManager.IMPORTANCE_LOW;
|
||||||
import static android.app.NotificationManager.IMPORTANCE_NONE;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.app.Notification;
|
||||||
import android.app.NotificationChannel;
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
|
import android.util.Pair;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.notification.NotificationBackend;
|
import com.android.settings.notification.NotificationBackend;
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -54,21 +58,21 @@ import org.robolectric.RuntimeEnvironment;
|
|||||||
import org.robolectric.shadows.ShadowApplication;
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class DefaultImportancePreferenceControllerTest {
|
public class ConversationPriorityPreferenceControllerTest {
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
@Mock
|
@Mock
|
||||||
private NotificationManager mNm;
|
|
||||||
@Mock
|
|
||||||
private NotificationBackend mBackend;
|
private NotificationBackend mBackend;
|
||||||
@Mock
|
@Mock
|
||||||
private NotificationSettings.DependentFieldListener mDependentFieldListener;
|
private NotificationManager mNm;
|
||||||
@Mock
|
@Mock
|
||||||
private UserManager mUm;
|
private UserManager mUm;
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
|
@Mock
|
||||||
|
private NotificationSettings.DependentFieldListener mDependentFieldListener;
|
||||||
|
|
||||||
private DefaultImportancePreferenceController mController;
|
private ConversationPriorityPreferenceController mController;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -77,54 +81,28 @@ public class DefaultImportancePreferenceControllerTest {
|
|||||||
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
|
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
|
||||||
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
|
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
mController = spy(new DefaultImportancePreferenceController(
|
mController = spy(new ConversationPriorityPreferenceController(
|
||||||
mContext, mDependentFieldListener, mBackend));
|
mContext, mBackend, mDependentFieldListener));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoCrashIfNoOnResume() {
|
public void testNoCrashIfNoOnResume() {
|
||||||
mController.isAvailable();
|
mController.isAvailable();
|
||||||
mController.updateState(mock(Preference.class));
|
mController.updateState(mock(Preference.class));
|
||||||
|
mController.onPreferenceChange(mock(Preference.class), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAvailable_notIfNull() {
|
public void testIsAvailable_notChannelNull() {
|
||||||
mController.onResume(null, null, null, null, null, null);
|
|
||||||
assertFalse(mController.isAvailable());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsAvailable_ifAppBlocked() {
|
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.banned = true;
|
mController.onResume(appRow, null, null, null, null, null);
|
||||||
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
|
|
||||||
assertFalse(mController.isAvailable());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsAvailable_notIfChannelBlocked() {
|
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
|
||||||
assertFalse(mController.isAvailable());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsAvailable_notForDefaultChannel() {
|
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
|
||||||
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAvailable() {
|
public void testIsAvailable() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
|
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
@@ -136,7 +114,7 @@ public class DefaultImportancePreferenceControllerTest {
|
|||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
|
||||||
RestrictedLockUtils.EnforcedAdmin.class));
|
RestrictedLockUtils.EnforcedAdmin.class));
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(mContext, null);
|
Preference pref = new ConversationPriorityPreference(mContext, null);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
assertFalse(pref.isEnabled());
|
assertFalse(pref.isEnabled());
|
||||||
@@ -150,7 +128,7 @@ public class DefaultImportancePreferenceControllerTest {
|
|||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(mContext, null);
|
Preference pref = new ConversationPriorityPreference(mContext, null);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
assertFalse(pref.isEnabled());
|
assertFalse(pref.isEnabled());
|
||||||
@@ -165,7 +143,7 @@ public class DefaultImportancePreferenceControllerTest {
|
|||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(mContext, null);
|
Preference pref = new ConversationPriorityPreference(mContext, null);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
assertTrue(pref.isEnabled());
|
assertTrue(pref.isEnabled());
|
||||||
@@ -180,67 +158,120 @@ public class DefaultImportancePreferenceControllerTest {
|
|||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(mContext, null);
|
Preference pref = new ConversationPriorityPreference(mContext, null);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
assertTrue(pref.isEnabled());
|
assertTrue(pref.isEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState_default() {
|
public void testUpdateState() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
|
||||||
|
channel.setImportantConversation(true);
|
||||||
|
channel.setOriginalImportance(IMPORTANCE_DEFAULT);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
ConversationPriorityPreference pref = mock(ConversationPriorityPreference.class);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
assertTrue(pref.isChecked());
|
verify(pref, times(1)).setConfigurable(anyBoolean());
|
||||||
|
verify(pref, times(1)).setImportance(IMPORTANCE_HIGH);
|
||||||
|
verify(pref, times(1)).setOriginalImportance(IMPORTANCE_DEFAULT);
|
||||||
|
verify(pref, times(1)).setPriorityConversation(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState_low() {
|
public void testImportanceLowToImportant() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
|
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
|
||||||
mController.updateState(pref);
|
|
||||||
|
|
||||||
assertFalse(pref.isChecked());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onPreferenceChange_onToOff() {
|
|
||||||
NotificationChannel channel =
|
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
|
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext, null);
|
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
|
||||||
mController.displayPreference(mScreen);
|
|
||||||
mController.updateState(pref);
|
|
||||||
|
|
||||||
mController.onPreferenceChange(pref, false);
|
|
||||||
|
|
||||||
assertEquals(IMPORTANCE_LOW, channel.getImportance());
|
|
||||||
verify(mDependentFieldListener, times(1)).onFieldValueChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onPreferenceChange_offToOn() {
|
|
||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext, null);
|
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
mController.onPreferenceChange(pref, true);
|
mController.onPreferenceChange(pref, new Pair(IMPORTANCE_HIGH, true));
|
||||||
|
|
||||||
|
assertEquals(IMPORTANCE_HIGH, channel.getImportance());
|
||||||
|
assertTrue(channel.canBubble());
|
||||||
|
assertTrue(channel.isImportantConversation());
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testImportanceLowToDefault() {
|
||||||
|
NotificationChannel channel =
|
||||||
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
|
||||||
|
channel.setAllowBubbles(false);
|
||||||
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
||||||
|
|
||||||
|
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
|
||||||
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
mController.updateState(pref);
|
||||||
|
|
||||||
|
mController.onPreferenceChange(pref, new Pair(IMPORTANCE_HIGH, false));
|
||||||
|
|
||||||
|
assertEquals(IMPORTANCE_HIGH, channel.getImportance());
|
||||||
|
assertFalse(channel.canBubble());
|
||||||
|
assertFalse(channel.isImportantConversation());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testImportanceDefaultToLow() {
|
||||||
|
NotificationChannel channel =
|
||||||
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_DEFAULT);
|
||||||
|
channel.setAllowBubbles(false);
|
||||||
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
||||||
|
|
||||||
|
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
|
||||||
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
mController.updateState(pref);
|
||||||
|
|
||||||
|
mController.onPreferenceChange(pref, new Pair(IMPORTANCE_LOW, false));
|
||||||
|
|
||||||
|
assertEquals(IMPORTANCE_LOW, channel.getImportance());
|
||||||
|
assertFalse(channel.canBubble());
|
||||||
|
assertFalse(channel.isImportantConversation());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testImportanceLowToDefault_bubblesMaintained() {
|
||||||
|
NotificationChannel channel =
|
||||||
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
|
||||||
|
channel.setAllowBubbles(true);
|
||||||
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
||||||
|
|
||||||
|
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
|
||||||
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
mController.updateState(pref);
|
||||||
|
|
||||||
|
mController.onPreferenceChange(pref, new Pair(IMPORTANCE_DEFAULT, false));
|
||||||
|
|
||||||
assertEquals(IMPORTANCE_DEFAULT, channel.getImportance());
|
assertEquals(IMPORTANCE_DEFAULT, channel.getImportance());
|
||||||
verify(mDependentFieldListener, times(1)).onFieldValueChanged();
|
assertTrue(channel.canBubble());
|
||||||
|
assertFalse(channel.isImportantConversation());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testImportancePriorityToDefault() {
|
||||||
|
NotificationChannel channel =
|
||||||
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
|
||||||
|
channel.setAllowBubbles(true);
|
||||||
|
channel.setImportantConversation(true);
|
||||||
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
||||||
|
|
||||||
|
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
|
||||||
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
mController.updateState(pref);
|
||||||
|
|
||||||
|
mController.onPreferenceChange(pref, new Pair(IMPORTANCE_HIGH, false));
|
||||||
|
|
||||||
|
assertEquals(IMPORTANCE_HIGH, channel.getImportance());
|
||||||
|
assertFalse(channel.canBubble());
|
||||||
|
assertFalse(channel.isImportantConversation());
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -0,0 +1,172 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.notification.app;
|
||||||
|
|
||||||
|
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
|
||||||
|
import static android.app.NotificationManager.IMPORTANCE_LOW;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.util.Pair;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.preference.PreferenceViewHolder;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
public class ConversationPriorityPreferenceTest {
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mContext = RuntimeEnvironment.application;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createNewPreference_shouldSetLayout() {
|
||||||
|
final ConversationPriorityPreference preference =
|
||||||
|
new ConversationPriorityPreference(mContext);
|
||||||
|
assertThat(preference.getLayoutResource()).isEqualTo(
|
||||||
|
R.layout.notif_priority_conversation_preference);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onBindViewHolder_nonConfigurable() {
|
||||||
|
final ConversationPriorityPreference preference =
|
||||||
|
new ConversationPriorityPreference(mContext);
|
||||||
|
final LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||||
|
PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
|
||||||
|
inflater.inflate(preference.getLayoutResource(), null));
|
||||||
|
Drawable unselected = mock(Drawable.class);
|
||||||
|
Drawable selected = mock(Drawable.class);
|
||||||
|
preference.selectedBackground = selected;
|
||||||
|
preference.unselectedBackground = unselected;
|
||||||
|
|
||||||
|
preference.setConfigurable(false);
|
||||||
|
preference.setImportance(IMPORTANCE_DEFAULT);
|
||||||
|
preference.setPriorityConversation(true);
|
||||||
|
preference.onBindViewHolder(holder);
|
||||||
|
|
||||||
|
assertThat(holder.itemView.findViewById(R.id.silence).isEnabled()).isFalse();
|
||||||
|
assertThat(holder.itemView.findViewById(R.id.priority_group).isEnabled()).isFalse();
|
||||||
|
assertThat(holder.itemView.findViewById(R.id.alert).isEnabled()).isFalse();
|
||||||
|
|
||||||
|
assertThat(holder.itemView.findViewById(R.id.priority_group).getBackground())
|
||||||
|
.isEqualTo(selected);
|
||||||
|
assertThat(holder.itemView.findViewById(R.id.alert).getBackground()).isEqualTo(unselected);
|
||||||
|
assertThat(holder.itemView.findViewById(R.id.silence).getBackground())
|
||||||
|
.isEqualTo(unselected);
|
||||||
|
|
||||||
|
// other button
|
||||||
|
preference.setPriorityConversation(false);
|
||||||
|
holder = PreferenceViewHolder.createInstanceForTests(
|
||||||
|
inflater.inflate(preference.getLayoutResource(), null));
|
||||||
|
preference.onBindViewHolder(holder);
|
||||||
|
|
||||||
|
assertThat(holder.itemView.findViewById(R.id.alert).getBackground()).isEqualTo(selected);
|
||||||
|
assertThat(holder.itemView.findViewById(R.id.silence).getBackground())
|
||||||
|
.isEqualTo(unselected);
|
||||||
|
assertThat(holder.itemView.findViewById(R.id.priority_group).getBackground())
|
||||||
|
.isEqualTo(unselected);
|
||||||
|
|
||||||
|
// other other button
|
||||||
|
preference.setImportance(IMPORTANCE_LOW);
|
||||||
|
holder = PreferenceViewHolder.createInstanceForTests(
|
||||||
|
inflater.inflate(preference.getLayoutResource(), null));
|
||||||
|
preference.onBindViewHolder(holder);
|
||||||
|
|
||||||
|
assertThat(holder.itemView.findViewById(R.id.priority_group).getBackground())
|
||||||
|
.isEqualTo(unselected);
|
||||||
|
assertThat(holder.itemView.findViewById(R.id.alert).getBackground()).isEqualTo(unselected);
|
||||||
|
assertThat(holder.itemView.findViewById(R.id.silence).getBackground()).isEqualTo(selected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onBindViewHolder_selectButtonAndText() {
|
||||||
|
final ConversationPriorityPreference preference =
|
||||||
|
new ConversationPriorityPreference(mContext);
|
||||||
|
final LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||||
|
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
|
||||||
|
inflater.inflate(preference.getLayoutResource(), null));
|
||||||
|
Drawable unselected = mock(Drawable.class);
|
||||||
|
Drawable selected = mock(Drawable.class);
|
||||||
|
preference.selectedBackground = selected;
|
||||||
|
preference.unselectedBackground = unselected;
|
||||||
|
|
||||||
|
preference.setConfigurable(true);
|
||||||
|
preference.setImportance(IMPORTANCE_LOW);
|
||||||
|
preference.setPriorityConversation(true);
|
||||||
|
|
||||||
|
preference.onBindViewHolder(holder);
|
||||||
|
|
||||||
|
assertThat(holder.itemView.findViewById(R.id.priority_group).getBackground())
|
||||||
|
.isEqualTo(unselected);
|
||||||
|
assertThat(holder.itemView.findViewById(R.id.alert).getBackground()).isEqualTo(unselected);
|
||||||
|
assertThat(holder.itemView.findViewById(R.id.silence).getBackground())
|
||||||
|
.isEqualTo(selected);
|
||||||
|
assertThat(holder.itemView.findViewById(R.id.silence_summary).getVisibility())
|
||||||
|
.isEqualTo(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onClick_changesUICallsListener() {
|
||||||
|
final ConversationPriorityPreference preference =
|
||||||
|
spy(new ConversationPriorityPreference(mContext));
|
||||||
|
final LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||||
|
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
|
||||||
|
inflater.inflate(preference.getLayoutResource(), null));
|
||||||
|
Drawable unselected = mock(Drawable.class);
|
||||||
|
Drawable selected = mock(Drawable.class);
|
||||||
|
preference.selectedBackground = selected;
|
||||||
|
preference.unselectedBackground = unselected;
|
||||||
|
|
||||||
|
preference.setConfigurable(true);
|
||||||
|
preference.setImportance(IMPORTANCE_DEFAULT);
|
||||||
|
preference.setPriorityConversation(true);
|
||||||
|
preference.setOriginalImportance(IMPORTANCE_DEFAULT);
|
||||||
|
preference.onBindViewHolder(holder);
|
||||||
|
|
||||||
|
View silenceButton = holder.itemView.findViewById(R.id.silence);
|
||||||
|
|
||||||
|
silenceButton.callOnClick();
|
||||||
|
|
||||||
|
assertThat(holder.itemView.findViewById(R.id.alert).getBackground()).isEqualTo(unselected);
|
||||||
|
assertThat(holder.itemView.findViewById(R.id.priority_group).getBackground())
|
||||||
|
.isEqualTo(unselected);
|
||||||
|
assertThat(holder.itemView.findViewById(R.id.silence).getBackground())
|
||||||
|
.isEqualTo(selected);
|
||||||
|
|
||||||
|
verify(preference, times(1)).callChangeListener(new Pair(IMPORTANCE_LOW, false));
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user