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

Commit 9145fb62 authored by Tony Mak's avatar Tony Mak
Browse files

Fix smart action is not enabled in first whatsapp notification

When there is only one incoming message, whatsapp neither set
category as msg nor use MessageStyle. To fix this, we add one more
heuristic. If a notification has inline reply, we consider it as a
message notification.

BUG: 110527159
Test: Send myself a whatsapp notification. Observe that smart action is
      added.

Change-Id: I2854764dce4eadd4b785d43f3042499607b2e8bf
parent b5bcf495
Loading
Loading
Loading
Loading
+22 −1
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.app.Notification;
import android.app.Notification;
import android.app.RemoteAction;
import android.app.RemoteAction;
import android.app.RemoteInput;
import android.content.Context;
import android.content.Context;
import android.os.Bundle;
import android.os.Bundle;
import android.os.Parcelable;
import android.os.Parcelable;
@@ -99,7 +100,27 @@ public class SmartActionsHelper {
        }
        }
        // For now, we are only interested in messages.
        // For now, we are only interested in messages.
        return Notification.CATEGORY_MESSAGE.equals(notification.category)
        return Notification.CATEGORY_MESSAGE.equals(notification.category)
                || Notification.MessagingStyle.class.equals(notification.getNotificationStyle());
                || Notification.MessagingStyle.class.equals(notification.getNotificationStyle())
                || hasInlineReply(notification);
    }

    private boolean hasInlineReply(Notification notification) {
        Notification.Action[] actions = notification.actions;
        if (actions == null) {
            return false;
        }
        for (Notification.Action action : actions) {
            RemoteInput[] remoteInputs = action.getRemoteInputs();
            if (remoteInputs == null) {
                continue;
            }
            for (RemoteInput remoteInput : remoteInputs) {
                if (remoteInput.getAllowFreeFormInput()) {
                    return true;
                }
            }
        }
        return false;
    }
    }


    /** Returns the text most salient for action extraction in a notification. */
    /** Returns the text most salient for action extraction in a notification. */