Merge "Prevent users from blocking certain system notifications."
diff --git a/packages/SettingsLib/src/com/android/settingslib/Utils.java b/packages/SettingsLib/src/com/android/settingslib/Utils.java
index 72df96d..fa2226d 100644
--- a/packages/SettingsLib/src/com/android/settingslib/Utils.java
+++ b/packages/SettingsLib/src/com/android/settingslib/Utils.java
@@ -2,7 +2,11 @@
import android.content.Context;
import android.content.Intent;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.UserInfo;
+import android.content.pm.Signature;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@@ -138,4 +142,33 @@
return statusString;
}
+
+ /**
+ * Determine whether a package is a "system package", in which case certain things (like
+ * disabling notifications or disabling the package altogether) should be disallowed.
+ */
+ public static boolean isSystemPackage(PackageManager pm, PackageInfo pkg) {
+ if (sSystemSignature == null) {
+ sSystemSignature = new Signature[]{ getSystemSignature(pm) };
+ }
+ return sSystemSignature[0] != null && sSystemSignature[0].equals(getFirstSignature(pkg));
+ }
+
+ private static Signature[] sSystemSignature;
+
+ private static Signature getFirstSignature(PackageInfo pkg) {
+ if (pkg != null && pkg.signatures != null && pkg.signatures.length > 0) {
+ return pkg.signatures[0];
+ }
+ return null;
+ }
+
+ private static Signature getSystemSignature(PackageManager pm) {
+ try {
+ final PackageInfo sys = pm.getPackageInfo("android", PackageManager.GET_SIGNATURES);
+ return getFirstSignature(sys);
+ } catch (NameNotFoundException e) {
+ }
+ return null;
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationGuts.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationGuts.java
index 20a6e7c..52326e3 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationGuts.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationGuts.java
@@ -16,10 +16,11 @@
package com.android.systemui.statusbar;
-import android.annotation.IdRes;
import android.app.INotificationManager;
import android.app.Notification;
import android.content.Context;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.RemoteException;
@@ -28,13 +29,12 @@
import android.service.notification.StatusBarNotification;
import android.util.AttributeSet;
import android.view.View;
-import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RadioButton;
-import android.widget.RadioGroup;
import android.widget.SeekBar;
import android.widget.TextView;
+import com.android.settingslib.Utils;
import com.android.systemui.R;
/**
@@ -123,10 +123,27 @@
final TextView topicSummary = ((TextView) row.findViewById(R.id.summary));
final TextView topicTitle = ((TextView) row.findViewById(R.id.title));
mSeekBar = (SeekBar) row.findViewById(R.id.seekbar);
- mSeekBar.setMax(4);
+ boolean systemApp = false;
+ try {
+ final PackageManager pm = BaseStatusBar.getPackageManagerForUser(
+ getContext(), sbn.getUser().getIdentifier());
+ final PackageInfo info =
+ pm.getPackageInfo(sbn.getPackageName(), PackageManager.GET_SIGNATURES);
+ systemApp = Utils.isSystemPackage(pm, info);
+ } catch (PackageManager.NameNotFoundException e) {
+ // unlikely.
+ }
+ final int minProgress = systemApp ?
+ NotificationListenerService.Ranking.IMPORTANCE_LOW
+ : NotificationListenerService.Ranking.IMPORTANCE_NONE;
+ mSeekBar.setMax(NotificationListenerService.Ranking.IMPORTANCE_MAX);
mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ if (progress < minProgress) {
+ seekBar.setProgress(minProgress);
+ progress = minProgress;
+ }
updateTitleAndSummary(progress);
if (fromUser) {
if (appUsesTopics) {