Permalink
Browse files

fb: less notifications sound (1/2)

add back the 4.3 feature like it was.
User can setup how often notification sound
for an app comes trough so that
it does not annoy to much

Change-Id: I3d7b2ef2e2ff99b7c23880626e0268ec4c5d8543
  • Loading branch information...
kufikugel authored and akhilnarang committed Dec 1, 2013
1 parent 3cdc793 commit 588b5ebd37bd83b4b9da7fc8eea06ce076741b36
@@ -3817,6 +3817,13 @@ public boolean validate(String value) {
*/
public static final String SAFE_HEADSET_VOLUME = "safe_headset_volume";
/**
* Whether to mute annoying notifications
* @hide
*/
public static final String MUTE_ANNOYING_NOTIFICATIONS_THRESHOLD =
"mute_annoying_notifications_threshold";
/**
* Whether to show the battery info on the lockscreen while charging
* @hide
@@ -172,6 +172,7 @@
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -298,6 +299,9 @@
// The last key in this list owns the hardware.
ArrayList<String> mLights = new ArrayList<>();
private HashMap<String, Long> mAnnoyingNotifications = new HashMap<String, Long>();
private long mAnnoyingNotificationThreshold = -1;
private AppOpsManager mAppOps;
private UsageStatsManagerInternal mAppUsageStats;
@@ -862,6 +866,8 @@ public void onReceive(Context context, Intent intent) {
= Settings.Global.getUriFor(Settings.Global.MAX_NOTIFICATION_ENQUEUE_RATE);
private final Uri ENABLED_NOTIFICATION_LISTENERS_URI
= Settings.Secure.getUriFor(Settings.Secure.ENABLED_NOTIFICATION_LISTENERS);
private final Uri MUTE_ANNOYING_NOTIFICATIONS_THRESHOLD_URI
= Settings.System.getUriFor(Settings.System.MUTE_ANNOYING_NOTIFICATIONS_THRESHOLD);
LEDSettingsObserver(Handler handler) {
super(handler);
@@ -896,8 +902,10 @@ void observe() {
Settings.System.NOTIFICATION_LIGHT_SCREEN_ON),
false, this, UserHandle.USER_ALL);
resolver.registerContentObserver(Settings.System.getUriFor(
Settings.System.NOTIFICATION_LIGHT_COLOR_AUTO), false,
this, UserHandle.USER_ALL);
Settings.System.NOTIFICATION_LIGHT_COLOR_AUTO),
false, this, UserHandle.USER_ALL);
resolver.registerContentObserver(MUTE_ANNOYING_NOTIFICATIONS_THRESHOLD_URI,
false, this, UserHandle.USER_ALL);
update(null);
}
@@ -947,6 +955,12 @@ public void update(Uri uri) {
if (uri == null || NOTIFICATION_RATE_LIMIT_URI.equals(uri)) {
mMaxPackageEnqueueRate = Settings.Global.getFloat(resolver,
Settings.Global.MAX_NOTIFICATION_ENQUEUE_RATE, mMaxPackageEnqueueRate);
}
if (uri == null || MUTE_ANNOYING_NOTIFICATIONS_THRESHOLD_URI.equals(uri)) {
mAnnoyingNotificationThreshold = Settings.System.getLongForUser(resolver,
Settings.System.MUTE_ANNOYING_NOTIFICATIONS_THRESHOLD, 0,
UserHandle.USER_CURRENT_OR_SELF);
}
if (uri == null || NOTIFICATION_SOUND_URI.equals(uri)) {
mSystemNotificationSound = Settings.System.getString(resolver,
@@ -2855,6 +2869,26 @@ public void run() {
}
}
private boolean notificationIsAnnoying(String pkg) {
if (pkg == null
|| mAnnoyingNotificationThreshold <= 0
|| "android".equals(pkg)) {
return false;
}
long currentTime = System.currentTimeMillis();
if (mAnnoyingNotifications.containsKey(pkg)
&& (currentTime - mAnnoyingNotifications.get(pkg)
< mAnnoyingNotificationThreshold)) {
// less than threshold; it's an annoying notification!!
return true;
} else {
// not in map or time to re-add
mAnnoyingNotifications.put(pkg, currentTime);
return false;
}
}
/**
* Ensures that grouped notification receive their special treatment.
*
@@ -2911,13 +2945,14 @@ void buzzBeepBlinkLocked(NotificationRecord record) {
final Notification notification = record.sbn.getNotification();
final String key = record.getKey();
final String pkg = record.sbn.getPackageName();
// Should this notification make noise, vibe, or use the LED?
final boolean aboveThreshold = record.getImportance() >= IMPORTANCE_DEFAULT;
final boolean canInterrupt = aboveThreshold && !record.isIntercepted();
if (DBG || record.isIntercepted())
Slog.v(TAG,
"pkg=" + record.sbn.getPackageName() + " canInterrupt=" + canInterrupt +
"pkg=" + pkg + " canInterrupt=" + canInterrupt +
" intercept=" + record.isIntercepted()
);
@@ -2956,6 +2991,7 @@ void buzzBeepBlinkLocked(NotificationRecord record) {
mUserProfiles.isCurrentProfile(record.getUserId()))
&& canInterrupt
&& mSystemReady
&& !notificationIsAnnoying(pkg)
&& mAudioManager != null) {
if (DBG) Slog.v(TAG, "Interrupting!");

0 comments on commit 588b5eb

Please sign in to comment.