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

Commit e8663a4b authored by Jeff DeCew's avatar Jeff DeCew
Browse files

[RONs] Create a flag for MetricStyle

Flag: android.app.api_metric_style
Bug: 415828647
Test: n/a
Change-Id: I084d82d86ce48eaeaa4d2f2d93e52f6efc3b2382
parent dbc97877
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -6980,6 +6980,10 @@ package android.app {
    method public android.app.Notification.MessagingStyle.Message setData(String, android.net.Uri);
  }
  @FlaggedApi("android.app.api_metric_style") public static class Notification.MetricStyle extends android.app.Notification.Style {
    ctor public Notification.MetricStyle();
  }
  @FlaggedApi("android.app.api_rich_ongoing") public static class Notification.ProgressStyle extends android.app.Notification.Style {
    ctor public Notification.ProgressStyle();
    method @NonNull public android.app.Notification.ProgressStyle addProgressPoint(@NonNull android.app.Notification.ProgressStyle.Point);
+89 −0
Original line number Diff line number Diff line
@@ -813,6 +813,10 @@ public class Notification implements Parcelable
            return style.getClass() == ProgressStyle.class;
        }
        if (Flags.apiMetricStyle()) {
            return style.getClass() == MetricStyle.class;
        }
        return false;
    }
@@ -3298,6 +3302,7 @@ public class Notification implements Parcelable
        return notificationStyle == null
                || BigTextStyle.class.equals(notificationStyle)
                || CallStyle.class.equals(notificationStyle)
                || MetricStyle.class.equals(notificationStyle)
                || ProgressStyle.class.equals(notificationStyle);
    }
@@ -8330,6 +8335,11 @@ public class Notification implements Parcelable
                return ProgressStyle.class;
            }
        }
        if (Flags.apiMetricStyle()) {
            if (templateClass.equals(MetricStyle.class.getName())) {
                return MetricStyle.class;
            }
        }
        return null;
    }
@@ -11463,6 +11473,85 @@ public class Notification implements Parcelable
        }
    }
    /**
     * A notification style which shows up to 3 metrics when expanded.
     */
    @FlaggedApi(Flags.FLAG_API_METRIC_STYLE)
    public static class MetricStyle extends Notification.Style {
        // TODO(b/415828647): Implement this class
        /** @hide */
        @Override
        public boolean areNotificationsVisiblyDifferent(Style other) {
            if (other == null || getClass() != other.getClass()) {
                return true;
            }
            // TODO(b/415828647): Implement for MetricStyle
            return false;
        }
        /** @hide */
        @Override
        public void purgeResources() {
            super.purgeResources();
            // TODO(b/415828647): Implement for MetricStyle (or delete if no image APIs)
        }
        /** @hide */
        @Override
        public void reduceImageSizes(Context context) {
            super.reduceImageSizes(context);
            // TODO(b/415828647): Implement for MetricStyle (or delete if no image APIs)
        }
        /** @hide */
        @Override
        public void addExtras(Bundle extras) {
            super.addExtras(extras);
            // TODO(b/415828647): Implement for MetricStyle
        }
        /** @hide */
        @Override
        protected void restoreFromExtras(Bundle extras) {
            super.restoreFromExtras(extras);
            // TODO(b/415828647): Implement for MetricStyle
        }
        /** @hide */
        @Override
        public boolean displayCustomViewInline() {
            // This is a lie; True is returned for metric notifications to make sure
            // that the custom view is not used instead of the template, but it will not
            // actually be included.
            return true;
        }
        /** @hide */
        @Override
        public RemoteViews makeContentView() {
            return null;
            // TODO(b/415828647): Implement for MetricStyle
            // Remember: Add new layout resources to isStandardLayout()
        }
        /** @hide */
        @Override
        public RemoteViews makeHeadsUpContentView() {
            return null;
            // TODO(b/415828647): Implement for MetricStyle
            // Remember: Add new layout resources to isStandardLayout()
        }
        /** @hide */
        @Override
        public RemoteViews makeExpandedContentView() {
            return null;
            // TODO(b/415828647): Implement for MetricStyle
            // Remember: Add new layout resources to isStandardLayout()
        }
    }
    /**
     * A Notification Style used to define a notification whose expanded state includes
     * a highly customizable progress bar with segments, points, a custom tracker icon,
+8 −0
Original line number Diff line number Diff line
@@ -34,6 +34,14 @@ flag {
  is_fixed_read_only: true
}

flag {
  name: "api_metric_style"
  is_exported: true
  namespace: "notifications"
  description: "This flag adds a new Notification.MetricStyle"
  bug: "415827681"
}

flag {
  name: "modes_ui_dnd_tile"
  namespace: "systemui"
+32 −0
Original line number Diff line number Diff line
@@ -359,6 +359,38 @@ public class NotificationTest {
        assertThat(n.containsCustomViews()).isTrue();
    }

    @Test
    @EnableFlags({Flags.FLAG_UI_RICH_ONGOING, Flags.FLAG_API_METRIC_STYLE})
    public void testGetNotificationStyle_metricStyle_withApiFlagEnabled() {
        // FIRST -- check that this works if you use the constructor
        Notification n = new Notification.Builder(mContext, "test")
                .setStyle(new Notification.MetricStyle())
                .setSmallIcon(android.R.drawable.sym_def_app_icon)
                .build();
        assertThat(n.extras.getString(Notification.EXTRA_TEMPLATE))
                .isEqualTo("android.app.Notification$MetricStyle");
        assertThat(n.getNotificationStyle()).isEqualTo(Notification.MetricStyle.class);

        // SECOND -- check that this works if you just set the extra on the notification
        n = new Notification.Builder(mContext, "test")
                .setSmallIcon(android.R.drawable.sym_def_app_icon)
                .build();
        n.extras.putString(Notification.EXTRA_TEMPLATE, "android.app.Notification$MetricStyle");
        assertThat(n.getNotificationStyle()).isEqualTo(Notification.MetricStyle.class);
    }

    @Test
    @EnableFlags(Flags.FLAG_UI_RICH_ONGOING)
    @DisableFlags(Flags.FLAG_API_METRIC_STYLE)
    public void testGetNotificationStyle_metricStyle_withApiFlagDisabled() {
        // ALTERNATIVELY -- check that this returns null if the API flag is disabled
        Notification n = new Notification.Builder(mContext, "test")
                .setSmallIcon(android.R.drawable.sym_def_app_icon)
                .build();
        n.extras.putString(Notification.EXTRA_TEMPLATE, "android.app.Notification$MetricStyle");
        assertThat(n.getNotificationStyle()).isNull();
    }

    @Test
    @EnableFlags(Flags.FLAG_UI_RICH_ONGOING)
    public void testHasPromotableStyle_noStyle() {