summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJohn Spurlock <jspurlock@google.com>2015-05-08 22:28:49 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-05-08 22:28:51 +0000
commitd89a6b2abc38907a532da7dec073663da5a74e7c (patch)
treed0ba1cec4ea6f69dda965770ca744bbe3b89400c /core
parent5759a8a9cfef08b7f9485c67b07be9ae268dea0a (diff)
parent807749301fcbda892dfc8a5832b19acf7d1cf53b (diff)
downloadframeworks_base-d89a6b2abc38907a532da7dec073663da5a74e7c.zip
frameworks_base-d89a6b2abc38907a532da7dec073663da5a74e7c.tar.gz
frameworks_base-d89a6b2abc38907a532da7dec073663da5a74e7c.tar.bz2
Merge "Zen: Simplify notification policy api, add zenmode api." into mnc-dev
Diffstat (limited to 'core')
-rw-r--r--core/java/android/app/INotificationManager.aidl13
-rw-r--r--core/java/android/app/INotificationManagerCallback.aidl2
-rw-r--r--core/java/android/app/NotificationManager.aidl1
-rw-r--r--core/java/android/app/NotificationManager.java290
-rw-r--r--core/java/android/provider/Settings.java12
-rw-r--r--core/java/android/service/notification/NotificationListenerService.java33
-rw-r--r--core/java/android/service/notification/ZenModeConfig.java6
7 files changed, 226 insertions, 131 deletions
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl
index ac8d5d8..63ff005 100644
--- a/core/java/android/app/INotificationManager.aidl
+++ b/core/java/android/app/INotificationManager.aidl
@@ -75,7 +75,7 @@ interface INotificationManager
void requestInterruptionFilterFromListener(in INotificationListener token, int interruptionFilter);
int getInterruptionFilterFromListener(in INotificationListener token);
void setOnNotificationPostedTrimFromListener(in INotificationListener token, int trim);
- NotificationManager.Policy.Token getPolicyTokenFromListener(in INotificationListener listener);
+ void setInterruptionFilter(String pkg, int interruptionFilter);
ComponentName getEffectsSuppressor();
boolean matchesCallFilter(in Bundle extras);
@@ -87,10 +87,13 @@ interface INotificationManager
oneway void setZenMode(int mode, in Uri conditionId, String reason);
oneway void notifyConditions(String pkg, in IConditionProvider provider, in Condition[] conditions);
oneway void requestZenModeConditions(in IConditionListener callback, int relevance);
- oneway void requestNotificationPolicyToken(String pkg, in INotificationManagerCallback callback);
- boolean isNotificationPolicyTokenValid(String pkg, in NotificationManager.Policy.Token token);
- NotificationManager.Policy getNotificationPolicy(in NotificationManager.Policy.Token token);
- void setNotificationPolicy(in NotificationManager.Policy.Token token, in NotificationManager.Policy policy);
+ oneway void requestNotificationPolicyAccess(String pkg, in INotificationManagerCallback callback);
+ boolean isNotificationPolicyAccessGranted(String pkg);
+ NotificationManager.Policy getNotificationPolicy(String pkg);
+ void setNotificationPolicy(String pkg, in NotificationManager.Policy policy);
+ String[] getPackagesRequestingNotificationPolicyAccess();
+ boolean isNotificationPolicyAccessGrantedForPackage(String pkg);
+ void setNotificationPolicyAccessGranted(String pkg, boolean granted);
byte[] getBackupPayload(int user);
void applyRestore(in byte[] payload, int user);
diff --git a/core/java/android/app/INotificationManagerCallback.aidl b/core/java/android/app/INotificationManagerCallback.aidl
index b9414ca..9929745 100644
--- a/core/java/android/app/INotificationManagerCallback.aidl
+++ b/core/java/android/app/INotificationManagerCallback.aidl
@@ -20,5 +20,5 @@ import android.app.NotificationManager;
/** @hide */
oneway interface INotificationManagerCallback {
- void onPolicyToken(in NotificationManager.Policy.Token token);
+ void onPolicyRequestResult(boolean granted);
}
diff --git a/core/java/android/app/NotificationManager.aidl b/core/java/android/app/NotificationManager.aidl
index 8380b8d..a5d5671 100644
--- a/core/java/android/app/NotificationManager.aidl
+++ b/core/java/android/app/NotificationManager.aidl
@@ -17,4 +17,3 @@
package android.app;
parcelable NotificationManager.Policy;
-parcelable NotificationManager.Policy.Token; \ No newline at end of file
diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java
index 0a59026..e4bbe27 100644
--- a/core/java/android/app/NotificationManager.java
+++ b/core/java/android/app/NotificationManager.java
@@ -20,7 +20,6 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SdkConstant;
import android.app.Notification.Builder;
-import android.app.NotificationManager.Policy.Token;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ParceledListSlice;
@@ -38,6 +37,7 @@ import android.provider.Settings.Global;
import android.service.notification.IConditionListener;
import android.service.notification.StatusBarNotification;
import android.service.notification.ZenModeConfig;
+import android.util.ArraySet;
import android.util.Log;
import java.util.Objects;
@@ -107,6 +107,43 @@ public class NotificationManager
public static final String ACTION_NOTIFICATION_POLICY_CHANGED
= "android.app.action.NOTIFICATION_POLICY_CHANGED";
+ /**
+ * Intent that is broadcast when the state of getCurrentInterruptionFilter() changes.
+ * This broadcast is only sent to registered receivers.
+ */
+ @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION)
+ public static final String ACTION_INTERRUPTION_FILTER_CHANGED
+ = "android.app.action.INTERRUPTION_FILTER_CHANGED";
+
+ /**
+ * {@link #getCurrentInterruptionFilter() Interruption filter} constant -
+ * Normal interruption filter.
+ */
+ public static final int INTERRUPTION_FILTER_ALL = 1;
+
+ /**
+ * {@link #getCurrentInterruptionFilter() Interruption filter} constant -
+ * Priority interruption filter.
+ */
+ public static final int INTERRUPTION_FILTER_PRIORITY = 2;
+
+ /**
+ * {@link #getCurrentInterruptionFilter() Interruption filter} constant -
+ * No interruptions filter.
+ */
+ public static final int INTERRUPTION_FILTER_NONE = 3;
+
+ /**
+ * {@link #getCurrentInterruptionFilter() Interruption filter} constant -
+ * Alarms only interruption filter.
+ */
+ public static final int INTERRUPTION_FILTER_ALARMS = 4;
+
+ /** {@link #getCurrentInterruptionFilter() Interruption filter} constant - returned when
+ * the value is unavailable for any reason.
+ */
+ public static final int INTERRUPTION_FILTER_UNKNOWN = 0;
+
private static INotificationManager sService;
/** @hide */
@@ -357,29 +394,29 @@ public class NotificationManager
}
/**
- * Requests a notification policy token for the calling package.
+ * Requests the ability to read/modify notification policy for the calling package.
*
- * @param callback required, used to receive the granted token or the deny signal.
+ * @param callback required, used to receive the granted or the denied signal.
* @param handler The handler used when receiving the result.
* If null, the current thread is used.
*/
- public void requestNotificationPolicyToken(@NonNull final Policy.Token.RequestCallback callback,
+ public void requestPolicyAccess(@NonNull final NotificationPolicyAccessRequestCallback callback,
@Nullable Handler handler) {
checkRequired("callback", callback);
final Handler h = handler != null ? handler : new Handler();
INotificationManager service = getService();
try {
- service.requestNotificationPolicyToken(mContext.getOpPackageName(),
+ service.requestNotificationPolicyAccess(mContext.getOpPackageName(),
new INotificationManagerCallback.Stub() {
@Override
- public void onPolicyToken(final Token token) throws RemoteException {
+ public void onPolicyRequestResult(final boolean granted) throws RemoteException {
h.post(new Runnable() {
@Override
public void run() {
- if (token != null) {
- callback.onTokenGranted(token);
+ if (granted) {
+ callback.onAccessGranted();
} else {
- callback.onTokenDenied();
+ callback.onAccessDenied();
}
}
});
@@ -389,16 +426,38 @@ public class NotificationManager
}
}
+ /** Callback for receiving the result of a policy access request. */
+ public static abstract class NotificationPolicyAccessRequestCallback {
+ /**
+ * Received if the request was granted for this package.
+ */
+ public abstract void onAccessGranted();
+
+ /**
+ * Received if the request was denied for this package.
+ */
+ public abstract void onAccessDenied();
+ }
+
/**
- * Checks a given notification policy token.
+ * Checks the ability to read/modify notification policy for the calling package.
*
- * Returns true if the token is still valid for managing policy.
+ * Returns true if the calling package can read/modify notification policy.
*/
- public boolean isNotificationPolicyTokenValid(@NonNull Policy.Token token) {
- if (token == null) return false;
+ public boolean isNotificationPolicyAccessGranted() {
INotificationManager service = getService();
try {
- return service.isNotificationPolicyTokenValid(mContext.getOpPackageName(), token);
+ return service.isNotificationPolicyAccessGranted(mContext.getOpPackageName());
+ } catch (RemoteException e) {
+ }
+ return false;
+ }
+
+ /** @hide */
+ public boolean isNotificationPolicyAccessGrantedForPackage(String pkg) {
+ INotificationManager service = getService();
+ try {
+ return service.isNotificationPolicyAccessGrantedForPackage(pkg);
} catch (RemoteException e) {
}
return false;
@@ -407,13 +466,13 @@ public class NotificationManager
/**
* Gets the current notification policy.
*
- * @param token A valid notification policy token is required to access the current policy.
+ * <p>
+ * Only available if policy access is granted.
*/
- public Policy getNotificationPolicy(@NonNull Policy.Token token) {
- checkRequired("token", token);
+ public Policy getNotificationPolicy() {
INotificationManager service = getService();
try {
- return service.getNotificationPolicy(token);
+ return service.getNotificationPolicy(mContext.getOpPackageName());
} catch (RemoteException e) {
}
return null;
@@ -422,19 +481,46 @@ public class NotificationManager
/**
* Sets the current notification policy.
*
- * @param token A valid notification policy token is required to modify the current policy.
+ * <p>
+ * Only available if policy access is granted.
+ *
* @param policy The new desired policy.
*/
- public void setNotificationPolicy(@NonNull Policy.Token token, @NonNull Policy policy) {
- checkRequired("token", token);
+ public void setNotificationPolicy(@NonNull Policy policy) {
checkRequired("policy", policy);
INotificationManager service = getService();
try {
- service.setNotificationPolicy(token, policy);
+ service.setNotificationPolicy(mContext.getOpPackageName(), policy);
+ } catch (RemoteException e) {
+ }
+ }
+
+ /** @hide */
+ public void setNotificationPolicyAccessGranted(String pkg, boolean granted) {
+ INotificationManager service = getService();
+ try {
+ service.setNotificationPolicyAccessGranted(pkg, granted);
} catch (RemoteException e) {
}
}
+ /** @hide */
+ public ArraySet<String> getPackagesRequestingNotificationPolicyAccess() {
+ INotificationManager service = getService();
+ try {
+ final String[] pkgs = service.getPackagesRequestingNotificationPolicyAccess();
+ if (pkgs != null && pkgs.length > 0) {
+ final ArraySet<String> rt = new ArraySet<>(pkgs.length);
+ for (int i = 0; i < pkgs.length; i++) {
+ rt.add(pkgs[i]);
+ }
+ return rt;
+ }
+ } catch (RemoteException e) {
+ }
+ return new ArraySet<String>();
+ }
+
private Context mContext;
private static void checkRequired(String name, Object value) {
@@ -477,24 +563,30 @@ public class NotificationManager
/** Notification categories to prioritize. Bitmask of PRIORITY_CATEGORY_* constants. */
public final int priorityCategories;
- /** Notification senders to prioritize. One of:
+ /** Notification senders to prioritize for calls. One of:
+ * PRIORITY_SENDERS_ANY, PRIORITY_SENDERS_CONTACTS, PRIORITY_SENDERS_STARRED */
+ public final int priorityCallSenders;
+
+ /** Notification senders to prioritize for messages. One of:
* PRIORITY_SENDERS_ANY, PRIORITY_SENDERS_CONTACTS, PRIORITY_SENDERS_STARRED */
- public final int prioritySenders;
+ public final int priorityMessageSenders;
- public Policy(int priorityCategories, int prioritySenders) {
+ public Policy(int priorityCategories, int priorityCallSenders, int priorityMessageSenders) {
this.priorityCategories = priorityCategories;
- this.prioritySenders = prioritySenders;
+ this.priorityCallSenders = priorityCallSenders;
+ this.priorityMessageSenders = priorityMessageSenders;
}
/** @hide */
public Policy(Parcel source) {
- this(source.readInt(), source.readInt());
+ this(source.readInt(), source.readInt(), source.readInt());
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(priorityCategories);
- dest.writeInt(prioritySenders);
+ dest.writeInt(priorityCallSenders);
+ dest.writeInt(priorityMessageSenders);
}
@Override
@@ -504,7 +596,7 @@ public class NotificationManager
@Override
public int hashCode() {
- return Objects.hash(priorityCategories, prioritySenders);
+ return Objects.hash(priorityCategories, priorityCallSenders, priorityMessageSenders);
}
@Override
@@ -513,14 +605,16 @@ public class NotificationManager
if (o == this) return true;
final Policy other = (Policy) o;
return other.priorityCategories == priorityCategories
- && other.prioritySenders == prioritySenders;
+ && other.priorityCallSenders == priorityCallSenders
+ && other.priorityMessageSenders == priorityMessageSenders;
}
@Override
public String toString() {
return "NotificationManager.Policy["
+ "priorityCategories=" + priorityCategoriesToString(priorityCategories)
- + ",prioritySenders=" + prioritySendersToString(prioritySenders)
+ + ",priorityCallSenders=" + prioritySendersToString(priorityCallSenders)
+ + ",priorityMessageSenders=" + prioritySendersToString(priorityMessageSenders)
+ "]";
}
@@ -574,75 +668,6 @@ public class NotificationManager
}
};
- /**
- * Represents a client-specific token required to manage notification policy.
- */
- public static class Token implements Parcelable {
- private final IBinder mBinder;
-
- /** @hide */
- public Token(IBinder binder) {
- if (binder == null) throw new IllegalArgumentException("Binder required for token");
- mBinder = binder;
- }
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(mBinder);
- }
-
- @Override
- public boolean equals(Object o) {
- if (!(o instanceof Token)) return false;
- if (o == this) return true;
- final Token other = (Token) o;
- return Objects.equals(other.mBinder, mBinder);
- }
-
- @Override
- public String toString() {
- return String.format("NotificationManager.Token[0x%08x]",
- System.identityHashCode(mBinder));
- }
-
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeStrongBinder(mBinder);
- }
-
- public static final Parcelable.Creator<Token> CREATOR
- = new Parcelable.Creator<Token>() {
- @Override
- public Token createFromParcel(Parcel in) {
- return new Token(in.readStrongBinder());
- }
-
- @Override
- public Token[] newArray(int size) {
- return new Token[size];
- }
- };
-
- /** Callback for receiving the result of a token request. */
- public static abstract class RequestCallback {
- /**
- * Received if the request was granted for this package.
- *
- * @param token can be used to manage notification policy.
- */
- public abstract void onTokenGranted(Policy.Token token);
-
- /**
- * Received if the request was denied for this package.
- */
- public abstract void onTokenDenied();
- }
- }
}
/**
@@ -671,4 +696,69 @@ public class NotificationManager
}
return new StatusBarNotification[0];
}
+
+ /**
+ * Gets the current notification interruption filter.
+ *
+ * <p>
+ * The interruption filter defines which notifications are allowed to interrupt the user
+ * (e.g. via sound &amp; vibration) and is applied globally.
+ * @return One of the INTERRUPTION_FILTER_ constants, or INTERRUPTION_FILTER_UNKNOWN when
+ * unavailable.
+ *
+ * <p>
+ * Only available if policy access is granted.
+ */
+ public final int getCurrentInterruptionFilter() {
+ final INotificationManager service = getService();
+ try {
+ return zenModeToInterruptionFilter(service.getZenMode());
+ } catch (RemoteException e) {
+ Log.e(TAG, "Unable to talk to notification manager. Woe!", e);
+ }
+ return INTERRUPTION_FILTER_UNKNOWN;
+ }
+
+ /**
+ * Sets the current notification interruption filter.
+ *
+ * <p>
+ * The interruption filter defines which notifications are allowed to interrupt the user
+ * (e.g. via sound &amp; vibration) and is applied globally.
+ * @return One of the INTERRUPTION_FILTER_ constants, or INTERRUPTION_FILTER_UNKNOWN when
+ * unavailable.
+ *
+ * <p>
+ * Only available if policy access is granted.
+ */
+ public final void setInterruptionFilter(int interruptionFilter) {
+ final INotificationManager service = getService();
+ try {
+ service.setInterruptionFilter(mContext.getOpPackageName(), interruptionFilter);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Unable to talk to notification manager. Woe!", e);
+ }
+ }
+
+ /** @hide */
+ public static int zenModeToInterruptionFilter(int zen) {
+ switch (zen) {
+ case Global.ZEN_MODE_OFF: return INTERRUPTION_FILTER_ALL;
+ case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS: return INTERRUPTION_FILTER_PRIORITY;
+ case Global.ZEN_MODE_ALARMS: return INTERRUPTION_FILTER_ALARMS;
+ case Global.ZEN_MODE_NO_INTERRUPTIONS: return INTERRUPTION_FILTER_NONE;
+ default: return INTERRUPTION_FILTER_UNKNOWN;
+ }
+ }
+
+ /** @hide */
+ public static int zenModeFromInterruptionFilter(int interruptionFilter, int defValue) {
+ switch (interruptionFilter) {
+ case INTERRUPTION_FILTER_ALL: return Global.ZEN_MODE_OFF;
+ case INTERRUPTION_FILTER_PRIORITY: return Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS;
+ case INTERRUPTION_FILTER_ALARMS: return Global.ZEN_MODE_ALARMS;
+ case INTERRUPTION_FILTER_NONE: return Global.ZEN_MODE_NO_INTERRUPTIONS;
+ default: return defValue;
+ }
+ }
}
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 7c3c11b..dc70d7b 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -809,6 +809,18 @@ public final class Settings {
= "android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS";
/**
+ * Activity Action: Show Do Not Disturb access settings.
+ * <p>
+ * In some cases, a matching Activity may not exist, so ensure you safeguard against this.
+ * <p>
+ * Input: Nothing.
+ * <p>
+ * Output: Nothing.
+ */
+ @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
+ public static final String ACTION_ZEN_ACCESS_SETTINGS = "android.settings.ZEN_ACCESS_SETTINGS";
+
+ /**
* @hide
*/
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
diff --git a/core/java/android/service/notification/NotificationListenerService.java b/core/java/android/service/notification/NotificationListenerService.java
index 35b8819..7956a3f 100644
--- a/core/java/android/service/notification/NotificationListenerService.java
+++ b/core/java/android/service/notification/NotificationListenerService.java
@@ -21,7 +21,7 @@ import android.annotation.SdkConstant;
import android.app.INotificationManager;
import android.app.Notification;
import android.app.Notification.Builder;
-import android.app.NotificationManager.Policy;
+import android.app.NotificationManager;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
@@ -64,25 +64,29 @@ public abstract class NotificationListenerService extends Service {
* {@link #getCurrentInterruptionFilter() Interruption filter} constant -
* Normal interruption filter.
*/
- public static final int INTERRUPTION_FILTER_ALL = 1;
+ public static final int INTERRUPTION_FILTER_ALL
+ = NotificationManager.INTERRUPTION_FILTER_ALL;
/**
* {@link #getCurrentInterruptionFilter() Interruption filter} constant -
* Priority interruption filter.
*/
- public static final int INTERRUPTION_FILTER_PRIORITY = 2;
+ public static final int INTERRUPTION_FILTER_PRIORITY
+ = NotificationManager.INTERRUPTION_FILTER_PRIORITY;
/**
* {@link #getCurrentInterruptionFilter() Interruption filter} constant -
* No interruptions filter.
*/
- public static final int INTERRUPTION_FILTER_NONE = 3;
+ public static final int INTERRUPTION_FILTER_NONE
+ = NotificationManager.INTERRUPTION_FILTER_NONE;
/**
* {@link #getCurrentInterruptionFilter() Interruption filter} constant -
* Alarms only interruption filter.
*/
- public static final int INTERRUPTION_FILTER_ALARMS = 4;
+ public static final int INTERRUPTION_FILTER_ALARMS
+ = NotificationManager.INTERRUPTION_FILTER_ALARMS;
/** {@link #getCurrentInterruptionFilter() Interruption filter} constant - returned when
* the value is unavailable for any reason. For example, before the notification listener
@@ -90,7 +94,8 @@ public abstract class NotificationListenerService extends Service {
*
* {@see #onListenerConnected()}
*/
- public static final int INTERRUPTION_FILTER_UNKNOWN = 0;
+ public static final int INTERRUPTION_FILTER_UNKNOWN
+ = NotificationManager.INTERRUPTION_FILTER_UNKNOWN;
/** {@link #getCurrentListenerHints() Listener hints} constant - the primary device UI
* should disable notification sound, vibrating and other visual or aural effects.
@@ -516,22 +521,6 @@ public abstract class NotificationListenerService extends Service {
}
/**
- * Gets the notification policy token associated with this listener.
- *
- * <p>
- * Returns null if this listener is not currently active.
- */
- public final Policy.Token getNotificationPolicyToken() {
- if (!isBound()) return null;
- try {
- return getNotificationInterface().getPolicyTokenFromListener(mWrapper);
- } catch (android.os.RemoteException ex) {
- Log.v(TAG, "Unable to contact notification manager", ex);
- return null;
- }
- }
-
- /**
* Sets the desired {@link #getCurrentListenerHints() listener hints}.
*
* <p>
diff --git a/core/java/android/service/notification/ZenModeConfig.java b/core/java/android/service/notification/ZenModeConfig.java
index 26bd10f..20b8cbe 100644
--- a/core/java/android/service/notification/ZenModeConfig.java
+++ b/core/java/android/service/notification/ZenModeConfig.java
@@ -538,7 +538,7 @@ public class ZenModeConfig implements Parcelable {
}
priorityCallSenders = sourceToPrioritySenders(allowCallsFrom, priorityCallSenders);
priorityMessageSenders = sourceToPrioritySenders(allowMessagesFrom, priorityMessageSenders);
- return new Policy(priorityCategories, priorityCallSenders);
+ return new Policy(priorityCategories, priorityCallSenders, priorityMessageSenders);
}
private static int sourceToPrioritySenders(int source, int def) {
@@ -567,7 +567,9 @@ public class ZenModeConfig implements Parcelable {
allowReminders = (policy.priorityCategories & Policy.PRIORITY_CATEGORY_REMINDERS) != 0;
allowRepeatCallers = (policy.priorityCategories & Policy.PRIORITY_CATEGORY_REPEAT_CALLERS)
!= 0;
- allowCallsFrom = prioritySendersToSource(policy.prioritySenders, allowCallsFrom);
+ allowCallsFrom = prioritySendersToSource(policy.priorityCallSenders, allowCallsFrom);
+ allowMessagesFrom = prioritySendersToSource(policy.priorityMessageSenders,
+ allowMessagesFrom);
}
public static Condition toTimeCondition(Context context, int minutesFromNow, int userHandle) {