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

Commit 8bfc4b15 authored by Lars Greiss's avatar Lars Greiss Committed by Adnan Begovic
Browse files

Frameworks: Add per app controls for LP keyguard notifications (1/2)

Nice done by google but the UX is a problem especially for ppl who are using a lot apps and just want
to see from important apps the notifications on the lockscreen.

This commit adds the ability to

- enable/disable per app the keyguard notification at all
- enable/disable per app ongoing notifications on the keyguard

We handle this over the app policy conf file like the other per app notification options.

Change-Id: I1064765428ac5e857cb441c121ece63d33747171
parent 1bf219d9
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -51,6 +51,9 @@ interface INotificationManager
    void setPackageVisibilityOverride(String pkg, int uid, int visibility);
    int getPackageVisibilityOverride(String pkg, int uid);

    void setShowNotificationForPackageOnKeyguard(String pkg, int uid, int status);
    int getShowNotificationForPackageOnKeyguard(String pkg, int uid);

    // TODO: Remove this when callers have been migrated to the equivalent
    // INotificationListener method.
    StatusBarNotification[] getActiveNotifications(String callingPkg);
+15 −0
Original line number Diff line number Diff line
@@ -509,6 +509,21 @@ public class Notification implements Parcelable
    @Priority
    public int priority;

    /**
     * Default.
     * Show all notifications from an app on keyguard.
     *
     * @hide
     */
    public static final int SHOW_ALL_NOTI_ON_KEYGUARD = 0x01;

    /**
     * Show only notifications from an app which are not ongoing ones.
     *
     * @hide
     */
    public static final int SHOW_NO_ONGOING_NOTI_ON_KEYGUARD = 0x02;

    /**
     * Accent color (an ARGB integer like the constants in {@link android.graphics.Color})
     * to be applied by the standard Style templates when presenting this notification.
+13 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.app;

import android.annotation.SdkConstant;
import android.app.Notification;
import android.app.Notification.Builder;
import android.content.ComponentName;
import android.content.Context;
@@ -264,5 +265,17 @@ public class NotificationManager
        }
    }

    /**
     * @hide
     */
    public int getShowNotificationForPackageOnKeyguard(String pkg, int uid) {
        INotificationManager service = getService();
        try {
            return getService().getShowNotificationForPackageOnKeyguard(pkg, uid);
        } catch (RemoteException e) {
            return Notification.SHOW_ALL_NOTI_ON_KEYGUARD;
        }
    }

    private Context mContext;
}
+17 −7
Original line number Diff line number Diff line
@@ -214,6 +214,8 @@ public abstract class BaseStatusBar extends SystemUI implements
    protected WindowManager mWindowManager;
    protected IWindowManager mWindowManagerService;

    private NotificationManager mNoMan;

    protected abstract void refreshLayout(int layoutDirection);

    protected Display mDisplay;
@@ -348,9 +350,7 @@ public abstract class BaseStatusBar extends SystemUI implements
                updateLockscreenNotificationSetting();
                updateNotifications();
            } else if (BANNER_ACTION_CANCEL.equals(action) || BANNER_ACTION_SETUP.equals(action)) {
                NotificationManager noMan = (NotificationManager)
                        mContext.getSystemService(Context.NOTIFICATION_SERVICE);
                noMan.cancel(HIDDEN_NOTIFICATION_ID);
                mNoMan.cancel(HIDDEN_NOTIFICATION_ID);

                Settings.Secure.putInt(mContext.getContentResolver(),
                        Settings.Secure.SHOW_NOTE_ABOUT_NOTIFICATION_HIDING, 0);
@@ -458,6 +458,9 @@ public abstract class BaseStatusBar extends SystemUI implements
    public void start() {
        mWindowManager = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
        mWindowManagerService = WindowManagerGlobal.getWindowManagerService();

        mNoMan = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);

        mDisplay = mWindowManager.getDefaultDisplay();
        mDevicePolicyManager = (DevicePolicyManager)mContext.getSystemService(
                Context.DEVICE_POLICY_SERVICE);
@@ -617,9 +620,7 @@ public abstract class BaseStatusBar extends SystemUI implements
                            mContext.getString(R.string.hidden_notifications_setup),
                            setupIntent);

            NotificationManager noMan =
                    (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
            noMan.notify(HIDDEN_NOTIFICATION_ID, note.build());
            mNoMan.notify(HIDDEN_NOTIFICATION_ID, note.build());
        }
    }

@@ -1734,7 +1735,16 @@ public abstract class BaseStatusBar extends SystemUI implements
    }

    private boolean shouldShowOnKeyguard(StatusBarNotification sbn) {
        return mShowLockscreenNotifications && !mNotificationData.isAmbient(sbn.getKey());
        final int showOnKeyguard = mNoMan.getShowNotificationForPackageOnKeyguard(
                sbn.getPackageName(), sbn.getUid());
        boolean isKeyguardAllowedForApp =
                (showOnKeyguard & Notification.SHOW_ALL_NOTI_ON_KEYGUARD) != 0;
        if (isKeyguardAllowedForApp && sbn.isOngoing()) {
            isKeyguardAllowedForApp =
                    (showOnKeyguard & Notification.SHOW_NO_ONGOING_NOTI_ON_KEYGUARD) == 0;
        }
        return mShowLockscreenNotifications && !mNotificationData.isAmbient(sbn.getKey())
                && isKeyguardAllowedForApp;
    }

    protected void setZenMode(int mode) {
+14 −0
Original line number Diff line number Diff line
@@ -1257,6 +1257,20 @@ public class NotificationManagerService extends SystemService {
            return mRankingHelper.getPackageVisibilityOverride(pkg, uid);
        }

        @Override
        public void setShowNotificationForPackageOnKeyguard(
                String pkg, int uid, int status) {
            checkCallerIsSystem();
            mRankingHelper.setShowNotificationForPackageOnKeyguard(pkg, uid, status);
            savePolicyFile();
        }

        @Override
        public int getShowNotificationForPackageOnKeyguard(String pkg, int uid) {
            enforceSystemOrSystemUI("INotificationManager.getShowNotificationForPackageOnKeyguard");
            return mRankingHelper.getShowNotificationForPackageOnKeyguard(pkg, uid);
        }

        /**
         * System-only API for getting a list of current (i.e. not cleared) notifications.
         *
Loading