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

Commit e05bc9a0 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Allow NLSes to supply a default notif type filter" into sc-dev

parents 87d49d2f b6c718c9
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -38076,6 +38076,10 @@ package android.service.notification {
    method public final void setNotificationsShown(String[]);
    method public final void snoozeNotification(String, long);
    method public final void updateNotificationChannel(@NonNull String, @NonNull android.os.UserHandle, @NonNull android.app.NotificationChannel);
    field public static final int FLAG_FILTER_TYPE_ALERTING = 2; // 0x2
    field public static final int FLAG_FILTER_TYPE_CONVERSATIONS = 1; // 0x1
    field public static final int FLAG_FILTER_TYPE_ONGOING = 8; // 0x8
    field public static final int FLAG_FILTER_TYPE_SILENT = 4; // 0x4
    field public static final int HINT_HOST_DISABLE_CALL_EFFECTS = 4; // 0x4
    field public static final int HINT_HOST_DISABLE_EFFECTS = 1; // 0x1
    field public static final int HINT_HOST_DISABLE_NOTIFICATION_EFFECTS = 2; // 0x2
@@ -38084,6 +38088,7 @@ package android.service.notification {
    field public static final int INTERRUPTION_FILTER_NONE = 3; // 0x3
    field public static final int INTERRUPTION_FILTER_PRIORITY = 2; // 0x2
    field public static final int INTERRUPTION_FILTER_UNKNOWN = 0; // 0x0
    field public static final String META_DATA_DEFAULT_FILTER_TYPES = "android.service.notification.default_filter_types";
    field public static final int NOTIFICATION_CHANNEL_OR_GROUP_ADDED = 1; // 0x1
    field public static final int NOTIFICATION_CHANNEL_OR_GROUP_DELETED = 3; // 0x3
    field public static final int NOTIFICATION_CHANNEL_OR_GROUP_UPDATED = 2; // 0x2
+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.util.ArraySet;
 */
public class NotificationListenerFilter implements Parcelable {
    private int mAllowedNotificationTypes;
    // VersionedPackage is holding the pkg name and pkg uid
    private ArraySet<VersionedPackage> mDisallowedPackages;

    public NotificationListenerFilter() {
+19 −4
Original line number Diff line number Diff line
@@ -80,6 +80,10 @@ import java.util.Objects;
 *     &lt;intent-filter>
 *         &lt;action android:name="android.service.notification.NotificationListenerService" />
 *     &lt;/intent-filter>
 *     &lt;meta-data
 *               android:name="android.service.notification.default_filter_types"
 *               android:value="1,2">
 *           &lt;/meta-data>
 * &lt;/service></pre>
 *
 * <p>The service should wait for the {@link #onListenerConnected()} event
@@ -102,6 +106,21 @@ public abstract class NotificationListenerService extends Service {
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
    private final String TAG = getClass().getSimpleName();

    /**
     * The name of the {@code meta-data} tag containing a comma separated list of default
     * integer notification types that should be provided to this listener. See
     * {@link #FLAG_FILTER_TYPE_ONGOING},
     * {@link #FLAG_FILTER_TYPE_CONVERSATIONS}, {@link #FLAG_FILTER_TYPE_ALERTING),
     * and {@link #FLAG_FILTER_TYPE_SILENT}.
     * <p>This value will only be read if the app has not previously specified a default type list,
     * and if the user has not overridden the allowed types.</p>
     * <p>An absent value means 'allow all types'.
     * A present but empty value means 'allow no types'.</p>
     *
     */
    public static final String META_DATA_DEFAULT_FILTER_TYPES
            = "android.service.notification.default_filter_types";

    /**
     * {@link #getCurrentInterruptionFilter() Interruption filter} constant -
     *     Normal interruption filter.
@@ -254,23 +273,19 @@ public abstract class NotificationListenerService extends Service {
    /**
     * A flag value indicating that this notification listener can see conversation type
     * notifications.
     * @hide
     */
    public static final int FLAG_FILTER_TYPE_CONVERSATIONS = 1;
    /**
     * A flag value indicating that this notification listener can see altering type notifications.
     * @hide
     */
    public static final int FLAG_FILTER_TYPE_ALERTING = 2;
    /**
     * A flag value indicating that this notification listener can see silent type notifications.
     * @hide
     */
    public static final int FLAG_FILTER_TYPE_SILENT = 4;
    /**
     * A flag value indicating that this notification listener can see important
     * ( > {@link NotificationManager#IMPORTANCE_MIN}) ongoing type notifications.
     * @hide
     */
    public static final int FLAG_FILTER_TYPE_ONGOING = 8;

+6 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.app.NotificationManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.IPackageManager;
import android.content.pm.ServiceInfo;
import android.net.Uri;
import android.os.IBinder;
import android.os.IInterface;
@@ -196,6 +197,11 @@ public class ConditionProviders extends ManagedServices {
        }
    }

    @Override
    protected void ensureFilters(ServiceInfo si, int userId) {
        // nothing to filter
    }

    @Override
    protected void loadDefaultsFromConfig() {
        String defaultDndAccess = mContext.getResources().getString(
+15 −5
Original line number Diff line number Diff line
@@ -189,6 +189,8 @@ abstract public class ManagedServices {

    abstract protected void onServiceAdded(ManagedServiceInfo info);

    abstract protected void ensureFilters(ServiceInfo si, int userId);

    protected List<ManagedServiceInfo> getServices() {
        synchronized (mMutex) {
            List<ManagedServiceInfo> services = new ArrayList<>(mServices);
@@ -1342,8 +1344,10 @@ abstract public class ManagedServices {
            for (ComponentName component : add) {
                try {
                    ServiceInfo info = mPm.getServiceInfo(component,
                            PackageManager.MATCH_DIRECT_BOOT_AWARE
                                    | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, userId);
                            PackageManager.GET_META_DATA
                                    | PackageManager.MATCH_DIRECT_BOOT_AWARE
                                    | PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
                            userId);
                    if (info == null) {
                        Slog.w(TAG, "Not binding " + getCaption() + " service " + component
                                + ": service not found");
@@ -1356,7 +1360,7 @@ abstract public class ManagedServices {
                    }
                    Slog.v(TAG,
                            "enabling " + getCaption() + " for " + userId + ": " + component);
                    registerService(component, userId);
                    registerService(info, userId);
                } catch (RemoteException e) {
                    e.rethrowFromSystemServer();
                }
@@ -1368,9 +1372,15 @@ abstract public class ManagedServices {
     * Version of registerService that takes the name of a service component to bind to.
     */
    @VisibleForTesting
    void registerService(final ComponentName name, final int userid) {
    void registerService(final ServiceInfo si, final int userId) {
        ensureFilters(si, userId);
        registerService(si.getComponentName(), userId);
    }

    @VisibleForTesting
    void registerService(final ComponentName cn, final int userId) {
        synchronized (mMutex) {
            registerServiceLocked(name, userid);
            registerServiceLocked(cn, userId);
        }
    }

Loading