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

Commit 3035e0bb authored by Yuri Lin's avatar Yuri Lin Committed by Android (Google) Code Review
Browse files

Merge "Change default ZenPolicy to use device defaults." into main

parents ac775657 ce2ae319
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -377,6 +377,7 @@ package android.app {
  public class NotificationManager {
    method @FlaggedApi("android.app.modes_api") @NonNull public String addAutomaticZenRule(@NonNull android.app.AutomaticZenRule, boolean);
    method public void cleanUpCallersAfter(long);
    method @FlaggedApi("android.app.modes_api") @NonNull public android.service.notification.ZenPolicy getDefaultZenPolicy();
    method public android.content.ComponentName getEffectsSuppressor();
    method public boolean isNotificationPolicyAccessGrantedForPackage(@NonNull String);
    method @FlaggedApi("android.app.modes_api") public boolean removeAutomaticZenRule(@NonNull String, boolean);
@@ -3027,6 +3028,10 @@ package android.service.notification {
    method @Deprecated public boolean isBound();
  }

  public final class ZenPolicy implements android.os.Parcelable {
    method @FlaggedApi("android.app.modes_api") @NonNull public android.service.notification.ZenPolicy overwrittenWith(@Nullable android.service.notification.ZenPolicy);
  }

  public static final class ZenPolicy.Builder {
    ctor public ZenPolicy.Builder(@Nullable android.service.notification.ZenPolicy);
  }
+2 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.service.notification.IConditionProvider;
import android.service.notification.INotificationListener;
import android.service.notification.NotificationListenerFilter;
import android.service.notification.StatusBarNotification;
import android.service.notification.ZenPolicy;
import android.app.AutomaticZenRule;
import android.service.notification.ZenModeConfig;

@@ -213,6 +214,7 @@ interface INotificationManager
    boolean isNotificationPolicyAccessGrantedForPackage(String pkg);
    void setNotificationPolicyAccessGranted(String pkg, boolean granted);
    void setNotificationPolicyAccessGrantedForUser(String pkg, int userId, boolean granted);
    ZenPolicy getDefaultZenPolicy();
    AutomaticZenRule getAutomaticZenRule(String id);
    Map<String, AutomaticZenRule> getAutomaticZenRules();
    // TODO: b/310620812 - Remove getZenRules() when MODES_API is inlined.
+14 −0
Original line number Diff line number Diff line
@@ -1750,6 +1750,20 @@ public class NotificationManager {
            @NonNull ComponentName listener, boolean granted) {
        setNotificationListenerAccessGranted(listener, granted, true);
    }
    /**
     * Gets the device-default notification policy as a ZenPolicy.
     * @hide
     */
    @TestApi
    @FlaggedApi(Flags.FLAG_MODES_API)
    public @NonNull ZenPolicy getDefaultZenPolicy() {
        INotificationManager service = getService();
        try {
            return service.getDefaultZenPolicy();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * For apps targeting {@link Build.VERSION_CODES#VANILLA_ICE_CREAM} and above, the
+16 −4
Original line number Diff line number Diff line
@@ -185,7 +185,13 @@ public class ZenModeConfig implements Parcelable {
            SUPPRESSED_EFFECT_SCREEN_OFF | SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
                    | SUPPRESSED_EFFECT_LIGHTS | SUPPRESSED_EFFECT_PEEK | SUPPRESSED_EFFECT_AMBIENT;

    public static final int XML_VERSION = 8;
    // ZenModeConfig XML versions distinguishing key changes.
    public static final int XML_VERSION_ZEN_UPGRADE = 8;
    public static final int XML_VERSION_MODES_API = 11;

    // TODO: b/310620812 - Update XML_VERSION and update default_zen_config.xml accordingly when
    //       modes_api is inlined.
    private static final int XML_VERSION = 10;
    public static final String ZEN_TAG = "zen";
    private static final String ZEN_ATT_VERSION = "version";
    private static final String ZEN_ATT_USER = "user";
@@ -586,6 +592,10 @@ public class ZenModeConfig implements Parcelable {
        }
    }

    public static int getCurrentXmlVersion() {
        return Flags.modesApi() ? XML_VERSION_MODES_API : XML_VERSION;
    }

    public static ZenModeConfig readXml(TypedXmlPullParser parser)
            throws XmlPullParserException, IOException {
        int type = parser.getEventType();
@@ -593,7 +603,7 @@ public class ZenModeConfig implements Parcelable {
        String tag = parser.getName();
        if (!ZEN_TAG.equals(tag)) return null;
        final ZenModeConfig rt = new ZenModeConfig();
        rt.version = safeInt(parser, ZEN_ATT_VERSION, XML_VERSION);
        rt.version = safeInt(parser, ZEN_ATT_VERSION, getCurrentXmlVersion());
        rt.user = safeInt(parser, ZEN_ATT_USER, rt.user);
        boolean readSuppressedEffects = false;
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) {
@@ -707,14 +717,16 @@ public class ZenModeConfig implements Parcelable {
    /**
     * Writes XML of current ZenModeConfig
     * @param out serializer
     * @param version uses XML_VERSION if version is null
     * @param version uses the current XML version if version is null
     * @throws IOException
     */

    public void writeXml(TypedXmlSerializer out, Integer version, boolean forBackup)
            throws IOException {
        int xmlVersion = getCurrentXmlVersion();
        out.startTag(null, ZEN_TAG);
        out.attribute(null, ZEN_ATT_VERSION, version == null
                ? Integer.toString(XML_VERSION) : Integer.toString(version));
                ? Integer.toString(xmlVersion) : Integer.toString(version));
        out.attributeInt(null, ZEN_ATT_USER, user);
        out.startTag(null, ALLOW_TAG);
        out.attributeBoolean(null, ALLOW_ATT_CALLS, allowCalls);
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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 android.service.notification;

parcelable ZenPolicy;
 No newline at end of file
Loading