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

Commit d3e4c499 authored by Ibrahim Yilmaz's avatar Ibrahim Yilmaz
Browse files

Remove conversation_style_set_avatar_async

Flag: EXEMPT Flag removal
Old Flag: android.widget.flags.conversation_style_set_avatar_async
Test: Presubmit
Fixes: 409611136

Change-Id: Ifa1dd175f07af160e89f056609cd2744cc2909c9
parent 906feec8
Loading
Loading
Loading
Loading
+0 −10
Original line number Diff line number Diff line
@@ -11,16 +11,6 @@ flag {
  }
}

flag {
  name: "conversation_style_set_avatar_async"
  namespace: "systemui"
  description: "Offloads conversation avatar drawable loading to the background thread"
  bug: "305540309"
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}

flag {
  name: "drop_non_existing_messages"
  namespace: "systemui"
+9 −86
Original line number Diff line number Diff line
@@ -510,7 +510,7 @@ public class ConversationLayout extends FrameLayout

        // load conversation header data, avatar and title.
        final ConversationHeaderData conversationHeaderData;
        if (includeConversationIcon && Flags.conversationStyleSetAvatarAsync()) {
        if (includeConversationIcon) {
            conversationHeaderData = loadConversationHeaderData(mIsOneToOne,
                    mConversationTitle,
                    mShortcutIcon,
@@ -638,9 +638,6 @@ public class ConversationLayout extends FrameLayout
     * Update the layout according to the data provided (i.e mIsOneToOne, expanded etc);
     */
    private void updateConversationLayout(MessagingData messagingData) {
        if (!Flags.conversationStyleSetAvatarAsync()) {
            computeAndSetConversationAvatarAndName();
        } else {
        ConversationHeaderData conversationHeaderData =
                messagingData.getConversationHeaderData();
        if (conversationHeaderData == null) {
@@ -650,7 +647,6 @@ public class ConversationLayout extends FrameLayout
                    mLayoutColor);
        }
        setConversationAvatarAndNameFromData(conversationHeaderData);
        }

        updateAppName();
        updateIconPositionAndSize();
@@ -660,60 +656,6 @@ public class ConversationLayout extends FrameLayout
        updateAppNameDividerVisibility();
    }

    @Deprecated
    private void computeAndSetConversationAvatarAndName() {
        // Set avatar and name
        CharSequence conversationText = mConversationTitle;
        mConversationIcon = mShortcutIcon;
        if (mIsOneToOne) {
            // Let's resolve the icon / text from the last sender
            CharSequence userKey = getKey(mUser);
            for (int i = mGroups.size() - 1; i >= 0; i--) {
                MessagingGroup messagingGroup = mGroups.get(i);
                Person messageSender = messagingGroup.getSender();
                if ((messageSender != null && !TextUtils.equals(userKey, getKey(messageSender)))
                        || i == 0) {
                    if (TextUtils.isEmpty(conversationText)) {
                        // We use the sendername as header text if no conversation title is provided
                        // (This usually happens for most 1:1 conversations)
                        conversationText = messagingGroup.getSenderName();
                    }
                    if (mConversationIcon == null) {
                        Icon avatarIcon = messagingGroup.getAvatarIcon();
                        if (avatarIcon == null) {
                            avatarIcon = mPeopleHelper.createAvatarSymbol(conversationText, "",
                                    mLayoutColor);
                        }
                        mConversationIcon = avatarIcon;
                    }
                    break;
                }
            }
        }
        if (mConversationIcon == null) {
            mConversationIcon = mLargeIcon;
        }
        if (mIsOneToOne || mConversationIcon != null) {
            mConversationIconView.setVisibility(VISIBLE);
            mConversationFacePile.setVisibility(GONE);
            mConversationIconView.setImageIcon(mConversationIcon);
        } else {
            mConversationIconView.setVisibility(GONE);
            // This will also inflate it!
            mConversationFacePile.setVisibility(VISIBLE);
            // rebind the value to the inflated view instead of the stub
            mConversationFacePile = findViewById(R.id.conversation_face_pile);
            bindFacePile();
        }
        if (TextUtils.isEmpty(conversationText)) {
            conversationText = mIsOneToOne ? mFallbackChatName : mFallbackGroupChatName;
        }
        mConversationText.setText(conversationText);
        // Update if the groups can hide the sender if they are first (applies to 1:1 conversations)
        // This needs to happen after all of the above o update all of the groups
        mPeopleHelper.maybeHideFirstSenderName(mGroups, mIsOneToOne, conversationText);
    }

    private void setConversationAvatarAndNameFromData(
            ConversationHeaderData conversationHeaderData) {
        mConversationHeaderData = conversationHeaderData;
@@ -1033,10 +975,6 @@ public class ConversationLayout extends FrameLayout
     */
    @RemotableViewMethod
    public Runnable setLargeIconAsync(Icon largeIcon) {
        if (!Flags.conversationStyleSetAvatarAsync()) {
            return () -> setLargeIcon(largeIcon);
        }

        mLargeIcon = largeIcon;
        return NotificationRunnables.NOOP;
    }
@@ -1051,10 +989,6 @@ public class ConversationLayout extends FrameLayout
     */
    @RemotableViewMethod
    public Runnable setShortcutIconAsync(Icon shortcutIcon) {
        if (!Flags.conversationStyleSetAvatarAsync()) {
            return () -> setShortcutIcon(shortcutIcon);
        }

        mShortcutIcon = shortcutIcon;
        return NotificationRunnables.NOOP;
    }
@@ -1069,10 +1003,6 @@ public class ConversationLayout extends FrameLayout
     */
    @RemotableViewMethod
    public Runnable setConversationTitleAsync(CharSequence conversationTitle) {
        if (!Flags.conversationStyleSetAvatarAsync()) {
            return () -> setConversationTitle(conversationTitle);
        }

        // Remove formatting from the title.
        mConversationTitle = conversationTitle != null ? conversationTitle.toString() : null;
        return NotificationRunnables.NOOP;
@@ -1176,10 +1106,6 @@ public class ConversationLayout extends FrameLayout
     */
    @RemotableViewMethod
    public Runnable setLayoutColorAsync(int color) {
        if (!Flags.conversationStyleSetAvatarAsync()) {
            return () -> setLayoutColor(color);
        }

        mLayoutColor = color;
        return NotificationRunnables.NOOP;
    }
@@ -1194,9 +1120,6 @@ public class ConversationLayout extends FrameLayout
     */
    @RemotableViewMethod
    public Runnable setIsOneToOneAsync(boolean oneToOne) {
        if (!Flags.conversationStyleSetAvatarAsync()) {
            return () -> setIsOneToOne(oneToOne);
        }
        mIsOneToOne = oneToOne;
        return NotificationRunnables.NOOP;
    }
+1 −39
Original line number Diff line number Diff line
@@ -40,7 +40,6 @@ import com.android.internal.widget.ConversationLayout;
import com.android.systemui.res.R;
import com.android.systemui.statusbar.notification.NotificationFadeAware;
import com.android.systemui.statusbar.notification.row.shared.AsyncHybridViewInflation;
import com.android.systemui.statusbar.notification.row.shared.ConversationStyleSetAvatarAsync;
import com.android.systemui.statusbar.notification.row.ui.viewmodel.ConversationAvatar;
import com.android.systemui.statusbar.notification.row.ui.viewmodel.FacePile;
import com.android.systemui.statusbar.notification.row.ui.viewmodel.SingleIcon;
@@ -151,46 +150,9 @@ public class HybridConversationNotificationView extends HybridNotificationView {

    private void loadConversationAvatar(ConversationLayout conversationLayout) {
        AsyncHybridViewInflation.assertInLegacyMode();
        if (ConversationStyleSetAvatarAsync.isEnabled()) {
        loadConversationAvatarWithDrawable(conversationLayout);
        } else {
            loadConversationAvatarWithIcon(conversationLayout);
        }
    }

    @Deprecated
    private void loadConversationAvatarWithIcon(ConversationLayout conversationLayout) {
        ConversationStyleSetAvatarAsync.assertInLegacyMode();
        AsyncHybridViewInflation.assertInLegacyMode();
        final Icon conversationIcon = conversationLayout.getConversationIcon();
        if (conversationIcon != null) {
            mConversationFacePile.setVisibility(GONE);
            mConversationIconView.setVisibility(VISIBLE);
            mConversationIconView.setImageIcon(conversationIcon);
            setSize(mConversationIconView, mSingleAvatarSize);
        } else {
            // If there isn't an icon, generate a "face pile" based on the sender avatars
            mConversationIconView.setVisibility(GONE);
            mConversationFacePile.setVisibility(VISIBLE);

            mConversationFacePile =
                    requireViewById(com.android.internal.R.id.conversation_face_pile);
            final ImageView facePileBottomBg = mConversationFacePile.requireViewById(
                    com.android.internal.R.id.conversation_face_pile_bottom_background);
            final ImageView facePileBottom = mConversationFacePile.requireViewById(
                    com.android.internal.R.id.conversation_face_pile_bottom);
            final ImageView facePileTop = mConversationFacePile.requireViewById(
                    com.android.internal.R.id.conversation_face_pile_top);
            conversationLayout.bindFacePile(facePileBottomBg, facePileBottom, facePileTop);
            setSize(mConversationFacePile, mFacePileSize);
            setSize(facePileBottom, mFacePileAvatarSize);
            setSize(facePileTop, mFacePileAvatarSize);
            setSize(facePileBottomBg, mFacePileAvatarSize + 2 * mFacePileProtectionWidth);
            mTransformationHelper.addViewTransformingToSimilar(facePileTop);
            mTransformationHelper.addViewTransformingToSimilar(facePileBottom);
            mTransformationHelper.addViewTransformingToSimilar(facePileBottomBg);
        }
    }

    private void loadConversationAvatarWithDrawable(ConversationLayout conversationLayout) {
        AsyncHybridViewInflation.assertInLegacyMode();
+0 −52
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.notification.row.shared

import android.widget.flags.Flags
import com.android.systemui.flags.FlagToken
import com.android.systemui.flags.RefactorFlagUtils

/** Helper for reading or using the conversation style set avatar async flag state. */
@Suppress("NOTHING_TO_INLINE")
object ConversationStyleSetAvatarAsync {
    const val FLAG_NAME = Flags.FLAG_CONVERSATION_STYLE_SET_AVATAR_ASYNC

    /** A token used for dependency declaration */
    val token: FlagToken
        get() = FlagToken(FLAG_NAME, isEnabled)

    /** Is async hybrid (single-line) view inflation enabled */
    @JvmStatic
    inline val isEnabled
        get() = Flags.conversationStyleSetAvatarAsync()

    /**
     * Called to ensure code is only run when the flag is enabled. This protects users from the
     * unintended behaviors caused by accidentally running new logic, while also crashing on an eng
     * build to ensure that the refactor author catches issues in testing.
     */
    @JvmStatic
    inline fun isUnexpectedlyInLegacyMode() =
        RefactorFlagUtils.isUnexpectedlyInLegacyMode(isEnabled, FLAG_NAME)

    /**
     * Called to ensure code is only run when the flag is disabled. This will throw an exception if
     * the flag is enabled to ensure that the refactor author catches issues in testing.
     */
    @JvmStatic
    inline fun assertInLegacyMode() = RefactorFlagUtils.assertInLegacyMode(isEnabled, FLAG_NAME)
}