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

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

Implement async version of CallLayout#setData

This CL introduces setDataAsync implementation of setData RemotableMethod to reduce the impact of loading image on main thread.

Bug: 293961072
Test: SystemUiTests. Put Thread.sleep(5000) into setData and setDataAsync and posting call style notification and observe that shade is usable and no ANR when setDataAsync is enabled.
Change-Id: Id6abe285e0852dc106c610164e33989b54e8613b
parent d34134b2
Loading
Loading
Loading
Loading
+35 −6
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ 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);
@@ -83,7 +84,8 @@ public class CallLayout extends FrameLayout {
        });
    }

    private void updateCallLayout() {
    @NonNull
    private Icon getConversationIcon() {
        CharSequence callerName = "";
        String symbol = "";
        Icon icon = null;
@@ -98,8 +100,7 @@ public class CallLayout extends FrameLayout {
        if (icon == null) {
            icon = mPeopleHelper.createAvatarSymbol(callerName, symbol, mLayoutColor);
        }
        // TODO(b/179178086): crop/clip the icon to a circle?
        mConversationIconView.setImageIcon(icon);
        return icon;
    }

    @RemotableViewMethod
@@ -123,10 +124,38 @@ public class CallLayout extends FrameLayout {
    /**
     * Set the notification extras so that this layout has access
     */
    @RemotableViewMethod
    @RemotableViewMethod(asyncImpl = "setDataAsync")
    public void setData(Bundle extras) {
        setUser(extras.getParcelable(Notification.EXTRA_CALL_PERSON, android.app.Person.class));
        updateCallLayout();
        final Person person = getPerson(extras);
        setUser(person);

        final Icon icon = getConversationIcon();
        mConversationIconView.setImageIcon(icon);
    }


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

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

        final Person person = getPerson(extras);
        setUser(person);

        final Icon conversationIcon = getConversationIcon();
        return mConversationIconView.setImageIconAsync(conversationIcon);
    }

    @Nullable
    private Person getPerson(Bundle extras) {
        return extras.getParcelable(Notification.EXTRA_CALL_PERSON, Person.class);
    }

    private void setUser(Person user) {