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

Commit 367b6142 authored by Evan Laird's avatar Evan Laird Committed by Steve Elliott
Browse files

Move the people filtering to DeviceConfig flag

This way it can be turned on/off without a recompile, and checking the
flag doesn't require a context

Test: adb shell device_config put systemui notifications_use_people_filtering false && adb shell kill $(pid com.android.systemui)
Bug: 140232781
Change-Id: I8ba5e7809dc58e9493397db8447456601a398540
parent 84e6de26
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -239,6 +239,13 @@ public final class SystemUiDeviceConfigFlags {
    public static final String ASSIST_TRANSCRIPTION_MIN_DURATION =
            "assist_transcription_min_duration";

    /**
     * (boolean) Whether or not to enable an extra section in the notification shade which
     * filters for "people" related messages.
     */
    public static final String NOTIFICATIONS_USE_PEOPLE_FILTERING =
            "notifications_use_people_filtering";

    // Flags related to brightline falsing

    /**
+3 −3
Original line number Diff line number Diff line
@@ -15,11 +15,11 @@
 */
package com.android.systemui.car;

import android.content.Context;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;

import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.collection.NotificationData;

import javax.inject.Inject;
import javax.inject.Singleton;
@@ -34,8 +34,8 @@ import javax.inject.Singleton;
public class CarNotificationEntryManager extends NotificationEntryManager {

    @Inject
    public CarNotificationEntryManager(Context context) {
        super(context);
    public CarNotificationEntryManager(NotificationData notificationData) {
        super(notificationData);
    }

    @Override
+2 −3
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import static android.service.notification.NotificationListenerService.REASON_ER

import android.annotation.Nullable;
import android.app.Notification;
import android.content.Context;
import android.service.notification.NotificationListenerService;
import android.service.notification.NotificationListenerService.Ranking;
import android.service.notification.StatusBarNotification;
@@ -124,8 +123,8 @@ public class NotificationEntryManager implements
    }

    @Inject
    public NotificationEntryManager(Context context) {
        mNotificationData = new NotificationData(context);
    public NotificationEntryManager(NotificationData notificationData) {
        mNotificationData = notificationData;
    }

    /** Adds a {@link NotificationEntryListener}. */
+73 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.notification

import android.content.Context
import android.provider.DeviceConfig

import com.android.internal.annotations.VisibleForTesting
import com.android.internal.config.sysui.SystemUiDeviceConfigFlags.NOTIFICATIONS_USE_PEOPLE_FILTERING
import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_ALERTING
import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_PEOPLE
import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_SILENT
import com.android.systemui.util.DeviceConfigProxy

import javax.inject.Inject

private var sUsePeopleFiltering: Boolean? = null

/**
 * Feature controller for the NOTIFICATIONS_USE_PEOPLE_FILTERING config.
 */
class NotificationSectionsFeatureManager @Inject constructor(
    val proxy: DeviceConfigProxy,
    val context: Context
) {

    fun isFilteringEnabled(): Boolean {
        return usePeopleFiltering(proxy)
    }

    fun getNotificationBuckets(): IntArray {
        return when {
            isFilteringEnabled() ->
                intArrayOf(BUCKET_PEOPLE, BUCKET_ALERTING, BUCKET_SILENT)
            NotificationUtils.useNewInterruptionModel(context) ->
                intArrayOf(BUCKET_ALERTING, BUCKET_SILENT)
            else ->
                intArrayOf(BUCKET_ALERTING)
        }
    }

    fun getNumberOfBuckets(): Int {
        return getNotificationBuckets().size
    }

    @VisibleForTesting
    fun clearCache() {
        sUsePeopleFiltering = null
    }
}

private fun usePeopleFiltering(proxy: DeviceConfigProxy): Boolean {
    if (sUsePeopleFiltering == null) {
        sUsePeopleFiltering = proxy.getBoolean(
                DeviceConfig.NAMESPACE_SYSTEMUI, NOTIFICATIONS_USE_PEOPLE_FILTERING, false)
    }

    return sUsePeopleFiltering!!
}
+0 −14
Original line number Diff line number Diff line
@@ -36,7 +36,6 @@ public class NotificationUtils {
    private static final int[] sLocationOffset = new int[2];

    @Nullable private static Boolean sUseNewInterruptionModel = null;
    @Nullable private static Boolean sUsePeopleFiltering = null;

    public static boolean isGrayscale(ImageView v, ContrastColorUtil colorUtil) {
        Object isGrayscale = v.getTag(R.id.icon_is_grayscale);
@@ -88,17 +87,4 @@ public class NotificationUtils {
        }
        return sUseNewInterruptionModel;
    }

    /**
     * Caches and returns the value of the people filtering setting. Cannot change except through
     * process restarts.
     */
    public static boolean usePeopleFiltering(Context context) {
        if (sUsePeopleFiltering == null) {
            sUsePeopleFiltering = context.getResources().getBoolean(
                    R.bool.config_usePeopleFiltering);
        }

        return sUsePeopleFiltering;
    }
}
Loading