Add silent status bar icon setting
Test: atest
Bug: 123419917
Change-Id: I40fe580b76589c45a70365c09a966a76b5bc882b
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 1a92f7b..ecb74bb 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -7590,6 +7590,12 @@
<!-- Configure Notifications: Work profile section header [CHAR LIMIT=30] -->
<string name="profile_section_header">Work notifications</string>
+ <!-- Configure Notifications: setting title [CHAR LIMIT=80] -->
+ <string name="hide_silent_icons_title">Hide silent notification status icons</string>
+
+ <!-- Configure Notifications: setting summary [CHAR LIMIT=NONE] -->
+ <string name="hide_silent_icons_summary">Hide icons for silent notifications in the status bar</string>
+
<!-- Configure Notifications: Title for the notification badging option. [CHAR LIMIT=30 BACKUP_MESSAGE_ID=5125022693565388760] -->
<string name="notification_badging_title">Allow notification dots</string>
diff --git a/res/xml/configure_notification_settings.xml b/res/xml/configure_notification_settings.xml
index e4d948b..ca82609 100644
--- a/res/xml/configure_notification_settings.xml
+++ b/res/xml/configure_notification_settings.xml
@@ -26,6 +26,12 @@
android:summary="@string/summary_placeholder"
settings:searchable="false"/>
+ <SwitchPreference
+ android:key="hide_silent_icons"
+ android:title="@string/hide_silent_icons_title"
+ android:summary="@string/hide_silent_icons_summary"
+ settings:controller="com.android.settings.notification.SilentStatusBarPreferenceController" />
+
<!-- Notification badging -->
<SwitchPreference
android:key="notification_badging"
diff --git a/src/com/android/settings/notification/NotificationBackend.java b/src/com/android/settings/notification/NotificationBackend.java
index a2be3ea..ec56369 100644
--- a/src/com/android/settings/notification/NotificationBackend.java
+++ b/src/com/android/settings/notification/NotificationBackend.java
@@ -300,6 +300,23 @@
}
}
+ public boolean shouldHideSilentStatusBarIcons(Context context) {
+ try {
+ return sINM.shouldHideSilentStatusIcons(context.getPackageName());
+ } catch (Exception e) {
+ Log.w(TAG, "Error calling NoMan", e);
+ return false;
+ }
+ }
+
+ public void setHideSilentStatusIcons(boolean hide) {
+ try {
+ sINM.setHideSilentStatusIcons(hide);
+ } catch (Exception e) {
+ Log.w(TAG, "Error calling NoMan", e);
+ }
+ }
+
protected void recordAggregatedUsageEvents(Context context, AppRow appRow) {
long now = System.currentTimeMillis();
long startTime = now - (DateUtils.DAY_IN_MILLIS * DAYS_TO_CHECK);
diff --git a/src/com/android/settings/notification/SilentStatusBarPreferenceController.java b/src/com/android/settings/notification/SilentStatusBarPreferenceController.java
new file mode 100644
index 0000000..4721f5c
--- /dev/null
+++ b/src/com/android/settings/notification/SilentStatusBarPreferenceController.java
@@ -0,0 +1,58 @@
+/*
+ * 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 android.provider.Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL;
+
+import android.content.Context;
+import android.os.UserHandle;
+import android.provider.Settings;
+
+import com.android.settings.core.TogglePreferenceController;
+
+public class SilentStatusBarPreferenceController extends TogglePreferenceController {
+
+ private static final String KEY = "hide_silent_icons";
+ private static final int MY_USER_ID = UserHandle.myUserId();
+ private final NotificationBackend mBackend;
+
+ public SilentStatusBarPreferenceController(Context context) {
+ super(context, KEY);
+ mBackend = new NotificationBackend();
+ }
+
+ @Override
+ public boolean isChecked() {
+ return mBackend.shouldHideSilentStatusBarIcons(mContext);
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ mBackend.setHideSilentStatusIcons(isChecked);
+ return true;
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return Settings.Secure.getInt(
+ mContext.getContentResolver(), NOTIFICATION_NEW_INTERRUPTION_MODEL, 1) != 0
+ ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+ }
+
+}
+
+
diff --git a/tests/robotests/src/com/android/settings/notification/SilentStatusBarPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/SilentStatusBarPreferenceControllerTest.java
new file mode 100644
index 0000000..8a43a1e
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/SilentStatusBarPreferenceControllerTest.java
@@ -0,0 +1,110 @@
+/*
+ * 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 android.provider.Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import com.android.settings.testutils.FakeFeatureFactory;
+
+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 androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
+@RunWith(RobolectricTestRunner.class)
+public class SilentStatusBarPreferenceControllerTest {
+
+ @Mock
+ private NotificationBackend mBackend;
+ @Mock
+ private PreferenceScreen mScreen;
+
+ private FakeFeatureFactory mFeatureFactory;
+ private Context mContext;
+ private SilentStatusBarPreferenceController mController;
+ private Preference mPreference;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mFeatureFactory = FakeFeatureFactory.setupForTest();
+ mController = new SilentStatusBarPreferenceController(mContext);
+ mPreference = new Preference(mContext);
+ mPreference.setKey(mController.getPreferenceKey());
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
+ }
+
+ @Test
+ public void isAvailable_featureEnabled() {
+ Settings.Secure.putInt(
+ mContext.getContentResolver(), NOTIFICATION_NEW_INTERRUPTION_MODEL, 1);
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void isAvailable_featureDisabled() {
+ Settings.Secure.putInt(
+ mContext.getContentResolver(), NOTIFICATION_NEW_INTERRUPTION_MODEL, 0);
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
+ public void isChecked_settingIsOff_false() {
+ when(mBackend.shouldHideSilentStatusBarIcons(any())).thenReturn(false);
+ assertThat(mController.isChecked()).isFalse();
+ }
+/**
+ @Test
+ public void isChecked_settingIsOn_true() {
+ when(mBackend.shouldHideSilentStatusBarIcons(any())).thenReturn(true);
+ assertThat(mController.isChecked()).isTrue();
+ }
+
+ @Test
+ public void onPreferenceChange_on() {
+ mController.onPreferenceChange(mPreference, true);
+
+ assertThat(mController.isChecked()).isTrue();
+ verify(mBackend).setHideSilentStatusIcons(true);
+ }
+
+ @Test
+ public void onPreferenceChange_off() {
+ mController.onPreferenceChange(mPreference, false);
+
+ assertThat(mController.isChecked()).isFalse();
+ verify(mBackend).setHideSilentStatusIcons(false);
+ }
+ **/
+}
+