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

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

CallStyle: Load conversation icon in setDataAsync

Loading ConversationIcon Drawable on the main thread causes ANR. This CL offloads this process on the background thread when call_style_async_set_data is enabled.

Bug: 293961072
Test: presubmit
Flag: ACONFIG android.widget.flags.call_style_async_set_data DEVELOPMENT
Change-Id: If44563698e83eab7cabf83d95b845047edb70ba9
parent 9fb2aa65
Loading
Loading
Loading
Loading
+38 −9
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.view.RemotableViewMethod;
import android.widget.FrameLayout;
import android.widget.RemoteViews;
import android.widget.TextView;
import android.widget.flags.Flags;

import com.android.internal.R;

@@ -41,7 +42,17 @@ import com.android.internal.R;
public class CallLayout extends FrameLayout {
    private final PeopleHelper mPeopleHelper = new PeopleHelper();

    /**
     * Layout Color is used for creating CallLayout person avatar.
     * It will be set on the background thread during CallLayout's inflation
     * when call_style_set_data_async is enabled.
     */
    private int mLayoutColor;
    /**
     * LargeIcon is used for creating CallLayout person avatar.
     * It will be set on the background thread during CallLayout's inflation
     * when call_style_set_data_async is enabled.
     */
    private Icon mLargeIcon;
    private Person mUser;

@@ -49,7 +60,6 @@ public class CallLayout extends FrameLayout {
    private CachingIconView mIcon;
    private CachingIconView mConversationIconBadgeBg;
    private TextView mConversationText;
    private boolean mSetDataAsyncEnabled = false;

    public CallLayout(@NonNull Context context) {
        super(context);
@@ -103,7 +113,19 @@ public class CallLayout extends FrameLayout {
        return icon;
    }

    @RemotableViewMethod
    /**
     * async version of {@link CallLayout#setLayoutColor}
     */
    public Runnable setLayoutColorAsync(int color) {
        if (!Flags.callStyleSetDataAsync()) {
            return () -> setLayoutColor(color);
        }

        mLayoutColor = color;
        return () -> {};
    }

    @RemotableViewMethod(asyncImpl = "setLayoutColorAsync")
    public void setLayoutColor(int color) {
        mLayoutColor = color;
    }
@@ -116,7 +138,19 @@ public class CallLayout extends FrameLayout {
        mConversationIconBadgeBg.setImageTintList(ColorStateList.valueOf(color));
    }

    @RemotableViewMethod
    /**
     * async version of {@link CallLayout#setLargeIcon}
     */
    public Runnable setLargeIconAsync(Icon largeIcon) {
        if (!Flags.callStyleSetDataAsync()) {
            return () -> setLargeIcon(largeIcon);
        }

        mLargeIcon = largeIcon;
        return () -> {};
    }

    @RemotableViewMethod(asyncImpl = "setLargeIconAsync")
    public void setLargeIcon(Icon largeIcon) {
        mLargeIcon = largeIcon;
    }
@@ -133,16 +167,11 @@ public class CallLayout extends FrameLayout {
        mConversationIconView.setImageIcon(icon);
    }


    public void setSetDataAsyncEnabled(boolean setDataAsyncEnabled) {
        mSetDataAsyncEnabled = setDataAsyncEnabled;
    }

    /**
     * Async implementation for setData
     */
    public Runnable setDataAsync(Bundle extras) {
        if (!mSetDataAsyncEnabled) {
        if (!Flags.callStyleSetDataAsync()) {
            return () -> setData(extras);
        }

+0 −4
Original line number Diff line number Diff line
@@ -542,10 +542,6 @@ object Flags {
    @JvmField
    val ENABLE_NEW_PRIVACY_DIALOG = releasedFlag("enable_new_privacy_dialog")

    // TODO(b/302087895): Tracking Bug
    @JvmField val CALL_LAYOUT_ASYNC_SET_DATA =
            unreleasedFlag("call_layout_async_set_data", teamfood = true)

    // TODO(b/302144438): Tracking Bug
    @JvmField val DECOUPLE_REMOTE_INPUT_DELEGATE_AND_CALLBACK_UPDATE =
            unreleasedFlag("decouple_remote_input_delegate_and_callback_update")
+0 −37
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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

import android.content.Context
import android.util.AttributeSet
import android.view.View
import com.android.internal.widget.CallLayout
import javax.inject.Inject

class CallLayoutSetDataAsyncFactory @Inject constructor() : NotifRemoteViewsFactory {
    override fun instantiate(
        row: ExpandableNotificationRow,
        @NotificationRowContentBinder.InflationFlag layoutType: Int,
        parent: View?,
        name: String,
        context: Context,
        attrs: AttributeSet
    ): View? =
        if (name == CallLayout::class.java.name)
            CallLayout(context, attrs).apply { setSetDataAsyncEnabled(true) }
        else null
}
+0 −4
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ constructor(
    featureFlags: FeatureFlags,
    precomputedTextViewFactory: PrecomputedTextViewFactory,
    bigPictureLayoutInflaterFactory: BigPictureLayoutInflaterFactory,
    callLayoutSetDataAsyncFactory: CallLayoutSetDataAsyncFactory,
    optimizedLinearLayoutFactory: NotificationOptimizedLinearLayoutFactory
) : NotifRemoteViewsFactoryContainer {
    override val factories: Set<NotifRemoteViewsFactory> = buildSet {
@@ -39,9 +38,6 @@ constructor(
        if (featureFlags.isEnabled(Flags.BIGPICTURE_NOTIFICATION_LAZY_LOADING)) {
            add(bigPictureLayoutInflaterFactory)
        }
        if (featureFlags.isEnabled(Flags.CALL_LAYOUT_ASYNC_SET_DATA)) {
            add(callLayoutSetDataAsyncFactory)
        }
        if (notifLinearlayoutOptimized()) {
            add(optimizedLinearLayoutFactory)
        }