Check in notification generator

Merge existing notification generator from emerald branch, which
has been reverted because of build breakage. Refactor the code and
bring up remote input action (for keyboard jank test). Remove un-
necessary dependencies.

Change-Id: I575994280605638f957dd94068f71e5820fea740
diff --git a/tests/jank/notificationsgenerator_wear/Android.mk b/tests/jank/notificationsgenerator_wear/Android.mk
new file mode 100644
index 0000000..9a80d59
--- /dev/null
+++ b/tests/jank/notificationsgenerator_wear/Android.mk
@@ -0,0 +1,19 @@
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_SDK_VERSION := current
+
+LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
+
+LOCAL_PACKAGE_NAME := NotificationsGeneratorWear
+
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    android-support-v4
+
+LOCAL_CERTIFICATE := vendor/unbundled_google/libraries/certs/clockwork
+
+LOCAL_PROGUARD_FLAG_FILES := proguard.flags
+
+include $(BUILD_PACKAGE)
\ No newline at end of file
diff --git a/tests/jank/notificationsgenerator_wear/AndroidManifest.xml b/tests/jank/notificationsgenerator_wear/AndroidManifest.xml
new file mode 100644
index 0000000..6e3ec81
--- /dev/null
+++ b/tests/jank/notificationsgenerator_wear/AndroidManifest.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.google.android.wearable.support" >
+
+     <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="23" />
+
+    <uses-permission android:name="android.permission.INTERNET" />
+
+    <application
+        android:allowBackup="true"
+        android:icon="@drawable/ic_launcher"
+        android:label="@string/app_name"
+        android:theme="@android:style/Theme.DeviceDefault" >
+        <activity
+            android:name="com.google.android.wearable.support.CustomNotificationStubBroadcastActivity"
+            android:label="@string/app_name"
+            android:launchMode="singleTask" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+        <activity
+            android:name="com.google.android.wearable.support.CustomNotificationRemoteInputActivity"
+            android:allowEmbedded="true"
+            android:exported="true"
+            android:taskAffinity=""
+            android:theme="@android:style/Theme.DeviceDefault.Light" >
+        </activity>
+        <receiver
+            android:name="com.google.android.wearable.support.CustomPostNotificationReceiver"
+            android:exported="true" >
+            <intent-filter>
+                <action android:name="com.google.android.wearable.support.wearnotificationgenerator.SHOW_NOTIFICATION" />
+            </intent-filter>
+        </receiver>
+    </application>
+
+</manifest>
\ No newline at end of file
diff --git a/tests/jank/notificationsgenerator_wear/proguard.flags b/tests/jank/notificationsgenerator_wear/proguard.flags
new file mode 100644
index 0000000..872c809
--- /dev/null
+++ b/tests/jank/notificationsgenerator_wear/proguard.flags
@@ -0,0 +1,54 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}
+
+# GmsCore Proguard rules.
+# See: https://developer.android.com/google/play-services/setup.html
+-keep class * extends java.util.ListResourceBundle {
+    protected Object[][] getContents();
+}
+
+# Keep SafeParcelable value, needed for reflection. This is required to support backwards
+# compatibility of some classes.
+-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
+    public static final *** NULL;
+}
+
+# Keep the names of classes/members we need for client functionality.
+-keepnames @com.google.android.gms.common.annotation.KeepName class *
+-keepclassmembernames class * {
+    @com.google.android.gms.common.annotation.KeepName *;
+}
+
+# Needed for Parcelable/SafeParcelable Creators to not get stripped
+-keepnames class * implements android.os.Parcelable {
+    public static final ** CREATOR;
+}
+
+# Suppress reblochon client library unexpected warnings
+# TODO: Remove the following suppression lines once either the platform prebuilts get updated
+# or the reblochon client library removes unexpected dependencies.
+# The following warnings were encountered:
+#   com.google.android.gms.car.* can't find android.view.SearchEvent
+#   com.google.android.gms.cast.* can't find android.support.v7.media.*
+-dontwarn android.view.SearchEvent
+-dontwarn android.support.v7.media.**
+
+# End GmsCore Proguard rules.
\ No newline at end of file
diff --git a/tests/jank/notificationsgenerator_wear/res/drawable-hdpi/ic_launcher.png b/tests/jank/notificationsgenerator_wear/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..6db17aa
--- /dev/null
+++ b/tests/jank/notificationsgenerator_wear/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/tests/jank/notificationsgenerator_wear/res/drawable-hdpi/ic_notification.png b/tests/jank/notificationsgenerator_wear/res/drawable-hdpi/ic_notification.png
new file mode 100644
index 0000000..0401013
--- /dev/null
+++ b/tests/jank/notificationsgenerator_wear/res/drawable-hdpi/ic_notification.png
Binary files differ
diff --git a/tests/jank/notificationsgenerator_wear/res/drawable-hdpi/ic_reply.png b/tests/jank/notificationsgenerator_wear/res/drawable-hdpi/ic_reply.png
new file mode 100644
index 0000000..b3e6146
--- /dev/null
+++ b/tests/jank/notificationsgenerator_wear/res/drawable-hdpi/ic_reply.png
Binary files differ
diff --git a/tests/jank/notificationsgenerator_wear/res/drawable-mdpi/ic_launcher.png b/tests/jank/notificationsgenerator_wear/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 0000000..ddedab6
--- /dev/null
+++ b/tests/jank/notificationsgenerator_wear/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/tests/jank/notificationsgenerator_wear/res/drawable-mdpi/ic_notification.png b/tests/jank/notificationsgenerator_wear/res/drawable-mdpi/ic_notification.png
new file mode 100644
index 0000000..7e93c94
--- /dev/null
+++ b/tests/jank/notificationsgenerator_wear/res/drawable-mdpi/ic_notification.png
Binary files differ
diff --git a/tests/jank/notificationsgenerator_wear/res/drawable-mdpi/ic_reply.png b/tests/jank/notificationsgenerator_wear/res/drawable-mdpi/ic_reply.png
new file mode 100644
index 0000000..8b01970
--- /dev/null
+++ b/tests/jank/notificationsgenerator_wear/res/drawable-mdpi/ic_reply.png
Binary files differ
diff --git a/tests/jank/notificationsgenerator_wear/res/drawable-xhdpi/ic_launcher.png b/tests/jank/notificationsgenerator_wear/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..36d56a4
--- /dev/null
+++ b/tests/jank/notificationsgenerator_wear/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/tests/jank/notificationsgenerator_wear/res/drawable-xhdpi/ic_notification.png b/tests/jank/notificationsgenerator_wear/res/drawable-xhdpi/ic_notification.png
new file mode 100644
index 0000000..1bda506
--- /dev/null
+++ b/tests/jank/notificationsgenerator_wear/res/drawable-xhdpi/ic_notification.png
Binary files differ
diff --git a/tests/jank/notificationsgenerator_wear/res/drawable-xhdpi/ic_reply.png b/tests/jank/notificationsgenerator_wear/res/drawable-xhdpi/ic_reply.png
new file mode 100644
index 0000000..784c4ba
--- /dev/null
+++ b/tests/jank/notificationsgenerator_wear/res/drawable-xhdpi/ic_reply.png
Binary files differ
diff --git a/tests/jank/notificationsgenerator_wear/res/drawable-xxhdpi/ic_launcher.png b/tests/jank/notificationsgenerator_wear/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..cabc1c9
--- /dev/null
+++ b/tests/jank/notificationsgenerator_wear/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/tests/jank/notificationsgenerator_wear/res/drawable-xxhdpi/ic_notification.png b/tests/jank/notificationsgenerator_wear/res/drawable-xxhdpi/ic_notification.png
new file mode 100644
index 0000000..eb0684b
--- /dev/null
+++ b/tests/jank/notificationsgenerator_wear/res/drawable-xxhdpi/ic_notification.png
Binary files differ
diff --git a/tests/jank/notificationsgenerator_wear/res/drawable-xxhdpi/ic_reply.png b/tests/jank/notificationsgenerator_wear/res/drawable-xxhdpi/ic_reply.png
new file mode 100644
index 0000000..ffc524a
--- /dev/null
+++ b/tests/jank/notificationsgenerator_wear/res/drawable-xxhdpi/ic_reply.png
Binary files differ
diff --git a/tests/jank/notificationsgenerator_wear/res/drawable-xxxhdpi/ic_launcher.png b/tests/jank/notificationsgenerator_wear/res/drawable-xxxhdpi/ic_launcher.png
new file mode 100644
index 0000000..ce22034
--- /dev/null
+++ b/tests/jank/notificationsgenerator_wear/res/drawable-xxxhdpi/ic_launcher.png
Binary files differ
diff --git a/tests/jank/notificationsgenerator_wear/res/values/strings.xml b/tests/jank/notificationsgenerator_wear/res/values/strings.xml
new file mode 100644
index 0000000..b363872
--- /dev/null
+++ b/tests/jank/notificationsgenerator_wear/res/values/strings.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+    <string name="app_name">NotificationsGeneratorWear</string>
+
+    <string name="notification_content">Notification Content</string>
+    <string name="notification_title">Clockwork Notifications</string>
+    <string name="notification_posted">Notification posted</string>
+</resources>
\ No newline at end of file
diff --git a/tests/jank/notificationsgenerator_wear/res/values/styles.xml b/tests/jank/notificationsgenerator_wear/res/values/styles.xml
new file mode 100644
index 0000000..e6cd596
--- /dev/null
+++ b/tests/jank/notificationsgenerator_wear/res/values/styles.xml
@@ -0,0 +1,16 @@
+<resources>
+
+    <!--
+        Base application theme, dependent on API level. This theme is replaced
+        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+        <item name="android:windowAnimationStyle">@null</item>
+    </style>
+
+    <!-- Application theme. -->
+    <style name="AppTheme" parent="AppBaseTheme">
+        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
+    </style>
+
+</resources>
\ No newline at end of file
diff --git a/tests/jank/notificationsgenerator_wear/src/com/google/android/wearable/support/CustomNotificationRemoteInputActivity.java b/tests/jank/notificationsgenerator_wear/src/com/google/android/wearable/support/CustomNotificationRemoteInputActivity.java
new file mode 100644
index 0000000..b58f8df
--- /dev/null
+++ b/tests/jank/notificationsgenerator_wear/src/com/google/android/wearable/support/CustomNotificationRemoteInputActivity.java
@@ -0,0 +1,24 @@
+/*
+
+ * Copyright (C) 2016 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.google.android.wearable.support;
+
+import android.app.Activity;
+
+public class CustomNotificationRemoteInputActivity extends Activity{
+
+}
diff --git a/tests/jank/notificationsgenerator_wear/src/com/google/android/wearable/support/CustomNotificationStubBroadcastActivity.java b/tests/jank/notificationsgenerator_wear/src/com/google/android/wearable/support/CustomNotificationStubBroadcastActivity.java
new file mode 100644
index 0000000..2ca29be
--- /dev/null
+++ b/tests/jank/notificationsgenerator_wear/src/com/google/android/wearable/support/CustomNotificationStubBroadcastActivity.java
@@ -0,0 +1,40 @@
+/*
+
+ * Copyright (C) 2016 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.google.android.wearable.support;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+
+/**
+ * A simple activity which broadcasts to our receiver and exits.
+ */
+public class CustomNotificationStubBroadcastActivity extends Activity {
+    public static final String LOAD_CARDS_FOR_TEST_ACTION =
+            "com.google.android.wearable.support.wearnotificationgenerator.SHOW_NOTIFICATION";
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        Intent intent = new Intent();
+        intent.setAction(LOAD_CARDS_FOR_TEST_ACTION);
+        sendBroadcast(intent);
+        finish();
+    }
+}
\ No newline at end of file
diff --git a/tests/jank/notificationsgenerator_wear/src/com/google/android/wearable/support/CustomPostNotificationReceiver.java b/tests/jank/notificationsgenerator_wear/src/com/google/android/wearable/support/CustomPostNotificationReceiver.java
new file mode 100644
index 0000000..0224dc5
--- /dev/null
+++ b/tests/jank/notificationsgenerator_wear/src/com/google/android/wearable/support/CustomPostNotificationReceiver.java
@@ -0,0 +1,78 @@
+/*
+
+ * Copyright (C) 2016 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.google.android.wearable.support;
+
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.support.v4.app.NotificationCompat;
+import android.support.v4.app.NotificationCompat.WearableExtender;
+import android.support.v4.app.NotificationManagerCompat;
+import android.support.v4.app.RemoteInput;
+import android.widget.Toast;
+
+
+/**
+ * Receiver to generate notification cards.
+ */
+public class CustomPostNotificationReceiver extends BroadcastReceiver {
+
+    public static final String REMOTE_INPUT_KEY = "demoCardQuickReply";
+    private static final int NOTIFICATION_CARDS_COUNT = 10;
+
+    public CustomPostNotificationReceiver() {
+    }
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        String contentTitle = context.getResources().getString(R.string.notification_title);
+        // Get an instance of NotificationManager service
+        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
+        for (int i = 1; i <= NOTIFICATION_CARDS_COUNT; i++) {
+            Intent remoteInputIntent = new Intent(context,
+                    CustomNotificationRemoteInputActivity.class);
+            PendingIntent remoteInputPendingIntent = PendingIntent
+                    .getActivity(context, i + NOTIFICATION_CARDS_COUNT, remoteInputIntent,
+                            PendingIntent.FLAG_UPDATE_CURRENT);
+            RemoteInput remoteInput = new RemoteInput.Builder(REMOTE_INPUT_KEY)
+                    .setLabel("Quick reply")
+                    .build();
+
+            NotificationCompat.Action action = new NotificationCompat.Action.Builder(
+                    R.drawable.ic_reply, "Reply", remoteInputPendingIntent)
+                    .addRemoteInput(remoteInput)
+                    .build();
+
+            NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
+                    .setSmallIcon(R.drawable.ic_notification)
+                    .setContentTitle(contentTitle + "-" + i)
+                    .setCategory(NotificationCompat.CATEGORY_MESSAGE)
+                    .setContentText(String.format("From iteration %d", i))
+                    .extend(new WearableExtender()
+                            .addAction(action));
+
+            // Build the notification and issues it with notification manager
+            notificationManager.notify(i, notificationBuilder.build());
+        }
+
+        // Show a toast once notifications cards are posted
+        Toast.makeText(context, context.getString(R.string.notification_posted), Toast.LENGTH_SHORT)
+                .show();
+    }
+}
\ No newline at end of file