Add silent status bar icon setting

Test: atest
Bug: 123419917
Change-Id: I40fe580b76589c45a70365c09a966a76b5bc882b
This commit is contained in:
Julia Reynolds
2019-01-29 12:12:39 -05:00
parent 1cf1d9b643
commit c04425fe38
5 changed files with 197 additions and 0 deletions

View File

@@ -7590,6 +7590,12 @@
<!-- Configure Notifications: Work profile section header [CHAR LIMIT=30] --> <!-- Configure Notifications: Work profile section header [CHAR LIMIT=30] -->
<string name="profile_section_header">Work notifications</string> <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] --> <!-- Configure Notifications: Title for the notification badging option. [CHAR LIMIT=30 BACKUP_MESSAGE_ID=5125022693565388760] -->
<string name="notification_badging_title">Allow notification dots</string> <string name="notification_badging_title">Allow notification dots</string>

View File

@@ -26,6 +26,12 @@
android:summary="@string/summary_placeholder" android:summary="@string/summary_placeholder"
settings:searchable="false"/> 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 --> <!-- Notification badging -->
<SwitchPreference <SwitchPreference
android:key="notification_badging" android:key="notification_badging"

View File

@@ -300,6 +300,23 @@ public class NotificationBackend {
} }
} }
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) { protected void recordAggregatedUsageEvents(Context context, AppRow appRow) {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
long startTime = now - (DateUtils.DAY_IN_MILLIS * DAYS_TO_CHECK); long startTime = now - (DateUtils.DAY_IN_MILLIS * DAYS_TO_CHECK);

View File

@@ -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;
}
}

View File

@@ -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);
}
**/
}