Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cb85a908 authored by Adnan's avatar Adnan Committed by Adnan Begovic
Browse files

HeadsUp: Add heads up blacklist options. (1/2)

Change-Id: If9e5eed658871400b3c21d9354262e0887bc592e
parent 86306dcd
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -2850,12 +2850,19 @@ public final class Settings {
        public static final String HEADS_UP_NOTIFICATION = "heads_up_enabled";

        /**
         * Which applications to disable heads up notifications for
         * Which applications to disable heads up notifications in
         *
         * @hide
         */
        public static final String HEADS_UP_CUSTOM_VALUES = "heads_up_custom_values";

        /**
         * Which applications to disable heads up notifications for
         *
         * @hide
         */
        public static final String HEADS_UP_BLACKLIST_VALUES = "heads_up_blacklist_values";

        /**
         * Quick Settings Panel Dynamic Tiles
         *
+5 −2
Original line number Diff line number Diff line
@@ -223,6 +223,9 @@
    <!-- Default value of Settings.System.QUICK_SETTINGS_RIBBON_TILES -->
    <string name="def_quick_settings_ribbon_tiles"></string>

    <!-- Default values of Settings.System.HEADS_UP_NOTIFICATION -->
    <string name="def_heads_up_notification_values"></string>
    <!-- Default DnD values of Settings.System.HEADS_UP_NOTIFICATION -->
    <string name="def_heads_up_notification_dnd_values"></string>

    <!-- Default Blacklist values of Settings.System.HEADS_UP_NOTIFICATION -->
    <string name="def_heads_up_notification_blacklist_values"></string>
</resources>
+7 −4
Original line number Diff line number Diff line
@@ -2098,11 +2098,14 @@ public class DatabaseHelper extends SQLiteOpenHelper {
    }

    private void loadHeadsUpSetting(SQLiteStatement stmt) {
        String headsUpValues = mContext.getResources()
                .getString(R.string.def_heads_up_notification_values);
        if (!TextUtils.isEmpty(headsUpValues)) {
        String dndValues = mContext.getResources()
                .getString(R.string.def_heads_up_notification_dnd_values);
        String blackListValues = mContext.getResources()
                .getString(R.string.def_heads_up_notification_blacklist_values);
        if (!TextUtils.isEmpty(dndValues)) {
            loadSetting(stmt, Settings.System.HEADS_UP_NOTIFICATION, "0");
            loadSetting(stmt, Settings.System.HEADS_UP_CUSTOM_VALUES, headsUpValues);
            loadSetting(stmt, Settings.System.HEADS_UP_CUSTOM_VALUES, dndValues);
            loadSetting(stmt, Settings.System.HEADS_UP_BLACKLIST_VALUES, blackListValues);
        }
    }

+35 −11
Original line number Diff line number Diff line
@@ -171,6 +171,9 @@ public abstract class BaseStatusBar extends SystemUI implements

    private RecentsComponent mRecents;

    private ArrayList<String> mDndList;
    private ArrayList<String> mBlacklist;

    private int mExpandedDesktopStyle = 0;

    public IStatusBarService getStatusBarService() {
@@ -200,6 +203,12 @@ public abstract class BaseStatusBar extends SystemUI implements

        public void observe() {
            ContentResolver resolver = mContext.getContentResolver();
            resolver.registerContentObserver(
                    Settings.System.getUriFor(Settings.System.HEADS_UP_CUSTOM_VALUES),
                    false, this);
            resolver.registerContentObserver(
                    Settings.System.getUriFor(Settings.System.HEADS_UP_BLACKLIST_VALUES),
                    false, this);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.STATUS_BAR_COLLAPSE_ON_DISMISS), false, this);
            resolver.registerContentObserver(Settings.System.getUriFor(
@@ -225,6 +234,12 @@ public abstract class BaseStatusBar extends SystemUI implements
                mExpandedDesktopStyle = Settings.System.getIntForUser(mContext.getContentResolver(),
                        Settings.System.EXPANDED_DESKTOP_STYLE, 0, UserHandle.USER_CURRENT);
            }
            final String dndString = Settings.System.getString(mContext.getContentResolver(),
                    Settings.System.HEADS_UP_CUSTOM_VALUES);
            final String blackString = Settings.System.getString(mContext.getContentResolver(),
                    Settings.System.HEADS_UP_BLACKLIST_VALUES);
            splitAndAddToArrayList(mDndList, dndString, "\\|");
            splitAndAddToArrayList(mBlacklist, blackString, "\\|");
        }
    };

@@ -283,6 +298,9 @@ public abstract class BaseStatusBar extends SystemUI implements
                ServiceManager.checkService(DreamService.DREAM_SERVICE));
        mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);

        mDndList = new ArrayList<String>();
        mBlacklist = new ArrayList<String>();

        mProvisioningObserver.onChange(false); // set up
        mContext.getContentResolver().registerContentObserver(
                Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED), true,
@@ -1182,6 +1200,11 @@ public abstract class BaseStatusBar extends SystemUI implements
    protected boolean shouldInterrupt(StatusBarNotification sbn) {
        Notification notification = sbn.getNotification();

        // check if notification from the package is blacklisted first
        if (isPackageBlacklisted(sbn.getPackageName())) {
            return false;
        }

        // some predicates to make the boolean logic legible
        boolean isNoisy = (notification.defaults & Notification.DEFAULT_SOUND) != 0
                || (notification.defaults & Notification.DEFAULT_VIBRATE) != 0
@@ -1238,24 +1261,25 @@ public abstract class BaseStatusBar extends SystemUI implements
    }

    private boolean isPackageInDnd(String packageName) {
        final String baseString = Settings.System.getString(mContext.getContentResolver(),
                Settings.System.HEADS_UP_CUSTOM_VALUES);
        return mDndList.contains(packageName);
    }

    private boolean isPackageBlacklisted(String packageName) {
        return mBlacklist.contains(packageName);
    }

    private void splitAndAddToArrayList(ArrayList<String> arrayList,
                                        String baseString, String separator) {
        // clear first
        arrayList.clear();
        if (baseString != null) {
            final String[] array = TextUtils.split(baseString, "\\|");
            final String[] array = TextUtils.split(baseString, separator);
            for (String item : array) {
                if (TextUtils.isEmpty(item)) {
                    continue;
                }
                if (TextUtils.equals(item, packageName)) {
                    return true;
                arrayList.add(item.trim());
            }
        }
    }

        return false;
    }

    // Q: What kinds of notifications should show during setup?
    // A: Almost none! Only things coming from the system (package is "android") that also
    // have special "kind" tags marking them as relevant for setup (see below).
+1 −1
Original line number Diff line number Diff line
@@ -474,7 +474,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
            boolean wasUsing = mUseHeadsUp;
            mUseHeadsUp = ENABLE_HEADS_UP && Settings.System.getIntForUser(
                    mContext.getContentResolver(),
                    Settings.System.HEADS_UP_NOTIFICATION, 0, UserHandle.USER_CURRENT) == 1;;
                    Settings.System.HEADS_UP_NOTIFICATION, 0, UserHandle.USER_CURRENT) == 1;
            Log.d(TAG, "heads up is " + (mUseHeadsUp ? "enabled" : "disabled"));
            if (wasUsing != mUseHeadsUp) {
                if (!mUseHeadsUp) {