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

Commit c8aba827 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "pulled atom for Do Not Disturb configuration" into rvc-dev am: 5599ca73

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11494623

Change-Id: Ib8fe0b6eb376563973d589977a1511e380b08027
parents ab839825 5599ca73
Loading
Loading
Loading
Loading
+71 −0
Original line number Diff line number Diff line
@@ -566,6 +566,7 @@ message Atom {
        DataUsageBytesTransfer data_usage_bytes_transfer = 10082 [(module) = "framework"];
        BytesTransferByTagAndMetered bytes_transfer_by_tag_and_metered =
                10083 [(module) = "framework"];
        DNDModeProto dnd_mode_rule = 10084 [(module) = "framework"];
    }

    // DO NOT USE field numbers above 100,000 in AOSP.
@@ -6082,6 +6083,76 @@ message PackageNotificationChannelPreferences {
    optional bool is_important_conversation = 10;
}

/**
 * Atom that represents an item in the list of Do Not Disturb rules, pulled from
 * NotificationManagerService.java.
 */
message DNDModeProto {
    enum Mode {
        ROOT_CONFIG = -1;  // Used to distinguish the config (one per user) from the rules.
        ZEN_MODE_OFF = 0;
        ZEN_MODE_IMPORTANT_INTERRUPTIONS = 1;
        ZEN_MODE_NO_INTERRUPTIONS = 2;
        ZEN_MODE_ALARMS = 3;
    }
    optional int32 user = 1;  // Android user ID (0, 1, 10, ...)
    optional bool enabled = 2;  // true for ROOT_CONFIG if a manualRule is enabled
    optional bool channels_bypassing = 3; // only valid for ROOT_CONFIG
    optional Mode zen_mode = 4;
    // id is one of the system default rule IDs, or empty
    // May also be "MANUAL_RULE" to indicate app-activation of the manual rule.
    optional string id = 5;
    optional int32 uid = 6 [(is_uid) = true]; // currently only SYSTEM_UID or 0 for other
    optional DNDPolicyProto policy = 7;
}

/**
 * Atom that represents a Do Not Disturb policy, an optional detail proto for DNDModeProto.
 */
message DNDPolicyProto {
    enum State {
        STATE_UNSET = 0;
        STATE_ALLOW = 1;
        STATE_DISALLOW = 2;
    }
    optional State calls = 1;
    optional State repeat_callers = 2;
    optional State messages = 3;
    optional State conversations = 4;
    optional State reminders = 5;
    optional State events = 6;
    optional State alarms = 7;
    optional State media = 8;
    optional State system = 9;
    optional State fullscreen = 10;
    optional State lights = 11;
    optional State peek = 12;
    optional State status_bar = 13;
    optional State badge = 14;
    optional State ambient = 15;
    optional State notification_list = 16;

    enum PeopleType {
        PEOPLE_UNSET = 0;
        PEOPLE_ANYONE = 1;
        PEOPLE_CONTACTS = 2;
        PEOPLE_STARRED = 3;
        PEOPLE_NONE = 4;
    }

    optional PeopleType allow_calls_from = 17;
    optional PeopleType allow_messages_from = 18;

    enum ConversationType {
        CONV_UNSET = 0;
        CONV_ANYONE = 1;
        CONV_IMPORTANT = 2;
        CONV_NONE = 3;
    }

    optional ConversationType allow_conversations_from = 19;
}

/**
 * Atom that contains a list of a package's channel group preferences, pulled from
 * NotificationManagerService.java.
+43 −0
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ public class ZenModeConfig implements Parcelable {
    private static final int DEFAULT_SOURCE = SOURCE_CONTACT;
    private static final int DEFAULT_CALLS_SOURCE = SOURCE_STAR;

    public static final String MANUAL_RULE_ID = "MANUAL_RULE";
    public static final String EVENTS_DEFAULT_RULE_ID = "EVENTS_DEFAULT_RULE";
    public static final String EVERY_NIGHT_DEFAULT_RULE_ID = "EVERY_NIGHT_DEFAULT_RULE";
    public static final List<String> DEFAULT_RULE_IDS = Arrays.asList(EVERY_NIGHT_DEFAULT_RULE_ID,
@@ -958,6 +959,48 @@ public class ZenModeConfig implements Parcelable {
        }
    };

    /**
     * Converts a ZenModeConfig to a ZenPolicy
     */
    public ZenPolicy toZenPolicy() {
        ZenPolicy.Builder builder = new ZenPolicy.Builder()
                .allowCalls(allowCalls
                        ? ZenModeConfig.getZenPolicySenders(allowCallsFrom)
                        : ZenPolicy.PEOPLE_TYPE_NONE)
                .allowRepeatCallers(allowRepeatCallers)
                .allowMessages(allowMessages
                        ? ZenModeConfig.getZenPolicySenders(allowMessagesFrom)
                        : ZenPolicy.PEOPLE_TYPE_NONE)
                .allowReminders(allowReminders)
                .allowEvents(allowEvents)
                .allowAlarms(allowAlarms)
                .allowMedia(allowMedia)
                .allowSystem(allowSystem)
                .allowConversations(allowConversations
                        ? ZenModeConfig.getZenPolicySenders(allowConversationsFrom)
                        : ZenPolicy.PEOPLE_TYPE_NONE);
        if (suppressedVisualEffects == 0) {
            builder.showAllVisualEffects();
        } else {
            // configs don't have an unset state: wither true or false.
            builder.showFullScreenIntent(
                    (suppressedVisualEffects & Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT) == 0);
            builder.showLights(
                    (suppressedVisualEffects & SUPPRESSED_EFFECT_LIGHTS) == 0);
            builder.showPeeking(
                    (suppressedVisualEffects & SUPPRESSED_EFFECT_PEEK) == 0);
            builder.showStatusBarIcons(
                    (suppressedVisualEffects & Policy.SUPPRESSED_EFFECT_STATUS_BAR) == 0);
            builder.showBadges(
                    (suppressedVisualEffects & Policy.SUPPRESSED_EFFECT_BADGE) == 0);
            builder.showInAmbientDisplay(
                    (suppressedVisualEffects & Policy.SUPPRESSED_EFFECT_AMBIENT) == 0);
            builder.showInNotificationList(
                    (suppressedVisualEffects & Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST) == 0);
        }
        return builder.build();
    }

    /**
     * Converts a zenPolicy to a notificationPolicy using this ZenModeConfig's values as its
     * defaults for all unset values in zenPolicy
+35 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.util.proto.ProtoOutputStream;

import java.io.ByteArrayOutputStream;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
@@ -1110,6 +1111,40 @@ public final class ZenPolicy implements Parcelable {
        proto.end(token);
    }

    /**
     * Converts a policy to a statsd proto.
     * @hides
     */
    public byte[] toProto() {
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        ProtoOutputStream proto = new ProtoOutputStream(bytes);

        proto.write(DNDPolicyProto.CALLS, getPriorityCategoryCalls());
        proto.write(DNDPolicyProto.REPEAT_CALLERS, getPriorityCategoryRepeatCallers());
        proto.write(DNDPolicyProto.MESSAGES, getPriorityCategoryMessages());
        proto.write(DNDPolicyProto.CONVERSATIONS, getPriorityCategoryConversations());
        proto.write(DNDPolicyProto.REMINDERS, getPriorityCategoryReminders());
        proto.write(DNDPolicyProto.EVENTS, getPriorityCategoryEvents());
        proto.write(DNDPolicyProto.ALARMS, getPriorityCategoryAlarms());
        proto.write(DNDPolicyProto.MEDIA, getPriorityCategoryMedia());
        proto.write(DNDPolicyProto.SYSTEM, getPriorityCategorySystem());

        proto.write(DNDPolicyProto.FULLSCREEN, getVisualEffectFullScreenIntent());
        proto.write(DNDPolicyProto.LIGHTS, getVisualEffectLights());
        proto.write(DNDPolicyProto.PEEK, getVisualEffectPeek());
        proto.write(DNDPolicyProto.STATUS_BAR, getVisualEffectStatusBar());
        proto.write(DNDPolicyProto.BADGE, getVisualEffectBadge());
        proto.write(DNDPolicyProto.AMBIENT, getVisualEffectAmbient());
        proto.write(DNDPolicyProto.NOTIFICATION_LIST, getVisualEffectNotificationList());

        proto.write(DNDPolicyProto.ALLOW_CALLS_FROM, getPriorityCallSenders());
        proto.write(DNDPolicyProto.ALLOW_MESSAGES_FROM, getPriorityMessageSenders());
        proto.write(DNDPolicyProto.ALLOW_CONVERSATIONS_FROM, getPriorityConversationSenders());

        proto.flush();
        return bytes.toByteArray();
    }

    /**
     * Makes deep copy of this ZenPolicy.
     * @hide
+71 −1
Original line number Diff line number Diff line
@@ -275,3 +275,73 @@ message PackageRemoteViewInfoProto {
message NotificationRemoteViewsProto {
    repeated PackageRemoteViewInfoProto package_remote_view_info = 1;
}

/**
 * Atom that represents an item in the list of Do Not Disturb rules, pulled from
 * NotificationManagerService.java.
 */
message DNDModeProto {
    enum Mode {
        ROOT_CONFIG = -1;  // Used to distinguish the config (one per user) from the rules.
        ZEN_MODE_OFF = 0;
        ZEN_MODE_IMPORTANT_INTERRUPTIONS = 1;
        ZEN_MODE_NO_INTERRUPTIONS = 2;
        ZEN_MODE_ALARMS = 3;
    }
    optional int32 user = 1;  // Android user ID (0, 1, 10, ...)
    optional bool enabled = 2;  // true for ROOT_CONFIG if a manualRule is enabled
    optional bool channels_bypassing = 3; // only valid for ROOT_CONFIG
    optional Mode zen_mode = 4;
    // id is one of the system default rule IDs, or empty
    // May also be "MANUAL_RULE" to indicate app-activation of the manual rule.
    optional string id = 5;
    optional int32 uid = 6; // currently only SYSTEM_UID or 0 for other
    optional DNDPolicyProto policy = 7;
}

/**
 * Atom that represents a Do Not Disturb policy, an optional detail proto for DNDModeProto.
 */
message DNDPolicyProto {
    enum State {
        STATE_UNSET = 0;
        STATE_ALLOW = 1;
        STATE_DISALLOW = 2;
    }
    optional State calls = 1;
    optional State repeat_callers = 2;
    optional State messages = 3;
    optional State conversations = 4;
    optional State reminders = 5;
    optional State events = 6;
    optional State alarms = 7;
    optional State media = 8;
    optional State system = 9;
    optional State fullscreen = 10;
    optional State lights = 11;
    optional State peek = 12;
    optional State status_bar = 13;
    optional State badge = 14;
    optional State ambient = 15;
    optional State notification_list = 16;

    enum PeopleType {
        PEOPLE_UNSET = 0;
        PEOPLE_ANYONE = 1;
        PEOPLE_CONTACTS = 2;
        PEOPLE_STARRED = 3;
        PEOPLE_NONE = 4;
    }

    optional PeopleType allow_calls_from = 17;
    optional PeopleType allow_messages_from = 18;

    enum ConversationType {
        CONV_UNSET = 0;
        CONV_ANYONE = 1;
        CONV_IMPORTANT = 2;
        CONV_NONE = 3;
    }

    optional ConversationType allow_conversations_from = 19;
}
+13 −1
Original line number Diff line number Diff line
@@ -92,6 +92,7 @@ import static android.service.notification.NotificationListenerService.TRIM_FULL
import static android.service.notification.NotificationListenerService.TRIM_LIGHT;
import static android.view.WindowManager.LayoutParams.TYPE_TOAST;

import static com.android.internal.util.FrameworkStatsLog.DND_MODE_RULE;
import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_CHANNEL_GROUP_PREFERENCES;
import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_CHANNEL_PREFERENCES;
import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_PREFERENCES;
@@ -1906,7 +1907,8 @@ public class NotificationManagerService extends SystemService {
        mMetricsLogger = new MetricsLogger();
        mRankingHandler = rankingHandler;
        mConditionProviders = conditionProviders;
        mZenModeHelper = new ZenModeHelper(getContext(), mHandler.getLooper(), mConditionProviders);
        mZenModeHelper = new ZenModeHelper(getContext(), mHandler.getLooper(), mConditionProviders,
                new SysUiStatsEvent.BuilderFactory());
        mZenModeHelper.addCallback(new ZenModeHelper.Callback() {
            @Override
            public void onConfigChanged() {
@@ -2189,6 +2191,12 @@ public class NotificationManagerService extends SystemService {
                ConcurrentUtils.DIRECT_EXECUTOR,
                mPullAtomCallback
        );
        mStatsManager.setPullAtomCallback(
                DND_MODE_RULE,
                null, // use default PullAtomMetadata values
                BackgroundThread.getExecutor(),
                mPullAtomCallback
        );
    }

    private class StatsPullAtomCallbackImpl implements StatsManager.StatsPullAtomCallback {
@@ -2198,6 +2206,7 @@ public class NotificationManagerService extends SystemService {
                case PACKAGE_NOTIFICATION_PREFERENCES:
                case PACKAGE_NOTIFICATION_CHANNEL_PREFERENCES:
                case PACKAGE_NOTIFICATION_CHANNEL_GROUP_PREFERENCES:
                case DND_MODE_RULE:
                    return pullNotificationStates(atomTag, data);
                default:
                    throw new UnsupportedOperationException("Unknown tagId=" + atomTag);
@@ -2216,6 +2225,9 @@ public class NotificationManagerService extends SystemService {
            case PACKAGE_NOTIFICATION_CHANNEL_GROUP_PREFERENCES:
                mPreferencesHelper.pullPackageChannelGroupPreferencesStats(data);
                break;
            case DND_MODE_RULE:
                mZenModeHelper.pullRules(data);
                break;
        }
        return StatsManager.PULL_SUCCESS;
    }
Loading