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

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

Merge "Deprecate ConditionProviderService."

parents f2e2a8f1 68062074
Loading
Loading
Loading
Loading
+16 −9
Original line number Diff line number Diff line
@@ -4433,11 +4433,12 @@ package android.app {
  }
  public final class AutomaticZenRule implements android.os.Parcelable {
    ctor public AutomaticZenRule(java.lang.String, android.content.ComponentName, android.net.Uri, int, boolean);
    ctor public AutomaticZenRule(java.lang.String, android.content.ComponentName, android.net.Uri, android.service.notification.ZenPolicy, boolean);
    ctor public deprecated AutomaticZenRule(java.lang.String, android.content.ComponentName, android.net.Uri, int, boolean);
    ctor public AutomaticZenRule(java.lang.String, android.content.ComponentName, android.content.ComponentName, android.net.Uri, android.service.notification.ZenPolicy, int, boolean);
    ctor public AutomaticZenRule(android.os.Parcel);
    method public int describeContents();
    method public android.net.Uri getConditionId();
    method public android.content.ComponentName getConfigurationActivity();
    method public long getCreationTime();
    method public int getInterruptionFilter();
    method public java.lang.String getName();
@@ -4445,6 +4446,7 @@ package android.app {
    method public android.service.notification.ZenPolicy getZenPolicy();
    method public boolean isEnabled();
    method public void setConditionId(android.net.Uri);
    method public void setConfigurationActivity(android.content.ComponentName);
    method public void setEnabled(boolean);
    method public void setInterruptionFilter(int);
    method public void setName(java.lang.String);
@@ -5773,16 +5775,19 @@ package android.app {
    method public void notifyAsPackage(java.lang.String, java.lang.String, int, android.app.Notification);
    method public boolean removeAutomaticZenRule(java.lang.String);
    method public void revokeNotificationDelegate();
    method public void setAutomaticZenRuleState(java.lang.String, android.service.notification.Condition);
    method public final void setInterruptionFilter(int);
    method public void setNotificationDelegate(java.lang.String);
    method public void setNotificationPolicy(android.app.NotificationManager.Policy);
    method public boolean updateAutomaticZenRule(java.lang.String, android.app.AutomaticZenRule);
    field public static final java.lang.String ACTION_APP_BLOCK_STATE_CHANGED = "android.app.action.APP_BLOCK_STATE_CHANGED";
    field public static final java.lang.String ACTION_AUTOMATIC_ZEN_RULE = "android.app.action.AUTOMATIC_ZEN_RULE";
    field public static final java.lang.String ACTION_INTERRUPTION_FILTER_CHANGED = "android.app.action.INTERRUPTION_FILTER_CHANGED";
    field public static final java.lang.String ACTION_NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED = "android.app.action.NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED";
    field public static final java.lang.String ACTION_NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED = "android.app.action.NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED";
    field public static final java.lang.String ACTION_NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED = "android.app.action.NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED";
    field public static final java.lang.String ACTION_NOTIFICATION_POLICY_CHANGED = "android.app.action.NOTIFICATION_POLICY_CHANGED";
    field public static final java.lang.String EXTRA_AUTOMATIC_RULE_ID = "android.app.extra.AUTOMATIC_RULE_ID";
    field public static final java.lang.String EXTRA_BLOCKED_STATE = "android.app.extra.BLOCKED_STATE";
    field public static final java.lang.String EXTRA_NOTIFICATION_CHANNEL_GROUP_ID = "android.app.extra.NOTIFICATION_CHANNEL_GROUP_ID";
    field public static final java.lang.String EXTRA_NOTIFICATION_CHANNEL_ID = "android.app.extra.NOTIFICATION_CHANNEL_ID";
@@ -5798,6 +5803,8 @@ package android.app {
    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 java.lang.String META_DATA_AUTOMATIC_RULE_TYPE = "android.app.automatic.ruleType";
    field public static final java.lang.String META_DATA_RULE_INSTANCE_LIMIT = "android.app.zen.automatic.ruleInstanceLimit";
  }
  public static class NotificationManager.Policy implements android.os.Parcelable {
@@ -41009,10 +41016,10 @@ package android.service.notification {
    field public final java.lang.String summary;
  }
  public abstract class ConditionProviderService extends android.app.Service {
  public abstract deprecated class ConditionProviderService extends android.app.Service {
    ctor public ConditionProviderService();
    method public final void notifyCondition(android.service.notification.Condition);
    method public final void notifyConditions(android.service.notification.Condition...);
    method public final deprecated void notifyCondition(android.service.notification.Condition);
    method public final deprecated void notifyConditions(android.service.notification.Condition...);
    method public android.os.IBinder onBind(android.content.Intent);
    method public abstract void onConnected();
    method public void onRequestConditions(int);
@@ -41020,10 +41027,10 @@ package android.service.notification {
    method public abstract void onUnsubscribe(android.net.Uri);
    method public static final void requestRebind(android.content.ComponentName);
    method public final void requestUnbind();
    field public static final java.lang.String EXTRA_RULE_ID = "android.service.notification.extra.RULE_ID";
    field public static final java.lang.String META_DATA_CONFIGURATION_ACTIVITY = "android.service.zen.automatic.configurationActivity";
    field public static final java.lang.String META_DATA_RULE_INSTANCE_LIMIT = "android.service.zen.automatic.ruleInstanceLimit";
    field public static final java.lang.String META_DATA_RULE_TYPE = "android.service.zen.automatic.ruleType";
    field public static final deprecated java.lang.String EXTRA_RULE_ID = "android.service.notification.extra.RULE_ID";
    field public static final deprecated java.lang.String META_DATA_CONFIGURATION_ACTIVITY = "android.service.zen.automatic.configurationActivity";
    field public static final deprecated java.lang.String META_DATA_RULE_INSTANCE_LIMIT = "android.service.zen.automatic.ruleInstanceLimit";
    field public static final deprecated java.lang.String META_DATA_RULE_TYPE = "android.service.zen.automatic.ruleType";
    field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.ConditionProviderService";
  }
+1 −1
Original line number Diff line number Diff line
@@ -1197,7 +1197,7 @@ package android.service.notification {
    field public static final java.lang.String KEY_USER_SENTIMENT = "key_user_sentiment";
  }

  public abstract class ConditionProviderService extends android.app.Service {
  public abstract deprecated class ConditionProviderService extends android.app.Service {
    method public boolean isBound();
  }

+60 −30
Original line number Diff line number Diff line
@@ -20,10 +20,14 @@ import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;

import android.app.NotificationManager.InterruptionFilter;
import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.service.notification.ZenPolicy;
import android.service.notification.Condition;

import com.android.internal.util.Preconditions;

import java.util.Objects;

@@ -40,6 +44,7 @@ public final class AutomaticZenRule implements Parcelable {
    private @InterruptionFilter int interruptionFilter;
    private Uri conditionId;
    private ComponentName owner;
    private ComponentName configurationActivity;
    private long creationTime;
    private ZenPolicy mZenPolicy;
    private boolean mModified = false;
@@ -49,39 +54,51 @@ public final class AutomaticZenRule implements Parcelable {
     *
     * @param name The name of the rule.
     * @param owner The Condition Provider service that owns this rule.
     * @param conditionId A representation of the state that should cause the Condition Provider
     *                    service to apply the given interruption filter.
     * @param interruptionFilter The interruption filter defines which notifications are allowed to
     *                           interrupt the user (e.g. via sound & vibration) while this rule
     *                           is active.
     * @param enabled Whether the rule is enabled.
     * @deprecated use {@link #AutomaticZenRule(String, ComponentName, ComponentName, Uri,
     * ZenPolicy, int, boolean)}.
     */
    @Deprecated
    public AutomaticZenRule(String name, ComponentName owner, Uri conditionId,
            int interruptionFilter, boolean enabled) {
        this.name = name;
        this.owner = owner;
        this.conditionId = conditionId;
        this.interruptionFilter = interruptionFilter;
        this.enabled = enabled;
        this(name, owner, null, conditionId, null, interruptionFilter, enabled);
    }

    /**
     * Creates an automatic zen rule.
     *
     * @param name The name of the rule.
     * @param owner The Condition Provider service that owns this rule.
     * @param conditionId A representation of the state that should cause the Condition Provider
     *                    service to apply the given interruption filter.
     * @param owner The Condition Provider service that owns this rule. This can be null if you're
     *              using {@link NotificationManager#setAutomaticZenRuleState(String, Condition)}
     *              instead of {@link android.service.notification.ConditionProviderService}.
     * @param configurationActivity An activity that handles
     *                              {@link NotificationManager#ACTION_AUTOMATIC_ZEN_RULE} that shows
     *                              the user
     *                              more information about this rule and/or allows them to
     *                              configure it. This is required if you are not using a
     *                              {@link android.service.notification.ConditionProviderService}.
     *                              If you are, it overrides the information specified in your
     *                              manifest.
     * @param conditionId A representation of the state that should cause your app to apply the
     *                    given interruption filter.
     * @param interruptionFilter The interruption filter defines which notifications are allowed to
     *                           interrupt the user (e.g. via sound & vibration) while this rule
     *                           is active.
     * @param policy The policy defines which notifications are allowed to interrupt the user
     *               while this rule is active
     *               while this rule is active. This overrides the global policy while this rule is
     *               action ({@link Condition#STATE_TRUE}).
     * @param enabled Whether the rule is enabled.
     */
    public AutomaticZenRule(String name, ComponentName owner, Uri conditionId, ZenPolicy policy,
            boolean enabled) {
    public AutomaticZenRule(String name, ComponentName owner, ComponentName configurationActivity,
            Uri conditionId, ZenPolicy policy, int interruptionFilter, boolean enabled) {
        this.name = name;
        this.owner = owner;
        this.configurationActivity = configurationActivity;
        this.conditionId = conditionId;
        this.interruptionFilter = INTERRUPTION_FILTER_PRIORITY;
        this.interruptionFilter = interruptionFilter;
        this.enabled = enabled;
        this.mZenPolicy = policy;
    }
@@ -89,18 +106,10 @@ public final class AutomaticZenRule implements Parcelable {
    /**
     * @hide
     */
    public AutomaticZenRule(String name, ComponentName owner, Uri conditionId,
            int interruptionFilter, boolean enabled, long creationTime) {
        this(name, owner, conditionId, interruptionFilter, enabled);
        this.creationTime = creationTime;
    }

    /**
     * @hide
     */
    public AutomaticZenRule(String name, ComponentName owner, Uri conditionId, ZenPolicy policy,
            boolean enabled, long creationTime) {
        this(name, owner, conditionId, policy, enabled);
    public AutomaticZenRule(String name, ComponentName owner, ComponentName configurationActivity,
            Uri conditionId, ZenPolicy policy, int interruptionFilter, boolean enabled,
            long creationTime) {
        this(name, owner, configurationActivity, conditionId, policy, interruptionFilter, enabled);
        this.creationTime = creationTime;
    }

@@ -112,6 +121,7 @@ public final class AutomaticZenRule implements Parcelable {
        interruptionFilter = source.readInt();
        conditionId = source.readParcelable(null);
        owner = source.readParcelable(null);
        configurationActivity = source.readParcelable(null);
        creationTime = source.readLong();
        mZenPolicy = source.readParcelable(null);
        mModified = source.readInt() == ENABLED;
@@ -124,6 +134,14 @@ public final class AutomaticZenRule implements Parcelable {
        return owner;
    }

    /**
     * Returns the {@link ComponentName} of the activity that shows configuration options
     * for this rule.
     */
    public ComponentName getConfigurationActivity() {
        return configurationActivity;
    }

    /**
     * Returns the representation of the state that causes this rule to become active.
     */
@@ -218,6 +236,15 @@ public final class AutomaticZenRule implements Parcelable {
        this.mZenPolicy = zenPolicy;
    }

    /**
     * Sets the configuration activity - an activity that handles
     * {@link NotificationManager#ACTION_AUTOMATIC_ZEN_RULE} that shows the user more information
     * about this rule and/or allows them to configure it.
     */
    public void setConfigurationActivity(ComponentName componentName) {
        this.configurationActivity = componentName;
    }

    @Override
    public int describeContents() {
        return 0;
@@ -235,6 +262,7 @@ public final class AutomaticZenRule implements Parcelable {
        dest.writeInt(interruptionFilter);
        dest.writeParcelable(conditionId, 0);
        dest.writeParcelable(owner, 0);
        dest.writeParcelable(configurationActivity, 0);
        dest.writeLong(creationTime);
        dest.writeParcelable(mZenPolicy, 0);
        dest.writeInt(mModified ? ENABLED : DISABLED);
@@ -248,6 +276,7 @@ public final class AutomaticZenRule implements Parcelable {
                .append(",interruptionFilter=").append(interruptionFilter)
                .append(",conditionId=").append(conditionId)
                .append(",owner=").append(owner)
                .append(",configActivity=").append(configurationActivity)
                .append(",creationTime=").append(creationTime)
                .append(",mZenPolicy=").append(mZenPolicy)
                .append(']').toString();
@@ -264,14 +293,15 @@ public final class AutomaticZenRule implements Parcelable {
                && other.interruptionFilter == interruptionFilter
                && Objects.equals(other.conditionId, conditionId)
                && Objects.equals(other.owner, owner)
                && other.creationTime == creationTime
                && Objects.equals(other.mZenPolicy, mZenPolicy);
                && Objects.equals(other.mZenPolicy, mZenPolicy)
                && Objects.equals(other.configurationActivity, configurationActivity)
                && other.creationTime == creationTime;
    }

    @Override
    public int hashCode() {
        return Objects.hash(enabled, name, interruptionFilter, conditionId, owner, creationTime,
                mZenPolicy, mModified);
        return Objects.hash(enabled, name, interruptionFilter, conditionId, owner,
                configurationActivity, mZenPolicy, mModified, creationTime);
    }

    public static final Parcelable.Creator<AutomaticZenRule> CREATOR
+1 −0
Original line number Diff line number Diff line
@@ -164,6 +164,7 @@ interface INotificationManager
    boolean removeAutomaticZenRule(String id);
    boolean removeAutomaticZenRules(String packageName);
    int getRuleInstanceCount(in ComponentName owner);
    void setAutomaticZenRuleState(String id, in Condition condition);

    byte[] getBackupPayload(int user);
    void applyRestore(in byte[] payload, int user);
+87 −8
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.os.ServiceManager;
import android.os.StrictMode;
import android.os.UserHandle;
import android.provider.Settings.Global;
import android.service.notification.Condition;
import android.service.notification.StatusBarNotification;
import android.service.notification.ZenModeConfig;
import android.util.Log;
@@ -262,6 +263,68 @@ public class NotificationManager {
    @Retention(RetentionPolicy.SOURCE)
    public @interface Importance {}

    /**
     * Activity Action: Launch an Automatic Zen Rule configuration screen
     * <p>
     * Input: Optionally, {@link #EXTRA_AUTOMATIC_RULE_ID}, if the configuration screen for an
     * existing rule should be displayed. If the rule id is missing or null, apps should display
     * a configuration screen where users can create a new instance of the rule.
     * <p>
     * Output: Nothing
     * <p>
     *     You can have multiple activities handling this intent, if you support multiple
     *     {@link AutomaticZenRule rules}. In order for the system to properly display all of your
     *     rule types so that users can create new instances or configure existing ones, you need
     *     to add some extra metadata ({@link #META_DATA_AUTOMATIC_RULE_TYPE})
     *     to your activity tag in your manifest. If you'd like to limit the number of rules a user
     *     can create from this flow, you can additionally optionally include
     *     {@link #META_DATA_RULE_INSTANCE_LIMIT}.
     *
     *     For example,
     *     &lt;meta-data
     *         android:name="android.app.zen.automatic.ruleType"
     *         android:value="@string/my_condition_rule">
     *     &lt;/meta-data>
     *     &lt;meta-data
     *         android:name="android.app.zen.automatic.ruleInstanceLimit"
     *         android:value="1">
     *     &lt;/meta-data>
     * </p>
     * </p>
     *
     * @see {@link #addAutomaticZenRule(AutomaticZenRule)}
     */
    @SdkConstant(SdkConstant.SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_AUTOMATIC_ZEN_RULE =
            "android.app.action.AUTOMATIC_ZEN_RULE";

    /**
     * Used as an optional string extra on {@link #ACTION_AUTOMATIC_ZEN_RULE} intents. If
     * provided, contains the id of the {@link AutomaticZenRule} (as returned from
     * {@link NotificationManager#addAutomaticZenRule(AutomaticZenRule)}) for which configuration
     * settings should be displayed.
     */
    public static final String EXTRA_AUTOMATIC_RULE_ID = "android.app.extra.AUTOMATIC_RULE_ID";

    /**
     * A required {@code meta-data} tag for activities that handle
     * {@link #ACTION_AUTOMATIC_ZEN_RULE}.
     *
     * This tag should contain a localized name of the type of the zen rule provided by the
     * activity.
     */
    public static final String META_DATA_AUTOMATIC_RULE_TYPE = "android.app.automatic.ruleType";

    /**
     * An optional {@code meta-data} tag for activities that handle
     * {@link #ACTION_AUTOMATIC_ZEN_RULE}.
     *
     * This tag should contain the maximum number of rule instances that
     * can be created for this rule type. Omit or enter a value <= 0 to allow unlimited instances.
     */
    public static final String META_DATA_RULE_INSTANCE_LIMIT =
            "android.app.zen.automatic.ruleInstanceLimit";

    /** Value signifying that the user has not expressed a per-app visibility override value.
     * @hide */
    public static final int VISIBILITY_NO_OVERRIDE = -1000;
@@ -859,14 +922,10 @@ public class NotificationManager {
            List<ZenModeConfig.ZenRule> rules = service.getZenRules();
            Map<String, AutomaticZenRule> ruleMap = new HashMap<>();
            for (ZenModeConfig.ZenRule rule : rules) {
                if (rule.zenPolicy == null) {
                    ruleMap.put(rule.id, new AutomaticZenRule(rule.name, rule.component,
                            rule.conditionId, zenModeToInterruptionFilter(rule.zenMode),
                            rule.enabled, rule.creationTime));
                } else {
                ruleMap.put(rule.id, new AutomaticZenRule(rule.name, rule.component,
                            rule.conditionId, rule.zenPolicy, rule.enabled, rule.creationTime));
                }
                        rule.configurationActivity, rule.conditionId, rule.zenPolicy,
                        zenModeToInterruptionFilter(rule.zenMode), rule.enabled,
                        rule.creationTime));
            }
            return ruleMap;
        } catch (RemoteException e) {
@@ -935,6 +994,26 @@ public class NotificationManager {
        }
    }

    /**
     * Informs the notification manager that the state of an {@link AutomaticZenRule} has changed.
     * Use this method to put the system into Do Not Disturb mode or request that it exits Do Not
     * Disturb mode. The calling app must own the provided {@link android.app.AutomaticZenRule}.
     * <p>
     *     This method can be used in conjunction with or as a replacement to
     *     {@link android.service.notification.ConditionProviderService#notifyCondition(Condition)}.
     * </p>
     * @param id The id of the rule whose state should change
     * @param condition The new state of this rule
     */
    public void setAutomaticZenRuleState(String id, Condition condition) {
        INotificationManager service = getService();
        try {
            service.setAutomaticZenRuleState(id, condition);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Deletes the automatic zen rule with the given id.
     *
Loading