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

Commit 802c6215 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Move app overlay permission to app level"

parents a034692c 33ab8a0c
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -5730,7 +5730,6 @@ package android.app {
  public final class NotificationChannelGroup implements android.os.Parcelable {
    ctor public NotificationChannelGroup(java.lang.String, java.lang.CharSequence);
    method public boolean canOverlayApps();
    method public android.app.NotificationChannelGroup clone();
    method public int describeContents();
    method public java.util.List<android.app.NotificationChannel> getChannels();
@@ -5738,7 +5737,6 @@ package android.app {
    method public java.lang.String getId();
    method public java.lang.CharSequence getName();
    method public boolean isBlocked();
    method public void setAllowAppOverlay(boolean);
    method public void setDescription(java.lang.String);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.app.NotificationChannelGroup> CREATOR;
@@ -5746,6 +5744,7 @@ package android.app {
  public class NotificationManager {
    method public java.lang.String addAutomaticZenRule(android.app.AutomaticZenRule);
    method public boolean areAppOverlaysAllowed();
    method public boolean areNotificationsEnabled();
    method public boolean canNotifyAsPackage(java.lang.String);
    method public void cancel(int);
+0 −1
Original line number Diff line number Diff line
@@ -182,7 +182,6 @@ package android.app {
    method public int getUserLockedFields();
    method public void lockFields(int);
    method public void setBlocked(boolean);
    field public static final int USER_LOCKED_ALLOW_APP_OVERLAY = 2; // 0x2
  }

  public class NotificationManager {
+4 −0
Original line number Diff line number Diff line
@@ -65,6 +65,10 @@ interface INotificationManager
    boolean areNotificationsEnabled(String pkg);
    int getPackageImportance(String pkg);

    void setAppOverlaysAllowed(String pkg, int uid, boolean allowed);
    boolean areAppOverlaysAllowed(String pkg);
    boolean areAppOverlaysAllowedForPackage(String pkg, int uid);

    void createNotificationChannelGroups(String pkg, in ParceledListSlice channelGroupList);
    void createNotificationChannels(String pkg, in ParceledListSlice channelsList);
    void createNotificationChannelsForPackage(String pkg, int uid, in ParceledListSlice channelsList);
+1 −45
Original line number Diff line number Diff line
@@ -50,20 +50,12 @@ public final class NotificationChannelGroup implements Parcelable {
    private static final String ATT_DESC = "desc";
    private static final String ATT_ID = "id";
    private static final String ATT_BLOCKED = "blocked";
    private static final String ATT_ALLOW_APP_OVERLAY = "app_overlay";
    private static final String ATT_USER_LOCKED = "locked";

    private static final boolean DEFAULT_ALLOW_APP_OVERLAY = true;

    /**
     * @hide
     */
    public static final int USER_LOCKED_BLOCKED_STATE = 0x00000001;
    /**
     * @hide
     */
    @TestApi
    public static final int USER_LOCKED_ALLOW_APP_OVERLAY = 0x00000002;

    /**
     * @see #getId()
@@ -74,7 +66,6 @@ public final class NotificationChannelGroup implements Parcelable {
    private String mDescription;
    private boolean mBlocked;
    private List<NotificationChannel> mChannels = new ArrayList<>();
    private boolean mAllowAppOverlay = DEFAULT_ALLOW_APP_OVERLAY;
    // Bitwise representation of fields that have been changed by the user
    private int mUserLockedFields;

@@ -110,7 +101,6 @@ public final class NotificationChannelGroup implements Parcelable {
        }
        in.readParcelableList(mChannels, NotificationChannel.class.getClassLoader());
        mBlocked = in.readBoolean();
        mAllowAppOverlay = in.readBoolean();
        mUserLockedFields = in.readInt();
    }

@@ -138,7 +128,6 @@ public final class NotificationChannelGroup implements Parcelable {
        }
        dest.writeParcelableList(mChannels, flags);
        dest.writeBoolean(mBlocked);
        dest.writeBoolean(mAllowAppOverlay);
        dest.writeInt(mUserLockedFields);
    }

@@ -180,15 +169,6 @@ public final class NotificationChannelGroup implements Parcelable {
        return mBlocked;
    }

    /**
     * Returns whether notifications posted to this channel group can display outside of the
     * notification shade, in a floating window on top of other apps. These may additionally be
     * blocked at the notification channel level, see {@link NotificationChannel#canOverlayApps()}.
     */
    public boolean canOverlayApps() {
        return mAllowAppOverlay;
    }

    /**
     * Sets the user visible description of this group.
     *
@@ -199,21 +179,6 @@ public final class NotificationChannelGroup implements Parcelable {
        mDescription = getTrimmedString(description);
    }

    /**
     * Sets whether notifications posted to this channel group can appear outside of the
     * notification shade, floating over other apps' content.
     *
     * <p>This value will be ignored for notifications that are posted to channels that do not
     * allow app overlays ({@link NotificationChannel#canOverlayApps()}.
     *
     * <p>Only modifiable before the channel is submitted to
     * {@link NotificationManager#createNotificationChannelGroup(NotificationChannelGroup)}.</p>
     * @see Notification#getAppOverlayIntent()
     */
    public void setAllowAppOverlay(boolean allowAppOverlay) {
        mAllowAppOverlay = allowAppOverlay;
    }

    /**
     * @hide
     */
@@ -266,7 +231,6 @@ public final class NotificationChannelGroup implements Parcelable {
        // Name, id, and importance are set in the constructor.
        setDescription(parser.getAttributeValue(null, ATT_DESC));
        setBlocked(safeBool(parser, ATT_BLOCKED, false));
        setAllowAppOverlay(safeBool(parser, ATT_ALLOW_APP_OVERLAY, DEFAULT_ALLOW_APP_OVERLAY));
    }

    private static boolean safeBool(XmlPullParser parser, String att, boolean defValue) {
@@ -289,9 +253,6 @@ public final class NotificationChannelGroup implements Parcelable {
            out.attribute(null, ATT_DESC, getDescription().toString());
        }
        out.attribute(null, ATT_BLOCKED, Boolean.toString(isBlocked()));
        if (canOverlayApps() != DEFAULT_ALLOW_APP_OVERLAY) {
            out.attribute(null, ATT_ALLOW_APP_OVERLAY, Boolean.toString(canOverlayApps()));
        }
        out.attribute(null, ATT_USER_LOCKED, Integer.toString(mUserLockedFields));

        out.endTag(null, TAG_GROUP);
@@ -307,7 +268,6 @@ public final class NotificationChannelGroup implements Parcelable {
        record.put(ATT_NAME, getName());
        record.put(ATT_DESC, getDescription());
        record.put(ATT_BLOCKED, isBlocked());
        record.put(ATT_ALLOW_APP_OVERLAY, canOverlayApps());
        record.put(ATT_USER_LOCKED, mUserLockedFields);
        return record;
    }
@@ -336,7 +296,6 @@ public final class NotificationChannelGroup implements Parcelable {
        if (o == null || getClass() != o.getClass()) return false;
        NotificationChannelGroup that = (NotificationChannelGroup) o;
        return isBlocked() == that.isBlocked() &&
                mAllowAppOverlay == that.mAllowAppOverlay &&
                mUserLockedFields == that.mUserLockedFields &&
                Objects.equals(getId(), that.getId()) &&
                Objects.equals(getName(), that.getName()) &&
@@ -347,7 +306,7 @@ public final class NotificationChannelGroup implements Parcelable {
    @Override
    public int hashCode() {
        return Objects.hash(getId(), getName(), getDescription(), isBlocked(), getChannels(),
                mAllowAppOverlay, mUserLockedFields);
                mUserLockedFields);
    }

    @Override
@@ -356,7 +315,6 @@ public final class NotificationChannelGroup implements Parcelable {
        cloned.setDescription(getDescription());
        cloned.setBlocked(isBlocked());
        cloned.setChannels(getChannels());
        cloned.setAllowAppOverlay(canOverlayApps());
        cloned.lockFields(mUserLockedFields);
        return cloned;
    }
@@ -369,7 +327,6 @@ public final class NotificationChannelGroup implements Parcelable {
                + ", mDescription=" + (!TextUtils.isEmpty(mDescription) ? "hasDescription " : "")
                + ", mBlocked=" + mBlocked
                + ", mChannels=" + mChannels
                + ", mAllowAppOverlay=" + mAllowAppOverlay
                + ", mUserLockedFields=" + mUserLockedFields
                + '}';
    }
@@ -385,7 +342,6 @@ public final class NotificationChannelGroup implements Parcelable {
        for (NotificationChannel channel : mChannels) {
            channel.writeToProto(proto, NotificationChannelGroupProto.CHANNELS);
        }
        proto.write(NotificationChannelGroupProto.ALLOW_APP_OVERLAY, mAllowAppOverlay);
        proto.end(token);
    }
}
+19 −0
Original line number Diff line number Diff line
@@ -1074,6 +1074,25 @@ public class NotificationManager {
        }
    }


    /**
     * Sets whether notifications posted by this app can appear outside of the
     * notification shade, floating over other apps' content.
     *
     * <p>This value will be ignored for notifications that are posted to channels that do not
     * allow app overlays ({@link NotificationChannel#canOverlayApps()}.
     *
     * @see Notification#getAppOverlayIntent()
     */
    public boolean areAppOverlaysAllowed() {
        INotificationManager service = getService();
        try {
            return service.areAppOverlaysAllowed(mContext.getPackageName());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Checks the ability to modify notification do not disturb policy for the calling package.
     *
Loading