From ed13b1971d5f7c93bb36f30872f1b10cd0a9b310 Mon Sep 17 00:00:00 2001
From: Ming-Shin Lu <lumark@google.com>
Date: Mon, 7 Jun 2021 00:24:41 +0800
Subject: [PATCH] Make direct-reply notification as HUN in EditTextVariations

Also, set the content intent to launch an editorActivity as the message
notifiation when tapping the notification.

Bug: 190057993
Test: make EditTextVariations, manual test by using EditTextVariations
      app to simulate the issue step.
Change-Id: I1a4463dc44031eaebb286ad2a289870e97a1c475
---
 tools/EditTextVariations/AndroidManifest.xml  |  4 +++
 .../edittextvariations/EditorActivity.java    | 35 +++++++++++++++++++
 .../edittextvariations/NotificationUtils.java |  5 ++-
 3 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100644 tools/EditTextVariations/src/com/android/inputmethod/tools/edittextvariations/EditorActivity.java

diff --git a/tools/EditTextVariations/AndroidManifest.xml b/tools/EditTextVariations/AndroidManifest.xml
index b5a27b9c8c..b283b3a015 100644
--- a/tools/EditTextVariations/AndroidManifest.xml
+++ b/tools/EditTextVariations/AndroidManifest.xml
@@ -34,6 +34,10 @@
                 <category android:name="android.intent.category.LAUNCHER"/>
             </intent-filter>
         </activity>
+        <activity android:name=".EditorActivity"
+                  android:windowSoftInputMode="stateHidden|adjustPan"
+                  android:theme="@style/defaultActivityTheme"
+                  android:label="@string/app_name"/>
         <receiver android:name=".NotificationBroadcastReceiver"
              android:exported="false"/>
     </application>
diff --git a/tools/EditTextVariations/src/com/android/inputmethod/tools/edittextvariations/EditorActivity.java b/tools/EditTextVariations/src/com/android/inputmethod/tools/edittextvariations/EditorActivity.java
new file mode 100644
index 0000000000..4fc947bffd
--- /dev/null
+++ b/tools/EditTextVariations/src/com/android/inputmethod/tools/edittextvariations/EditorActivity.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2021 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.inputmethod.tools.edittextvariations;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+
+public final class EditorActivity extends Activity {
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        LinearLayout layout = new LinearLayout(this);
+        layout.setOrientation(LinearLayout.VERTICAL);
+        EditText editText = new EditText(this);
+        editText.setHint("reply the message");
+        layout.addView(editText);
+        setContentView(layout);
+    }
+}
diff --git a/tools/EditTextVariations/src/com/android/inputmethod/tools/edittextvariations/NotificationUtils.java b/tools/EditTextVariations/src/com/android/inputmethod/tools/edittextvariations/NotificationUtils.java
index a9b7132eb2..78d52bb009 100644
--- a/tools/EditTextVariations/src/com/android/inputmethod/tools/edittextvariations/NotificationUtils.java
+++ b/tools/EditTextVariations/src/com/android/inputmethod/tools/edittextvariations/NotificationUtils.java
@@ -57,7 +57,7 @@ final class NotificationUtils {
         synchronized (sLock) {
             if (!sNotificationChannelInitialized) {
                 final NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
-                        CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);
+                        CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
                 channel.setDescription(CHANNEL_DESCRIPTION);
                 context.getSystemService(NotificationManager.class)
                         .createNotificationChannel(channel);
@@ -79,12 +79,15 @@ final class NotificationUtils {
 
         final int notificationId = sNextNotificationId.getAndIncrement();
         final PendingIntent pendingIntent = getReplyPendingIntent(context, notificationId);
+        final PendingIntent activityIntent = PendingIntent.getActivity(context, 0,
+                new Intent(context, EditorActivity.class), 0);
         final Notification.Action action =
                 new Notification.Action.Builder(null, "Direct Reply Test", pendingIntent)
                         .addRemoteInput(remoteInput)
                         .build();
         final Notification notification = createNotificationBuilder(context)
                 .setContentText("Content Title")
+                .setContentIntent(activityIntent)
                 .setSmallIcon(R.drawable.ic_launcher)
                 .setContentText("Message from " + UserHandle.getUserHandleForUid(Process.myUid()))
                 .setShowWhen(true)
-- 
GitLab