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

Commit b0a773f6 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Allow third party condition providers.

Bug: 22977552
Change-Id: I3d8689f52daa9376496e14997a6dd7862fb3ade6
parent fa0f7cdd
Loading
Loading
Loading
Loading
+44 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ package android {
    field public static final deprecated java.lang.String BIND_CARRIER_MESSAGING_SERVICE = "android.permission.BIND_CARRIER_MESSAGING_SERVICE";
    field public static final java.lang.String BIND_CARRIER_SERVICES = "android.permission.BIND_CARRIER_SERVICES";
    field public static final java.lang.String BIND_CHOOSER_TARGET_SERVICE = "android.permission.BIND_CHOOSER_TARGET_SERVICE";
    field public static final java.lang.String BIND_CONDITION_PROVIDER_SERVICE = "android.permission.BIND_CONDITION_PROVIDER_SERVICE";
    field public static final java.lang.String BIND_DEVICE_ADMIN = "android.permission.BIND_DEVICE_ADMIN";
    field public static final java.lang.String BIND_DREAM_SERVICE = "android.permission.BIND_DREAM_SERVICE";
    field public static final java.lang.String BIND_INCALL_SERVICE = "android.permission.BIND_INCALL_SERVICE";
@@ -28743,6 +28744,49 @@ package android.service.media {
package android.service.notification {
  public class Condition implements android.os.Parcelable {
    ctor public Condition(android.net.Uri, java.lang.String, java.lang.String, java.lang.String, int, int, int);
    method public android.service.notification.Condition copy();
    method public int describeContents();
    method public static boolean isValidId(android.net.Uri, java.lang.String);
    method public static android.net.Uri.Builder newId(android.content.Context);
    method public static java.lang.String relevanceToString(int);
    method public static java.lang.String stateToString(int);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.service.notification.Condition> CREATOR;
    field public static final int FLAG_RELEVANT_ALWAYS = 2; // 0x2
    field public static final int FLAG_RELEVANT_NOW = 1; // 0x1
    field public static final java.lang.String SCHEME = "condition";
    field public static final int STATE_ERROR = 3; // 0x3
    field public static final int STATE_FALSE = 0; // 0x0
    field public static final int STATE_TRUE = 1; // 0x1
    field public static final int STATE_UNKNOWN = 2; // 0x2
    field public final int flags;
    field public final int icon;
    field public final android.net.Uri id;
    field public final java.lang.String line1;
    field public final java.lang.String line2;
    field public final int state;
    field public final java.lang.String summary;
  }
  public abstract 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 android.os.IBinder onBind(android.content.Intent);
    method public abstract void onConnected();
    method public abstract void onRequestConditions(int);
    method public abstract void onSubscribe(android.net.Uri);
    method public abstract void onUnsubscribe(android.net.Uri);
    field public static final java.lang.String EXTRA_CONDITION_ID = "android.content.automatic.conditionId";
    field public static final java.lang.String EXTRA_RULE_NAME = "android.content.automatic.ruleName";
    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_DEFAULT_CONDITION_ID = "android.service.zen.automatic.defaultConditionId";
    field public static final 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";
  }
  public abstract class NotificationListenerService extends android.app.Service {
    ctor public NotificationListenerService();
    method public final void cancelAllNotifications();
+5 −0
Original line number Diff line number Diff line
@@ -30868,6 +30868,11 @@ package android.service.notification {
    method public abstract void onRequestConditions(int);
    method public abstract void onSubscribe(android.net.Uri);
    method public abstract void onUnsubscribe(android.net.Uri);
    field public static final java.lang.String EXTRA_CONDITION_ID = "android.content.automatic.conditionId";
    field public static final java.lang.String EXTRA_RULE_NAME = "android.content.automatic.ruleName";
    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_DEFAULT_CONDITION_ID = "android.service.zen.automatic.defaultConditionId";
    field public static final 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";
  }
+0 −4
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package android.service.notification;

import android.annotation.SystemApi;
import android.content.Context;
import android.net.Uri;
import android.os.Parcel;
@@ -26,10 +25,7 @@ import java.util.Objects;

/**
 * Condition information from condition providers.
 *
 * @hide
 */
@SystemApi
public class Condition implements Parcelable {

    public static final String SCHEME = "condition";
+79 −4
Original line number Diff line number Diff line
@@ -17,9 +17,9 @@
package android.service.notification;

import android.annotation.SdkConstant;
import android.annotation.SystemApi;
import android.app.INotificationManager;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
@@ -33,7 +33,10 @@ import android.util.Log;
 * A service that provides conditions about boolean state.
 * <p>To extend this class, you must declare the service in your manifest file with
 * the {@link android.Manifest.permission#BIND_CONDITION_PROVIDER_SERVICE} permission
 * and include an intent filter with the {@link #SERVICE_INTERFACE} action. For example:</p>
 * and include an intent filter with the {@link #SERVICE_INTERFACE} action. If you want users to be
 * able to create and update conditions for this service to monitor, include the
 * {@link #META_DATA_RULE_TYPE}, {@link #META_DATA_DEFAULT_CONDITION_ID}, and
 * {@link #META_DATA_CONFIGURATION_ACTIVITY} tags. For example:</p>
 * <pre>
 * &lt;service android:name=".MyConditionProvider"
 *          android:label="&#64;string/service_name"
@@ -41,11 +44,21 @@ import android.util.Log;
 *     &lt;intent-filter>
 *         &lt;action android:name="android.service.notification.ConditionProviderService" />
 *     &lt;/intent-filter>
 *     &lt;meta-data
 *               android:name="android.service.zen.automatic.ruleType"
 *               android:value="@string/my_condition_rule">
 *           &lt;/meta-data>
 *           &lt;meta-data
 *               android:name="android.service.zen.automatic.defaultConditionId"
 *               android:value="condition://com.my.package/mycondition">
 *           &lt;/meta-data>
 *           &lt;meta-data
 *               android:name="android.service.zen.automatic.configurationActivity"
 *               android:value="com.my.package/.MyConditionConfigurationActivity">
 *           &lt;/meta-data>
 * &lt;/service></pre>
 *
 * @hide
 */
@SystemApi
public abstract class ConditionProviderService extends Service {
    private final String TAG = ConditionProviderService.class.getSimpleName()
            + "[" + getClass().getSimpleName() + "]";
@@ -62,9 +75,63 @@ public abstract class ConditionProviderService extends Service {
    public static final String SERVICE_INTERFACE
            = "android.service.notification.ConditionProviderService";

    /**
     * The name of the {@code meta-data} tag containing a localized name of the type of zen rules
     * provided by this service.
     */
    public static final String META_DATA_RULE_TYPE = "android.service.zen.automatic.ruleType";

    /**
     * The name of the {@code meta-data} tag containing a default Condition {@link Uri} that can
     * be parsed by this service.
     */
    public static final String META_DATA_DEFAULT_CONDITION_ID =
            "android.service.zen.automatic.defaultConditionId";

    /**
     * The name of the {@code meta-data} tag containing the {@link ComponentName} of an activity
     * that allows users to configure the conditions provided by this service.
     */
    public static final String META_DATA_CONFIGURATION_ACTIVITY =
            "android.service.zen.automatic.configurationActivity";

    /**
     * A condition {@link Uri} extra passed to {@link #META_DATA_CONFIGURATION_ACTIVITY}. If the
     * condition Uri is modified by that activity, it must be included in the result Intent extras
     * in order to be persisted.
     */
    public static final String EXTRA_CONDITION_ID = "android.content.automatic.conditionId";

    /**
     * A String rule name extra passed to {@link #META_DATA_CONFIGURATION_ACTIVITY}. This extra is
     * informative only, and will be ignored if included in the result Intent extras.
     */
    public static final String EXTRA_RULE_NAME = "android.content.automatic.ruleName";

    /**
     * Called when this service is connected.
     */
    abstract public void onConnected();

    /**
     * Called when the system wants to know the state of Conditions managed by this provider.
     *
     * Implementations should evaluate the state of all subscribed conditions, and provide updates
     * by calling {@link #notifyCondition(Condition)} or {@link #notifyConditions(Condition...)}.
     * @param relevance
     */
    abstract public void onRequestConditions(int relevance);

    /**
     * Called by the system when there is a new {@link Condition} to be managed by this provider.
     * @param conditionId the Uri describing the criteria of the condition.
     */
    abstract public void onSubscribe(Uri conditionId);

    /**
     * Called by the system when a {@link Condition} has been deleted.
     * @param conditionId the Uri describing the criteria of the deleted condition.
     */
    abstract public void onUnsubscribe(Uri conditionId);

    private final INotificationManager getNotificationInterface() {
@@ -75,11 +142,19 @@ public abstract class ConditionProviderService extends Service {
        return mNoMan;
    }

    /**
     * Informs the notification manager that the state of a Condition has changed.
     * @param condition the condition that has changed.
     */
    public final void notifyCondition(Condition condition) {
        if (condition == null) return;
        notifyConditions(new Condition[]{ condition });
    }

    /**
     * Informs the notification manager that the state of one or more Conditions has changed.
     * @param conditions the changed conditions.
     */
    public final void notifyConditions(Condition... conditions) {
        if (!isBound() || conditions == null) return;
        try {
+3 −2
Original line number Diff line number Diff line
@@ -2567,10 +2567,11 @@
    <permission android:name="android.permission.BIND_CHOOSER_TARGET_SERVICE"
        android:protectionLevel="signature" />

    <!-- @SystemApi Must be required by a {@link
    <!-- Must be required by a {@link
         android.service.notification.ConditionProviderService},
         to ensure that only the system can bind to it.
         @hide -->
         <p>Protection level: signature
         -->
    <permission android:name="android.permission.BIND_CONDITION_PROVIDER_SERVICE"
        android:protectionLevel="signature" />