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

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

Add Notification channels

In this iteration:
-Every app gets a default channel that notifications will be posted
to if they don't specify a channel themselves. The default channel
inherits app-wide settings on upgrade.
-Apps can create new channels without user approval, but apps
cannot change the name of a channel once created, nor can they ever
set the importance.
- When a notification is posted:
  - If the channel is marked as 'vibrates', vibration will be
    applied to notifications that lack a vibration. unlike the default
    notification flag, notifications will retain their custom vibration
    if given
  - Same with sound and lights
  - A notification's importance is the min of the app and channel
    importance
  - A notification can bypass dnd if: either the app or channel settings
    say it can
  - A notification's show on lockscreen setting comes from the app first,
    and the channel second if the app has no preference

Tests: in cl. also there's a cl for cts and a test app.

Change-Id: I630f99df655800b00586dcfab538d320d04fe0f0
parent 3cece220
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -4923,6 +4923,7 @@ package android.app {
    method public int describeContents();
    method public java.lang.String getGroup();
    method public android.graphics.drawable.Icon getLargeIcon();
    method public java.lang.String getNotificationChannel();
    method public android.graphics.drawable.Icon getSmallIcon();
    method public java.lang.String getSortKey();
    method public void writeToParcel(android.os.Parcel, int);
@@ -5111,6 +5112,7 @@ package android.app {
    method public android.app.Notification.Builder setActions(android.app.Notification.Action...);
    method public android.app.Notification.Builder setAutoCancel(boolean);
    method public android.app.Notification.Builder setCategory(java.lang.String);
    method public android.app.Notification.Builder setChannel(java.lang.String);
    method public android.app.Notification.Builder setChronometerCountDown(boolean);
    method public android.app.Notification.Builder setColor(int);
    method public deprecated android.app.Notification.Builder setContent(android.widget.RemoteViews);
@@ -5306,17 +5308,40 @@ package android.app {
    field public static final int UNSET_ACTION_INDEX = -1; // 0xffffffff
  }
  public final class NotificationChannel implements android.os.Parcelable {
    ctor public NotificationChannel(java.lang.String, java.lang.CharSequence);
    ctor protected NotificationChannel(android.os.Parcel);
    method public boolean canBypassDnd();
    method public int describeContents();
    method public android.net.Uri getDefaultRingtone();
    method public java.lang.String getId();
    method public int getImportance();
    method public java.lang.CharSequence getName();
    method public void setDefaultRingtone(android.net.Uri);
    method public void setLights(boolean);
    method public void setVibration(boolean);
    method public boolean shouldShowLights();
    method public boolean shouldVibrate();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.app.NotificationChannel> CREATOR;
    field public static final java.lang.String DEFAULT_CHANNEL_ID = "miscellaneous";
  }
  public class NotificationManager {
    method public java.lang.String addAutomaticZenRule(android.app.AutomaticZenRule);
    method public boolean areNotificationsEnabled();
    method public void cancel(int);
    method public void cancel(java.lang.String, int);
    method public void cancelAll();
    method public void createNotificationChannel(android.app.NotificationChannel);
    method public void deleteNotificationChannel(java.lang.String);
    method public android.service.notification.StatusBarNotification[] getActiveNotifications();
    method public android.app.AutomaticZenRule getAutomaticZenRule(java.lang.String);
    method public java.util.Map<java.lang.String, android.app.AutomaticZenRule> getAutomaticZenRules();
    method public final int getCurrentInterruptionFilter();
    method public int getImportance();
    method public android.app.NotificationChannel getNotificationChannel(java.lang.String);
    method public java.util.List<android.app.NotificationChannel> getNotificationChannels();
    method public android.app.NotificationManager.Policy getNotificationPolicy();
    method public boolean isNotificationPolicyAccessGranted();
    method public void notify(int, android.app.Notification);
@@ -5325,6 +5350,7 @@ package android.app {
    method public final void setInterruptionFilter(int);
    method public void setNotificationPolicy(android.app.NotificationManager.Policy);
    method public boolean updateAutomaticZenRule(java.lang.String, android.app.AutomaticZenRule);
    method public void updateNotificationChannel(android.app.NotificationChannel);
    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_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";
+35 −0
Original line number Diff line number Diff line
@@ -5068,6 +5068,7 @@ package android.app {
    method public int describeContents();
    method public java.lang.String getGroup();
    method public android.graphics.drawable.Icon getLargeIcon();
    method public java.lang.String getNotificationChannel();
    method public android.graphics.drawable.Icon getSmallIcon();
    method public java.lang.String getSortKey();
    method public void writeToParcel(android.os.Parcel, int);
@@ -5258,6 +5259,7 @@ package android.app {
    method public android.app.Notification.Builder setActions(android.app.Notification.Action...);
    method public android.app.Notification.Builder setAutoCancel(boolean);
    method public android.app.Notification.Builder setCategory(java.lang.String);
    method public android.app.Notification.Builder setChannel(java.lang.String);
    method public android.app.Notification.Builder setChronometerCountDown(boolean);
    method public android.app.Notification.Builder setColor(int);
    method public deprecated android.app.Notification.Builder setContent(android.widget.RemoteViews);
@@ -5453,17 +5455,48 @@ package android.app {
    field public static final int UNSET_ACTION_INDEX = -1; // 0xffffffff
  }
  public final class NotificationChannel implements android.os.Parcelable {
    ctor public NotificationChannel(java.lang.String, java.lang.CharSequence);
    ctor protected NotificationChannel(android.os.Parcel);
    method public boolean canBypassDnd();
    method public int describeContents();
    method public android.net.Uri getDefaultRingtone();
    method public java.lang.String getId();
    method public int getImportance();
    method public int getLockscreenVisibility();
    method public java.lang.CharSequence getName();
    method public void populateFromXml(org.xmlpull.v1.XmlPullParser);
    method public void setBypassDnd(boolean);
    method public void setDefaultRingtone(android.net.Uri);
    method public void setImportance(int);
    method public void setLights(boolean);
    method public void setLockscreenVisibility(int);
    method public void setName(java.lang.CharSequence);
    method public void setVibration(boolean);
    method public boolean shouldShowLights();
    method public boolean shouldVibrate();
    method public org.json.JSONObject toJson() throws org.json.JSONException;
    method public void writeToParcel(android.os.Parcel, int);
    method public void writeXml(org.xmlpull.v1.XmlSerializer) throws java.io.IOException;
    field public static final android.os.Parcelable.Creator<android.app.NotificationChannel> CREATOR;
    field public static final java.lang.String DEFAULT_CHANNEL_ID = "miscellaneous";
  }
  public class NotificationManager {
    method public java.lang.String addAutomaticZenRule(android.app.AutomaticZenRule);
    method public boolean areNotificationsEnabled();
    method public void cancel(int);
    method public void cancel(java.lang.String, int);
    method public void cancelAll();
    method public void createNotificationChannel(android.app.NotificationChannel);
    method public void deleteNotificationChannel(java.lang.String);
    method public android.service.notification.StatusBarNotification[] getActiveNotifications();
    method public android.app.AutomaticZenRule getAutomaticZenRule(java.lang.String);
    method public java.util.Map<java.lang.String, android.app.AutomaticZenRule> getAutomaticZenRules();
    method public final int getCurrentInterruptionFilter();
    method public int getImportance();
    method public android.app.NotificationChannel getNotificationChannel(java.lang.String);
    method public java.util.List<android.app.NotificationChannel> getNotificationChannels();
    method public android.app.NotificationManager.Policy getNotificationPolicy();
    method public boolean isNotificationPolicyAccessGranted();
    method public void notify(int, android.app.Notification);
@@ -5472,6 +5505,7 @@ package android.app {
    method public final void setInterruptionFilter(int);
    method public void setNotificationPolicy(android.app.NotificationManager.Policy);
    method public boolean updateAutomaticZenRule(java.lang.String, android.app.AutomaticZenRule);
    method public void updateNotificationChannel(android.app.NotificationChannel);
    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_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";
@@ -37649,6 +37683,7 @@ package android.service.notification {
    method public void onNotificationVisibilityChanged(java.lang.String, long, boolean);
    field public static final int REASON_APP_CANCEL = 8; // 0x8
    field public static final int REASON_APP_CANCEL_ALL = 9; // 0x9
    field public static final int REASON_CHANNEL_BANNED = 17; // 0x11
    field public static final int REASON_DELEGATE_CANCEL = 2; // 0x2
    field public static final int REASON_DELEGATE_CANCEL_ALL = 3; // 0x3
    field public static final int REASON_DELEGATE_CLICK = 1; // 0x1
+26 −0
Original line number Diff line number Diff line
@@ -4926,6 +4926,7 @@ package android.app {
    method public int describeContents();
    method public java.lang.String getGroup();
    method public android.graphics.drawable.Icon getLargeIcon();
    method public java.lang.String getNotificationChannel();
    method public android.graphics.drawable.Icon getSmallIcon();
    method public java.lang.String getSortKey();
    method public void writeToParcel(android.os.Parcel, int);
@@ -5114,6 +5115,7 @@ package android.app {
    method public android.app.Notification.Builder setActions(android.app.Notification.Action...);
    method public android.app.Notification.Builder setAutoCancel(boolean);
    method public android.app.Notification.Builder setCategory(java.lang.String);
    method public android.app.Notification.Builder setChannel(java.lang.String);
    method public android.app.Notification.Builder setChronometerCountDown(boolean);
    method public android.app.Notification.Builder setColor(int);
    method public deprecated android.app.Notification.Builder setContent(android.widget.RemoteViews);
@@ -5309,17 +5311,40 @@ package android.app {
    field public static final int UNSET_ACTION_INDEX = -1; // 0xffffffff
  }
  public final class NotificationChannel implements android.os.Parcelable {
    ctor public NotificationChannel(java.lang.String, java.lang.CharSequence);
    ctor protected NotificationChannel(android.os.Parcel);
    method public boolean canBypassDnd();
    method public int describeContents();
    method public android.net.Uri getDefaultRingtone();
    method public java.lang.String getId();
    method public int getImportance();
    method public java.lang.CharSequence getName();
    method public void setDefaultRingtone(android.net.Uri);
    method public void setLights(boolean);
    method public void setVibration(boolean);
    method public boolean shouldShowLights();
    method public boolean shouldVibrate();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.app.NotificationChannel> CREATOR;
    field public static final java.lang.String DEFAULT_CHANNEL_ID = "miscellaneous";
  }
  public class NotificationManager {
    method public java.lang.String addAutomaticZenRule(android.app.AutomaticZenRule);
    method public boolean areNotificationsEnabled();
    method public void cancel(int);
    method public void cancel(java.lang.String, int);
    method public void cancelAll();
    method public void createNotificationChannel(android.app.NotificationChannel);
    method public void deleteNotificationChannel(java.lang.String);
    method public android.service.notification.StatusBarNotification[] getActiveNotifications();
    method public android.app.AutomaticZenRule getAutomaticZenRule(java.lang.String);
    method public java.util.Map<java.lang.String, android.app.AutomaticZenRule> getAutomaticZenRules();
    method public final int getCurrentInterruptionFilter();
    method public int getImportance();
    method public android.app.NotificationChannel getNotificationChannel(java.lang.String);
    method public java.util.List<android.app.NotificationChannel> getNotificationChannels();
    method public android.app.NotificationManager.Policy getNotificationPolicy();
    method public boolean isNotificationPolicyAccessGranted();
    method public void notify(int, android.app.Notification);
@@ -5328,6 +5353,7 @@ package android.app {
    method public final void setInterruptionFilter(int);
    method public void setNotificationPolicy(android.app.NotificationManager.Policy);
    method public boolean updateAutomaticZenRule(java.lang.String, android.app.AutomaticZenRule);
    method public void updateNotificationChannel(android.app.NotificationChannel);
    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_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";
+10 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.app;

import android.app.ITransientNotification;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.ComponentName;
import android.content.Intent;
@@ -57,6 +58,15 @@ interface INotificationManager
    int getImportance(String pkg, int uid);
    int getPackageImportance(String pkg);

    void createNotificationChannel(String pkg, in NotificationChannel channel);
    void updateNotificationChannel(String pkg, in NotificationChannel channel);
    void updateNotificationChannelForPackage(String pkg, int uid, in NotificationChannel channel);
    NotificationChannel getNotificationChannel(String pkg, String channelId);
    NotificationChannel getNotificationChannelForPackage(String pkg, int uid, String channelId);
    void deleteNotificationChannel(String pkg, String channelId);
    ParceledListSlice getNotificationChannels(String pkg);
    ParceledListSlice getNotificationChannelsForPackage(String pkg, int uid);

    // TODO: Remove this when callers have been migrated to the equivalent
    // INotificationListener method.
    StatusBarNotification[] getActiveNotifications(String callingPkg);
+0 −1
Original line number Diff line number Diff line
@@ -17,4 +17,3 @@
package android.app;

parcelable Notification;
parcelable Notification.Topic;
Loading