Clean un-used code for notification cool down

Clean the un-used code for notification cool down.

Bug: 330606963
Test: PoliteNotificationGlobalPreferenceControllerTest
Flag: com.android.server.notification.polite_notifications
Change-Id: I081a35c8be8b9996fabb04b238cb426f0da2de58
This commit is contained in:
Yining Liu
2024-05-23 01:16:12 +00:00
parent fae05be212
commit 3d0640985b
7 changed files with 0 additions and 509 deletions

View File

@@ -1511,20 +1511,6 @@
<item>fr</item> <!-- French --> <item>fr</item> <!-- French -->
</string-array> </string-array>
<!-- Values for notification cooldown -->
<string-array name="notification_polite_options">
<item>@string/notification_polite_all_apps</item>
<item>@string/notification_polite_conversations</item>
<item>@string/notification_polite_disabled</item>
</string-array>
<!-- Values for notification cooldown -->
<string-array name="notification_polite_options_values" translatable="false">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
<!-- Entries for private space auto lock option --> <!-- Entries for private space auto lock option -->
<string-array name="private_space_auto_lock_options"> <string-array name="private_space_auto_lock_options">
<item>@string/private_space_auto_lock_every_time</item> <item>@string/private_space_auto_lock_every_time</item>

View File

@@ -8683,14 +8683,6 @@
<string name="notification_polite_title">Cooldown</string> <string name="notification_polite_title">Cooldown</string>
<string name="notification_polite_main_control_title">Use Cooldown</string> <string name="notification_polite_main_control_title">Use Cooldown</string>
<string name="notification_polite_description">When you get many notifications within a short time span, your device will minimize sound interruptions and pop-ups on the screen. Calls, alarms, and priority conversations will still alert as notmal, and all delivered notifications are easy to find in the Shade.</string> <string name="notification_polite_description">When you get many notifications within a short time span, your device will minimize sound interruptions and pop-ups on the screen. Calls, alarms, and priority conversations will still alert as notmal, and all delivered notifications are easy to find in the Shade.</string>
<string name="notification_polite_all_apps">Apply cooldown to all notifications</string>
<string name="notification_polite_all_apps_summary">Gradually lower the notification volume when you get many successive notifications from the same app</string>
<string name="notification_polite_conversations">Apply cooldown to conversations</string>
<string name="notification_polite_conversations_summary">Gradually lower the notification volume when you get many messages from the same chat within a short period of time</string>
<string name="notification_polite_disabled">Don\'t use notification cooldown</string>
<string name="notification_polite_disabled_summary">Never lower notification volume, regardless of the amount of successive notifications from the same app</string>
<string name="notification_polite_vibrate_unlocked">Vibrate when unlocked</string>
<string name="notification_polite_vibrate_unlocked_summary">Only vibrate when screen is unlocked</string>
<string name="notification_polite_work">Apply to work profiles</string> <string name="notification_polite_work">Apply to work profiles</string>
<string name="notification_polite_work_summary">Apply to work profile apps</string> <string name="notification_polite_work_summary">Apply to work profile apps</string>

View File

@@ -17,24 +17,8 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto" xmlns:settings="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:title="@string/notification_polite_title"> android:title="@string/notification_polite_title">
<!-- <com.android.settings.RestrictedListPreference-->
<!-- android:key="polite_notifications_pref_dlg"-->
<!-- android:persistent="false"-->
<!-- android:title="@string/notification_polite_title"-->
<!-- android:entries="@array/notification_polite_options"-->
<!-- android:entryValues="@array/notification_polite_options_values"-->
<!-- settings:controller="com.android.settings.notification.PoliteNotificationFilterController"/>-->
<!-- <SwitchPreferenceCompat-->
<!-- android:key="notification_polite_vibrate_unlocked"-->
<!-- android:persistent="false"-->
<!-- android:title="@string/notification_polite_vibrate_unlocked"-->
<!-- android:summary="@string/notification_polite_vibrate_unlocked_summary"-->
<!-- settings:controller="com.android.settings.notification.PoliteNotifVibrateUnlockedToggleController" />-->
<com.android.settingslib.widget.TopIntroPreference <com.android.settingslib.widget.TopIntroPreference
android:key="polite_notification_desc" android:key="polite_notification_desc"
android:title="@string/notification_polite_description"/> android:title="@string/notification_polite_description"/>

View File

@@ -1,66 +0,0 @@
/*
* Copyright (C) 2023 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.accessibility.AccessibilityUtil.State.OFF;
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
import android.content.Context;
import android.os.Vibrator;
import android.provider.Settings;
import com.android.server.notification.Flags;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
/**
* Controls the toggle that determines whether notifications
* should only vibrate (no sound) when the device is unlocked.
*/
public class PoliteNotifVibrateUnlockedToggleController extends TogglePreferenceController {
public PoliteNotifVibrateUnlockedToggleController(Context context, String preferenceKey) {
super(context, preferenceKey);
}
@Override
public int getAvailabilityStatus() {
// TODO: b/291897570 - remove this when the feature flag is removed!
if (!Flags.politeNotifications() || !Flags.vibrateWhileUnlocked()) {
return CONDITIONALLY_UNAVAILABLE;
}
return mContext.getSystemService(Vibrator.class).hasVibrator() ? AVAILABLE
: UNSUPPORTED_ON_DEVICE;
}
@Override
public boolean isChecked() {
return Settings.System.getInt(mContext.getContentResolver(),
Settings.System.NOTIFICATION_COOLDOWN_VIBRATE_UNLOCKED, OFF) != OFF;
}
@Override
public boolean setChecked(boolean isChecked) {
return Settings.System.putInt(mContext.getContentResolver(),
Settings.System.NOTIFICATION_COOLDOWN_VIBRATE_UNLOCKED, (isChecked ? ON : OFF));
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_accessibility;
}
}

View File

@@ -1,114 +0,0 @@
/*
* Copyright (C) 2023 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.accessibility.AccessibilityUtil.State.OFF;
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
import android.content.Context;
import android.provider.Settings;
import android.util.Log;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import com.android.server.notification.Flags;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.PreferenceControllerMixin;
/**
* Controls whether polite notifications are enabled and apply to all apps or just to conversations.
*/
public class PoliteNotificationFilterController extends BasePreferenceController
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
static final String TAG = "PoliteNotificationFilterController";
private static final int POLITE_NOTIFICATIONS_ALL = 0;
private static final int POLITE_NOTIFICATIONS_CONVERSATIONS = 1;
private static final int POLITE_NOTIFICATIONS_DISABLED = 2;
public PoliteNotificationFilterController(Context context, String key) {
super(context, key);
}
@Override
public int getAvailabilityStatus() {
// TODO: b/291897570 - remove this when the feature flag is removed!
return Flags.politeNotifications() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
final ListPreference pref = (ListPreference) preference;
if (isPoliteNotifDisabled()) {
pref.setValue(Integer.toString(POLITE_NOTIFICATIONS_DISABLED));
} else if (shouldApplyForAllApps()) {
pref.setValue(Integer.toString(POLITE_NOTIFICATIONS_ALL));
} else {
pref.setValue(Integer.toString(POLITE_NOTIFICATIONS_CONVERSATIONS));
}
}
@Override
public CharSequence getSummary() {
if (isPoliteNotifDisabled()) {
return mContext.getString(R.string.notification_polite_disabled_summary);
}
if (shouldApplyForAllApps()) {
return mContext.getString(R.string.notification_polite_all_apps_summary);
} else {
return mContext.getString(R.string.notification_polite_conversations_summary);
}
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final int prefValue = Integer.parseInt((String) newValue);
if (prefValue == POLITE_NOTIFICATIONS_ALL) {
Settings.System.putInt(mContext.getContentResolver(),
Settings.System.NOTIFICATION_COOLDOWN_ENABLED, ON);
Settings.System.putInt(mContext.getContentResolver(),
Settings.System.NOTIFICATION_COOLDOWN_ALL, ON);
} else if (prefValue == POLITE_NOTIFICATIONS_CONVERSATIONS) {
Settings.System.putInt(mContext.getContentResolver(),
Settings.System.NOTIFICATION_COOLDOWN_ENABLED, ON);
Settings.System.putInt(mContext.getContentResolver(),
Settings.System.NOTIFICATION_COOLDOWN_ALL, OFF);
} else if (prefValue == POLITE_NOTIFICATIONS_DISABLED) {
Settings.System.putInt(mContext.getContentResolver(),
Settings.System.NOTIFICATION_COOLDOWN_ENABLED, OFF);
} else {
Log.e(TAG, "Unexpected preference value: " + prefValue);
}
refreshSummary(preference);
return true;
}
private boolean isPoliteNotifDisabled() {
return Settings.System.getInt(mContext.getContentResolver(),
Settings.System.NOTIFICATION_COOLDOWN_ENABLED, ON) == OFF;
}
private boolean shouldApplyForAllApps() {
return Settings.System.getInt(mContext.getContentResolver(),
Settings.System.NOTIFICATION_COOLDOWN_ALL, ON) != OFF;
}
}

View File

@@ -1,126 +0,0 @@
/*
* Copyright (C) 2023 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.accessibility.AccessibilityUtil.State.OFF;
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.os.Vibrator;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import com.android.server.notification.Flags;
import com.android.settings.core.BasePreferenceController;
import org.junit.Before;
import org.junit.Rule;
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;
@RunWith(RobolectricTestRunner.class)
public class PoliteNotifVibrateUnlockedToggleControllerTest {
@Rule
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
private static final String PREFERENCE_KEY = "preference_key";
private PoliteNotifVibrateUnlockedToggleController mController;
private Context mContext;
@Mock
private Vibrator mVibrator;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mController = new PoliteNotifVibrateUnlockedToggleController(mContext, PREFERENCE_KEY);
when(mContext.getSystemService(Vibrator.class)).thenReturn(mVibrator);
}
@Test
public void isAvailable_flagEnabled_vibrationSupported_shouldReturnTrue() {
// TODO: b/291907312 - remove feature flags
mSetFlagsRule.enableFlags(Flags.FLAG_POLITE_NOTIFICATIONS);
mSetFlagsRule.enableFlags(Flags.FLAG_VIBRATE_WHILE_UNLOCKED);
when(mVibrator.hasVibrator()).thenReturn(true);
assertThat(mController.isAvailable()).isTrue();
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.AVAILABLE);
}
@Test
public void isAvailable_flagEnabled_vibrationNotSupported_shouldReturnFalse() {
// TODO: b/291907312 - remove feature flags
mSetFlagsRule.enableFlags(Flags.FLAG_POLITE_NOTIFICATIONS);
mSetFlagsRule.enableFlags(Flags.FLAG_VIBRATE_WHILE_UNLOCKED);
when(mVibrator.hasVibrator()).thenReturn(false);
assertThat(mController.isAvailable()).isFalse();
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.UNSUPPORTED_ON_DEVICE);
}
@Test
public void isAvailable_flagDisabled_shouldReturnFalse() {
// TODO: b/291907312 - remove feature flags
mSetFlagsRule.disableFlags(Flags.FLAG_POLITE_NOTIFICATIONS);
mSetFlagsRule.enableFlags(Flags.FLAG_VIBRATE_WHILE_UNLOCKED);
assertThat(mController.isAvailable()).isFalse();
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
}
@Test
public void isChecked_vibrateEnabled_shouldReturnTrue() {
Settings.System.putInt(mContext.getContentResolver(),
Settings.System.NOTIFICATION_COOLDOWN_VIBRATE_UNLOCKED, ON);
assertThat(mController.isChecked()).isTrue();
}
@Test
public void isChecked_vibrateDisabled_shouldReturnFalse() {
Settings.System.putInt(mContext.getContentResolver(),
Settings.System.NOTIFICATION_COOLDOWN_VIBRATE_UNLOCKED, OFF);
assertThat(mController.isChecked()).isFalse();
}
@Test
public void setChecked_setTrue_shouldEnableVibrateSetting() {
Settings.System.putInt(mContext.getContentResolver(),
Settings.System.NOTIFICATION_COOLDOWN_VIBRATE_UNLOCKED, OFF);
mController.setChecked(true);
assertThat(Settings.System.getInt(mContext.getContentResolver(),
Settings.System.NOTIFICATION_COOLDOWN_VIBRATE_UNLOCKED, OFF)).isEqualTo(ON);
}
@Test
public void setChecked_setFalse_shouldDisableVibrateSetting() {
Settings.System.putInt(mContext.getContentResolver(),
Settings.System.NOTIFICATION_COOLDOWN_VIBRATE_UNLOCKED, ON);
mController.setChecked(false);
assertThat(Settings.System.getInt(mContext.getContentResolver(),
Settings.System.NOTIFICATION_COOLDOWN_VIBRATE_UNLOCKED, ON)).isEqualTo(OFF);
}
}

View File

@@ -1,165 +0,0 @@
/*
* Copyright (C) 2023 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.accessibility.AccessibilityUtil.State.OFF;
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
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.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.server.notification.Flags;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import org.junit.Before;
import org.junit.Rule;
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;
@RunWith(RobolectricTestRunner.class)
public class PoliteNotificationFilterControllerTest {
@Rule
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
private static final String PREFERENCE_KEY = "preference_key";
private static final int POLITE_NOTIFICATIONS_ALL = 0;
private static final int POLITE_NOTIFICATIONS_CONVERSATIONS = 1;
private static final int POLITE_NOTIFICATIONS_DISABLED = 2;
@Mock
private PreferenceScreen mScreen;
private PoliteNotificationFilterController mController;
private Preference mPreference;
private Context mContext;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mController = new PoliteNotificationFilterController(mContext, PREFERENCE_KEY);
mPreference = new Preference(mContext);
mPreference.setKey(mController.getPreferenceKey());
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
}
@Test
public void isAvailable_flagEnabled_shouldReturnTrue() {
// TODO: b/291907312 - remove feature flags
mSetFlagsRule.enableFlags(Flags.FLAG_POLITE_NOTIFICATIONS);
assertThat(mController.isAvailable()).isTrue();
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.AVAILABLE);
}
@Test
public void isAvailable_flagDisabled_shouldReturnFalse() {
// TODO: b/291907312 - remove feature flags
mSetFlagsRule.disableFlags(Flags.FLAG_POLITE_NOTIFICATIONS);
assertThat(mController.isAvailable()).isFalse();
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
}
@Test
public void updateState_politeNotificationDisabled() {
final ListPreference preference = mock(ListPreference.class);
Settings.System.putInt(mContext.getContentResolver(),
Settings.System.NOTIFICATION_COOLDOWN_ENABLED, OFF);
mController.updateState(preference);
verify(preference).setValue(Integer.toString(POLITE_NOTIFICATIONS_DISABLED));
assertThat(mController.getSummary().toString()).isEqualTo(
mContext.getString(R.string.notification_polite_disabled_summary));
}
@Test
public void updateState_politeNotificationEnabled_applyAllApps() {
final ListPreference preference = mock(ListPreference.class);
Settings.System.putInt(mContext.getContentResolver(),
Settings.System.NOTIFICATION_COOLDOWN_ENABLED, ON);
Settings.System.putInt(mContext.getContentResolver(),
Settings.System.NOTIFICATION_COOLDOWN_ALL, ON);
mController.updateState(preference);
verify(preference).setValue(Integer.toString(POLITE_NOTIFICATIONS_ALL));
assertThat(mController.getSummary().toString()).isEqualTo(
mContext.getString(R.string.notification_polite_all_apps_summary));
}
@Test
public void updateState_politeNotificationEnabled_applyOnlyConversations() {
final ListPreference preference = mock(ListPreference.class);
Settings.System.putInt(mContext.getContentResolver(),
Settings.System.NOTIFICATION_COOLDOWN_ENABLED, ON);
Settings.System.putInt(mContext.getContentResolver(),
Settings.System.NOTIFICATION_COOLDOWN_ALL, OFF);
mController.updateState(preference);
verify(preference).setValue(Integer.toString(POLITE_NOTIFICATIONS_CONVERSATIONS));
assertThat(mController.getSummary().toString()).isEqualTo(
mContext.getString(R.string.notification_polite_conversations_summary));
}
@Test
public void onPreferenceChanged_firstItemSelected_shouldEnableForAll() {
mController.displayPreference(mScreen);
mController.onPreferenceChange(mPreference, "0");
assertThat(Settings.System.getInt(mContext.getContentResolver(),
Settings.System.NOTIFICATION_COOLDOWN_ENABLED, OFF)).isEqualTo(ON);
assertThat(Settings.System.getInt(mContext.getContentResolver(),
Settings.System.NOTIFICATION_COOLDOWN_ALL, OFF)).isEqualTo(ON);
}
@Test
public void onPreferenceChanged_secondItemSelected_shouldEnableForConversationsOnly() {
mController.displayPreference(mScreen);
mController.onPreferenceChange(mPreference, "1");
assertThat(Settings.System.getInt(mContext.getContentResolver(),
Settings.System.NOTIFICATION_COOLDOWN_ENABLED, OFF)).isEqualTo(ON);
assertThat(Settings.System.getInt(mContext.getContentResolver(),
Settings.System.NOTIFICATION_COOLDOWN_ALL, OFF)).isEqualTo(OFF);
}
@Test
public void onPreferenceChanged_thirdItemSelected_shouldDisable() {
mController.displayPreference(mScreen);
mController.onPreferenceChange(mPreference, "2");
assertThat(Settings.System.getInt(mContext.getContentResolver(),
Settings.System.NOTIFICATION_COOLDOWN_ENABLED, OFF)).isEqualTo(OFF);
}
}