Add helper APK to CtsVerifier zip.

Some tests require posting notifications from different packages.
This APK adds a service that CTS tests can use when they need to
post notifications that are not from the CtsVerifier package.

Bug: 16005082
Change-Id: If98e313fcd6262ad146dc583d3d3f31661d41daa
diff --git a/apps/CtsVerifier/Android.mk b/apps/CtsVerifier/Android.mk
index e370c81..d0a3c43 100644
--- a/apps/CtsVerifier/Android.mk
+++ b/apps/CtsVerifier/Android.mk
@@ -40,10 +40,13 @@
 
 include $(BUILD_PACKAGE)
 
+notification-bot := $(call intermediates-dir-for,APPS,NotificationBot)/package.apk
+
 # Builds and launches CTS Verifier on a device.
 .PHONY: cts-verifier
-cts-verifier: CtsVerifier adb
+cts-verifier: CtsVerifier adb NotificationBot
 	adb install -r $(PRODUCT_OUT)/data/app/CtsVerifier/CtsVerifier.apk \
+		&& adb install -r $(notification-bot) \
 		&& adb shell "am start -n com.android.cts.verifier/.CtsVerifierActivity"
 
 #
@@ -79,10 +82,11 @@
 $(verifier-zip) : $(HOST_OUT)/bin/cts-usb-accessory
 endif
 $(verifier-zip) : $(HOST_OUT)/CameraITS
-
+$(verifier-zip) : $(notification-bot)
 $(verifier-zip) : $(call intermediates-dir-for,APPS,CtsVerifier)/package.apk | $(ACP)
 		$(hide) mkdir -p $(verifier-dir)
 		$(hide) $(ACP) -fp $< $(verifier-dir)/CtsVerifier.apk
+		$(ACP) -fp $(notification-bot) $(verifier-dir)/NotificationBot.apk
 ifeq ($(HOST_OS),linux)
 		$(hide) $(ACP) -fp $(HOST_OUT)/bin/cts-usb-accessory $(verifier-dir)/cts-usb-accessory
 endif
diff --git a/apps/NotificationBot/Android.mk b/apps/NotificationBot/Android.mk
new file mode 100644
index 0000000..9d9c9f9
--- /dev/null
+++ b/apps/NotificationBot/Android.mk
@@ -0,0 +1,36 @@
+#
+# Copyright (C) 2014 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.
+#
+
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-Iaidl-files-under, src)
+
+LOCAL_PACKAGE_NAME := NotificationBot
+
+LOCAL_PROGUARD_FLAG_FILES := proguard.flags
+
+LOCAL_SDK_VERSION := current
+
+LOCAL_DEX_PREOPT := false
+
+include $(BUILD_PACKAGE)
+
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/apps/NotificationBot/AndroidManifest.xml b/apps/NotificationBot/AndroidManifest.xml
new file mode 100644
index 0000000..b63791f
--- /dev/null
+++ b/apps/NotificationBot/AndroidManifest.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- Copyright (C) 2010 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+      package="com.android.cts.robot"
+      android:versionCode="1"
+      android:versionName="1.0">
+
+    <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="21"/>
+
+    <application android:label="@string/app_name"
+            android:icon="@drawable/icon"
+            android:debuggable="true">
+
+        <!-- Required because a bare service won't show up in the app notifications list. -->
+        <activity android:name=".NotificationBotActivity">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+
+        <!-- services used by the CtsVerifier to test notifications. -->
+        <receiver android:name=".NotificationBot" android:exported="true">
+            <intent-filter>
+                <action android:name="com.android.cts.robot.ACTION_POST" />
+                <action android:name="com.android.cts.robot.ACTION_CANCEL" />
+            </intent-filter>
+        </receiver>
+
+
+    </application>
+
+</manifest>
diff --git a/apps/NotificationBot/proguard.flags b/apps/NotificationBot/proguard.flags
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/apps/NotificationBot/proguard.flags
diff --git a/apps/NotificationBot/res/drawable-hdpi/icon.png b/apps/NotificationBot/res/drawable-hdpi/icon.png
new file mode 100644
index 0000000..ecaabbe
--- /dev/null
+++ b/apps/NotificationBot/res/drawable-hdpi/icon.png
Binary files differ
diff --git a/apps/NotificationBot/res/drawable-ldpi/icon.png b/apps/NotificationBot/res/drawable-ldpi/icon.png
new file mode 100644
index 0000000..f2de61f
--- /dev/null
+++ b/apps/NotificationBot/res/drawable-ldpi/icon.png
Binary files differ
diff --git a/apps/NotificationBot/res/drawable-mdpi/icon.png b/apps/NotificationBot/res/drawable-mdpi/icon.png
new file mode 100644
index 0000000..4950761
--- /dev/null
+++ b/apps/NotificationBot/res/drawable-mdpi/icon.png
Binary files differ
diff --git a/apps/NotificationBot/res/drawable-xhdpi/icon.png b/apps/NotificationBot/res/drawable-xhdpi/icon.png
new file mode 100644
index 0000000..9b39cfb
--- /dev/null
+++ b/apps/NotificationBot/res/drawable-xhdpi/icon.png
Binary files differ
diff --git a/apps/NotificationBot/res/drawable-xxhdpi/icon.png b/apps/NotificationBot/res/drawable-xxhdpi/icon.png
new file mode 100644
index 0000000..b944c10
--- /dev/null
+++ b/apps/NotificationBot/res/drawable-xxhdpi/icon.png
Binary files differ
diff --git a/apps/NotificationBot/res/layout/main.xml b/apps/NotificationBot/res/layout/main.xml
new file mode 100644
index 0000000..bf84fa9
--- /dev/null
+++ b/apps/NotificationBot/res/layout/main.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2014 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.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+             android:layout_width="match_parent"
+             android:layout_height="match_parent"
+             android:orientation="vertical"
+        >
+
+    <Space android:layout_width="match_parent"
+           android:layout_height="0dp"
+           android:layout_weight="1"
+            />
+    <TextView
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:text="@string/call_to_action"
+            android:textAlignment="center"
+            />
+    <Space android:layout_width="match_parent"
+           android:layout_height="0dp"
+           android:layout_weight="1"
+            />
+</LinearLayout>
\ No newline at end of file
diff --git a/apps/NotificationBot/res/values/strings.xml b/apps/NotificationBot/res/values/strings.xml
new file mode 100644
index 0000000..866a9ec
--- /dev/null
+++ b/apps/NotificationBot/res/values/strings.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2014 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.
+-->
+<resources>
+    <string name="app_name">CTS Robot</string>
+    <string name="call_to_action">Nothing to do here,\nPlease run the CTSVerifier App instead.</string>
+</resources>
\ No newline at end of file
diff --git a/apps/NotificationBot/src/com/android/cts/robot/NotificationBot.java b/apps/NotificationBot/src/com/android/cts/robot/NotificationBot.java
new file mode 100644
index 0000000..2aa5f41
--- /dev/null
+++ b/apps/NotificationBot/src/com/android/cts/robot/NotificationBot.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2014 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.cts.robot;
+
+import android.app.Activity;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+
+
+public class NotificationBot extends BroadcastReceiver {
+    private static final String TAG = "NotificationBot";
+    private static final String EXTRA_ID = "ID";
+    private static final String EXTRA_NOTIFICATION = "NOTIFICATION";
+    private static final String ACTION_POST = "com.android.cts.robot.ACTION_POST";
+    private static final String ACTION_CANCEL = "com.android.cts.robot.ACTION_CANCEL";
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        Log.i(TAG, "received intent: " + intent);
+        if (ACTION_POST.equals(intent.getAction())) {
+            Log.i(TAG, ACTION_POST);
+            if (!intent.hasExtra(EXTRA_NOTIFICATION) || !intent.hasExtra(EXTRA_ID)) {
+                Log.e(TAG, "received post action with missing content");
+                return;
+            }
+            int id = intent.getIntExtra(EXTRA_ID, -1);
+            Log.i(TAG, "id: " + id);
+            Notification n = (Notification) intent.getParcelableExtra(EXTRA_NOTIFICATION);
+            Log.i(TAG, "n: " + n);
+            NotificationManager noMa =
+                    (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+            noMa.notify(id, n);
+
+        } else if (ACTION_CANCEL.equals(intent.getAction())) {
+            Log.i(TAG, ACTION_CANCEL);
+            int id = intent.getIntExtra(EXTRA_ID, -1);
+            Log.i(TAG, "id: " + id);
+            if (id < 0) {
+                Log.e(TAG, "received cancel action with no ID");
+                return;
+            }
+            NotificationManager noMa =
+                    (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+            noMa.cancel(id);
+
+        } else {
+            Log.i(TAG, "received unexpected action: " + intent.getAction());
+        }
+    }
+}
diff --git a/apps/NotificationBot/src/com/android/cts/robot/NotificationBotActivity.java b/apps/NotificationBot/src/com/android/cts/robot/NotificationBotActivity.java
new file mode 100644
index 0000000..1b9408e
--- /dev/null
+++ b/apps/NotificationBot/src/com/android/cts/robot/NotificationBotActivity.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2014 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.cts.robot;
+
+import android.app.Activity;
+import android.os.Bundle;
+import com.android.cts.robot.R;
+
+public class NotificationBotActivity extends Activity {
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.main);
+    }
+}
\ No newline at end of file