Merge "Remove NAS adjustments related settings" into sc-dev

This commit is contained in:
Chloris Kuo
2021-02-09 17:12:24 +00:00
committed by Android (Google) Code Review
5 changed files with 0 additions and 318 deletions

View File

@@ -115,12 +115,6 @@
android:title="@string/snooze_options_title"
settings:controller="com.android.settings.notification.SnoozeNotificationPreferenceController" />
<SwitchPreference
android:key="asst_capabilities_actions_replies"
android:title="@string/asst_capabilities_actions_replies_title"
android:summary="@string/asst_capabilities_actions_replies_summary"
settings:controller="com.android.settings.notification.AssistantCapabilityPreferenceController" />
<!-- Notification badging -->
<SwitchPreference
android:key="notification_badging"

View File

@@ -134,12 +134,6 @@
android:title="@string/snooze_options_title"
settings:controller="com.android.settings.notification.SnoozeNotificationPreferenceController" />
<SwitchPreference
android:key="asst_capabilities_actions_replies"
android:title="@string/asst_capabilities_actions_replies_title"
android:summary="@string/asst_capabilities_actions_replies_summary"
settings:controller="com.android.settings.notification.AssistantCapabilityPreferenceController" />
<!-- Notification badging -->
<SwitchPreference
android:key="notification_badging"

View File

@@ -592,16 +592,6 @@
android:title="@string/show_notification_channel_warnings"
android:summary="@string/show_notification_channel_warnings_summary" />
<SwitchPreference
android:key="asst_capability_prioritizer"
android:title="@string/asst_capability_prioritizer_title"
settings:controller="com.android.settings.notification.AssistantCapabilityPreferenceController" />
<SwitchPreference
android:key="asst_capability_ranking"
android:title="@string/asst_capability_ranking_title"
settings:controller="com.android.settings.notification.AssistantCapabilityPreferenceController" />
<SwitchPreference
android:key="asst_feedback_indicator"
android:title="@string/asst_feedback_indicator_title"

View File

@@ -1,79 +0,0 @@
/*
* Copyright (C) 2019 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;
import android.content.Context;
import android.service.notification.Adjustment;
import com.android.settings.core.TogglePreferenceController;
import com.google.common.annotations.VisibleForTesting;
import java.util.List;
public class AssistantCapabilityPreferenceController extends TogglePreferenceController {
static final String PRIORITIZER_KEY = "asst_capability_prioritizer";
static final String RANKING_KEY = "asst_capability_ranking";
static final String SMART_KEY = "asst_capabilities_actions_replies";
private NotificationBackend mBackend;
public AssistantCapabilityPreferenceController(Context context, String key) {
super(context, key);
mBackend = new NotificationBackend();
}
@VisibleForTesting
void setBackend(NotificationBackend backend) {
mBackend = backend;
}
@Override
public boolean isChecked() {
List<String> capabilities = mBackend.getAssistantAdjustments(mContext.getPackageName());
if (PRIORITIZER_KEY.equals(getPreferenceKey())) {
return capabilities.contains(Adjustment.KEY_IMPORTANCE);
} else if (RANKING_KEY.equals(getPreferenceKey())) {
return capabilities.contains(Adjustment.KEY_RANKING_SCORE);
} else if (SMART_KEY.equals(getPreferenceKey())) {
return capabilities.contains(Adjustment.KEY_CONTEXTUAL_ACTIONS)
&& capabilities.contains(Adjustment.KEY_TEXT_REPLIES);
}
return false;
}
@Override
public boolean setChecked(boolean isChecked) {
if (PRIORITIZER_KEY.equals(getPreferenceKey())) {
mBackend.allowAssistantAdjustment(Adjustment.KEY_IMPORTANCE, isChecked);
} else if (RANKING_KEY.equals(getPreferenceKey())) {
mBackend.allowAssistantAdjustment(Adjustment.KEY_RANKING_SCORE, isChecked);
} else if (SMART_KEY.equals(getPreferenceKey())) {
mBackend.allowAssistantAdjustment(Adjustment.KEY_CONTEXTUAL_ACTIONS, isChecked);
mBackend.allowAssistantAdjustment(Adjustment.KEY_TEXT_REPLIES, isChecked);
}
return true;
}
@Override
public int getAvailabilityStatus() {
return mBackend.getAllowedNotificationAssistant() != null
? AVAILABLE : DISABLED_DEPENDENT_SETTING;
}
}

View File

@@ -1,217 +0,0 @@
/*
* Copyright (C) 2019 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;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
import static com.android.settings.notification.AssistantCapabilityPreferenceController.PRIORITIZER_KEY;
import static com.android.settings.notification.AssistantCapabilityPreferenceController.RANKING_KEY;
import static com.android.settings.notification.AssistantCapabilityPreferenceController.SMART_KEY;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.ComponentName;
import android.content.Context;
import android.service.notification.Adjustment;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import java.util.ArrayList;
import java.util.List;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
@RunWith(RobolectricTestRunner.class)
public class AssistantCapabilityPreferenceControllerTest {
@Mock
private NotificationBackend mBackend;
@Mock
private PreferenceScreen mScreen;
private Context mContext;
private AssistantCapabilityPreferenceController mPrioritizerController;
private AssistantCapabilityPreferenceController mRankingController;
private AssistantCapabilityPreferenceController mChipController;
private Preference mPrioritizerPreference;
private Preference mRankingPreference;
private Preference mChipPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mPrioritizerController = new AssistantCapabilityPreferenceController(
mContext, PRIORITIZER_KEY);
mPrioritizerController.setBackend(mBackend);
mPrioritizerPreference = new Preference(mContext);
mPrioritizerPreference.setKey(mPrioritizerController.getPreferenceKey());
when(mScreen.findPreference(
mPrioritizerController.getPreferenceKey())).thenReturn(mPrioritizerPreference);
mRankingController = new AssistantCapabilityPreferenceController(
mContext, RANKING_KEY);
mRankingController.setBackend(mBackend);
mRankingPreference = new Preference(mContext);
mRankingPreference.setKey(mRankingController.getPreferenceKey());
when(mScreen.findPreference(
mRankingController.getPreferenceKey())).thenReturn(mRankingPreference);
mChipController = new AssistantCapabilityPreferenceController(mContext, SMART_KEY);
mChipController.setBackend(mBackend);
mChipPreference = new Preference(mContext);
mChipPreference.setKey(mChipController.getPreferenceKey());
when(mScreen.findPreference(
mChipController.getPreferenceKey())).thenReturn(mChipPreference);
}
@Test
public void getAvailabilityStatus_NAS() {
when(mBackend.getAllowedNotificationAssistant()).thenReturn(mock(ComponentName.class));
assertThat(mPrioritizerController.getAvailabilityStatus())
.isEqualTo(AVAILABLE);
assertThat(mChipController.getAvailabilityStatus())
.isEqualTo(AVAILABLE);
}
@Test
public void getAvailabilityStatus_noNAS() {
when(mBackend.getAllowedNotificationAssistant()).thenReturn(null);
assertThat(mPrioritizerController.getAvailabilityStatus())
.isEqualTo(DISABLED_DEPENDENT_SETTING);
assertThat(mChipController.getAvailabilityStatus())
.isEqualTo(DISABLED_DEPENDENT_SETTING);
}
@Test
public void isChecked_prioritizerSettingIsOff_false() {
List<String> capabilities = new ArrayList<>();
capabilities.add(Adjustment.KEY_USER_SENTIMENT);
when(mBackend.getAssistantAdjustments(anyString())).thenReturn(capabilities);
assertThat(mPrioritizerController.isChecked()).isFalse();
}
@Test
public void isChecked_prioritizerSettingIsOn_true() {
List<String> capabilities = new ArrayList<>();
capabilities.add(Adjustment.KEY_IMPORTANCE);
when(mBackend.getAssistantAdjustments(anyString())).thenReturn(capabilities);
assertThat(mPrioritizerController.isChecked()).isTrue();
capabilities = new ArrayList<>();
capabilities.add(Adjustment.KEY_RANKING_SCORE);
when(mBackend.getAssistantAdjustments(anyString())).thenReturn(capabilities);
assertThat(mPrioritizerController.isChecked()).isFalse();
}
@Test
public void isChecked_rankingSettingIsOff_false() {
List<String> capabilities = new ArrayList<>();
capabilities.add(Adjustment.KEY_IMPORTANCE);
when(mBackend.getAssistantAdjustments(anyString())).thenReturn(capabilities);
assertThat(mRankingController.isChecked()).isFalse();
}
@Test
public void isChecked_rankingSettingIsOn_true() {
List<String> capabilities = new ArrayList<>();
capabilities.add(Adjustment.KEY_RANKING_SCORE);
when(mBackend.getAssistantAdjustments(anyString())).thenReturn(capabilities);
assertThat(mRankingController.isChecked()).isTrue();
}
@Test
public void isChecked_chipSettingIsOff_false() {
List<String> capabilities = new ArrayList<>();
capabilities.add(Adjustment.KEY_IMPORTANCE);
when(mBackend.getAssistantAdjustments(anyString())).thenReturn(capabilities);
assertThat(mChipController.isChecked()).isFalse();
capabilities = new ArrayList<>();
capabilities.add(Adjustment.KEY_RANKING_SCORE);
when(mBackend.getAssistantAdjustments(anyString())).thenReturn(capabilities);
assertThat(mChipController.isChecked()).isFalse();
capabilities = new ArrayList<>();
capabilities.add(Adjustment.KEY_CONTEXTUAL_ACTIONS);
when(mBackend.getAssistantAdjustments(anyString())).thenReturn(capabilities);
assertThat(mChipController.isChecked()).isFalse();
capabilities = new ArrayList<>();
capabilities.add(Adjustment.KEY_TEXT_REPLIES);
when(mBackend.getAssistantAdjustments(anyString())).thenReturn(capabilities);
assertThat(mChipController.isChecked()).isFalse();
}
@Test
public void isChecked_chipSettingIsOn_true() {
List<String> capabilities = new ArrayList<>();
capabilities.add(Adjustment.KEY_TEXT_REPLIES);
capabilities.add(Adjustment.KEY_CONTEXTUAL_ACTIONS);
when(mBackend.getAssistantAdjustments(anyString())).thenReturn(capabilities);
assertThat(mChipController.isChecked()).isTrue();
}
@Test
public void onPreferenceChange_prioritizerOn() {
mPrioritizerController.onPreferenceChange(mPrioritizerPreference, true);
verify(mBackend).allowAssistantAdjustment(Adjustment.KEY_IMPORTANCE, true);
}
@Test
public void onPreferenceChange_prioritizerOff() {
mPrioritizerController.onPreferenceChange(mPrioritizerPreference, false);
verify(mBackend).allowAssistantAdjustment(Adjustment.KEY_IMPORTANCE, false);
}
@Test
public void onPreferenceChange_rankingOn() {
mRankingController.onPreferenceChange(mRankingPreference, true);
verify(mBackend).allowAssistantAdjustment(Adjustment.KEY_RANKING_SCORE, true);
}
@Test
public void onPreferenceChange_rankingOff() {
mRankingController.onPreferenceChange(mRankingPreference, false);
verify(mBackend).allowAssistantAdjustment(Adjustment.KEY_RANKING_SCORE, false);
}
@Test
public void onPreferenceChange_chipsOn() {
mChipController.onPreferenceChange(mChipPreference, true);
verify(mBackend).allowAssistantAdjustment(Adjustment.KEY_CONTEXTUAL_ACTIONS, true);
verify(mBackend).allowAssistantAdjustment(Adjustment.KEY_TEXT_REPLIES, true);
}
@Test
public void onPreferenceChange_chipsOff() {
mChipController.onPreferenceChange(mChipPreference, false);
verify(mBackend).allowAssistantAdjustment(Adjustment.KEY_CONTEXTUAL_ACTIONS, false);
verify(mBackend).allowAssistantAdjustment(Adjustment.KEY_TEXT_REPLIES, false);
}
}