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

Commit a5afd2a3 authored by Selim Cinek's avatar Selim Cinek Committed by Android (Google) Code Review
Browse files

Merge "Added a targetAPi check to the user name requirement"

parents 27a266b3 9034386c
Loading
Loading
Loading
Loading
+22 −3
Original line number Diff line number Diff line
@@ -5226,6 +5226,7 @@ public class Notification implements Parcelable
            if (mStyle != null) {
                mStyle.reduceImageSizes(mContext);
                mStyle.purgeResources();
                mStyle.validate(mContext);
                mStyle.buildStyled(mN);
            }
            mN.reduceImageSizes(mContext);
@@ -5795,6 +5796,13 @@ public class Notification implements Parcelable
         */
        public void reduceImageSizes(Context context) {
        }

        /**
         * Validate that this style was properly composed. This is called at build time.
         * @hide
         */
        public void validate(Context context) {
        }
    }

    /**
@@ -6185,12 +6193,23 @@ public class Notification implements Parcelable
         * @param user Required - The person displayed for any messages that are sent by the
         * user. Any messages added with {@link #addMessage(Notification.MessagingStyle.Message)}
         * who don't have a Person associated with it will be displayed as if they were sent
         * by this user. The user also needs to have a valid name associated with it.
         * by this user. The user also needs to have a valid name associated with it, which will
         * be enforced starting in Android P.
         */
        public MessagingStyle(@NonNull Person user) {
            mUser = user;
            if (user == null || user.getName() == null) {
                throw new RuntimeException("user must be valid and have a name");
        }

        /**
         * Validate that this style was properly composed. This is called at build time.
         * @hide
         */
        @Override
        public void validate(Context context) {
            super.validate(context);
            if (context.getApplicationInfo().targetSdkVersion
                    >= Build.VERSION_CODES.P && (mUser == null || mUser.getName() == null)) {
                throw new RuntimeException("User must be valid and have a name.");
            }
        }