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

Commit cb64a683 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Noti importance from certain Roles cannot be modified"

parents 5659644e 0c24500a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -315,7 +315,9 @@ package android.app {
  }

  public final class NotificationChannel implements android.os.Parcelable {
    method public boolean isImportanceLockedByCriticalDeviceFunction();
    method public boolean isImportanceLockedByOEM();
    method public void setImportanceLockedByCriticalDeviceFunction(boolean);
    method public void setImportanceLockedByOEM(boolean);
  }

+27 −3
Original line number Diff line number Diff line
@@ -170,6 +170,7 @@ public final class NotificationChannel implements Parcelable {
    private boolean mBlockableSystem = false;
    private boolean mAllowBubbles = DEFAULT_ALLOW_BUBBLE;
    private boolean mImportanceLockedByOEM;
    private boolean mImportanceLockedDefaultApp;

    /**
     * Creates a notification channel.
@@ -652,6 +653,14 @@ public final class NotificationChannel implements Parcelable {
        mImportanceLockedByOEM = locked;
    }

    /**
     * @hide
     */
    @TestApi
    public void setImportanceLockedByCriticalDeviceFunction(boolean locked) {
        mImportanceLockedDefaultApp = locked;
    }

    /**
     * @hide
     */
@@ -660,6 +669,14 @@ public final class NotificationChannel implements Parcelable {
        return mImportanceLockedByOEM;
    }

    /**
     * @hide
     */
    @TestApi
    public boolean isImportanceLockedByCriticalDeviceFunction() {
        return mImportanceLockedDefaultApp;
    }

    /**
     * Returns whether the user has chosen the importance of this channel, either to affirm the
     * initial selection from the app, or changed it to be higher or lower.
@@ -834,6 +851,9 @@ public final class NotificationChannel implements Parcelable {
            out.attribute(null, ATT_ALLOW_BUBBLE, Boolean.toString(canBubble()));
        }

        // mImportanceLockedDefaultApp and mImportanceLockedByOEM have a different source of
        // truth and so aren't written to this xml file

        out.endTag(null, TAG_CHANNEL);
    }

@@ -942,7 +962,8 @@ public final class NotificationChannel implements Parcelable {
        return sb.toString();
    }

    public static final @android.annotation.NonNull Creator<NotificationChannel> CREATOR = new Creator<NotificationChannel>() {
    public static final @android.annotation.NonNull Creator<NotificationChannel> CREATOR =
            new Creator<NotificationChannel>() {
        @Override
        public NotificationChannel createFromParcel(Parcel in) {
            return new NotificationChannel(in);
@@ -983,7 +1004,8 @@ public final class NotificationChannel implements Parcelable {
                && Arrays.equals(mVibration, that.mVibration)
                && Objects.equals(getGroup(), that.getGroup())
                && Objects.equals(getAudioAttributes(), that.getAudioAttributes())
                && mImportanceLockedByOEM == that.mImportanceLockedByOEM;
                && mImportanceLockedByOEM == that.mImportanceLockedByOEM
                && mImportanceLockedDefaultApp == that.mImportanceLockedDefaultApp;
    }

    @Override
@@ -993,7 +1015,7 @@ public final class NotificationChannel implements Parcelable {
                getUserLockedFields(),
                isFgServiceShown(), mVibrationEnabled, mShowBadge, isDeleted(), getGroup(),
                getAudioAttributes(), isBlockableSystem(), mAllowBubbles,
                mImportanceLockedByOEM);
                mImportanceLockedByOEM, mImportanceLockedDefaultApp);
        result = 31 * result + Arrays.hashCode(mVibration);
        return result;
    }
@@ -1022,6 +1044,7 @@ public final class NotificationChannel implements Parcelable {
                + ", mBlockableSystem=" + mBlockableSystem
                + ", mAllowBubbles=" + mAllowBubbles
                + ", mImportanceLockedByOEM=" + mImportanceLockedByOEM
                + ", mImportanceLockedDefaultApp=" + mImportanceLockedDefaultApp
                + '}';
        pw.println(prefix + output);
    }
@@ -1049,6 +1072,7 @@ public final class NotificationChannel implements Parcelable {
                + ", mBlockableSystem=" + mBlockableSystem
                + ", mAllowBubbles=" + mAllowBubbles
                + ", mImportanceLockedByOEM=" + mImportanceLockedByOEM
                + ", mImportanceLockedDefaultApp=" + mImportanceLockedDefaultApp
                + '}';
    }

+3 −0
Original line number Diff line number Diff line
@@ -552,6 +552,9 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
            mEntry.mIsSystemNotification = isSystemNotification(mContext, mStatusBarNotification);
        }

        isNonblockable |= mEntry.channel.isImportanceLockedByOEM();
        isNonblockable |= mEntry.channel.isImportanceLockedByCriticalDeviceFunction();

        if (!isNonblockable && mEntry != null && mEntry.mIsSystemNotification != null) {
            if (mEntry.mIsSystemNotification) {
                if (mEntry.channel != null
+1 −1
Original line number Diff line number Diff line
@@ -212,7 +212,7 @@ public class NotificationTestHelper {
     *
     * @return a notification with no special properties
     */
    private Notification createNotification() {
    public Notification createNotification() {
        return createNotification(false /* isGroupSummary */, null /* groupKey */);
    }

+28 −0
Original line number Diff line number Diff line
@@ -37,7 +37,9 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.app.AppOpsManager;
import android.app.Notification;
import android.app.NotificationChannel;
import android.os.UserHandle;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.testing.TestableLooper.RunWithLooper;
@@ -355,4 +357,30 @@ public class ExpandableNotificationRowTest extends SysuiTestCase {
        mGroupRow.setUserExpanded(true);
        Assert.assertTrue(mGroupRow.isExpanded());
    }

    @Test
    public void testGetIsNonblockable() throws Exception {
        ExpandableNotificationRow row =
                mNotificationTestHelper.createRow(mNotificationTestHelper.createNotification());

        assertFalse(row.getIsNonblockable());
    }

    @Test
    public void testGetIsNonblockable_oemLocked() throws Exception {
        ExpandableNotificationRow row =
                mNotificationTestHelper.createRow(mNotificationTestHelper.createNotification());
        row.getEntry().channel.setImportanceLockedByOEM(true);

        assertTrue(row.getIsNonblockable());
    }

    @Test
    public void testGetIsNonblockable_criticalDeviceFunction() throws Exception {
        ExpandableNotificationRow row =
                mNotificationTestHelper.createRow(mNotificationTestHelper.createNotification());
        row.getEntry().channel.setImportanceLockedByCriticalDeviceFunction(true);

        assertTrue(row.getIsNonblockable());
    }
}
Loading