Condition cleanup.

Change-Id: If978bebac52c0b1438e86339669f409b4b17c6fc
This commit is contained in:
Julia Reynolds
2016-03-07 13:51:02 -05:00
parent 9edd36a8ba
commit 1d6d16d699
9 changed files with 61 additions and 64 deletions

View File

@@ -34426,8 +34426,9 @@ 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);
ctor public Condition(android.net.Uri, java.lang.String, int);
ctor public Condition(android.net.Uri, java.lang.String, java.lang.String, java.lang.String, int, int, int);
ctor public Condition(android.os.Parcel);
method public android.service.notification.Condition copy();
method public int describeContents();
method public static boolean isValidId(android.net.Uri, java.lang.String);
@@ -34458,6 +34459,7 @@ package android.service.notification {
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 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_RULE_ID = "android.content.automatic.ruleId";

View File

@@ -201,14 +201,6 @@ package android.provider {
}
package android.service.notification {
public abstract class ConditionProviderService extends android.app.Service {
method public void onRequestConditions(int);
}
}
package android.test.mock {
public deprecated class MockPackageManager extends android.content.pm.PackageManager {

View File

@@ -36916,8 +36916,9 @@ 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);
ctor public Condition(android.net.Uri, java.lang.String, int);
ctor public Condition(android.net.Uri, java.lang.String, java.lang.String, java.lang.String, int, int, int);
ctor public Condition(android.os.Parcel);
method public android.service.notification.Condition copy();
method public int describeContents();
method public static boolean isValidId(android.net.Uri, java.lang.String);

View File

@@ -34443,8 +34443,9 @@ 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);
ctor public Condition(android.net.Uri, java.lang.String, int);
ctor public Condition(android.net.Uri, java.lang.String, java.lang.String, java.lang.String, int, int, int);
ctor public Condition(android.os.Parcel);
method public android.service.notification.Condition copy();
method public int describeContents();
method public static boolean isValidId(android.net.Uri, java.lang.String);
@@ -34475,6 +34476,7 @@ package android.service.notification {
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 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_RULE_ID = "android.content.automatic.ruleId";

View File

@@ -201,14 +201,6 @@ package android.provider {
}
package android.service.notification {
public abstract class ConditionProviderService extends android.app.Service {
method public void onRequestConditions(int);
}
}
package android.test.mock {
public deprecated class MockPackageManager extends android.content.pm.PackageManager {

View File

@@ -42,7 +42,7 @@ 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 interruption filter.
* 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.

View File

@@ -16,32 +16,56 @@
package android.service.notification;
import android.annotation.IntDef;
import android.annotation.SystemApi;
import android.app.AutomaticZenRule;
import android.content.Context;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Objects;
/**
* Condition information from condition providers. Used to tell the system to enter Do Not Disturb
* mode and request that the system exit Do Not Disturb mode.
* The current condition of an {@link android.app.AutomaticZenRule}, provided by the
* {@link ConditionProviderService} that owns the rule. Used to tell the system to enter Do Not
* Disturb mode and request that the system exit Do Not Disturb mode.
*/
public class Condition implements Parcelable {
@SystemApi
public static final String SCHEME = "condition";
/** @hide */
@IntDef({STATE_FALSE, STATE_TRUE, STATE_TRUE, STATE_ERROR})
@Retention(RetentionPolicy.SOURCE)
public @interface State {}
/**
* Indicates that Do Not Disturb should be turned off. Note that all Conditions from all
* {@link ConditionProviderService} providers must be off for Do Not Disturb to be turned off on
* the device.
*/
public static final int STATE_FALSE = 0;
/**
* Indicates that Do Not Disturb should be turned on.
*/
public static final int STATE_TRUE = 1;
@SystemApi
public static final int STATE_UNKNOWN = 2;
@SystemApi
public static final int STATE_ERROR = 3;
@SystemApi
public static final int FLAG_RELEVANT_NOW = 1 << 0;
@SystemApi
public static final int FLAG_RELEVANT_ALWAYS = 1 << 1;
/**
* The URI representing the condition being updated.
* The URI representing the rule being updated.
* See {@link android.app.AutomaticZenRule#getConditionId()}.
*/
public final Uri id;
@@ -52,23 +76,17 @@ public class Condition implements Parcelable {
*/
public final String summary;
/**
* Additional information about what the rule encoded in {@link #id} means when it is enabled.
* User visible if the state of the condition is {@link #STATE_TRUE}.
*/
@SystemApi
public final String line1;
/**
* Additional information about what the rule encoded in {@link #id} means when it is enabled.
* User visible if the state of the condition is {@link #STATE_TRUE}.
*/
@SystemApi
public final String line2;
/**
* The state of this condition. {@link #STATE_TRUE} will enable Do Not Disturb mode. Any other
* state will turn Do Not Disturb off for this rule. Note that Do Not Disturb might still be
* enabled globally if other conditions are in a {@link #STATE_TRUE} state.
* The state of this condition. {@link #STATE_TRUE} will enable Do Not Disturb mode.
* {@link #STATE_FALSE} will turn Do Not Disturb off for this rule. Note that Do Not Disturb
* might still be enabled globally if other conditions are in a {@link #STATE_TRUE} state.
*/
@State
public final int state;
@SystemApi
@@ -76,8 +94,13 @@ public class Condition implements Parcelable {
@SystemApi
public final int icon;
public Condition(Uri id, String summary, String line1, String line2, int state) {
this(id, summary, line1, line2, -1, state, FLAG_RELEVANT_ALWAYS);
/**
* An object representing the current state of a {@link android.app.AutomaticZenRule}.
* @param id the {@link android.app.AutomaticZenRule#getConditionId()} of the zen rule
* @param summary a user visible description of the rule state.
*/
public Condition(Uri id, String summary, int state) {
this(id, summary, "", "", -1, state, FLAG_RELEVANT_ALWAYS);
}
@SystemApi
@@ -85,8 +108,6 @@ public class Condition implements Parcelable {
int state, int flags) {
if (id == null) throw new IllegalArgumentException("id is required");
if (summary == null) throw new IllegalArgumentException("summary is required");
if (line1 == null) throw new IllegalArgumentException("line1 is required");
if (line2 == null) throw new IllegalArgumentException("line2 is required");
if (!isValidState(state)) throw new IllegalArgumentException("state is invalid: " + state);
this.id = id;
this.summary = summary;
@@ -97,7 +118,7 @@ public class Condition implements Parcelable {
this.flags = flags;
}
private Condition(Parcel source) {
public Condition(Parcel source) {
this((Uri)source.readParcelable(Condition.class.getClassLoader()),
source.readString(),
source.readString(),
@@ -135,6 +156,7 @@ public class Condition implements Parcelable {
.append(']').toString();
}
@SystemApi
public static String stateToString(int state) {
if (state == STATE_FALSE) return "STATE_FALSE";
if (state == STATE_TRUE) return "STATE_TRUE";
@@ -143,6 +165,7 @@ public class Condition implements Parcelable {
throw new IllegalArgumentException("state is invalid: " + state);
}
@SystemApi
public static String relevanceToString(int flags) {
final boolean now = (flags & FLAG_RELEVANT_NOW) != 0;
final boolean always = (flags & FLAG_RELEVANT_ALWAYS) != 0;
@@ -175,6 +198,7 @@ public class Condition implements Parcelable {
return 0;
}
@SystemApi
public Condition copy() {
final Parcel parcel = Parcel.obtain();
try {
@@ -186,10 +210,14 @@ public class Condition implements Parcelable {
}
}
@SystemApi
public static Uri.Builder newId(Context context) {
return new Uri.Builder().scheme(SCHEME).authority(context.getPackageName());
return new Uri.Builder()
.scheme(Condition.SCHEME)
.authority(context.getPackageName());
}
@SystemApi
public static boolean isValidId(Uri id, String pkg) {
return id != null && SCHEME.equals(id.getScheme()) && pkg.equals(id.getAuthority());
}

View File

@@ -102,9 +102,6 @@ public abstract class ConditionProviderService extends Service {
*/
abstract public void onConnected();
/**
* @removed
*/
@SystemApi
public void onRequestConditions(int relevance) {}

View File

@@ -16,6 +16,7 @@
package com.android.server.notification;
import android.app.AutomaticZenRule;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
@@ -44,7 +45,6 @@ import java.util.Arrays;
public class ConditionProviders extends ManagedServices {
private final ArrayList<ConditionRecord> mRecords = new ArrayList<>();
private final ArrayMap<IBinder, IConditionListener> mListeners = new ArrayMap<>();
private final ArraySet<String> mSystemConditionProviderNames;
private final ArraySet<SystemConditionProviderService> mSystemConditionProviders
= new ArraySet<>();
@@ -103,12 +103,6 @@ public class ConditionProviders extends ManagedServices {
}
}
}
if (filter == null) {
pw.print(" mListeners("); pw.print(mListeners.size()); pw.println("):");
for (int i = 0; i < mListeners.size(); i++) {
pw.print(" "); pw.println(mListeners.keyAt(i));
}
}
pw.print(" mSystemConditionProviders: "); pw.println(mSystemConditionProviderNames);
for (int i = 0; i < mSystemConditionProviders.size(); i++) {
mSystemConditionProviders.valueAt(i).dump(pw, filter);
@@ -173,16 +167,12 @@ public class ConditionProviders extends ManagedServices {
}
}
private Condition[] validateConditions(String pkg, Condition[] conditions) {
private Condition[] removeDuplicateConditions(String pkg, Condition[] conditions) {
if (conditions == null || conditions.length == 0) return null;
final int N = conditions.length;
final ArrayMap<Uri, Condition> valid = new ArrayMap<Uri, Condition>(N);
for (int i = 0; i < N; i++) {
final Uri id = conditions[i].id;
if (!Condition.isValidId(id, pkg)) {
Slog.w(TAG, "Ignoring condition from " + pkg + " for invalid id: " + id);
continue;
}
if (valid.containsKey(id)) {
Slog.w(TAG, "Ignoring condition from " + pkg + " for duplicate id: " + id);
continue;
@@ -219,16 +209,9 @@ public class ConditionProviders extends ManagedServices {
synchronized(mMutex) {
if (DEBUG) Slog.d(TAG, "notifyConditions pkg=" + pkg + " info=" + info + " conditions="
+ (conditions == null ? null : Arrays.asList(conditions)));
conditions = validateConditions(pkg, conditions);
conditions = removeDuplicateConditions(pkg, conditions);
if (conditions == null || conditions.length == 0) return;
final int N = conditions.length;
for (IConditionListener listener : mListeners.values()) {
try {
listener.onConditionsReceived(conditions);
} catch (RemoteException e) {
Slog.w(TAG, "Error sending conditions to listener " + listener, e);
}
}
for (int i = 0; i < N; i++) {
final Condition c = conditions[i];
final ConditionRecord r = getRecordLocked(c.id, info.component, true /*create*/);